@@ -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:
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@alliedtelesis.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(+)