Sensor problem while writing I2C device driver

I'm new to writing a linux device driver, forgive me if anything stupid is asked and my bad english ^^
I am trying to write a driver for a touchpad that communicates with a processor through I2C.
I tried to add the device driver to the linux platform, and the register was successful, I mean that the driver was loaded, but the probe function did not light up!

Above is the partial driver code that I wrote.

static int i2c_ts_probe(struct i2c_client *client, const struct i2c_device_id * id) { /* ... */ } static int i2c_ts_remove(struct i2c_client *client) { /* ... */ } static const struct i2c_device_id i2c_ts_id[] = { {"Capacitive TS", 0}, { } }; MODULE_DEVICE_TABLE(i2c, i2c_ts_id); static struct i2c_driver i2c_ts = { .id_table = i2c_ts_id, .probe = i2c_ts_probe, .remove = i1c_ts_remobe, .driver = { .name = "i2c_ts", }, }; static int __init i2c_ts_init(void) { return i2c_add_driver(&i2c_ts); } static int __init i2c_ts_exit(void) { return i2c_del_driver(&i2c_ts); } module_init(i2c_ts_init); module_exit(i2c_ts_exit); 

The above is a partial platform code (/kernel/arch/arm/mach-pxa/saarb.c) used to register an i2c device.

 static struct i2c_board_info i2c_board_info_ts[] = { { .type = i2c_ts, .irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)), }, }; static void __init saarb_init(void) { ... i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts)); ... } 

Any suggestion and comment would be welcome, thanks ^^

+6
linux-device-driver i2c
source share
2 answers

For the Linux device / driver model to be able to examine your driver, this device must be requested: this is achieved by comparing the driver name ("i2c_ts") and the type of device in the i2c_board_info structure. In your case, I assume that the type is not equal to "i2c_ts".

Therefore, I suggest you use the I2C_BOARD_INFO macro to instantiate your device, as described in Documentation / i2c / instantiation_devices.

 static struct i2c_board_info i2c_board_info_ts[] = { { I2C_BOARD_INFO("i2c_ts", 0x12), .irq = IRQ_GPIO(mfp_to_gpio(MFP_PIN_GPIO0)), }, }; static void __init saarb_init(void) { ... i2c_register_board_info(0, ARRAY_AND_SIZE(i2c_board_info_ts)); ... } 

You also did not provide an address on your device, and I2C_BOARD_INFO needs it. Read the technical description of your touch screen to find out what the address is.

Finally, as suggested above, make sure i2c_ts_id is correct. I'm not sure that it plays a role in the mechanism of association of devices / modules in the kernel, but I would say that it is much less confusing, they all have the same name.

+7
source share

The probe method will only be called when the device matches the driver name. As you mentioned your driver name as "i2c_ts", check the device tree for the device name. Both must be the same.

+1
source share

All Articles