linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] regulator: core: make bulk API support optional supplies
Date: Mon, 6 Feb 2017 12:08:28 +0000	[thread overview]
Message-ID: <20170206120828.nqxcbkafjpgxur6b@sirena.org.uk> (raw)
In-Reply-To: <20170206043033.GA1900@dtor-ws>

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

On Sun, Feb 05, 2017 at 08:30:33PM -0800, Dmitry Torokhov wrote:
> On Sun, Feb 05, 2017 at 05:07:37PM +0100, Mark Brown wrote:

> > The tlv320aic32x4 driver isn't a particularly well written driver in
> > this regard in the first place - I don't recall the details but I
> > strongly suspect that the driver is an example of abuse of the optional
> > API and that of the supplies possibly only ldoin is actually optional.
> > I would expect that this should look *much* more like sgtl5000, or

> OK, I think the optional support in regulator_bulk_get will help
> sgtl5000 as well, as you would not have to go through contortions of
> requesting the optional regulator first and then figuring out if it
> should be included or excluded from the bulk supply list.

It does make things better, though I'm not sure that simply open coding
the optional regulators wouldn't be just as good.  I'm not 100% sure
that this is what the driver actually should be doing - there were lots
of problems with that driver figuring out what on earth it was supposed
to do as there were some older revisions of the chip with very serious
errata which used to be handled in the driver but broken the production
versions.  There's a degree of "it works, don't touch it" going on.

> > I'd be a lot happier if I were seeing examples where this helped a lot
> > and the original code looked good, I've not really been seeing those
> > though.

> If you can point me at a few examples where original code looks good I
> can see how it can be converter to bulk with optionals support.

The main one is the MMC core (which is what this was written for).

> >  A lot of the examples of use of optional regulators that I see
> > (including both those in drivers/input FWIW) don't look like they are
> > for supplies that should be optional.

> Fair enough. The regulators there are not optional, rather we are trying
> to avoid delays (i.e. doing msleep(N)) if regulators are not descried by
> the firmware (incomplete DT in OF system, or ACPI system). Will you
> accept:

> bool regulator_is_dummy(struct regulator *r)
> {
> 	return r == dummy_regulator_rdev;
> }

This is obviously a total failure of abstraction.

> or maybe even better

> bool regulator_is_always_on(struct regulator *r)
> {
> 	return r->always_on;
> }

> Then we can switch to straightforward (non-optional) regulator_get() in
> input and still avoid waiting when we don't actually control regulators.

This is also an abstraction failure, though it is better, and doesn't
quite do what you want since if the regulator is shared you may still
end up delaying when you don't need to.  What the drivers should be
doing is registering a notifier which they use to check when the
regulator was last enabled and using that to tell them if they need to
delay (with bonus points for adjusting the delay if we're part way
through the needed time).

It's probably worth having a helper which registers notifiers and
provides query functions that wraps this up, updates a timestamp for the
last enable and has a helper drivers can use to check if it was within a
given period, this is probably going to be a useful enough pattern for
that.  Drivers can then just enable and ask if how long ago the last
physical enable happened.

Depending on how severe the delays are and if anything else needs doing
(like resetting registers) a simpler thing can be to use a notifier to
determine if the power has been removed and reinitialize if that's
happened.

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

  reply	other threads:[~2017-02-06 12:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03 23:16 [PATCH 1/4] regulator: core: fix typo in regulator_bulk_disable() Dmitry Torokhov
2017-02-03 23:16 ` [PATCH 2/4] regulator: core: simplify regulator_bulk_force_disable() Dmitry Torokhov
2017-02-04 10:48   ` Applied "regulator: core: simplify regulator_bulk_force_disable()" to the regulator tree Mark Brown
2017-02-03 23:16 ` [PATCH 3/4] regulator: core: optimize devm_regulator_bulk_get() Dmitry Torokhov
2017-02-04 10:48   ` Applied "regulator: core: optimize devm_regulator_bulk_get()" to the regulator tree Mark Brown
2017-02-03 23:16 ` [PATCH 4/4] regulator: core: make bulk API support optional supplies Dmitry Torokhov
2017-02-04  7:53   ` kbuild test robot
2017-02-04 10:56   ` Mark Brown
2017-02-04 18:13     ` Dmitry Torokhov
2017-02-05 16:07       ` Mark Brown
2017-02-06  4:30         ` Dmitry Torokhov
2017-02-06 12:08           ` Mark Brown [this message]
2017-02-07  0:21   ` Bjorn Andersson
2017-02-07  0:47     ` Dmitry Torokhov
2017-02-04 10:47 ` Applied "regulator: core: fix typo in regulator_bulk_disable()" to the regulator tree Mark Brown

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=20170206120828.nqxcbkafjpgxur6b@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.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 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).