All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Sven Van Asbroeck <thesven73@gmail.com>,
	thierry.reding@gmail.com, "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org,
	clemens.gruber@pqgruber.com, mika.westerberg@linux.intel.com,
	Sven Van Asbroeck <TheSven73@googlemail.com>
Subject: Re: [PATCH v4 1/1] pwm: pca9685: fix gpio-only operation.
Date: Tue, 18 Apr 2017 12:14:12 +0300	[thread overview]
Message-ID: <1492506852.24567.54.camel@linux.intel.com> (raw)
In-Reply-To: <1492088291-5215-2-git-send-email-svenv@arcx.com>


+Cc: Rafael (one question to you below)

On Thu, 2017-04-13 at 08:58 -0400, Sven Van Asbroeck wrote:
> 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 letting the runtime_pm framework
> control the SLEEP bit. This will put the chip to SLEEP if
> no pwms/gpios are exported/in use.
> 

I know the patch is applied already, though please consider below to be
addressed as usual (w/o Fixes tag).

> +static void pca9685_set_sleep_mode(struct pca9685 *pca, int sleep)
> +{
> +	regmap_update_bits(pca->regmap, PCA9685_MODE1,
> +			   MODE1_SLEEP, sleep ? MODE1_SLEEP : 0);

> +	if (!sleep) {
> +		/* Wait 500us for the oscillator to be back up */
> +		udelay(500);
> +	}

I would go with

/* Wait for @sleep microseconds for the oscillator to be back up */
if (sleep)
 udelay(sleep);

Otherwise int sleep is oddly here.

Or

bool sleep

/* Wait 500us ... */
if (sleep)
 udelay(500);

> +}


> +#ifdef CONFIG_PM
> +static int pca9685_pwm_runtime_suspend(struct device *dev)

__maybe_unused and remove ugly #ifdef:ery.

> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct pca9685 *pca = i2c_get_clientdata(client);
> +
> +	pca9685_set_sleep_mode(pca, 1);
> +	return 0;
>  }
>  
> +static int pca9685_pwm_runtime_resume(struct device *dev)

Ditto.

> +{
> +	struct i2c_client *client = to_i2c_client(dev);
> +	struct pca9685 *pca = i2c_get_clientdata(client);
> +
> +	pca9685_set_sleep_mode(pca, 0);
> +	return 0;
> +}
> +#endif

> +static const struct dev_pm_ops pca9685_pwm_pm = {
> +	SET_RUNTIME_PM_OPS(pca9685_pwm_runtime_suspend,
> +			   pca9685_pwm_runtime_resume, NULL)
> +};
> +

Perhaps we may introduce RUNTIME_DEV_PM_OPS() macro and re-use it here.
Rafael?

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

  parent reply	other threads:[~2017-04-18  9:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 12:58 [PATCH v4 0/1] pwm: pca9685: fix gpio-only operation Sven Van Asbroeck
2017-04-13 12:58 ` [PATCH v4 1/1] " Sven Van Asbroeck
2017-04-13 15:34   ` Thierry Reding
2017-04-18  9:14   ` Andy Shevchenko [this message]
2017-04-18 15:52     ` Sven Van Asbroeck
2017-04-19 20:24       ` Mika Westerberg
2017-04-20  7:29       ` Andy Shevchenko
2017-04-20 14:12         ` Sven Van Asbroeck
2017-04-20 15:07           ` Andy Shevchenko
2017-04-20 15:50             ` Sven Van Asbroeck
2017-04-20 16:13               ` Andy Shevchenko
2017-04-20 15:55             ` 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=1492506852.24567.54.camel@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=TheSven73@googlemail.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=rjw@rjwysocki.net \
    --cc=thesven73@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.