各位大哥:
最近在做i2c的设备驱动程序。在网上找了些资料。针对自己的设备写了一个驱动程序。但编译不过去。
提示variable 'ds2746_driver' has initializer but incomplete type.
unknow field 'ower' specified in initializer.结构体ds2746_driver中的所有域都不认识。
还提示ds2746_attach函数中new_client->name=ds2746_driver.name位置 dereferencing pointer to incomplete type
下面是全部的代码,请各位大哥指点。
谢谢。
#include
#include
#include
#include
#include
#include
#include
#include "ds2746.h"
#define BUFFER_SIZE 100 * 1024
static unsigned char ds2746_MAJOR = 127;
static char INNODEV_NAME[] = "ds2746";
struct i2c_adapter;
#ifndef u8
#define u8 unsigned char
#endif
#ifndef u16
#define u16 unsigned int
#endif
struct ds2746_data {
struct i2c_client *client;
u16 ctrl;
};
static int ds2746_attach(struct i2c_adapter *adap, int addr, int kind)
{
int ret, res;
struct i2c_client *new_client;
u8 sendbuf[2];
new_client->name = ds2746_driver.name;
new_client->id = ds2746_driver.id;
new_client->addr = DS2746_SLAVE_ADDR;
new_client->flags = I2C_CLIENT_ALLOW_USE | I2C_DF_NOTIFY;
new_client->adapter = adap;
new_client->driver = &ds2746_driver;
ret = i2c_attach_client(new_client);
if(ret < 0)
{
printk("cant init ds2746\n");
return 1;
}
sendbuf[0] = DS2746_REG_CONFIG;
sendbuf[1] = DS2746_CON_INITDATA;
res = ds2746_write_value(new_client, sendbuf, 2);
if(res < 0)
{
printk("cant init status/config reg\n");
return 2;
}
return res;
}
static int ds2746_write_value(struct i2c_client *client,u8 reg,u16 value)
{
if (reg == DS2746_REG_CONFIG)
return i2c_smbus_write_byte_data(client,reg,value);
else
return i2c_smbus_write_word_data(client,reg,swab16(value));
}
static int ds2746_read_value(struct i2c_client *client,u8 reg)
{
if (reg == DS2746_REG_CONFIG)
return i2c_smbus_read_byte_data(client,reg);
else
return swab16(i2c_smbus_read_word_data(client,reg));
}
static int ds2746_probe(struct i2c_adapter *adap)
{
return i2c_probe(adap, &addr_data, ds2746_attach);
}
static int ds2746_detach(struct i2c_client *client)
{
return i2c_detach_client(client);
}
static struct file_operations ds2746_fops = {
.owner = THIS_MODULE,
.read = ds2746_read_value,
.write = ds2746_write_value,
};
static struct i2c_driver ds2746_driver =
{
.name = DS2746,
.id = I2C_DRIVERID_DS2746,
.flags = I2C_DF_NOTIFY,
.attach_adapter = ds2746_probe,
.detach_client = ds2746_detach,
.command = ds2746_command,
};
static int __init ds2746_init(void)
{
int ret, res;
res = i2c_add_driver(&ds2746_driver);
if(res < 0)
{
printk("Cant add ds2746 driver\n");
return 1;
}
ret = register_chrdev(ds2746_MAJOR, INNODEV_NAME, &ds2746_fops);
if(ret < 0)
{
printk("Cant register ds2746 device\n");
return 1;
}
return 0;
}
static void __exit ds2746_exit(void)
{
i2c_del_driver(&ds2746_driver);
unregister_chrdev(ds2746_MAJOR,"ds2746");
}
module_init(ds2746_init);
module_init(ds2746_exit);
MODULE_LICENSE("GPL");