Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c-ocores: Can add I2C devices to the bus

There is sometimes a need for the ocores driver to add devices to the
bus when installed.

i2c_register_board_info can not always be used, because the I2C devices
are not known at an early state, they could for instance be connected
on a I2C bus on a PCI device which has the Open Cores IP.

i2c_new_device can not be used in all cases either since the resulting
bus nummer might be unknown.

The solution is the pass a list of I2C devices in the platform data to
the Open Cores driver. This is useful for MFD drivers.

Signed-off-by: Richard Röjfors <richard.rojfors.ext@mocean-labs.com>
Signed-off-by: Ben Dooks <ben-linux@fluff.org>

authored by

Richard Röjfors and committed by
Ben Dooks
dd14be4c 7d85ccd8

+24
+17
Documentation/i2c/busses/i2c-ocores
··· 20 20 dev.platform_data of the device should also point to a struct 21 21 ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the 22 22 distance between registers and the input clock speed. 23 + There is also a possibility to attach a list of i2c_board_info which 24 + the i2c-ocores driver will add to the bus upon creation. 23 25 24 26 E.G. something like: 25 27 ··· 38 36 }, 39 37 }; 40 38 39 + /* optional board info */ 40 + struct i2c_board_info ocores_i2c_board_info[] = { 41 + { 42 + I2C_BOARD_INFO("tsc2003", 0x48), 43 + .platform_data = &tsc2003_platform_data, 44 + .irq = TSC_IRQ 45 + }, 46 + { 47 + I2C_BOARD_INFO("adv7180", 0x42 >> 1), 48 + .irq = ADV_IRQ 49 + } 50 + }; 51 + 41 52 static struct ocores_i2c_platform_data myi2c_data = { 42 53 .regstep = 2, /* two bytes between registers */ 43 54 .clock_khz = 50000, /* input clock of 50MHz */ 55 + .devices = ocores_i2c_board_info, /* optional table of devices */ 56 + .num_devices = ARRAY_SIZE(ocores_i2c_board_info), /* table size */ 44 57 }; 45 58 46 59 static struct platform_device myi2c = {
+5
drivers/i2c/busses/i2c-ocores.c
··· 216 216 struct ocores_i2c_platform_data *pdata; 217 217 struct resource *res, *res2; 218 218 int ret; 219 + int i; 219 220 220 221 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 221 222 if (!res) ··· 271 270 dev_err(&pdev->dev, "Failed to add adapter\n"); 272 271 goto add_adapter_failed; 273 272 } 273 + 274 + /* add in known devices to the bus */ 275 + for (i = 0; i < pdata->num_devices; i++) 276 + i2c_new_device(&i2c->adap, pdata->devices + i); 274 277 275 278 return 0; 276 279
+2
include/linux/i2c-ocores.h
··· 14 14 struct ocores_i2c_platform_data { 15 15 u32 regstep; /* distance between registers */ 16 16 u32 clock_khz; /* input clock in kHz */ 17 + u8 num_devices; /* number of devices in the devices list */ 18 + struct i2c_board_info const *devices; /* devices connected to the bus */ 17 19 }; 18 20 19 21 #endif /* _LINUX_I2C_OCORES_H */