Skip to content

Commit 01aa905

Browse files
jwrdegoedethierryreding
authored andcommitted
pwm: lpss: Fix get_state runtime-pm reference handling
Before commit cfc4c18 ("pwm: Read initial hardware state at request time"), a driver's get_state callback would get called once per PWM from pwmchip_add(). pwm-lpss' runtime-pm code was relying on this, getting a runtime-pm ref for PWMs which are enabled at probe time from within its get_state callback, before enabling runtime-pm. The change to calling get_state at request time causes a number of problems: 1. PWMs enabled at probe time may get runtime suspended before they are requested, causing e.g. a LCD backlight controlled by the PWM to turn off. 2. When the request happens when the PWM has been runtime suspended, the ctrl register will read all 1 / 0xffffffff, causing get_state to store bogus values in the pwm_state. 3. get_state was using an async pm_runtime_get() call, because it assumed that runtime-pm has not been enabled yet. If shortly after the request an apply call is made, then the pwm_lpss_is_updating() check may trigger because the resume triggered by the pm_runtime_get() call is not complete yet, so the ctrl register still reads all 1 / 0xffffffff. This commit fixes these issues by moving the initial pm_runtime_get() call for PWMs which are enabled at probe time to the pwm_lpss_probe() function; and by making get_state take a runtime-pm ref before reading the ctrl reg. BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1828927 Fixes: cfc4c18 ("pwm: Read initial hardware state at request time") Cc: [email protected] Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 856c45d commit 01aa905

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/pwm/pwm-lpss.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
158158
return 0;
159159
}
160160

161-
/* This function gets called once from pwmchip_add to get the initial state */
162161
static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
163162
struct pwm_state *state)
164163
{
@@ -167,6 +166,8 @@ static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
167166
unsigned long long base_unit, freq, on_time_div;
168167
u32 ctrl;
169168

169+
pm_runtime_get_sync(chip->dev);
170+
170171
base_unit_range = BIT(lpwm->info->base_unit_bits);
171172

172173
ctrl = pwm_lpss_read(pwm);
@@ -187,8 +188,7 @@ static void pwm_lpss_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
187188
state->polarity = PWM_POLARITY_NORMAL;
188189
state->enabled = !!(ctrl & PWM_ENABLE);
189190

190-
if (state->enabled)
191-
pm_runtime_get(chip->dev);
191+
pm_runtime_put(chip->dev);
192192
}
193193

194194
static const struct pwm_ops pwm_lpss_ops = {
@@ -202,7 +202,8 @@ struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
202202
{
203203
struct pwm_lpss_chip *lpwm;
204204
unsigned long c;
205-
int ret;
205+
int i, ret;
206+
u32 ctrl;
206207

207208
if (WARN_ON(info->npwm > MAX_PWMS))
208209
return ERR_PTR(-ENODEV);
@@ -232,6 +233,12 @@ struct pwm_lpss_chip *pwm_lpss_probe(struct device *dev, struct resource *r,
232233
return ERR_PTR(ret);
233234
}
234235

236+
for (i = 0; i < lpwm->info->npwm; i++) {
237+
ctrl = pwm_lpss_read(&lpwm->chip.pwms[i]);
238+
if (ctrl & PWM_ENABLE)
239+
pm_runtime_get(dev);
240+
}
241+
235242
return lpwm;
236243
}
237244
EXPORT_SYMBOL_GPL(pwm_lpss_probe);

0 commit comments

Comments
 (0)