Skip to content

Commit 08d8c9f

Browse files
geo-starkUwe Kleine-König
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 5dca8a9 commit 08d8c9f

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

drivers/pwm/pwm-meson.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -331,32 +331,22 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
331331
return 0;
332332
}
333333

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)
336335
{
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;
349337
}
350338

351339
static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
352340
struct pwm_state *state)
353341
{
354342
struct meson_pwm *meson = to_meson_pwm(chip);
355343
struct meson_pwm_channel_data *channel_data;
344+
unsigned long fin_freq;
356345
unsigned int hi, lo;
357346
u32 value;
358347

359348
channel_data = &meson_pwm_per_channel_data[pwm->hwpwm];
349+
fin_freq = clk_get_rate(meson->channels[pwm->hwpwm].clk);
360350

361351
value = readl(meson->base + REG_MISC_AB);
362352
state->enabled = value & channel_data->pwm_en_mask;
@@ -370,8 +360,8 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
370360
lo = FIELD_GET(PWM_LOW_MASK, value);
371361
hi = FIELD_GET(PWM_HIGH_MASK, value);
372362

373-
state->period = meson_pwm_cnt_to_ns(chip, pwm, lo + hi);
374-
state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, hi);
363+
state->period = meson_pwm_cnt_to_ns(fin_freq, lo + hi);
364+
state->duty_cycle = meson_pwm_cnt_to_ns(fin_freq, hi);
375365

376366
return 0;
377367
}

0 commit comments

Comments
 (0)