drivers/input/touchscreen/gslx680.c(该文件需要自己添加)
static int __init gsl_ts_init(void) { int ret; print_info("==gsl_ts_init==\n"); ret = i2c_add_driver(&gsl_ts_driver); print_info("ret=%d\n",ret); return ret; } static void __exit gsl_ts_exit(void) { print_info("==gsl_ts_exit==\n"); i2c_del_driver(&gsl_ts_driver); return; } module_init(gsl_ts_init); module_exit(gsl_ts_exit);
gsl_ts_init函数中调用了i2c子系统核心部分提供的i2c_add_driver函数注册了i2c触摸屏驱动。
i2c_driver
static struct i2c_driver gsl_ts_driver = { .driver = { .name = GSLX680_I2C_NAME, .owner = THIS_MODULE, }, #ifndef CONFIG_HAS_EARLYSUSPEND .suspend = gsl_ts_suspend, .resume = gsl_ts_resume, #endif .probe = gsl_ts_probe, .remove = __devexit_p(gsl_ts_remove), .id_table = gsl_ts_id, };
static const struct i2c_device_id gsl_ts_id[] = { {GSLX680_I2C_NAME, 0}, {} };
struct i2c_device_id { char name[I2C_NAME_SIZE]; kernel_ulong_t driver_data /* Data private to the driver */ __attribute__((aligned(sizeof(kernel_ulong_t)))); };
gsl_ts_id中的name会被用来进行和client的匹配(可通过分析i2c bus的match函数得到),driver_data是一个索引值用来记录当前这个i2c_device_id项在id_table中的索引
i2c_client
smdkc110_machine_init
i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));
i2c_register_board_info(1, i2c_devs1, ARRAY_SIZE(i2c_devs1));
i2c_register_board_info(2, i2c_devs2, ARRAY_SIZE(i2c_devs2));/* I2C0 */ static struct i2c_board_info i2c_devs0[] __initdata = { #ifdef CONFIG_SND_SOC_WM8580 { I2C_BOARD_INFO("wm8580", 0x1b), }, #endif