Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> I2C 總線的注冊

I2C 總線的注冊

日期:2017/2/7 14:38:59      編輯:Linux教程
  static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,const struct i2c_client *client) { while (id->name[0]) { if (strcmp(client->name, id->name) == 0)//比較名字 return id; id++; } return NULL; }
  static int i2c_device_match(struct device *dev, struct device_driver *drv) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; if (!client) return 0; driver = to_i2c_driver(drv); /* match on an id table if there is one */ if (driver->id_table)//id_table表示該驅動所支持的設備的id表 return i2c_match_id(driver->id_table, client) != NULL; return 0; }
  static int i2c_device_probe(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver;
  driver = to_i2c_driver(dev->driver); ..... status = driver->probe(client, i2c_match_id(driver->id_table, client));//probe ... }
  struct bus_type i2c_bus_type = { .name = "i2c", .match = i2c_device_match, .probe = i2c_device_probe, .remove = i2c_device_remove, .shutdown = i2c_device_shutdown, .suspend = i2c_device_suspend, .resume = i2c_device_resume, }; static int __init i2c_init(void) { int retval;
  retval = bus_register(&i2c_bus_type); if (retval) return retval; #ifdef CONFIG_I2C_COMPAT i2c_adapter_compat_class = class_compat_register("i2c-adapter"); if (!i2c_adapter_compat_class) { retval = -ENOMEM; goto bus_err; } #endif retval = i2c_add_driver(&dummy_driver);//虛擬的驅動 if (retval) goto class_err; return 0; }
  /* We must initialize early, because some subsystems register i2c drivers * in subsys_initcall() code, but are linked (and initialized) before i2c. */ postcore_initcall(i2c_init);

Copyright © Windows教程網 All Rights Reserved