public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Doug Anderson <dianders@chromium.org>
Cc: "Heiko Stuebner" <heiko@sntech.de>,
	"David.Wu" <david.wu@rock-chips.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	黄涛 <huangtao@rock-chips.com>,
	"Kever Yang" <kever.yang@rock-chips.com>,
	张睛 <zhangqing@rock-chips.com>, 许剑群 <jay.xu@rock-chips.com>,
	"Brian Norris" <briannorris@chromium.org>,
	"open list:ARM/Rockchip SoC..."
	<linux-rockchip@lists.infradead.org>,
	"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@codeaurora.org>
Subject: Re: [v5,22/46] pwm: rockchip: avoid glitches on already running PWMs
Date: Mon, 21 Aug 2017 21:50:31 +0200	[thread overview]
Message-ID: <20170821215031.17d54ab5@bbrezillon> (raw)
In-Reply-To: <CAD=FV=V6MvyO5XygsYCzDahG1C8ZX4+LuXebkhRuWPOzOx1RsQ@mail.gmail.com>

Le Mon, 21 Aug 2017 09:49:52 -0700,
Doug Anderson <dianders@chromium.org> a =C3=A9crit :

> Hi,
>=20
> On Mon, Aug 21, 2017 at 8:39 AM, Boris Brezillon
> <boris.brezillon@free-electrons.com> wrote:
> > Hi Doug,
> >
> > Sorry for the late reply.
> >
> > Le Fri, 4 Aug 2017 09:22:56 -0700,
> > Doug Anderson <dianders@chromium.org> a =C3=A9crit :
> > =20
> >> Hi,
> >>
> >> On Fri, Aug 4, 2017 at 7:48 AM, Heiko Stuebner <heiko@sntech.de> wrote=
: =20
> >> >> > We found a issue recently, if the pwm0 is not enabled at uboot an=
d pwm2
> >> >> > is enabled at uboot, the PWM clock will be disabled at pwm0's pro=
be. It
> >> >> > is true to close the pwm clock, and the pwm2 can't work during a =
while,
> >> >> > until the pwm2 probe, because the pwm0 and pwm2 are the same cloc=
k for
> >> >> > their work. In fact, the pwm0 can not know the pwm2's status.
> >> >> >
> >> >> > So we need to get all the PWMs state in a public place where it's=
 early
> >> >> > than the PWM probe, if that's the way it is. Then keep the PWM clk
> >> >> > enabled if theis is one PWM appears to be up and running. The pla=
ce
> >> >> > maybe in the clock core init, like adding pwm clock as critial on=
e.
> >> >> >
> >> >> > Another way is that we don't enable pwm clock firstly at PWM prob=
e,
> >> >> > because whether or not the PWM state has been enabled in the Uboo=
t, like
> >> >> > other modules, our chip default PWM clock registers are enabled a=
t the
> >> >> > beginning, read the PWM registers directly to know the PWM state.=
 Then
> >> >> > if the PWM state is enabled, call the enable_clk(pc->clk) to add =
the
> >> >> > clock count=3D1. If the PWM state is disabled, we do nothing. Aft=
er all
> >> >> > the PWMs are probed and all modules are probed, the clock core wi=
ll gate
> >> >> > the PWM clock if the clock count is 0, and keep clk enabled if th=
e clock
> >> >> > count is not 0.
> >> >> >
> >> >> > How do you feel about it? =20
> >> >>
> >> >> Ouch. That's indeed hard to solve in a clean way. I may have
> >> >> something to suggest but I'm not sure clk maintainers will like it:=
 what
> >> >> if we make clk_disable() and clk_unprepare() just decrement the ref=
count
> >> >> before the disable-unused-clks procedure has been executed (see
> >> >> proposed patch below)? This way all clks that have been enabled by =
the
> >> >> bootloader will stay in such state until all drivers have had a cha=
nce
> >> >> to retain them (IOW, call clk_prepare()+clk_enable()).
> >> >>
> >> >> BTW, I think the problem you're describing here is not unique to PWM
> >> >> devices, it's just that now, some PWM drivers are smart and try to =
keep
> >> >> clks enabled to prevent glitches. =20
> >> >
> >> > Actually, Mike had patches that introduced so called "handoff" clock=
s [0].
> >> > Clocks that were handled as critical until some driver picked them u=
p.
> >> >
> >> > It's not exactly the same as your change and still would require
> >> > intervention from clock-drivers to mark clocks in such a way. =20
> >>
> >> Right.  As you're saying handoff isn't enough because in this case a
> >> driver _has_ picked up the clock.  The whole issue is that it's a
> >> shared clock between the 4 PLLs.  One driver already claimed the
> >> clock, enabled it, and disabled it.  Really something would need to
> >> know that another driver in the future might want to also pick up the
> >> clock.
> >>
> >> =20
> >> > So I really also like your approach, as it would make clock wiggling
> >> > during early boot safe for everyone involved :-) .
> >> >
> >> > And both seem to cater to slightly different use-cases as well. =20
> >>
> >> One worry I have about not truly disabling any clocks at boot time is
> >> that it could break someone who relies on a clock being disabled.  I'm
> >> not 100% sure that any of these would really affect someone, but...
> >>
> >> ...there is one example case I know of where you absolutely need a
> >> clock to stop on command (AKA it wouldn't be OK to defer till late
> >> init).  That case is for SD Card Tuning.  When you're doing a voltage
> >> switch the actual transition is keyed off the card clock stopping.
> >> That would break if there was a situation where clk_disable() didn't
> >> actually do what it was supposed to.  This is a bit of a contrived
> >> case and probably isn't 100% relevant (I think dw_mmc, for instance,
> >> stops the card clock directly through the dw_mmc IP block and it's
> >> invisible to the common clock framework), but it illustrates the point
> >> that there could plausibly be cases where deferring a clk_disable()
> >> might be unwise. =20
> >
> > Right, I didn't consider this use case, but some drivers might rely on
> > the fact that clk_disable() disables the clk right away instead of
> > deferring it.
> > =20
> >>
> >> I suppose, though, that it would be possible to distinguish those two
> >> cases via a 2nd API call.  AKA:
> >>
> >> clk_disable() -- disable the clock eventually
> >> clk_disable_sync() -- disable the clock but don't defer.  Still won't
> >> actually disable if someone else explicitly holds a reference. =20
> >
> > Actually, I'd recommend keeping the existing behavior for clk_disable()
> > and adding a new function called clk_disable_async() (or
> > clk_disable_deferrable()). This way we do not break existing users that
> > rely on clk_disable() synchronicity and force users that actually allow
> > deferring clk gating to explicitly state it. =20
>=20
> Yeah, there's a tradeoff.  Your solution is definitely safer and
> causes less short term churn.  ...but it's at the expense of some
> inconsistency between various similar APIs (some APIs the "default" is
> sync and some the "default" is async).  Although I guess if there's
> one consistent thing about the kernel APIs it's that they're
> inconsistent.  :-P

Yep.

>=20
> Is anyone volunteering to do this?

Looks like you found a volunteer: Elaine already posted my patch to the
linux-clk ML :-).

> Do we want anyone with actual
> "approval" authority to chime in?

Don't if that's what you meant by "approval" authority, but you'll
need Mike or Stephen (or both) to validate this approach.

  reply	other threads:[~2017-08-21 19:50 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 20:03 [PATCH v5 00/46] pwm: add support for atomic update Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 01/46] pwm: rcar: make use of pwm_is_enabled() Boris Brezillon
2016-04-12 11:01   ` Thierry Reding
2016-04-14 11:05     ` Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 02/46] backlight: pwm_bl: remove useless call to pwm_set_period() Boris Brezillon
2016-04-12 11:03   ` Thierry Reding
2016-04-12 14:16     ` Lee Jones
2016-04-12 14:25       ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 03/46] backlight: lm3630a_bl: stop messing with the pwm->period field Boris Brezillon
2016-04-12 11:08   ` Thierry Reding
2016-04-12 14:16     ` Lee Jones
2016-04-12 14:26       ` Thierry Reding
2016-04-13  8:25         ` Lee Jones
2016-04-13  8:26           ` Lee Jones
2016-03-30 20:03 ` [PATCH v5 04/46] pwm: get rid of pwm->lock Boris Brezillon
2016-04-12 11:22   ` Thierry Reding
2016-04-12 11:32     ` Boris Brezillon
2016-04-12 11:46       ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 05/46] pwm: introduce the pwm_args concept Boris Brezillon
2016-03-30 21:55   ` Stephen Boyd
2016-03-31  7:09     ` Boris Brezillon
2016-03-31  7:57     ` Boris Brezillon
2016-04-12 11:39   ` Thierry Reding
2016-04-12 12:04     ` Boris Brezillon
2016-04-12 12:20       ` Thierry Reding
2016-04-12 12:55         ` Boris Brezillon
2016-04-12 13:06     ` Boris Brezillon
2016-04-12 13:15       ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 06/46] pwm: use pwm_get/set_xxx() helpers where appropriate Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 07/46] clk: pwm: use pwm_get_args() " Boris Brezillon
2016-03-30 21:58   ` Stephen Boyd
2016-03-30 20:03 ` [PATCH v5 08/46] hwmon: pwm-fan: " Boris Brezillon
2016-03-30 22:52   ` Guenter Roeck
2016-03-31  7:07     ` Boris Brezillon
2016-04-04 15:20       ` Thierry Reding
2016-04-01  8:29   ` Kamil Debski
2016-03-30 20:03 ` [PATCH v5 09/46] misc: max77693-haptic: " Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 10/46] leds: pwm: " Boris Brezillon
2016-03-31  7:13   ` Jacek Anaszewski
2016-03-30 20:03 ` [PATCH v5 11/46] regulator: " Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 12/46] fbdev: ssd1307fb: " Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 13/46] backlight: pwm_bl: " Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 14/46] pwm: keep PWM state in sync with hardware state Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 15/46] pwm: introduce the pwm_state concept Boris Brezillon
2016-04-12 11:49   ` Thierry Reding
2016-04-12 12:17     ` Boris Brezillon
2016-04-12 12:21       ` Thierry Reding
2016-04-12 12:45         ` Boris Brezillon
2016-04-12 13:11           ` Thierry Reding
2016-04-12 13:26             ` Boris Brezillon
2016-04-12 14:05               ` Thierry Reding
2016-04-12 14:13                 ` Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 16/46] pwm: move the enabled/disabled info into pwm_state Boris Brezillon
2016-04-12 11:51   ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 17/46] pwm: add the PWM initial state retrieval infra Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 18/46] pwm: add the core infrastructure to allow atomic update Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 19/46] pwm: switch to the atomic API Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 20/46] pwm: add information about polarity, duty cycle and period to debugfs Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 21/46] pwm: rockchip: add initial state retrieval Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 22/46] pwm: rockchip: avoid glitches on already running PWMs Boris Brezillon
     [not found]   ` <a5efa7d7-ceb5-e6b0-b2d1-2d79cd20265f@rock-chips.com>
2017-08-04 14:07     ` [v5,22/46] " Boris Brezillon
2017-08-04 14:48       ` Heiko Stuebner
2017-08-04 16:22         ` Doug Anderson
2017-08-21 15:39           ` Boris Brezillon
2017-08-21 16:49             ` Doug Anderson
2017-08-21 19:50               ` Boris Brezillon [this message]
2017-08-07  7:43         ` Elaine Zhang
2016-03-30 20:03 ` [PATCH v5 23/46] pwm: rockchip: add support for atomic update Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 24/46] pwm: sti: add support for initial state retrieval Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 25/46] pwm: sti: avoid glitches on already running PWMs Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 26/46] pwm: sun4i: implement hardware readout Boris Brezillon
2016-03-31  8:00   ` Alexandre Belloni
2016-03-30 20:03 ` [PATCH v5 27/46] regulator: pwm: adjust PWM config at probe time Boris Brezillon
2016-03-30 21:22   ` Mark Brown
2016-03-30 20:03 ` [PATCH v5 28/46] regulator: pwm: swith to the atomic PWM API Boris Brezillon
2016-03-30 21:23   ` Mark Brown
2016-03-30 20:03 ` [PATCH v5 29/46] regulator: pwm: properly initialize the ->state field Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 30/46] regulator: pwm: retrieve correct voltage Boris Brezillon
2016-03-30 21:24   ` Mark Brown
2016-04-07 21:54     ` Boris Brezillon
2016-04-12  4:42       ` Mark Brown
2016-04-12  8:37         ` Boris Brezillon
2016-04-12 10:09           ` Mark Brown
2016-04-12 10:31             ` Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 31/46] pwm: update documentation Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 32/46] pwm: deprecate pwm_config(), pwm_enable() and pwm_disable() Boris Brezillon
2016-03-31 17:38   ` Dmitry Torokhov
2016-03-31 18:54     ` Boris Brezillon
2016-04-04 15:22       ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 33/46] pwm: replace pwm_disable() by pwm_apply_state() Boris Brezillon
2016-03-30 20:03 ` [PATCH v5 34/46] clk: pwm: switch to the atomic API Boris Brezillon
2016-03-30 22:01   ` Stephen Boyd
2016-03-31  6:57     ` Boris Brezillon
2016-04-04 15:30       ` Thierry Reding
2016-03-30 20:03 ` [PATCH v5 35/46] hwmon: pwm-fan: " Boris Brezillon
2016-04-01  8:29   ` Kamil Debski
2016-03-30 20:03 ` [PATCH v5 36/46] input: misc: max77693: " Boris Brezillon
2016-03-31 17:48   ` Dmitry Torokhov
2016-03-31 18:57     ` Boris Brezillon
2016-04-04 15:34       ` Thierry Reding
2016-03-30 20:04 ` [PATCH v5 37/46] input: misc: max8997: switch to the atomic PWM API Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 38/46] input: misc: pwm-beeper: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 39/46] leds: pwm: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 40/46] backlight: lm3630a: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 41/46] backlight: lp855x: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 42/46] backlight: lp8788: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 43/46] backlight: pwm_bl: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 44/46] video: ssd1307fb: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 45/46] drm: i915: " Boris Brezillon
2016-03-30 20:04 ` [PATCH v5 46/46] ARM: s3c24xx: rx1950: " Boris Brezillon
2016-03-30 20:18 ` [PATCH v5 00/46] pwm: add support for atomic update Boris Brezillon
2016-04-11 22:42 ` Boris Brezillon

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=20170821215031.17d54ab5@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=briannorris@chromium.org \
    --cc=david.wu@rock-chips.com \
    --cc=dianders@chromium.org \
    --cc=heiko@sntech.de \
    --cc=huangtao@rock-chips.com \
    --cc=jay.xu@rock-chips.com \
    --cc=kever.yang@rock-chips.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@codeaurora.org \
    --cc=thierry.reding@gmail.com \
    --cc=zhangqing@rock-chips.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