linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/5] powerpc: Add of_register_i2c_devices().
@ 2007-05-17 14:38 Scott Wood
  2007-05-18  0:09 ` Stephen Rothwell
  0 siblings, 1 reply; 3+ messages in thread
From: Scott Wood @ 2007-05-17 14:38 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: i2c

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>
---
 arch/powerpc/kernel/prom_parse.c |   42 ++++++++++++++++++++++++++++++++++++++
 drivers/i2c/busses/i2c-mpc.c     |    2 +-
 include/asm-powerpc/prom.h       |    1 +
 3 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 3786dcc..5e80062 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -1067,3 +1067,45 @@ 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;
+		int len;
+
+		addr = 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 = get_property(node, "compatible", NULL);
+		if (!name)
+			name = node->name;
+		if (!name)
+			continue;
+
+		/* 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, name);
+		info.platform_data = NULL;
+		info.addr = *addr;
+
+		i2c_register_board_info(bus_num, &info, 1);
+	}
+}
+#endif /* CONFIG_I2C */
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index c6b6898..b7870de 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -329,7 +329,7 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	i2c->adap = mpc_ops;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
-	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+	if ((result = i2c_add_prenumbered_adapter(&i2c->adap, pdev->id)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
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
-- 
1.5.0.3

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

* Re: [PATCH 4/5] powerpc: Add of_register_i2c_devices().
  2007-05-17 14:38 [PATCH 4/5] powerpc: Add of_register_i2c_devices() Scott Wood
@ 2007-05-18  0:09 ` Stephen Rothwell
  2007-06-04 19:57   ` Guennadi Liakhovetski
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Rothwell @ 2007-05-18  0:09 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, i2c

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

On Thu, 17 May 2007 09:38:56 -0500 Scott Wood <scottwood@freescale.com> wrote:
>
> +		addr = get_property(node, "reg", &len);

get_property has been replaced by of_get_property.

> +		name = get_property(node, "compatible", NULL);

ditto.

--
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH 4/5] powerpc: Add of_register_i2c_devices().
  2007-05-18  0:09 ` Stephen Rothwell
@ 2007-06-04 19:57   ` Guennadi Liakhovetski
  0 siblings, 0 replies; 3+ messages in thread
From: Guennadi Liakhovetski @ 2007-06-04 19:57 UTC (permalink / raw)
  To: Stephen Rothwell; +Cc: linuxppc-dev, i2c

Hi,

I need this patch, as well as "Scott Wood: [PATCH 5/5] powerpc: Call 
of_register_i2c_devices() for fsl-i2c." 
(http://ozlabs.org/pipermail/linuxppc-dev/2007-May/036333.html) to keep 
linkstation working after the migration of the rtc-rs5c372 driver to the 
new i2c api.

On Fri, 18 May 2007, Stephen Rothwell wrote:

> On Thu, 17 May 2007 09:38:56 -0500 Scott Wood <scottwood@freescale.com> wrote:
> >
> > +		addr = get_property(node, "reg", &len);
> 
> get_property has been replaced by of_get_property.
> 
> > +		name = get_property(node, "compatible", NULL);
> 
> ditto.

Taking care of these corrections, and also using platform device id for 
i2c adapter number, as suggested by Grant Likely (added to cc:) in 
"[PATCH] Make i2c-mpc driver use i2c_add_numbered_adapter" 
(http://ozlabs.org/pipermail/linuxppc-dev/2007-May/036079.html), and using 
"model" of-property, if available, to specify the exact model of the i2c 
device, below is the updated version of the original patch of the hijacked 
thread. Not sure what I shall do with sign-offs... I think, I'll post it 
with none first, wait for Scott Woods comment and his sign-off, and then 
add mine.

Please notice, these two patches suffice to be able to use i2c device 
definitions from of. the "[PATCH 3/5] powerpc: Document device nodes for 
I2C devices." is just documentation, that nobody needs anyway (/me hides), 
and "[PATCH 2/5] i2c: Allow preallocation of I2C bus numbers." was pretty 
controversal too, so, they can be addressed later again...

Thanks
Guennadi
---
Guennadi Liakhovetski

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/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index c6b6898..a769efc 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -327,9 +327,10 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, i2c);
 
 	i2c->adap = mpc_ops;
+	i2c->adap.nr = pdev->id;
 	i2c_set_adapdata(&i2c->adap, i2c);
 	i2c->adap.dev.parent = &pdev->dev;
-	if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+	if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) {
 		printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
 		goto fail_add;
 	}
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] 3+ messages in thread

end of thread, other threads:[~2007-06-04 19:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-17 14:38 [PATCH 4/5] powerpc: Add of_register_i2c_devices() Scott Wood
2007-05-18  0:09 ` Stephen Rothwell
2007-06-04 19:57   ` Guennadi Liakhovetski

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).