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: meson: Simplify meson_pwm_cnt_to_ns()

meson_pwm_cnt_to_ns() uses clock rate got from clk_get_rate(). clk object
is getting from driver's private data thru several steps. Since
meson_pwm_cnt_to_ns() is called several times from a single scope it's
easier to get clock rate once and pass it as parameter.

Signed-off-by: George Stark <gnstark@salutedevices.com>
Link: https://lore.kernel.org/r/20241225105639.1787237-2-gnstark@salutedevices.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

George Stark and committed by
Uwe Kleine-König
08d8c9f5 5dca8a93

+6 -16
+6 -16
drivers/pwm/pwm-meson.c
··· 331 331 return 0; 332 332 } 333 333 334 - static u64 meson_pwm_cnt_to_ns(struct pwm_chip *chip, struct pwm_device *pwm, 335 - u32 cnt) 334 + static u64 meson_pwm_cnt_to_ns(unsigned long fin_freq, u32 cnt) 336 335 { 337 - struct meson_pwm *meson = to_meson_pwm(chip); 338 - struct meson_pwm_channel *channel; 339 - unsigned long fin_freq; 340 - 341 - /* to_meson_pwm() can only be used after .get_state() is called */ 342 - channel = &meson->channels[pwm->hwpwm]; 343 - 344 - fin_freq = clk_get_rate(channel->clk); 345 - if (fin_freq == 0) 346 - return 0; 347 - 348 - return div64_ul(NSEC_PER_SEC * (u64)cnt, fin_freq); 336 + return fin_freq ? div64_ul(NSEC_PER_SEC * (u64)cnt, fin_freq) : 0; 349 337 } 350 338 351 339 static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, ··· 341 353 { 342 354 struct meson_pwm *meson = to_meson_pwm(chip); 343 355 struct meson_pwm_channel_data *channel_data; 356 + unsigned long fin_freq; 344 357 unsigned int hi, lo; 345 358 u32 value; 346 359 347 360 channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; 361 + fin_freq = clk_get_rate(meson->channels[pwm->hwpwm].clk); 348 362 349 363 value = readl(meson->base + REG_MISC_AB); 350 364 state->enabled = value & channel_data->pwm_en_mask; ··· 360 370 lo = FIELD_GET(PWM_LOW_MASK, value); 361 371 hi = FIELD_GET(PWM_HIGH_MASK, value); 362 372 363 - state->period = meson_pwm_cnt_to_ns(chip, pwm, lo + hi); 364 - state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, hi); 373 + state->period = meson_pwm_cnt_to_ns(fin_freq, lo + hi); 374 + state->duty_cycle = meson_pwm_cnt_to_ns(fin_freq, hi); 365 375 366 376 return 0; 367 377 }