1
2
3
4
5
6
7
8
9
10#ifndef _PLATFORM_DEVICE_H_
11#define _PLATFORM_DEVICE_H_
12
13#include <linux/device.h>
14
15#define PLATFORM_DEVID_NONE (-1)
16#define PLATFORM_DEVID_AUTO (-2)
17
18struct irq_affinity;
19struct mfd_cell;
20struct property_entry;
21struct platform_device_id;
22
23struct platform_device {
24 const char *name;
25 int id;
26 bool id_auto;
27 struct device dev;
28 u64 platform_dma_mask;
29 struct device_dma_parameters dma_parms;
30 u32 num_resources;
31 struct resource *resource;
32
33 const struct platform_device_id *id_entry;
34 char *driver_override;
35
36
37 struct mfd_cell *mfd_cell;
38
39
40 struct pdev_archdata archdata;
41};
42
43#define platform_get_device_id(pdev) ((pdev)->id_entry)
44
45#define dev_is_platform(dev) ((dev)->bus == &platform_bus_type)
46#define to_platform_device(x) container_of((x), struct platform_device, dev)
47
48extern int platform_device_register(struct platform_device *);
49extern void platform_device_unregister(struct platform_device *);
50
51extern struct bus_type platform_bus_type;
52extern struct device platform_bus;
53
54extern struct resource *platform_get_resource(struct platform_device *,
55 unsigned int, unsigned int);
56extern struct resource *platform_get_mem_or_io(struct platform_device *,
57 unsigned int);
58
59extern struct device *
60platform_find_device_by_driver(struct device *start,
61 const struct device_driver *drv);
62extern void __iomem *
63devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
64 unsigned int index, struct resource **res);
65extern void __iomem *
66devm_platform_ioremap_resource(struct platform_device *pdev,
67 unsigned int index);
68extern void __iomem *
69devm_platform_ioremap_resource_wc(struct platform_device *pdev,
70 unsigned int index);
71extern void __iomem *
72devm_platform_ioremap_resource_byname(struct platform_device *pdev,
73 const char *name);
74extern int platform_get_irq(struct platform_device *, unsigned int);
75extern int platform_get_irq_optional(struct platform_device *, unsigned int);
76extern int platform_irq_count(struct platform_device *);
77extern int devm_platform_get_irqs_affinity(struct platform_device *dev,
78 struct irq_affinity *affd,
79 unsigned int minvec,
80 unsigned int maxvec,
81 int **irqs);
82extern struct resource *platform_get_resource_byname(struct platform_device *,
83 unsigned int,
84 const char *);
85extern int platform_get_irq_byname(struct platform_device *, const char *);
86extern int platform_get_irq_byname_optional(struct platform_device *dev,
87 const char *name);
88extern int platform_add_devices(struct platform_device **, int);
89
90struct platform_device_info {
91 struct device *parent;
92 struct fwnode_handle *fwnode;
93 bool of_node_reused;
94
95 const char *name;
96 int id;
97
98 const struct resource *res;
99 unsigned int num_res;
100
101 const void *data;
102 size_t size_data;
103 u64 dma_mask;
104
105 const struct property_entry *properties;
106};
107extern struct platform_device *platform_device_register_full(
108 const struct platform_device_info *pdevinfo);
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124static inline struct platform_device *platform_device_register_resndata(
125 struct device *parent, const char *name, int id,
126 const struct resource *res, unsigned int num,
127 const void *data, size_t size) {
128
129 struct platform_device_info pdevinfo = {
130 .parent = parent,
131 .name = name,
132 .id = id,
133 .res = res,
134 .num_res = num,
135 .data = data,
136 .size_data = size,
137 .dma_mask = 0,
138 };
139
140 return platform_device_register_full(&pdevinfo);
141}
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165static inline struct platform_device *platform_device_register_simple(
166 const char *name, int id,
167 const struct resource *res, unsigned int num)
168{
169 return platform_device_register_resndata(NULL, name, id,
170 res, num, NULL, 0);
171}
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189static inline struct platform_device *platform_device_register_data(
190 struct device *parent, const char *name, int id,
191 const void *data, size_t size)
192{
193 return platform_device_register_resndata(parent, name, id,
194 NULL, 0, data, size);
195}
196
197extern struct platform_device *platform_device_alloc(const char *name, int id);
198extern int platform_device_add_resources(struct platform_device *pdev,
199 const struct resource *res,
200 unsigned int num);
201extern int platform_device_add_data(struct platform_device *pdev,
202 const void *data, size_t size);
203extern int platform_device_add_properties(struct platform_device *pdev,
204 const struct property_entry *properties);
205extern int platform_device_add(struct platform_device *pdev);
206extern void platform_device_del(struct platform_device *pdev);
207extern void platform_device_put(struct platform_device *pdev);
208
209struct platform_driver {
210 int (*probe)(struct platform_device *);
211 int (*remove)(struct platform_device *);
212 void (*shutdown)(struct platform_device *);
213 int (*suspend)(struct platform_device *, pm_message_t state);
214 int (*resume)(struct platform_device *);
215 struct device_driver driver;
216 const struct platform_device_id *id_table;
217 bool prevent_deferred_probe;
218};
219
220#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
221 driver))
222
223
224
225
226#define platform_driver_register(drv) \
227 __platform_driver_register(drv, THIS_MODULE)
228extern int __platform_driver_register(struct platform_driver *,
229 struct module *);
230extern void platform_driver_unregister(struct platform_driver *);
231
232
233
234
235#define platform_driver_probe(drv, probe) \
236 __platform_driver_probe(drv, probe, THIS_MODULE)
237extern int __platform_driver_probe(struct platform_driver *driver,
238 int (*probe)(struct platform_device *), struct module *module);
239
240static inline void *platform_get_drvdata(const struct platform_device *pdev)
241{
242 return dev_get_drvdata(&pdev->dev);
243}
244
245static inline void platform_set_drvdata(struct platform_device *pdev,
246 void *data)
247{
248 dev_set_drvdata(&pdev->dev, data);
249}
250
251
252
253
254
255
256#define module_platform_driver(__platform_driver) \
257 module_driver(__platform_driver, platform_driver_register, \
258 platform_driver_unregister)
259
260
261
262
263
264
265
266#define builtin_platform_driver(__platform_driver) \
267 builtin_driver(__platform_driver, platform_driver_register)
268
269
270
271
272
273
274#define module_platform_driver_probe(__platform_driver, __platform_probe) \
275static int __init __platform_driver##_init(void) \
276{ \
277 return platform_driver_probe(&(__platform_driver), \
278 __platform_probe); \
279} \
280module_init(__platform_driver##_init); \
281static void __exit __platform_driver##_exit(void) \
282{ \
283 platform_driver_unregister(&(__platform_driver)); \
284} \
285module_exit(__platform_driver##_exit);
286
287
288
289
290
291
292
293#define builtin_platform_driver_probe(__platform_driver, __platform_probe) \
294static int __init __platform_driver##_init(void) \
295{ \
296 return platform_driver_probe(&(__platform_driver), \
297 __platform_probe); \
298} \
299device_initcall(__platform_driver##_init); \
300
301#define platform_create_bundle(driver, probe, res, n_res, data, size) \
302 __platform_create_bundle(driver, probe, res, n_res, data, size, THIS_MODULE)
303extern struct platform_device *__platform_create_bundle(
304 struct platform_driver *driver, int (*probe)(struct platform_device *),
305 struct resource *res, unsigned int n_res,
306 const void *data, size_t size, struct module *module);
307
308int __platform_register_drivers(struct platform_driver * const *drivers,
309 unsigned int count, struct module *owner);
310void platform_unregister_drivers(struct platform_driver * const *drivers,
311 unsigned int count);
312
313#define platform_register_drivers(drivers, count) \
314 __platform_register_drivers(drivers, count, THIS_MODULE)
315
316#ifdef CONFIG_SUSPEND
317extern int platform_pm_suspend(struct device *dev);
318extern int platform_pm_resume(struct device *dev);
319#else
320#define platform_pm_suspend NULL
321#define platform_pm_resume NULL
322#endif
323
324#ifdef CONFIG_HIBERNATE_CALLBACKS
325extern int platform_pm_freeze(struct device *dev);
326extern int platform_pm_thaw(struct device *dev);
327extern int platform_pm_poweroff(struct device *dev);
328extern int platform_pm_restore(struct device *dev);
329#else
330#define platform_pm_freeze NULL
331#define platform_pm_thaw NULL
332#define platform_pm_poweroff NULL
333#define platform_pm_restore NULL
334#endif
335
336extern int platform_dma_configure(struct device *dev);
337
338#ifdef CONFIG_PM_SLEEP
339#define USE_PLATFORM_PM_SLEEP_OPS \
340 .suspend = platform_pm_suspend, \
341 .resume = platform_pm_resume, \
342 .freeze = platform_pm_freeze, \
343 .thaw = platform_pm_thaw, \
344 .poweroff = platform_pm_poweroff, \
345 .restore = platform_pm_restore,
346#else
347#define USE_PLATFORM_PM_SLEEP_OPS
348#endif
349
350#ifndef CONFIG_SUPERH
351
352
353
354
355
356static inline int is_sh_early_platform_device(struct platform_device *pdev)
357{
358 return 0;
359}
360#endif
361
362#endif
363