iTOP4412设备驱动学习十五-I2C主机驱动
作者:互联网
资料观看的讯为电子Linux视频教程学习。
1. I2C驱动注册和卸载:i2c_add_driver, i2c_del_driver, i2c_driver
下面直接写驱动注册程序:头文件可以参考./drivers/input/touchscreen/ft5x06_ts.c
module_init和late_initcall: 优先加载驱动和后加载驱动,驱动加载的前后关系。
关于i2c_driver的结构体定义如下:
1 ./include/linux/i2c.h 2 3 /** 4 * struct i2c_driver - represent an I2C device driver 5 * @class: What kind of i2c device we instantiate (for detect) 6 * @attach_adapter: Callback for bus addition (deprecated) 7 * @detach_adapter: Callback for bus removal (deprecated) 8 * @probe: Callback for device binding 9 * @remove: Callback for device unbinding 10 * @shutdown: Callback for device shutdown 11 * @suspend: Callback for device suspend 12 * @resume: Callback for device resume 13 * @alert: Alert callback, for example for the SMBus alert protocol 14 * @command: Callback for bus-wide signaling (optional) 15 * @driver: Device driver model driver 16 * @id_table: List of I2C devices supported by this driver 17 * @detect: Callback for device detection 18 * @address_list: The I2C addresses to probe (for detect) 19 * @clients: List of detected clients we created (for i2c-core use only) 20 * 21 * The driver.owner field should be set to the module owner of this driver. 22 * The driver.name field should be set to the name of this driver. 23 * 24 * For automatic device detection, both @detect and @address_data must 25 * be defined. @class should also be set, otherwise only devices forced 26 * with module parameters will be created. The detect function must 27 * fill at least the name field of the i2c_board_info structure it is 28 * handed upon successful detection, and possibly also the flags field. 29 * 30 * If @detect is missing, the driver will still work fine for enumerated 31 * devices. Detected devices simply won't be supported. This is expected 32 * for the many I2C/SMBus devices which can't be detected reliably, and 33 * the ones which can always be enumerated in practice. 34 * 35 * If @detect is missing, the driver will still work fine for enumerated 36 * devices. Detected devices simply won't be supported. This is expected 37 * for the many I2C/SMBus devices which can't be detected reliably, and 38 * the ones which can always be enumerated in practice. 39 * 40 * The i2c_client structure which is handed to the @detect callback is 41 * not a real i2c_client. It is initialized just enough so that you can 42 * call i2c_smbus_read_byte_data and friends on it. Don't do anything 43 * else with it. In particular, calling dev_dbg and friends on it is 44 * not allowed. 45 */ 46 struct i2c_driver { 47 unsigned int class; 48 49 /* Notifies the driver that a new bus has appeared or is about to be 50 * removed. You should avoid using this, it will be removed in a 51 * near future. 52 */ 53 int (*attach_adapter)(struct i2c_adapter *) __deprecated; 54 int (*detach_adapter)(struct i2c_adapter *) __deprecated; 55 56 /* Standard driver model interfaces */ 57 int (*probe)(struct i2c_client *, const struct i2c_device_id *); 58 int (*remove)(struct i2c_client *); 59 60 /* driver model interfaces that don't relate to enumeration */ 61 void (*shutdown)(struct i2c_client *); 62 int (*suspend)(struct i2c_client *, pm_message_t mesg); 63 int (*resume)(struct i2c_client *); 64 65 /* Alert callback, for example for the SMBus alert protocol. 66 * The format and meaning of the data value depends on the protocol. 67 * For the SMBus alert protocol, there is a single bit of data passed 68 * as the alert response's low bit ("event flag"). 69 */ 70 void (*alert)(struct i2c_client *, unsigned int data); 71 72 /* a ioctl like command that can be used to perform specific functions 73 * with the device. 74 */ 75 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg); 76 77 struct device_driver driver; 78 const struct i2c_device_id *id_table; 79 80 /* Device detection callback for automatic device creation */ 81 int (*detect)(struct i2c_client *, struct i2c_board_info *); 82 const unsigned short *address_list; 83 struct list_head clients; 84 };
标签:iTOP4412,struct,int,driver,client,device,驱动,I2C,i2c 来源: https://www.cnblogs.com/nanzh/p/13339484.html