From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: dri-devel@lists.freedesktop.org, linux-pwm@vger.kernel.org,
Jernej Skrabec <jernej.skrabec@gmail.com>,
kernel@pengutronix.de, Neil Armstrong <narmstrong@baylibre.com>,
Linus Walleij <linus.walleij@linaro.org>,
Jonas Karlman <jonas@kwiboo.se>,
Douglas Anderson <dianders@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
linux-gpio@vger.kernel.org,
Andrzej Hajda <andrzej.hajda@intel.com>,
Ingo Molnar <mingo@redhat.com>,
Robert Foss <robert.foss@linaro.org>, Pavel Machek <pavel@ucw.cz>,
Bartosz Golaszewski <brgl@bgdev.pl>,
linux-leds@vger.kernel.org,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
Subject: Re: [PATCH 1/3] pwm: Change prototype of .get_state() callback to return an error
Date: Thu, 29 Sep 2022 08:55:32 +0200 [thread overview]
Message-ID: <20220929065532.n3kc44zimshufe4c@pengutronix.de> (raw)
In-Reply-To: <YzRCvGNpWXKyO/PE@orome>
[-- Attachment #1: Type: text/plain, Size: 5261 bytes --]
On Wed, Sep 28, 2022 at 02:49:00PM +0200, Thierry Reding wrote:
> On Fri, Sep 16, 2022 at 05:15:04PM +0200, Uwe Kleine-König wrote:
> [...]
> > diff --git a/drivers/pwm/pwm-crc.c b/drivers/pwm/pwm-crc.c
> > index 7b357d1cf642..811e6f424927 100644
> > --- a/drivers/pwm/pwm-crc.c
> > +++ b/drivers/pwm/pwm-crc.c
> > @@ -121,8 +121,8 @@ static int crc_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > return 0;
> > }
> >
> > -static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > - struct pwm_state *state)
> > +static int crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > + struct pwm_state *state)
> > {
> > struct crystalcove_pwm *crc_pwm = to_crc_pwm(chip);
> > struct device *dev = crc_pwm->chip.dev;
> > @@ -132,13 +132,13 @@ static void crc_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > error = regmap_read(crc_pwm->regmap, PWM0_CLK_DIV, &clk_div_reg);
> > if (error) {
> > dev_err(dev, "Error reading PWM0_CLK_DIV %d\n", error);
> > - return;
> > + return -EIO;
> > }
> >
> > error = regmap_read(crc_pwm->regmap, PWM0_DUTY_CYCLE, &duty_cycle_reg);
> > if (error) {
> > dev_err(dev, "Error reading PWM0_DUTY_CYCLE %d\n", error);
> > - return;
> > + return -EIO;
> > }
>
> In other drivers you propagate errors from regmap_read(), why not here?
Oh, this is indeed wrong and should be "return error".
>
> > diff --git a/drivers/pwm/pwm-sprd.c b/drivers/pwm/pwm-sprd.c
> > index 7004f55bbf11..aa06b3ce81a6 100644
> > --- a/drivers/pwm/pwm-sprd.c
> > +++ b/drivers/pwm/pwm-sprd.c
> > @@ -65,8 +65,8 @@ static void sprd_pwm_write(struct sprd_pwm_chip *spc, u32 hwid,
> > writel_relaxed(val, spc->base + offset);
> > }
> >
> > -static void sprd_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > - struct pwm_state *state)
> > +static int sprd_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > + struct pwm_state *state)
> > {
> > struct sprd_pwm_chip *spc =
> > container_of(chip, struct sprd_pwm_chip, chip);
> > @@ -80,11 +80,8 @@ static void sprd_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > * reading to the registers.
> > */
> > ret = clk_bulk_prepare_enable(SPRD_PWM_CHN_CLKS_NUM, chn->clks);
> > - if (ret) {
> > - dev_err(spc->dev, "failed to enable pwm%u clocks\n",
> > - pwm->hwpwm);
>
> This might be useful information, so perhaps leave it in?
Ok, I don't like .get_state emitting an error, but agreed, that's an
orthogonal issue that shouldn't be addressed en passant in this change.
> [...]
> > diff --git a/drivers/pwm/pwm-sun4i.c b/drivers/pwm/pwm-sun4i.c
> > index c8445b0a3339..ead909400e64 100644
> > --- a/drivers/pwm/pwm-sun4i.c
> > +++ b/drivers/pwm/pwm-sun4i.c
> > @@ -108,9 +108,9 @@ static inline void sun4i_pwm_writel(struct sun4i_pwm_chip *chip,
> > writel(val, chip->base + offset);
> > }
> >
> > -static void sun4i_pwm_get_state(struct pwm_chip *chip,
> > - struct pwm_device *pwm,
> > - struct pwm_state *state)
> > +static int sun4i_pwm_get_state(struct pwm_chip *chip,
> > + struct pwm_device *pwm,
> > + struct pwm_state *state)
> > {
> > struct sun4i_pwm_chip *sun4i_pwm = to_sun4i_pwm_chip(chip);
> > u64 clk_rate, tmp;
> > @@ -132,7 +132,7 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip,
> > state->duty_cycle = DIV_ROUND_UP_ULL(state->period, 2);
> > state->polarity = PWM_POLARITY_NORMAL;
> > state->enabled = true;
> > - return;
> > + return 0;
> > }
> >
> > if ((PWM_REG_PRESCAL(val, pwm->hwpwm) == PWM_PRESCAL_MASK) &&
> > @@ -142,7 +142,8 @@ static void sun4i_pwm_get_state(struct pwm_chip *chip,
> > prescaler = prescaler_table[PWM_REG_PRESCAL(val, pwm->hwpwm)];
> >
> > if (prescaler == 0)
> > - return;
> > + /* huh? is this an error? */
> > + return 0;
>
> Yeah, I think this would count as an error. The prescaler value returned
> from that table is 0 in what seems to be "invalid" configurations. If
> you look at how this is used in sun4i_pwm_calculate(), these entries are
> skipped for the computation of the duty cycle. So I would expect this to
> happen in either an invalidly configured or completely unconfigured PWM.
>
> That raises the question about what to do in these cases. If we return
> an error, that could potentially throw off consumers. So perhaps the
> closest would be to return a disabled PWM? Or perhaps it'd be up to the
> consumer to provide some fallback configuration for invalidly configured
> or unconfigured PWMs.
This is something I'd address on the framework level. i.e. don't care in
the lowlevel driver about setting .enabled = false (or whatever we
choose to do) but care for that in drivers/pwm/core.c.
Note that the status quo is that if that error happens the consumer sees
whatever state the lowlevel driver stored in pwm->state, without an
error indication.
Will send a v2.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2022-09-29 6:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-16 15:15 [PATCH 1/3] pwm: Change prototype of .get_state() callback to return an error Uwe Kleine-König
2022-09-16 15:15 ` [PATCH 2/3] pwm/tracing: Also record trace events for failed apply calls Uwe Kleine-König
2022-09-28 12:50 ` Thierry Reding
2022-09-16 15:15 ` [PATCH 3/3] pwm: Handle .get_state() failures Uwe Kleine-König
2022-09-28 12:55 ` Thierry Reding
2022-09-28 12:49 ` [PATCH 1/3] pwm: Change prototype of .get_state() callback to return an error Thierry Reding
2022-09-29 6:55 ` Uwe Kleine-König [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=20220929065532.n3kc44zimshufe4c@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=andrzej.hajda@intel.com \
--cc=brgl@bgdev.pl \
--cc=dianders@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel@pengutronix.de \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=narmstrong@baylibre.com \
--cc=pavel@ucw.cz \
--cc=robert.foss@linaro.org \
--cc=rostedt@goodmis.org \
--cc=thierry.reding@gmail.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).