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: atmel: Implement .get_state()

This function reads back the configured parameters from the hardware. As
.apply() rounds down (mostly) I'm rounding up in .get_state() to achieve
that applying a state just read from hardware is a no-op.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Acked-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>

authored by

Uwe Kleine-König and committed by
Thierry Reding
651b510a 02afb811

+40
+40
drivers/pwm/pwm-atmel.c
··· 295 295 return 0; 296 296 } 297 297 298 + static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, 299 + struct pwm_state *state) 300 + { 301 + struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip); 302 + u32 sr, cmr; 303 + 304 + sr = atmel_pwm_readl(atmel_pwm, PWM_SR); 305 + cmr = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, PWM_CMR); 306 + 307 + if (sr & (1 << pwm->hwpwm)) { 308 + unsigned long rate = clk_get_rate(atmel_pwm->clk); 309 + u32 cdty, cprd, pres; 310 + u64 tmp; 311 + 312 + pres = cmr & PWM_CMR_CPRE_MSK; 313 + 314 + cprd = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, 315 + atmel_pwm->data->regs.period); 316 + tmp = (u64)cprd * NSEC_PER_SEC; 317 + tmp <<= pres; 318 + state->period = DIV64_U64_ROUND_UP(tmp, rate); 319 + 320 + cdty = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm, 321 + atmel_pwm->data->regs.duty); 322 + tmp = (u64)cdty * NSEC_PER_SEC; 323 + tmp <<= pres; 324 + state->duty_cycle = DIV64_U64_ROUND_UP(tmp, rate); 325 + 326 + state->enabled = true; 327 + } else { 328 + state->enabled = false; 329 + } 330 + 331 + if (cmr & PWM_CMR_CPOL) 332 + state->polarity = PWM_POLARITY_INVERSED; 333 + else 334 + state->polarity = PWM_POLARITY_NORMAL; 335 + } 336 + 298 337 static const struct pwm_ops atmel_pwm_ops = { 299 338 .apply = atmel_pwm_apply, 339 + .get_state = atmel_pwm_get_state, 300 340 .owner = THIS_MODULE, 301 341 }; 302 342