Skip to contentSkip to conversation

hwmon: (adt7475) attenuator bypass and pwm invert

PATCH Applied Chris Packham 3 participants 12 messages Feb 27, 2020 – Mar 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover hwmon: (adt7475) attenuator bypass and pwm invert

I've picked up Logan's changes[1] and am combining them with an old series of mine[2] to hopefully get them both over the line.

[1] - https://lore.kernel.org/linux-hwmon/[email protected]/
[2] - https://lore.kernel.org/linux-hwmon/[email protected]/

Chris Packham (2):
dt-bindings: hwmon: Document adt7475 pwm-active-state property
hwmon: (adt7475) Add support for inverting pwm output

Logan Shaw (3):
dt-bindings: hwmon: Document adt7475 binding
dt-bindings: hwmon: Document adt7475 bypass-attenuator property
hwmon: (adt7475) Add attenuator bypass support

 .../devicetree/bindings/hwmon/adt7475.yaml    | 84 ++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  8 --
 drivers/hwmon/adt7475.c                       | 95 ++++++++++++++++++-
 3 files changed, 176 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adt7475.yaml
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/5 dt-bindings: hwmon: Document adt7475 binding

From: Logan Shaw <[email protected]>

Add binding for adi,adt7475 and variants.
Remove from trivial-devices.

---

Notes:
Changes in v5:
- add review from Rob

Changes in v4:
- None

Changes in v3:
- split conversion to yaml from addition of new properties

 .../devicetree/bindings/hwmon/adt7475.yaml    | 57 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  8 ---
 2 files changed, 57 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adt7475.yaml
Documentation/devicetree/bindings/hwmon/adt7475.yaml new file +57 -0
new file mode 100644
index 000000000000..2252499ea201
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/adt7475.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ADT7475 hwmon sensor
+
+maintainers:
+  - Jean Delvare <[email protected]>
+
+description: |
+  The ADT7473, ADT7475, ADT7476, and ADT7490 are thermal monitors and multiple
+  PWN fan controllers.
+
+  They support monitoring and controlling up to four fans (the ADT7490 can only
+  control up to three). They support reading a single on chip temperature
+  sensor and two off chip temperature sensors (the ADT7490 additionally
+  supports measuring up to three current external temperature sensors with
+  series resistance cancellation (SRC)).
+
+  Datasheets:
+  https://www.onsemi.com/pub/Collateral/ADT7473-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7475-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7476-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7490-D.PDF
+
+  Description taken from onsemiconductors specification sheets, with minor
+  rephrasing.
+
+properties:
+  compatible:
+    enum:
+      - adi,adt7473
+      - adi,adt7475
+      - adi,adt7476
+      - adi,adt7490
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      hwmon@2e {
+        compatible = "adi,adt7476";
+        reg = <0x2e>;
+      };
+    };
+
Documentation/devicetree/bindings/trivial-devices.yaml +0 -8
index 978de7d37c66..57173ec41c30 100644
@@ -34,14 +34,6 @@ properties:
           - adi,adt7461
             # +/-1C TDM Extended Temp Range I.C
           - adt7461
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7473
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7475
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7476
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7490
             # Three-Axis Digital Accelerometer
           - adi,adxl345
             # Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too)
Signature · 1 line
2.25.1
maintainer Applied
#2 lore raw

Re: [PATCH v5 1/5] dt-bindings: hwmon: Document adt7475 binding

Quoted 8 lines · Chris Packham

From: Logan Shaw <[email protected]>

Add binding for adi,adt7475 and variants.
Remove from trivial-devices.

Applied.

Thanks,
Guenter

Quoted 99 lines

---

Notes:
Changes in v5:
- add review from Rob

Changes in v4:
- None

Changes in v3:
- split conversion to yaml from addition of new properties

 .../devicetree/bindings/hwmon/adt7475.yaml    | 57 +++++++++++++++++++
 .../devicetree/bindings/trivial-devices.yaml  |  8 ---
 2 files changed, 57 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adt7475.yaml
Documentation/devicetree/bindings/hwmon/adt7475.yaml new file +57 -0
new file mode 100644
index 000000000000..2252499ea201
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/adt7475.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ADT7475 hwmon sensor
+
+maintainers:
+  - Jean Delvare <[email protected]>
+
+description: |
+  The ADT7473, ADT7475, ADT7476, and ADT7490 are thermal monitors and multiple
+  PWN fan controllers.
+
+  They support monitoring and controlling up to four fans (the ADT7490 can only
+  control up to three). They support reading a single on chip temperature
+  sensor and two off chip temperature sensors (the ADT7490 additionally
+  supports measuring up to three current external temperature sensors with
+  series resistance cancellation (SRC)).
+
+  Datasheets:
+  https://www.onsemi.com/pub/Collateral/ADT7473-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7475-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7476-D.PDF
+  https://www.onsemi.com/pub/Collateral/ADT7490-D.PDF
+
+  Description taken from onsemiconductors specification sheets, with minor
+  rephrasing.
+
+properties:
+  compatible:
+    enum:
+      - adi,adt7473
+      - adi,adt7475
+      - adi,adt7476
+      - adi,adt7490
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      hwmon@2e {
+        compatible = "adi,adt7476";
+        reg = <0x2e>;
+      };
+    };
+
Documentation/devicetree/bindings/trivial-devices.yaml +0 -8
index 978de7d37c66..57173ec41c30 100644
@@ -34,14 +34,6 @@ properties:
           - adi,adt7461
             # +/-1C TDM Extended Temp Range I.C
           - adt7461
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7473
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7475
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7476
-            # +/-1C TDM Extended Temp Range I.C
-          - adi,adt7490
             # Three-Axis Digital Accelerometer
           - adi,adxl345
             # Three-Axis Digital Accelerometer (backward-compatibility value "adi,adxl345" must be listed too)
#3 lore raw

PATCH v5 2/5 dt-bindings: hwmon: Document adt7475 bypass-attenuator property

In reply to Chris Packham

From: Logan Shaw <[email protected]>

Add documentation for the bypass-attenuator-in[0-4] property.

---

Notes:
Changes in v5:
- add review from Rob

Changes in v4:
- use $ref uint32 and enum
- add 'adi' vendor prefix

Changes in v3:
- separated addition of new properties from conversion to yaml

 .../devicetree/bindings/hwmon/adt7475.yaml          | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/hwmon/adt7475.yaml +13 -0
index 2252499ea201..e40612ee075f 100644
@@ -39,6 +39,17 @@ properties:
   reg:
     maxItems: 1
 
+patternProperties:
+  "^adi,bypass-attenuator-in[0-4]$":
+    description: |
+      Configures bypassing the individual voltage input attenuator. If
+      set to 1 the attenuator is bypassed if set to 0 the attenuator is
+      not bypassed. If the property is absent then the attenuator
+      retains it's configuration from the bios/bootloader.
+    allOf:
+     - $ref: /schemas/types.yaml#/definitions/uint32
+     - enum: [0, 1]
+
 required:
   - compatible
   - reg
@@ -52,6 +63,8 @@ examples:
       hwmon@2e {
         compatible = "adi,adt7476";
         reg = <0x2e>;
+        adi,bypass-attenuator-in0 = <1>;
+        adi,bypass-attenuator-in1 = <0>;
       };
     };
 
Signature · 1 line
2.25.1
maintainer Applied
#4 lore raw

Re: [PATCH v5 2/5] dt-bindings: hwmon: Document adt7475 bypass-attenuator property

Quoted 7 lines · Chris Packham

From: Logan Shaw <[email protected]>

Add documentation for the bypass-attenuator-in[0-4] property.

Applied.

Thanks,
Guenter

Quoted 47 lines

---

Notes:
Changes in v5:
- add review from Rob

Changes in v4:
- use $ref uint32 and enum
- add 'adi' vendor prefix

Changes in v3:
- separated addition of new properties from conversion to yaml

 .../devicetree/bindings/hwmon/adt7475.yaml          | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Documentation/devicetree/bindings/hwmon/adt7475.yaml +13 -0
index 2252499ea201..e40612ee075f 100644
@@ -39,6 +39,17 @@ properties:
   reg:
     maxItems: 1
 
+patternProperties:
+  "^adi,bypass-attenuator-in[0-4]$":
+    description: |
+      Configures bypassing the individual voltage input attenuator. If
+      set to 1 the attenuator is bypassed if set to 0 the attenuator is
+      not bypassed. If the property is absent then the attenuator
+      retains it's configuration from the bios/bootloader.
+    allOf:
+     - $ref: /schemas/types.yaml#/definitions/uint32
+     - enum: [0, 1]
+
 required:
   - compatible
   - reg
@@ -52,6 +63,8 @@ examples:
       hwmon@2e {
         compatible = "adi,adt7476";
         reg = <0x2e>;
+        adi,bypass-attenuator-in0 = <1>;
+        adi,bypass-attenuator-in1 = <0>;
       };
     };
 
#5 lore raw

PATCH v5 3/5 dt-bindings: hwmon: Document adt7475 pwm-active-state property

In reply to Chris Packham

Add binding information for the adi,pwm-active-state property.

---

Notes:
Changes in v5:
- change to adi,pwm-active-state
- uint32 array

Changes in v4:
- use $ref uint32 and enum
- add adi vendor prefix

Cahnges in v3:
- new

 .../devicetree/bindings/hwmon/adt7475.yaml         | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/hwmon/adt7475.yaml +14 -0
index e40612ee075f..76985034ea73 100644
@@ -50,6 +50,19 @@ patternProperties:
      - $ref: /schemas/types.yaml#/definitions/uint32
      - enum: [0, 1]
 
+  "^adi,pwm-active-state$":
+    description: |
+      Integer array, represents the active state of the pwm outputs If set to 0
+      the pwm uses a logic low output for 100% duty cycle. If set to 1 the pwm
+      uses a logic high output for 100% duty cycle.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32-array
+      - minItems: 3
+        maxItems: 3
+        items:
+          enum: [0, 1]
+          default: 1
+
 required:
   - compatible
   - reg
@@ -65,6 +78,7 @@ examples:
         reg = <0x2e>;
         adi,bypass-attenuator-in0 = <1>;
         adi,bypass-attenuator-in1 = <0>;
+        adi,pwm-active-state = <1 0 1>;
       };
     };
 
Signature · 1 line
2.25.1
maintainer Reviewed-by on v5 3/5
#6 lore raw

Re: [PATCH v5 3/5] dt-bindings: hwmon: Document adt7475 pwm-active-state property

Quoted 15 lines · Chris Packham

Add binding information for the adi,pwm-active-state property.

---

Notes:
Changes in v5:
- change to adi,pwm-active-state
- uint32 array

Changes in v4:
- use $ref uint32 and enum
- add adi vendor prefix

Quoted 6 lines

Cahnges in v3:
- new

 .../devicetree/bindings/hwmon/adt7475.yaml         | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
maintainer Applied
#7 lore raw

Re: [PATCH v5 3/5] dt-bindings: hwmon: Document adt7475 pwm-active-state property

In reply to Chris Packham
Quoted 4 lines · Chris Packham

Add binding information for the adi,pwm-active-state property.

Applied.

Thanks,
Guenter

Quoted 49 lines

---

Notes:
Changes in v5:
- change to adi,pwm-active-state
- uint32 array

Changes in v4:
- use $ref uint32 and enum
- add adi vendor prefix

Cahnges in v3:
- new

 .../devicetree/bindings/hwmon/adt7475.yaml         | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/hwmon/adt7475.yaml +14 -0
index e40612ee075f..76985034ea73 100644
@@ -50,6 +50,19 @@ patternProperties:
      - $ref: /schemas/types.yaml#/definitions/uint32
      - enum: [0, 1]
 
+  "^adi,pwm-active-state$":
+    description: |
+      Integer array, represents the active state of the pwm outputs If set to 0
+      the pwm uses a logic low output for 100% duty cycle. If set to 1 the pwm
+      uses a logic high output for 100% duty cycle.
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32-array
+      - minItems: 3
+        maxItems: 3
+        items:
+          enum: [0, 1]
+          default: 1
+
 required:
   - compatible
   - reg
@@ -65,6 +78,7 @@ examples:
         reg = <0x2e>;
         adi,bypass-attenuator-in0 = <1>;
         adi,bypass-attenuator-in1 = <0>;
+        adi,pwm-active-state = <1 0 1>;
       };
     };
 
#8 lore raw

PATCH v5 4/5 hwmon: (adt7475) Add attenuator bypass support

In reply to Chris Packham

From: Logan Shaw <[email protected]>

Added support for reading DTS properties to set attenuators on device probe for the ADT7473, ADT7475, ADT7476, and ADT7490.

---

Notes:
Changes in v5:
- None

Changes in v4:
- use vendor prefix for new property

Changes in v3:
- move config2 to struct adt7475_data
- set_property_bit() new helper function to set/clear bit based on dt property value.
- rename to use load_attenuators()

 drivers/hwmon/adt7475.c | 61 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/hwmon/adt7475.c +58 -3
index 01c2eeb02aa9..3649b18359dc 100644
@@ -19,6 +19,7 @@
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/jiffies.h>
+#include <linux/of.h>
 #include <linux/util_macros.h>
 
 /* Indexes for the sysfs hooks */
@@ -193,6 +194,7 @@ struct adt7475_data {
 	unsigned long measure_updated;
 	bool valid;
 
+	u8 config2;
 	u8 config4;
 	u8 config5;
 	u8 has_voltage;
@@ -1458,6 +1460,55 @@ static int adt7475_update_limits(struct i2c_client *client)
 	return 0;
 }
 
+static int set_property_bit(const struct i2c_client *client, char *property,
+			  u8 *config, u8 bit_index)
+{
+	u32 prop_value = 0;
+	int ret = of_property_read_u32(client->dev.of_node, property,
+					&prop_value);
+
+	if (!ret) {
+		if (prop_value)
+			*config |= (1 << bit_index);
+		else
+			*config &= ~(1 << bit_index);
+	}
+
+	return ret;
+}
+
+static int load_attenuators(const struct i2c_client *client, int chip,
+			    struct adt7475_data *data)
+{
+	int ret;
+
+	if (chip == adt7476 || chip == adt7490) {
+		set_property_bit(client, "adi,bypass-attenuator-in0",
+				 &data->config4, 4);
+		set_property_bit(client, "adi,bypass-attenuator-in1",
+				 &data->config4, 5);
+		set_property_bit(client, "adi,bypass-attenuator-in3",
+				 &data->config4, 6);
+		set_property_bit(client, "adi,bypass-attenuator-in4",
+				 &data->config4, 7);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
+						data->config4);
+		if (ret < 0)
+			return ret;
+	} else if (chip == adt7473 || chip == adt7475) {
+		set_property_bit(client, "adi,bypass-attenuator-in1",
+				 &data->config2, 5);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
+						data->config2);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1472,7 +1523,7 @@ static int adt7475_probe(struct i2c_client *client,
 	struct adt7475_data *data;
 	struct device *hwmon_dev;
 	int i, ret = 0, revision, group_num = 0;
-	u8 config2, config3;
+	u8 config3;
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (data == NULL)
@@ -1546,8 +1597,12 @@ static int adt7475_probe(struct i2c_client *client,
 	}
 
 	/* Voltage attenuators can be bypassed, globally or individually */
-	config2 = adt7475_read(REG_CONFIG2);
-	if (config2 & CONFIG2_ATTN) {
+	data->config2 = adt7475_read(REG_CONFIG2);
+	ret = load_attenuators(client, chip, data);
+	if (ret)
+		dev_err(&client->dev, "Error configuring attenuator bypass\n");
+
+	if (data->config2 & CONFIG2_ATTN) {
 		data->bypass_attn = (0x3 << 3) | 0x3;
 	} else {
 		data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
Signature · 1 line
2.25.1
maintainer Applied
#9 lore raw

Re: [PATCH v5 4/5] hwmon: (adt7475) Add attenuator bypass support

Quoted 7 lines · Chris Packham

From: Logan Shaw <[email protected]>

Added support for reading DTS properties to set attenuators on device probe for the ADT7473, ADT7475, ADT7476, and ADT7490.

Applied, with two small changes; see inline.

Thanks,
Guenter

Quoted 39 lines

---

Notes:
Changes in v5:
- None

Changes in v4:
- use vendor prefix for new property

Changes in v3:
- move config2 to struct adt7475_data
- set_property_bit() new helper function to set/clear bit based on dt property value.
- rename to use load_attenuators()

 drivers/hwmon/adt7475.c | 61 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 3 deletions(-)
drivers/hwmon/adt7475.c +2 -0
index 01c2eeb02aa9..3649b18359dc 100644
@@ -19,6 +19,7 @@
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/jiffies.h>
+#include <linux/of.h>
 #include <linux/util_macros.h>
 
 /* Indexes for the sysfs hooks */
@@ -193,6 +194,7 @@ struct adt7475_data {
 	unsigned long measure_updated;
 	bool valid;
 
+	u8 config2;
 	u8 config4;
 	u8 config5;
 	u8 has_voltage;

drivers/hwmon/adt7475.c static int adt7475_update_limits(struct i2c_client *client) · line 1464

Quoted 5 lines
drivers/hwmon/adt7475.c +2 -0
@@ -1458,6 +1460,55 @@ static int adt7475_update_limits(struct i2c_client *client)
 	return 0;
 }
 
+static int set_property_bit(const struct i2c_client *client, char *property,
+			  u8 *config, u8 bit_index)

Aligned continuation line with '('.

Quoted 60 lines
drivers/hwmon/adt7475.c +48 -1
+{
+	u32 prop_value = 0;
+	int ret = of_property_read_u32(client->dev.of_node, property,
+					&prop_value);
+
+	if (!ret) {
+		if (prop_value)
+			*config |= (1 << bit_index);
+		else
+			*config &= ~(1 << bit_index);
+	}
+
+	return ret;
+}
+
+static int load_attenuators(const struct i2c_client *client, int chip,
+			    struct adt7475_data *data)
+{
+	int ret;
+
+	if (chip == adt7476 || chip == adt7490) {
+		set_property_bit(client, "adi,bypass-attenuator-in0",
+				 &data->config4, 4);
+		set_property_bit(client, "adi,bypass-attenuator-in1",
+				 &data->config4, 5);
+		set_property_bit(client, "adi,bypass-attenuator-in3",
+				 &data->config4, 6);
+		set_property_bit(client, "adi,bypass-attenuator-in4",
+				 &data->config4, 7);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
+						data->config4);
+		if (ret < 0)
+			return ret;
+	} else if (chip == adt7473 || chip == adt7475) {
+		set_property_bit(client, "adi,bypass-attenuator-in1",
+				 &data->config2, 5);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
+						data->config2);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1472,7 +1523,7 @@ static int adt7475_probe(struct i2c_client *client,
 	struct adt7475_data *data;
 	struct device *hwmon_dev;
 	int i, ret = 0, revision, group_num = 0;
-	u8 config2, config3;
+	u8 config3;
 
 	data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
 	if (data == NULL)

drivers/hwmon/adt7475.c static int adt7475_probe(struct i2c_client *client, · line 1603

Quoted 9 lines
drivers/hwmon/adt7475.c +4 -2
@@ -1546,8 +1597,12 @@ static int adt7475_probe(struct i2c_client *client,
 	}
 
 	/* Voltage attenuators can be bypassed, globally or individually */
-	config2 = adt7475_read(REG_CONFIG2);
-	if (config2 & CONFIG2_ATTN) {
+	data->config2 = adt7475_read(REG_CONFIG2);
+	ret = load_attenuators(client, chip, data);
+	if (ret)
+		dev_err(&client->dev, "Error configuring attenuator bypass\n");

I would expect this to be a dev_warn() or to abort and return an error. Assuming you want the code to continue in this case, I changed the message to dev_warn(). If that is not what you want, please let me know.

Quoted 5 lines
drivers/hwmon/adt7475.c +2 -0
+
+	if (data->config2 & CONFIG2_ATTN) {
 		data->bypass_attn = (0x3 << 3) | 0x3;
 	} else {
 		data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
#10 lore raw

PATCH v5 5/5 hwmon: (adt7475) Add support for inverting pwm output

In reply to Chris Packham

Add a "adi,pwm-active-state" device-tree property to allow hardware designs to use inverted logic on the PWM output.

---

Notes:
Changes in v5:
- change to adi,pwm-active-state
- uint32 array

Changes in v4:
- use vendor prefix for new property

Changes in v3:
- New

 drivers/hwmon/adt7475.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/hwmon/adt7475.c +34 -0
index 3649b18359dc..142a4fec688b 100644
@@ -1509,6 +1509,36 @@ static int load_attenuators(const struct i2c_client *client, int chip,
 	return 0;
 }
 
+static int adt7475_set_pwm_polarity(struct i2c_client *client)
+{
+	u32 states[ADT7475_PWM_COUNT];
+	int ret, i;
+	u8 val;
+
+	ret = of_property_read_u32_array(client->dev.of_node,
+					 "adi,pwm-active-state", states,
+					 ARRAY_SIZE(states));
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+		ret = adt7475_read(PWM_CONFIG_REG(i));
+		if (ret < 0)
+			return ret;
+		val = ret;
+		if (states[i])
+			val &= ~BIT(4);
+		else
+			val |= BIT(4);
+
+		ret = i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(i), val);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1617,6 +1647,10 @@ static int adt7475_probe(struct i2c_client *client,
 	for (i = 0; i < ADT7475_PWM_COUNT; i++)
 		adt7475_read_pwm(client, i);
 
+	ret = adt7475_set_pwm_polarity(client);
+	if (ret && ret != -EINVAL)
+		dev_err(&client->dev, "Error configuring pwm polarity\n");
+
 	/* Start monitoring */
 	switch (chip) {
 	case adt7475:
Signature · 1 line
2.25.1
maintainer Applied
#11 lore raw

Re: [PATCH v5 5/5] hwmon: (adt7475) Add support for inverting pwm output

Quoted 4 lines · Chris Packham

Add a "adi,pwm-active-state" device-tree property to allow hardware designs to use inverted logic on the PWM output.

Applied, with change described below. Please let me know if ignoring the error is not what you wanted.

Thanks,
Guenter

Quoted 58 lines

---

Notes:
Changes in v5:
- change to adi,pwm-active-state
- uint32 array

Changes in v4:
- use vendor prefix for new property

Changes in v3:
- New

 drivers/hwmon/adt7475.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/hwmon/adt7475.c +30 -0
index 3649b18359dc..142a4fec688b 100644
@@ -1509,6 +1509,36 @@ static int load_attenuators(const struct i2c_client *client, int chip,
 	return 0;
 }
 
+static int adt7475_set_pwm_polarity(struct i2c_client *client)
+{
+	u32 states[ADT7475_PWM_COUNT];
+	int ret, i;
+	u8 val;
+
+	ret = of_property_read_u32_array(client->dev.of_node,
+					 "adi,pwm-active-state", states,
+					 ARRAY_SIZE(states));
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+		ret = adt7475_read(PWM_CONFIG_REG(i));
+		if (ret < 0)
+			return ret;
+		val = ret;
+		if (states[i])
+			val &= ~BIT(4);
+		else
+			val |= BIT(4);
+
+		ret = i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(i), val);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {

drivers/hwmon/adt7475.c static int adt7475_probe(struct i2c_client *client, · line 1652

Quoted 6 lines
drivers/hwmon/adt7475.c +3 -0
@@ -1617,6 +1647,10 @@ static int adt7475_probe(struct i2c_client *client,
 	for (i = 0; i < ADT7475_PWM_COUNT; i++)
 		adt7475_read_pwm(client, i);
 
+	ret = adt7475_set_pwm_polarity(client);
+	if (ret && ret != -EINVAL)
+		dev_err(&client->dev, "Error configuring pwm polarity\n");
		dev_err -> dev_warn
Quoted 4 lines
drivers/hwmon/adt7475.c +1 -0
+
 	/* Start monitoring */
 	switch (chip) {
 	case adt7475: