diff mbox series

[2/2] hwmon: emc2305: Add device tree support for polarity and pwm output

Message ID 20250210073158.336522-3-florin.leotescu@oss.nxp.com (mailing list archive)
State New
Headers show
Series emc2305 driver updates | expand

Commit Message

Florin Leotescu (OSS) Feb. 10, 2025, 7:31 a.m. UTC
From: Florin Leotescu <florin.leotescu@nxp.com>

The patch enhances emc2305 driver by adding support for configuring
pwm output and polarity via Device Tree properties.

Signed-off-by: Florin Leotescu <florin.leotescu@nxp.com>
---
 drivers/hwmon/emc2305.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Guenter Roeck Feb. 10, 2025, 4:15 p.m. UTC | #1
On 2/9/25 23:31, florin.leotescu@oss.nxp.com wrote:
> From: Florin Leotescu <florin.leotescu@nxp.com>
> 
> The patch enhances emc2305 driver by adding support for configuring
> pwm output and polarity via Device Tree properties.
> 
> Signed-off-by: Florin Leotescu <florin.leotescu@nxp.com>

You can not just add support for devictree attributes to a driver
without documenting it in a devicetree .yaml file and getting it approved
by devicetree maintainers.

Guenter
Florin Leotescu (OSS) Feb. 10, 2025, 4:28 p.m. UTC | #2
Hi Guenter,

Thanks for reviewing the patch and for your feedback. I will document device tree attributes in a separate patch as suggested.

Best regards,
Florin

-----Original Message-----
From: Guenter Roeck <groeck7@gmail.com> On Behalf Of Guenter Roeck
Sent: Monday, February 10, 2025 6:15 PM
To: Florin Leotescu (OSS) <florin.leotescu@oss.nxp.com>; Jean Delvare <jdelvare@suse.com>; linux-hwmon@vger.kernel.org; linux-kernel@vger.kernel.org; Viorel Suman <viorel.suman@nxp.com>
Cc: Florin Leotescu <florin.leotescu@nxp.com>
Subject: [EXT] Re: [PATCH 2/2] hwmon: emc2305: Add device tree support for polarity and pwm output

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button


On 2/9/25 23:31, florin.leotescu@oss.nxp.com wrote:
> From: Florin Leotescu <florin.leotescu@nxp.com>
>
> The patch enhances emc2305 driver by adding support for configuring 
> pwm output and polarity via Device Tree properties.
>
> Signed-off-by: Florin Leotescu <florin.leotescu@nxp.com>

You can not just add support for devictree attributes to a driver without documenting it in a devicetree .yaml file and getting it approved by devicetree maintainers.

Guenter
diff mbox series

Patch

diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 18e765902d32..e8cdc0cbcb35 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -23,6 +23,8 @@ 
 #define EMC2305_TACH_REGS_UNUSE_BITS	3
 #define EMC2305_TACH_CNT_MULTIPLIER	0x02
 #define EMC2305_TACH_RANGE_MIN		480
+#define EMC2305_REG_DRIVE_PWM_OUT_CONFIG 0x2b
+#define EMC2305_REG_POLARITY 0x2a
 
 #define EMC2305_PWM_DUTY2STATE(duty, max_state, pwm_max) \
 	DIV_ROUND_CLOSEST((duty) * (max_state), (pwm_max))
@@ -537,6 +539,8 @@  static int emc2305_probe(struct i2c_client *client)
 	int vendor;
 	int ret;
 	int i;
+	int pwm_polarity;
+	int pwm_output;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
 		return -ENODEV;
@@ -590,6 +594,29 @@  static int emc2305_probe(struct i2c_client *client)
 			return ret;
 	}
 
+	if (!of_property_read_u32(dev->of_node, "pwm_output", &pwm_output)) {
+		dev_dbg(dev, "Configuring pwm output\n");
+		if (pwm_output >= 0 && pwm_output <= ((1 << data->pwm_num) - 1)) {
+			ret = i2c_smbus_write_byte_data(client, EMC2305_REG_DRIVE_PWM_OUT_CONFIG,
+							 pwm_output);
+			if (ret < 0)
+				dev_err(dev, "Failed to configure pwm output, using default\n");
+		} else {
+			dev_err(dev, "Wrong PWM output config provided: %u\n", pwm_output);
+		}
+	}
+
+	if (!of_property_read_u32(dev->of_node, "pwm_polarity", &pwm_polarity)) {
+		dev_dbg(dev, "Configuring pwm polarity\n");
+		if (pwm_polarity >= 0 && pwm_polarity  <= ((1 << data->pwm_num) - 1)) {
+			ret = i2c_smbus_write_byte_data(client, EMC2305_REG_POLARITY, pwm_polarity);
+			if (ret < 0)
+				dev_err(dev, "Failed to configure pwm polarity, using default\n");
+		} else {
+			dev_err(dev, "Wrong PWM polarity config provided: %u\n", pwm_polarity);
+		}
+	}
+
 	for (i = 0; i < data->pwm_num; i++) {
 		ret = i2c_smbus_write_byte_data(client, EMC2305_REG_FAN_MIN_DRIVE(i),
 						data->pwm_min[i]);