Skip to content

Commit 68ef162

Browse files
Sakari Ailusrkhuangtao
authored andcommitted
BACKPORT: 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 <sakari.ailus@linux.intel.com> (cherry picked from commit 3e3119d3088f41106f3581d39e7694a50ca3fc02) Signed-off-by: Brian J Lovin <brian.j.lovin@intel.com> Brian L: Had to de-constify this commit, and picks are unclean due to the number of commits skipped for this kernel. Conflicts: drivers/acpi/property.c drivers/base/property.c include/linux/fwnode.h BUG=b:64133998 TEST=media device topology shows subdevs registered successfully TEST=no camera regression Change-Id: I982255df1aabaadb9de09fc71e6db5c4b99b0e02 Reviewed-on: https://chromium-review.googlesource.com/693682 Commit-Ready: Tomasz Figa <tfiga@chromium.org> Tested-by: Hyungwoo Yang <hyungwoo.yang@intel.com> Reviewed-by: Tomasz Figa <tfiga@chromium.org> Signed-off-by: Jacob Chen <jacob2.chen@rock-chips.com>
1 parent bc255db commit 68ef162

5 files changed

Lines changed: 109 additions & 0 deletions

File tree

drivers/acpi/property.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,32 @@ acpi_fwnode_get_named_child_node(struct fwnode_handle *fwnode,
11871187
return NULL;
11881188
}
11891189

1190+
static int
1191+
acpi_fwnode_get_reference_args(struct fwnode_handle *fwnode,
1192+
const char *prop, const char *nargs_prop,
1193+
unsigned int args_count, unsigned int index,
1194+
struct fwnode_reference_args *args)
1195+
{
1196+
struct acpi_reference_args acpi_args;
1197+
unsigned int i;
1198+
int ret;
1199+
1200+
ret = __acpi_node_get_property_reference(fwnode, prop, index,
1201+
args_count, &acpi_args);
1202+
if (ret < 0)
1203+
return ret;
1204+
if (!args)
1205+
return 0;
1206+
1207+
args->nargs = acpi_args.nargs;
1208+
args->fwnode = acpi_fwnode_handle(acpi_args.adev);
1209+
1210+
for (i = 0; i < NR_OF_FWNODE_REFERENCE_ARGS; i++)
1211+
args->args[i] = i < acpi_args.nargs ? acpi_args.args[i] : 0;
1212+
1213+
return 0;
1214+
}
1215+
11901216
static struct fwnode_handle *
11911217
acpi_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
11921218
struct fwnode_handle *prev)
@@ -1231,6 +1257,7 @@ const struct fwnode_operations acpi_fwnode_ops = {
12311257
.get_parent = acpi_node_get_parent,
12321258
.get_next_child_node = acpi_get_next_subnode,
12331259
.get_named_child_node = acpi_fwnode_get_named_child_node,
1260+
.get_reference_args = acpi_fwnode_get_reference_args,
12341261
.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
12351262
.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
12361263
.graph_get_port_parent = acpi_node_get_parent,

drivers/base/property.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,34 @@ int fwnode_property_match_string(struct fwnode_handle *fwnode,
652652
}
653653
EXPORT_SYMBOL_GPL(fwnode_property_match_string);
654654

655+
/**
656+
* fwnode_property_get_reference_args() - Find a reference with arguments
657+
* @fwnode: Firmware node where to look for the reference
658+
* @prop: The name of the property
659+
* @nargs_prop: The name of the property telling the number of
660+
* arguments in the referred node. NULL if @nargs is known,
661+
* otherwise @nargs is ignored. Only relevant on OF.
662+
* @nargs: Number of arguments. Ignored if @nargs_prop is non-NULL.
663+
* @index: Index of the reference, from zero onwards.
664+
* @args: Result structure with reference and integer arguments.
665+
*
666+
* Obtain a reference based on a named property in an fwnode, with
667+
* integer arguments.
668+
*
669+
* Caller is responsible to call fwnode_handle_put() on the returned
670+
* args->fwnode pointer.
671+
*
672+
*/
673+
int fwnode_property_get_reference_args(struct fwnode_handle *fwnode,
674+
const char *prop, const char *nargs_prop,
675+
unsigned int nargs, unsigned int index,
676+
struct fwnode_reference_args *args)
677+
{
678+
return fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
679+
nargs, index, args);
680+
}
681+
EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args);
682+
655683
/**
656684
* pset_free_set - releases memory allocated for copied property set
657685
* @pset: Property set to release

drivers/of/property.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,36 @@ of_fwnode_get_named_child_node(struct fwnode_handle *fwnode,
849849
return NULL;
850850
}
851851

852+
static int
853+
of_fwnode_get_reference_args(struct fwnode_handle *fwnode,
854+
const char *prop, const char *nargs_prop,
855+
unsigned int nargs, unsigned int index,
856+
struct fwnode_reference_args *args)
857+
{
858+
struct of_phandle_args of_args;
859+
unsigned int i;
860+
int ret;
861+
862+
if (nargs_prop)
863+
ret = of_parse_phandle_with_args(to_of_node(fwnode), prop,
864+
nargs_prop, index, &of_args);
865+
else
866+
ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop,
867+
nargs, index, &of_args);
868+
if (ret < 0)
869+
return ret;
870+
if (!args)
871+
return 0;
872+
873+
args->nargs = of_args.args_count;
874+
args->fwnode = of_fwnode_handle(of_args.np);
875+
876+
for (i = 0; i < NR_OF_FWNODE_REFERENCE_ARGS; i++)
877+
args->args[i] = i < of_args.args_count ? of_args.args[i] : 0;
878+
879+
return 0;
880+
}
881+
852882
static struct fwnode_handle *
853883
of_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
854884
struct fwnode_handle *prev)
@@ -907,6 +937,7 @@ const struct fwnode_operations of_fwnode_ops = {
907937
.get_parent = of_fwnode_get_parent,
908938
.get_next_child_node = of_fwnode_get_next_child_node,
909939
.get_named_child_node = of_fwnode_get_named_child_node,
940+
.get_reference_args = of_fwnode_get_reference_args,
910941
.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
911942
.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
912943
.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
@@ -43,6 +43,20 @@ struct fwnode_endpoint {
4343
const struct fwnode_handle *local_fwnode;
4444
};
4545

46+
#define NR_OF_FWNODE_REFERENCE_ARGS 8
47+
48+
/**
49+
* struct fwnode_reference_args - Fwnode reference with additional arguments
50+
* @fwnode:- A reference to the base fwnode
51+
* @nargs: Number of elements in @args array
52+
* @args: Integer arguments on the fwnode
53+
*/
54+
struct fwnode_reference_args {
55+
struct fwnode_handle *fwnode;
56+
unsigned int nargs;
57+
unsigned int args[NR_OF_FWNODE_REFERENCE_ARGS];
58+
};
59+
4660
/**
4761
* struct fwnode_operations - Operations for fwnode interface
4862
* @get: Get a reference to an fwnode.
@@ -56,6 +70,7 @@ struct fwnode_endpoint {
5670
* @get_parent: Return the parent of an fwnode.
5771
* @get_next_child_node: Return the next child node in an iteration.
5872
* @get_named_child_node: Return a child node with a given name.
73+
* @get_reference_args: Return a reference pointed to by a property, with args
5974
* @graph_get_next_endpoint: Return an endpoint node in an iteration.
6075
* @graph_get_remote_endpoint: Return the remote endpoint node of a local
6176
* endpoint node.
@@ -81,6 +96,10 @@ struct fwnode_operations {
8196
struct fwnode_handle *child);
8297
struct fwnode_handle *
8398
(*get_named_child_node)(struct fwnode_handle *fwnode, const char *name);
99+
int (*get_reference_args)(struct fwnode_handle *fwnode,
100+
const char *prop, const char *nargs_prop,
101+
unsigned int nargs, unsigned int index,
102+
struct fwnode_reference_args *args);
84103
struct fwnode_handle *
85104
(*graph_get_next_endpoint)(struct fwnode_handle *fwnode,
86105
struct fwnode_handle *prev);

include/linux/property.h

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

7680
struct fwnode_handle *fwnode_get_parent(struct fwnode_handle *fwnode);
7781
struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode);

0 commit comments

Comments
 (0)