2012年(1008)
分类:
2012-07-31 11:46:53
原文地址:linux下IIC驱动开发分析(4) 作者:putiancaijunyu
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEV_NAME "zlg7290"
/* Addresses to scan */
static unsigned short normal_i
// Insmod parameters
I
//I
/* Each client has this additional data */
struct zlg7290_device {
struct i
struct cdev dev;
};
static int zlg7290_attach_adapter(struct i
static int zlg7290_detect(struct i
static int zlg7290_detach_client(struct i
static ssize_t zlg7290_key_read(struct file *filp, char *buff, size_t count, loff_t *offp);
static ssize_t zlg7290_led_write(struct file *filp, const char *buff, size_t count, loff_t *offp);
static int zlg7290_open(struct inode *inode, struct file *filp);
/* This is the driver that will be inserted */
static struct i2c_driver zlg7290_driver = {
.owner = THIS_MODULE,
.name = DEV_NAME,
// .id = I
.flags = I
.attach_adapter = zlg7290_attach_adapter,
.detach_client = zlg7290_detach_client,
};
static struct file_operations zlg7290_fops = {
.owner = THIS_MODULE,
.open = zlg7290_open,
// .release = led_release,
.write =
.read = zlg7290_key_read,
};
static int zlg7290_attach_adapter(struct i
{
// printk("In function %s\n", __FUNCTION__);
return i2c_probe(adapter, &addr_data, zlg7290_detect);
}
/* This function is called by i
static int (struct i
{
struct i
struct zlg7290_device *pdev;
dev_t dev_no;
int err = 0;
/* There are three ways we can read the EEPROM data:
(1) I
(2) Consecutive byte reads (100% overhead)
(3) Regular byte data reads (200% overhead)
The third method is not implemented by this driver because all
known adapters support at least the second. */
// printk("In function %s\n", __FUNCTION__);
if (!i
| I
printk("i
goto exit;
}
if (!(pdev = kmalloc(sizeof(struct zlg7290_device), GFP_KERNEL))) {
printk("Kmalloc error.\n");
err = -ENOMEM;
goto exit;
}
memset(pdev, 0, sizeof(struct zlg7290_device));
new_client = &pdev->client;
i
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &zlg7290_driver;
new_client->flags = 0;
/* Fill in the remaining client fields */
strlcpy(new_client->name, DEV_NAME, I
/* Tell the I
if ((err = i