aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/acpi/acpi_platform.c2
-rw-r--r--drivers/acpi/dock.c2
-rw-r--r--drivers/acpi/glue.c4
-rw-r--r--drivers/base/core.c51
-rw-r--r--drivers/base/platform.c2
-rw-r--r--drivers/base/property.c198
-rw-r--r--drivers/gpio/gpiolib.h2
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c4
-rw-r--r--drivers/i2c/i2c-core.c4
-rw-r--r--drivers/iommu/intel-iommu.c2
-rw-r--r--include/acpi/acpi_bus.h3
-rw-r--r--include/linux/acpi.h15
-rw-r--r--include/linux/device.h16
-rw-r--r--include/linux/fwnode.h27
-rw-r--r--include/linux/i2c.h4
-rw-r--r--include/linux/platform_device.h2
-rw-r--r--include/linux/property.h44
17 files changed, 292 insertions, 90 deletions
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 1284138e42ab..4bf75597f732 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -102,7 +102,7 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
102 pdevinfo.id = -1; 102 pdevinfo.id = -1;
103 pdevinfo.res = resources; 103 pdevinfo.res = resources;
104 pdevinfo.num_res = count; 104 pdevinfo.num_res = count;
105 pdevinfo.acpi_node.companion = adev; 105 pdevinfo.fwnode = acpi_fwnode_handle(adev);
106 pdevinfo.dma_mask = DMA_BIT_MASK(32); 106 pdevinfo.dma_mask = DMA_BIT_MASK(32);
107 pdev = platform_device_register_full(&pdevinfo); 107 pdev = platform_device_register_full(&pdevinfo);
108 if (IS_ERR(pdev)) 108 if (IS_ERR(pdev))
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index d9339b442a4e..a688aa243f6c 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -615,7 +615,7 @@ void acpi_dock_add(struct acpi_device *adev)
615 memset(&pdevinfo, 0, sizeof(pdevinfo)); 615 memset(&pdevinfo, 0, sizeof(pdevinfo));
616 pdevinfo.name = "dock"; 616 pdevinfo.name = "dock";
617 pdevinfo.id = dock_station_count; 617 pdevinfo.id = dock_station_count;
618 pdevinfo.acpi_node.companion = adev; 618 pdevinfo.fwnode = acpi_fwnode_handle(adev);
619 pdevinfo.data = &ds; 619 pdevinfo.data = &ds;
620 pdevinfo.size_data = sizeof(ds); 620 pdevinfo.size_data = sizeof(ds);
621 dd = platform_device_register_full(&pdevinfo); 621 dd = platform_device_register_full(&pdevinfo);
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index f774c65ecb8b..39c485b0c25c 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -168,7 +168,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
168 unsigned int node_id; 168 unsigned int node_id;
169 int retval = -EINVAL; 169 int retval = -EINVAL;
170 170
171 if (ACPI_COMPANION(dev)) { 171 if (has_acpi_companion(dev)) {
172 if (acpi_dev) { 172 if (acpi_dev) {
173 dev_warn(dev, "ACPI companion already set\n"); 173 dev_warn(dev, "ACPI companion already set\n");
174 return -EINVAL; 174 return -EINVAL;
@@ -220,7 +220,7 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
220 list_add(&physical_node->node, physnode_list); 220 list_add(&physical_node->node, physnode_list);
221 acpi_dev->physical_node_count++; 221 acpi_dev->physical_node_count++;
222 222
223 if (!ACPI_COMPANION(dev)) 223 if (!has_acpi_companion(dev))
224 ACPI_COMPANION_SET(dev, acpi_dev); 224 ACPI_COMPANION_SET(dev, acpi_dev);
225 225
226 acpi_physnode_link_name(physical_node_name, node_id); 226 acpi_physnode_link_name(physical_node_name, node_id);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 07304a3b9ee2..c7e2a9a70865 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/fwnode.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
@@ -2133,3 +2134,53 @@ define_dev_printk_level(dev_notice, KERN_NOTICE);
2133define_dev_printk_level(_dev_info, KERN_INFO); 2134define_dev_printk_level(_dev_info, KERN_INFO);
2134 2135
2135#endif 2136#endif
2137
2138static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
2139{
2140 return fwnode && !IS_ERR(fwnode->secondary);
2141}
2142
2143/**
2144 * set_primary_fwnode - Change the primary firmware node of a given device.
2145 * @dev: Device to handle.
2146 * @fwnode: New primary firmware node of the device.
2147 *
2148 * Set the device's firmware node pointer to @fwnode, but if a secondary
2149 * firmware node of the device is present, preserve it.
2150 */
2151void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
2152{
2153 if (fwnode) {
2154 struct fwnode_handle *fn = dev->fwnode;
2155
2156 if (fwnode_is_primary(fn))
2157 fn = fn->secondary;
2158
2159 fwnode->secondary = fn;
2160 dev->fwnode = fwnode;
2161 } else {
2162 dev->fwnode = fwnode_is_primary(dev->fwnode) ?
2163 dev->fwnode->secondary : NULL;
2164 }
2165}
2166EXPORT_SYMBOL_GPL(set_primary_fwnode);
2167
2168/**
2169 * set_secondary_fwnode - Change the secondary firmware node of a given device.
2170 * @dev: Device to handle.
2171 * @fwnode: New secondary firmware node of the device.
2172 *
2173 * If a primary firmware node of the device is present, set its secondary
2174 * pointer to @fwnode. Otherwise, set the device's firmware node pointer to
2175 * @fwnode.
2176 */
2177void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
2178{
2179 if (fwnode)
2180 fwnode->secondary = ERR_PTR(-ENODEV);
2181
2182 if (fwnode_is_primary(dev->fwnode))
2183 dev->fwnode->secondary = fwnode;
2184 else
2185 dev->fwnode = fwnode;
2186}
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 9421fed40905..17f0204fabef 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -454,7 +454,7 @@ struct platform_device *platform_device_register_full(
454 goto err_alloc; 454 goto err_alloc;
455 455
456 pdev->dev.parent = pdevinfo->parent; 456 pdev->dev.parent = pdevinfo->parent;
457 ACPI_COMPANION_SET(&pdev->dev, pdevinfo->acpi_node.companion); 457 pdev->dev.fwnode = pdevinfo->fwnode;
458 458
459 if (pdevinfo->dma_mask) { 459 if (pdevinfo->dma_mask) {
460 /* 460 /*
diff --git a/drivers/base/property.c b/drivers/base/property.c
index c45845874d4f..6a3f7d8af341 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -10,10 +10,102 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/property.h>
14#include <linux/export.h>
15#include <linux/acpi.h> 13#include <linux/acpi.h>
14#include <linux/export.h>
15#include <linux/kernel.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/property.h>
18
19/**
20 * device_add_property_set - Add a collection of properties to a device object.
21 * @dev: Device to add properties to.
22 * @pset: Collection of properties to add.
23 *
24 * Associate a collection of device properties represented by @pset with @dev
25 * as its secondary firmware node.
26 */
27void device_add_property_set(struct device *dev, struct property_set *pset)
28{
29 if (pset)
30 pset->fwnode.type = FWNODE_PDATA;
31
32 set_secondary_fwnode(dev, &pset->fwnode);
33}
34EXPORT_SYMBOL_GPL(device_add_property_set);
35
36static inline bool is_pset(struct fwnode_handle *fwnode)
37{
38 return fwnode && fwnode->type == FWNODE_PDATA;
39}
40
41static inline struct property_set *to_pset(struct fwnode_handle *fwnode)
42{
43 return is_pset(fwnode) ?
44 container_of(fwnode, struct property_set, fwnode) : NULL;
45}
46
47static struct property_entry *pset_prop_get(struct property_set *pset,
48 const char *name)
49{
50 struct property_entry *prop;
51
52 if (!pset || !pset->properties)
53 return NULL;
54
55 for (prop = pset->properties; prop->name; prop++)
56 if (!strcmp(name, prop->name))
57 return prop;
58
59 return NULL;
60}
61
62static int pset_prop_read_array(struct property_set *pset, const char *name,
63 enum dev_prop_type type, void *val, size_t nval)
64{
65 struct property_entry *prop;
66 unsigned int item_size;
67
68 prop = pset_prop_get(pset, name);
69 if (!prop)
70 return -ENODATA;
71
72 if (prop->type != type)
73 return -EPROTO;
74
75 if (!val)
76 return prop->nval;
77
78 if (prop->nval < nval)
79 return -EOVERFLOW;
80
81 switch (type) {
82 case DEV_PROP_U8:
83 item_size = sizeof(u8);
84 break;
85 case DEV_PROP_U16:
86 item_size = sizeof(u16);
87 break;
88 case DEV_PROP_U32:
89 item_size = sizeof(u32);
90 break;
91 case DEV_PROP_U64:
92 item_size = sizeof(u64);
93 break;
94 case DEV_PROP_STRING:
95 item_size = sizeof(const char *);
96 break;
97 default:
98 return -EINVAL;
99 }
100 memcpy(val, prop->value.raw_data, nval * item_size);
101 return 0;
102}
103
104static inline struct fwnode_handle *dev_fwnode(struct device *dev)
105{
106 return IS_ENABLED(CONFIG_OF) && dev->of_node ?
107 &dev->of_node->fwnode : dev->fwnode;
108}
17 109
18/** 110/**
19 * device_property_present - check if a property of a device is present 111 * device_property_present - check if a property of a device is present
@@ -24,10 +116,7 @@
24 */ 116 */
25bool device_property_present(struct device *dev, const char *propname) 117bool device_property_present(struct device *dev, const char *propname)
26{ 118{
27 if (IS_ENABLED(CONFIG_OF) && dev->of_node) 119 return fwnode_property_present(dev_fwnode(dev), propname);
28 return of_property_read_bool(dev->of_node, propname);
29
30 return !acpi_dev_prop_get(ACPI_COMPANION(dev), propname, NULL);
31} 120}
32EXPORT_SYMBOL_GPL(device_property_present); 121EXPORT_SYMBOL_GPL(device_property_present);
33 122
@@ -43,32 +132,22 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)
43 else if (is_acpi_node(fwnode)) 132 else if (is_acpi_node(fwnode))
44 return !acpi_dev_prop_get(acpi_node(fwnode), propname, NULL); 133 return !acpi_dev_prop_get(acpi_node(fwnode), propname, NULL);
45 134
46 return false; 135 return !!pset_prop_get(to_pset(fwnode), propname);
47} 136}
48EXPORT_SYMBOL_GPL(fwnode_property_present); 137EXPORT_SYMBOL_GPL(fwnode_property_present);
49 138
50#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
51 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
52 : of_property_count_elems_of_size((node), (propname), sizeof(type))
53
54#define DEV_PROP_READ_ARRAY(_dev_, _propname_, _type_, _proptype_, _val_, _nval_) \
55 IS_ENABLED(CONFIG_OF) && _dev_->of_node ? \
56 (OF_DEV_PROP_READ_ARRAY(_dev_->of_node, _propname_, _type_, \
57 _val_, _nval_)) : \
58 acpi_dev_prop_read(ACPI_COMPANION(_dev_), _propname_, \
59 _proptype_, _val_, _nval_)
60
61/** 139/**
62 * device_property_read_u8_array - return a u8 array property of a device 140 * device_property_read_u8_array - return a u8 array property of a device
63 * @dev: Device to get the property of 141 * @dev: Device to get the property of
64 * @propname: Name of the property 142 * @propname: Name of the property
65 * @val: The values are stored here 143 * @val: The values are stored here or %NULL to return the number of values
66 * @nval: Size of the @val array 144 * @nval: Size of the @val array
67 * 145 *
68 * Function reads an array of u8 properties with @propname from the device 146 * Function reads an array of u8 properties with @propname from the device
69 * firmware description and stores them to @val if found. 147 * firmware description and stores them to @val if found.
70 * 148 *
71 * Return: %0 if the property was found (success), 149 * Return: number of values if @val was %NULL,
150 * %0 if the property was found (success),
72 * %-EINVAL if given arguments are not valid, 151 * %-EINVAL if given arguments are not valid,
73 * %-ENODATA if the property does not have a value, 152 * %-ENODATA if the property does not have a value,
74 * %-EPROTO if the property is not an array of numbers, 153 * %-EPROTO if the property is not an array of numbers,
@@ -77,7 +156,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_present);
77int device_property_read_u8_array(struct device *dev, const char *propname, 156int device_property_read_u8_array(struct device *dev, const char *propname,
78 u8 *val, size_t nval) 157 u8 *val, size_t nval)
79{ 158{
80 return DEV_PROP_READ_ARRAY(dev, propname, u8, DEV_PROP_U8, val, nval); 159 return fwnode_property_read_u8_array(dev_fwnode(dev), propname, val, nval);
81} 160}
82EXPORT_SYMBOL_GPL(device_property_read_u8_array); 161EXPORT_SYMBOL_GPL(device_property_read_u8_array);
83 162
@@ -85,13 +164,14 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array);
85 * device_property_read_u16_array - return a u16 array property of a device 164 * device_property_read_u16_array - return a u16 array property of a device
86 * @dev: Device to get the property of 165 * @dev: Device to get the property of
87 * @propname: Name of the property 166 * @propname: Name of the property
88 * @val: The values are stored here 167 * @val: The values are stored here or %NULL to return the number of values
89 * @nval: Size of the @val array 168 * @nval: Size of the @val array
90 * 169 *
91 * Function reads an array of u16 properties with @propname from the device 170 * Function reads an array of u16 properties with @propname from the device
92 * firmware description and stores them to @val if found. 171 * firmware description and stores them to @val if found.
93 * 172 *
94 * Return: %0 if the property was found (success), 173 * Return: number of values if @val was %NULL,
174 * %0 if the property was found (success),
95 * %-EINVAL if given arguments are not valid, 175 * %-EINVAL if given arguments are not valid,
96 * %-ENODATA if the property does not have a value, 176 * %-ENODATA if the property does not have a value,
97 * %-EPROTO if the property is not an array of numbers, 177 * %-EPROTO if the property is not an array of numbers,
@@ -100,7 +180,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u8_array);
100int device_property_read_u16_array(struct device *dev, const char *propname, 180int device_property_read_u16_array(struct device *dev, const char *propname,
101 u16 *val, size_t nval) 181 u16 *val, size_t nval)
102{ 182{
103 return DEV_PROP_READ_ARRAY(dev, propname, u16, DEV_PROP_U16, val, nval); 183 return fwnode_property_read_u16_array(dev_fwnode(dev), propname, val, nval);
104} 184}
105EXPORT_SYMBOL_GPL(device_property_read_u16_array); 185EXPORT_SYMBOL_GPL(device_property_read_u16_array);
106 186
@@ -108,13 +188,14 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array);
108 * device_property_read_u32_array - return a u32 array property of a device 188 * device_property_read_u32_array - return a u32 array property of a device
109 * @dev: Device to get the property of 189 * @dev: Device to get the property of
110 * @propname: Name of the property 190 * @propname: Name of the property
111 * @val: The values are stored here 191 * @val: The values are stored here or %NULL to return the number of values
112 * @nval: Size of the @val array 192 * @nval: Size of the @val array
113 * 193 *
114 * Function reads an array of u32 properties with @propname from the device 194 * Function reads an array of u32 properties with @propname from the device
115 * firmware description and stores them to @val if found. 195 * firmware description and stores them to @val if found.
116 * 196 *
117 * Return: %0 if the property was found (success), 197 * Return: number of values if @val was %NULL,
198 * %0 if the property was found (success),
118 * %-EINVAL if given arguments are not valid, 199 * %-EINVAL if given arguments are not valid,
119 * %-ENODATA if the property does not have a value, 200 * %-ENODATA if the property does not have a value,
120 * %-EPROTO if the property is not an array of numbers, 201 * %-EPROTO if the property is not an array of numbers,
@@ -123,7 +204,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u16_array);
123int device_property_read_u32_array(struct device *dev, const char *propname, 204int device_property_read_u32_array(struct device *dev, const char *propname,
124 u32 *val, size_t nval) 205 u32 *val, size_t nval)
125{ 206{
126 return DEV_PROP_READ_ARRAY(dev, propname, u32, DEV_PROP_U32, val, nval); 207 return fwnode_property_read_u32_array(dev_fwnode(dev), propname, val, nval);
127} 208}
128EXPORT_SYMBOL_GPL(device_property_read_u32_array); 209EXPORT_SYMBOL_GPL(device_property_read_u32_array);
129 210
@@ -131,13 +212,14 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array);
131 * device_property_read_u64_array - return a u64 array property of a device 212 * device_property_read_u64_array - return a u64 array property of a device
132 * @dev: Device to get the property of 213 * @dev: Device to get the property of
133 * @propname: Name of the property 214 * @propname: Name of the property
134 * @val: The values are stored here 215 * @val: The values are stored here or %NULL to return the number of values
135 * @nval: Size of the @val array 216 * @nval: Size of the @val array
136 * 217 *
137 * Function reads an array of u64 properties with @propname from the device 218 * Function reads an array of u64 properties with @propname from the device
138 * firmware description and stores them to @val if found. 219 * firmware description and stores them to @val if found.
139 * 220 *
140 * Return: %0 if the property was found (success), 221 * Return: number of values if @val was %NULL,
222 * %0 if the property was found (success),
141 * %-EINVAL if given arguments are not valid, 223 * %-EINVAL if given arguments are not valid,
142 * %-ENODATA if the property does not have a value, 224 * %-ENODATA if the property does not have a value,
143 * %-EPROTO if the property is not an array of numbers, 225 * %-EPROTO if the property is not an array of numbers,
@@ -146,7 +228,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u32_array);
146int device_property_read_u64_array(struct device *dev, const char *propname, 228int device_property_read_u64_array(struct device *dev, const char *propname,
147 u64 *val, size_t nval) 229 u64 *val, size_t nval)
148{ 230{
149 return DEV_PROP_READ_ARRAY(dev, propname, u64, DEV_PROP_U64, val, nval); 231 return fwnode_property_read_u64_array(dev_fwnode(dev), propname, val, nval);
150} 232}
151EXPORT_SYMBOL_GPL(device_property_read_u64_array); 233EXPORT_SYMBOL_GPL(device_property_read_u64_array);
152 234
@@ -154,13 +236,14 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array);
154 * device_property_read_string_array - return a string array property of device 236 * device_property_read_string_array - return a string array property of device
155 * @dev: Device to get the property of 237 * @dev: Device to get the property of
156 * @propname: Name of the property 238 * @propname: Name of the property
157 * @val: The values are stored here 239 * @val: The values are stored here or %NULL to return the number of values
158 * @nval: Size of the @val array 240 * @nval: Size of the @val array
159 * 241 *
160 * Function reads an array of string properties with @propname from the device 242 * Function reads an array of string properties with @propname from the device
161 * firmware description and stores them to @val if found. 243 * firmware description and stores them to @val if found.
162 * 244 *
163 * Return: %0 if the property was found (success), 245 * Return: number of values if @val was %NULL,
246 * %0 if the property was found (success),
164 * %-EINVAL if given arguments are not valid, 247 * %-EINVAL if given arguments are not valid,
165 * %-ENODATA if the property does not have a value, 248 * %-ENODATA if the property does not have a value,
166 * %-EPROTO or %-EILSEQ if the property is not an array of strings, 249 * %-EPROTO or %-EILSEQ if the property is not an array of strings,
@@ -169,10 +252,7 @@ EXPORT_SYMBOL_GPL(device_property_read_u64_array);
169int device_property_read_string_array(struct device *dev, const char *propname, 252int device_property_read_string_array(struct device *dev, const char *propname,
170 const char **val, size_t nval) 253 const char **val, size_t nval)
171{ 254{
172 return IS_ENABLED(CONFIG_OF) && dev->of_node ? 255 return fwnode_property_read_string_array(dev_fwnode(dev), propname, val, nval);
173 of_property_read_string_array(dev->of_node, propname, val, nval) :
174 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
175 DEV_PROP_STRING, val, nval);
176} 256}
177EXPORT_SYMBOL_GPL(device_property_read_string_array); 257EXPORT_SYMBOL_GPL(device_property_read_string_array);
178 258
@@ -193,13 +273,14 @@ EXPORT_SYMBOL_GPL(device_property_read_string_array);
193int device_property_read_string(struct device *dev, const char *propname, 273int device_property_read_string(struct device *dev, const char *propname,
194 const char **val) 274 const char **val)
195{ 275{
196 return IS_ENABLED(CONFIG_OF) && dev->of_node ? 276 return fwnode_property_read_string(dev_fwnode(dev), propname, val);
197 of_property_read_string(dev->of_node, propname, val) :
198 acpi_dev_prop_read(ACPI_COMPANION(dev), propname,
199 DEV_PROP_STRING, val, 1);
200} 277}
201EXPORT_SYMBOL_GPL(device_property_read_string); 278EXPORT_SYMBOL_GPL(device_property_read_string);
202 279
280#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
281 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
282 : of_property_count_elems_of_size((node), (propname), sizeof(type))
283
203#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \ 284#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_) \
204({ \ 285({ \
205 int _ret_; \ 286 int _ret_; \
@@ -210,7 +291,8 @@ EXPORT_SYMBOL_GPL(device_property_read_string);
210 _ret_ = acpi_dev_prop_read(acpi_node(_fwnode_), _propname_, \ 291 _ret_ = acpi_dev_prop_read(acpi_node(_fwnode_), _propname_, \
211 _proptype_, _val_, _nval_); \ 292 _proptype_, _val_, _nval_); \
212 else \ 293 else \
213 _ret_ = -ENXIO; \ 294 _ret_ = pset_prop_read_array(to_pset(_fwnode_), _propname_, \
295 _proptype_, _val_, _nval_); \
214 _ret_; \ 296 _ret_; \
215}) 297})
216 298
@@ -218,13 +300,14 @@ EXPORT_SYMBOL_GPL(device_property_read_string);
218 * fwnode_property_read_u8_array - return a u8 array property of firmware node 300 * fwnode_property_read_u8_array - return a u8 array property of firmware node
219 * @fwnode: Firmware node to get the property of 301 * @fwnode: Firmware node to get the property of
220 * @propname: Name of the property 302 * @propname: Name of the property
221 * @val: The values are stored here 303 * @val: The values are stored here or %NULL to return the number of values
222 * @nval: Size of the @val array 304 * @nval: Size of the @val array
223 * 305 *
224 * Read an array of u8 properties with @propname from @fwnode and stores them to 306 * Read an array of u8 properties with @propname from @fwnode and stores them to
225 * @val if found. 307 * @val if found.
226 * 308 *
227 * Return: %0 if the property was found (success), 309 * Return: number of values if @val was %NULL,
310 * %0 if the property was found (success),
228 * %-EINVAL if given arguments are not valid, 311 * %-EINVAL if given arguments are not valid,
229 * %-ENODATA if the property does not have a value, 312 * %-ENODATA if the property does not have a value,
230 * %-EPROTO if the property is not an array of numbers, 313 * %-EPROTO if the property is not an array of numbers,
@@ -243,13 +326,14 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array);
243 * fwnode_property_read_u16_array - return a u16 array property of firmware node 326 * fwnode_property_read_u16_array - return a u16 array property of firmware node
244 * @fwnode: Firmware node to get the property of 327 * @fwnode: Firmware node to get the property of
245 * @propname: Name of the property 328 * @propname: Name of the property
246 * @val: The values are stored here 329 * @val: The values are stored here or %NULL to return the number of values
247 * @nval: Size of the @val array 330 * @nval: Size of the @val array
248 * 331 *
249 * Read an array of u16 properties with @propname from @fwnode and store them to 332 * Read an array of u16 properties with @propname from @fwnode and store them to
250 * @val if found. 333 * @val if found.
251 * 334 *
252 * Return: %0 if the property was found (success), 335 * Return: number of values if @val was %NULL,
336 * %0 if the property was found (success),
253 * %-EINVAL if given arguments are not valid, 337 * %-EINVAL if given arguments are not valid,
254 * %-ENODATA if the property does not have a value, 338 * %-ENODATA if the property does not have a value,
255 * %-EPROTO if the property is not an array of numbers, 339 * %-EPROTO if the property is not an array of numbers,
@@ -268,13 +352,14 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array);
268 * fwnode_property_read_u32_array - return a u32 array property of firmware node 352 * fwnode_property_read_u32_array - return a u32 array property of firmware node
269 * @fwnode: Firmware node to get the property of 353 * @fwnode: Firmware node to get the property of
270 * @propname: Name of the property 354 * @propname: Name of the property
271 * @val: The values are stored here 355 * @val: The values are stored here or %NULL to return the number of values
272 * @nval: Size of the @val array 356 * @nval: Size of the @val array
273 * 357 *
274 * Read an array of u32 properties with @propname from @fwnode store them to 358 * Read an array of u32 properties with @propname from @fwnode store them to
275 * @val if found. 359 * @val if found.
276 * 360 *
277 * Return: %0 if the property was found (success), 361 * Return: number of values if @val was %NULL,
362 * %0 if the property was found (success),
278 * %-EINVAL if given arguments are not valid, 363 * %-EINVAL if given arguments are not valid,
279 * %-ENODATA if the property does not have a value, 364 * %-ENODATA if the property does not have a value,
280 * %-EPROTO if the property is not an array of numbers, 365 * %-EPROTO if the property is not an array of numbers,
@@ -293,13 +378,14 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array);
293 * fwnode_property_read_u64_array - return a u64 array property firmware node 378 * fwnode_property_read_u64_array - return a u64 array property firmware node
294 * @fwnode: Firmware node to get the property of 379 * @fwnode: Firmware node to get the property of
295 * @propname: Name of the property 380 * @propname: Name of the property
296 * @val: The values are stored here 381 * @val: The values are stored here or %NULL to return the number of values
297 * @nval: Size of the @val array 382 * @nval: Size of the @val array
298 * 383 *
299 * Read an array of u64 properties with @propname from @fwnode and store them to 384 * Read an array of u64 properties with @propname from @fwnode and store them to
300 * @val if found. 385 * @val if found.
301 * 386 *
302 * Return: %0 if the property was found (success), 387 * Return: number of values if @val was %NULL,
388 * %0 if the property was found (success),
303 * %-EINVAL if given arguments are not valid, 389 * %-EINVAL if given arguments are not valid,
304 * %-ENODATA if the property does not have a value, 390 * %-ENODATA if the property does not have a value,
305 * %-EPROTO if the property is not an array of numbers, 391 * %-EPROTO if the property is not an array of numbers,
@@ -318,13 +404,14 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array);
318 * fwnode_property_read_string_array - return string array property of a node 404 * fwnode_property_read_string_array - return string array property of a node
319 * @fwnode: Firmware node to get the property of 405 * @fwnode: Firmware node to get the property of
320 * @propname: Name of the property 406 * @propname: Name of the property
321 * @val: The values are stored here 407 * @val: The values are stored here or %NULL to return the number of values
322 * @nval: Size of the @val array 408 * @nval: Size of the @val array
323 * 409 *
324 * Read an string list property @propname from the given firmware node and store 410 * Read an string list property @propname from the given firmware node and store
325 * them to @val if found. 411 * them to @val if found.
326 * 412 *
327 * Return: %0 if the property was found (success), 413 * Return: number of values if @val was %NULL,
414 * %0 if the property was found (success),
328 * %-EINVAL if given arguments are not valid, 415 * %-EINVAL if given arguments are not valid,
329 * %-ENODATA if the property does not have a value, 416 * %-ENODATA if the property does not have a value,
330 * %-EPROTO if the property is not an array of strings, 417 * %-EPROTO if the property is not an array of strings,
@@ -336,13 +423,16 @@ int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
336 size_t nval) 423 size_t nval)
337{ 424{
338 if (is_of_node(fwnode)) 425 if (is_of_node(fwnode))
339 return of_property_read_string_array(of_node(fwnode), propname, 426 return val ?
340 val, nval); 427 of_property_read_string_array(of_node(fwnode), propname,
428 val, nval) :
429 of_property_count_strings(of_node(fwnode), propname);
341 else if (is_acpi_node(fwnode)) 430 else if (is_acpi_node(fwnode))
342 return acpi_dev_prop_read(acpi_node(fwnode), propname, 431 return acpi_dev_prop_read(acpi_node(fwnode), propname,
343 DEV_PROP_STRING, val, nval); 432 DEV_PROP_STRING, val, nval);
344 433
345 return -ENXIO; 434 return pset_prop_read_array(to_pset(fwnode), propname,
435 DEV_PROP_STRING, val, nval);
346} 436}
347EXPORT_SYMBOL_GPL(fwnode_property_read_string_array); 437EXPORT_SYMBOL_GPL(fwnode_property_read_string_array);
348 438
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 550a5eafbd38..ab892be26dc2 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -17,6 +17,8 @@
17 17
18enum of_gpio_flags; 18enum of_gpio_flags;
19 19
20struct acpi_device;
21
20/** 22/**
21 * struct acpi_gpio_info - ACPI GPIO specific information 23 * struct acpi_gpio_info - ACPI GPIO specific information
22 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo 24 * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index c270f5f9a8f9..538d6910b550 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -166,7 +166,7 @@ static int dw_i2c_probe(struct platform_device *pdev)
166 /* fast mode by default because of legacy reasons */ 166 /* fast mode by default because of legacy reasons */
167 clk_freq = 400000; 167 clk_freq = 400000;
168 168
169 if (ACPI_COMPANION(&pdev->dev)) { 169 if (has_acpi_companion(&pdev->dev)) {
170 dw_i2c_acpi_configure(pdev); 170 dw_i2c_acpi_configure(pdev);
171 } else if (pdev->dev.of_node) { 171 } else if (pdev->dev.of_node) {
172 of_property_read_u32(pdev->dev.of_node, 172 of_property_read_u32(pdev->dev.of_node,
@@ -286,7 +286,7 @@ static int dw_i2c_remove(struct platform_device *pdev)
286 pm_runtime_put(&pdev->dev); 286 pm_runtime_put(&pdev->dev);
287 pm_runtime_disable(&pdev->dev); 287 pm_runtime_disable(&pdev->dev);
288 288
289 if (ACPI_COMPANION(&pdev->dev)) 289 if (has_acpi_companion(&pdev->dev))
290 dw_i2c_acpi_unconfigure(pdev); 290 dw_i2c_acpi_unconfigure(pdev);
291 291
292 return 0; 292 return 0;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index edf274cabe81..c87c31387e2d 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -133,7 +133,7 @@ static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
133 return AE_OK; 133 return AE_OK;
134 134
135 memset(&info, 0, sizeof(info)); 135 memset(&info, 0, sizeof(info));
136 info.acpi_node.companion = adev; 136 info.fwnode = acpi_fwnode_handle(adev);
137 info.irq = -1; 137 info.irq = -1;
138 138
139 INIT_LIST_HEAD(&resource_list); 139 INIT_LIST_HEAD(&resource_list);
@@ -971,7 +971,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
971 client->dev.bus = &i2c_bus_type; 971 client->dev.bus = &i2c_bus_type;
972 client->dev.type = &i2c_client_type; 972 client->dev.type = &i2c_client_type;
973 client->dev.of_node = info->of_node; 973 client->dev.of_node = info->of_node;
974 ACPI_COMPANION_SET(&client->dev, info->acpi_node.companion); 974 client->dev.fwnode = info->fwnode;
975 975
976 i2c_dev_set_name(adap, client); 976 i2c_dev_set_name(adap, client);
977 status = device_register(&client->dev); 977 status = device_register(&client->dev);
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 2d1e05bdbb53..4fc1f8a7f98e 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -684,7 +684,7 @@ static struct intel_iommu *device_to_iommu(struct device *dev, u8 *bus, u8 *devf
684 if (dev_is_pci(dev)) { 684 if (dev_is_pci(dev)) {
685 pdev = to_pci_dev(dev); 685 pdev = to_pci_dev(dev);
686 segment = pci_domain_nr(pdev->bus); 686 segment = pci_domain_nr(pdev->bus);
687 } else if (ACPI_COMPANION(dev)) 687 } else if (has_acpi_companion(dev))
688 dev = &ACPI_COMPANION(dev)->dev; 688 dev = &ACPI_COMPANION(dev)->dev;
689 689
690 rcu_read_lock(); 690 rcu_read_lock();
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index f8009d99190a..8de4fa90e8c4 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -387,7 +387,8 @@ static inline bool is_acpi_node(struct fwnode_handle *fwnode)
387 387
388static inline struct acpi_device *acpi_node(struct fwnode_handle *fwnode) 388static inline struct acpi_device *acpi_node(struct fwnode_handle *fwnode)
389{ 389{
390 return fwnode ? container_of(fwnode, struct acpi_device, fwnode) : NULL; 390 return is_acpi_node(fwnode) ?
391 container_of(fwnode, struct acpi_device, fwnode) : NULL;
391} 392}
392 393
393static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev) 394static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 24c7aa8b1d20..dd12127f171c 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -53,10 +53,16 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
53 return adev ? adev->handle : NULL; 53 return adev ? adev->handle : NULL;
54} 54}
55 55
56#define ACPI_COMPANION(dev) ((dev)->acpi_node.companion) 56#define ACPI_COMPANION(dev) acpi_node((dev)->fwnode)
57#define ACPI_COMPANION_SET(dev, adev) ACPI_COMPANION(dev) = (adev) 57#define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \
58 acpi_fwnode_handle(adev) : NULL)
58#define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev)) 59#define ACPI_HANDLE(dev) acpi_device_handle(ACPI_COMPANION(dev))
59 60
61static inline bool has_acpi_companion(struct device *dev)
62{
63 return is_acpi_node(dev->fwnode);
64}
65
60static inline void acpi_preset_companion(struct device *dev, 66static inline void acpi_preset_companion(struct device *dev,
61 struct acpi_device *parent, u64 addr) 67 struct acpi_device *parent, u64 addr)
62{ 68{
@@ -471,6 +477,11 @@ static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
471 return NULL; 477 return NULL;
472} 478}
473 479
480static inline bool has_acpi_companion(struct device *dev)
481{
482 return false;
483}
484
474static inline const char *acpi_dev_name(struct acpi_device *adev) 485static inline const char *acpi_dev_name(struct acpi_device *adev)
475{ 486{
476 return NULL; 487 return NULL;
diff --git a/include/linux/device.h b/include/linux/device.h
index 0eb8ee2dc6d1..324d02add7b4 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -38,6 +38,7 @@ struct class;
38struct subsys_private; 38struct subsys_private;
39struct bus_type; 39struct bus_type;
40struct device_node; 40struct device_node;
41struct fwnode_handle;
41struct iommu_ops; 42struct iommu_ops;
42struct iommu_group; 43struct iommu_group;
43 44
@@ -650,14 +651,6 @@ struct device_dma_parameters {
650 unsigned long segment_boundary_mask; 651 unsigned long segment_boundary_mask;
651}; 652};
652 653
653struct acpi_device;
654
655struct acpi_dev_node {
656#ifdef CONFIG_ACPI
657 struct acpi_device *companion;
658#endif
659};
660
661/** 654/**
662 * struct device - The basic device structure 655 * struct device - The basic device structure
663 * @parent: The device's "parent" device, the device to which it is attached. 656 * @parent: The device's "parent" device, the device to which it is attached.
@@ -703,7 +696,7 @@ struct acpi_dev_node {
703 * @cma_area: Contiguous memory area for dma allocations 696 * @cma_area: Contiguous memory area for dma allocations
704 * @archdata: For arch-specific additions. 697 * @archdata: For arch-specific additions.
705 * @of_node: Associated device tree node. 698 * @of_node: Associated device tree node.
706 * @acpi_node: Associated ACPI device node. 699 * @fwnode: Associated device node supplied by platform firmware.
707 * @devt: For creating the sysfs "dev". 700 * @devt: For creating the sysfs "dev".
708 * @id: device instance 701 * @id: device instance
709 * @devres_lock: Spinlock to protect the resource of the device. 702 * @devres_lock: Spinlock to protect the resource of the device.
@@ -779,7 +772,7 @@ struct device {
779 struct dev_archdata archdata; 772 struct dev_archdata archdata;
780 773
781 struct device_node *of_node; /* associated device tree node */ 774 struct device_node *of_node; /* associated device tree node */
782 struct acpi_dev_node acpi_node; /* associated ACPI device node */ 775 struct fwnode_handle *fwnode; /* firmware device node */
783 776
784 dev_t devt; /* dev_t, creates the sysfs "dev" */ 777 dev_t devt; /* dev_t, creates the sysfs "dev" */
785 u32 id; /* device instance */ 778 u32 id; /* device instance */
@@ -947,6 +940,9 @@ extern void unlock_device_hotplug(void);
947extern int lock_device_hotplug_sysfs(void); 940extern int lock_device_hotplug_sysfs(void);
948extern int device_offline(struct device *dev); 941extern int device_offline(struct device *dev);
949extern int device_online(struct device *dev); 942extern int device_online(struct device *dev);
943extern void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
944extern void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode);
945
950/* 946/*
951 * Root device objects for grouping under /sys/devices 947 * Root device objects for grouping under /sys/devices
952 */ 948 */
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
new file mode 100644
index 000000000000..0408545bce42
--- /dev/null
+++ b/include/linux/fwnode.h
@@ -0,0 +1,27 @@
1/*
2 * fwnode.h - Firmware device node object handle type definition.
3 *
4 * Copyright (C) 2015, Intel Corporation
5 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _LINUX_FWNODE_H_
13#define _LINUX_FWNODE_H_
14
15enum fwnode_type {
16 FWNODE_INVALID = 0,
17 FWNODE_OF,
18 FWNODE_ACPI,
19 FWNODE_PDATA,
20};
21
22struct fwnode_handle {
23 enum fwnode_type type;
24 struct fwnode_handle *secondary;
25};
26
27#endif
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index f17da50402a4..6d89575361a8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -278,7 +278,7 @@ static inline int i2c_slave_event(struct i2c_client *client,
278 * @platform_data: stored in i2c_client.dev.platform_data 278 * @platform_data: stored in i2c_client.dev.platform_data
279 * @archdata: copied into i2c_client.dev.archdata 279 * @archdata: copied into i2c_client.dev.archdata
280 * @of_node: pointer to OpenFirmware device node 280 * @of_node: pointer to OpenFirmware device node
281 * @acpi_node: ACPI device node 281 * @fwnode: device node supplied by the platform firmware
282 * @irq: stored in i2c_client.irq 282 * @irq: stored in i2c_client.irq
283 * 283 *
284 * I2C doesn't actually support hardware probing, although controllers and 284 * I2C doesn't actually support hardware probing, although controllers and
@@ -299,7 +299,7 @@ struct i2c_board_info {
299 void *platform_data; 299 void *platform_data;
300 struct dev_archdata *archdata; 300 struct dev_archdata *archdata;
301 struct device_node *of_node; 301 struct device_node *of_node;
302 struct acpi_dev_node acpi_node; 302 struct fwnode_handle *fwnode;
303 int irq; 303 int irq;
304}; 304};
305 305
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index ae4882ca4a64..58f1e75ba105 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -59,7 +59,7 @@ extern int platform_add_devices(struct platform_device **, int);
59 59
60struct platform_device_info { 60struct platform_device_info {
61 struct device *parent; 61 struct device *parent;
62 struct acpi_dev_node acpi_node; 62 struct fwnode_handle *fwnode;
63 63
64 const char *name; 64 const char *name;
65 int id; 65 int id;
diff --git a/include/linux/property.h b/include/linux/property.h
index a6a3d98bd7e9..de8bdf417a35 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -13,6 +13,7 @@
13#ifndef _LINUX_PROPERTY_H_ 13#ifndef _LINUX_PROPERTY_H_
14#define _LINUX_PROPERTY_H_ 14#define _LINUX_PROPERTY_H_
15 15
16#include <linux/fwnode.h>
16#include <linux/types.h> 17#include <linux/types.h>
17 18
18struct device; 19struct device;
@@ -40,16 +41,6 @@ int device_property_read_string_array(struct device *dev, const char *propname,
40int device_property_read_string(struct device *dev, const char *propname, 41int device_property_read_string(struct device *dev, const char *propname,
41 const char **val); 42 const char **val);
42 43
43enum fwnode_type {
44 FWNODE_INVALID = 0,
45 FWNODE_OF,
46 FWNODE_ACPI,
47};
48
49struct fwnode_handle {
50 enum fwnode_type type;
51};
52
53bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname); 44bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname);
54int fwnode_property_read_u8_array(struct fwnode_handle *fwnode, 45int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
55 const char *propname, u8 *val, 46 const char *propname, u8 *val,
@@ -140,4 +131,37 @@ static inline int fwnode_property_read_u64(struct fwnode_handle *fwnode,
140 return fwnode_property_read_u64_array(fwnode, propname, val, 1); 131 return fwnode_property_read_u64_array(fwnode, propname, val, 1);
141} 132}
142 133
134/**
135 * struct property_entry - "Built-in" device property representation.
136 * @name: Name of the property.
137 * @type: Type of the property.
138 * @nval: Number of items of type @type making up the value.
139 * @value: Value of the property (an array of @nval items of type @type).
140 */
141struct property_entry {
142 const char *name;
143 enum dev_prop_type type;
144 size_t nval;
145 union {
146 void *raw_data;
147 u8 *u8_data;
148 u16 *u16_data;
149 u32 *u32_data;
150 u64 *u64_data;
151 const char **str;
152 } value;
153};
154
155/**
156 * struct property_set - Collection of "built-in" device properties.
157 * @fwnode: Handle to be pointed to by the fwnode field of struct device.
158 * @properties: Array of properties terminated with a null entry.
159 */
160struct property_set {
161 struct fwnode_handle fwnode;
162 struct property_entry *properties;
163};
164
165void device_add_property_set(struct device *dev, struct property_set *pset);
166
143#endif /* _LINUX_PROPERTY_H_ */ 167#endif /* _LINUX_PROPERTY_H_ */