linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sven Van Asbroeck <thesven73@gmail.com>
To: thierry.reding@gmail.com
Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
	clemens.gruber@pqgruber.com, mika.westerberg@linux.intel.com,
	andriy.shevchenko@linux.intel.com,
	Sven Van Asbroeck <TheSven73@googlemail.com>
Subject: [PATCH 1/1] pwm: pca9685: fix gpio-only operation.
Date: Sun,  9 Apr 2017 12:11:24 -0400	[thread overview]
Message-ID: <1491754284-3870-2-git-send-email-svenv@arcx.com> (raw)
In-Reply-To: <1491754284-3870-1-git-send-email-svenv@arcx.com>

gpio-only driver operation never clears the SLEEP bit, which can
cause the gpios to become unusable.

Example:
1. user requests first pwm  ->      driver clears SLEEP bit
2. user frees last pwm      ->      driver sets SLEEP bit
3. user requests gpio
4. user switches gpio on    ->      output does not turn on
                                    because SLEEP bit is set

Prevent this behaviour by keeping the SLEEP bit cleared
for the lifetime of the driver instance.

Fixes: bccec89f0a35 ("Allow any of the 16 PWMs to be used as a GPIO")
Signed-off-by: Sven Van Asbroeck <TheSven73@googlemail.com>
---
 drivers/pwm/pwm-pca9685.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/pwm/pwm-pca9685.c b/drivers/pwm/pwm-pca9685.c
index 0cfb357..4b6adaf 100644
--- a/drivers/pwm/pwm-pca9685.c
+++ b/drivers/pwm/pwm-pca9685.c
@@ -79,7 +79,6 @@
 struct pca9685 {
 	struct pwm_chip chip;
 	struct regmap *regmap;
-	int active_cnt;
 	int duty_ns;
 	int period_ns;
 #if IS_ENABLED(CONFIG_GPIOLIB)
@@ -407,28 +406,14 @@ static int pca9685_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
 	if (pca9685_pwm_is_gpio(pca, pwm))
 		return -EBUSY;
 
-	if (pca->active_cnt++ == 0)
-		return regmap_update_bits(pca->regmap, PCA9685_MODE1,
-					  MODE1_SLEEP, 0x0);
-
 	return 0;
 }
 
-static void pca9685_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
-{
-	struct pca9685 *pca = to_pca(chip);
-
-	if (--pca->active_cnt == 0)
-		regmap_update_bits(pca->regmap, PCA9685_MODE1, MODE1_SLEEP,
-				   MODE1_SLEEP);
-}
-
 static const struct pwm_ops pca9685_pwm_ops = {
 	.enable = pca9685_pwm_enable,
 	.disable = pca9685_pwm_disable,
 	.config = pca9685_pwm_config,
 	.request = pca9685_pwm_request,
-	.free = pca9685_pwm_free,
 	.owner = THIS_MODULE,
 };
 
@@ -479,6 +464,9 @@ static int pca9685_pwm_probe(struct i2c_client *client,
 	/* clear all "full off" bits */
 	regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_L, 0);
 	regmap_write(pca->regmap, PCA9685_ALL_LED_OFF_H, 0);
+	/* clear the "sleep" bit */
+	regmap_update_bits(pca->regmap, PCA9685_MODE1,
+					  MODE1_SLEEP, 0x0);
 
 	pca->chip.ops = &pca9685_pwm_ops;
 	/* add an extra channel for ALL_LED */
-- 
1.9.1

  reply	other threads:[~2017-04-09 16:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-09 16:11 [PATCH 0/1] pwm: pca9685: fix gpio-only operation Sven Van Asbroeck
2017-04-09 16:11 ` Sven Van Asbroeck [this message]
2017-04-10 10:33   ` [PATCH 1/1] " Mika Westerberg
2017-04-10 16:08     ` Sven Van Asbroeck
2017-04-11  3:35     ` Sven Van Asbroeck
2017-04-11  9:11       ` Mika Westerberg

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=1491754284-3870-2-git-send-email-svenv@arcx.com \
    --to=thesven73@gmail.com \
    --cc=TheSven73@googlemail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=clemens.gruber@pqgruber.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=thierry.reding@gmail.com \
    /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).