From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
Cc: Andrzej Hajda <a.hajda@samsung.com>,
Neil Armstrong <narmstrong@baylibre.com>,
Robert Foss <robert.foss@linaro.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
Thierry Reding <thierry.reding@gmail.com>,
Lee Jones <lee.jones@linaro.org>,
Doug Anderson <dianders@chromium.org>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-pwm@vger.kernel.org
Subject: Re: [PATCH v2 2/2] drm/bridge: ti-sn65dsi86: Implement the pwm_chip
Date: Thu, 17 Jun 2021 11:38:26 -0500 [thread overview]
Message-ID: <YMt6gvXQKijtPOql@yoga> (raw)
In-Reply-To: <20210617062449.qwsjcpkyiwzdyfi3@pengutronix.de>
On Thu 17 Jun 01:24 CDT 2021, Uwe Kleine-K?nig wrote:
> Hello Bjorn,
>
> On Wed, Jun 16, 2021 at 10:22:17PM -0500, Bjorn Andersson wrote:
> > > > +static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > > > + const struct pwm_state *state)
> > > > +{
> > > > + struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip);
> > > > + unsigned int pwm_en_inv;
> > > > + unsigned int backlight;
> > > > + unsigned int pre_div;
> > > > + unsigned int scale;
> > > > + int ret;
> > > > +
> > > > + if (!pdata->pwm_enabled) {
> > > > + ret = pm_runtime_get_sync(pdata->dev);
> > > > + if (ret < 0)
> > > > + return ret;
> > > > +
> > > > + ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG,
> > > > + SN_GPIO_MUX_MASK << (2 * SN_PWM_GPIO_IDX),
> > > > + SN_GPIO_MUX_SPECIAL << (2 * SN_PWM_GPIO_IDX));
> > > > + if (ret) {
> > > > + dev_err(pdata->dev, "failed to mux in PWM function\n");
> > > > + goto out;
> > > > + }
> > >
> > > Do you need to do this even if state->enabled is false?
> >
> > I presume I should be able to explicitly mux in the GPIO function and
> > configure that to output low. But I am not able to find anything in the
> > data sheet that would indicate this to be preferred.
>
> My question targetted a different case. If the PWM is off
> (!pdata->pwm_enabled) and should remain off (state->enabled is false)
> you can shortcut here, can you not?
>
Right, if we're going off->off then we don't need to touch the hardware.
But am I expected to -EINVAL improper period and duty cycle even though
enabled is false?
And also, what is the supposed behavior of enabled = false? Is it
supposedly equivalent of asking for a duty_cycle of 0?
> > > Does this already modify the output pin?
> >
> > Yes, coming out of reset this pin is configured as input, so switching
> > the mux here will effectively start driving the pin.
>
> So please document this in the format the recently added drivers do,
> too. See e.g. drivers/pwm/pwm-sifive.c. (The idea is to start that with
> " * Limitations:" to make it easy to grep it.)
>
Okay, will do. Although I believe that for this driver it makes sense to
place such comment close to this function, rather than at the top of the
driver.
> > > Lets continue the above example with the fixed calculation. So we have:
> > >
> > > pdata->pwm_refclk_freq = 3333334
> > > state->period = 100000 [ns]
> > > state->duty_cycle = 600
> > > scale = 332
> > >
> > > so the actually emitted period = 99899.98002000399 ns
> > >
> > > Now you calculate:
> > >
> > > backlight = 1
> > >
> > > which yields an actual duty_cycle of 299.99994 ns, with backlight = 2
> > > you would get an actual duty_cycle of 599.99988 ns, which is better. The
> > > culprit here is that you divide by state->period but instead should
> > > divide by the actual period.
> >
> > What do I do about the case where the actual period is lower than the
> > requested one and thereby the duty cycle becomes larger than the period?
>
> The general principle is: Pick the biggest possible duty_cycle available
> for the just picked period. So in your example you have to clamp it to
> period (assuming you can, otherwise pick the next lower possible value).
>
Sounds good.
Thank you,
Bjorn
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
WARNING: multiple messages have this Message-ID (diff)
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
Cc: linux-pwm@vger.kernel.org, Jonas Karlman <jonas@kwiboo.se>,
David Airlie <airlied@linux.ie>,
Robert Foss <robert.foss@linaro.org>,
dri-devel@lists.freedesktop.org,
Neil Armstrong <narmstrong@baylibre.com>,
Doug Anderson <dianders@chromium.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
linux-kernel@vger.kernel.org, Andrzej Hajda <a.hajda@samsung.com>,
Thierry Reding <thierry.reding@gmail.com>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Lee Jones <lee.jones@linaro.org>
Subject: Re: [PATCH v2 2/2] drm/bridge: ti-sn65dsi86: Implement the pwm_chip
Date: Thu, 17 Jun 2021 11:38:26 -0500 [thread overview]
Message-ID: <YMt6gvXQKijtPOql@yoga> (raw)
In-Reply-To: <20210617062449.qwsjcpkyiwzdyfi3@pengutronix.de>
On Thu 17 Jun 01:24 CDT 2021, Uwe Kleine-K?nig wrote:
> Hello Bjorn,
>
> On Wed, Jun 16, 2021 at 10:22:17PM -0500, Bjorn Andersson wrote:
> > > > +static int ti_sn_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > > > + const struct pwm_state *state)
> > > > +{
> > > > + struct ti_sn65dsi86 *pdata = pwm_chip_to_ti_sn_bridge(chip);
> > > > + unsigned int pwm_en_inv;
> > > > + unsigned int backlight;
> > > > + unsigned int pre_div;
> > > > + unsigned int scale;
> > > > + int ret;
> > > > +
> > > > + if (!pdata->pwm_enabled) {
> > > > + ret = pm_runtime_get_sync(pdata->dev);
> > > > + if (ret < 0)
> > > > + return ret;
> > > > +
> > > > + ret = regmap_update_bits(pdata->regmap, SN_GPIO_CTRL_REG,
> > > > + SN_GPIO_MUX_MASK << (2 * SN_PWM_GPIO_IDX),
> > > > + SN_GPIO_MUX_SPECIAL << (2 * SN_PWM_GPIO_IDX));
> > > > + if (ret) {
> > > > + dev_err(pdata->dev, "failed to mux in PWM function\n");
> > > > + goto out;
> > > > + }
> > >
> > > Do you need to do this even if state->enabled is false?
> >
> > I presume I should be able to explicitly mux in the GPIO function and
> > configure that to output low. But I am not able to find anything in the
> > data sheet that would indicate this to be preferred.
>
> My question targetted a different case. If the PWM is off
> (!pdata->pwm_enabled) and should remain off (state->enabled is false)
> you can shortcut here, can you not?
>
Right, if we're going off->off then we don't need to touch the hardware.
But am I expected to -EINVAL improper period and duty cycle even though
enabled is false?
And also, what is the supposed behavior of enabled = false? Is it
supposedly equivalent of asking for a duty_cycle of 0?
> > > Does this already modify the output pin?
> >
> > Yes, coming out of reset this pin is configured as input, so switching
> > the mux here will effectively start driving the pin.
>
> So please document this in the format the recently added drivers do,
> too. See e.g. drivers/pwm/pwm-sifive.c. (The idea is to start that with
> " * Limitations:" to make it easy to grep it.)
>
Okay, will do. Although I believe that for this driver it makes sense to
place such comment close to this function, rather than at the top of the
driver.
> > > Lets continue the above example with the fixed calculation. So we have:
> > >
> > > pdata->pwm_refclk_freq = 3333334
> > > state->period = 100000 [ns]
> > > state->duty_cycle = 600
> > > scale = 332
> > >
> > > so the actually emitted period = 99899.98002000399 ns
> > >
> > > Now you calculate:
> > >
> > > backlight = 1
> > >
> > > which yields an actual duty_cycle of 299.99994 ns, with backlight = 2
> > > you would get an actual duty_cycle of 599.99988 ns, which is better. The
> > > culprit here is that you divide by state->period but instead should
> > > divide by the actual period.
> >
> > What do I do about the case where the actual period is lower than the
> > requested one and thereby the duty cycle becomes larger than the period?
>
> The general principle is: Pick the biggest possible duty_cycle available
> for the just picked period. So in your example you have to clamp it to
> period (assuming you can, otherwise pick the next lower possible value).
>
Sounds good.
Thank you,
Bjorn
> Best regards
> Uwe
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
next prev parent reply other threads:[~2021-06-17 16:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 23:18 [PATCH v2 1/2] pwm: Introduce single-PWM of_xlate function Bjorn Andersson
2021-06-15 23:18 ` Bjorn Andersson
2021-06-15 23:18 ` [PATCH v2 2/2] drm/bridge: ti-sn65dsi86: Implement the pwm_chip Bjorn Andersson
2021-06-15 23:18 ` Bjorn Andersson
2021-06-16 7:56 ` Uwe Kleine-König
2021-06-16 7:56 ` Uwe Kleine-König
2021-06-17 3:22 ` Bjorn Andersson
2021-06-17 3:22 ` Bjorn Andersson
2021-06-17 6:24 ` Uwe Kleine-König
2021-06-17 6:24 ` Uwe Kleine-König
2021-06-17 16:38 ` Bjorn Andersson [this message]
2021-06-17 16:38 ` Bjorn Andersson
2021-06-17 16:54 ` Uwe Kleine-König
2021-06-17 16:54 ` Uwe Kleine-König
2021-06-17 18:06 ` Bjorn Andersson
2021-06-17 18:06 ` Bjorn Andersson
2021-06-18 7:46 ` Uwe Kleine-König
2021-06-18 7:46 ` Uwe Kleine-König
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=YMt6gvXQKijtPOql@yoga \
--to=bjorn.andersson@linaro.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=a.hajda@samsung.com \
--cc=airlied@linux.ie \
--cc=daniel@ffwll.ch \
--cc=dianders@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=narmstrong@baylibre.com \
--cc=robert.foss@linaro.org \
--cc=thierry.reding@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.