Skip to content

Commit 3e3119d

Browse files
Sakari Ailusrafaeljw
authored andcommitted
device property: Introduce fwnode_property_get_reference_args
The new fwnode_property_get_reference_args() interface amends the fwnode property API with the functionality of both of_parse_phandle_with_args() and __acpi_node_get_property_reference(). The semantics is slightly different: the cells property is ignored on ACPI as the number of arguments can be explicitly obtained from the firmware interface. Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 37ba983 commit 3e3119d

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

drivers/acpi/property.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,32 @@ acpi_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
11951195
return NULL;
11961196
}
11971197

1198+
static int
1199+
acpi_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
1200+
const char *prop, const char *nargs_prop,
1201+
unsigned int args_count, unsigned int index,
1202+
struct fwnode_reference_args *args)
1203+
{
1204+
struct acpi_reference_args acpi_args;
1205+
unsigned int i;
1206+
int ret;
1207+
1208+
ret = __acpi_node_get_property_reference(fwnode, prop, index,
1209+
args_count, &acpi_args);
1210+
if (ret < 0)
1211+
return ret;
1212+
if (!args)
1213+
return 0;
1214+
1215+
args->nargs = acpi_args.nargs;
1216+
args->fwnode = acpi_fwnode_handle(acpi_args.adev);
1217+
1218+
for (i = 0; i < NR_FWNODE_REFERENCE_ARGS; i++)
1219+
args->args[i] = i < acpi_args.nargs ? acpi_args.args[i] : 0;
1220+
1221+
return 0;
1222+
}
1223+
11981224
static struct fwnode_handle *
11991225
acpi_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
12001226
struct fwnode_handle *prev)
@@ -1248,6 +1274,7 @@ static int acpi_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
12481274
.get_parent = acpi_node_get_parent, \
12491275
.get_next_child_node = acpi_get_next_subnode, \
12501276
.get_named_child_node = acpi_fwnode_get_named_child_node, \
1277+
.get_reference_args = acpi_fwnode_get_reference_args, \
12511278
.graph_get_next_endpoint = \
12521279
acpi_fwnode_graph_get_next_endpoint, \
12531280
.graph_get_remote_endpoint = \

drivers/base/property.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,34 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
665665
}
666666
EXPORT_SYMBOL_GPL(fwnode_property_match_string);
667667

668+
/**
669+
* fwnode_property_get_reference_args() - Find a reference with arguments
670+
* @fwnode: Firmware node where to look for the reference
671+
* @prop: The name of the property
672+
* @nargs_prop: The name of the property telling the number of
673+
* arguments in the referred node. NULL if @nargs is known,
674+
* otherwise @nargs is ignored. Only relevant on OF.
675+
* @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL.
676+
* @index: Index of the reference, from zero onwards.
677+
* @args: Result structure with reference and integer arguments.
678+
*
679+
* Obtain a reference based on a named property in an fwnode, with
680+
* integer arguments.
681+
*
682+
* Caller is responsible to call fwnode_handle_put() on the returned
683+
* args->fwnode pointer.
684+
*
685+
*/
686+
int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
687+
const char *prop, const char *nargs_prop,
688+
unsigned int nargs, unsigned int index,
689+
struct fwnode_reference_args *args)
690+
{
691+
return fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
692+
nargs, index, args);
693+
}
694+
EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args);
695+
668696
static int property_copy_string_array(struct property_entry *dst,
669697
const struct property_entry *src)
670698
{

drivers/of/property.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,36 @@ of_fwnode_get_named_child_node(const struct fwnode_handle *fwnode,
891891
return NULL;
892892
}
893893

894+
static int
895+
of_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
896+
const char *prop, const char *nargs_prop,
897+
unsigned int nargs, unsigned int index,
898+
struct fwnode_reference_args *args)
899+
{
900+
struct of_phandle_args of_args;
901+
unsigned int i;
902+
int ret;
903+
904+
if (nargs_prop)
905+
ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
906+
nargs_prop, index, &of_args);
907+
else
908+
ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
909+
nargs, index, &of_args);
910+
if (ret < 0)
911+
return ret;
912+
if (!args)
913+
return 0;
914+
915+
args->nargs = of_args.args_count;
916+
args->fwnode = of_fwnode_handle(of_args.np);
917+
918+
for (i = 0; i < NR_FWNODE_REFERENCE_ARGS; i++)
919+
args->args[i] = i < of_args.args_count ? of_args.args[i] : 0;
920+
921+
return 0;
922+
}
923+
894924
static struct fwnode_handle *
895925
of_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
896926
struct fwnode_handle *prev)
@@ -949,6 +979,7 @@ const struct fwnode_operations of_fwnode_ops = {
949979
.get_parent = of_fwnode_get_parent,
950980
.get_next_child_node = of_fwnode_get_next_child_node,
951981
.get_named_child_node = of_fwnode_get_named_child_node,
982+
.get_reference_args = of_fwnode_get_reference_args,
952983
.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
953984
.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
954985
.graph_get_port_parent = of_fwnode_graph_get_port_parent,

include/linux/fwnode.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ struct fwnode_endpoint {
3333
const struct fwnode_handle *local_fwnode;
3434
};
3535

36+
#define NR_FWNODE_REFERENCE_ARGS 8
37+
38+
/**
39+
* struct fwnode_reference_args - Fwnode reference with additional arguments
40+
* @fwnode:- A reference to the base fwnode
41+
* @nargs: Number of elements in @args array
42+
* @args: Integer arguments on the fwnode
43+
*/
44+
struct fwnode_reference_args {
45+
struct fwnode_handle *fwnode;
46+
unsigned int nargs;
47+
unsigned int args[NR_FWNODE_REFERENCE_ARGS];
48+
};
49+
3650
/**
3751
* struct fwnode_operations - Operations for fwnode interface
3852
* @get: Get a reference to an fwnode.
@@ -46,6 +60,7 @@ struct fwnode_endpoint {
4660
* @get_parent: Return the parent of an fwnode.
4761
* @get_next_child_node: Return the next child node in an iteration.
4862
* @get_named_child_node: Return a child node with a given name.
63+
* @get_reference_args: Return a reference pointed to by a property, with args
4964
* @graph_get_next_endpoint: Return an endpoint node in an iteration.
5065
* @graph_get_remote_endpoint: Return the remote endpoint node of a local
5166
* endpoint node.
@@ -73,6 +88,10 @@ struct fwnode_operations {
7388
struct fwnode_handle *
7489
(*get_named_child_node)(const struct fwnode_handle *fwnode,
7590
const char *name);
91+
int (*get_reference_args)(const struct fwnode_handle *fwnode,
92+
const char *prop, const char *nargs_prop,
93+
unsigned int nargs, unsigned int index,
94+
struct fwnode_reference_args *args);
7695
struct fwnode_handle *
7796
(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
7897
struct fwnode_handle *prev);

include/linux/property.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ int fwnode_property_read_string(const struct fwnode_handle *fwnode,
7373
const char *propname, const char **val);
7474
int fwnode_property_match_string(const struct fwnode_handle *fwnode,
7575
const char *propname, const char *string);
76+
int fwnode_property_get_reference_args(const struct fwnode_handle *fwnode,
77+
const char *prop, const char *nargs_prop,
78+
unsigned int nargs, unsigned int index,
79+
struct fwnode_reference_args *args);
7680

7781
struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode);
7882
struct fwnode_handle *fwnode_get_next_parent(

0 commit comments

Comments
 (0)