Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <u.kleine-koenig@baylibre.com>
Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20240607084416.897777-7-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
40571a5b f7d5463e

+12 -20
+12 -20
drivers/pwm/pwm-cros-ec.c
··· 168 168 return 0; 169 169 } 170 170 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 - 189 171 static const struct pwm_ops cros_ec_pwm_ops = { 190 172 .get_state = cros_ec_pwm_get_state, 191 173 .apply = cros_ec_pwm_apply, ··· 218 236 struct cros_ec_pwm_device *ec_pwm; 219 237 struct pwm_chip *chip; 220 238 bool use_pwm_type = false; 221 - unsigned int npwm; 239 + unsigned int i, npwm; 222 240 int ret; 223 241 224 242 if (!ec) ··· 244 262 245 263 /* PWM chip */ 246 264 chip->ops = &cros_ec_pwm_ops; 247 - chip->of_xlate = cros_ec_pwm_xlate; 265 + 266 + /* 267 + * The device tree binding for this device is special as it only uses a 268 + * single cell (for the hwid) and so doesn't provide a default period. 269 + * This isn't a big problem though as the hardware only supports a 270 + * single period length, it's just a bit ugly to make this fit into the 271 + * pwm core abstractions. So initialize the period here, as 272 + * of_pwm_xlate_with_flags() won't do that for us. 273 + */ 274 + for (i = 0; i < npwm; ++i) 275 + chip->pwms[i].args.period = EC_PWM_MAX_DUTY; 248 276 249 277 dev_dbg(dev, "Probed %u PWMs\n", chip->npwm); 250 278