Skip to content

Commit f7d5463

Browse files
Uwe Kleine-KönigUwe Kleine-König
authored andcommitted
pwm: cros-ec: Don't care about consumers in .get_state()
The get_state() callback is never called (in a visible way) after there is a consumer for a pwm device. The core handles loosing the information about duty_cycle just fine. Simplify the driver accordingly. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected] [Drop kdoc comment for channel to make W=1 builds happy] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 33c651a commit f7d5463

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

drivers/pwm/pwm-cros-ec.c

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,10 @@
2020
*
2121
* @ec: Pointer to EC device
2222
* @use_pwm_type: Use PWM types instead of generic channels
23-
* @channel: array with per-channel data
2423
*/
2524
struct cros_ec_pwm_device {
2625
struct cros_ec_device *ec;
2726
bool use_pwm_type;
28-
struct cros_ec_pwm *channel;
29-
};
30-
31-
/**
32-
* struct cros_ec_pwm - per-PWM driver data
33-
* @duty_cycle: cached duty cycle
34-
*/
35-
struct cros_ec_pwm {
36-
u16 duty_cycle;
3727
};
3828

3929
static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip)
@@ -135,7 +125,6 @@ static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
135125
const struct pwm_state *state)
136126
{
137127
struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
138-
struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
139128
u16 duty_cycle;
140129
int ret;
141130

@@ -156,16 +145,13 @@ static int cros_ec_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
156145
if (ret < 0)
157146
return ret;
158147

159-
channel->duty_cycle = state->duty_cycle;
160-
161148
return 0;
162149
}
163150

164151
static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
165152
struct pwm_state *state)
166153
{
167154
struct cros_ec_pwm_device *ec_pwm = pwm_to_cros_ec_pwm(chip);
168-
struct cros_ec_pwm *channel = &ec_pwm->channel[pwm->hwpwm];
169155
int ret;
170156

171157
ret = cros_ec_pwm_get_duty(ec_pwm->ec, ec_pwm->use_pwm_type, pwm->hwpwm);
@@ -175,23 +161,10 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
175161
}
176162

177163
state->enabled = (ret > 0);
164+
state->duty_cycle = ret;
178165
state->period = EC_PWM_MAX_DUTY;
179166
state->polarity = PWM_POLARITY_NORMAL;
180167

181-
/*
182-
* Note that "disabled" and "duty cycle == 0" are treated the same. If
183-
* the cached duty cycle is not zero, used the cached duty cycle. This
184-
* ensures that the configured duty cycle is kept across a disable and
185-
* enable operation and avoids potentially confusing consumers.
186-
*
187-
* For the case of the initial hardware readout, channel->duty_cycle
188-
* will be 0 and the actual duty cycle read from the EC is used.
189-
*/
190-
if (ret == 0 && channel->duty_cycle > 0)
191-
state->duty_cycle = channel->duty_cycle;
192-
else
193-
state->duty_cycle = ret;
194-
195168
return 0;
196169
}
197170

@@ -291,11 +264,6 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
291264
chip->ops = &cros_ec_pwm_ops;
292265
chip->of_xlate = cros_ec_pwm_xlate;
293266

294-
ec_pwm->channel = devm_kcalloc(dev, chip->npwm, sizeof(*ec_pwm->channel),
295-
GFP_KERNEL);
296-
if (!ec_pwm->channel)
297-
return -ENOMEM;
298-
299267
dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
300268

301269
ret = devm_pwmchip_add(dev, chip);

0 commit comments

Comments
 (0)