#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEV_NAME "zlg7290"
/* Addresses to scan */
static unsigned short normal_i2c[] = {0x38, I2C_CLIENT_END };
// Insmod parameters
I2C_CLIENT_INSMOD_1(zlg7290);
//I2C_CLIENT_INSMOD;
/* Each client has this additional data */
struct zlg7290_device {
struct i2c_clientclient;
struct cdevdev;
};
static int zlg7290_attach_adapter(struct i2c_adapter *adapter);
static int zlg7290_detect(struct i2c_adapter *adapter, int address, int kind);
static int zlg7290_detach_client(struct i2c_client *client);
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 structi2c_driverzlg7290_driver = {
.owner= THIS_MODULE,
.name= DEV_NAME,
//.id= I2C_DRIVERID_ZLG7290,
.flags= I2C_DF_NOTIFY,
.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=zlg7290_led_write,
.read=zlg7290_key_read,
};
static int zlg7290_attach_adapter(struct i2c_adapter *adapter)
{
//printk("In function %s\n", __FUNCTION__);
returni2c_probe(adapter, &addr_data,zlg7290_detect);
}
/* This function is called by i2c_probe */
static intzlg7290_detect(struct i2c_adapter *adapter, int address, int kind)
{
struct i2c_client *new_client;
struct zlg7290_device *pdev;
dev_t dev_no;
int err = 0;
/* There are three ways we can read the EEPROM data:
(1) I2Cblock reads (faster, but unsupported by most adapters)
(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 (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA
| I2C_FUNC_SMBUS_BYTE)){
printk("i2ccheck functionality error.\n");
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;
i2c_set_clientdata(new_client, pdev);
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, I2C_NAME_SIZE);
/* Tell the I2Clayer a new client has arrived */
if ((err = i