linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Thierry Reding <thierry.reding@gmail.com>
Cc: mark.rutland@arm.com, linux-pwm@vger.kernel.org,
	devicetree@vger.kernel.org, palmer@sifive.com,
	linux-kernel@vger.kernel.org, sachin.ghadi@sifive.com,
	Yash Shah <yash.shah@sifive.com>,
	robh+dt@kernel.org, paul.walmsley@sifive.com,
	linux-riscv@lists.infradead.org
Subject: Re: [PATCH v5 2/2] pwm: sifive: Add a driver for SiFive SoC PWM
Date: Tue, 12 Mar 2019 08:27:28 +0100	[thread overview]
Message-ID: <20190312072728.dy26cg4cateumuug@pengutronix.de> (raw)
In-Reply-To: <20190214155903.7h3b7v3nbhj57uy2@pengutronix.de>

Hello,

On Thu, Feb 14, 2019 at 04:59:03PM +0100, Uwe Kleine-König wrote:
> On Wed, Feb 13, 2019 at 01:37:03PM +0100, Thierry Reding wrote:
> > On Thu, Feb 07, 2019 at 11:16:57AM +0100, Uwe Kleine-König wrote:
> > > On Tue, Jan 29, 2019 at 05:13:19PM +0530, Yash Shah wrote:
> > [...]
> > > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
> > [...]
> > > > +	writel(val, pwm->regs + PWM_SIFIVE_PWMCFG);
> > > > +
> > > > +	writel(frac, pwm->regs + PWM_SIFIVE_PWMCMP0 + dev->hwpwm * SIZE_PWMCMP);
> > > > +
> > > > +	val &= ~(1 << PWM_SIFIVE_PWMCFG_DEGLITCH);
> > > > +	writel(val, pwm->regs + PWM_SIFIVE_PWMCFG);
> > > > +
> > > > +	pwm_sifive_get_state(chip, dev, state);
> > > 
> > > Thierry: This changes the pwm_state. Is this how this should be done?
> > 
> > Yes, I think that's fine. The PWM state should always reflect the
> > current hardware state. If the configuration that we program does not
> > reflect the state that was requested, that should be reflected in the
> > PWM state.
> 
> I'm not sure you blessed what is really done here. If I do:
> 
> 	state.duty_cycle = state.period;
> 	pwm_apply_state(pwm, &state);
> 
> the call in question doesn't only result in pwm->state.duty_cycle <
> pwm->state.period, but it also corrects my local state variable (i.e. I
> have state.duty_cycle < state.period afterwards).
> 
> Is this what you thought to be fine?

I thought a bit about this and I'm convinced that updating struct
pwm_device::state is/might be fine, but changing the caller's struct pwm_state
that was passed to pwm_apply_state is not.

Consider a consumer who does:

	#define PERIOD 5000000
	#define DUTY_LITTLE 10
	...
	struct pwm_state state = {
		.period = PERIOD,
		.duty_cycle = DUTY_LITTLE,
		.polarity = PWM_POLARITY_NORMAL,
		.enabled = true,
	};

	pwm_apply_state(mypwm, &state);
	...
	state.duty_cycle = PERIOD / 2;
	pwm_apply_state(mypwm, &state);

I think the second request should have state.period = 5000000 and not
some other value (that might only have chosen by the respective driver
because the first duty cycle was so short).

Best regards
Uwe

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

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

      reply	other threads:[~2019-03-12  7:27 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 11:43 [PATCH v5 0/2] PWM support for HiFive Unleashed Yash Shah
2019-01-29 11:43 ` [PATCH v5 1/2] pwm: sifive: Add DT documentation for SiFive PWM Controller Yash Shah
2019-01-30  8:14   ` Uwe Kleine-König
2019-02-06 10:48     ` Yash Shah
2019-02-06 11:07       ` Uwe Kleine-König
2019-02-06 12:40         ` Thierry Reding
2019-02-06 15:38           ` Uwe Kleine-König
2019-02-06 16:16             ` Thierry Reding
2019-02-06 16:35               ` Uwe Kleine-König
2019-01-29 11:43 ` [PATCH v5 2/2] pwm: sifive: Add a driver for SiFive SoC PWM Yash Shah
2019-02-05  8:21   ` kbuild test robot
2019-02-05 17:25   ` kbuild test robot
2019-02-06 12:44   ` Thierry Reding
2019-02-07  8:24     ` Yash Shah
2019-02-07 10:16   ` Uwe Kleine-König
2019-02-11 11:26     ` Yash Shah
2019-02-11 12:29       ` Uwe Kleine-König
2019-02-13 12:34         ` Thierry Reding
2019-02-13 17:39           ` Uwe Kleine-König
2019-02-13 12:37     ` Thierry Reding
2019-02-14 15:59       ` Uwe Kleine-König
2019-03-12  7:27         ` 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=20190312072728.dy26cg4cateumuug@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=palmer@sifive.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh+dt@kernel.org \
    --cc=sachin.ghadi@sifive.com \
    --cc=thierry.reding@gmail.com \
    --cc=yash.shah@sifive.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).