Skip to content

Commit bc0500c

Browse files
Sakari Ailusrafaeljw
authored andcommitted
device property: Add fwnode_get_name for returning the name of a node
The fwnode framework did not have means to obtain the name of a node. Add that now, in form of the fwnode_get_name() function and a corresponding get_name fwnode op. OF and ACPI support is included. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Acked-by: Rob Herring <robh@kernel.org> (for OF) Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 87e5e95 commit bc0500c

6 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎drivers/acpi/property.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,31 @@ acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
13171317
args_count, args);
13181318
}
13191319

1320+
static const char *acpi_fwnode_get_name(const struct fwnode_handle *fwnode)
1321+
{
1322+
const struct acpi_device *adev;
1323+
struct fwnode_handle *parent;
1324+
1325+
/* Is this the root node? */
1326+
parent = fwnode_get_parent(fwnode);
1327+
if (!parent)
1328+
return "\\";
1329+
1330+
fwnode_handle_put(parent);
1331+
1332+
if (is_acpi_data_node(fwnode)) {
1333+
const struct acpi_data_node *dn = to_acpi_data_node(fwnode);
1334+
1335+
return dn->name;
1336+
}
1337+
1338+
adev = to_acpi_device_node(fwnode);
1339+
if (WARN_ON(!adev))
1340+
return NULL;
1341+
1342+
return acpi_device_bid(adev);
1343+
}
1344+
13201345
static struct fwnode_handle *
13211346
acpi_fwnode_get_parent(struct fwnode_handle *fwnode)
13221347
{
@@ -1357,6 +1382,7 @@ acpi_fwnode_device_get_match_data(const struct fwnode_handle *fwnode,
13571382
.get_parent = acpi_node_get_parent, \
13581383
.get_next_child_node = acpi_get_next_subnode, \
13591384
.get_named_child_node = acpi_fwnode_get_named_child_node, \
1385+
.get_name = acpi_fwnode_get_name, \
13601386
.get_reference_args = acpi_fwnode_get_reference_args, \
13611387
.graph_get_next_endpoint = \
13621388
acpi_graph_get_next_endpoint, \

‎drivers/base/property.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ int device_add_properties(struct device *dev,
556556
}
557557
EXPORT_SYMBOL_GPL(device_add_properties);
558558

559+
/**
560+
* fwnode_get_name - Return the name of a node
561+
* @fwnode: The firmware node
562+
*
563+
* Returns a pointer to the node name.
564+
*/
565+
const char *fwnode_get_name(const struct fwnode_handle *fwnode)
566+
{
567+
return fwnode_call_ptr_op(fwnode, get_name);
568+
}
569+
559570
/**
560571
* fwnode_get_parent - Return parent firwmare node
561572
* @fwnode: Firmware whose parent is retrieved

‎drivers/base/swnode.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ static int software_node_read_string_array(const struct fwnode_handle *fwnode,
515515
propname, val, nval);
516516
}
517517

518+
static const char *
519+
software_node_get_name(const struct fwnode_handle *fwnode)
520+
{
521+
const struct swnode *swnode = to_swnode(fwnode);
522+
523+
if (!swnode)
524+
return "(null)";
525+
526+
return kobject_name(&swnode->kobj);
527+
}
528+
518529
static struct fwnode_handle *
519530
software_node_get_parent(const struct fwnode_handle *fwnode)
520531
{
@@ -615,6 +626,7 @@ static const struct fwnode_operations software_node_ops = {
615626
.property_present = software_node_property_present,
616627
.property_read_int_array = software_node_read_int_array,
617628
.property_read_string_array = software_node_read_string_array,
629+
.get_name = software_node_get_name,
618630
.get_parent = software_node_get_parent,
619631
.get_next_child_node = software_node_get_next_child,
620632
.get_named_child_node = software_node_get_named_child_node,

‎drivers/of/property.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,11 @@ of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
872872
of_property_count_strings(node, propname);
873873
}
874874

875+
static const char *of_fwnode_get_name(const struct fwnode_handle *fwnode)
876+
{
877+
return kbasename(to_of_node(fwnode)->full_name);
878+
}
879+
875880
static struct fwnode_handle *
876881
of_fwnode_get_parent(const struct fwnode_handle *fwnode)
877882
{
@@ -993,6 +998,7 @@ const struct fwnode_operations of_fwnode_ops = {
993998
.property_present = of_fwnode_property_present,
994999
.property_read_int_array = of_fwnode_property_read_int_array,
9951000
.property_read_string_array = of_fwnode_property_read_string_array,
1001+
.get_name = of_fwnode_get_name,
9961002
.get_parent = of_fwnode_get_parent,
9971003
.get_next_child_node = of_fwnode_get_next_child_node,
9981004
.get_named_child_node = of_fwnode_get_named_child_node,

‎include/linux/fwnode.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct fwnode_reference_args {
5656
* otherwise.
5757
* @property_read_string_array: Read an array of string properties. Return zero
5858
* on success, a negative error code otherwise.
59+
* @get_name: Return the name of an fwnode.
5960
* @get_parent: Return the parent of an fwnode.
6061
* @get_next_child_node: Return the next child node in an iteration.
6162
* @get_named_child_node: Return a child node with a given name.
@@ -82,6 +83,7 @@ struct fwnode_operations {
8283
(*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
8384
const char *propname, const char **val,
8485
size_t nval);
86+
const char *(*get_name)(const struct fwnode_handle *fwnode);
8587
struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
8688
struct fwnode_handle *
8789
(*get_next_child_node)(const struct fwnode_handle *fwnode,

‎include/linux/property.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fwnode,
8080
const char *name,
8181
unsigned int index);
8282

83+
const char *fwnode_get_name(const struct fwnode_handle *fwnode);
8384
struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
8485
struct fwnode_handle *fwnode_get_next_parent(
8586
struct fwnode_handle *fwnode);

0 commit comments

Comments
 (0)