* [PATCH 1/2] [POWERPC] Consolidate compatible-to-i2c_boardinfo mapping code
@ 2007-11-30 3:26 Olof Johansson
2007-11-30 3:29 ` [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info Olof Johansson
0 siblings, 1 reply; 6+ messages in thread
From: Olof Johansson @ 2007-11-30 3:26 UTC (permalink / raw)
To: linuxppc-dev
[POWERPC] Consolidate compatible-to-i2c_boardinfo mapping code
Move the mapping from device tree compatible field to i2c_boardinfo
structures for powerpc, since several platforms now use this.
Signed-off-by: Olof Johansson <olof@lixom.net>
---
arch/powerpc/sysdev/Makefile | 1
arch/powerpc/sysdev/fsl_soc.c | 38 ---------------------
arch/powerpc/sysdev/i2c_of_mapping.c | 61 +++++++++++++++++++++++++++++++++++
include/asm-powerpc/i2c_of.h | 14 ++++++++
4 files changed, 77 insertions(+), 37 deletions(-)
Index: 2.6.24/arch/powerpc/sysdev/Makefile
===================================================================
--- 2.6.24.orig/arch/powerpc/sysdev/Makefile
+++ 2.6.24/arch/powerpc/sysdev/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_MV64X60) += $(mv64x60-y) m
mv64x60_udbg.o
obj-$(CONFIG_RTC_DRV_CMOS) += rtc_cmos_setup.o
obj-$(CONFIG_AXON_RAM) += axonram.o
+obj-$(CONFIG_I2C_BOARDINFO) += i2c_of_mapping.o
ifeq ($(CONFIG_PPC_MERGE),y)
obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o
Index: 2.6.24/arch/powerpc/sysdev/i2c_of_mapping.c
===================================================================
--- /dev/null
+++ 2.6.24/arch/powerpc/sysdev/i2c_of_mapping.c
@@ -0,0 +1,61 @@
+/*
+ * 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/of.h>
+#include <linux/i2c.h>
+#include <asm/i2c_of.h>
+
+struct i2c_driver_device {
+ char *of_device;
+ char *i2c_driver;
+ char *i2c_type;
+};
+
+
+/* This table is used to map from device tree compat fields to
+ * the driver and model used by the i2c board info structures.
+ *
+ * Add new mappings as needed.
+ */
+
+static struct i2c_driver_device i2c_devices[] __initdata = {
+ {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
+ {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
+ {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
+ {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
+ {"dallas,ds1307", "rtc-ds1307", "ds1307",},
+ {"dallas,ds1337", "rtc-ds1307", "ds1337",},
+ {"dallas,ds1338", "rtc-ds1307", "ds1338",},
+ {"dallas,ds1339", "rtc-ds1307", "ds1339",},
+ {"dallas,ds1340", "rtc-ds1307", "ds1340",},
+ {"stm,m41t00", "rtc-ds1307", "m41t00"},
+ {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
+};
+
+int __init of_fill_i2c_info(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;
+}
Index: 2.6.24/include/asm-powerpc/i2c_of.h
===================================================================
--- /dev/null
+++ 2.6.24/include/asm-powerpc/i2c_of.h
@@ -0,0 +1,14 @@
+/*
+ * Functions to map device tree compatible fields to values used by i2c
+ * board info structures
+ */
+
+#ifndef POWERPC_I2C_OF_H
+#define POWERPC_I2C_OF_H
+
+#ifdef CONFIG_I2C_BOARDINFO
+extern int __init of_fill_i2c_info(struct device_node *node,
+ struct i2c_board_info *info);
+#endif
+
+#endif
Index: 2.6.24/arch/powerpc/sysdev/fsl_soc.c
===================================================================
--- 2.6.24.orig/arch/powerpc/sysdev/fsl_soc.c
+++ 2.6.24/arch/powerpc/sysdev/fsl_soc.c
@@ -320,43 +320,7 @@ arch_initcall(gfar_of_init);
#ifdef CONFIG_I2C_BOARDINFO
#include <linux/i2c.h>
-struct i2c_driver_device {
- char *of_device;
- char *i2c_driver;
- char *i2c_type;
-};
-
-static struct i2c_driver_device i2c_devices[] __initdata = {
- {"ricoh,rs5c372a", "rtc-rs5c372", "rs5c372a",},
- {"ricoh,rs5c372b", "rtc-rs5c372", "rs5c372b",},
- {"ricoh,rv5c386", "rtc-rs5c372", "rv5c386",},
- {"ricoh,rv5c387a", "rtc-rs5c372", "rv5c387a",},
- {"dallas,ds1307", "rtc-ds1307", "ds1307",},
- {"dallas,ds1337", "rtc-ds1307", "ds1337",},
- {"dallas,ds1338", "rtc-ds1307", "ds1338",},
- {"dallas,ds1339", "rtc-ds1307", "ds1339",},
- {"dallas,ds1340", "rtc-ds1307", "ds1340",},
- {"stm,m41t00", "rtc-ds1307", "m41t00"},
- {"dallas,ds1374", "rtc-ds1374", "rtc-ds1374",},
-};
-
-static int __init of_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;
-}
+#include <asm/i2c_of.h>
static void __init of_register_i2c_devices(struct device_node *adap_node,
int bus_num)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info
2007-11-30 3:26 [PATCH 1/2] [POWERPC] Consolidate compatible-to-i2c_boardinfo mapping code Olof Johansson
@ 2007-11-30 3:29 ` Olof Johansson
2007-12-04 13:28 ` David Woodhouse
0 siblings, 1 reply; 6+ messages in thread
From: Olof Johansson @ 2007-11-30 3:29 UTC (permalink / raw)
To: linuxppc-dev
[POWERPC] pasemi: Register i2c_board_info
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: 2.6.24/arch/powerpc/platforms/pasemi/Makefile
===================================================================
--- 2.6.24.orig/arch/powerpc/platforms/pasemi/Makefile
+++ 2.6.24/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: 2.6.24/arch/powerpc/platforms/pasemi/misc.c
===================================================================
--- /dev/null
+++ 2.6.24/arch/powerpc/platforms/pasemi/misc.c
@@ -0,0 +1,66 @@
+/*
+ * 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>
+#include <asm/i2c_of.h>
+
+#ifdef CONFIG_I2C_BOARDINFO
+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 (of_fill_i2c_info(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] 6+ messages in thread
* Re: [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info
2007-11-30 3:29 ` [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info Olof Johansson
@ 2007-12-04 13:28 ` David Woodhouse
2007-12-04 19:32 ` Olof Johansson
0 siblings, 1 reply; 6+ messages in thread
From: David Woodhouse @ 2007-12-04 13:28 UTC (permalink / raw)
To: Olof Johansson; +Cc: linuxppc-dev
On Thu, 2007-11-29 at 21:29 -0600, Olof Johansson wrote:
> + continue;
> +
> + info.addr = *addr;
> +
> + i2c_register_board_info(PCI_FUNC(pdev->devfn),
> &info,
> + 1);
> + }
> + }
+ /* Ensure that buses up to 2 are reserved */
+ i2c_register_board_info(2, NULL, 0);
+
> + return 0;
> +}
> +device_initcall(pasemi_register_i2c_devices);
> +#endif
Otherwise when you make i2c-pasemi use i2c_add_numbered_adapter(), it
might fail to register the third bus -- because there were no devices
preregistered on it, so something else might have stolen that bus number
already.
You might want to add the patch to use i2c_add_numbered_adapter() to
your tree, btw.
--
dwmw2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info
2007-12-04 13:28 ` David Woodhouse
@ 2007-12-04 19:32 ` Olof Johansson
2007-12-05 0:41 ` Paul Mackerras
0 siblings, 1 reply; 6+ messages in thread
From: Olof Johansson @ 2007-12-04 19:32 UTC (permalink / raw)
To: David Woodhouse; +Cc: linuxppc-dev
On Tue, Dec 04, 2007 at 01:28:46PM +0000, David Woodhouse wrote:
>
> On Thu, 2007-11-29 at 21:29 -0600, Olof Johansson wrote:
> > + continue;
> > +
> > + info.addr = *addr;
> > +
> > + i2c_register_board_info(PCI_FUNC(pdev->devfn),
> > &info,
> > + 1);
> > + }
> > + }
>
> + /* Ensure that buses up to 2 are reserved */
> + i2c_register_board_info(2, NULL, 0);
> +
>
>
> > + return 0;
> > +}
> > +device_initcall(pasemi_register_i2c_devices);
> > +#endif
>
>
> Otherwise when you make i2c-pasemi use i2c_add_numbered_adapter(), it
> might fail to register the third bus -- because there were no devices
> preregistered on it, so something else might have stolen that bus number
> already.
Good point, I'd missed that. Thanks!
> You might want to add the patch to use i2c_add_numbered_adapter() to
> your tree, btw.
Yep, I realized that after (re)asking Paul to pull though, and didn't
want to do a third request before he's done it. :)
If he doesn't pull in the next few days I might just keep adding new
patches as they come in though, and add it back.
-Olof
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info
2007-12-04 19:32 ` Olof Johansson
@ 2007-12-05 0:41 ` Paul Mackerras
2007-12-05 2:09 ` Olof Johansson
0 siblings, 1 reply; 6+ messages in thread
From: Paul Mackerras @ 2007-12-05 0:41 UTC (permalink / raw)
To: Olof Johansson; +Cc: linuxppc-dev, David Woodhouse
Olof Johansson writes:
> Yep, I realized that after (re)asking Paul to pull though, and didn't
> want to do a third request before he's done it. :)
>
> If he doesn't pull in the next few days I might just keep adding new
> patches as they come in though, and add it back.
I haven't pulled yet; sounds like I need to wait a few more days
first. :)
Paul.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info
2007-12-05 0:41 ` Paul Mackerras
@ 2007-12-05 2:09 ` Olof Johansson
0 siblings, 0 replies; 6+ messages in thread
From: Olof Johansson @ 2007-12-05 2:09 UTC (permalink / raw)
To: Paul Mackerras; +Cc: linuxppc-dev, David Woodhouse
On Wed, Dec 05, 2007 at 11:41:50AM +1100, Paul Mackerras wrote:
> Olof Johansson writes:
>
> > Yep, I realized that after (re)asking Paul to pull though, and didn't
> > want to do a third request before he's done it. :)
> >
> > If he doesn't pull in the next few days I might just keep adding new
> > patches as they come in though, and add it back.
>
> I haven't pulled yet; sounds like I need to wait a few more days
> first. :)
Heh, nah, just pull now, I'll have more going in before 2.6.25 as but it's
good to get current contents into -mm sooner rather than later. :)
Thanks,
-Olof
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-12-05 2:05 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-30 3:26 [PATCH 1/2] [POWERPC] Consolidate compatible-to-i2c_boardinfo mapping code Olof Johansson
2007-11-30 3:29 ` [PATCH 2/2] [POWERPC] pasemi: Register i2c_board_info Olof Johansson
2007-12-04 13:28 ` David Woodhouse
2007-12-04 19:32 ` Olof Johansson
2007-12-05 0:41 ` Paul Mackerras
2007-12-05 2:09 ` Olof Johansson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.