public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>,
	 Jaehoon Chung <jh80.chung@samsung.com>,
	Lukasz Majewski <lukma@denx.de>,
	 Sean Anderson <seanga2@gmail.com>,
	Anatolij Gustschin <agust@denx.de>,
	 Fabio Estevm <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
	 Mario Six <mario.six@gdsys.cc>,
	 Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 u-boot@lists.denx.de,  Ian Ray <ian.ray@gehealthcare.com>,
	 Michael Nazzareno Trimarchi <michael@amarulasolutions.com>,
	 Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	 Adam Ford <aford173@gmail.com>, Marek Vasut <marex@denx.de>
Subject: Re: [PATCH v3 05/13] power-domain: Add refcounting
Date: Fri, 24 Jan 2025 16:20:00 +0100	[thread overview]
Message-ID: <87r04sfdcv.fsf@bootlin.com> (raw)
In-Reply-To: <CAFLszThgbakRhLTC3T04uV6W+MbXENyVvhT4Bvam4ymmUqBf2Q@mail.gmail.com> (Simon Glass's message of "Thu, 23 Jan 2025 07:38:32 -0700")

Hi Simon,

>> > If we
>> > want a power domain to actually turn off, how many times do we need to
>> > call power_domain_off()?
>>
>> We do not? It is why I add refcounting, if a power domain has 2
>> consumers, each consumer says whether it needs the power domain to be on
>> or off and the core will handle, but in no case they should force it's
>> state.
>
> This is a bootloader, so we do sometimes need to force something off,
> or on.

This, I do understand.

>> > The function silently does nothing in many
>> > cases, so it is not deterministic.
>>
>> It is fully deterministic, as long as consumers call power_on/off
>> evenly (and this is already what we request in U-Boot).
>
> But I foresee people setting up power domains in board code, not
> drivers. My concern is that this is hiding the real state.

Setting up power domains in board code is drawback. It is legacy
behaviour, people should switch to the device model (ie. using a proper
DT description) and stop messing around with board files. It's been like
5 years since U-Boot forced people to transition, I wouldn't feel bad if
these boards were no longer behaving like expected (mind there are very
little chances this will break anything, as the kernel is supposed to
re-init these domains anyway).

>> > In the case where we *actually*
>> > want to turn the power domain off, we are at a loss as to what code to
>> > write.
>> >
>> >> Hence, I do not agree with returning error codes in these situations,
>> >> they are misleading and they would have to be ignored anyway.
>> >>
>> >
>> > How about creating a power_domain_off_if_allowed() or
>> > power_domain_soft_off/on() or power_domain_req_off (for request)?
>>
>> The power domain logic has a hardware reality in many SoCs but is also a
>> software concept that is shared with Linux. Changing the semantics in
>> U-Boot would be very misleading and if my understanding is correct, this
>> approach would be new.
>
> Yes this is quite a strong argument. Can you point me to the
> equivalent API in Linux? I see pm_domain but not the same as U-Boot

Yes, pmdomain (former genpd if I get it correctly), how are they
different? From my point of view it is the same. The same devices are
supported. So why would we want the API to be different?

>> If you really want a way to track the state of the power domain,
>> however, I can maybe add a helper returning its state, ie:
>>
>>          bool power_domain_is_on(domain)
>>
>> Would that work?
>
> Not really. We should have an API which returns -EALREADY or -EBUSY
> based on the ref counts. But yes, we can change the naming, so that
> this 'deterministic' ones have a different name, with the current
> names used for your ref-counting one. Then the ref-counting one is a
> thin layer on top of the deterministic one.

Honestly, I am not convinced, but I will anyway assume we need a way to
force a domain off. There is no need to force a power domain on however,
as after power_domain_on(), the power domain cannot be off (except error
condition of course).

So I'll add a helper to force power off. It will be called
power_domain_off_force() and be preceded with a comment stating that
this is not the standard approach, to guide people towards the
refcounted helper instead.

Would this address your request?

Thanks,
Miquèl

  reply	other threads:[~2025-01-24 15:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-10 18:42 [PATCH v3 00/13] Add imx8mp video support Miquel Raynal
2025-01-10 18:42 ` [PATCH v3 01/13] dm: doc: Fix example Miquel Raynal
2025-01-10 18:42 ` [PATCH v3 02/13] dm: core: Add a helper to retrieve devices through graph endpoints Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 03/13] sandbox: Add a fake DSI controller and link it to the panel Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 04/13] test: dm: test-fdt: Add checks for uclass_get_device_by_endpoint() Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 05/13] power-domain: Add refcounting Miquel Raynal
2025-01-15 13:19   ` Simon Glass
2025-01-20 10:34     ` Miquel Raynal
2025-01-20 19:21       ` Simon Glass
2025-01-21  8:34         ` Miquel Raynal
2025-01-23 14:38           ` Simon Glass
2025-01-24 15:20             ` Miquel Raynal [this message]
2025-01-25 17:11               ` Simon Glass
2025-01-27 17:11                 ` Miquel Raynal
2025-01-27 17:42                   ` Simon Glass
2025-01-28  8:56                     ` Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 06/13] clk: Ensure the parent clocks are enabled while reparenting Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 07/13] clk: imx8mp: Add media related clocks Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 08/13] imx: power-domain: Describe the i.MX8 MEDIAMIX domain Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 09/13] imx: power-domain: Add support for the MEDIAMIX control block Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 10/13] video: imx: Fix Makefile in order to be able to add other imx drivers Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 11/13] video: imx: Add LDB driver Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 12/13] video: imx: Add LCDIF driver Miquel Raynal
2025-01-10 18:43 ` [PATCH v3 13/13] imx8mp_evk: Enable display support Miquel Raynal
2025-01-10 18:53   ` Fabio Estevam
2025-01-11  9:51     ` Miquel Raynal
2025-01-16 16:13       ` Fabio Estevam
2025-01-16 17:09         ` Miquel Raynal
2025-01-10 19:11   ` Fabio Estevam

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=87r04sfdcv.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=aford173@gmail.com \
    --cc=agust@denx.de \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=festevam@gmail.com \
    --cc=ian.ray@gehealthcare.com \
    --cc=jh80.chung@samsung.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=mario.six@gdsys.cc \
    --cc=michael@amarulasolutions.com \
    --cc=peng.fan@nxp.com \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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