aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-10-25 17:51:48 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-10-25 17:51:48 -0400
commitab736d7dc17e681be001648607be20c549b6229c (patch)
tree1bdb29dd23105897329c3b796f2e88877ef6d8b8 /drivers/base
parent32b88194f71d6ae7768a29f87fbba454728273ee (diff)
parent205ad97fc5a6386214323641dd28b822cb6fc624 (diff)
Merge branch 'device-properties'
* device-properties: ACPI / property: Fix subnode lookup scope for data-only subnodes acpi-dma: Add support for "dma-names" device property device property: Add fwnode_property_match_string() ACPI / property: Extend device_get_next_child_node() to data-only nodes ACPI / gpio: Split acpi_get_gpiod_by_index() ACPI / property: Extend fwnode_property_* to data-only subnodes ACPI / property: Expose data-only subnodes via sysfs ACPI / property: Add support for data-only subnodes ACPI / property: Add routine for extraction of _DSD properties
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/property.c88
1 files changed, 76 insertions, 12 deletions
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 2d75366c61e0..de40623bbd8a 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -134,7 +134,7 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)
134 if (is_of_node(fwnode)) 134 if (is_of_node(fwnode))
135 return of_property_read_bool(to_of_node(fwnode), propname); 135 return of_property_read_bool(to_of_node(fwnode), propname);
136 else if (is_acpi_node(fwnode)) 136 else if (is_acpi_node(fwnode))
137 return !acpi_dev_prop_get(to_acpi_node(fwnode), propname, NULL); 137 return !acpi_node_prop_get(fwnode, propname, NULL);
138 138
139 return !!pset_prop_get(to_pset(fwnode), propname); 139 return !!pset_prop_get(to_pset(fwnode), propname);
140} 140}
@@ -287,6 +287,28 @@ int device_property_read_string(struct device *dev, const char *propname,
287} 287}
288EXPORT_SYMBOL_GPL(device_property_read_string); 288EXPORT_SYMBOL_GPL(device_property_read_string);
289 289
290/**
291 * device_property_match_string - find a string in an array and return index
292 * @dev: Device to get the property of
293 * @propname: Name of the property holding the array
294 * @string: String to look for
295 *
296 * Find a given string in a string array and if it is found return the
297 * index back.
298 *
299 * Return: %0 if the property was found (success),
300 * %-EINVAL if given arguments are not valid,
301 * %-ENODATA if the property does not have a value,
302 * %-EPROTO if the property is not an array of strings,
303 * %-ENXIO if no suitable firmware interface is present.
304 */
305int device_property_match_string(struct device *dev, const char *propname,
306 const char *string)
307{
308 return fwnode_property_match_string(dev_fwnode(dev), propname, string);
309}
310EXPORT_SYMBOL_GPL(device_property_match_string);
311
290#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \ 312#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval) \
291 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \ 313 (val) ? of_property_read_##type##_array((node), (propname), (val), (nval)) \
292 : of_property_count_elems_of_size((node), (propname), sizeof(type)) 314 : of_property_count_elems_of_size((node), (propname), sizeof(type))
@@ -298,8 +320,8 @@ EXPORT_SYMBOL_GPL(device_property_read_string);
298 _ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), _propname_, \ 320 _ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), _propname_, \
299 _type_, _val_, _nval_); \ 321 _type_, _val_, _nval_); \
300 else if (is_acpi_node(_fwnode_)) \ 322 else if (is_acpi_node(_fwnode_)) \
301 _ret_ = acpi_dev_prop_read(to_acpi_node(_fwnode_), _propname_, \ 323 _ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_, \
302 _proptype_, _val_, _nval_); \ 324 _val_, _nval_); \
303 else if (is_pset(_fwnode_)) \ 325 else if (is_pset(_fwnode_)) \
304 _ret_ = pset_prop_read_array(to_pset(_fwnode_), _propname_, \ 326 _ret_ = pset_prop_read_array(to_pset(_fwnode_), _propname_, \
305 _proptype_, _val_, _nval_); \ 327 _proptype_, _val_, _nval_); \
@@ -440,8 +462,8 @@ int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
440 propname, val, nval) : 462 propname, val, nval) :
441 of_property_count_strings(to_of_node(fwnode), propname); 463 of_property_count_strings(to_of_node(fwnode), propname);
442 else if (is_acpi_node(fwnode)) 464 else if (is_acpi_node(fwnode))
443 return acpi_dev_prop_read(to_acpi_node(fwnode), propname, 465 return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
444 DEV_PROP_STRING, val, nval); 466 val, nval);
445 else if (is_pset(fwnode)) 467 else if (is_pset(fwnode))
446 return pset_prop_read_array(to_pset(fwnode), propname, 468 return pset_prop_read_array(to_pset(fwnode), propname,
447 DEV_PROP_STRING, val, nval); 469 DEV_PROP_STRING, val, nval);
@@ -470,8 +492,8 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode,
470 if (is_of_node(fwnode)) 492 if (is_of_node(fwnode))
471 return of_property_read_string(to_of_node(fwnode), propname, val); 493 return of_property_read_string(to_of_node(fwnode), propname, val);
472 else if (is_acpi_node(fwnode)) 494 else if (is_acpi_node(fwnode))
473 return acpi_dev_prop_read(to_acpi_node(fwnode), propname, 495 return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
474 DEV_PROP_STRING, val, 1); 496 val, 1);
475 497
476 return pset_prop_read_array(to_pset(fwnode), propname, 498 return pset_prop_read_array(to_pset(fwnode), propname,
477 DEV_PROP_STRING, val, 1); 499 DEV_PROP_STRING, val, 1);
@@ -479,6 +501,52 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode,
479EXPORT_SYMBOL_GPL(fwnode_property_read_string); 501EXPORT_SYMBOL_GPL(fwnode_property_read_string);
480 502
481/** 503/**
504 * fwnode_property_match_string - find a string in an array and return index
505 * @fwnode: Firmware node to get the property of
506 * @propname: Name of the property holding the array
507 * @string: String to look for
508 *
509 * Find a given string in a string array and if it is found return the
510 * index back.
511 *
512 * Return: %0 if the property was found (success),
513 * %-EINVAL if given arguments are not valid,
514 * %-ENODATA if the property does not have a value,
515 * %-EPROTO if the property is not an array of strings,
516 * %-ENXIO if no suitable firmware interface is present.
517 */
518int fwnode_property_match_string(struct fwnode_handle *fwnode,
519 const char *propname, const char *string)
520{
521 const char **values;
522 int nval, ret, i;
523
524 nval = fwnode_property_read_string_array(fwnode, propname, NULL, 0);
525 if (nval < 0)
526 return nval;
527
528 values = kcalloc(nval, sizeof(*values), GFP_KERNEL);
529 if (!values)
530 return -ENOMEM;
531
532 ret = fwnode_property_read_string_array(fwnode, propname, values, nval);
533 if (ret < 0)
534 goto out;
535
536 ret = -ENODATA;
537 for (i = 0; i < nval; i++) {
538 if (!strcmp(values[i], string)) {
539 ret = i;
540 break;
541 }
542 }
543out:
544 kfree(values);
545 return ret;
546}
547EXPORT_SYMBOL_GPL(fwnode_property_match_string);
548
549/**
482 * device_get_next_child_node - Return the next child node handle for a device 550 * device_get_next_child_node - Return the next child node handle for a device
483 * @dev: Device to find the next child node for. 551 * @dev: Device to find the next child node for.
484 * @child: Handle to one of the device's child nodes or a null handle. 552 * @child: Handle to one of the device's child nodes or a null handle.
@@ -493,11 +561,7 @@ struct fwnode_handle *device_get_next_child_node(struct device *dev,
493 if (node) 561 if (node)
494 return &node->fwnode; 562 return &node->fwnode;
495 } else if (IS_ENABLED(CONFIG_ACPI)) { 563 } else if (IS_ENABLED(CONFIG_ACPI)) {
496 struct acpi_device *node; 564 return acpi_get_next_subnode(dev, child);
497
498 node = acpi_get_next_child(dev, to_acpi_node(child));
499 if (node)
500 return acpi_fwnode_handle(node);
501 } 565 }
502 return NULL; 566 return NULL;
503} 567}