linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] of: Add of_machine_compatible_match()
@ 2018-07-30 13:15 Michael Ellerman
  2018-07-30 13:15 ` [PATCH 2/2] powerpc: Use of_machine_compatible_match() Michael Ellerman
  2018-07-30 14:06 ` [PATCH 1/2] of: Add of_machine_compatible_match() Rob Herring
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-07-30 13:15 UTC (permalink / raw)
  To: devicetree, robh+dt, frowand.list; +Cc: linuxppc-dev

We have of_machine_is_compatible() to check if a machine is compatible
with a single compatible string. However some code is able to support
multiple compatible boards, and so wants to check for one of many
compatible strings.

So add of_machine_compatible_match() which takes a NULL terminated
array of compatible strings to check against the root node's
compatible property.

Compared to an open coded match this is slightly more self
documenting, and also avoids the caller needing to juggle the root
node either directly or via of_find_node_by_path().

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 drivers/of/base.c  | 21 +++++++++++++++++++++
 include/linux/of.h |  6 ++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 848f549164cd..603716ba8513 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -505,6 +505,27 @@ int of_device_compatible_match(struct device_node *device,
 	return score;
 }
 
+/**
+ * of_machine_compatible_match - Test root of device tree against a compatible array
+ * @compats: NULL terminated array of compatible strings to look for in root node's compatible property.
+ *
+ * Returns true if the root node has any of the given compatible values in its
+ * compatible property.
+ */
+bool of_machine_compatible_match(const char *const *compats)
+{
+	struct device_node *root;
+	int rc = 0;
+
+	root = of_node_get(of_root);
+	if (root) {
+		rc = of_device_compatible_match(root, compats);
+		of_node_put(root);
+	}
+
+	return rc != 0;
+}
+
 /**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
  * @compat: compatible string to look for in root node's compatible property.
diff --git a/include/linux/of.h b/include/linux/of.h
index 4d25e4f952d9..05e3e23a3a57 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -389,6 +389,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern int of_alias_get_highest_id(const char *stem);
 
 extern int of_machine_is_compatible(const char *compat);
+extern bool of_machine_compatible_match(const char *const *compats);
 
 extern int of_add_property(struct device_node *np, struct property *prop);
 extern int of_remove_property(struct device_node *np, struct property *prop);
@@ -877,6 +878,11 @@ static inline int of_machine_is_compatible(const char *compat)
 	return 0;
 }
 
+static inline bool of_machine_compatible_match(const char *const *compats)
+{
+	return false;
+}
+
 static inline bool of_console_check(const struct device_node *dn, const char *name, int index)
 {
 	return false;
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] powerpc: Use of_machine_compatible_match()
  2018-07-30 13:15 [PATCH 1/2] of: Add of_machine_compatible_match() Michael Ellerman
@ 2018-07-30 13:15 ` Michael Ellerman
  2018-07-30 14:14   ` Rob Herring
  2018-07-30 14:06 ` [PATCH 1/2] of: Add of_machine_compatible_match() Rob Herring
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2018-07-30 13:15 UTC (permalink / raw)
  To: devicetree, robh+dt, frowand.list; +Cc: linuxppc-dev

Use of_machine_compatible_match() in platform code rather than open
coding.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/platforms/40x/ppc40x_simple.c    | 2 +-
 arch/powerpc/platforms/512x/mpc512x_generic.c | 2 +-
 arch/powerpc/platforms/52xx/lite5200.c        | 2 +-
 arch/powerpc/platforms/52xx/media5200.c       | 2 +-
 arch/powerpc/platforms/52xx/mpc5200_simple.c  | 2 +-
 arch/powerpc/platforms/83xx/mpc830x_rdb.c     | 2 +-
 arch/powerpc/platforms/83xx/mpc831x_rdb.c     | 2 +-
 arch/powerpc/platforms/83xx/mpc837x_rdb.c     | 2 +-
 arch/powerpc/platforms/85xx/corenet_generic.c | 2 +-
 arch/powerpc/platforms/85xx/tqm85xx.c         | 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)


Tested the corenet_generic.c change on a p5020ds, the rest are untested owing to
lack of hardware.

diff --git a/arch/powerpc/platforms/40x/ppc40x_simple.c b/arch/powerpc/platforms/40x/ppc40x_simple.c
index 2a050007bbae..f401a8add141 100644
--- a/arch/powerpc/platforms/40x/ppc40x_simple.c
+++ b/arch/powerpc/platforms/40x/ppc40x_simple.c
@@ -63,7 +63,7 @@ static const char * const board[] __initconst = {
 
 static int __init ppc40x_probe(void)
 {
-	if (of_device_compatible_match(of_root, board)) {
+	if (of_machine_compatible_match(board)) {
 		pci_set_flags(PCI_REASSIGN_ALL_RSRC);
 		return 1;
 	}
diff --git a/arch/powerpc/platforms/512x/mpc512x_generic.c b/arch/powerpc/platforms/512x/mpc512x_generic.c
index bf884d3075e4..952ea53d4829 100644
--- a/arch/powerpc/platforms/512x/mpc512x_generic.c
+++ b/arch/powerpc/platforms/512x/mpc512x_generic.c
@@ -38,7 +38,7 @@ static const char * const board[] __initconst = {
  */
 static int __init mpc512x_generic_probe(void)
 {
-	if (!of_device_compatible_match(of_root, board))
+	if (!of_machine_compatible_match(board))
 		return 0;
 
 	mpc512x_init_early();
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index c94c385cc919..5f11e906e02c 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -183,7 +183,7 @@ static const char * const board[] __initconst = {
  */
 static int __init lite5200_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 define_machine(lite5200) {
diff --git a/arch/powerpc/platforms/52xx/media5200.c b/arch/powerpc/platforms/52xx/media5200.c
index 1fcab233d2f2..8641bb55c8e8 100644
--- a/arch/powerpc/platforms/52xx/media5200.c
+++ b/arch/powerpc/platforms/52xx/media5200.c
@@ -242,7 +242,7 @@ static const char * const board[] __initconst = {
  */
 static int __init media5200_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 define_machine(media5200_platform) {
diff --git a/arch/powerpc/platforms/52xx/mpc5200_simple.c b/arch/powerpc/platforms/52xx/mpc5200_simple.c
index a80c6278d515..7b8b3be0f159 100644
--- a/arch/powerpc/platforms/52xx/mpc5200_simple.c
+++ b/arch/powerpc/platforms/52xx/mpc5200_simple.c
@@ -70,7 +70,7 @@ static const char *board[] __initdata = {
  */
 static int __init mpc5200_simple_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 define_machine(mpc5200_simple_platform) {
diff --git a/arch/powerpc/platforms/83xx/mpc830x_rdb.c b/arch/powerpc/platforms/83xx/mpc830x_rdb.c
index 272c41c387b9..7c0cd27e71e7 100644
--- a/arch/powerpc/platforms/83xx/mpc830x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc830x_rdb.c
@@ -43,7 +43,7 @@ static const char *board[] __initdata = {
  */
 static int __init mpc830x_rdb_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 machine_device_initcall(mpc830x_rdb, mpc83xx_declare_of_platform_devices);
diff --git a/arch/powerpc/platforms/83xx/mpc831x_rdb.c b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
index fd80fd570e67..3718db1c74e4 100644
--- a/arch/powerpc/platforms/83xx/mpc831x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc831x_rdb.c
@@ -43,7 +43,7 @@ static const char *board[] __initdata = {
  */
 static int __init mpc831x_rdb_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 machine_device_initcall(mpc831x_rdb, mpc83xx_declare_of_platform_devices);
diff --git a/arch/powerpc/platforms/83xx/mpc837x_rdb.c b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
index 0c55fa6af2d5..08c8434d895c 100644
--- a/arch/powerpc/platforms/83xx/mpc837x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc837x_rdb.c
@@ -70,7 +70,7 @@ static const char * const board[] __initconst = {
  */
 static int __init mpc837x_rdb_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 define_machine(mpc837x_rdb) {
diff --git a/arch/powerpc/platforms/85xx/corenet_generic.c b/arch/powerpc/platforms/85xx/corenet_generic.c
index ac191a7a1337..8a2a32b75c66 100644
--- a/arch/powerpc/platforms/85xx/corenet_generic.c
+++ b/arch/powerpc/platforms/85xx/corenet_generic.c
@@ -174,7 +174,7 @@ static int __init corenet_generic_probe(void)
 	extern struct smp_ops_t smp_85xx_ops;
 #endif
 
-	if (of_device_compatible_match(of_root, boards))
+	if (of_machine_compatible_match(boards))
 		return 1;
 
 	/* Check if we're running under the Freescale hypervisor */
diff --git a/arch/powerpc/platforms/85xx/tqm85xx.c b/arch/powerpc/platforms/85xx/tqm85xx.c
index 9fc20a37835e..2172e93a7c67 100644
--- a/arch/powerpc/platforms/85xx/tqm85xx.c
+++ b/arch/powerpc/platforms/85xx/tqm85xx.c
@@ -122,7 +122,7 @@ static const char * const board[] __initconst = {
  */
 static int __init tqm85xx_probe(void)
 {
-	return of_device_compatible_match(of_root, board);
+	return of_machine_compatible_match(board);
 }
 
 define_machine(tqm85xx) {
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] of: Add of_machine_compatible_match()
  2018-07-30 13:15 [PATCH 1/2] of: Add of_machine_compatible_match() Michael Ellerman
  2018-07-30 13:15 ` [PATCH 2/2] powerpc: Use of_machine_compatible_match() Michael Ellerman
@ 2018-07-30 14:06 ` Rob Herring
  2018-08-03 10:31   ` Michael Ellerman
  1 sibling, 1 reply; 5+ messages in thread
From: Rob Herring @ 2018-07-30 14:06 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: devicetree, Frank Rowand, linuxppc-dev

On Mon, Jul 30, 2018 at 7:15 AM Michael Ellerman <mpe@ellerman.id.au> wrote:
>
> We have of_machine_is_compatible() to check if a machine is compatible
> with a single compatible string. However some code is able to support
> multiple compatible boards, and so wants to check for one of many
> compatible strings.
>
> So add of_machine_compatible_match() which takes a NULL terminated
> array of compatible strings to check against the root node's
> compatible property.
>
> Compared to an open coded match this is slightly more self
> documenting, and also avoids the caller needing to juggle the root
> node either directly or via of_find_node_by_path().
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  drivers/of/base.c  | 21 +++++++++++++++++++++
>  include/linux/of.h |  6 ++++++
>  2 files changed, 27 insertions(+)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 848f549164cd..603716ba8513 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -505,6 +505,27 @@ int of_device_compatible_match(struct device_node *device,
>         return score;
>  }
>
> +/**
> + * of_machine_compatible_match - Test root of device tree against a compatible array
> + * @compats: NULL terminated array of compatible strings to look for in root node's compatible property.
> + *
> + * Returns true if the root node has any of the given compatible values in its
> + * compatible property.
> + */
> +bool of_machine_compatible_match(const char *const *compats)
> +{
> +       struct device_node *root;
> +       int rc = 0;
> +
> +       root = of_node_get(of_root);
> +       if (root) {
> +               rc = of_device_compatible_match(root, compats);
> +               of_node_put(root);
> +       }
> +
> +       return rc != 0;
> +}
> +
>  /**
>   * of_machine_is_compatible - Test root of device tree for a given compatible value
>   * @compat: compatible string to look for in root node's compatible property.
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 4d25e4f952d9..05e3e23a3a57 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -389,6 +389,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem);
>  extern int of_alias_get_highest_id(const char *stem);
>
>  extern int of_machine_is_compatible(const char *compat);
> +extern bool of_machine_compatible_match(const char *const *compats);

Would be nice if of_machine_is_compatible could be implemented in
terms of of_machine_compatible_match like this:

int of_machine_is_compatible(const char *compat)
{
  const char *compats[] = { compat, NULL };
  return of_machine_is_compatible(compats);
}

Probably can be inline too.

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] powerpc: Use of_machine_compatible_match()
  2018-07-30 13:15 ` [PATCH 2/2] powerpc: Use of_machine_compatible_match() Michael Ellerman
@ 2018-07-30 14:14   ` Rob Herring
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2018-07-30 14:14 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: devicetree, Frank Rowand, linuxppc-dev

On Mon, Jul 30, 2018 at 7:15 AM Michael Ellerman <mpe@ellerman.id.au> wrote:
>
> Use of_machine_compatible_match() in platform code rather than open
> coding.

This is good because I want to get rid of of_root being used outside
of drivers/of/. Can you also convert this one:

drivers/clk/clk-qoriq.c:            of_device_is_compatible(of_root,
"fsl,ls1021a")) {

>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  arch/powerpc/platforms/40x/ppc40x_simple.c    | 2 +-
>  arch/powerpc/platforms/512x/mpc512x_generic.c | 2 +-
>  arch/powerpc/platforms/52xx/lite5200.c        | 2 +-
>  arch/powerpc/platforms/52xx/media5200.c       | 2 +-
>  arch/powerpc/platforms/52xx/mpc5200_simple.c  | 2 +-
>  arch/powerpc/platforms/83xx/mpc830x_rdb.c     | 2 +-
>  arch/powerpc/platforms/83xx/mpc831x_rdb.c     | 2 +-
>  arch/powerpc/platforms/83xx/mpc837x_rdb.c     | 2 +-
>  arch/powerpc/platforms/85xx/corenet_generic.c | 2 +-
>  arch/powerpc/platforms/85xx/tqm85xx.c         | 2 +-
>  10 files changed, 10 insertions(+), 10 deletions(-)

Acked-by: Rob Herring <robh@kernel.org>

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] of: Add of_machine_compatible_match()
  2018-07-30 14:06 ` [PATCH 1/2] of: Add of_machine_compatible_match() Rob Herring
@ 2018-08-03 10:31   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2018-08-03 10:31 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree, Frank Rowand, linuxppc-dev

Rob Herring <robh+dt@kernel.org> writes:
> On Mon, Jul 30, 2018 at 7:15 AM Michael Ellerman <mpe@ellerman.id.au> wrote:
...
>> diff --git a/include/linux/of.h b/include/linux/of.h
>> index 4d25e4f952d9..05e3e23a3a57 100644
>> --- a/include/linux/of.h
>> +++ b/include/linux/of.h
>> @@ -389,6 +389,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem);
>>  extern int of_alias_get_highest_id(const char *stem);
>>
>>  extern int of_machine_is_compatible(const char *compat);
>> +extern bool of_machine_compatible_match(const char *const *compats);
>
> Would be nice if of_machine_is_compatible could be implemented in
> terms of of_machine_compatible_match like this:
>
> int of_machine_is_compatible(const char *compat)
> {
>   const char *compats[] = { compat, NULL };
>   return of_machine_is_compatible(compats);
> }
>
> Probably can be inline too.

Yeah good idea, I'll do a v2 next week.

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-03 10:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30 13:15 [PATCH 1/2] of: Add of_machine_compatible_match() Michael Ellerman
2018-07-30 13:15 ` [PATCH 2/2] powerpc: Use of_machine_compatible_match() Michael Ellerman
2018-07-30 14:14   ` Rob Herring
2018-07-30 14:06 ` [PATCH 1/2] of: Add of_machine_compatible_match() Rob Herring
2018-08-03 10:31   ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).