mirror of https://github.com/torvalds/linux.git
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>
This commit is contained in:
parent
5dca8a93b0
commit
08d8c9f593
|
|
@ -331,21 +331,9 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u64 meson_pwm_cnt_to_ns(struct pwm_chip *chip, struct pwm_device *pwm,
|
static u64 meson_pwm_cnt_to_ns(unsigned long fin_freq, u32 cnt)
|
||||||
u32 cnt)
|
|
||||||
{
|
{
|
||||||
struct meson_pwm *meson = to_meson_pwm(chip);
|
return fin_freq ? div64_ul(NSEC_PER_SEC * (u64)cnt, fin_freq) : 0;
|
||||||
struct meson_pwm_channel *channel;
|
|
||||||
unsigned long fin_freq;
|
|
||||||
|
|
||||||
/* to_meson_pwm() can only be used after .get_state() is called */
|
|
||||||
channel = &meson->channels[pwm->hwpwm];
|
|
||||||
|
|
||||||
fin_freq = clk_get_rate(channel->clk);
|
|
||||||
if (fin_freq == 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return div64_ul(NSEC_PER_SEC * (u64)cnt, fin_freq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
|
|
@ -353,10 +341,12 @@ static int meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
|
||||||
{
|
{
|
||||||
struct meson_pwm *meson = to_meson_pwm(chip);
|
struct meson_pwm *meson = to_meson_pwm(chip);
|
||||||
struct meson_pwm_channel_data *channel_data;
|
struct meson_pwm_channel_data *channel_data;
|
||||||
|
unsigned long fin_freq;
|
||||||
unsigned int hi, lo;
|
unsigned int hi, lo;
|
||||||
u32 value;
|
u32 value;
|
||||||
|
|
||||||
channel_data = &meson_pwm_per_channel_data[pwm->hwpwm];
|
channel_data = &meson_pwm_per_channel_data[pwm->hwpwm];
|
||||||
|
fin_freq = clk_get_rate(meson->channels[pwm->hwpwm].clk);
|
||||||
|
|
||||||
value = readl(meson->base + REG_MISC_AB);
|
value = readl(meson->base + REG_MISC_AB);
|
||||||
state->enabled = value & channel_data->pwm_en_mask;
|
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,
|
||||||
lo = FIELD_GET(PWM_LOW_MASK, value);
|
lo = FIELD_GET(PWM_LOW_MASK, value);
|
||||||
hi = FIELD_GET(PWM_HIGH_MASK, value);
|
hi = FIELD_GET(PWM_HIGH_MASK, value);
|
||||||
|
|
||||||
state->period = meson_pwm_cnt_to_ns(chip, pwm, lo + hi);
|
state->period = meson_pwm_cnt_to_ns(fin_freq, lo + hi);
|
||||||
state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, hi);
|
state->duty_cycle = meson_pwm_cnt_to_ns(fin_freq, hi);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue