[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181108225607.7521-3-chris.packham@alliedtelesis.co.nz>
Date: Fri, 9 Nov 2018 11:56:07 +1300
From: Chris Packham <chris.packham@...iedtelesis.co.nz>
To: linux@...ck-us.net, robh+dt@...nel.org, jdelvare@...e.com
Cc: linux-hwmon@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Chris Packham <chris.packham@...iedtelesis.co.nz>
Subject: [PATCH v2 2/2] hwmon: (adt7475): add support for inverting the pwm output
Add a "invert-pwm" device-tree property to allow hardware designs to use
inverted logic on the PWM output. We intentionally preserve the invert
PWM output bit if the property is not found to allow for
bootloaders/bios which may have configured this earlier.
Signed-off-by: Chris Packham <chris.packham@...iedtelesis.co.nz>
---
Changes in v2:
- use "pwm-polarity" and support setting both logic high and logic low
drivers/hwmon/adt7475.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index f4c7516eb989..ce2c7d6493c0 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -23,6 +23,7 @@
#include <linux/err.h>
#include <linux/jiffies.h>
#include <linux/util_macros.h>
+#include <linux/pwm.h>
/* Indexes for the sysfs hooks */
@@ -1536,6 +1537,23 @@ static int adt7475_update_limits(struct i2c_client *client)
return 0;
}
+static int adt7475_set_pwm_polarity(struct i2c_client *client, int index,
+ enum pwm_polarity pol)
+{
+ int ret;
+
+ ret = adt7475_read(PWM_CONFIG_REG(index));
+ if (ret < 0)
+ return ret;
+
+ if (pol == PWM_POLARITY_INVERSED)
+ ret |= BIT(4);
+ else
+ ret &= ~BIT(4);
+
+ return i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(index), ret);
+}
+
static int adt7475_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -1638,6 +1656,16 @@ static int adt7475_probe(struct i2c_client *client,
for (i = 0; i < ADT7475_PWM_COUNT; i++)
adt7475_read_pwm(client, i);
+ if (client->dev.of_node) {
+ enum pwm_polarity polarity;
+
+ ret = of_property_read_u32(client->dev.of_node, "pwm-polarity",
+ &polarity);
+ if (!ret)
+ for (i = 0; i < ADT7475_PWM_COUNT; i++)
+ adt7475_set_pwm_polarity(client, i, polarity);
+ }
+
/* Start monitoring */
switch (chip) {
case adt7475:
--
2.19.1
Powered by blists - more mailing lists