osd3358 and "poweroff"

Hi,
I have a custom board based on osd3358 and a little trouble getting the
"poweroff" command work as expected.

The device tree is almost the same as am335x-pocketbeagle.dts and I am running a v5.9-rc4 kernel.
Therefore,

&rtc {
  system-power-controller;
};

is defined.

The board is powered through USB (haven't tried other options).

"poweroff" results in:

...
[info] Hardware Clock updated to Wed Sep 9 14:31:56 UTC 2020.
[ ok ] Deactivating swap...done.
[ 200.324307] EXT4-fs (mmcblk1p2): re-mounted. Opts: (null)
[info] Will now halt.
[ 202.548073] reboot: Power down

After that, the gpio-led showing cpu activity trigger goes off for a moment
but after that it is flickering as if there is still CPU activity with some
1 second modulation.

Pressing the reset button immediately reboots.

So this means that "poweroff" does not shut down the PMIC and the processor
is still idling.

Pressing the power button for 10 seconds does a forced shutdown and the
reset button is without significance.

And hints how to make "poweroff" work are welcome.

BR and thanks,
Nikolaus Schaller

This two parts to make it work with the PocketBeagle, first is the
patch you have and then also configure the RTC in u-boot to use an
internal 32Khz reference:

U-boot doesn't make this too easy, so some things need to be moved around..

https://github.com/RobertCNelson/Bootloader-Builder/blob/master/patches/v2019.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch#L185-L207

Regards,

Hi,
I have a custom board based on osd3358 and a little trouble getting the
"poweroff" command work as expected.

The device tree is almost the same as am335x-pocketbeagle.dts and I am running a v5.9-rc4 kernel.
Therefore,

&rtc {
       system-power-controller;
};

is defined.

The board is powered through USB (haven't tried other options).

"poweroff" results in:

...
[info] Hardware Clock updated to Wed Sep 9 14:31:56 UTC 2020.
[ ok ] Deactivating swap...done.
[ 200.324307] EXT4-fs (mmcblk1p2): re-mounted. Opts: (null)
[info] Will now halt.
[ 202.548073] reboot: Power down

After that, the gpio-led showing cpu activity trigger goes off for a moment
but after that it is flickering as if there is still CPU activity with some
1 second modulation.

Pressing the reset button immediately reboots.

So this means that "poweroff" does not shut down the PMIC and the processor
is still idling.

Pressing the power button for 10 seconds does a forced shutdown and the
reset button is without significance.

And hints how to make "poweroff" work are welcome.

This two parts to make it work with the PocketBeagle, first is the
patch you have and then also configure the RTC in u-boot to use an
internal 32Khz reference:

U-boot doesn't make this too easy, so some things need to be moved around..

Bootloader-Builder/patches/v2019.04/0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch at master · RobertCNelson/Bootloader-Builder · GitHub

Ah, ok. I'll look into that.

But does it mean it is not a kernel problem? Is there no kernel-only solution (without touching u-boot)?
I do not need the RTC or RTC wakeup, just safe power-down by user-command...

BR and thanks,
Nikolaus

Ah, ok. I'll look into that.

But does it mean it is not a kernel problem? Is there no kernel-only solution (without touching u-boot)?
I do not need the RTC or RTC wakeup, just safe power-down by user-command...

RTC "sub-system" is used for Power Off on am335x, from what i've read,
that RTC register can only be set in u-boot (aka very early)..

Regards,

Ah, ok. I'll look into that.

But does it mean it is not a kernel problem? Is there no kernel-only solution (without touching u-boot)?
I do not need the RTC or RTC wakeup, just safe power-down by user-command...

RTC "sub-system" is used for Power Off on am335x, from what i've read,
that RTC register can only be set in u-boot (aka very early)..

Ok, I'll dig into that code and direction...

Many thanks,
Nikolaus Schallr

Hi Robert,

Ah, ok. I'll look into that.

But does it mean it is not a kernel problem? Is there no kernel-only solution (without touching u-boot)?
I do not need the RTC or RTC wakeup, just safe power-down by user-command...

RTC "sub-system" is used for Power Off on am335x, from what i've read,
that RTC register can only be set in u-boot (aka very early)..

Ok, I'll dig into that code and direction...

I have checked your patch and I have found that my U-Boot already includes rtc32k_enable().
It is compiled into SPL/MLO and seems to work because depending on

  writel((0 << 3) | (1 << 6), &rtc->osc);

or

  writel((1 << 3) | (1 << 6), &rtc->osc);

I can read different values from Linux:

root@letux:~# devmem2 0x44E3E054
/dev/mem opened.
Memory mapped at address 0xb6fba000.
Value at address 0x44E3E054 (0xb6fba054): 0x40
root@letux:~#

or

root@letux:~# devmem2 0x44E3E054
/dev/mem opened.
Memory mapped at address 0xb6f77000.
Value at address 0x44E3E054 (0xb6f77054): 0x48
root@letux:~#

But it has no influence on the "poweroff" behaviour. In either case reboot does not
shut down the PMIC like pressing the power button 10 seconds.

Did I miss something what your patch is doing in addition to handle the osd3358?

I didn't mention, but
* "reboot" works
* rtcwake -m mem -s 10 fails to wake up (sleeps and there is no activity LED flickering like with poweroff)
* 32kHz XTAL is working and active (even during suspend and in the strange poweroff state)
* oscillator is off after forced poweroff (there is no backup battery connected)

Suspend seems to be a deeper sleep state than power off?

Interestingly, hwclock -r stalls for 10 seconds, reports 00:00:57 (or similar after cold boot)
and does not increment. I can write the hwclock but it still does not increment.

So for some reason the RTC isn't running but can be accessed.

BR and thanks,
Nikolaus Schaller

Hi,

Hi Robert,

Ah, ok. I'll look into that.

But does it mean it is not a kernel problem? Is there no kernel-only solution (without touching u-boot)?
I do not need the RTC or RTC wakeup, just safe power-down by user-command...

RTC "sub-system" is used for Power Off on am335x, from what i've read,
that RTC register can only be set in u-boot (aka very early)..

Ok, I'll dig into that code and direction...

I have checked your patch and I have found that my U-Boot already includes rtc32k_enable().
It is compiled into SPL/MLO and seems to work because depending on

  writel((0 << 3) | (1 << 6), &rtc->osc);

or

  writel((1 << 3) | (1 << 6), &rtc->osc);

I can read different values from Linux:

root@letux:~# devmem2 0x44E3E054
/dev/mem opened.
Memory mapped at address 0xb6fba000.
Value at address 0x44E3E054 (0xb6fba054): 0x40
root@letux:~#

or

root@letux:~# devmem2 0x44E3E054
/dev/mem opened.
Memory mapped at address 0xb6f77000.
Value at address 0x44E3E054 (0xb6f77054): 0x48
root@letux:~#

But it has no influence on the "poweroff" behaviour. In either case reboot does not
shut down the PMIC like pressing the power button 10 seconds.

Maybe I had done something wrong with installing the new MLO and testing.
But now "poweroff" in kernel works with writel((0 << 3) | (1 << 6), &rtc->osc);
in U-Boot.

Did I miss something what your patch is doing in addition to handle the osd3358?

I didn't mention, but
* "reboot" works
* rtcwake -m mem -s 10 fails to wake up (sleeps and there is no activity LED flickering like with poweroff)
* 32kHz XTAL is working and active (even during suspend and in the strange poweroff state)
* oscillator is off after forced poweroff (there is no backup battery connected)

Suspend seems to be a deeper sleep state than power off?

Interestingly, hwclock -r stalls for 10 seconds, reports 00:00:57 (or similar after cold boot)
and does not increment. I can write the hwclock but it still does not increment.

So for some reason the RTC isn't running but can be accessed.

This seems to be a separate issue.

BR and thanks,
Nikolaus