diff options
Diffstat (limited to 'arch/powerpc/kernel/of_device.c')
-rw-r--r-- | arch/powerpc/kernel/of_device.c | 173 |
1 files changed, 28 insertions, 145 deletions
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c index 397c83eda20..8a06724e029 100644 --- a/arch/powerpc/kernel/of_device.c +++ b/arch/powerpc/kernel/of_device.c | |||
@@ -9,30 +9,26 @@ | |||
9 | #include <asm/of_device.h> | 9 | #include <asm/of_device.h> |
10 | 10 | ||
11 | /** | 11 | /** |
12 | * of_match_device - Tell if an of_device structure has a matching | 12 | * of_match_node - Tell if an device_node has a matching of_match structure |
13 | * of_match structure | ||
14 | * @ids: array of of device match structures to search in | 13 | * @ids: array of of device match structures to search in |
15 | * @dev: the of device structure to match against | 14 | * @node: the of device structure to match against |
16 | * | 15 | * |
17 | * Used by a driver to check whether an of_device present in the | 16 | * Low level utility function used by device matching. |
18 | * system is in its list of supported devices. | ||
19 | */ | 17 | */ |
20 | const struct of_device_id *of_match_device(const struct of_device_id *matches, | 18 | const struct of_device_id *of_match_node(const struct of_device_id *matches, |
21 | const struct of_device *dev) | 19 | const struct device_node *node) |
22 | { | 20 | { |
23 | if (!dev->node) | ||
24 | return NULL; | ||
25 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { | 21 | while (matches->name[0] || matches->type[0] || matches->compatible[0]) { |
26 | int match = 1; | 22 | int match = 1; |
27 | if (matches->name[0]) | 23 | if (matches->name[0]) |
28 | match &= dev->node->name | 24 | match &= node->name |
29 | && !strcmp(matches->name, dev->node->name); | 25 | && !strcmp(matches->name, node->name); |
30 | if (matches->type[0]) | 26 | if (matches->type[0]) |
31 | match &= dev->node->type | 27 | match &= node->type |
32 | && !strcmp(matches->type, dev->node->type); | 28 | && !strcmp(matches->type, node->type); |
33 | if (matches->compatible[0]) | 29 | if (matches->compatible[0]) |
34 | match &= device_is_compatible(dev->node, | 30 | match &= device_is_compatible(node, |
35 | matches->compatible); | 31 | matches->compatible); |
36 | if (match) | 32 | if (match) |
37 | return matches; | 33 | return matches; |
38 | matches++; | 34 | matches++; |
@@ -40,16 +36,21 @@ const struct of_device_id *of_match_device(const struct of_device_id *matches, | |||
40 | return NULL; | 36 | return NULL; |
41 | } | 37 | } |
42 | 38 | ||
43 | static int of_platform_bus_match(struct device *dev, struct device_driver *drv) | 39 | /** |
40 | * of_match_device - Tell if an of_device structure has a matching | ||
41 | * of_match structure | ||
42 | * @ids: array of of device match structures to search in | ||
43 | * @dev: the of device structure to match against | ||
44 | * | ||
45 | * Used by a driver to check whether an of_device present in the | ||
46 | * system is in its list of supported devices. | ||
47 | */ | ||
48 | const struct of_device_id *of_match_device(const struct of_device_id *matches, | ||
49 | const struct of_device *dev) | ||
44 | { | 50 | { |
45 | struct of_device * of_dev = to_of_device(dev); | 51 | if (!dev->node) |
46 | struct of_platform_driver * of_drv = to_of_platform_driver(drv); | 52 | return NULL; |
47 | const struct of_device_id * matches = of_drv->match_table; | 53 | return of_match_node(matches, dev->node); |
48 | |||
49 | if (!matches) | ||
50 | return 0; | ||
51 | |||
52 | return of_match_device(matches, of_dev) != NULL; | ||
53 | } | 54 | } |
54 | 55 | ||
55 | struct of_device *of_dev_get(struct of_device *dev) | 56 | struct of_device *of_dev_get(struct of_device *dev) |
@@ -71,96 +72,8 @@ void of_dev_put(struct of_device *dev) | |||
71 | put_device(&dev->dev); | 72 | put_device(&dev->dev); |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | static ssize_t dev_show_devspec(struct device *dev, | |
75 | static int of_device_probe(struct device *dev) | 76 | struct device_attribute *attr, char *buf) |
76 | { | ||
77 | int error = -ENODEV; | ||
78 | struct of_platform_driver *drv; | ||
79 | struct of_device *of_dev; | ||
80 | const struct of_device_id *match; | ||
81 | |||
82 | drv = to_of_platform_driver(dev->driver); | ||
83 | of_dev = to_of_device(dev); | ||
84 | |||
85 | if (!drv->probe) | ||
86 | return error; | ||
87 | |||
88 | of_dev_get(of_dev); | ||
89 | |||
90 | match = of_match_device(drv->match_table, of_dev); | ||
91 | if (match) | ||
92 | error = drv->probe(of_dev, match); | ||
93 | if (error) | ||
94 | of_dev_put(of_dev); | ||
95 | |||
96 | return error; | ||
97 | } | ||
98 | |||
99 | static int of_device_remove(struct device *dev) | ||
100 | { | ||
101 | struct of_device * of_dev = to_of_device(dev); | ||
102 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
103 | |||
104 | if (dev->driver && drv->remove) | ||
105 | drv->remove(of_dev); | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static int of_device_suspend(struct device *dev, pm_message_t state) | ||
110 | { | ||
111 | struct of_device * of_dev = to_of_device(dev); | ||
112 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
113 | int error = 0; | ||
114 | |||
115 | if (dev->driver && drv->suspend) | ||
116 | error = drv->suspend(of_dev, state); | ||
117 | return error; | ||
118 | } | ||
119 | |||
120 | static int of_device_resume(struct device * dev) | ||
121 | { | ||
122 | struct of_device * of_dev = to_of_device(dev); | ||
123 | struct of_platform_driver * drv = to_of_platform_driver(dev->driver); | ||
124 | int error = 0; | ||
125 | |||
126 | if (dev->driver && drv->resume) | ||
127 | error = drv->resume(of_dev); | ||
128 | return error; | ||
129 | } | ||
130 | |||
131 | struct bus_type of_platform_bus_type = { | ||
132 | .name = "of_platform", | ||
133 | .match = of_platform_bus_match, | ||
134 | .probe = of_device_probe, | ||
135 | .remove = of_device_remove, | ||
136 | .suspend = of_device_suspend, | ||
137 | .resume = of_device_resume, | ||
138 | }; | ||
139 | |||
140 | static int __init of_bus_driver_init(void) | ||
141 | { | ||
142 | return bus_register(&of_platform_bus_type); | ||
143 | } | ||
144 | |||
145 | postcore_initcall(of_bus_driver_init); | ||
146 | |||
147 | int of_register_driver(struct of_platform_driver *drv) | ||
148 | { | ||
149 | /* initialize common driver fields */ | ||
150 | drv->driver.name = drv->name; | ||
151 | drv->driver.bus = &of_platform_bus_type; | ||
152 | |||
153 | /* register with core */ | ||
154 | return driver_register(&drv->driver); | ||
155 | } | ||
156 | |||
157 | void of_unregister_driver(struct of_platform_driver *drv) | ||
158 | { | ||
159 | driver_unregister(&drv->driver); | ||
160 | } | ||
161 | |||
162 | |||
163 | static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) | ||
164 | { | 77 | { |
165 | struct of_device *ofdev; | 78 | struct of_device *ofdev; |
166 | 79 | ||
@@ -208,41 +121,11 @@ void of_device_unregister(struct of_device *ofdev) | |||
208 | device_unregister(&ofdev->dev); | 121 | device_unregister(&ofdev->dev); |
209 | } | 122 | } |
210 | 123 | ||
211 | struct of_device* of_platform_device_create(struct device_node *np, | ||
212 | const char *bus_id, | ||
213 | struct device *parent) | ||
214 | { | ||
215 | struct of_device *dev; | ||
216 | |||
217 | dev = kmalloc(sizeof(*dev), GFP_KERNEL); | ||
218 | if (!dev) | ||
219 | return NULL; | ||
220 | memset(dev, 0, sizeof(*dev)); | ||
221 | |||
222 | dev->node = of_node_get(np); | ||
223 | dev->dma_mask = 0xffffffffUL; | ||
224 | dev->dev.dma_mask = &dev->dma_mask; | ||
225 | dev->dev.parent = parent; | ||
226 | dev->dev.bus = &of_platform_bus_type; | ||
227 | dev->dev.release = of_release_dev; | ||
228 | |||
229 | strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE); | ||
230 | |||
231 | if (of_device_register(dev) != 0) { | ||
232 | kfree(dev); | ||
233 | return NULL; | ||
234 | } | ||
235 | |||
236 | return dev; | ||
237 | } | ||
238 | 124 | ||
125 | EXPORT_SYMBOL(of_match_node); | ||
239 | EXPORT_SYMBOL(of_match_device); | 126 | EXPORT_SYMBOL(of_match_device); |
240 | EXPORT_SYMBOL(of_platform_bus_type); | ||
241 | EXPORT_SYMBOL(of_register_driver); | ||
242 | EXPORT_SYMBOL(of_unregister_driver); | ||
243 | EXPORT_SYMBOL(of_device_register); | 127 | EXPORT_SYMBOL(of_device_register); |
244 | EXPORT_SYMBOL(of_device_unregister); | 128 | EXPORT_SYMBOL(of_device_unregister); |
245 | EXPORT_SYMBOL(of_dev_get); | 129 | EXPORT_SYMBOL(of_dev_get); |
246 | EXPORT_SYMBOL(of_dev_put); | 130 | EXPORT_SYMBOL(of_dev_put); |
247 | EXPORT_SYMBOL(of_platform_device_create); | ||
248 | EXPORT_SYMBOL(of_release_dev); | 131 | EXPORT_SYMBOL(of_release_dev); |