From: Jingbao Qiu <qiujingbao.dlmu@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, paul.walmsley@sifive.com,
palmer@dabbelt.com, aou@eecs.berkeley.edu,
linux-pwm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
dlan@gentoo.org, inochiama@outlook.com
Subject: Re: [PATCH v4 2/2] pwm: sophgo: add pwm support for Sophgo CV1800 SoC
Date: Tue, 12 Mar 2024 16:07:30 +0800 [thread overview]
Message-ID: <CAJRtX8RagduSxqxh-jH2wcoNgzbRdNRYW5Gcka1_uPR-o-Tj7w@mail.gmail.com> (raw)
In-Reply-To: <CAJRtX8T3GD-zu43-+U_rGQugqzGQQ-QbjHATV1NRdEMWevSUGw@mail.gmail.com>
Hi Uwe,
Gentle ping,
I'm sorry for wasting your time, and I look forward to your feedback.
> > > + if (tem < PWM_CV1800_MINPERIOD)
> > > + return -EINVAL;
> > > +
> > > + if (tem > PWM_CV1800_MAXPERIOD)
> > > + tem = PWM_CV1800_MAXPERIOD;
> > > +
> > > + period_val = (u32)tem;
> > > +
> > > + /*
> > > + * The meaning of HLPERIOD is the number of beats in the low or high level
> > > + * of the PERIOD. When the value of the POLARITY register is 0, HLPERIOD
> > > + * represents a low level.
> > > + * HLPERIOD = period_val - rate(MHz) / duty(MHz)
> > > + * HLPERIOD = period_val - duty(ns) * rate(Hz) / NSEC_PER_SEC
> >
> > So HLPERIOD defines the second part of each period, right? This isn't
> > considered in .get_state().
>
> I am so sorry about this. I made a mess of the duty cycle.
> According to the PWM_DEBUG, it can be inferred that configure the
> biggest duty_cycle not
> bigger than the requested value, so in .apply duty_cycle should round down and
> in .get_state duty_cycle should round up. However, when the polarity is normal,
> This hardware requires a low-level beat count. So the corrected code
> is as follows.
>
> in .apply()
>
> ticks = mul_u64_u64_div_u64(state->duty_cycle , priv->clk_rate,NSEC_PER_SEC);
> ...
> hlperiod_val =period_val- (u32)ticks;
>
> in .get_state()
>
> u32 hlperiod_val=0;
>
> period_ns = DIV_ROUND_UP_ULL(period_val * NSEC_PER_SEC,priv->clk_rate);
> duty_ns = DIV_ROUND_UP_ULL(hlperiod_val * period_ns, period_val);
> hlperiod_val = period_ns - duty_ns;
>
> I tested this code with PWM_DEBUG. no warning output. What do you
> think about this?
>
>
in .apply()
ticks = mul_u64_u64_div_u64(state->duty_cycle, priv->clk_rate,
NSEC_PER_SEC);
if (ticks > period_val)
ticks = period_val;
hlperiod_val = period_val - (u32)ticks;
...
regmap_write(priv->map, PWM_CV1800_HLPERIOD(pwm->hwpwm), hlperiod_val);
in .get_state()
u64 hlperiod_ns = 0;
regmap_read(priv->map, PWM_CV1800_HLPERIOD(pwm->hwpwm), &hlperiod_val);
...
period_ns = DIV_ROUND_UP_ULL(period_val * NSEC_PER_SEC,
priv->clk_rate);
hlperiod_ns = DIV_ROUND_UP_ULL(hlperiod_val * NSEC_PER_SEC,
priv->clk_rate);
duty_ns = period_ns - hlperiod_ns;
I tested this code with PWM_DEBUG. no warning output.
> >
> > > + */
> > > + tem = mul_u64_u64_div_u64(state->duty_cycle, priv->clk_rate,
> > > + NSEC_PER_SEC);
> > > + if (tem > period_val)
> > > + return -EINVAL;
> >
> > if (tem > period_val)
> > tem = period_val;
> >
> > > + hlperiod_val = period_val - (u32)tem;
> >
> > Wrong rounding I think. Did you test your driver with PWM_DEBUG enabled?
>
> ditto.
>
Best regards
Jingbao Qiu
prev parent reply other threads:[~2024-03-12 8:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-04 8:59 [PATCH v4 0/2] riscv: pwm: sophgo: add pwm support for CV1800 Jingbao Qiu
2024-03-04 8:59 ` [PATCH v4 1/2] dt-bindings: pwm: sophgo: add pwm for Sophgo CV1800 series SoC Jingbao Qiu
2024-03-04 9:02 ` [PATCH v4 2/2] pwm: sophgo: add pwm support for Sophgo CV1800 SoC Jingbao Qiu
2024-03-04 10:14 ` Krzysztof Kozlowski
2024-03-04 13:40 ` Jingbao Qiu
2024-03-04 15:02 ` Krzysztof Kozlowski
2024-03-05 1:46 ` Jingbao Qiu
2024-03-04 15:37 ` Uwe Kleine-König
2024-03-05 9:19 ` Jingbao Qiu
2024-03-12 8:07 ` Jingbao Qiu [this message]
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=CAJRtX8RagduSxqxh-jH2wcoNgzbRdNRYW5Gcka1_uPR-o-Tj7w@mail.gmail.com \
--to=qiujingbao.dlmu@gmail.com \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlan@gentoo.org \
--cc=inochiama@outlook.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh+dt@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).