diff options
author | Hans de Goede <hdegoede@redhat.com> | 2018-10-14 11:12:02 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2018-10-16 07:16:15 -0400 |
commit | 2153bbc12f77fb2203276befc0f0dddbfb023bb1 (patch) | |
tree | 3e6d98a0d7406446f6a0ae470ab8f3ad0d0c1fe0 /drivers/pwm/pwm-lpss.c | |
parent | 4743765babb278a7d399df5733fc8a6b6bbedf3e (diff) |
pwm: lpss: Only set update bit if we are actually changing the settings
According to the datasheet the update bit must be set if the on-time-div
or the base-unit changes.
Now that we properly order device resume on Cherry Trail so that the GFX0
_PS0 method no longer exits with an error, we end up with a sequence of
events where we are writing the same values twice in a row.
First the _PS0 method restores the duty cycle of 0% the GPU driver set
on suspend and then the GPU driver first updates just the enabled bit in
the pwm_state from 0 to 1, causing us to write the same values again,
before restoring the pre-suspend duty-cycle in a separate pwm_apply call.
When writing the update bit the second time, without changing any of
the values the update bit clears immediately / instantly, instead of
staying 1 for a while as usual. After this the next setting of the update
bit seems to be ignored, causing the restoring of the pre-suspend
duty-cycle to not get applied. This makes the backlight come up with
a 0% dutycycle after suspend/resume.
Any further brightness changes after this do work.
This commit moves the setting of the update bit into pwm_lpss_prepare()
and only sets the bit if we have actually changed any of the values.
This avoids the setting of the update bit the second time we configure
the PWM to 0% dutycycle, this fixes the backlight coming up with 0%
duty-cycle after a suspend/resume.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-lpss.c')
-rw-r--r-- | drivers/pwm/pwm-lpss.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c index ea93ef9f3672..2ac3a2aa9e53 100644 --- a/drivers/pwm/pwm-lpss.c +++ b/drivers/pwm/pwm-lpss.c | |||
@@ -88,7 +88,7 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, | |||
88 | unsigned long long on_time_div; | 88 | unsigned long long on_time_div; |
89 | unsigned long c = lpwm->info->clk_rate, base_unit_range; | 89 | unsigned long c = lpwm->info->clk_rate, base_unit_range; |
90 | unsigned long long base_unit, freq = NSEC_PER_SEC; | 90 | unsigned long long base_unit, freq = NSEC_PER_SEC; |
91 | u32 ctrl; | 91 | u32 orig_ctrl, ctrl; |
92 | 92 | ||
93 | do_div(freq, period_ns); | 93 | do_div(freq, period_ns); |
94 | 94 | ||
@@ -105,13 +105,17 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm, | |||
105 | do_div(on_time_div, period_ns); | 105 | do_div(on_time_div, period_ns); |
106 | on_time_div = 255ULL - on_time_div; | 106 | on_time_div = 255ULL - on_time_div; |
107 | 107 | ||
108 | ctrl = pwm_lpss_read(pwm); | 108 | orig_ctrl = ctrl = pwm_lpss_read(pwm); |
109 | ctrl &= ~PWM_ON_TIME_DIV_MASK; | 109 | ctrl &= ~PWM_ON_TIME_DIV_MASK; |
110 | ctrl &= ~(base_unit_range << PWM_BASE_UNIT_SHIFT); | 110 | ctrl &= ~(base_unit_range << PWM_BASE_UNIT_SHIFT); |
111 | base_unit &= base_unit_range; | 111 | base_unit &= base_unit_range; |
112 | ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT; | 112 | ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT; |
113 | ctrl |= on_time_div; | 113 | ctrl |= on_time_div; |
114 | pwm_lpss_write(pwm, ctrl); | 114 | |
115 | if (orig_ctrl != ctrl) { | ||
116 | pwm_lpss_write(pwm, ctrl); | ||
117 | pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE); | ||
118 | } | ||
115 | } | 119 | } |
116 | 120 | ||
117 | static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) | 121 | static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond) |
@@ -135,7 +139,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, | |||
135 | return ret; | 139 | return ret; |
136 | } | 140 | } |
137 | pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); | 141 | pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); |
138 | pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE); | ||
139 | pwm_lpss_cond_enable(pwm, lpwm->info->bypass == false); | 142 | pwm_lpss_cond_enable(pwm, lpwm->info->bypass == false); |
140 | ret = pwm_lpss_wait_for_update(pwm); | 143 | ret = pwm_lpss_wait_for_update(pwm); |
141 | if (ret) { | 144 | if (ret) { |
@@ -148,7 +151,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm, | |||
148 | if (ret) | 151 | if (ret) |
149 | return ret; | 152 | return ret; |
150 | pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); | 153 | pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period); |
151 | pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE); | ||
152 | return pwm_lpss_wait_for_update(pwm); | 154 | return pwm_lpss_wait_for_update(pwm); |
153 | } | 155 | } |
154 | } else if (pwm_is_enabled(pwm)) { | 156 | } else if (pwm_is_enabled(pwm)) { |