Commit | Line | Data |
---|---|---|
af6074fc | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
b41912ca SR |
2 | #ifndef _LINUX_OF_PLATFORM_H |
3 | #define _LINUX_OF_PLATFORM_H | |
4 | /* | |
5 | * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. | |
6 | * <benh@kernel.crashing.org> | |
b41912ca SR |
7 | */ |
8 | ||
b41912ca SR |
9 | #include <linux/device.h> |
10 | #include <linux/mod_devicetable.h> | |
11 | #include <linux/pm.h> | |
12 | #include <linux/of_device.h> | |
eca39301 | 13 | #include <linux/platform_device.h> |
b41912ca | 14 | |
15c3597d GL |
15 | /** |
16 | * struct of_dev_auxdata - lookup table entry for device names & platform_data | |
17 | * @compatible: compatible value of node to match against node | |
18 | * @phys_addr: Start address of registers to match against node | |
19 | * @name: Name to assign for matching nodes | |
20 | * @platform_data: platform_data to assign for matching nodes | |
21 | * | |
22 | * This lookup table allows the caller of of_platform_populate() to override | |
23 | * the names of devices when creating devices from the device tree. The table | |
24 | * should be terminated with an empty entry. It also allows the platform_data | |
25 | * pointer to be set. | |
26 | * | |
27 | * The reason for this functionality is that some Linux infrastructure uses | |
28 | * the device name to look up a specific device, but the Linux-specific names | |
29 | * are not encoded into the device tree, so the kernel needs to provide specific | |
30 | * values. | |
31 | * | |
32 | * Note: Using an auxdata lookup table should be considered a last resort when | |
33 | * converting a platform to use the DT. Normally the automatically generated | |
34 | * device name will not matter, and drivers should obtain data from the device | |
8c1eb253 | 35 | * node instead of from an anonymous platform_data pointer. |
15c3597d GL |
36 | */ |
37 | struct of_dev_auxdata { | |
38 | char *compatible; | |
39 | resource_size_t phys_addr; | |
40 | char *name; | |
41 | void *platform_data; | |
42 | }; | |
43 | ||
44 | /* Macro to simplify populating a lookup table */ | |
45 | #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \ | |
46 | { .compatible = _compat, .phys_addr = _phys, .name = _name, \ | |
47 | .platform_data = _pdata } | |
48 | ||
cbb49c26 GL |
49 | extern const struct of_device_id of_default_bus_match_table[]; |
50 | ||
0763ed23 | 51 | /* Platform drivers register/unregister */ |
94a0cb1f | 52 | extern struct platform_device *of_device_alloc(struct device_node *np, |
94c09319 GL |
53 | const char *bus_id, |
54 | struct device *parent); | |
aa767cfb | 55 | #ifdef CONFIG_OF |
94a0cb1f | 56 | extern struct platform_device *of_find_device_by_node(struct device_node *np); |
aa767cfb AB |
57 | #else |
58 | static inline struct platform_device *of_find_device_by_node(struct device_node *np) | |
59 | { | |
60 | return NULL; | |
61 | } | |
62 | #endif | |
b41912ca | 63 | |
620e8e8b MK |
64 | extern int of_platform_bus_probe(struct device_node *root, |
65 | const struct of_device_id *matches, | |
66 | struct device *parent); | |
67 | ||
68 | #ifdef CONFIG_OF_ADDRESS | |
5fd200f3 | 69 | /* Platform devices and busses creation */ |
94a0cb1f | 70 | extern struct platform_device *of_platform_device_create(struct device_node *np, |
5fd200f3 GL |
71 | const char *bus_id, |
72 | struct device *parent); | |
73 | ||
c2372c20 | 74 | extern int of_platform_device_destroy(struct device *dev, void *data); |
620e8e8b | 75 | |
29d4f8a4 GL |
76 | extern int of_platform_populate(struct device_node *root, |
77 | const struct of_device_id *matches, | |
15c3597d | 78 | const struct of_dev_auxdata *lookup, |
29d4f8a4 | 79 | struct device *parent); |
43443ad6 HM |
80 | extern int of_platform_default_populate(struct device_node *root, |
81 | const struct of_dev_auxdata *lookup, | |
82 | struct device *parent); | |
75f353b6 | 83 | extern void of_platform_depopulate(struct device *parent); |
38b0b219 BG |
84 | |
85 | extern int devm_of_platform_populate(struct device *dev); | |
86 | ||
87 | extern void devm_of_platform_depopulate(struct device *dev); | |
8a46f4f7 | 88 | #else |
620e8e8b MK |
89 | /* Platform devices and busses creation */ |
90 | static inline struct platform_device *of_platform_device_create(struct device_node *np, | |
91 | const char *bus_id, | |
92 | struct device *parent) | |
93 | { | |
94 | return NULL; | |
95 | } | |
96 | static inline int of_platform_device_destroy(struct device *dev, void *data) | |
97 | { | |
98 | return -ENODEV; | |
99 | } | |
100 | ||
964dba28 GL |
101 | static inline int of_platform_populate(struct device_node *root, |
102 | const struct of_device_id *matches, | |
103 | const struct of_dev_auxdata *lookup, | |
104 | struct device *parent) | |
105 | { | |
106 | return -ENODEV; | |
107 | } | |
43443ad6 HM |
108 | static inline int of_platform_default_populate(struct device_node *root, |
109 | const struct of_dev_auxdata *lookup, | |
110 | struct device *parent) | |
111 | { | |
112 | return -ENODEV; | |
113 | } | |
75f353b6 | 114 | static inline void of_platform_depopulate(struct device *parent) { } |
38b0b219 BG |
115 | |
116 | static inline int devm_of_platform_populate(struct device *dev) | |
117 | { | |
118 | return -ENODEV; | |
119 | } | |
120 | ||
121 | static inline void devm_of_platform_depopulate(struct device *dev) { } | |
8a46f4f7 | 122 | #endif |
5fd200f3 | 123 | |
a697c2ef | 124 | #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS) |
801d728c PA |
125 | extern void of_platform_register_reconfig_notifier(void); |
126 | #else | |
127 | static inline void of_platform_register_reconfig_notifier(void) { } | |
128 | #endif | |
129 | ||
b41912ca | 130 | #endif /* _LINUX_OF_PLATFORM_H */ |