linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: Add of_register_i2c_devices()
@ 2007-06-29 19:20 Guennadi Liakhovetski
  2007-07-01 23:36 ` Kumar Gala
  2007-07-02 12:03 ` Segher Boessenkool
  0 siblings, 2 replies; 34+ messages in thread
From: Guennadi Liakhovetski @ 2007-06-29 19:20 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Paul Mackerras

Add of_register_i2c_devices(), which scans the children of the specified
I2C adapter node, and registers them with the I2C code.

Signed-off-by: Scott Wood <scottwood@freescale.com>
Signed-off-by: G. Liakhovetski <g.liakhovetski@gmx.de>

diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 3786dcc..9caf96d 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -1067,3 +1067,49 @@ void __iomem *of_iomap(struct device_node *np, int index)
 	return ioremap(res.start, 1 + res.end - res.start);
 }
 EXPORT_SYMBOL(of_iomap);
+
+#ifdef CONFIG_I2C
+#include <linux/i2c.h>
+
+void of_register_i2c_devices(struct device_node *adap_node, int bus_num)
+{
+	struct device_node *node = NULL;
+
+	while ((node = of_get_next_child(adap_node, node))) {
+		struct i2c_board_info info;
+		const u32 *addr;
+		const char *name, *model;
+		int len;
+
+		addr = of_get_property(node, "reg", &len);
+		if (!addr || len < sizeof(int) || *addr > 0xffff)
+			continue;
+
+		info.irq = irq_of_parse_and_map(node, 0);
+		if (info.irq == NO_IRQ)
+			info.irq = -1;
+
+		name = of_get_property(node, "compatible", NULL);
+		if (!name)
+			name = node->name;
+		if (!name)
+			continue;
+
+		model = of_get_property(node, "model", NULL);
+		if (!model)
+			model = name;
+
+		/* FIXME: the i2c code should allow drivers to specify
+		 * multiple match names; board code shouldn't need to
+		 * know what driver will handle a given type.
+		 */
+
+		snprintf(info.driver_name, KOBJ_NAME_LEN, name);
+		snprintf(info.type, KOBJ_NAME_LEN, model);
+		info.platform_data = NULL;
+		info.addr = *addr;
+
+		i2c_register_board_info(bus_num, &info, 1);
+	}
+}
+#endif /* CONFIG_I2C */
diff --git a/include/asm-powerpc/prom.h b/include/asm-powerpc/prom.h
index 6845af9..ed085e1 100644
--- a/include/asm-powerpc/prom.h
+++ b/include/asm-powerpc/prom.h
@@ -305,6 +305,7 @@ extern int of_irq_map_raw(struct device_node *parent, const u32 *intspec,
 			  u32 ointsize, const u32 *addr,
 			  struct of_irq *out_irq);
 
+void of_register_i2c_devices(struct device_node *adap_node, int bus_num);
 
 /**
  * of_irq_map_one - Resolve an interrupt for a device

^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2007-08-16  0:36 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-29 19:20 [PATCH] powerpc: Add of_register_i2c_devices() Guennadi Liakhovetski
2007-07-01 23:36 ` Kumar Gala
2007-07-02 11:56   ` Segher Boessenkool
2007-07-02 12:03 ` Segher Boessenkool
2007-07-02 20:11   ` Guennadi Liakhovetski
2007-07-02 22:46     ` Scott Wood
2007-07-02 23:10       ` Segher Boessenkool
2007-07-02 23:06     ` Segher Boessenkool
2007-07-03 22:34       ` Guennadi Liakhovetski
2007-07-03 23:02         ` Segher Boessenkool
2007-07-04  5:28           ` Guennadi Liakhovetski
2007-07-04 12:19             ` Segher Boessenkool
2007-07-04 17:50               ` Guennadi Liakhovetski
2007-07-17 22:17           ` Guennadi Liakhovetski
2007-07-19 15:32             ` Segher Boessenkool
2007-07-19 22:07               ` Guennadi Liakhovetski
2007-07-20  7:26                 ` Segher Boessenkool
2007-07-20 20:26                   ` Guennadi Liakhovetski
2007-07-31 22:55                     ` Segher Boessenkool
2007-08-01  5:41                       ` Guennadi Liakhovetski
2007-08-01  8:18                         ` Segher Boessenkool
2007-08-01 20:36                           ` Guennadi Liakhovetski
2007-08-01 20:42                             ` Scott Wood
2007-08-07 22:32                               ` [PATCH] powerpc: fix i2c device string format Guennadi Liakhovetski
2007-08-09 19:45                                 ` Segher Boessenkool
2007-08-09 20:46                                   ` Guennadi Liakhovetski
2007-08-10 17:44                                     ` Segher Boessenkool
2007-08-15  6:23                                     ` Paul Mackerras
2007-08-15 19:15                                       ` Guennadi Liakhovetski
2007-08-15 21:29                                         ` Scott Wood
2007-08-15 22:23                                           ` Guennadi Liakhovetski
2007-08-16  0:36                                         ` Stephen Rothwell
2007-07-03  0:42   ` [PATCH] powerpc: Add of_register_i2c_devices() Benjamin Herrenschmidt
2007-07-03 12:33     ` Segher Boessenkool

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).