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