Linux PWM subsystem development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Thierry Reding <thierry.reding@gmail.com>,
	linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org
Subject: Re: [PATCH 1/2] pwm: lpss: Add pwm_lpss_get_put_runtime_pm helper function
Date: Mon, 24 Sep 2018 12:16:53 +0300	[thread overview]
Message-ID: <20180924091653.GF15943@smile.fi.intel.com> (raw)
In-Reply-To: <20180911174533.4484-2-hdegoede@redhat.com>

On Tue, Sep 11, 2018 at 07:45:32PM +0200, Hans de Goede wrote:
> Add a helper function to properly get / put the pwm's runtime_pm
> reference when changing from enabled to disable or vice versa.
> 
> And use this to ensure the pwm's runtime_pm reference is properly
> released on remove.
> 

Can you provide a test sequence to reproduce the issue?

> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  drivers/pwm/pwm-lpss.c | 47 +++++++++++++++++++++++++++++-------------
>  1 file changed, 33 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
> index e602835fd6de..d39158800baa 100644
> --- a/drivers/pwm/pwm-lpss.c
> +++ b/drivers/pwm/pwm-lpss.c
> @@ -120,43 +120,58 @@ static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond)
>  		pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_ENABLE);
>  }
>  
> +static void pwm_lpss_get_put_runtime_pm(struct pwm_chip *chip,
> +					bool old_enabled, bool new_enabled)
> +{
> +	if (new_enabled == old_enabled)
> +		return;
> +
> +	if (new_enabled)
> +		pm_runtime_get(chip->dev);
> +	else
> +		pm_runtime_put(chip->dev);
> +}
> +
>  static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>  			  struct pwm_state *state)
>  {
>  	struct pwm_lpss_chip *lpwm = to_lpwm(chip);
> -	int ret;
> +	int ret = 0;
> +
> +	pm_runtime_get_sync(chip->dev);
>  
>  	if (state->enabled) {
>  		if (!pwm_is_enabled(pwm)) {
> -			pm_runtime_get_sync(chip->dev);
>  			ret = pwm_lpss_is_updating(pwm);
> -			if (ret) {
> -				pm_runtime_put(chip->dev);
> -				return ret;
> -			}
> +			if (ret)
> +				goto out;
> +
>  			pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period);
>  			pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE);
>  			pwm_lpss_cond_enable(pwm, lpwm->info->bypass == false);
>  			ret = pwm_lpss_wait_for_update(pwm);
> -			if (ret) {
> -				pm_runtime_put(chip->dev);
> -				return ret;
> -			}
> +			if (ret)
> +				goto out;
> +
>  			pwm_lpss_cond_enable(pwm, lpwm->info->bypass == true);
>  		} else {
>  			ret = pwm_lpss_is_updating(pwm);
>  			if (ret)
> -				return ret;
> +				goto out;
> +
>  			pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period);
>  			pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE);
> -			return pwm_lpss_wait_for_update(pwm);
> +			ret = pwm_lpss_wait_for_update(pwm);
>  		}
>  	} else if (pwm_is_enabled(pwm)) {
>  		pwm_lpss_write(pwm, pwm_lpss_read(pwm) & ~PWM_ENABLE);
> -		pm_runtime_put(chip->dev);
>  	}
>  
> -	return 0;
> +	pwm_lpss_get_put_runtime_pm(chip, pwm_is_enabled(pwm), state->enabled);
> +
> +out:
> +	pm_runtime_put(chip->dev);
> +	return ret;
>  }
>  
>  static const struct pwm_ops pwm_lpss_ops = {
> @@ -205,6 +220,10 @@ EXPORT_SYMBOL_GPL(pwm_lpss_probe);
>  
>  int pwm_lpss_remove(struct pwm_lpss_chip *lpwm)
>  {
> +	bool enabled = pwm_is_enabled(&lpwm->chip.pwms[0]);
> +
> +	pwm_lpss_get_put_runtime_pm(&lpwm->chip, enabled, false);
> +
>  	return pwmchip_remove(&lpwm->chip);
>  }
>  EXPORT_SYMBOL_GPL(pwm_lpss_remove);
> -- 
> 2.19.0.rc0
> 

-- 
With Best Regards,
Andy Shevchenko

  reply	other threads:[~2018-09-24  9:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11 17:45 [PATCH 0/2] pwm: lpss: Atomic PWM support for LPSS Hans de Goede
2018-09-11 17:45 ` [PATCH 1/2] pwm: lpss: Add pwm_lpss_get_put_runtime_pm helper function Hans de Goede
2018-09-24  9:16   ` Andy Shevchenko [this message]
2018-09-24  9:58     ` Hans de Goede
2018-09-24 10:05       ` Andy Shevchenko
2018-09-24 12:13         ` Hans de Goede
2018-09-24 13:22           ` Andy Shevchenko
2018-09-11 17:45 ` [PATCH 2/2] pwm: lpss: Add get_state callback Hans de Goede

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=20180924091653.GF15943@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --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