* [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback
@ 2018-09-25 7:25 Hans de Goede
2018-09-25 7:25 ` [PATCH v2 2/2] pwm: lpss: Add get_state callback Hans de Goede
2018-09-25 9:09 ` [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Hans de Goede @ 2018-09-25 7:25 UTC (permalink / raw)
To: Thierry Reding, Andy Shevchenko; +Cc: Hans de Goede, linux-pwm, linux-acpi
For each pwm output which gets enabled through pwm_lpss_apply(), we do a
pm_runtime_get_sync().
This commit adds pm_runtime_put() calls to pwm_lpss_remove() to balance
these when the driver gets removed with some of the outputs still enabled.
Fixes: f080be27d7d9 ("pwm: lpss: Add support for runtime PM")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-New patch in v2 of this patch-set replacing "pwm: lpss: Add
pwm_lpss_get_put_runtime_pm helper function"
---
drivers/pwm/pwm-lpss.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
index e602835fd6de..723ca9de8325 100644
--- a/drivers/pwm/pwm-lpss.c
+++ b/drivers/pwm/pwm-lpss.c
@@ -205,6 +205,12 @@ EXPORT_SYMBOL_GPL(pwm_lpss_probe);
int pwm_lpss_remove(struct pwm_lpss_chip *lpwm)
{
+ int i;
+
+ for (i = 0; i < lpwm->info->npwm; i++) {
+ if (pwm_is_enabled(&lpwm->chip.pwms[i]))
+ pm_runtime_put(lpwm->chip.dev);
+ }
return pwmchip_remove(&lpwm->chip);
}
EXPORT_SYMBOL_GPL(pwm_lpss_remove);
--
2.19.0.rc1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] pwm: lpss: Add get_state callback
2018-09-25 7:25 [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Hans de Goede
@ 2018-09-25 7:25 ` Hans de Goede
2018-09-25 9:40 ` Andy Shevchenko
2018-09-25 9:09 ` [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2018-09-25 7:25 UTC (permalink / raw)
To: Thierry Reding, Andy Shevchenko; +Cc: Hans de Goede, linux-pwm, linux-acpi
Add a get_state callback so that the initial state correctly reflects
the actual hardware state.
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v2:
-Stop using the dropped pwm_lpss_get_put_runtime_pm() helper
---
drivers/pwm/pwm-lpss.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
index 723ca9de8325..ea93ef9f3672 100644
--- a/drivers/pwm/pwm-lpss.c
+++ b/drivers/pwm/pwm-lpss.c
@@ -159,8 +159,42 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
return 0;
}
+/* This function gets called once from pwmchip_add to get the initial state */
+static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
+ struct pwm_state *state)
+{
+ struct pwm_lpss_chip *lpwm = to_lpwm(chip);
+ unsigned long base_unit_range;
+ unsigned long long base_unit, freq, on_time_div;
+ u32 ctrl;
+
+ base_unit_range = BIT(lpwm->info->base_unit_bits);
+
+ ctrl = pwm_lpss_read(pwm);
+ on_time_div = 255 - (ctrl & PWM_ON_TIME_DIV_MASK);
+ base_unit = (ctrl >> PWM_BASE_UNIT_SHIFT) & (base_unit_range - 1);
+
+ freq = base_unit * lpwm->info->clk_rate;
+ do_div(freq, base_unit_range);
+ if (freq == 0)
+ state->period = NSEC_PER_SEC;
+ else
+ state->period = NSEC_PER_SEC / (unsigned long)freq;
+
+ on_time_div *= state->period;
+ do_div(on_time_div, 255);
+ state->duty_cycle = on_time_div;
+
+ state->polarity = PWM_POLARITY_NORMAL;
+ state->enabled = !!(ctrl & PWM_ENABLE);
+
+ if (state->enabled)
+ pm_runtime_get(chip->dev);
+}
+
static const struct pwm_ops pwm_lpss_ops = {
.apply = pwm_lpss_apply,
+ .get_state = pwm_lpss_get_state,
.owner = THIS_MODULE,
};
--
2.19.0.rc1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback
2018-09-25 7:25 [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Hans de Goede
2018-09-25 7:25 ` [PATCH v2 2/2] pwm: lpss: Add get_state callback Hans de Goede
@ 2018-09-25 9:09 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-09-25 9:09 UTC (permalink / raw)
To: Hans de Goede; +Cc: Thierry Reding, linux-pwm, linux-acpi
On Tue, Sep 25, 2018 at 09:25:35AM +0200, Hans de Goede wrote:
> For each pwm output which gets enabled through pwm_lpss_apply(), we do a
> pm_runtime_get_sync().
>
> This commit adds pm_runtime_put() calls to pwm_lpss_remove() to balance
> these when the driver gets removed with some of the outputs still enabled.
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Fixes: f080be27d7d9 ("pwm: lpss: Add support for runtime PM")
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> -New patch in v2 of this patch-set replacing "pwm: lpss: Add
> pwm_lpss_get_put_runtime_pm helper function"
> ---
> drivers/pwm/pwm-lpss.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
> index e602835fd6de..723ca9de8325 100644
> --- a/drivers/pwm/pwm-lpss.c
> +++ b/drivers/pwm/pwm-lpss.c
> @@ -205,6 +205,12 @@ EXPORT_SYMBOL_GPL(pwm_lpss_probe);
>
> int pwm_lpss_remove(struct pwm_lpss_chip *lpwm)
> {
> + int i;
> +
> + for (i = 0; i < lpwm->info->npwm; i++) {
> + if (pwm_is_enabled(&lpwm->chip.pwms[i]))
> + pm_runtime_put(lpwm->chip.dev);
> + }
> return pwmchip_remove(&lpwm->chip);
> }
> EXPORT_SYMBOL_GPL(pwm_lpss_remove);
> --
> 2.19.0.rc1
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] pwm: lpss: Add get_state callback
2018-09-25 7:25 ` [PATCH v2 2/2] pwm: lpss: Add get_state callback Hans de Goede
@ 2018-09-25 9:40 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-09-25 9:40 UTC (permalink / raw)
To: Hans de Goede; +Cc: Thierry Reding, linux-pwm, linux-acpi
On Tue, Sep 25, 2018 at 09:25:36AM +0200, Hans de Goede wrote:
> Add a get_state callback so that the initial state correctly reflects
> the actual hardware state.
>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> -Stop using the dropped pwm_lpss_get_put_runtime_pm() helper
> ---
> drivers/pwm/pwm-lpss.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
> index 723ca9de8325..ea93ef9f3672 100644
> --- a/drivers/pwm/pwm-lpss.c
> +++ b/drivers/pwm/pwm-lpss.c
> @@ -159,8 +159,42 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> return 0;
> }
>
> +/* This function gets called once from pwmchip_add to get the initial state */
> +static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> + struct pwm_state *state)
> +{
> + struct pwm_lpss_chip *lpwm = to_lpwm(chip);
> + unsigned long base_unit_range;
> + unsigned long long base_unit, freq, on_time_div;
> + u32 ctrl;
> +
> + base_unit_range = BIT(lpwm->info->base_unit_bits);
> +
> + ctrl = pwm_lpss_read(pwm);
> + on_time_div = 255 - (ctrl & PWM_ON_TIME_DIV_MASK);
> + base_unit = (ctrl >> PWM_BASE_UNIT_SHIFT) & (base_unit_range - 1);
> +
> + freq = base_unit * lpwm->info->clk_rate;
> + do_div(freq, base_unit_range);
> + if (freq == 0)
> + state->period = NSEC_PER_SEC;
> + else
> + state->period = NSEC_PER_SEC / (unsigned long)freq;
> +
> + on_time_div *= state->period;
> + do_div(on_time_div, 255);
> + state->duty_cycle = on_time_div;
> +
> + state->polarity = PWM_POLARITY_NORMAL;
> + state->enabled = !!(ctrl & PWM_ENABLE);
> +
> + if (state->enabled)
> + pm_runtime_get(chip->dev);
> +}
> +
> static const struct pwm_ops pwm_lpss_ops = {
> .apply = pwm_lpss_apply,
> + .get_state = pwm_lpss_get_state,
> .owner = THIS_MODULE,
> };
>
> --
> 2.19.0.rc1
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-25 9:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-25 7:25 [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Hans de Goede
2018-09-25 7:25 ` [PATCH v2 2/2] pwm: lpss: Add get_state callback Hans de Goede
2018-09-25 9:40 ` Andy Shevchenko
2018-09-25 9:09 ` [PATCH v2 1/2] pwm: lpss: Release runtime-pm reference from the driver's remove callback Andy Shevchenko
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.