本文主要是介绍Linux kernel-3.10 I2C 驱动程式之Master,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Linux kernel-3.10 I2C Master最简驱动程式
重要数据结构: struct i2c_algorithmv, struct platform_driver, struct i2c_adapter
重要i2c子系统API: i2c_add_numbered_adapter(&adap);
int lxx_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msgs[], S32 num)
{
//实例化i2c master设备传送操作方法
}
static struct i2c_algorithm lxx_i2c_algorithm = {
.master_xfer = lxx_i2c_transfer,
.smbus_xfer = NULL,
.functionality = lxx_i2c_functionality,
};
static S32 lxx_i2c_probe(struct platform_device *pdev)
{
struct i2c_adapter adap;
adap.nr = i2c->id;
adap.owner = THIS_MODULE;
adap.algo = &mt_i2c_algorithm;
adap.algo_data = NULL;
adap.timeout = 2 * HZ; /*2s*/
adap.retries = 1; /*DO NOT TRY*/
request_irq(); // 注册中断
// i2c_set_adapdata(&i2c->adap, i2c);
i2c_add_numbered_adapter(&adap); // 注册adapter
// platform_set_drvdata(pdev, i2c);
}
static S32 lxx_i2c_remove(struct platform_device *pdev)
{
free_irq();
i2c_del_adapter();
}
static struct platform_driver lxx_i2c_driver = {
.probe = lxx_i2c_probe,
.remove = lxx_i2c_remove,
.driver = {
.name = I2C_DRV_NAME,
.owner = THIS_MODULE,
},
};
static S32 __init lxx_i2c_init(void)
{
return platform_driver_register(&lxx_i2c_driver);
}
static void __exit mt_i2c_exit(void)
{
platform_driver_unregister(&lxx_i2c_driver);
}
module_init(mt_i2c_init);
module_exit(mt_i2c_exit);
这篇关于Linux kernel-3.10 I2C 驱动程式之Master的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!