linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mfd/syscon: Add device_node_to_regmap()
@ 2019-07-23 18:55 Paul Cercueil
  2019-07-24  2:35 ` Paul Cercueil
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Cercueil @ 2019-07-23 18:55 UTC (permalink / raw)
  To: Lee Jones, Arnd Bergmann; +Cc: od, linux-kernel, Paul Cercueil

device_node_to_regmap() is exactly like syscon_node_to_regmap(), but it
does not check that the node is compatible with "syscon".

The rationale behind this, is that one device node with a standard
compatible string "foo,bar" can be covered by multiple drivers sharing a
regmap, or by a single driver doing all the job without a regmap, but
these are implementation details which shouldn't reflect on the
devicetree.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/mfd/syscon.c       | 14 ++++++++++----
 include/linux/mfd/syscon.h |  6 ++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index b65e585fc8c6..3dcb56d4688d 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -51,9 +51,6 @@ static struct syscon *of_syscon_register(struct device_node *np)
 	struct regmap_config syscon_config = syscon_regmap_config;
 	struct resource res;
 
-	if (!of_device_is_compatible(np, "syscon"))
-		return ERR_PTR(-EINVAL);
-
 	syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
 	if (!syscon)
 		return ERR_PTR(-ENOMEM);
@@ -150,7 +147,7 @@ static struct syscon *of_syscon_register(struct device_node *np)
 	return ERR_PTR(ret);
 }
 
-struct regmap *syscon_node_to_regmap(struct device_node *np)
+struct regmap *device_node_to_regmap(struct device_node *np)
 {
 	struct syscon *entry, *syscon = NULL;
 
@@ -172,6 +169,15 @@ struct regmap *syscon_node_to_regmap(struct device_node *np)
 
 	return syscon->regmap;
 }
+EXPORT_SYMBOL_GPL(device_node_to_regmap);
+
+struct regmap *syscon_node_to_regmap(struct device_node *np)
+{
+	if (!of_device_is_compatible(np, "syscon"))
+		return ERR_PTR(-EINVAL);
+
+	return device_node_to_regmap(np);
+}
 EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
 
 struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h
index 8cfda0554381..112dc66262cc 100644
--- a/include/linux/mfd/syscon.h
+++ b/include/linux/mfd/syscon.h
@@ -17,12 +17,18 @@
 struct device_node;
 
 #ifdef CONFIG_MFD_SYSCON
+extern struct regmap *device_node_to_regmap(struct device_node *np);
 extern struct regmap *syscon_node_to_regmap(struct device_node *np);
 extern struct regmap *syscon_regmap_lookup_by_compatible(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_phandle(
 					struct device_node *np,
 					const char *property);
 #else
+static inline struct regmap *device_node_to_regmap(struct device_node *np)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 static inline struct regmap *syscon_node_to_regmap(struct device_node *np)
 {
 	return ERR_PTR(-ENOTSUPP);
-- 
2.21.0.593.g511ec345e18


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

* Re: [PATCH] mfd/syscon: Add device_node_to_regmap()
  2019-07-23 18:55 [PATCH] mfd/syscon: Add device_node_to_regmap() Paul Cercueil
@ 2019-07-24  2:35 ` Paul Cercueil
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Cercueil @ 2019-07-24  2:35 UTC (permalink / raw)
  To: Lee Jones, Arnd Bergmann; +Cc: od, linux-kernel

Actually I'll make a revised version and merge it with a patchset that
makes use of this feature.

-Paul



Le mar. 23 juil. 2019 à 14:55, Paul Cercueil <paul@crapouillou.net> a 
écrit :
> device_node_to_regmap() is exactly like syscon_node_to_regmap(), but 
> it
> does not check that the node is compatible with "syscon".
> 
> The rationale behind this, is that one device node with a standard
> compatible string "foo,bar" can be covered by multiple drivers 
> sharing a
> regmap, or by a single driver doing all the job without a regmap, but
> these are implementation details which shouldn't reflect on the
> devicetree.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  drivers/mfd/syscon.c       | 14 ++++++++++----
>  include/linux/mfd/syscon.h |  6 ++++++
>  2 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
> index b65e585fc8c6..3dcb56d4688d 100644
> --- a/drivers/mfd/syscon.c
> +++ b/drivers/mfd/syscon.c
> @@ -51,9 +51,6 @@ static struct syscon *of_syscon_register(struct 
> device_node *np)
>  	struct regmap_config syscon_config = syscon_regmap_config;
>  	struct resource res;
> 
> -	if (!of_device_is_compatible(np, "syscon"))
> -		return ERR_PTR(-EINVAL);
> -
>  	syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
>  	if (!syscon)
>  		return ERR_PTR(-ENOMEM);
> @@ -150,7 +147,7 @@ static struct syscon *of_syscon_register(struct 
> device_node *np)
>  	return ERR_PTR(ret);
>  }
> 
> -struct regmap *syscon_node_to_regmap(struct device_node *np)
> +struct regmap *device_node_to_regmap(struct device_node *np)
>  {
>  	struct syscon *entry, *syscon = NULL;
> 
> @@ -172,6 +169,15 @@ struct regmap *syscon_node_to_regmap(struct 
> device_node *np)
> 
>  	return syscon->regmap;
>  }
> +EXPORT_SYMBOL_GPL(device_node_to_regmap);
> +
> +struct regmap *syscon_node_to_regmap(struct device_node *np)
> +{
> +	if (!of_device_is_compatible(np, "syscon"))
> +		return ERR_PTR(-EINVAL);
> +
> +	return device_node_to_regmap(np);
> +}
>  EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
> 
>  struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
> diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h
> index 8cfda0554381..112dc66262cc 100644
> --- a/include/linux/mfd/syscon.h
> +++ b/include/linux/mfd/syscon.h
> @@ -17,12 +17,18 @@
>  struct device_node;
> 
>  #ifdef CONFIG_MFD_SYSCON
> +extern struct regmap *device_node_to_regmap(struct device_node *np);
>  extern struct regmap *syscon_node_to_regmap(struct device_node *np);
>  extern struct regmap *syscon_regmap_lookup_by_compatible(const char 
> *s);
>  extern struct regmap *syscon_regmap_lookup_by_phandle(
>  					struct device_node *np,
>  					const char *property);
>  #else
> +static inline struct regmap *device_node_to_regmap(struct 
> device_node *np)
> +{
> +	return ERR_PTR(-ENOTSUPP);
> +}
> +
>  static inline struct regmap *syscon_node_to_regmap(struct 
> device_node *np)
>  {
>  	return ERR_PTR(-ENOTSUPP);
> --
> 2.21.0.593.g511ec345e18
> 



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

end of thread, other threads:[~2019-07-24  2:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-23 18:55 [PATCH] mfd/syscon: Add device_node_to_regmap() Paul Cercueil
2019-07-24  2:35 ` Paul Cercueil

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).