diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-05-02 12:38:57 -0400 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-07-20 00:25:51 -0400 |
commit | 3f23de10f283819bcdc0d2282e8b5b14c2e96d3b (patch) | |
tree | 49c64fc622953e4ffc3af665bdc380fd37079e14 /arch | |
parent | b41912ca345e6de8ec8469d57cd585881271e2b9 (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')
-rw-r--r-- | arch/powerpc/kernel/of_platform.c | 82 | ||||
-rw-r--r-- | arch/sparc/kernel/of_device.c | 107 | ||||
-rw-r--r-- | arch/sparc64/kernel/of_device.c | 118 |
3 files changed, 21 insertions, 286 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 | ||
56 | static atomic_t bus_no_reg_magic; | 56 | static atomic_t bus_no_reg_magic; |
57 | 57 | ||
58 | /* | ||
59 | * | ||
60 | * OF platform device type definition & base infrastructure | ||
61 | * | ||
62 | */ | ||
63 | |||
64 | static 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 | |||
76 | static 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 | |||
100 | static 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 | |||
110 | static 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 | |||
121 | static 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 | |||
132 | struct bus_type of_platform_bus_type = { | 58 | struct 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 | }; |
141 | EXPORT_SYMBOL(of_platform_bus_type); | 61 | EXPORT_SYMBOL(of_platform_bus_type); |
142 | 62 | ||
143 | static int __init of_bus_driver_init(void) | 63 | static 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 | ||
148 | postcore_initcall(of_bus_driver_init); | 68 | postcore_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 | |||
12 | static 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 | |||
24 | static 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 | |||
48 | static 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 | |||
58 | static 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 | |||
69 | static 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 | ||
80 | static int node_match(struct device *dev, void *data) | 12 | static 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) | |||
98 | EXPORT_SYMBOL(of_find_device_by_node); | 30 | EXPORT_SYMBOL(of_find_device_by_node); |
99 | 31 | ||
100 | #ifdef CONFIG_PCI | 32 | #ifdef CONFIG_PCI |
101 | struct bus_type ebus_bus_type = { | 33 | struct 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 | }; | ||
109 | EXPORT_SYMBOL(ebus_bus_type); | 34 | EXPORT_SYMBOL(ebus_bus_type); |
110 | #endif | 35 | #endif |
111 | 36 | ||
112 | #ifdef CONFIG_SBUS | 37 | #ifdef CONFIG_SBUS |
113 | struct bus_type sbus_bus_type = { | 38 | struct 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 | }; | ||
121 | EXPORT_SYMBOL(sbus_bus_type); | 39 | EXPORT_SYMBOL(sbus_bus_type); |
122 | #endif | 40 | #endif |
123 | 41 | ||
124 | struct bus_type of_platform_bus_type = { | 42 | struct 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 | }; | ||
132 | EXPORT_SYMBOL(of_platform_bus_type); | 43 | EXPORT_SYMBOL(of_platform_bus_type); |
133 | 44 | ||
134 | static inline u64 of_read_addr(const u32 *cell, int size) | 45 | static 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 | |||
12 | static 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 | |||
24 | static 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 | |||
48 | static 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 | |||
58 | static 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 | |||
69 | static 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 | ||
80 | void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name) | 12 | void __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) | |||
123 | EXPORT_SYMBOL(of_find_device_by_node); | 55 | EXPORT_SYMBOL(of_find_device_by_node); |
124 | 56 | ||
125 | #ifdef CONFIG_PCI | 57 | #ifdef CONFIG_PCI |
126 | struct bus_type isa_bus_type = { | 58 | struct 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 | }; | ||
134 | EXPORT_SYMBOL(isa_bus_type); | 59 | EXPORT_SYMBOL(isa_bus_type); |
135 | 60 | ||
136 | struct bus_type ebus_bus_type = { | 61 | struct 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 | }; | ||
144 | EXPORT_SYMBOL(ebus_bus_type); | 62 | EXPORT_SYMBOL(ebus_bus_type); |
145 | #endif | 63 | #endif |
146 | 64 | ||
147 | #ifdef CONFIG_SBUS | 65 | #ifdef CONFIG_SBUS |
148 | struct bus_type sbus_bus_type = { | 66 | struct 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 | }; | ||
156 | EXPORT_SYMBOL(sbus_bus_type); | 67 | EXPORT_SYMBOL(sbus_bus_type); |
157 | #endif | 68 | #endif |
158 | 69 | ||
159 | struct bus_type of_platform_bus_type = { | 70 | struct 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 | }; | ||
167 | EXPORT_SYMBOL(of_platform_bus_type); | 71 | EXPORT_SYMBOL(of_platform_bus_type); |
168 | 72 | ||
169 | static inline u64 of_read_addr(const u32 *cell, int size) | 73 | static 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) |