aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2008-02-20 21:25:54 -0500
committerPaul Mackerras <paulus@samba.org>2008-02-21 05:08:35 -0500
commitbe2553ffb5773e9a689c94bb85326c5b5f00577f (patch)
treeed0af15d0d72bcf50867359165d46da3c9ff4c0c /arch
parent3d5d27c40fb38a51eae96a55f51b5a306ed3668d (diff)
[POWERPC] pasemi: Register i2c devices at boot
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> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/platforms/pasemi/Makefile2
-rw-r--r--arch/powerpc/platforms/pasemi/misc.c97
2 files changed, 98 insertions, 1 deletions
diff --git a/arch/powerpc/platforms/pasemi/Makefile b/arch/powerpc/platforms/pasemi/Makefile
index 8f52d7515793..ce6d789e0741 100644
--- a/arch/powerpc/platforms/pasemi/Makefile
+++ b/arch/powerpc/platforms/pasemi/Makefile
@@ -1,3 +1,3 @@
1obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o dma_lib.o 1obj-y += setup.o pci.o time.o idle.o powersave.o iommu.o dma_lib.o misc.o
2obj-$(CONFIG_PPC_PASEMI_MDIO) += gpio_mdio.o 2obj-$(CONFIG_PPC_PASEMI_MDIO) += gpio_mdio.o
3obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o 3obj-$(CONFIG_PPC_PASEMI_CPUFREQ) += cpufreq.o
diff --git a/arch/powerpc/platforms/pasemi/misc.c b/arch/powerpc/platforms/pasemi/misc.c
new file mode 100644
index 000000000000..ded7d152d00c
--- /dev/null
+++ b/arch/powerpc/platforms/pasemi/misc.c
@@ -0,0 +1,97 @@
1/*
2 * Copyright (C) 2007 PA Semi, Inc
3 *
4 * Parts based on arch/powerpc/sysdev/fsl_soc.c:
5 *
6 * 2006 (c) MontaVista Software, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/pci.h>
17#include <linux/of.h>
18#include <linux/i2c.h>
19
20#ifdef CONFIG_I2C_BOARDINFO
21/* The below is from fsl_soc.c. It's copied because since there are no
22 * official bus bindings at this time it doesn't make sense to share across
23 * the platforms, even though they happen to be common.
24 */
25struct i2c_driver_device {
26 char *of_device;
27 char *i2c_driver;
28 char *i2c_type;
29};
30
31static struct i2c_driver_device i2c_devices[] __initdata = {
32 {"dallas,ds1338", "rtc-ds1307", "ds1338"},
33};
34
35static int __init find_i2c_driver(struct device_node *node,
36 struct i2c_board_info *info)
37{
38 int i;
39
40 for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {
41 if (!of_device_is_compatible(node, i2c_devices[i].of_device))
42 continue;
43 if (strlcpy(info->driver_name, i2c_devices[i].i2c_driver,
44 KOBJ_NAME_LEN) >= KOBJ_NAME_LEN ||
45 strlcpy(info->type, i2c_devices[i].i2c_type,
46 I2C_NAME_SIZE) >= I2C_NAME_SIZE)
47 return -ENOMEM;
48 return 0;
49 }
50 return -ENODEV;
51}
52
53static int __init pasemi_register_i2c_devices(void)
54{
55 struct pci_dev *pdev;
56 struct device_node *adap_node;
57 struct device_node *node;
58
59 pdev = NULL;
60 while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {
61 adap_node = pci_device_to_OF_node(pdev);
62
63 if (!adap_node)
64 continue;
65
66 node = NULL;
67 while ((node = of_get_next_child(adap_node, node))) {
68 struct i2c_board_info info = {};
69 const u32 *addr;
70 int len;
71
72 addr = of_get_property(node, "reg", &len);
73 if (!addr || len < sizeof(int) ||
74 *addr > (1 << 10) - 1) {
75 printk(KERN_WARNING
76 "pasemi_register_i2c_devices: "
77 "invalid i2c device entry\n");
78 continue;
79 }
80
81 info.irq = irq_of_parse_and_map(node, 0);
82 if (info.irq == NO_IRQ)
83 info.irq = -1;
84
85 if (find_i2c_driver(node, &info) < 0)
86 continue;
87
88 info.addr = *addr;
89
90 i2c_register_board_info(PCI_FUNC(pdev->devfn), &info,
91 1);
92 }
93 }
94 return 0;
95}
96device_initcall(pasemi_register_i2c_devices);
97#endif