All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Michael Walle <michael@walle.cc>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	linux-pwm@vger.kernel.org, linux-watchdog@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Rob Herring <robh+dt@kernel.org>,
	Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	Lee Jones <lee.jones@linaro.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	Shawn Guo <shawnguo@kernel.org>, Li Yang <leoyang.li@nxp.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jason Cooper <jason@lakedaemon.net>,
	Marc Zyngier <maz@kernel.org>, Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Date: Fri, 7 Aug 2020 12:24:41 +0200	[thread overview]
Message-ID: <20200807102441.qcshhsc36nzj7bpn@pengutronix.de> (raw)
In-Reply-To: <92116be9aa56250becc4019c6c7a1538@walle.cc>

[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]

Hi Michael,

On Fri, Aug 07, 2020 at 09:55:19AM +0200, Michael Walle wrote:
> Am 2020-08-07 09:45, schrieb Uwe Kleine-König:
> > On Fri, Aug 07, 2020 at 09:28:31AM +0200, Michael Walle wrote:
> > > Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
> > > > On Mon, Aug 03, 2020 at 11:35:52AM +0200, Michael Walle wrote:
> > > > > +static void sl28cpld_pwm_get_state(struct pwm_chip *chip,
> > > > > +				   struct pwm_device *pwm,
> > > > > +				   struct pwm_state *state)
> > > > > +{
> > > > > +	struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev);
> > > > > +	unsigned int reg;
> > > > > +	int prescaler;
> > > > > +
> > > > > +	sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, &reg);
> > > > > +
> > > > > +	state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE;
> > > > > +
> > > > > +	prescaler = FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg);
> > > > > +	state->period = SL28CPLD_PWM_PERIOD(prescaler);
> > > > > +
> > > > > +	sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, &reg);
> > > > > +	state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg);
> > > >
> > > > Should reg be masked to SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that
> > > > the upper bits are zero?
> > > 
> > > Mh, the hardware guarantees that bit7 is zero. So masking with
> > > SL28CPLD_PWM_CYCLE_MAX won't buy us much. But what I could think
> > > could go wrong is this: someone set the prescaler to != 0 and the
> > > duty cycle to a value greater than the max value for this particular
> > > prescaler mode. For the above calculations this would result in a
> > > duty_cycle greater than the period, if I'm not mistaken.
> > > 
> > > The behavior of the hardware is undefined in that case (at the moment
> > > it will be always on, I guess). So this isn't a valid setting.
> > > Nevertheless it might happen. So what about the following:
> > > 
> > > state->duty_cycle = min(state->duty_cycle, state->period);
> > 
> > If you care about this: This can also happen (at least shortly) in
> > sl28cpld_pwm_apply() as you write SL28CPLD_PWM_CTRL before
> > SL28CPLD_PWM_CYCLE there.
> 
> It could also happen if it was the other way around, couldn't it?
> Changing modes might glitch.

If you want to prevent this, you have to order the writes depending on
prescaler increasing or decreasing.

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 --]

WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Michael Walle <michael@walle.cc>
Cc: devicetree@vger.kernel.org,
	Catalin Marinas <catalin.marinas@arm.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Pavel Machek <pavel@ucw.cz>, Lee Jones <lee.jones@linaro.org>,
	Jason Cooper <jason@lakedaemon.net>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Marc Zyngier <maz@kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Guenter Roeck <linux@roeck-us.net>,
	linux-pwm@vger.kernel.org, Jean Delvare <jdelvare@suse.com>,
	linux-watchdog@vger.kernel.org, Will Deacon <will@kernel.org>,
	linux-gpio@vger.kernel.org, Mark Brown <broonie@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Wim Van Sebroeck <wim@linux-watchdog.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-hwmon@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org, Li Yang <leoyang.li@nxp.com>,
	Rob Herring <robh+dt@kernel.org>, Shawn Guo <shawnguo@kernel.org>
Subject: Re: [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller
Date: Fri, 7 Aug 2020 12:24:41 +0200	[thread overview]
Message-ID: <20200807102441.qcshhsc36nzj7bpn@pengutronix.de> (raw)
In-Reply-To: <92116be9aa56250becc4019c6c7a1538@walle.cc>


[-- Attachment #1.1: Type: text/plain, Size: 2490 bytes --]

Hi Michael,

On Fri, Aug 07, 2020 at 09:55:19AM +0200, Michael Walle wrote:
> Am 2020-08-07 09:45, schrieb Uwe Kleine-König:
> > On Fri, Aug 07, 2020 at 09:28:31AM +0200, Michael Walle wrote:
> > > Am 2020-08-06 10:40, schrieb Uwe Kleine-König:
> > > > On Mon, Aug 03, 2020 at 11:35:52AM +0200, Michael Walle wrote:
> > > > > +static void sl28cpld_pwm_get_state(struct pwm_chip *chip,
> > > > > +				   struct pwm_device *pwm,
> > > > > +				   struct pwm_state *state)
> > > > > +{
> > > > > +	struct sl28cpld_pwm *priv = dev_get_drvdata(chip->dev);
> > > > > +	unsigned int reg;
> > > > > +	int prescaler;
> > > > > +
> > > > > +	sl28cpld_pwm_read(priv, SL28CPLD_PWM_CTRL, &reg);
> > > > > +
> > > > > +	state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE;
> > > > > +
> > > > > +	prescaler = FIELD_GET(SL28CPLD_PWM_CTRL_PRESCALER_MASK, reg);
> > > > > +	state->period = SL28CPLD_PWM_PERIOD(prescaler);
> > > > > +
> > > > > +	sl28cpld_pwm_read(priv, SL28CPLD_PWM_CYCLE, &reg);
> > > > > +	state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg);
> > > >
> > > > Should reg be masked to SL28CPLD_PWM_CYCLE_MAX, or is it guaranteed that
> > > > the upper bits are zero?
> > > 
> > > Mh, the hardware guarantees that bit7 is zero. So masking with
> > > SL28CPLD_PWM_CYCLE_MAX won't buy us much. But what I could think
> > > could go wrong is this: someone set the prescaler to != 0 and the
> > > duty cycle to a value greater than the max value for this particular
> > > prescaler mode. For the above calculations this would result in a
> > > duty_cycle greater than the period, if I'm not mistaken.
> > > 
> > > The behavior of the hardware is undefined in that case (at the moment
> > > it will be always on, I guess). So this isn't a valid setting.
> > > Nevertheless it might happen. So what about the following:
> > > 
> > > state->duty_cycle = min(state->duty_cycle, state->period);
> > 
> > If you care about this: This can also happen (at least shortly) in
> > sl28cpld_pwm_apply() as you write SL28CPLD_PWM_CTRL before
> > SL28CPLD_PWM_CYCLE there.
> 
> It could also happen if it was the other way around, couldn't it?
> Changing modes might glitch.

If you want to prevent this, you have to order the writes depending on
prescaler increasing or decreasing.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2020-08-07 10:24 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-03  9:35 [PATCH v7 00/13] Add support for Kontron sl28cpld Michael Walle
2020-08-03  9:35 ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 01/13] mfd: add simple regmap based I2C driver Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 02/13] dt-bindings: mfd: Add bindings for sl28cpld Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 03/13] mfd: simple-mfd-i2c: add sl28cpld support Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 04/13] irqchip: add sl28cpld interrupt controller support Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 05/13] watchdog: add support for sl28cpld watchdog Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 06/13] pwm: add support for sl28cpld PWM controller Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-06  8:40   ` Uwe Kleine-König
2020-08-06  8:40     ` Uwe Kleine-König
2020-08-07  7:28     ` Michael Walle
2020-08-07  7:28       ` Michael Walle
2020-08-07  7:45       ` Uwe Kleine-König
2020-08-07  7:45         ` Uwe Kleine-König
2020-08-07  7:55         ` Michael Walle
2020-08-07  7:55           ` Michael Walle
2020-08-07 10:24           ` Uwe Kleine-König [this message]
2020-08-07 10:24             ` Uwe Kleine-König
2020-08-10  7:13       ` Lee Jones
2020-08-10  7:13         ` Lee Jones
2020-08-10  7:31         ` Michael Walle
2020-08-10  7:31           ` Michael Walle
2020-08-13  7:09           ` Michael Walle
2020-08-13  7:09             ` Michael Walle
2020-08-13  8:21           ` Lee Jones
2020-08-13  8:21             ` Lee Jones
2020-08-03  9:35 ` [PATCH v7 07/13] gpio: add support for the sl28cpld GPIO controller Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 08/13] hwmon: add support for the sl28cpld hardware monitoring controller Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 09/13] arm64: dts: freescale: sl28: enable sl28cpld Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 10/13] arm64: dts: freescale: sl28: map GPIOs to input events Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 11/13] arm64: dts: freescale: sl28: enable LED support Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 12/13] arm64: dts: freescale: sl28: enable fan support Michael Walle
2020-08-03  9:35   ` Michael Walle
2020-08-03  9:35 ` [PATCH v7 13/13] arm64: defconfig: enable the sl28cpld board management controller Michael Walle
2020-08-03  9:35   ` Michael Walle

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=20200807102441.qcshhsc36nzj7bpn@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jason@lakedaemon.net \
    --cc=jdelvare@suse.com \
    --cc=lee.jones@linaro.org \
    --cc=leoyang.li@nxp.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=maz@kernel.org \
    --cc=michael@walle.cc \
    --cc=pavel@ucw.cz \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=thierry.reding@gmail.com \
    --cc=will@kernel.org \
    --cc=wim@linux-watchdog.org \
    /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.