Skip to content

Commit 40571a5

Browse files
Uwe Kleine-KönigUwe Kleine-König
authored andcommitted
pwm: cros-ec: Simplify device tree xlation
The cros-ec device tree binding only uses #pwm-cells = <1>, and so there is no period provided in the device tree. Up to now this was handled by hardcoding the period to the only supported value in the custom xlate callback. Apart from that, the default xlate callback (i.e. of_pwm_xlate_with_flags()) handles this just fine (and better, e.g. by checking args->args_count >= 1 before accessing args->args[0]). To simplify make use of of_pwm_xlate_with_flags(), drop the custom callback and provide the default period in .probe() already. Apart from simplifying the driver this also drops the last non-core user of pwm_request_from_chip() and so makes further simplifications possible. Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent f7d5463 commit 40571a5

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

drivers/pwm/pwm-cros-ec.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,6 @@ static int cros_ec_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
168168
return 0;
169169
}
170170

171-
static struct pwm_device *
172-
cros_ec_pwm_xlate(struct pwm_chip *chip, const struct of_phandle_args *args)
173-
{
174-
struct pwm_device *pwm;
175-
176-
if (args->args[0] >= chip->npwm)
177-
return ERR_PTR(-EINVAL);
178-
179-
pwm = pwm_request_from_chip(chip, args->args[0], NULL);
180-
if (IS_ERR(pwm))
181-
return pwm;
182-
183-
/* The EC won't let us change the period */
184-
pwm->args.period = EC_PWM_MAX_DUTY;
185-
186-
return pwm;
187-
}
188-
189171
static const struct pwm_ops cros_ec_pwm_ops = {
190172
.get_state = cros_ec_pwm_get_state,
191173
.apply = cros_ec_pwm_apply,
@@ -236,7 +218,7 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
236218
struct cros_ec_pwm_device *ec_pwm;
237219
struct pwm_chip *chip;
238220
bool use_pwm_type = false;
239-
unsigned int npwm;
221+
unsigned int i, npwm;
240222
int ret;
241223

242224
if (!ec)
@@ -262,7 +244,17 @@ static int cros_ec_pwm_probe(struct platform_device *pdev)
262244

263245
/* PWM chip */
264246
chip->ops = &cros_ec_pwm_ops;
265-
chip->of_xlate = cros_ec_pwm_xlate;
247+
248+
/*
249+
* The device tree binding for this device is special as it only uses a
250+
* single cell (for the hwid) and so doesn't provide a default period.
251+
* This isn't a big problem though as the hardware only supports a
252+
* single period length, it's just a bit ugly to make this fit into the
253+
* pwm core abstractions. So initialize the period here, as
254+
* of_pwm_xlate_with_flags() won't do that for us.
255+
*/
256+
for (i = 0; i < npwm; ++i)
257+
chip->pwms[i].args.period = EC_PWM_MAX_DUTY;
266258

267259
dev_dbg(dev, "Probed %u PWMs\n", chip->npwm);
268260

0 commit comments

Comments
 (0)