]>
Commit | Line | Data |
---|---|---|
55716d26 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
bbbf508d RK |
2 | /* |
3 | * platform_device.h - generic, centralized driver model | |
4 | * | |
5 | * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> | |
6 | * | |
fe34c89d | 7 | * See Documentation/driver-api/driver-model/ for more information. |
bbbf508d RK |
8 | */ |
9 | ||
10 | #ifndef _PLATFORM_DEVICE_H_ | |
11 | #define _PLATFORM_DEVICE_H_ | |
12 | ||
13 | #include <linux/device.h> | |
14 | ||
689ae231 JD |
15 | #define PLATFORM_DEVID_NONE (-1) |
16 | #define PLATFORM_DEVID_AUTO (-2) | |
17 | ||
e15f2fa9 | 18 | struct irq_affinity; |
e710d7d5 | 19 | struct mfd_cell; |
f4d05266 | 20 | struct property_entry; |
ac316725 | 21 | struct platform_device_id; |
e710d7d5 | 22 | |
bbbf508d | 23 | struct platform_device { |
6ae07f27 | 24 | const char *name; |
1359555e | 25 | int id; |
689ae231 | 26 | bool id_auto; |
bbbf508d | 27 | struct device dev; |
e3a36eb6 | 28 | u64 platform_dma_mask; |
9495b7e9 | 29 | struct device_dma_parameters dma_parms; |
bbbf508d | 30 | u32 num_resources; |
6ae07f27 | 31 | struct resource *resource; |
57fee4a5 | 32 | |
3d03ba4d | 33 | const struct platform_device_id *id_entry; |
3d713e0e | 34 | char *driver_override; /* Driver name to force a match */ |
d7aacadd | 35 | |
e710d7d5 SO |
36 | /* MFD cell pointer */ |
37 | struct mfd_cell *mfd_cell; | |
38 | ||
d7aacadd MD |
39 | /* arch specific additions */ |
40 | struct pdev_archdata archdata; | |
bbbf508d RK |
41 | }; |
42 | ||
57fee4a5 EM |
43 | #define platform_get_device_id(pdev) ((pdev)->id_entry) |
44 | ||
719cf71c | 45 | #define dev_is_platform(dev) ((dev)->bus == &platform_bus_type) |
bbbf508d RK |
46 | #define to_platform_device(x) container_of((x), struct platform_device, dev) |
47 | ||
48 | extern int platform_device_register(struct platform_device *); | |
49 | extern void platform_device_unregister(struct platform_device *); | |
50 | ||
51 | extern struct bus_type platform_bus_type; | |
52 | extern struct device platform_bus; | |
53 | ||
6ae07f27 FP |
54 | extern struct resource *platform_get_resource(struct platform_device *, |
55 | unsigned int, unsigned int); | |
0aec2da4 AS |
56 | extern struct resource *platform_get_mem_or_io(struct platform_device *, |
57 | unsigned int); | |
58 | ||
36f3313d SP |
59 | extern struct device * |
60 | platform_find_device_by_driver(struct device *start, | |
61 | const struct device_driver *drv); | |
7945f929 | 62 | extern void __iomem * |
890cc39a DZ |
63 | devm_platform_get_and_ioremap_resource(struct platform_device *pdev, |
64 | unsigned int index, struct resource **res); | |
65 | extern void __iomem * | |
7945f929 BG |
66 | devm_platform_ioremap_resource(struct platform_device *pdev, |
67 | unsigned int index); | |
bb6243b4 BG |
68 | extern void __iomem * |
69 | devm_platform_ioremap_resource_wc(struct platform_device *pdev, | |
70 | unsigned int index); | |
c9c8641d BG |
71 | extern void __iomem * |
72 | devm_platform_ioremap_resource_byname(struct platform_device *pdev, | |
73 | const char *name); | |
bbbf508d | 74 | extern int platform_get_irq(struct platform_device *, unsigned int); |
8973ea47 | 75 | extern int platform_get_irq_optional(struct platform_device *, unsigned int); |
4b83555d | 76 | extern int platform_irq_count(struct platform_device *); |
e15f2fa9 JG |
77 | extern 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); | |
6ae07f27 FP |
82 | extern struct resource *platform_get_resource_byname(struct platform_device *, |
83 | unsigned int, | |
84 | const char *); | |
c0afe7ba | 85 | extern int platform_get_irq_byname(struct platform_device *, const char *); |
f1da567f HG |
86 | extern int platform_get_irq_byname_optional(struct platform_device *dev, |
87 | const char *name); | |
bbbf508d RK |
88 | extern int platform_add_devices(struct platform_device **, int); |
89 | ||
01dcc60a UKK |
90 | struct platform_device_info { |
91 | struct device *parent; | |
ce793486 | 92 | struct fwnode_handle *fwnode; |
2c1ea6ab | 93 | bool of_node_reused; |
01dcc60a UKK |
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; | |
00bbc1d8 | 104 | |
469e1906 | 105 | const struct property_entry *properties; |
01dcc60a UKK |
106 | }; |
107 | extern struct platform_device *platform_device_register_full( | |
5a3072be | 108 | const struct platform_device_info *pdevinfo); |
01dcc60a UKK |
109 | |
110 | /** | |
111 | * platform_device_register_resndata - add a platform-level device with | |
112 | * resources and platform-specific data | |
113 | * | |
114 | * @parent: parent device for the device we're adding | |
115 | * @name: base name of the device we're adding | |
116 | * @id: instance id | |
117 | * @res: set of resources that needs to be allocated for the device | |
118 | * @num: number of resources | |
119 | * @data: platform specific data for this platform device | |
120 | * @size: size of platform specific data | |
121 | * | |
122 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
123 | */ | |
124 | static inline struct platform_device *platform_device_register_resndata( | |
44f28bde UKK |
125 | struct device *parent, const char *name, int id, |
126 | const struct resource *res, unsigned int num, | |
01dcc60a UKK |
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 | } | |
44f28bde UKK |
142 | |
143 | /** | |
144 | * platform_device_register_simple - add a platform-level device and its resources | |
145 | * @name: base name of the device we're adding | |
146 | * @id: instance id | |
147 | * @res: set of resources that needs to be allocated for the device | |
148 | * @num: number of resources | |
149 | * | |
150 | * This function creates a simple platform device that requires minimal | |
151 | * resource and memory management. Canned release function freeing memory | |
152 | * allocated for the device allows drivers using such devices to be | |
153 | * unloaded without waiting for the last reference to the device to be | |
154 | * dropped. | |
155 | * | |
156 | * This interface is primarily intended for use with legacy drivers which | |
157 | * probe hardware directly. Because such drivers create sysfs device nodes | |
158 | * themselves, rather than letting system infrastructure handle such device | |
159 | * enumeration tasks, they don't fully conform to the Linux driver model. | |
160 | * In particular, when such drivers are built as modules, they can't be | |
161 | * "hotplugged". | |
162 | * | |
163 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
164 | */ | |
165 | static 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 | * platform_device_register_data - add a platform-level device with platform-specific data | |
175 | * @parent: parent device for the device we're adding | |
176 | * @name: base name of the device we're adding | |
177 | * @id: instance id | |
178 | * @data: platform specific data for this platform device | |
179 | * @size: size of platform specific data | |
180 | * | |
181 | * This function creates a simple platform device that requires minimal | |
182 | * resource and memory management. Canned release function freeing memory | |
183 | * allocated for the device allows drivers using such devices to be | |
184 | * unloaded without waiting for the last reference to the device to be | |
185 | * dropped. | |
186 | * | |
187 | * Returns &struct platform_device pointer on success, or ERR_PTR() on error. | |
188 | */ | |
189 | static 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 | } | |
bbbf508d | 196 | |
1359555e | 197 | extern struct platform_device *platform_device_alloc(const char *name, int id); |
0b7f1a7e GU |
198 | extern int platform_device_add_resources(struct platform_device *pdev, |
199 | const struct resource *res, | |
200 | unsigned int num); | |
6ae07f27 FP |
201 | extern int platform_device_add_data(struct platform_device *pdev, |
202 | const void *data, size_t size); | |
00bbc1d8 | 203 | extern int platform_device_add_properties(struct platform_device *pdev, |
277036f0 | 204 | const struct property_entry *properties); |
37c12e74 | 205 | extern int platform_device_add(struct platform_device *pdev); |
93ce3061 | 206 | extern void platform_device_del(struct platform_device *pdev); |
37c12e74 RK |
207 | extern void platform_device_put(struct platform_device *pdev); |
208 | ||
00d3dcdd RK |
209 | struct 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; | |
831fad2f | 216 | const struct platform_device_id *id_table; |
3f9120b0 | 217 | bool prevent_deferred_probe; |
00d3dcdd RK |
218 | }; |
219 | ||
10dbc5e3 RH |
220 | #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \ |
221 | driver)) | |
222 | ||
9447057e LC |
223 | /* |
224 | * use a macro to avoid include chaining to get THIS_MODULE | |
225 | */ | |
226 | #define platform_driver_register(drv) \ | |
227 | __platform_driver_register(drv, THIS_MODULE) | |
228 | extern int __platform_driver_register(struct platform_driver *, | |
229 | struct module *); | |
00d3dcdd RK |
230 | extern void platform_driver_unregister(struct platform_driver *); |
231 | ||
c67334fb DB |
232 | /* non-hotpluggable platform devices may use this so that probe() and |
233 | * its support may live in __init sections, conserving runtime memory. | |
234 | */ | |
c3b50dc2 WS |
235 | #define platform_driver_probe(drv, probe) \ |
236 | __platform_driver_probe(drv, probe, THIS_MODULE) | |
237 | extern int __platform_driver_probe(struct platform_driver *driver, | |
238 | int (*probe)(struct platform_device *), struct module *module); | |
c67334fb | 239 | |
71d64290 MKB |
240 | static inline void *platform_get_drvdata(const struct platform_device *pdev) |
241 | { | |
242 | return dev_get_drvdata(&pdev->dev); | |
243 | } | |
244 | ||
6ae07f27 FP |
245 | static inline void platform_set_drvdata(struct platform_device *pdev, |
246 | void *data) | |
71d64290 MKB |
247 | { |
248 | dev_set_drvdata(&pdev->dev, data); | |
249 | } | |
00d3dcdd | 250 | |
940ab889 GL |
251 | /* module_platform_driver() - Helper macro for drivers that don't do |
252 | * anything special in module init/exit. This eliminates a lot of | |
253 | * boilerplate. Each module may only use this macro once, and | |
254 | * calling it replaces module_init() and module_exit() | |
255 | */ | |
256 | #define module_platform_driver(__platform_driver) \ | |
907d0ed1 LPC |
257 | module_driver(__platform_driver, platform_driver_register, \ |
258 | platform_driver_unregister) | |
940ab889 | 259 | |
f309d444 PG |
260 | /* builtin_platform_driver() - Helper macro for builtin drivers that |
261 | * don't do anything special in driver init. This eliminates some | |
262 | * boilerplate. Each driver may only use this macro once, and | |
263 | * calling it replaces device_initcall(). Note this is meant to be | |
264 | * a parallel of module_platform_driver() above, but w/o _exit stuff. | |
265 | */ | |
266 | #define builtin_platform_driver(__platform_driver) \ | |
267 | builtin_driver(__platform_driver, platform_driver_register) | |
268 | ||
bab734fc FP |
269 | /* module_platform_driver_probe() - Helper macro for drivers that don't do |
270 | * anything special in module init/exit. This eliminates a lot of | |
271 | * boilerplate. Each module may only use this macro once, and | |
272 | * calling it replaces module_init() and module_exit() | |
273 | */ | |
274 | #define module_platform_driver_probe(__platform_driver, __platform_probe) \ | |
275 | static int __init __platform_driver##_init(void) \ | |
276 | { \ | |
277 | return platform_driver_probe(&(__platform_driver), \ | |
278 | __platform_probe); \ | |
279 | } \ | |
280 | module_init(__platform_driver##_init); \ | |
281 | static void __exit __platform_driver##_exit(void) \ | |
282 | { \ | |
283 | platform_driver_unregister(&(__platform_driver)); \ | |
284 | } \ | |
285 | module_exit(__platform_driver##_exit); | |
286 | ||
f309d444 PG |
287 | /* builtin_platform_driver_probe() - Helper macro for drivers that don't do |
288 | * anything special in device init. This eliminates some boilerplate. Each | |
289 | * driver may only use this macro once, and using it replaces device_initcall. | |
290 | * This is meant to be a parallel of module_platform_driver_probe above, but | |
291 | * without the __exit parts. | |
292 | */ | |
293 | #define builtin_platform_driver_probe(__platform_driver, __platform_probe) \ | |
294 | static int __init __platform_driver##_init(void) \ | |
295 | { \ | |
296 | return platform_driver_probe(&(__platform_driver), \ | |
297 | __platform_probe); \ | |
298 | } \ | |
299 | device_initcall(__platform_driver##_init); \ | |
300 | ||
291f653a WS |
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) | |
303 | extern struct platform_device *__platform_create_bundle( | |
6ae07f27 FP |
304 | struct platform_driver *driver, int (*probe)(struct platform_device *), |
305 | struct resource *res, unsigned int n_res, | |
291f653a | 306 | const void *data, size_t size, struct module *module); |
ecdf6ceb | 307 | |
dbe2256d TR |
308 | int __platform_register_drivers(struct platform_driver * const *drivers, |
309 | unsigned int count, struct module *owner); | |
310 | void 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 | ||
69c9dd1e RW |
316 | #ifdef CONFIG_SUSPEND |
317 | extern int platform_pm_suspend(struct device *dev); | |
69c9dd1e | 318 | extern int platform_pm_resume(struct device *dev); |
69c9dd1e RW |
319 | #else |
320 | #define platform_pm_suspend NULL | |
321 | #define platform_pm_resume NULL | |
69c9dd1e RW |
322 | #endif |
323 | ||
324 | #ifdef CONFIG_HIBERNATE_CALLBACKS | |
325 | extern int platform_pm_freeze(struct device *dev); | |
69c9dd1e | 326 | extern int platform_pm_thaw(struct device *dev); |
69c9dd1e | 327 | extern int platform_pm_poweroff(struct device *dev); |
69c9dd1e | 328 | extern int platform_pm_restore(struct device *dev); |
69c9dd1e RW |
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 | |
69c9dd1e RW |
334 | #endif |
335 | ||
07397df2 NG |
336 | extern int platform_dma_configure(struct device *dev); |
337 | ||
69c9dd1e RW |
338 | #ifdef CONFIG_PM_SLEEP |
339 | #define USE_PLATFORM_PM_SLEEP_OPS \ | |
69c9dd1e RW |
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, \ | |
9b39e73d | 345 | .restore = platform_pm_restore, |
69c9dd1e RW |
346 | #else |
347 | #define USE_PLATFORM_PM_SLEEP_OPS | |
348 | #endif | |
349 | ||
507fd01d BG |
350 | #ifndef CONFIG_SUPERH |
351 | /* | |
352 | * REVISIT: This stub is needed for all non-SuperH users of early platform | |
353 | * drivers. It should go away once we introduce the new platform_device-based | |
354 | * early driver framework. | |
355 | */ | |
201e9109 | 356 | static inline int is_sh_early_platform_device(struct platform_device *pdev) |
507fd01d BG |
357 | { |
358 | return 0; | |
359 | } | |
360 | #endif /* CONFIG_SUPERH */ | |
361 | ||
1768289b AS |
362 | /* For now only SuperH uses it */ |
363 | void early_platform_cleanup(void); | |
364 | ||
bbbf508d | 365 | #endif /* _PLATFORM_DEVICE_H_ */ |