[PATCH v2 2/9] cmd: boot: implement PMIC based poweroff
Svyatoslav Ryhel
clamor95 at gmail.com
Sun Jul 23 10:41:29 CEST 2023
нд, 23 лип. 2023 р. о 06:48 Simon Glass <sjg at chromium.org> пише:
>
> Hi Svyatoslav,
>
> On Thu, 20 Jul 2023 at 02:48, Svyatoslav Ryhel <clamor95 at gmail.com> wrote:
> >
> > Use new PMIC ops to perform device poweroff.
> >
> > Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
> > ---
> > cmd/Kconfig | 6 ++++++
> > cmd/boot.c | 40 ++++++++++++++++++++++++++++++++++++++++
> > 2 files changed, 46 insertions(+)
> >
> > diff --git a/cmd/Kconfig b/cmd/Kconfig
> > index ecfd575237..47654297f8 100644
> > --- a/cmd/Kconfig
> > +++ b/cmd/Kconfig
> > @@ -1439,6 +1439,12 @@ config CMD_POWEROFF
> > help
> > Poweroff/Shutdown the system
> >
> > +config CMD_PMIC_POWEROFF
> > + bool "PMIC poweroff"
> > + select CMD_POWEROFF
> > + help
> > + Shutdown the system using PMIC poweroff sequence.
> > +
> > config CMD_READ
> > bool "read - Read binary data from a partition"
> > help
> > diff --git a/cmd/boot.c b/cmd/boot.c
> > index 14839c1ced..4270034194 100644
> > --- a/cmd/boot.c
> > +++ b/cmd/boot.c
> > @@ -9,7 +9,13 @@
> > */
> > #include <common.h>
> > #include <command.h>
> > +#include <dm.h>
> > +#include <log.h>
> > #include <net.h>
> > +#include <dm/device-internal.h>
> > +#include <dm/uclass-internal.h>
> > +#include <power/pmic.h>
> > +#include <linux/delay.h>
> >
> > #ifdef CONFIG_CMD_GO
> >
> > @@ -64,6 +70,40 @@ U_BOOT_CMD(
> > );
> >
> > #ifdef CONFIG_CMD_POWEROFF
> > +#ifdef CONFIG_CMD_PMIC_POWEROFF
> > +int do_poweroff(struct cmd_tbl *cmdtp, int flag,
> > + int argc, char *const argv[])
> > +{
> > + struct uc_pmic_priv *pmic_priv;
> > + struct udevice *dev;
> > + int ret;
> > +
> > + for (uclass_find_first_device(UCLASS_PMIC, &dev);
> > + dev;
> > + uclass_find_next_device(&dev)) {
> > + if (dev && !device_active(dev)) {
> > + ret = device_probe(dev);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + /* value we need to check is set after probe */
> > + pmic_priv = dev_get_uclass_priv(dev);
> > + if (pmic_priv->sys_pow_ctrl) {
> > + ret = pmic_poweroff(dev);
> > +
> > + /* wait some time and then print error */
> > + mdelay(5000);
> > + log_err("Failed to power off!!!\n");
> > + return ret;
> > + }
> > + }
> > +
> > + /* no device should reach here */
> > + return 1;
> > +}
> > +#endif
> > +
> > U_BOOT_CMD(
> > poweroff, 1, 0, do_poweroff,
> > "Perform POWEROFF of the device",
> > --
> > 2.39.2
> >
>
> How does this relate to sysreset_walk(SYSRESET_POWER_OFF) and
> do_poweroff() in cmd/boot.c?
>
It does not, or at least I might misunderstand you. This is made more
to fit embedded devices or at least devices where power off is
controlled by PMIC. In this case the device must have DM pmic driver
with poweroff function implemented and set in the dts as
system-power-controller. If this is true, the maintainer in defconfig
enables PMIC driver and CONFIG_CMD_PMIC_POWEROFF so the function above
is unlocked and used. This avoids board definitions of do_poweroff
like I had to do with my devices and at the same time does not break
any other devices since CMD_POWEROFF is still available in unmodded
state.
> Regards,
> Simon
More information about the U-Boot
mailing list