xiaoxiang781216 commented on code in PR #20491:
URL: https://github.com/apache/nuttx/pull/20491#discussion_r4214594070
##########
arch/arm/src/rp23xx/rp23xx_serial.c:
##########
@@ -609,6 +613,14 @@ static int up_interrupt(int irq, void *context, void *arg)
if (status & (RP23XX_UART_UARTICR_RXIC | RP23XX_UART_UARTICR_RTIC))
{
+#ifdef CONFIG_RP23XX_PM
+ /* The dormant state stops the UART: stay out of it while input
+ * arrives.
+ */
+
+ rp23xx_pm_hold(CONFIG_RP23XX_PM_WAKE_HOLD_MS);
Review Comment:
why not call pm_staytimeout
##########
arch/arm/src/rp23xx/rp23xx_pminitialize.c:
##########
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * arch/arm/src/rp23xx/rp23xx_pminitialize.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/power/pm.h>
+
+#include "arm_internal.h"
+#include "rp23xx_pm.h"
+
+#ifdef CONFIG_PM
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm_pminitialize
+ *
+ * Description:
+ * This function is called by MCU-specific logic at power-on reset in
+ * order to provide one-time initialization the power management
+ * subsystem. This function must be called *very* early in the
+ * initialization sequence *before* any other device drivers are
+ * initialized (since they may attempt to register with the power
+ * management subsystem).
+ *
+ ****************************************************************************/
+
+void arm_pminitialize(void)
+{
+ /* Initialize the NuttX power management subsystem proper */
+
+ pm_initialize();
+
+#if defined(CONFIG_RP23XX_PM) && CONFIG_RP23XX_PM_WAKEUP_GPIO >= 0
+ /* Arm the wake pin, without which PM_SLEEP is never dormant */
+
+# ifdef CONFIG_RP23XX_PM_WAKEUP_GPIO_HIGH
Review Comment:
move to predefined section
##########
arch/arm/src/rp23xx/rp23xx_pm.c:
##########
@@ -0,0 +1,837 @@
+/****************************************************************************
+ * arch/arm/src/rp23xx/rp23xx_pm.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include <arch/board/board.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+
+#include "arm_internal.h"
+#include "nvic.h"
+
+#include "rp23xx_pm.h"
+#include "rp23xx_gpio.h"
+#include "rp23xx_pll.h"
+
+#include "hardware/rp23xx_clocks.h"
+#include "hardware/rp23xx_powman.h"
+#include "hardware/rp23xx_xosc.h"
+#include "hardware/rp23xx_pll.h"
+#include "hardware/rp23xx_pads_bank0.h"
+#include "hardware/rp23xx_io_bank0.h"
+#include "hardware/rp23xx_memorymap.h"
+#include "hardware/rp23xx_uart.h"
+#include "hardware/rp23xx_resets.h"
+
+#ifdef CONFIG_RP23XX_PM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* No flash fetch works while the crystal oscillator is stopped, so the
+ * dormant sequence runs from RAM (.time_critical).
+ */
+
+#define RP23XX_PM_RAMFUNC \
+ __attribute__((section(".time_critical.rp23xx_pm"), noinline))
+
+/* POWMAN ignores a write without this password in the top 16 bits */
+
+#define POWMAN_PASSWORD 0x5afe0000
+
+/* Atomic set/clear aliases of a bus register (RP2350 memory map). */
+
+#define POWMAN_SET_ALIAS 0x2000
+#define POWMAN_CLR_ALIAS 0x3000
+
+/* Clocks that keep running through a PM_STANDBY WFI. SLEEP_EN0/1 use the
+ * bits of WAKE_EN0/1. Only blocks with no driver in the configuration are
+ * gated: the rp23xx drivers have no PM callbacks to say they are idle.
+ */
+
+#define RP23XX_PM_SLEEP_EN0_BASE \
+ (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_CLOCKS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ACCESSCTRL | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BOOTRAM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BUSCTRL | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BUSFABRIC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_IO | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PADS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PLL_SYS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_REF_POWMAN | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_POWMAN | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PSM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_RESETS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ROM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ROSC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_SIO)
+
+#define RP23XX_PM_SLEEP_EN1_BASE \
+ (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM2 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM3 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM4 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM5 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM6 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM7 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM8 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM9 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SYSCFG | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SYSINFO | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TBMAN | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_REF_TICKS | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TICKS | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_WATCHDOG | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_XIP | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_XOSC)
+
+/* Optional blocks, kept only when their driver is configured. */
+
+#ifdef CONFIG_RP23XX_ADC
+# define RP23XX_PM_EN0_ADC (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ADC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_ADC_ADC)
+#else
+# define RP23XX_PM_EN0_ADC 0
+#endif
+
+#ifdef CONFIG_RP23XX_DMAC
+# define RP23XX_PM_EN0_DMA RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_DMA
+#else
+# define RP23XX_PM_EN0_DMA 0
+#endif
+
+#ifdef CONFIG_RP23XX_I2C0
+# define RP23XX_PM_EN0_I2C0 RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_I2C0
+#else
+# define RP23XX_PM_EN0_I2C0 0
+#endif
+
+#ifdef CONFIG_RP23XX_I2C1
+# define RP23XX_PM_EN0_I2C1 RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_I2C1
+#else
+# define RP23XX_PM_EN0_I2C1 0
+#endif
+
+#ifdef CONFIG_RP23XX_PWM
+# define RP23XX_PM_EN0_PWM RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PWM
+#else
+# define RP23XX_PM_EN0_PWM 0
+#endif
+
+#ifdef CONFIG_RP23XX_OTP
+# define RP23XX_PM_EN0_OTP (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_OTP | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_REF_OTP)
+#else
+# define RP23XX_PM_EN0_OTP 0
+#endif
+
+#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE
+# define RP23XX_PM_EN0_SHA RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_SHA256
+#else
+# define RP23XX_PM_EN0_SHA 0
+#endif
+
+/* The PIO blocks are shared by several drivers */
+
+#if defined(CONFIG_RP23XX_I2S) || defined(CONFIG_WS2812) || \
+ defined(CONFIG_IEEE80211_INFINEON_CYW43439)
+# define RP23XX_PM_EN0_PIO (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO0 | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO1 | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO2)
+#else
+# define RP23XX_PM_EN0_PIO 0
+#endif
+
+#ifdef CONFIG_USBDEV
+# define RP23XX_PM_EN0_USB RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PLL_USB
+# define RP23XX_PM_EN1_USB (RP23XX_CLOCKS_WAKE_EN1_CLK_USB | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_USBCTRL)
+#else
+# define RP23XX_PM_EN0_USB 0
+# define RP23XX_PM_EN1_USB 0
+#endif
+
+#ifdef CONFIG_RP23XX_UART0
+# define RP23XX_PM_EN1_UART0 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_UART0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_UART0)
+#else
+# define RP23XX_PM_EN1_UART0 0
+#endif
+
+#ifdef CONFIG_RP23XX_UART1
+# define RP23XX_PM_EN1_UART1 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_UART1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_UART1)
+#else
+# define RP23XX_PM_EN1_UART1 0
+#endif
+
+#ifdef CONFIG_RP23XX_SPI0
+# define RP23XX_PM_EN1_SPI0 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SPI0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_SPI0)
+#else
+# define RP23XX_PM_EN1_SPI0 0
+#endif
+
+#ifdef CONFIG_RP23XX_SPI1
+# define RP23XX_PM_EN1_SPI1 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SPI1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_SPI1)
+#else
+# define RP23XX_PM_EN1_SPI1 0
+#endif
+
+#ifdef CONFIG_RP23XX_RNG
+# define RP23XX_PM_EN1_TRNG RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TRNG
+#else
+# define RP23XX_PM_EN1_TRNG 0
+#endif
+
+#ifdef CONFIG_RP23XX_TIMER0
+# define RP23XX_PM_EN1_TIMER0 RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER0
+#else
+# define RP23XX_PM_EN1_TIMER0 0
+#endif
+
+#ifdef CONFIG_RP23XX_TIMER1
+# define RP23XX_PM_EN1_TIMER1 RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER1
+#else
+# define RP23XX_PM_EN1_TIMER1 0
+#endif
+
+/* The timer block that the tickless scheduler uses */
+
+#if defined(CONFIG_RP23XX_SYSTIMER_TICKLESS_TIMER0)
+# define RP23XX_PM_EN1_SYSTIMER RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER0
+#elif defined(CONFIG_RP23XX_SYSTIMER_TICKLESS_TIMER1)
+# define RP23XX_PM_EN1_SYSTIMER RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER1
+#else
+# define RP23XX_PM_EN1_SYSTIMER 0
+#endif
+
+#define RP23XX_PM_SLEEP_EN0 \
+ (RP23XX_PM_SLEEP_EN0_BASE | RP23XX_PM_EN0_ADC | RP23XX_PM_EN0_DMA | \
+ RP23XX_PM_EN0_I2C0 | RP23XX_PM_EN0_I2C1 | RP23XX_PM_EN0_PWM | \
+ RP23XX_PM_EN0_OTP | RP23XX_PM_EN0_SHA | RP23XX_PM_EN0_PIO | \
+ RP23XX_PM_EN0_USB)
+
+#define RP23XX_PM_SLEEP_EN1 \
+ (RP23XX_PM_SLEEP_EN1_BASE | RP23XX_PM_EN1_USB | \
+ RP23XX_PM_EN1_UART0 | RP23XX_PM_EN1_UART1 | \
+ RP23XX_PM_EN1_SPI0 | RP23XX_PM_EN1_SPI1 | \
+ RP23XX_PM_EN1_TRNG | RP23XX_PM_EN1_TIMER0 | \
+ RP23XX_PM_EN1_TIMER1 | RP23XX_PM_EN1_SYSTIMER)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* GPIOs armed in the dormant-wake detector. With none, no dormant state */
+
+static uint64_t g_pm_wakeup_gpios;
+
+/* No dormant state for g_pm_hold_ms after g_pm_hold_start (always-on
+ * timer milliseconds).
+ */
+
+static uint64_t g_pm_hold_start;
Review Comment:
why not reuse the common wake lock logic in pm
##########
arch/arm/src/rp23xx/rp23xx_pm.c:
##########
@@ -0,0 +1,837 @@
+/****************************************************************************
+ * arch/arm/src/rp23xx/rp23xx_pm.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include <arch/board/board.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+
+#include "arm_internal.h"
+#include "nvic.h"
+
+#include "rp23xx_pm.h"
+#include "rp23xx_gpio.h"
+#include "rp23xx_pll.h"
+
+#include "hardware/rp23xx_clocks.h"
+#include "hardware/rp23xx_powman.h"
+#include "hardware/rp23xx_xosc.h"
+#include "hardware/rp23xx_pll.h"
+#include "hardware/rp23xx_pads_bank0.h"
+#include "hardware/rp23xx_io_bank0.h"
+#include "hardware/rp23xx_memorymap.h"
+#include "hardware/rp23xx_uart.h"
+#include "hardware/rp23xx_resets.h"
+
+#ifdef CONFIG_RP23XX_PM
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* No flash fetch works while the crystal oscillator is stopped, so the
+ * dormant sequence runs from RAM (.time_critical).
+ */
+
+#define RP23XX_PM_RAMFUNC \
+ __attribute__((section(".time_critical.rp23xx_pm"), noinline))
+
+/* POWMAN ignores a write without this password in the top 16 bits */
+
+#define POWMAN_PASSWORD 0x5afe0000
+
+/* Atomic set/clear aliases of a bus register (RP2350 memory map). */
+
+#define POWMAN_SET_ALIAS 0x2000
+#define POWMAN_CLR_ALIAS 0x3000
+
+/* Clocks that keep running through a PM_STANDBY WFI. SLEEP_EN0/1 use the
+ * bits of WAKE_EN0/1. Only blocks with no driver in the configuration are
+ * gated: the rp23xx drivers have no PM callbacks to say they are idle.
+ */
+
+#define RP23XX_PM_SLEEP_EN0_BASE \
+ (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_CLOCKS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ACCESSCTRL | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BOOTRAM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BUSCTRL | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_BUSFABRIC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_IO | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PADS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PLL_SYS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_REF_POWMAN | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_POWMAN | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PSM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_RESETS | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ROM | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ROSC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_SIO)
+
+#define RP23XX_PM_SLEEP_EN1_BASE \
+ (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM2 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM3 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM4 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM5 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM6 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM7 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM8 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SRAM9 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SYSCFG | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SYSINFO | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TBMAN | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_REF_TICKS | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TICKS | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_WATCHDOG | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_XIP | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_XOSC)
+
+/* Optional blocks, kept only when their driver is configured. */
+
+#ifdef CONFIG_RP23XX_ADC
+# define RP23XX_PM_EN0_ADC (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_ADC | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_ADC_ADC)
+#else
+# define RP23XX_PM_EN0_ADC 0
+#endif
+
+#ifdef CONFIG_RP23XX_DMAC
+# define RP23XX_PM_EN0_DMA RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_DMA
+#else
+# define RP23XX_PM_EN0_DMA 0
+#endif
+
+#ifdef CONFIG_RP23XX_I2C0
+# define RP23XX_PM_EN0_I2C0 RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_I2C0
+#else
+# define RP23XX_PM_EN0_I2C0 0
+#endif
+
+#ifdef CONFIG_RP23XX_I2C1
+# define RP23XX_PM_EN0_I2C1 RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_I2C1
+#else
+# define RP23XX_PM_EN0_I2C1 0
+#endif
+
+#ifdef CONFIG_RP23XX_PWM
+# define RP23XX_PM_EN0_PWM RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PWM
+#else
+# define RP23XX_PM_EN0_PWM 0
+#endif
+
+#ifdef CONFIG_RP23XX_OTP
+# define RP23XX_PM_EN0_OTP (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_OTP | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_REF_OTP)
+#else
+# define RP23XX_PM_EN0_OTP 0
+#endif
+
+#ifdef CONFIG_CRYPTO_CRYPTODEV_HARDWARE
+# define RP23XX_PM_EN0_SHA RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_SHA256
+#else
+# define RP23XX_PM_EN0_SHA 0
+#endif
+
+/* The PIO blocks are shared by several drivers */
+
+#if defined(CONFIG_RP23XX_I2S) || defined(CONFIG_WS2812) || \
+ defined(CONFIG_IEEE80211_INFINEON_CYW43439)
+# define RP23XX_PM_EN0_PIO (RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO0 | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO1 | \
+ RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PIO2)
+#else
+# define RP23XX_PM_EN0_PIO 0
+#endif
+
+#ifdef CONFIG_USBDEV
+# define RP23XX_PM_EN0_USB RP23XX_CLOCKS_WAKE_EN0_CLK_SYS_PLL_USB
+# define RP23XX_PM_EN1_USB (RP23XX_CLOCKS_WAKE_EN1_CLK_USB | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_USBCTRL)
+#else
+# define RP23XX_PM_EN0_USB 0
+# define RP23XX_PM_EN1_USB 0
+#endif
+
+#ifdef CONFIG_RP23XX_UART0
+# define RP23XX_PM_EN1_UART0 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_UART0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_UART0)
+#else
+# define RP23XX_PM_EN1_UART0 0
+#endif
+
+#ifdef CONFIG_RP23XX_UART1
+# define RP23XX_PM_EN1_UART1 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_UART1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_UART1)
+#else
+# define RP23XX_PM_EN1_UART1 0
+#endif
+
+#ifdef CONFIG_RP23XX_SPI0
+# define RP23XX_PM_EN1_SPI0 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SPI0 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_SPI0)
+#else
+# define RP23XX_PM_EN1_SPI0 0
+#endif
+
+#ifdef CONFIG_RP23XX_SPI1
+# define RP23XX_PM_EN1_SPI1 (RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_SPI1 | \
+ RP23XX_CLOCKS_WAKE_EN1_CLK_PERI_SPI1)
+#else
+# define RP23XX_PM_EN1_SPI1 0
+#endif
+
+#ifdef CONFIG_RP23XX_RNG
+# define RP23XX_PM_EN1_TRNG RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TRNG
+#else
+# define RP23XX_PM_EN1_TRNG 0
+#endif
+
+#ifdef CONFIG_RP23XX_TIMER0
+# define RP23XX_PM_EN1_TIMER0 RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER0
+#else
+# define RP23XX_PM_EN1_TIMER0 0
+#endif
+
+#ifdef CONFIG_RP23XX_TIMER1
+# define RP23XX_PM_EN1_TIMER1 RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER1
+#else
+# define RP23XX_PM_EN1_TIMER1 0
+#endif
+
+/* The timer block that the tickless scheduler uses */
+
+#if defined(CONFIG_RP23XX_SYSTIMER_TICKLESS_TIMER0)
+# define RP23XX_PM_EN1_SYSTIMER RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER0
+#elif defined(CONFIG_RP23XX_SYSTIMER_TICKLESS_TIMER1)
+# define RP23XX_PM_EN1_SYSTIMER RP23XX_CLOCKS_WAKE_EN1_CLK_SYS_TIMER1
+#else
+# define RP23XX_PM_EN1_SYSTIMER 0
+#endif
+
+#define RP23XX_PM_SLEEP_EN0 \
+ (RP23XX_PM_SLEEP_EN0_BASE | RP23XX_PM_EN0_ADC | RP23XX_PM_EN0_DMA | \
+ RP23XX_PM_EN0_I2C0 | RP23XX_PM_EN0_I2C1 | RP23XX_PM_EN0_PWM | \
+ RP23XX_PM_EN0_OTP | RP23XX_PM_EN0_SHA | RP23XX_PM_EN0_PIO | \
+ RP23XX_PM_EN0_USB)
+
+#define RP23XX_PM_SLEEP_EN1 \
+ (RP23XX_PM_SLEEP_EN1_BASE | RP23XX_PM_EN1_USB | \
+ RP23XX_PM_EN1_UART0 | RP23XX_PM_EN1_UART1 | \
+ RP23XX_PM_EN1_SPI0 | RP23XX_PM_EN1_SPI1 | \
+ RP23XX_PM_EN1_TRNG | RP23XX_PM_EN1_TIMER0 | \
+ RP23XX_PM_EN1_TIMER1 | RP23XX_PM_EN1_SYSTIMER)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* GPIOs armed in the dormant-wake detector. With none, no dormant state */
+
+static uint64_t g_pm_wakeup_gpios;
+
+/* No dormant state for g_pm_hold_ms after g_pm_hold_start (always-on
+ * timer milliseconds).
+ */
+
+static uint64_t g_pm_hold_start;
+static uint32_t g_pm_hold_ms;
+
+/* Set by the wake interrupt */
+
+static volatile bool g_pm_woken;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static inline void powman_setbits(uint32_t reg, uint32_t bits)
+{
+ putreg32(POWMAN_PASSWORD | bits, reg + POWMAN_SET_ALIAS);
+}
+
+static inline void powman_clrbits(uint32_t reg, uint32_t bits)
+{
+ putreg32(POWMAN_PASSWORD | bits, reg + POWMAN_CLR_ALIAS);
+}
+
+/****************************************************************************
+ * Name: rp23xx_pm_time_ms
+ *
+ * Description:
+ * Read the always-on timer. It runs in every state, unlike the system
+ * tick.
+ *
+ ****************************************************************************/
+
+static uint64_t rp23xx_pm_time_ms(void)
+{
+ uint32_t upper;
+ uint32_t lower;
+
+ do
+ {
+ upper = getreg32(RP23XX_POWMAN_READ_TIME_UPPER);
+ lower = getreg32(RP23XX_POWMAN_READ_TIME_LOWER);
+ }
+ while (upper != getreg32(RP23XX_POWMAN_READ_TIME_UPPER));
+
+ return ((uint64_t)upper << 32) | lower;
+}
+
+/****************************************************************************
+ * Name: rp23xx_pm_wake_irq
+ *
+ * Description:
+ * One-shot interrupt of a wake GPIO. The dormant-wake edge stays in the
+ * INTR latch, so this interrupt ends the WFI of the dormant state as soon
+ * as the crystal oscillator runs again.
+ *
+ ****************************************************************************/
+
+static int rp23xx_pm_wake_irq(int irq, FAR void *context, FAR void *arg)
+{
+ rp23xx_gpio_disable_irq(irq);
+ g_pm_woken = true;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: rp23xx_pm_held
+ *
+ * Description:
+ * True while a hold from rp23xx_pm_hold() runs. Setting the clock back
+ * ends it.
+ *
+ ****************************************************************************/
+
+static bool rp23xx_pm_held(void)
+{
+ uint64_t now = rp23xx_pm_time_ms();
+
+ return now >= g_pm_hold_start && now - g_pm_hold_start < g_pm_hold_ms;
+}
+
+/****************************************************************************
+ * Name: rp23xx_pm_uart_busy
+ *
+ * Description:
+ * True while a UART still transmits. The dormant state stops clk_peri,
+ * which would hold a transmit until the next wake.
+ *
+ ****************************************************************************/
+
+static bool rp23xx_pm_uart_busy(void)
Review Comment:
should change to pm_callback_s::prepare
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]