public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies
@ 2023-10-04 12:10 Naresh Solanki
  2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Naresh Solanki @ 2023-10-04 12:10 UTC (permalink / raw)
  To: broonie, zev, Liam Girdwood, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: Naresh Solanki, linux-kernel, devicetree

Add support for multiple supplies.

Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com>
---
 .../devicetree/bindings/regulator/regulator-output.yaml  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/regulator-output.yaml b/Documentation/devicetree/bindings/regulator/regulator-output.yaml
index 078b37a1a71a..6d077f123729 100644
--- a/Documentation/devicetree/bindings/regulator/regulator-output.yaml
+++ b/Documentation/devicetree/bindings/regulator/regulator-output.yaml
@@ -21,13 +21,13 @@ properties:
   compatible:
     const: regulator-output
 
-  vout-supply:
+patternProperties:
+  ".*-supply":
     description:
       Phandle of the regulator supplying the output.
 
 required:
   - compatible
-  - vout-supply
 
 additionalProperties: false
 
@@ -37,3 +37,8 @@ examples:
           compatible = "regulator-output";
           vout-supply = <&output_reg>;
       };
+      output1 {
+          compatible = "regulator-output";
+          sw0-supply = <&output_reg0>;
+          sw1-supply = <&output_reg2>;
+      };

base-commit: f9a1d31874c383f58bb4f89bfe79b764682cd026
-- 
2.41.0


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

* [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT
  2023-10-04 12:10 [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Naresh Solanki
@ 2023-10-04 12:10 ` Naresh Solanki
  2023-10-04 18:11   ` kernel test robot
  2023-10-10 16:47   ` kernel test robot
  2023-10-04 12:10 ` [PATCH v2 3/3] regulator: userspace-consumer: Update name Naresh Solanki
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Naresh Solanki @ 2023-10-04 12:10 UTC (permalink / raw)
  To: broonie, zev, Liam Girdwood; +Cc: Naresh Solanki, linux-kernel

From: Naresh Solanki <Naresh.Solanki@9elements.com>

Instead of hardcoding a single supply, retrieve supplies from DT.

Signed-off-by: Naresh Solanki <Naresh.Solanki@9elements.com>
---
Changes in V2:
- Use strlen for SUPPLY_SUFFIX_LEN,
- Remove bracket for single line statements in if statement.
- Remove extra space in variable declaration.
- Simplify multi line statement by calculating size in seperate
  variable.
- Add function prop_supply_name & simplify code.
- Use devm_kstrdup instead to simplify code further.
- Update DT binding to align with changes.
---
 drivers/regulator/userspace-consumer.c | 51 ++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 97f075ed68c9..13c0a86ab32c 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -115,12 +115,41 @@ static const struct attribute_group attr_group = {
 	.is_visible =  attr_visible,
 };
 
+#define SUPPLY_SUFFIX "-supply"
+#define SUPPLY_SUFFIX_LEN strlen(SUPPLY_SUFFIX)
+
+static size_t prop_supply_name(char *prop_name)
+{
+	int len = strlen(prop_name);
+
+	if (len <= SUPPLY_SUFFIX_LEN)
+		return 0;
+
+	if (strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0)
+		return len - SUPPLY_SUFFIX_LEN;
+
+	return 0;
+}
+
+static int get_num_supplies(struct platform_device *pdev)
+{
+	struct  property *prop;
+	int num_supplies = 0;
+
+	for_each_property_of_node(pdev->dev.of_node, prop) {
+		if (prop_supply_name(prop->name))
+			num_supplies++;
+	}
+	return num_supplies;
+}
+
 static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 {
 	struct regulator_userspace_consumer_data tmpdata;
 	struct regulator_userspace_consumer_data *pdata;
 	struct userspace_consumer_data *drvdata;
-	int ret;
+	struct property *prop;
+	int ret, supplies_size;
 
 	pdata = dev_get_platdata(&pdev->dev);
 	if (!pdata) {
@@ -131,11 +160,25 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 		memset(pdata, 0, sizeof(*pdata));
 
 		pdata->no_autoswitch = true;
-		pdata->num_supplies = 1;
-		pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies), GFP_KERNEL);
+		pdata->num_supplies = get_num_supplies(pdev);
+
+		supplies_size = pdata->num_supplies * sizeof(*pdata->supplies);
+		pdata->supplies = devm_kzalloc(&pdev->dev, supplies_size, GFP_KERNEL);
 		if (!pdata->supplies)
 			return -ENOMEM;
-		pdata->supplies[0].supply = "vout";
+
+		for_each_property_of_node(pdev->dev.of_node, prop) {
+			const char *prop_name = prop->name;
+			size_t supply_len = prop_supply_name(prop->name);
+
+			if (!supply_len)
+				continue;
+
+			char *supply_name = devm_kstrdup(&pdev->dev, prop_name, GFP_KERNEL);
+
+			supply_name[supply_len] = '\0';
+			pdata->supplies[0].supply = supply_name;
+		}
 	}
 
 	if (pdata->num_supplies < 1) {
-- 
2.41.0


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

* [PATCH v2 3/3] regulator: userspace-consumer: Update name
  2023-10-04 12:10 [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Naresh Solanki
  2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
@ 2023-10-04 12:10 ` Naresh Solanki
  2023-10-05 20:12 ` [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Krzysztof Kozlowski
  2023-10-06 16:30 ` Rob Herring
  3 siblings, 0 replies; 8+ messages in thread
From: Naresh Solanki @ 2023-10-04 12:10 UTC (permalink / raw)
  To: broonie, zev, Liam Girdwood; +Cc: Naresh Solanki, linux-kernel

Set name to dt node name.

Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com>
---
 drivers/regulator/userspace-consumer.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 13c0a86ab32c..9030e1d9ce3c 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -159,6 +159,7 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 		pdata = &tmpdata;
 		memset(pdata, 0, sizeof(*pdata));
 
+		pdata->name = devm_kstrdup(&pdev->dev, pdev->dev.of_node->name, GFP_KERNEL);
 		pdata->no_autoswitch = true;
 		pdata->num_supplies = get_num_supplies(pdev);
 
-- 
2.41.0


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

* Re: [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT
  2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
@ 2023-10-04 18:11   ` kernel test robot
  2023-10-10 16:47   ` kernel test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2023-10-04 18:11 UTC (permalink / raw)
  To: Naresh Solanki, broonie, zev, Liam Girdwood
  Cc: oe-kbuild-all, Naresh Solanki, linux-kernel

Hi Naresh,

kernel test robot noticed the following build errors:

[auto build test ERROR on f9a1d31874c383f58bb4f89bfe79b764682cd026]

url:    https://github.com/intel-lab-lkp/linux/commits/Naresh-Solanki/regulator-userspace-consumer-Retrieve-supplies-from-DT/20231004-201151
base:   f9a1d31874c383f58bb4f89bfe79b764682cd026
patch link:    https://lore.kernel.org/r/20231004121010.1192344-2-naresh.solanki%409elements.com
patch subject: [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT
config: i386-buildonly-randconfig-003-20231004 (https://download.01.org/0day-ci/archive/20231005/202310050133.mv0eecfC-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231005/202310050133.mv0eecfC-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310050133.mv0eecfC-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/regulator/userspace-consumer.c: In function 'get_num_supplies':
>> drivers/regulator/userspace-consumer.c:139:9: error: implicit declaration of function 'for_each_property_of_node'; did you mean 'for_each_child_of_node'? [-Werror=implicit-function-declaration]
     139 |         for_each_property_of_node(pdev->dev.of_node, prop) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
         |         for_each_child_of_node
>> drivers/regulator/userspace-consumer.c:139:59: error: expected ';' before '{' token
     139 |         for_each_property_of_node(pdev->dev.of_node, prop) {
         |                                                           ^~
         |                                                           ;
   drivers/regulator/userspace-consumer.c:137:13: warning: unused variable 'num_supplies' [-Wunused-variable]
     137 |         int num_supplies = 0;
         |             ^~~~~~~~~~~~
   drivers/regulator/userspace-consumer.c:144:1: error: no return statement in function returning non-void [-Werror=return-type]
     144 | }
         | ^
   drivers/regulator/userspace-consumer.c: In function 'regulator_userspace_consumer_probe':
   drivers/regulator/userspace-consumer.c:170:67: error: expected ';' before '{' token
     170 |                 for_each_property_of_node(pdev->dev.of_node, prop) {
         |                                                                   ^~
         |                                                                   ;
   drivers/regulator/userspace-consumer.c: At top level:
>> drivers/regulator/userspace-consumer.c:121:15: warning: 'prop_supply_name' defined but not used [-Wunused-function]
     121 | static size_t prop_supply_name(char *prop_name)
         |               ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +139 drivers/regulator/userspace-consumer.c

   120	
 > 121	static size_t prop_supply_name(char *prop_name)
   122	{
   123		int len = strlen(prop_name);
   124	
   125		if (len <= SUPPLY_SUFFIX_LEN)
   126			return 0;
   127	
   128		if (strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0)
   129			return len - SUPPLY_SUFFIX_LEN;
   130	
   131		return 0;
   132	}
   133	
   134	static int get_num_supplies(struct platform_device *pdev)
   135	{
   136		struct  property *prop;
   137		int num_supplies = 0;
   138	
 > 139		for_each_property_of_node(pdev->dev.of_node, prop) {
   140			if (prop_supply_name(prop->name))
   141				num_supplies++;
   142		}
   143		return num_supplies;
   144	}
   145	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies
  2023-10-04 12:10 [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Naresh Solanki
  2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
  2023-10-04 12:10 ` [PATCH v2 3/3] regulator: userspace-consumer: Update name Naresh Solanki
@ 2023-10-05 20:12 ` Krzysztof Kozlowski
  2023-10-06 16:30 ` Rob Herring
  3 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2023-10-05 20:12 UTC (permalink / raw)
  To: Naresh Solanki, broonie, zev, Liam Girdwood, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley
  Cc: linux-kernel, devicetree

On 04/10/2023 14:10, Naresh Solanki wrote:
> Add support for multiple supplies.
> 

Nothing improved here. Why?

BTW, for regulator please use subject with reversed prefixes.
You can get them for example with `git log --oneline --
DIRECTORY_OR_FILE` on the directory your patch is touching.

Best regards,
Krzysztof


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

* Re: [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies
  2023-10-04 12:10 [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Naresh Solanki
                   ` (2 preceding siblings ...)
  2023-10-05 20:12 ` [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Krzysztof Kozlowski
@ 2023-10-06 16:30 ` Rob Herring
  2023-10-10 17:30   ` Mark Brown
  3 siblings, 1 reply; 8+ messages in thread
From: Rob Herring @ 2023-10-06 16:30 UTC (permalink / raw)
  To: Naresh Solanki
  Cc: broonie, zev, Liam Girdwood, Krzysztof Kozlowski, Conor Dooley,
	linux-kernel, devicetree

On Wed, Oct 04, 2023 at 02:10:07PM +0200, Naresh Solanki wrote:
> Add support for multiple supplies.

Again, why?

> 
> Signed-off-by: Naresh Solanki <naresh.solanki@9elements.com>
> ---
>  .../devicetree/bindings/regulator/regulator-output.yaml  | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/regulator/regulator-output.yaml b/Documentation/devicetree/bindings/regulator/regulator-output.yaml
> index 078b37a1a71a..6d077f123729 100644
> --- a/Documentation/devicetree/bindings/regulator/regulator-output.yaml
> +++ b/Documentation/devicetree/bindings/regulator/regulator-output.yaml
> @@ -21,13 +21,13 @@ properties:
>    compatible:
>      const: regulator-output
>  
> -  vout-supply:
> +patternProperties:
> +  ".*-supply":
>      description:
>        Phandle of the regulator supplying the output.
>  
>  required:
>    - compatible
> -  - vout-supply
>  
>  additionalProperties: false
>  
> @@ -37,3 +37,8 @@ examples:
>            compatible = "regulator-output";
>            vout-supply = <&output_reg>;
>        };
> +      output1 {
> +          compatible = "regulator-output";
> +          sw0-supply = <&output_reg0>;
> +          sw1-supply = <&output_reg2>;
> +      };
> 
> base-commit: f9a1d31874c383f58bb4f89bfe79b764682cd026
> -- 
> 2.41.0
> 

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

* Re: [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT
  2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
  2023-10-04 18:11   ` kernel test robot
@ 2023-10-10 16:47   ` kernel test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kernel test robot @ 2023-10-10 16:47 UTC (permalink / raw)
  To: Naresh Solanki, broonie, zev, Liam Girdwood
  Cc: oe-kbuild-all, Naresh Solanki, linux-kernel

Hi Naresh,

kernel test robot noticed the following build errors:

[auto build test ERROR on f9a1d31874c383f58bb4f89bfe79b764682cd026]

url:    https://github.com/intel-lab-lkp/linux/commits/Naresh-Solanki/regulator-userspace-consumer-Retrieve-supplies-from-DT/20231004-201151
base:   f9a1d31874c383f58bb4f89bfe79b764682cd026
patch link:    https://lore.kernel.org/r/20231004121010.1192344-2-naresh.solanki%409elements.com
patch subject: [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT
config: x86_64-buildonly-randconfig-003-20231010 (https://download.01.org/0day-ci/archive/20231011/202310110043.uMSq3kAw-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231011/202310110043.uMSq3kAw-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310110043.uMSq3kAw-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/regulator/userspace-consumer.c: In function 'get_num_supplies':
   drivers/regulator/userspace-consumer.c:139:9: error: implicit declaration of function 'for_each_property_of_node'; did you mean 'for_each_child_of_node'? [-Werror=implicit-function-declaration]
     139 |         for_each_property_of_node(pdev->dev.of_node, prop) {
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
         |         for_each_child_of_node
   drivers/regulator/userspace-consumer.c:139:59: error: expected ';' before '{' token
     139 |         for_each_property_of_node(pdev->dev.of_node, prop) {
         |                                                           ^~
         |                                                           ;
   drivers/regulator/userspace-consumer.c:137:13: warning: unused variable 'num_supplies' [-Wunused-variable]
     137 |         int num_supplies = 0;
         |             ^~~~~~~~~~~~
>> drivers/regulator/userspace-consumer.c:144:1: error: no return statement in function returning non-void [-Werror=return-type]
     144 | }
         | ^
   drivers/regulator/userspace-consumer.c: In function 'regulator_userspace_consumer_probe':
   drivers/regulator/userspace-consumer.c:170:67: error: expected ';' before '{' token
     170 |                 for_each_property_of_node(pdev->dev.of_node, prop) {
         |                                                                   ^~
         |                                                                   ;
   drivers/regulator/userspace-consumer.c: At top level:
   drivers/regulator/userspace-consumer.c:121:15: warning: 'prop_supply_name' defined but not used [-Wunused-function]
     121 | static size_t prop_supply_name(char *prop_name)
         |               ^~~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors


vim +144 drivers/regulator/userspace-consumer.c

   133	
   134	static int get_num_supplies(struct platform_device *pdev)
   135	{
   136		struct  property *prop;
   137		int num_supplies = 0;
   138	
   139		for_each_property_of_node(pdev->dev.of_node, prop) {
   140			if (prop_supply_name(prop->name))
   141				num_supplies++;
   142		}
   143		return num_supplies;
 > 144	}
   145	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies
  2023-10-06 16:30 ` Rob Herring
@ 2023-10-10 17:30   ` Mark Brown
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Brown @ 2023-10-10 17:30 UTC (permalink / raw)
  To: Rob Herring
  Cc: Naresh Solanki, zev, Liam Girdwood, Krzysztof Kozlowski,
	Conor Dooley, linux-kernel, devicetree

[-- Attachment #1: Type: text/plain, Size: 534 bytes --]

On Fri, Oct 06, 2023 at 11:30:54AM -0500, Rob Herring wrote:
> On Wed, Oct 04, 2023 at 02:10:07PM +0200, Naresh Solanki wrote:

> > Add support for multiple supplies.

> Again, why?

FWIW I do tend to share the same question that Rob and other people have
asked a few times here - is this really one userspace consumer with
multiple supplies, if so what does that userspace consumer represent?
I'd be expecting that this was representing a single supply to an
external device which for the most part would have a single input
supply.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2023-10-10 17:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-04 12:10 [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Naresh Solanki
2023-10-04 12:10 ` [PATCH v2 2/3] regulator: userspace-consumer: Retrieve supplies from DT Naresh Solanki
2023-10-04 18:11   ` kernel test robot
2023-10-10 16:47   ` kernel test robot
2023-10-04 12:10 ` [PATCH v2 3/3] regulator: userspace-consumer: Update name Naresh Solanki
2023-10-05 20:12 ` [PATCH v2 1/3] dt-bindings: regulator: regulator-output: Multiple supplies Krzysztof Kozlowski
2023-10-06 16:30 ` Rob Herring
2023-10-10 17:30   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox