@@ -168,48 +168,18 @@ static int uart_ambiq_pm_action(const struct device *dev, enum pm_device_action
168
168
}
169
169
#endif /* CONFIG_PM_DEVICE */
170
170
171
- /* Problem: writes to power configure register takes some time to take effective.
172
- * Solution: Check device's power status to ensure that register has taken effective.
173
- * Note: busy wait is not allowed to use here due to UART is initiated before timer starts.
174
- */
175
- #if defined(CONFIG_SOC_SERIES_APOLLO3X )
176
- #define DEVPWRSTATUS_OFFSET 0x10
177
- #define HCPA_MASK 0x4
178
171
#define AMBIQ_UART_DEFINE (n ) \
179
172
PM_DEVICE_DT_INST_DEFINE(n, uart_ambiq_pm_action); \
180
173
static int pwr_on_ambiq_uart_##n(void) \
181
174
{ \
182
- uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
183
- DT_INST_PHA(n, ambiq_pwrcfg, offset); \
184
- uint32_t pwr_status_addr = addr + DEVPWRSTATUS_OFFSET; \
185
- sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
186
- while (!(sys_read32(pwr_status_addr) & HCPA_MASK)) { \
187
- }; \
188
- return 0; \
175
+ uint32_t module = (DT_INST_REG_ADDR(n) - UART0_BASE) / (UART1_BASE - UART0_BASE); \
176
+ am_hal_pwrctrl_periph_e eUARTPowerModule = \
177
+ ((am_hal_pwrctrl_periph_e)(AM_HAL_PWRCTRL_PERIPH_UART0 + module)); \
178
+ return am_hal_pwrctrl_periph_enable(eUARTPowerModule); \
189
179
} \
190
180
static inline int clk_enable_ambiq_uart_##n(const struct device *dev, uint32_t clk) \
191
181
{ \
192
182
return clk_enable_ambiq_uart(dev, clk); \
193
183
}
194
- #else
195
- #define DEVPWRSTATUS_OFFSET 0x4
196
- #define AMBIQ_UART_DEFINE (n ) \
197
- PM_DEVICE_DT_INST_DEFINE(n, uart_ambiq_pm_action); \
198
- static int pwr_on_ambiq_uart_##n(void) \
199
- { \
200
- uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
201
- DT_INST_PHA(n, ambiq_pwrcfg, offset); \
202
- uint32_t pwr_status_addr = addr + DEVPWRSTATUS_OFFSET; \
203
- sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
204
- while ((sys_read32(pwr_status_addr) & DT_INST_PHA(n, ambiq_pwrcfg, mask)) != \
205
- DT_INST_PHA(n, ambiq_pwrcfg, mask)) { \
206
- }; \
207
- return 0; \
208
- } \
209
- static inline int clk_enable_ambiq_uart_##n(const struct device *dev, uint32_t clk) \
210
- { \
211
- return clk_enable_ambiq_uart(dev, clk); \
212
- }
213
- #endif
214
184
215
185
#endif /* ZEPHYR_DRIVERS_SERIAL_UART_PL011_AMBIQ_H_ */
0 commit comments