简体   繁体   English

Linux设备驱动程序

[英]Linux Device Driver

I have problem concerning about my module it it installed/initialized correctly but the other parts of the driver is not installed or showing up in the output. 我对模块是否正确安装/初始化有疑问,但驱动程序的其他部分未安装或未在输出中显示。

   static struct i2c_driver qt2120_dev {
       .probe = qt2120_probe,
       .remove = qt2120_remove,
       .owner = {
           .name = qt2120,
           .module = THIS_MODULE, 
       }
       ....           
   }

  static __init qt2120_init(){
       prink("********init******");
       .......
  }
  module_init(qt2120_init)

  static int qt2120_probe(){
       prink("********probe******");
       .......     
  }

  static __devinit qt2120_remove(){
       prink("********probe******");
       .......     
  }    

Only "/ * * init * " appeared in the output. 输出中仅显示“ / * * init * ”。 The module has been installed to the i2c according to the output. 根据输出,模块已安装到i2c。

  "bus: i2c. qt2120 as qt2120/input" 

Something is wrong with module because the printk's in probe and remove never at all. 模块出了点问题,因为printk一直在探针中,根本不会被取出。

I also changed in the MAKEFILE @CONFIG_AT2120 += qt2160.o with qt2120.o as the module 我还用qt2120.o作为模块在MAKEFILE @ CONFIG_AT2120 + = qt2160.o中进行了更改

Is there something wrong with my configuration? 我的配置有问题吗? qt2120.c is very similar to qt2160.c in code aurora. 在代码aurora中,qt2120.c与qt2160.c非常相似。

Probe and remove function is not calling because you have not registered your driver with i2c subsystem. 由于尚未向i2c子系统注册驱动程序,因此未调用探测和删除功能。 Register your driver using i2c_add_driver() API. 使用i2c_add_driver()API注册驱动程序。 In your case, 就你而言

static int __init qt2120_init(void)
{
    return i2c_add_driver(&qt2120_dev);
}

static void __exit qt2120_remove(void)
{
    return i2c_del_driver(&qt2120_dev);
}
  • First you need to make ,I2C driver registering the 'struct i2c_driver' structure with the I2C core using i2c_add_driver(addr_of_struct i2c_driver) . 首先,您需要使用i2c_add_driver(addr_of_struct i2c_driver)使I2C驱动程序向I2C内核注册“ struct i2c_driver”结构。

     static const struct i2c_device_id sample_i2c_id[] = { { "qt2120", 0 }, { } }; static struct i2c_driver qt2120_dev = { .probe = qt2120_probe, .remove = qt2120_remove, .id_table = sample_i2c_id, .driver = { .name = "qt2120", }, .... }; 
    • You need to add .id_table entry . 您需要添加.id_table条目。 The id_table member allows us to tell the framework which I2C slaves chips we support. id_table成员允许我们告诉框架我们支持哪些I2C从属芯片。

After matching .id_table entry.Driver calls probe function. 匹配.id_table条目后,驱动程序调用探测函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM