Skip to contentSkip to conversation

I2C: i2c-ocores: Can add I2C devices to the bus

PATCH In review Richard Röjfors 2 participants 2 messages Jun 5, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/9 I2C: 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.

---

drivers/i2c/busses/i2c-ocores.c +5 -0
Index: linux-2.6.30-rc7/drivers/i2c/busses/i2c-ocores.c
===================================================================
@@ -216,6 +216,7 @@
 	struct ocores_i2c_platform_data *pdata;
 	struct resource *res, *res2;
 	int ret;
+	int i;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res)
@@ -271,6 +272,10 @@
 		goto add_adapter_failed;
 	}
 
+	/* add in known devices to the bus */
+	for (i = 0; i < pdata->num_devices; i++)
+		i2c_new_device(&i2c->adap, pdata->devices + i);
+
 	return 0;
 
 add_adapter_failed:
Documentation/i2c/busses/i2c-ocores +17 -0
Index: linux-2.6.30-rc7/Documentation/i2c/busses/i2c-ocores
===================================================================
@@ -20,6 +20,8 @@
 dev.platform_data of the device should also point to a struct
 ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the
 distance between registers and the input clock speed.
+There is also a possibility to attach a list of i2c_board_info which
+the i2c-ocores driver will add to the bus upon creation.
 
 E.G. something like:
 
@@ -36,9 +38,24 @@
 	},
 };
 
+/* optional board info */
+struct i2c_board_info ocores_i2c_board_info[] = {
+	{
+		I2C_BOARD_INFO("tsc2003", 0x48),
+		.platform_data = &tsc2003_platform_data,
+		.irq = TSC_IRQ
+	},
+	{
+		I2C_BOARD_INFO("adv7180", 0x42 >> 1),
+		.irq = ADV_IRQ
+	}
+};
+
 static struct ocores_i2c_platform_data myi2c_data = {
 	.regstep	= 2,		/* two bytes between registers */
 	.clock_khz	= 50000,	/* input clock of 50MHz */
+	.devices	= ocores_i2c_board_info, /* optional table of devices */
+	.num_devices	= ARRAY_SIZE(ocores_i2c_board_info), /* table size */
 };
 
 static struct platform_device myi2c = {
include/linux/i2c-ocores.h +2 -0
Index: linux-2.6.30-rc7/include/linux/i2c-ocores.h
===================================================================
@@ -14,6 +14,8 @@
 struct ocores_i2c_platform_data {
 	u32 regstep;   /* distance between registers */
 	u32 clock_khz; /* input clock in kHz */
+	u8 num_devices; /* number of devices in the devices list */
+	struct i2c_board_info const *devices; /* devices connected to the bus */
 };
 
 #endif /* _LINUX_I2C_OCORES_H */
Acked-by on v1 3/9
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Richard" == Richard Röjfors <[email protected]> writes:

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

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

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

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

Richard> Signed-off-by: Richard Röjfors <[email protected]>

Signature · 1 line
Bye, Peter Korsgaard