歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

I2C 總線的注冊

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 © Linux教程網 All Rights Reserved