1,319
社区成员
发帖
与我相关
我的任务
分享
static const struct i2c_device_id dm2016_ids[] =
{
{"dm2016", 0},
{/* END OF LIST */}
};
MODULE_DEVICE_TABLE(i2c, dm2016_ids);
struct dm2016_data {
struct i2c_client *client;
};
static int __devinit dm2016_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct dm2016_data *pstDM2016Data = NULL;
struct device *pstDev = &client->dev;
int s32Ret = 0;
pstDM2016Data = kzalloc(sizeof(*pstDev), GFP_KERNEL);
if (NULL == pstDM2016Data)
{
dev_err(pstDev, "alloc dm2016 data memory fail!\n");
return -ENOMEM;
}
pstDM2016Data->client = client;
i2c_set_clientdata(client, pstDM2016Data);
dev_info(pstDev, "create dm2016 client OK!\n");
return 0;
}
static int __devexit dm2016_remove(struct i2c_client *client)
{
struct dm2016_data *pstDM2016Data = i2c_get_clientdata(client);
kfree(pstDM2016Data);
return 0;
}
static struct i2c_driver dm2016_driver = {
.driver = {
.name = "dm2016",
.owner = THIS_MODULE,
},
.probe = dm2016_probe,
.remove = __devexit_p(dm2016_remove),
.id_table = dm2016_ids,
};
static int __init dm2016_init(void)
{
return i2c_add_driver(&dm2016_driver);
}
static void __exit dm2016_exit(void)
{
i2c_del_driver(&dm2016_driver);
}