mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/2] hwmon: (amc6821) Add PWM polarity configuration with OF
@ 2025-04-02 10:21 Francesco Dolcini
  2025-04-02 10:21 ` [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Francesco Dolcini
  2025-04-02 10:21 ` [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
  0 siblings, 2 replies; 7+ messages in thread
From: Francesco Dolcini @ 2025-04-02 10:21 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Farouk Bouabid, Quentin Schulz
  Cc: Francesco Dolcini, linux-hwmon, devicetree, linux-kernel

From: Francesco Dolcini <francesco.dolcini@toradex.com>

Add support for configuring the PWM polarity of the amc6821 fan controller.

Francesco Dolcini (2):
  dt-bindings: hwmon: amc6821: add fan and PWM output
  hwmon: (amc6821) Add PWM polarity configuration with OF

 .../devicetree/bindings/hwmon/ti,amc6821.yaml | 18 ++++++-
 drivers/hwmon/amc6821.c                       | 50 +++++++++++++++++--
 2 files changed, 62 insertions(+), 6 deletions(-)

-- 
2.39.5


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

* [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output
  2025-04-02 10:21 [PATCH v4 0/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
@ 2025-04-02 10:21 ` Francesco Dolcini
  2025-04-02 14:31   ` Rob Herring (Arm)
  2025-04-02 16:15   ` Guenter Roeck
  2025-04-02 10:21 ` [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
  1 sibling, 2 replies; 7+ messages in thread
From: Francesco Dolcini @ 2025-04-02 10:21 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Farouk Bouabid, Quentin Schulz
  Cc: Francesco Dolcini, linux-hwmon, devicetree, linux-kernel

From: Francesco Dolcini <francesco.dolcini@toradex.com>

Add properties to describe the fan and the PWM controller output.

Link: https://www.ti.com/lit/gpn/amc6821
Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
---
v4:
 - add #pwm-cells description
 - remove useless first #pwm-cells, that was supposed to be the instance
   number
v3: https://lore.kernel.org/all/20250331155229.147879-2-francesco@dolcini.it/
 - explicitly describe the fan, use standard PWM and FAN bindings
 - pwm.yaml cannot be referenced, because of the $nodename pattern that is
   enforced there
v2: https://lore.kernel.org/all/20250224180801.128685-2-francesco@dolcini.it/
 - no changes
v1: https://lore.kernel.org/all/20250218165633.106867-2-francesco@dolcini.it/
---
 .../devicetree/bindings/hwmon/ti,amc6821.yaml  | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml b/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml
index 5d33f1a23d03..9ca7356760a7 100644
--- a/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml
+++ b/Documentation/devicetree/bindings/hwmon/ti,amc6821.yaml
@@ -28,6 +28,17 @@ properties:
   i2c-mux:
     type: object
 
+  fan:
+    $ref: fan-common.yaml#
+    unevaluatedProperties: false
+
+  "#pwm-cells":
+    const: 2
+    description: |
+      Number of cells in a PWM specifier.
+      - cell 0: PWM period in nanoseconds
+      - cell 1: PWM polarity: 0 or PWM_POLARITY_INVERTED
+
 required:
   - compatible
   - reg
@@ -50,9 +61,14 @@ examples:
         #address-cells = <1>;
         #size-cells = <0>;
 
-        fan@18 {
+        fan_controller: fan@18 {
             compatible = "ti,amc6821";
             reg = <0x18>;
+            #pwm-cells = <2>;
+
+            fan {
+                pwms = <&fan_controller 40000 0>;
+            };
         };
     };
 
-- 
2.39.5


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

* [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF
  2025-04-02 10:21 [PATCH v4 0/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
  2025-04-02 10:21 ` [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Francesco Dolcini
@ 2025-04-02 10:21 ` Francesco Dolcini
  2025-04-02 13:21   ` Guenter Roeck
  2025-04-02 16:16   ` Guenter Roeck
  1 sibling, 2 replies; 7+ messages in thread
From: Francesco Dolcini @ 2025-04-02 10:21 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Farouk Bouabid, Quentin Schulz
  Cc: Francesco Dolcini, linux-hwmon, devicetree, linux-kernel

From: Francesco Dolcini <francesco.dolcini@toradex.com>

Add support to configure the PWM-Out pin polarity based on the device
tree. The binding would allow also to configure the PWM period, this is
currently not implemented by the driver.

The driver has a module option to set the PWM polarity (normal=0,
inverted=1), when specified it always takes the precedence over the DT.

Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
---
v4:
 - remove first #pwm-cells
v3: https://lore.kernel.org/all/20250331155229.147879-3-francesco@dolcini.it/
 - configure PWM polarity using standard PWM DT properties
v2: https://lore.kernel.org/lkml/20250224180801.128685-3-francesco@dolcini.it/
 - pwminv module parameter takes always the precedence over the DT property
v1: https://lore.kernel.org/all/20250218165633.106867-3-francesco@dolcini.it/
---
 drivers/hwmon/amc6821.c | 50 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/amc6821.c b/drivers/hwmon/amc6821.c
index 1e3c6acd8974..13a789cc85d2 100644
--- a/drivers/hwmon/amc6821.c
+++ b/drivers/hwmon/amc6821.c
@@ -23,9 +23,12 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/of_platform.h>
+#include <linux/pwm.h>
 #include <linux/regmap.h>
 #include <linux/slab.h>
 
+#include <dt-bindings/pwm/pwm.h>
+
 /*
  * Addresses to scan.
  */
@@ -37,7 +40,7 @@ static const unsigned short normal_i2c[] = {0x18, 0x19, 0x1a, 0x2c, 0x2d, 0x2e,
  * Insmod parameters
  */
 
-static int pwminv;	/*Inverted PWM output. */
+static int pwminv = -1; /*Inverted PWM output. */
 module_param(pwminv, int, 0444);
 
 static int init = 1; /*Power-on initialization.*/
@@ -845,9 +848,43 @@ static int amc6821_detect(struct i2c_client *client, struct i2c_board_info *info
 	return 0;
 }
 
-static int amc6821_init_client(struct amc6821_data *data)
+static enum pwm_polarity amc6821_pwm_polarity(struct i2c_client *client)
+{
+	enum pwm_polarity polarity = PWM_POLARITY_NORMAL;
+	struct of_phandle_args args;
+	struct device_node *fan_np;
+
+	/*
+	 * For backward compatibility, the pwminv module parameter takes
+	 * always the precedence over any other device description
+	 */
+	if (pwminv == 0)
+		return PWM_POLARITY_NORMAL;
+	if (pwminv > 0)
+		return PWM_POLARITY_INVERSED;
+
+	fan_np = of_get_child_by_name(client->dev.of_node, "fan");
+	if (!fan_np)
+		return PWM_POLARITY_NORMAL;
+
+	if (of_parse_phandle_with_args(fan_np, "pwms", "#pwm-cells", 0, &args))
+		goto out;
+	of_node_put(args.np);
+
+	if (args.args_count != 2)
+		goto out;
+
+	if (args.args[1] & PWM_POLARITY_INVERTED)
+		polarity = PWM_POLARITY_INVERSED;
+out:
+	of_node_put(fan_np);
+	return polarity;
+}
+
+static int amc6821_init_client(struct i2c_client *client, struct amc6821_data *data)
 {
 	struct regmap *regmap = data->regmap;
+	u32 regval;
 	int err;
 
 	if (init) {
@@ -864,11 +901,14 @@ static int amc6821_init_client(struct amc6821_data *data)
 		if (err)
 			return err;
 
+		regval = AMC6821_CONF1_START;
+		if (amc6821_pwm_polarity(client) == PWM_POLARITY_INVERSED)
+			regval |= AMC6821_CONF1_PWMINV;
+
 		err = regmap_update_bits(regmap, AMC6821_REG_CONF1,
 					 AMC6821_CONF1_THERMOVIE | AMC6821_CONF1_FANIE |
 					 AMC6821_CONF1_START | AMC6821_CONF1_PWMINV,
-					 AMC6821_CONF1_START |
-					 (pwminv ? AMC6821_CONF1_PWMINV : 0));
+					 regval);
 		if (err)
 			return err;
 	}
@@ -916,7 +956,7 @@ static int amc6821_probe(struct i2c_client *client)
 				     "Failed to initialize regmap\n");
 	data->regmap = regmap;
 
-	err = amc6821_init_client(data);
+	err = amc6821_init_client(client, data);
 	if (err)
 		return err;
 
-- 
2.39.5


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

* Re: [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF
  2025-04-02 10:21 ` [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
@ 2025-04-02 13:21   ` Guenter Roeck
  2025-04-02 16:16   ` Guenter Roeck
  1 sibling, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2025-04-02 13:21 UTC (permalink / raw)
  To: Francesco Dolcini, Jean Delvare, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Farouk Bouabid,
	Quentin Schulz
  Cc: Francesco Dolcini, linux-hwmon, devicetree, linux-kernel

On 4/2/25 03:21, Francesco Dolcini wrote:
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> 
> Add support to configure the PWM-Out pin polarity based on the device
> tree. The binding would allow also to configure the PWM period, this is
> currently not implemented by the driver.
> 
> The driver has a module option to set the PWM polarity (normal=0,
> inverted=1), when specified it always takes the precedence over the DT.
> 
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>

For my reference:

Reviewed-by: Guenter Roeck <linux@roeck-us.net>


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

* Re: [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output
  2025-04-02 10:21 ` [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Francesco Dolcini
@ 2025-04-02 14:31   ` Rob Herring (Arm)
  2025-04-02 16:15   ` Guenter Roeck
  1 sibling, 0 replies; 7+ messages in thread
From: Rob Herring (Arm) @ 2025-04-02 14:31 UTC (permalink / raw)
  To: Francesco Dolcini
  Cc: Farouk Bouabid, Francesco Dolcini, devicetree, linux-kernel,
	Jean Delvare, Krzysztof Kozlowski, Guenter Roeck, linux-hwmon,
	Conor Dooley, Quentin Schulz


On Wed, 02 Apr 2025 12:21:45 +0200, Francesco Dolcini wrote:
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> 
> Add properties to describe the fan and the PWM controller output.
> 
> Link: https://www.ti.com/lit/gpn/amc6821
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> ---
> v4:
>  - add #pwm-cells description
>  - remove useless first #pwm-cells, that was supposed to be the instance
>    number
> v3: https://lore.kernel.org/all/20250331155229.147879-2-francesco@dolcini.it/
>  - explicitly describe the fan, use standard PWM and FAN bindings
>  - pwm.yaml cannot be referenced, because of the $nodename pattern that is
>    enforced there
> v2: https://lore.kernel.org/all/20250224180801.128685-2-francesco@dolcini.it/
>  - no changes
> v1: https://lore.kernel.org/all/20250218165633.106867-2-francesco@dolcini.it/
> ---
>  .../devicetree/bindings/hwmon/ti,amc6821.yaml  | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


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

* Re: [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output
  2025-04-02 10:21 ` [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Francesco Dolcini
  2025-04-02 14:31   ` Rob Herring (Arm)
@ 2025-04-02 16:15   ` Guenter Roeck
  1 sibling, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2025-04-02 16:15 UTC (permalink / raw)
  To: Francesco Dolcini
  Cc: Jean Delvare, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Farouk Bouabid, Quentin Schulz, Francesco Dolcini, linux-hwmon,
	devicetree, linux-kernel

On Wed, Apr 02, 2025 at 12:21:45PM +0200, Francesco Dolcini wrote:
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> 
> Add properties to describe the fan and the PWM controller output.
> 
> Link: https://www.ti.com/lit/gpn/amc6821
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> Reviewed-by: Rob Herring (Arm) <robh@kernel.org>

Applied to hwmon-next.

Thanks,
Guenter

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

* Re: [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF
  2025-04-02 10:21 ` [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
  2025-04-02 13:21   ` Guenter Roeck
@ 2025-04-02 16:16   ` Guenter Roeck
  1 sibling, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2025-04-02 16:16 UTC (permalink / raw)
  To: Francesco Dolcini
  Cc: Jean Delvare, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Farouk Bouabid, Quentin Schulz, Francesco Dolcini, linux-hwmon,
	devicetree, linux-kernel

On Wed, Apr 02, 2025 at 12:21:46PM +0200, Francesco Dolcini wrote:
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> 
> Add support to configure the PWM-Out pin polarity based on the device
> tree. The binding would allow also to configure the PWM period, this is
> currently not implemented by the driver.
> 
> The driver has a module option to set the PWM polarity (normal=0,
> inverted=1), when specified it always takes the precedence over the DT.
> 
> Signed-off-by: Francesco Dolcini <francesco.dolcini@toradex.com>

Applied to hwmon-next.

Thanks,
Guenter

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

end of thread, other threads:[~2025-04-02 16:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-02 10:21 [PATCH v4 0/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
2025-04-02 10:21 ` [PATCH v4 1/2] dt-bindings: hwmon: amc6821: add fan and PWM output Francesco Dolcini
2025-04-02 14:31   ` Rob Herring (Arm)
2025-04-02 16:15   ` Guenter Roeck
2025-04-02 10:21 ` [PATCH v4 2/2] hwmon: (amc6821) Add PWM polarity configuration with OF Francesco Dolcini
2025-04-02 13:21   ` Guenter Roeck
2025-04-02 16:16   ` Guenter Roeck

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

all inboxes | Powered by JetHome®