Messages in this thread | | | Subject | Re: [PATCH v10 2/2] leds: Add driver for Qualcomm LPG | From | Subbaraman Narayanamurthy <> | Date | Mon, 25 Oct 2021 17:37:58 -0700 |
| |
Hi Bjorn,
> +#define LPG_RESOLUTION 512
Just a thought. Having this fixed to 9-bit resolution would require a lot of code churn if this driver ends up supporting higher resolution PWM later. Would it be possible to have this as a parameter in "struct lpg_channel" ?
> +static const unsigned int lpg_clk_rates[] = {1024, 32768, 19200000}; > +static const unsigned int lpg_pre_divs[] = {1, 3, 5, 6}; > + > +static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period) > +{ > + unsigned int clk, best_clk = 0; > + unsigned int div, best_div = 0; > + unsigned int m, best_m = 0; > + unsigned int error; > + unsigned int best_err = UINT_MAX; > + u64 best_period = 0; > + > + /* > + * The PWM period is determined by: > + * > + * resolution * pre_div * 2^M > + * period = -------------------------- > + * refclk > + * > + * With resolution fixed at 2^9 bits, pre_div = {1, 3, 5, 6} and > + * M = [0..7]. > + * > + * This allows for periods between 27uS and 384s, as the PWM framework > + * wants a period of equal or lower length than requested, reject > + * anything below 27uS. > + */ > + if (period <= (u64)NSEC_PER_SEC * LPG_RESOLUTION / 19200000) > + return -EINVAL; > + > + /* Limit period to largest possible value, to avoid overflows */ > + if (period > (u64)NSEC_PER_SEC * LPG_RESOLUTION * 6 * (1 << LPG_MAX_M) / 1024) > + period = (u64)NSEC_PER_SEC * LPG_RESOLUTION * 6 * (1 << LPG_MAX_M) / 2014;
s/2014/1024 ?
Thanks, Subbaraman
| |