aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel/of_device.c
diff options
context:
space:
mode:
authorStephen Rothwell <sfr@canb.auug.org.au>2007-05-02 12:38:57 -0400
committerStephen Rothwell <sfr@canb.auug.org.au>2007-07-20 00:25:51 -0400
commit3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (patch)
tree49c64fc622953e4ffc3af665bdc380fd37079e14 /arch/sparc64/kernel/of_device.c
parentb41912ca345e6de8ec8469d57cd585881271e2b9 (diff)
Create drivers/of/platform.c
and populate it with the common parts from PowerPC and Sparc[64]. Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Paul Mackerras <paulus@samba.org> Acked-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc64/kernel/of_device.c')
-rw-r--r--arch/sparc64/kernel/of_device.c118
1 files changed, 11 insertions, 107 deletions
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index 485f8579899a..7b0dce9604ee 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -5,77 +5,9 @@
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8 8#include <linux/errno.h>
9#include <asm/errno.h> 9#include <linux/of_device.h>
10#include <asm/of_device.h> 10#include <linux/of_platform.h>
11
12static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
13{
14 struct of_device * of_dev = to_of_device(dev);
15 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
16 const struct of_device_id * matches = of_drv->match_table;
17
18 if (!matches)
19 return 0;
20
21 return of_match_device(matches, of_dev) != NULL;
22}
23
24static int of_platform_device_probe(struct device *dev)
25{
26 int error = -ENODEV;
27 struct of_platform_driver *drv;
28 struct of_device *of_dev;
29 const struct of_device_id *match;
30
31 drv = to_of_platform_driver(dev->driver);
32 of_dev = to_of_device(dev);
33
34 if (!drv->probe)
35 return error;
36
37 of_dev_get(of_dev);
38
39 match = of_match_device(drv->match_table, of_dev);
40 if (match)
41 error = drv->probe(of_dev, match);
42 if (error)
43 of_dev_put(of_dev);
44
45 return error;
46}
47
48static int of_platform_device_remove(struct device *dev)
49{
50 struct of_device * of_dev = to_of_device(dev);
51 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
52
53 if (dev->driver && drv->remove)
54 drv->remove(of_dev);
55 return 0;
56}
57
58static int of_platform_device_suspend(struct device *dev, pm_message_t state)
59{
60 struct of_device * of_dev = to_of_device(dev);
61 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
62 int error = 0;
63
64 if (dev->driver && drv->suspend)
65 error = drv->suspend(of_dev, state);
66 return error;
67}
68
69static int of_platform_device_resume(struct device * dev)
70{
71 struct of_device * of_dev = to_of_device(dev);
72 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
73 int error = 0;
74
75 if (dev->driver && drv->resume)
76 error = drv->resume(of_dev);
77 return error;
78}
79 11
80void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name) 12void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name)
81{ 13{
@@ -123,47 +55,19 @@ struct of_device *of_find_device_by_node(struct device_node *dp)
123EXPORT_SYMBOL(of_find_device_by_node); 55EXPORT_SYMBOL(of_find_device_by_node);
124 56
125#ifdef CONFIG_PCI 57#ifdef CONFIG_PCI
126struct bus_type isa_bus_type = { 58struct bus_type isa_bus_type;
127 .name = "isa",
128 .match = of_platform_bus_match,
129 .probe = of_platform_device_probe,
130 .remove = of_platform_device_remove,
131 .suspend = of_platform_device_suspend,
132 .resume = of_platform_device_resume,
133};
134EXPORT_SYMBOL(isa_bus_type); 59EXPORT_SYMBOL(isa_bus_type);
135 60
136struct bus_type ebus_bus_type = { 61struct bus_type ebus_bus_type;
137 .name = "ebus",
138 .match = of_platform_bus_match,
139 .probe = of_platform_device_probe,
140 .remove = of_platform_device_remove,
141 .suspend = of_platform_device_suspend,
142 .resume = of_platform_device_resume,
143};
144EXPORT_SYMBOL(ebus_bus_type); 62EXPORT_SYMBOL(ebus_bus_type);
145#endif 63#endif
146 64
147#ifdef CONFIG_SBUS 65#ifdef CONFIG_SBUS
148struct bus_type sbus_bus_type = { 66struct bus_type sbus_bus_type;
149 .name = "sbus",
150 .match = of_platform_bus_match,
151 .probe = of_platform_device_probe,
152 .remove = of_platform_device_remove,
153 .suspend = of_platform_device_suspend,
154 .resume = of_platform_device_resume,
155};
156EXPORT_SYMBOL(sbus_bus_type); 67EXPORT_SYMBOL(sbus_bus_type);
157#endif 68#endif
158 69
159struct bus_type of_platform_bus_type = { 70struct bus_type of_platform_bus_type;
160 .name = "of",
161 .match = of_platform_bus_match,
162 .probe = of_platform_device_probe,
163 .remove = of_platform_device_remove,
164 .suspend = of_platform_device_suspend,
165 .resume = of_platform_device_resume,
166};
167EXPORT_SYMBOL(of_platform_bus_type); 71EXPORT_SYMBOL(of_platform_bus_type);
168 72
169static inline u64 of_read_addr(const u32 *cell, int size) 73static inline u64 of_read_addr(const u32 *cell, int size)
@@ -926,16 +830,16 @@ static int __init of_bus_driver_init(void)
926{ 830{
927 int err; 831 int err;
928 832
929 err = bus_register(&of_platform_bus_type); 833 err = of_bus_type_init(&of_platform_bus_type, "of");
930#ifdef CONFIG_PCI 834#ifdef CONFIG_PCI
931 if (!err) 835 if (!err)
932 err = bus_register(&isa_bus_type); 836 err = of_bus_type_init(&isa_bus_type, "isa");
933 if (!err) 837 if (!err)
934 err = bus_register(&ebus_bus_type); 838 err = of_bus_type_init(&ebus_bus_type, "ebus");
935#endif 839#endif
936#ifdef CONFIG_SBUS 840#ifdef CONFIG_SBUS
937 if (!err) 841 if (!err)
938 err = bus_register(&sbus_bus_type); 842 err = of_bus_type_init(&sbus_bus_type, "sbus");
939#endif 843#endif
940 844
941 if (!err) 845 if (!err)