Skip to content

Commit 00e7e69

Browse files
Uwe Kleine-Königlag-linaro
authored andcommitted
backlight: pwm_bl: Configure pwm only once per backlight toggle
When the function pwm_backlight_update_status() was called with brightness > 0, pwm_get_state() was called twice (once directly and once in compute_duty_cycle). Also pwm_apply_state() was called twice (once in pwm_backlight_power_on() and once directly). Optimize this to do both calls only once. Note that with this affects the order of regulator and PWM setup. It's not expected to have a relevant effect on hardware. The rationale for this is that the regulator (and the GPIO) are reasonable to switch in pwm_backlight_power_on()/pwm_backlight_power_off() but the PWM has nothing to do with power. (The post_pwm_on_delay and pwm_off_delay are still there though.) Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 744fc2d commit 00e7e69

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

drivers/video/backlight/pwm_bl.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@ struct pwm_bl_data {
4040

4141
static void pwm_backlight_power_on(struct pwm_bl_data *pb)
4242
{
43-
struct pwm_state state;
4443
int err;
4544

46-
pwm_get_state(pb->pwm, &state);
4745
if (pb->enabled)
4846
return;
4947

5048
err = regulator_enable(pb->power_supply);
5149
if (err < 0)
5250
dev_err(pb->dev, "failed to enable power supply\n");
5351

54-
state.enabled = true;
55-
pwm_apply_state(pb->pwm, &state);
56-
5752
if (pb->post_pwm_on_delay)
5853
msleep(pb->post_pwm_on_delay);
5954

@@ -65,9 +60,6 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb)
6560

6661
static void pwm_backlight_power_off(struct pwm_bl_data *pb)
6762
{
68-
struct pwm_state state;
69-
70-
pwm_get_state(pb->pwm, &state);
7163
if (!pb->enabled)
7264
return;
7365

@@ -77,28 +69,21 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
7769
if (pb->pwm_off_delay)
7870
msleep(pb->pwm_off_delay);
7971

80-
state.enabled = false;
81-
state.duty_cycle = 0;
82-
pwm_apply_state(pb->pwm, &state);
83-
8472
regulator_disable(pb->power_supply);
8573
pb->enabled = false;
8674
}
8775

88-
static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
76+
static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness, struct pwm_state *state)
8977
{
9078
unsigned int lth = pb->lth_brightness;
91-
struct pwm_state state;
9279
u64 duty_cycle;
9380

94-
pwm_get_state(pb->pwm, &state);
95-
9681
if (pb->levels)
9782
duty_cycle = pb->levels[brightness];
9883
else
9984
duty_cycle = brightness;
10085

101-
duty_cycle *= state.period - lth;
86+
duty_cycle *= state->period - lth;
10287
do_div(duty_cycle, pb->scale);
10388

10489
return duty_cycle + lth;
@@ -115,11 +100,18 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
115100

116101
if (brightness > 0) {
117102
pwm_get_state(pb->pwm, &state);
118-
state.duty_cycle = compute_duty_cycle(pb, brightness);
103+
state.duty_cycle = compute_duty_cycle(pb, brightness, &state);
104+
state.enabled = true;
119105
pwm_apply_state(pb->pwm, &state);
106+
120107
pwm_backlight_power_on(pb);
121108
} else {
122109
pwm_backlight_power_off(pb);
110+
111+
pwm_get_state(pb->pwm, &state);
112+
state.enabled = false;
113+
state.duty_cycle = 0;
114+
pwm_apply_state(pb->pwm, &state);
123115
}
124116

125117
if (pb->notify_after)

0 commit comments

Comments
 (0)