From: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
To: "Bjorn Andersson" <bjorn.andersson@linaro.org>,
"Pavel Machek" <pavel@ucw.cz>, "Rob Herring" <robh+dt@kernel.org>,
"Andy Gross" <agross@kernel.org>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Lee Jones" <lee.jones@linaro.org>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-pwm@vger.kernel.org,
Marijn Suijten <marijn.suijten@somainline.org>,
Yassine Oudjana <y.oudjana@protonmail.com>,
Luca Weiss <luca@z3ntu.xyz>
Subject: Re: [PATCH v10 2/2] leds: Add driver for Qualcomm LPG
Date: Mon, 25 Oct 2021 17:37:58 -0700 [thread overview]
Message-ID: <1ad508af-f7cb-a88f-07d8-5731c5a45403@codeaurora.org> (raw)
In-Reply-To: <20211010043912.136640-2-bjorn.andersson@linaro.org>
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
next prev parent reply other threads:[~2021-10-26 0:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-10 4:39 [PATCH v10 1/2] dt-bindings: leds: Add Qualcomm Light Pulse Generator binding Bjorn Andersson
2021-10-10 4:39 ` [PATCH v10 2/2] leds: Add driver for Qualcomm LPG Bjorn Andersson
2021-10-22 17:25 ` Bjorn Andersson
2021-10-27 21:19 ` Marijn Suijten
2021-10-27 21:27 ` Marijn Suijten
2022-01-29 0:53 ` Bjorn Andersson
2022-02-02 10:17 ` Marijn Suijten
2022-01-29 0:50 ` Bjorn Andersson
2022-02-02 11:03 ` Marijn Suijten
2022-02-02 21:56 ` Bjorn Andersson
2022-02-03 23:13 ` Marijn Suijten
2021-10-26 0:37 ` Subbaraman Narayanamurthy [this message]
2021-10-26 2:57 ` Bjorn Andersson
2021-10-16 14:36 ` [PATCH v10 1/2] dt-bindings: leds: Add Qualcomm Light Pulse Generator binding Rob Herring
2022-01-07 0:18 ` Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ad508af-f7cb-a88f-07d8-5731c5a45403@codeaurora.org \
--to=subbaram@codeaurora.org \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=lee.jones@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=luca@z3ntu.xyz \
--cc=marijn.suijten@somainline.org \
--cc=pavel@ucw.cz \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=y.oudjana@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).