linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] hwmon: (adt7475) duty cycle configuration
@ 2024-05-08 17:05 Chris Packham
  2024-05-08 17:05 ` [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle Chris Packham
  2024-05-08 17:05 ` [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM " Chris Packham
  0 siblings, 2 replies; 5+ messages in thread
From: Chris Packham @ 2024-05-08 17:05 UTC (permalink / raw)
  To: jdelvare, linux, robh, krzk+dt, conor+dt
  Cc: linux-hwmon, devicetree, linux-kernel, Chris Packham

I have a system that has very over spec'd fans so the amount of noise when they
run at 100% duty cycle is considerable. We have userspace monitoring tools that
will configure appropriate fan control parameters but there is a bit of a delay
between the kernel loading the driver and the userland tools catching up to
configure the fan control. This series adds device properties that allow the
PWM duty cycle to be specified via device properties so the PWM duty cycle can
be reduced as soon as possible.

Chris Packham (2):
  dt-bindings: hwmon: Document adt7475 PWM initial duty cycle
  hwmon: (adt7475) Add support for configuring initial PWM duty cycle

 .../devicetree/bindings/hwmon/adt7475.yaml    | 26 ++++++++-
 drivers/hwmon/adt7475.c                       | 56 +++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)

-- 
2.43.2


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

* [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle
  2024-05-08 17:05 [PATCH 0/2] hwmon: (adt7475) duty cycle configuration Chris Packham
@ 2024-05-08 17:05 ` Chris Packham
  2024-05-08 19:00   ` Rob Herring (Arm)
  2024-05-08 17:05 ` [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM " Chris Packham
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Packham @ 2024-05-08 17:05 UTC (permalink / raw)
  To: jdelvare, linux, robh, krzk+dt, conor+dt
  Cc: linux-hwmon, devicetree, linux-kernel, Chris Packham

Add documentation for the pwm-initial-duty-cycle and
pwm-initial-frequency properties. These allow the starting state of the
PWM outputs to be set to cater for hardware designs where undesirable
amounts of noise is created by the default hardware state.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 .../devicetree/bindings/hwmon/adt7475.yaml    | 26 ++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/hwmon/adt7475.yaml b/Documentation/devicetree/bindings/hwmon/adt7475.yaml
index 051c976ab711..3de300c9da2a 100644
--- a/Documentation/devicetree/bindings/hwmon/adt7475.yaml
+++ b/Documentation/devicetree/bindings/hwmon/adt7475.yaml
@@ -51,6 +51,29 @@ properties:
       enum: [0, 1]
       default: 1
 
+  adi,pwm-initial-duty-cycle:
+    description: |
+      Configures the initial duty cycle for the PWM outputs. The hardware
+      default is 100% but this may cause unwanted fan noise at startup. Set
+      this to a value from 0 (0% duty cycle) to 255 (100% duty cycle).
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 3
+    maxItems: 3
+    items:
+      minimum: 0
+      maximum: 255
+      default: 255
+
+  adi,pwm-initial-frequency:
+    description: |
+      Configures the initial frequency for the PWM outputs.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 3
+    maxItems: 3
+    items:
+      enum: [11, 14, 22, 29, 35, 44, 58, 88, 22500]
+      default: 35
+
 patternProperties:
   "^adi,bypass-attenuator-in[0-4]$":
     description: |
@@ -80,7 +103,6 @@ patternProperties:
       - therm#
       - smbalert#
       - gpio
-
 required:
   - compatible
   - reg
@@ -99,6 +121,8 @@ examples:
         adi,bypass-attenuator-in0 = <1>;
         adi,bypass-attenuator-in1 = <0>;
         adi,pwm-active-state = <1 0 1>;
+        adi,pwm-initial-duty-cycle = <128 0 128>;
+        adi,pwm-initial-frequency = <22500 0 22500>;
         adi,pin10-function = "smbalert#";
         adi,pin14-function = "tach4";
       };
-- 
2.43.2


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

* [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM duty cycle
  2024-05-08 17:05 [PATCH 0/2] hwmon: (adt7475) duty cycle configuration Chris Packham
  2024-05-08 17:05 ` [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle Chris Packham
@ 2024-05-08 17:05 ` Chris Packham
  2024-05-08 17:49   ` Chris Packham
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Packham @ 2024-05-08 17:05 UTC (permalink / raw)
  To: jdelvare, linux, robh, krzk+dt, conor+dt
  Cc: linux-hwmon, devicetree, linux-kernel, Chris Packham

By default the PWM duty cycle in hardware is 100%. On some systems this
can cause unwanted fan noise. Add the ability to take an initial PWM
duty cycle and frequency via device properties.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
 drivers/hwmon/adt7475.c | 56 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 4224ffb30483..b0c7c1a95897 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1662,6 +1662,54 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
 	return 0;
 }
 
+static int adt7475_set_pwm_initial_freq(struct i2c_client *client)
+{
+	int ret, out, i;
+	u32 freqs[ADT7475_PWM_COUNT];
+	int data;
+
+	ret = device_property_read_u32_array(&client->dev,
+					     "pwm-initial-frequency", freqs,
+					     ARRAY_SIZE(freqs));
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+		out = find_closest(freqs[i], pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
+		data = adt7475_read(TEMP_TRANGE_REG(i));
+		if (data < 0)
+			return data;
+		data &= ~0xf;
+		data |= out;
+
+		ret = i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(i), data);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int adt7475_set_pwm_initial_duty(struct i2c_client *client)
+{
+	int ret, i;
+	u32 dutys[ADT7475_PWM_COUNT];
+
+	ret = device_property_read_u32_array(&client->dev,
+					     "adi,pwm-initial-duty-cycle", dutys,
+					     ARRAY_SIZE(dutys));
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+		ret = i2c_smbus_write_byte_data(client, PWM_MAX_REG(i), dutys[i] & 0xff);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client)
 {
 	enum chips chip;
@@ -1778,6 +1826,14 @@ static int adt7475_probe(struct i2c_client *client)
 	if (ret && ret != -EINVAL)
 		dev_warn(&client->dev, "Error configuring pwm polarity\n");
 
+	ret = adt7475_set_pwm_initial_freq(client);
+	if (ret)
+		return ret;
+
+	ret = adt7475_set_pwm_initial_duty(client);
+	if (ret)
+		return ret;
+
 	/* Start monitoring */
 	switch (chip) {
 	case adt7475:
-- 
2.43.2


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

* Re: [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM duty cycle
  2024-05-08 17:05 ` [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM " Chris Packham
@ 2024-05-08 17:49   ` Chris Packham
  0 siblings, 0 replies; 5+ messages in thread
From: Chris Packham @ 2024-05-08 17:49 UTC (permalink / raw)
  To: jdelvare, linux, robh, krzk+dt, conor+dt
  Cc: linux-hwmon, devicetree, linux-kernel


On 9/05/24 05:05, Chris Packham wrote:
> By default the PWM duty cycle in hardware is 100%. On some systems this
> can cause unwanted fan noise. Add the ability to take an initial PWM
> duty cycle and frequency via device properties.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>   drivers/hwmon/adt7475.c | 56 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 56 insertions(+)
>
> diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
> index 4224ffb30483..b0c7c1a95897 100644
> --- a/drivers/hwmon/adt7475.c
> +++ b/drivers/hwmon/adt7475.c
> @@ -1662,6 +1662,54 @@ static int adt7475_set_pwm_polarity(struct i2c_client *client)
>   	return 0;
>   }
>   
> +static int adt7475_set_pwm_initial_freq(struct i2c_client *client)
> +{
> +	int ret, out, i;
> +	u32 freqs[ADT7475_PWM_COUNT];
> +	int data;
> +
> +	ret = device_property_read_u32_array(&client->dev,
> +					     "pwm-initial-frequency", freqs,
> +					     ARRAY_SIZE(freqs));
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
> +		out = find_closest(freqs[i], pwmfreq_table, ARRAY_SIZE(pwmfreq_table));
> +		data = adt7475_read(TEMP_TRANGE_REG(i));
> +		if (data < 0)
> +			return data;
> +		data &= ~0xf;
> +		data |= out;
> +
> +		ret = i2c_smbus_write_byte_data(client, TEMP_TRANGE_REG(i), data);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int adt7475_set_pwm_initial_duty(struct i2c_client *client)
> +{
> +	int ret, i;
> +	u32 dutys[ADT7475_PWM_COUNT];
> +
> +	ret = device_property_read_u32_array(&client->dev,
> +					     "adi,pwm-initial-duty-cycle", dutys,
> +					     ARRAY_SIZE(dutys));
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
> +		ret = i2c_smbus_write_byte_data(client, PWM_MAX_REG(i), dutys[i] & 0xff);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}
> +
>   static int adt7475_probe(struct i2c_client *client)
>   {
>   	enum chips chip;
> @@ -1778,6 +1826,14 @@ static int adt7475_probe(struct i2c_client *client)
>   	if (ret && ret != -EINVAL)
>   		dev_warn(&client->dev, "Error configuring pwm polarity\n");
>   
> +	ret = adt7475_set_pwm_initial_freq(client);
> +	if (ret)
> +		return ret;

Whoops I meant to send the version that handles -EINVAL. v2 will handle 
errors the same way as pwm_polarity above. I'll wait for a bit before 
sending that out.

> +
> +	ret = adt7475_set_pwm_initial_duty(client);
> +	if (ret)
> +		return ret;
> +
>   	/* Start monitoring */
>   	switch (chip) {
>   	case adt7475:

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

* Re: [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle
  2024-05-08 17:05 ` [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle Chris Packham
@ 2024-05-08 19:00   ` Rob Herring (Arm)
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Herring (Arm) @ 2024-05-08 19:00 UTC (permalink / raw)
  To: Chris Packham
  Cc: jdelvare, linux-hwmon, linux, linux-kernel, conor+dt, krzk+dt,
	devicetree


On Thu, 09 May 2024 05:05:42 +1200, Chris Packham wrote:
> Add documentation for the pwm-initial-duty-cycle and
> pwm-initial-frequency properties. These allow the starting state of the
> PWM outputs to be set to cater for hardware designs where undesirable
> amounts of noise is created by the default hardware state.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>  .../devicetree/bindings/hwmon/adt7475.yaml    | 26 ++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/hwmon/adt7475.example.dtb: hwmon@2e: adi,pwm-initial-frequency:0:1: 0 is not one of [11, 14, 22, 29, 35, 44, 58, 88, 22500]
	from schema $id: http://devicetree.org/schemas/hwmon/adt7475.yaml#

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20240508170544.263059-2-chris.packham@alliedtelesis.co.nz

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


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

end of thread, other threads:[~2024-05-08 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 17:05 [PATCH 0/2] hwmon: (adt7475) duty cycle configuration Chris Packham
2024-05-08 17:05 ` [PATCH 1/2] dt-bindings: hwmon: Document adt7475 PWM initial duty cycle Chris Packham
2024-05-08 19:00   ` Rob Herring (Arm)
2024-05-08 17:05 ` [PATCH 2/2] hwmon: (adt7475) Add support for configuring initial PWM " Chris Packham
2024-05-08 17:49   ` Chris Packham

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