aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--arch/powerpc/kernel/of_platform.c82
-rw-r--r--arch/sparc/kernel/of_device.c107
-rw-r--r--arch/sparc64/kernel/of_device.c118
-rw-r--r--drivers/of/Makefile2
-rw-r--r--drivers/of/platform.c96
-rw-r--r--include/linux/of_platform.h2
6 files changed, 120 insertions, 287 deletions
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index 8ded4e7dc87e..f70e787d556f 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -55,94 +55,14 @@ static struct of_device_id of_default_bus_ids[] = {
55 55
56static atomic_t bus_no_reg_magic; 56static atomic_t bus_no_reg_magic;
57 57
58/*
59 *
60 * OF platform device type definition & base infrastructure
61 *
62 */
63
64static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
65{
66 struct of_device * of_dev = to_of_device(dev);
67 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
68 const struct of_device_id * matches = of_drv->match_table;
69
70 if (!matches)
71 return 0;
72
73 return of_match_device(matches, of_dev) != NULL;
74}
75
76static int of_platform_device_probe(struct device *dev)
77{
78 int error = -ENODEV;
79 struct of_platform_driver *drv;
80 struct of_device *of_dev;
81 const struct of_device_id *match;
82
83 drv = to_of_platform_driver(dev->driver);
84 of_dev = to_of_device(dev);
85
86 if (!drv->probe)
87 return error;
88
89 of_dev_get(of_dev);
90
91 match = of_match_device(drv->match_table, of_dev);
92 if (match)
93 error = drv->probe(of_dev, match);
94 if (error)
95 of_dev_put(of_dev);
96
97 return error;
98}
99
100static int of_platform_device_remove(struct device *dev)
101{
102 struct of_device * of_dev = to_of_device(dev);
103 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
104
105 if (dev->driver && drv->remove)
106 drv->remove(of_dev);
107 return 0;
108}
109
110static int of_platform_device_suspend(struct device *dev, pm_message_t state)
111{
112 struct of_device * of_dev = to_of_device(dev);
113 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
114 int error = 0;
115
116 if (dev->driver && drv->suspend)
117 error = drv->suspend(of_dev, state);
118 return error;
119}
120
121static int of_platform_device_resume(struct device * dev)
122{
123 struct of_device * of_dev = to_of_device(dev);
124 struct of_platform_driver * drv = to_of_platform_driver(dev->driver);
125 int error = 0;
126
127 if (dev->driver && drv->resume)
128 error = drv->resume(of_dev);
129 return error;
130}
131
132struct bus_type of_platform_bus_type = { 58struct bus_type of_platform_bus_type = {
133 .name = "of_platform",
134 .match = of_platform_bus_match,
135 .uevent = of_device_uevent, 59 .uevent = of_device_uevent,
136 .probe = of_platform_device_probe,
137 .remove = of_platform_device_remove,
138 .suspend = of_platform_device_suspend,
139 .resume = of_platform_device_resume,
140}; 60};
141EXPORT_SYMBOL(of_platform_bus_type); 61EXPORT_SYMBOL(of_platform_bus_type);
142 62
143static int __init of_bus_driver_init(void) 63static int __init of_bus_driver_init(void)
144{ 64{
145 return bus_register(&of_platform_bus_type); 65 return of_bus_type_init(&of_platform_bus_type, "of_platform");
146} 66}
147 67
148postcore_initcall(of_bus_driver_init); 68postcore_initcall(of_bus_driver_init);
diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c
index cb21983cff9f..7176040caba0 100644
--- a/arch/sparc/kernel/of_device.c
+++ b/arch/sparc/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
80static int node_match(struct device *dev, void *data) 12static int node_match(struct device *dev, void *data)
81{ 13{
@@ -98,37 +30,16 @@ struct of_device *of_find_device_by_node(struct device_node *dp)
98EXPORT_SYMBOL(of_find_device_by_node); 30EXPORT_SYMBOL(of_find_device_by_node);
99 31
100#ifdef CONFIG_PCI 32#ifdef CONFIG_PCI
101struct bus_type ebus_bus_type = { 33struct bus_type ebus_bus_type;
102 .name = "ebus",
103 .match = of_platform_bus_match,
104 .probe = of_platform_device_probe,
105 .remove = of_platform_device_remove,
106 .suspend = of_platform_device_suspend,
107 .resume = of_platform_device_resume,
108};
109EXPORT_SYMBOL(ebus_bus_type); 34EXPORT_SYMBOL(ebus_bus_type);
110#endif 35#endif
111 36
112#ifdef CONFIG_SBUS 37#ifdef CONFIG_SBUS
113struct bus_type sbus_bus_type = { 38struct bus_type sbus_bus_type;
114 .name = "sbus",
115 .match = of_platform_bus_match,
116 .probe = of_platform_device_probe,
117 .remove = of_platform_device_remove,
118 .suspend = of_platform_device_suspend,
119 .resume = of_platform_device_resume,
120};
121EXPORT_SYMBOL(sbus_bus_type); 39EXPORT_SYMBOL(sbus_bus_type);
122#endif 40#endif
123 41
124struct bus_type of_platform_bus_type = { 42struct bus_type of_platform_bus_type;
125 .name = "of",
126 .match = of_platform_bus_match,
127 .probe = of_platform_device_probe,
128 .remove = of_platform_device_remove,
129 .suspend = of_platform_device_suspend,
130 .resume = of_platform_device_resume,
131};
132EXPORT_SYMBOL(of_platform_bus_type); 43EXPORT_SYMBOL(of_platform_bus_type);
133 44
134static inline u64 of_read_addr(const u32 *cell, int size) 45static inline u64 of_read_addr(const u32 *cell, int size)
@@ -639,14 +550,14 @@ static int __init of_bus_driver_init(void)
639{ 550{
640 int err; 551 int err;
641 552
642 err = bus_register(&of_platform_bus_type); 553 err = of_bus_type_init(&of_platform_bus_type, "of");
643#ifdef CONFIG_PCI 554#ifdef CONFIG_PCI
644 if (!err) 555 if (!err)
645 err = bus_register(&ebus_bus_type); 556 err = of_bus_type_init(&ebus_bus_type, "ebus");
646#endif 557#endif
647#ifdef CONFIG_SBUS 558#ifdef CONFIG_SBUS
648 if (!err) 559 if (!err)
649 err = bus_register(&sbus_bus_type); 560 err = of_bus_type_init(&sbus_bus_type, "sbus");
650#endif 561#endif
651 562
652 if (!err) 563 if (!err)
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)
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index c46d998e367b..ab9be5d5255b 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,2 +1,2 @@
1obj-y = base.o 1obj-y = base.o
2obj-$(CONFIG_OF_DEVICE) += device.o 2obj-$(CONFIG_OF_DEVICE) += device.o platform.o
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
new file mode 100644
index 000000000000..864f09fd9f86
--- /dev/null
+++ b/drivers/of/platform.c
@@ -0,0 +1,96 @@
1/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org>
4 * and Arnd Bergmann, IBM Corp.
5 * Merged from powerpc/kernel/of_platform.c and
6 * sparc{,64}/kernel/of_device.c by Stephen Rothwell
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 */
14#include <linux/errno.h>
15#include <linux/device.h>
16#include <linux/of_device.h>
17#include <linux/of_platform.h>
18
19static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
20{
21 struct of_device *of_dev = to_of_device(dev);
22 struct of_platform_driver *of_drv = to_of_platform_driver(drv);
23 const struct of_device_id *matches = of_drv->match_table;
24
25 if (!matches)
26 return 0;
27
28 return of_match_device(matches, of_dev) != NULL;
29}
30
31static int of_platform_device_probe(struct device *dev)
32{
33 int error = -ENODEV;
34 struct of_platform_driver *drv;
35 struct of_device *of_dev;
36 const struct of_device_id *match;
37
38 drv = to_of_platform_driver(dev->driver);
39 of_dev = to_of_device(dev);
40
41 if (!drv->probe)
42 return error;
43
44 of_dev_get(of_dev);
45
46 match = of_match_device(drv->match_table, of_dev);
47 if (match)
48 error = drv->probe(of_dev, match);
49 if (error)
50 of_dev_put(of_dev);
51
52 return error;
53}
54
55static int of_platform_device_remove(struct device *dev)
56{
57 struct of_device *of_dev = to_of_device(dev);
58 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
59
60 if (dev->driver && drv->remove)
61 drv->remove(of_dev);
62 return 0;
63}
64
65static int of_platform_device_suspend(struct device *dev, pm_message_t state)
66{
67 struct of_device *of_dev = to_of_device(dev);
68 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
69 int error = 0;
70
71 if (dev->driver && drv->suspend)
72 error = drv->suspend(of_dev, state);
73 return error;
74}
75
76static int of_platform_device_resume(struct device * dev)
77{
78 struct of_device *of_dev = to_of_device(dev);
79 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
80 int error = 0;
81
82 if (dev->driver && drv->resume)
83 error = drv->resume(of_dev);
84 return error;
85}
86
87int of_bus_type_init(struct bus_type *bus, const char *name)
88{
89 bus->name = name;
90 bus->match = of_platform_bus_match;
91 bus->probe = of_platform_device_probe;
92 bus->remove = of_platform_device_remove;
93 bus->suspend = of_platform_device_suspend;
94 bus->resume = of_platform_device_resume;
95 return bus_register(bus);
96}
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index c85d0f835783..5fd44e63fb26 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -52,4 +52,6 @@ struct of_platform_driver
52 52
53extern struct of_device *of_find_device_by_node(struct device_node *np); 53extern struct of_device *of_find_device_by_node(struct device_node *np);
54 54
55extern int of_bus_type_init(struct bus_type *bus, const char *name);
56
55#endif /* _LINUX_OF_PLATFORM_H */ 57#endif /* _LINUX_OF_PLATFORM_H */