Merge branch 'device-properties'

* device-properties:
device property: Introduce firmware node type for platform data
device property: Make it possible to use secondary firmware nodes
driver core: Implement device property accessors through fwnode ones
driver core: property: Update fwnode_property_read_string_array()
driver core: Add comments about returning array counts
ACPI: Introduce has_acpi_companion()
driver core / ACPI: Represent ACPI companions using fwnode_handle

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