linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pasemi: process i2c device tree entries at boot
@ 2007-10-15  1:52 Olof Johansson
  2007-10-15 22:49 ` [PATCH v2] " Olof Johansson
  0 siblings, 1 reply; 5+ messages in thread
From: Olof Johansson @ 2007-10-15  1:52 UTC (permalink / raw)
  To: paulus; +Cc: linuxppc-dev

Setup i2c_board_info based on device tree contents. This has to be
a device_initcall since we need PCI to be probed by the time we
run it, but before the actual driver is initialized.


Signed-off-by: Olof Johansson <olof@lixom.net>

Index: k.org/arch/powerpc/platforms/pasemi/Makefile
===================================================================
--- k.org.orig/arch/powerpc/platforms/pasemi/Makefile
+++ k.org/arch/powerpc/platforms/pasemi/Makefile
@@ -1,4 +1,4 @@
-obj-y	+= setup.o pci.o time.o idle.o powersave.o iommu.o
+obj-y	+= setup.o pci.o time.o idle.o powersave.o iommu.o misc.o
 obj-$(CONFIG_PPC_PASEMI_MDIO)	+= gpio_mdio.o
 obj-$(CONFIG_ELECTRA_IDE) += electra_ide.o
 obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o
Index: k.org/arch/powerpc/platforms/pasemi/misc.c
===================================================================
--- /dev/null
+++ k.org/arch/powerpc/platforms/pasemi/misc.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2007 PA Semi, Inc
+ *
+ * Parts based on arch/powerpc/sysdev/fsl_soc.c:
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/of.h>
+#include <linux/i2c.h>
+
+#ifdef CONFIG_I2C_BOARDINFO
+/* The below is from fsl_soc.c.  It's copied because since there are no
+ * official bus bindings at this time it doesn't make sense to share across
+ * the platforms, even though they happen to be common.
+ */
+struct i2c_driver_device {
+	char    *of_device;
+	char    *i2c_driver;
+	char    *i2c_type;
+};
+
+static struct i2c_driver_device i2c_devices[] __initdata = {
+	{"dallas,ds1338",  "rtc-ds1307",  "ds1338"},
+};
+
+static int __init find_i2c_driver(struct device_node *node,
+				     struct i2c_board_info *info)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
+		if (!of_device_is_compatible(node, i2c_devices[i].of_device))
+			continue;
+		if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
+			    KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
+		    strlcpy(info->type, i2c_devices[i].i2c_type,
+			    I2C_NAME_SIZE) >= I2C_NAME_SIZE)
+			return -ENOMEM;
+		return 0;
+	}
+	return -ENODEV;
+}
+
+static int __init pasemi_register_i2c_devices(void)
+{
+	struct pci_dev *pdev;
+	struct device_node *adap_node;
+	struct device_node *node;
+
+	pdev = NULL;
+	while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {
+		adap_node = pci_device_to_OF_node(pdev);
+
+		node = NULL;
+		while ((node = of_get_next_child(adap_node, node))) {
+			struct i2c_board_info info = {};
+			const u32 *addr;
+			int len;
+
+			addr = of_get_property(node, "reg", &len);
+			if (!addr || len < sizeof(int) ||
+			    *addr > (1 << 10) - 1) {
+				printk(KERN_WARNING
+					"pasemi_register_i2c_devices: "
+					"invalid i2c device entry\n");
+				continue;
+			}
+
+			info.irq = irq_of_parse_and_map(node, 0);
+			if (info.irq == NO_IRQ)
+				info.irq = -1;
+
+			if (find_i2c_driver(node, &info) < 0)
+				continue;
+
+			info.addr = *addr;
+
+			i2c_register_board_info(PCI_FUNC(pdev->devfn), &info,
+						1);
+		}
+	}
+	return 0;
+}
+device_initcall(pasemi_register_i2c_devices);
+#endif

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

* [PATCH v2] pasemi: process i2c device tree entries at boot
  2007-10-15  1:52 [PATCH] pasemi: process i2c device tree entries at boot Olof Johansson
@ 2007-10-15 22:49 ` Olof Johansson
  2007-10-15 22:54   ` Scott Wood
  0 siblings, 1 reply; 5+ messages in thread
From: Olof Johansson @ 2007-10-15 22:49 UTC (permalink / raw)
  To: paulus; +Cc: linuxppc-dev

Setup i2c_board_info based on device tree contents. This has to be
a device_initcall since we need PCI to be probed by the time we
run it, but before the actual driver is initialized.


Signed-off-by: Olof Johansson <olof@lixom.net>


---

Turns out some old firmwares don't create the device node for the
second and third function, so we need to check for it.


Index: k.org/arch/powerpc/platforms/pasemi/Makefile
===================================================================
--- k.org.orig/arch/powerpc/platforms/pasemi/Makefile
+++ k.org/arch/powerpc/platforms/pasemi/Makefile
@@ -1,4 +1,4 @@
-obj-y	+= setup.o pci.o time.o idle.o powersave.o iommu.o
+obj-y	+= setup.o pci.o time.o idle.o powersave.o iommu.o misc.o
 obj-$(CONFIG_PPC_PASEMI_MDIO)	+= gpio_mdio.o
 obj-$(CONFIG_ELECTRA_IDE) += electra_ide.o
 obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o
Index: k.org/arch/powerpc/platforms/pasemi/misc.c
===================================================================
--- /dev/null
+++ k.org/arch/powerpc/platforms/pasemi/misc.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2007 PA Semi, Inc
+ *
+ * Parts based on arch/powerpc/sysdev/fsl_soc.c:
+ *
+ * 2006 (c) MontaVista Software, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/of.h>
+#include <linux/i2c.h>
+
+#ifdef CONFIG_I2C_BOARDINFO
+/* The below is from fsl_soc.c.  It's copied because since there are no
+ * official bus bindings at this time it doesn't make sense to share across
+ * the platforms, even though they happen to be common.
+ */
+struct i2c_driver_device {
+	char    *of_device;
+	char    *i2c_driver;
+	char    *i2c_type;
+};
+
+static struct i2c_driver_device i2c_devices[] __initdata = {
+	{"dallas,ds1338",  "rtc-ds1307",  "ds1338"},
+};
+
+static int __init find_i2c_driver(struct device_node *node,
+				     struct i2c_board_info *info)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
+		if (!of_device_is_compatible(node, i2c_devices[i].of_device))
+			continue;
+		if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
+			    KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
+		    strlcpy(info->type, i2c_devices[i].i2c_type,
+			    I2C_NAME_SIZE) >= I2C_NAME_SIZE)
+			return -ENOMEM;
+		return 0;
+	}
+	return -ENODEV;
+}
+
+static int __init pasemi_register_i2c_devices(void)
+{
+	struct pci_dev *pdev;
+	struct device_node *adap_node;
+	struct device_node *node;
+
+	pdev = NULL;
+	while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {
+		adap_node = pci_device_to_OF_node(pdev);
+
+		if (!adap_node)
+			continue;
+
+		node = NULL;
+		while ((node = of_get_next_child(adap_node, node))) {
+			struct i2c_board_info info = {};
+			const u32 *addr;
+			int len;
+
+			addr = of_get_property(node, "reg", &len);
+			if (!addr || len < sizeof(int) ||
+			    *addr > (1 << 10) - 1) {
+				printk(KERN_WARNING
+					"pasemi_register_i2c_devices: "
+					"invalid i2c device entry\n");
+				continue;
+			}
+
+			info.irq = irq_of_parse_and_map(node, 0);
+			if (info.irq == NO_IRQ)
+				info.irq = -1;
+
+			if (find_i2c_driver(node, &info) < 0)
+				continue;
+
+			info.addr = *addr;
+
+			i2c_register_board_info(PCI_FUNC(pdev->devfn), &info,
+						1);
+		}
+	}
+	return 0;
+}
+device_initcall(pasemi_register_i2c_devices);
+#endif

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

* Re: [PATCH v2] pasemi: process i2c device tree entries at boot
  2007-10-15 22:49 ` [PATCH v2] " Olof Johansson
@ 2007-10-15 22:54   ` Scott Wood
  2007-10-16  0:17     ` Olof Johansson
  0 siblings, 1 reply; 5+ messages in thread
From: Scott Wood @ 2007-10-15 22:54 UTC (permalink / raw)
  To: Olof Johansson; +Cc: linuxppc-dev, paulus

Olof Johansson wrote:
> Setup i2c_board_info based on device tree contents. This has to be
> a device_initcall since we need PCI to be probed by the time we
> run it, but before the actual driver is initialized.

Can we factor at least some of this stuff out into common code?

We certainly shouldn't need more than one translation table, and this loop:

> +static int __init pasemi_register_i2c_devices(void)
> +{
> +	struct pci_dev *pdev;
> +	struct device_node *adap_node;
> +	struct device_node *node;
> +
> +	pdev = NULL;
> +	while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {
> +		adap_node = pci_device_to_OF_node(pdev);

Should be in the pasemi code, and pass a bus number and device node to 
generic code that does this:

> +		node = NULL;
> +		while ((node = of_get_next_child(adap_node, node))) {

-Scott

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

* Re: [PATCH v2] pasemi: process i2c device tree entries at boot
  2007-10-15 22:54   ` Scott Wood
@ 2007-10-16  0:17     ` Olof Johansson
  2007-10-16 16:21       ` Scott Wood
  0 siblings, 1 reply; 5+ messages in thread
From: Olof Johansson @ 2007-10-16  0:17 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, paulus

On Mon, Oct 15, 2007 at 05:54:51PM -0500, Scott Wood wrote:
> Olof Johansson wrote:
>> Setup i2c_board_info based on device tree contents. This has to be
>> a device_initcall since we need PCI to be probed by the time we
>> run it, but before the actual driver is initialized.
>
> Can we factor at least some of this stuff out into common code?

I didn't really feel strong motivations to do so, given that the amount
of shared code is quite small, and the official bindings are not yet
determined.

Chances are whenever the bindings are done they might be incompatible
with what we already have in our firmware, so the code would need to be
separated out again.

> We certainly shouldn't need more than one translation table, and this loop:
>
>> +static int __init pasemi_register_i2c_devices(void)
>> +{
>> +	struct pci_dev *pdev;
>> +	struct device_node *adap_node;
>> +	struct device_node *node;
>> +
>> +	pdev = NULL;
>> +	while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {
>> +		adap_node = pci_device_to_OF_node(pdev);
>
> Should be in the pasemi code, and pass a bus number and device node to 
> generic code that does this:

Yeah, it'd be the natural way of doing it, if it was needed.


-Olof

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

* Re: [PATCH v2] pasemi: process i2c device tree entries at boot
  2007-10-16  0:17     ` Olof Johansson
@ 2007-10-16 16:21       ` Scott Wood
  0 siblings, 0 replies; 5+ messages in thread
From: Scott Wood @ 2007-10-16 16:21 UTC (permalink / raw)
  To: Olof Johansson; +Cc: linuxppc-dev, paulus

Olof Johansson wrote:
> On Mon, Oct 15, 2007 at 05:54:51PM -0500, Scott Wood wrote:
>> Olof Johansson wrote:
>>> Setup i2c_board_info based on device tree contents. This has to be
>>> a device_initcall since we need PCI to be probed by the time we
>>> run it, but before the actual driver is initialized.
>> Can we factor at least some of this stuff out into common code?
> 
> I didn't really feel strong motivations to do so, given that the amount
> of shared code is quite small, and the official bindings are not yet
> determined.

Enh...  I'm just irked because I originally did it in a generic manner, 
and whoever it was that did further work on my patch shoved in into 
fsl_soc. :-P

> Chances are whenever the bindings are done they might be incompatible
> with what we already have in our firmware, so the code would need to be
> separated out again.

Well, then it'd be better to just have one bit of code to fix, right? :-)

It'd suck to see different i2c controllers end up implementing the 
binding differently due to the forking, though.  Already with this 
patch, we have a different set of i2c devices that will be recognized 
depending on the adapter.

-Scott

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

end of thread, other threads:[~2007-10-16 19:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-15  1:52 [PATCH] pasemi: process i2c device tree entries at boot Olof Johansson
2007-10-15 22:49 ` [PATCH v2] " Olof Johansson
2007-10-15 22:54   ` Scott Wood
2007-10-16  0:17     ` Olof Johansson
2007-10-16 16:21       ` Scott Wood

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