linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: linux@roeck-us.net, robh+dt@kernel.org, jdelvare@suse.com
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH v2 2/2] hwmon: (adt7475): add support for inverting the pwm output
Date: Fri,  9 Nov 2018 11:56:07 +1300	[thread overview]
Message-ID: <20181108225607.7521-3-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20181108225607.7521-1-chris.packham@alliedtelesis.co.nz>

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(+)

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

      parent reply	other threads:[~2018-11-08 22:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-08 22:56 [PATCH v2 0/2] hwmon: (adt7475): inverted PWM output Chris Packham
2018-11-08 22:56 ` [PATCH v2 1/2] dt-bindings: hwmon: add binding documentation for adt7475 Chris Packham
2018-11-12  0:34   ` Chris Packham
2018-11-17 15:29   ` Rob Herring
2018-11-18 22:56     ` Guenter Roeck
2018-11-19 21:40       ` Rob Herring
2018-11-19 21:55         ` Chris Packham
2018-11-08 22:56 ` Chris Packham [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181108225607.7521-3-chris.packham@alliedtelesis.co.nz \
    --to=chris.packham@alliedtelesis.co.nz \
    --cc=devicetree@vger.kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).