Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: power: sam: Introduce Atmel SAM SUPC, wakeup sources and poweroff implementation #63961

Merged

Conversation

bjarki-andreasen
Copy link
Collaborator

@bjarki-andreasen bjarki-andreasen commented Oct 15, 2023

This PR adds two features required for power off of the atmel sam series chips

  • Driver and DTS entry for SUPC. This component sets up wakeup sources and powers down the core voltage regulator, which is required to go to sleep and wake up again.
  • sys_poweroff implementation required to synchronously enable the wakeup sources using SUPC, and entering deep sleep (backup mode)

@bjarki-andreasen bjarki-andreasen force-pushed the sam4_add_poweroff branch 2 times, most recently from 1c65aca to 2ea4b77 Compare October 15, 2023 18:15
@bjarki-andreasen bjarki-andreasen marked this pull request as ready for review October 15, 2023 22:31
@zephyrbot zephyrbot added the platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) label Oct 15, 2023
gmarull
gmarull previously approved these changes Oct 16, 2023
gmarull
gmarull previously approved these changes Oct 16, 2023
soc/arm/atmel_sam/common/soc_poweroff.c Outdated Show resolved Hide resolved
@bjarki-andreasen
Copy link
Collaborator Author

@nandojve I have created a PR to add missing defines for registers required by this PR and the RTC PR (to avoid some ugly hackery), please review it :)

@bjarki-andreasen bjarki-andreasen force-pushed the sam4_add_poweroff branch 2 times, most recently from 3f1b294 to 5944121 Compare October 19, 2023 22:27
@bjarki-andreasen bjarki-andreasen changed the title Add sys_poweroff implementation for atmel_sam series Add SUPC and sys_poweroff implementation for atmel_sam series Oct 19, 2023
@bjarki-andreasen bjarki-andreasen changed the title Add SUPC and sys_poweroff implementation for atmel_sam series Add SUPC, wakeup sources and poweroff implementation for atmel_sam series Oct 19, 2023
@gmarull
Copy link
Member

gmarull commented Oct 20, 2023

@nandojve @gmarull Using the RTC device as an example, we could then have

rtc: rtc@01010101 {
        ...
        wakeup-source-channel = <&supc SUPC_CHANNEL_RTC_ALARM>;
};

in the .dtsi and

&rtc: {
        ...
        wakeup-source;
        status = "okay";
};

in the overlay :)

lgtm

@nandojve
Copy link
Member

Hi @bjarki-trackunit ,

@nandojve @gmarull Using the RTC device as an example, we could then have

rtc: rtc@01010101 {
        ...
        wakeup-source-channel = <&supc SUPC_CHANNEL_RTC_ALARM>;
};

Let's use supc for now since it have multiple functions and it will be used in more places.

rtc: rtc@01010101 {
        ...
        supc = <&supc SUPC_CHANNEL_RTC_ALARM>;
or
        atmel,supc = <&supc SUPC_CHANNEL_RTC_ALARM>;
};

The below seems to be the correct way to enable the wake-up source.

in the .dtsi and

&rtc: {
        ...
        wakeup-source;
        status = "okay";
};

@bjarki-andreasen
Copy link
Collaborator Author

bjarki-andreasen commented Oct 20, 2023

Let's use supc for now since it have multiple functions and it will be used in more places.

rtc: rtc@01010101 {
        ...
        supc = <&supc SUPC_CHANNEL_RTC_ALARM>;
or
        atmel,supc = <&supc SUPC_CHANNEL_RTC_ALARM>;
};

I might be misunderstanding something. This is a concrete example of using the wakeup-souce-id cell:

.dtsi

supc: supc@400e1810 {
	compatible = "atmel,sam-supc";
	reg = <0x400e1810 0x20>;
	#wakeup-source-id-cells = <1>;
	status = "okay";
};

...

rtc: rtc@400e1860 {
	compatible = "atmel,sam-rtc";
	reg = <0x400e1860 0x100>;
	interrupts = <2 0>;
	clocks = <&pmc PMC_TYPE_PERIPHERAL 2>;
	wakeup-source-ids = <&supc SUPC_WAKEUP_SOURCE_RTC>;
	alarms-count = <1>;
	status = "disabled";
};

.dts

&rtc {
	status = "okay";
	wakeup-source;
};

I don't understand why we would call the #wakeup-source-id-cells supc?

@nandojve
Copy link
Member

Hi @bjarki-trackunit ,

You are right in your approach defining the #wakeup-source-id-cells at supc. Let's use it.


zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_pm.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_gpio.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_poweroff.c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean

-zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_poweroff.c)
+zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_poweroff.c)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#define _ATMEL_SAM_SOC_SUPC_H_

#include <zephyr/types.h>
#include <soc.h>
Copy link
Member

@nandojve nandojve Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include is not necessary.

-#include <soc.h>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@nandojve nandojve changed the title Add SUPC, wakeup sources and poweroff implementation for atmel_sam series drivers: power: sam: Introduce Atmel SAM SUPC, wakeup sources and poweroff implementation Oct 21, 2023
@bjarki-andreasen
Copy link
Collaborator Author

The failing test will succeed once the hal is updated :)

Comment on lines 7 to 8
The supply controller manages wakeup sources and core voltages and
regulators.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supply controller manages the voltage reference, power supply and supply
monitoring of the device. It have a special feature that it can wake-up the
device from a low-power state using special peripherals as wake-up sources.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with your suggestion

Comment on lines 10 to 12
To specify the wakeup source channel used by a peripheral, the custom
property wakeup-source-channel needs to be used, e.g. for the RTC
device:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dedicated peripherals that can wake-up the core supply domain are: RTC,
RTT, Supply Monitor and GPIOs. In the first three peripherals it is necessary
inform the wakeup-source-id property on their respective nodes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with your suggestion

Comment on lines 20 to 22
The device drivers will then use the provided channel to enable its wakeup
if they have been designated as wakeup sources using the standard
wakeup-source property, e.g.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The special peripheral will wake-up the device only when the standard property
wakeup-source is defined, e.g.:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with your suggestion


rtc: rtc@xxx {
...
wakeup-source-id = <&supc SUPC_WAKEUP_SOURCE_RTT>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-      wakeup-source-id = <&supc SUPC_WAKEUP_SOURCE_RTT>;
+      wakeup-source-id = <&supc SUPC_WAKEUP_SOURCE_RTC>;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with your suggestion

@nandojve nandojve added this to the v3.6.0 milestone Oct 23, 2023
@nandojve
Copy link
Member

Hi @bjarki-trackunit ,

I was wondering if you can update this PR to us check if is already passing CI.

Bjarki Arge Andreasen added 3 commits October 23, 2023 20:16
This commit adds a driver and dts model for the ATMEL SAM
SUPC component.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
This commit adds the new SUPC devicetree instance to the
soc dtsi files.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
This commit adds an implementation of poweroff, which first
uses SUPC to enable all defined wakeup sources (except for
sam4l), followed by entering backup mode.

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
@bjarki-andreasen
Copy link
Collaborator Author

@nandojve In progress :)

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok to poweroff changes

@carlescufi carlescufi merged commit 9b21d4d into zephyrproject-rtos:main Oct 24, 2023
18 checks passed
@bjarki-andreasen bjarki-andreasen deleted the sam4_add_poweroff branch October 24, 2023 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants