Skip to content

Commit 4744d13

Browse files
AlessandroLuokartben
authored andcommitted
drivers: ambiq: Change the way to power on ambiq drivers
This commit changes to use ambiq hal power control APIs to replace the previous register settings to power on ambiq drivers. Signed-off-by: Hao Luo <[email protected]>
1 parent b117036 commit 4744d13

18 files changed

+15
-179
lines changed

drivers/adc/adc_ambiq.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include <zephyr/logging/log.h>
2222
LOG_MODULE_REGISTER(adc_ambiq, CONFIG_ADC_LOG_LEVEL);
2323

24-
typedef int (*ambiq_adc_pwr_func_t)(void);
25-
#define PWRCTRL_MAX_WAIT_US 5
2624
/* Number of slots available. */
2725
#define AMBIQ_ADC_SLOT_NUMBER AM_HAL_ADC_MAX_SLOTS
2826

@@ -32,7 +30,6 @@ struct adc_ambiq_config {
3230
uint8_t num_channels;
3331
void (*irq_config_func)(void);
3432
const struct pinctrl_dev_config *pin_cfg;
35-
ambiq_adc_pwr_func_t pwr_func;
3633
};
3734

3835
struct adc_ambiq_data {
@@ -290,7 +287,7 @@ static int adc_ambiq_init(const struct device *dev)
290287
}
291288

292289
/* power on ADC*/
293-
ret = cfg->pwr_func();
290+
ret = am_hal_adc_power_control(data->adcHandle, AM_HAL_SYSCTRL_WAKE, false);
294291

295292
/* Set up the ADC configuration parameters. These settings are reasonable
296293
* for accurate measurements at a low sample rate.
@@ -404,14 +401,6 @@ static int adc_ambiq_pm_action(const struct device *dev, enum pm_device_action a
404401
#define ADC_AMBIQ_INIT(n) \
405402
PINCTRL_DT_INST_DEFINE(n); \
406403
ADC_AMBIQ_DRIVER_API(n); \
407-
static int pwr_on_ambiq_adc_##n(void) \
408-
{ \
409-
uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
410-
DT_INST_PHA(n, ambiq_pwrcfg, offset); \
411-
sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
412-
k_busy_wait(PWRCTRL_MAX_WAIT_US); \
413-
return 0; \
414-
} \
415404
static void adc_irq_config_func_##n(void) \
416405
{ \
417406
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), adc_ambiq_isr, \
@@ -429,7 +418,6 @@ static int adc_ambiq_pm_action(const struct device *dev, enum pm_device_action a
429418
.num_channels = DT_PROP(DT_DRV_INST(n), channel_count), \
430419
.irq_config_func = adc_irq_config_func_##n, \
431420
.pin_cfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
432-
.pwr_func = pwr_on_ambiq_adc_##n, \
433421
}; \
434422
PM_DEVICE_DT_INST_DEFINE(n, adc_ambiq_pm_action); \
435423
DEVICE_DT_INST_DEFINE(n, &adc_ambiq_init, PM_DEVICE_DT_INST_GET(n), &adc_ambiq_data_##n, \

drivers/i2c/i2c_ambiq.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343

4444
LOG_MODULE_REGISTER(ambiq_i2c, CONFIG_I2C_LOG_LEVEL);
4545

46-
typedef int (*ambiq_i2c_pwr_func_t)(void);
47-
48-
#define PWRCTRL_MAX_WAIT_US 5
4946
#define I2C_TRANSFER_TIMEOUT_MSEC 500 /* Transfer timeout period */
5047

5148
#include "i2c-priv.h"
@@ -59,7 +56,6 @@ struct i2c_ambiq_config {
5956
int size;
6057
uint32_t bitrate;
6158
const struct pinctrl_dev_config *pcfg;
62-
ambiq_i2c_pwr_func_t pwr_func;
6359
void (*irq_config_func)(void);
6460
};
6561

@@ -420,7 +416,7 @@ static int i2c_ambiq_init(const struct device *dev)
420416
return -ENXIO;
421417
}
422418

423-
ret = config->pwr_func();
419+
ret = am_hal_iom_power_ctrl(data->iom_handler, AM_HAL_SYSCTRL_WAKE, false);
424420

425421
ret |= i2c_ambiq_configure(dev, I2C_MODE_CONTROLLER | bitrate_cfg);
426422
if (ret < 0) {
@@ -492,14 +488,6 @@ static int i2c_ambiq_pm_action(const struct device *dev, enum pm_device_action a
492488

493489
#define AMBIQ_I2C_DEFINE(n) \
494490
PINCTRL_DT_INST_DEFINE(n); \
495-
static int pwr_on_ambiq_i2c_##n(void) \
496-
{ \
497-
uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
498-
DT_INST_PHA(n, ambiq_pwrcfg, offset); \
499-
sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
500-
k_busy_wait(PWRCTRL_MAX_WAIT_US); \
501-
return 0; \
502-
} \
503491
static void i2c_irq_config_func_##n(void) \
504492
{ \
505493
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), i2c_ambiq_isr, \
@@ -517,7 +505,6 @@ static int i2c_ambiq_pm_action(const struct device *dev, enum pm_device_action a
517505
.bitrate = DT_INST_PROP(n, clock_frequency), \
518506
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
519507
.irq_config_func = i2c_irq_config_func_##n, \
520-
.pwr_func = pwr_on_ambiq_i2c_##n, \
521508
IF_ENABLED(CONFIG_I2C_AMBIQ_BUS_RECOVERY, \
522509
(.scl = GPIO_DT_SPEC_INST_GET_OR(n, scl_gpios, {0}),\
523510
.sda = GPIO_DT_SPEC_INST_GET_OR(n, sda_gpios, {0}),)) }; \

drivers/serial/uart_pl011_ambiq.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "uart_pl011_registers.h"
1616
#include <am_mcu_apollo.h>
1717

18-
#define PWRCTRL_MAX_WAIT_US 5
19-
2018
static inline void pl011_ambiq_enable_clk(const struct device *dev)
2119
{
2220
get_uart(dev)->cr |= PL011_CR_AMBIQ_CLKEN;

drivers/spi/spi_ambiq_bleif.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ LOG_MODULE_REGISTER(spi_ambiq_bleif);
2323
#include "spi_context.h"
2424
#include <am_mcu_apollo.h>
2525

26-
#define PWRCTRL_MAX_WAIT_US 5
27-
28-
typedef int (*ambiq_spi_pwr_func_t)(void);
29-
3026
struct spi_ambiq_config {
3127
uint32_t base;
3228
int size;
3329
const struct pinctrl_dev_config *pcfg;
34-
ambiq_spi_pwr_func_t pwr_func;
3530
};
3631

3732
struct spi_ambiq_data {
@@ -190,29 +185,18 @@ static int spi_ambiq_init(const struct device *dev)
190185
return ret;
191186
}
192187

193-
ret = cfg->pwr_func();
194-
195188
return ret;
196189
}
197190

198191
#define AMBIQ_SPI_BLEIF_INIT(n) \
199192
PINCTRL_DT_INST_DEFINE(n); \
200-
static int pwr_on_ambiq_spi_##n(void) \
201-
{ \
202-
uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
203-
DT_INST_PHA(n, ambiq_pwrcfg, offset); \
204-
sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
205-
k_busy_wait(PWRCTRL_MAX_WAIT_US); \
206-
return 0; \
207-
} \
208193
static struct spi_ambiq_data spi_ambiq_data##n = { \
209194
SPI_CONTEXT_INIT_LOCK(spi_ambiq_data##n, ctx), \
210195
SPI_CONTEXT_INIT_SYNC(spi_ambiq_data##n, ctx)}; \
211196
static const struct spi_ambiq_config spi_ambiq_config##n = { \
212197
.base = DT_INST_REG_ADDR(n), \
213198
.size = DT_INST_REG_SIZE(n), \
214-
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
215-
.pwr_func = pwr_on_ambiq_spi_##n}; \
199+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n)}; \
216200
SPI_DEVICE_DT_INST_DEFINE(n, spi_ambiq_init, NULL, &spi_ambiq_data##n, \
217201
&spi_ambiq_config##n, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
218202
&spi_ambiq_driver_api);

drivers/spi/spi_ambiq_spic.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ LOG_MODULE_REGISTER(spi_ambiq);
4141
#define SPI_AMBIQ_MANUAL_CACHE_COHERENCY_REQUIRED 0
4242
#endif /* defined(CONFIG_DCACHE) && !defined(CONFIG_NOCACHE_MEMORY) */
4343

44-
#define PWRCTRL_MAX_WAIT_US 5
45-
46-
typedef int (*ambiq_spi_pwr_func_t)(void);
47-
4844
struct spi_ambiq_config {
4945
uint32_t base;
5046
int size;
5147
uint32_t clock_freq;
5248
const struct pinctrl_dev_config *pcfg;
53-
ambiq_spi_pwr_func_t pwr_func;
5449
void (*irq_config_func)(void);
5550
};
5651

@@ -517,7 +512,7 @@ static int spi_ambiq_init(const struct device *dev)
517512
return -ENXIO;
518513
}
519514

520-
ret = cfg->pwr_func();
515+
ret = am_hal_iom_power_ctrl(data->iom_handler, AM_HAL_SYSCTRL_WAKE, false);
521516

522517
ret |= pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
523518
ret |= spi_context_cs_configure_all(&data->ctx);
@@ -571,14 +566,6 @@ static int spi_ambiq_pm_action(const struct device *dev, enum pm_device_action a
571566

572567
#define AMBIQ_SPI_INIT(n) \
573568
PINCTRL_DT_INST_DEFINE(n); \
574-
static int pwr_on_ambiq_spi_##n(void) \
575-
{ \
576-
uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
577-
DT_INST_PHA(n, ambiq_pwrcfg, offset); \
578-
sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
579-
k_busy_wait(PWRCTRL_MAX_WAIT_US); \
580-
return 0; \
581-
} \
582569
static void spi_irq_config_func_##n(void) \
583570
{ \
584571
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), spi_ambiq_isr, \
@@ -594,8 +581,7 @@ static int spi_ambiq_pm_action(const struct device *dev, enum pm_device_action a
594581
.size = DT_INST_REG_SIZE(n), \
595582
.clock_freq = DT_INST_PROP(n, clock_frequency), \
596583
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
597-
.irq_config_func = spi_irq_config_func_##n, \
598-
.pwr_func = pwr_on_ambiq_spi_##n}; \
584+
.irq_config_func = spi_irq_config_func_##n}; \
599585
PM_DEVICE_DT_INST_DEFINE(n, spi_ambiq_pm_action); \
600586
SPI_DEVICE_DT_INST_DEFINE(n, spi_ambiq_init, PM_DEVICE_DT_INST_GET(n), &spi_ambiq_data##n, \
601587
&spi_ambiq_config##n, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \

drivers/spi/spi_ambiq_spid.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,11 @@ LOG_MODULE_REGISTER(spi_ambiq_spid);
2222
#include "spi_context.h"
2323
#include <am_mcu_apollo.h>
2424

25-
#define AMBIQ_SPID_PWRCTRL_MAX_WAIT_US 5
26-
27-
typedef int (*ambiq_spi_pwr_func_t)(void);
28-
2925
struct spi_ambiq_config {
3026
const struct gpio_dt_spec int_gpios;
3127
uint32_t base;
3228
int size;
3329
const struct pinctrl_dev_config *pcfg;
34-
ambiq_spi_pwr_func_t pwr_func;
3530
void (*irq_config_func)(void);
3631
};
3732

@@ -342,7 +337,7 @@ static int spi_ambiq_init(const struct device *dev)
342337
return -ENXIO;
343338
}
344339

345-
ret = cfg->pwr_func();
340+
ret = am_hal_ios_power_ctrl(data->ios_handler, AM_HAL_SYSCTRL_WAKE, false);
346341

347342
ret |= pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
348343
if (ret < 0) {
@@ -396,14 +391,6 @@ static int spi_ambiq_pm_action(const struct device *dev, enum pm_device_action a
396391

397392
#define AMBIQ_SPID_INIT(n) \
398393
PINCTRL_DT_INST_DEFINE(n); \
399-
static int pwr_on_ambiq_spi_##n(void) \
400-
{ \
401-
uint32_t addr = DT_REG_ADDR(DT_INST_PHANDLE(n, ambiq_pwrcfg)) + \
402-
DT_INST_PHA(n, ambiq_pwrcfg, offset); \
403-
sys_write32((sys_read32(addr) | DT_INST_PHA(n, ambiq_pwrcfg, mask)), addr); \
404-
k_busy_wait(AMBIQ_SPID_PWRCTRL_MAX_WAIT_US); \
405-
return 0; \
406-
} \
407394
static void spi_irq_config_func_##n(void) \
408395
{ \
409396
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), spi_ambiq_isr, \
@@ -420,8 +407,7 @@ static int spi_ambiq_pm_action(const struct device *dev, enum pm_device_action a
420407
.base = DT_INST_REG_ADDR(n), \
421408
.size = DT_INST_REG_SIZE(n), \
422409
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
423-
.irq_config_func = spi_irq_config_func_##n, \
424-
.pwr_func = pwr_on_ambiq_spi_##n}; \
410+
.irq_config_func = spi_irq_config_func_##n}; \
425411
PM_DEVICE_DT_INST_DEFINE(n, spi_ambiq_pm_action); \
426412
SPI_DEVICE_DT_INST_DEFINE(n, spi_ambiq_init, PM_DEVICE_DT_INST_GET(n), &spi_ambiq_data##n, \
427413
&spi_ambiq_config##n, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \

dts/arm/ambiq/ambiq_apollo3_blue.dtsi

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@
204204
#size-cells = <0>;
205205
interrupts = <4 0>;
206206
status = "disabled";
207-
ambiq,pwrcfg = <&pwrcfg 0x8 0>;
208207
zephyr,pm-device-runtime-auto;
209208
};
210209

@@ -215,7 +214,6 @@
215214
#size-cells = <0>;
216215
interrupts = <6 0>;
217216
status = "disabled";
218-
ambiq,pwrcfg = <&pwrcfg 0x8 0x2>;
219217
zephyr,pm-device-runtime-auto;
220218
};
221219

@@ -226,7 +224,6 @@
226224
#size-cells = <0>;
227225
interrupts = <7 0>;
228226
status = "disabled";
229-
ambiq,pwrcfg = <&pwrcfg 0x8 0x4>;
230227
zephyr,pm-device-runtime-auto;
231228
};
232229

@@ -237,7 +234,6 @@
237234
#size-cells = <0>;
238235
interrupts = <8 0>;
239236
status = "disabled";
240-
ambiq,pwrcfg = <&pwrcfg 0x8 0x8>;
241237
zephyr,pm-device-runtime-auto;
242238
};
243239

@@ -248,7 +244,6 @@
248244
#size-cells = <0>;
249245
interrupts = <9 0>;
250246
status = "disabled";
251-
ambiq,pwrcfg = <&pwrcfg 0x8 0x10>;
252247
zephyr,pm-device-runtime-auto;
253248
};
254249

@@ -259,7 +254,6 @@
259254
#size-cells = <0>;
260255
interrupts = <10 0>;
261256
status = "disabled";
262-
ambiq,pwrcfg = <&pwrcfg 0x8 0x20>;
263257
zephyr,pm-device-runtime-auto;
264258
};
265259

@@ -270,7 +264,6 @@
270264
#size-cells = <0>;
271265
interrupts = <11 0>;
272266
status = "disabled";
273-
ambiq,pwrcfg = <&pwrcfg 0x8 0x40>;
274267
zephyr,pm-device-runtime-auto;
275268
};
276269

@@ -281,7 +274,6 @@
281274
#size-cells = <0>;
282275
interrupts = <6 0>;
283276
status = "disabled";
284-
ambiq,pwrcfg = <&pwrcfg 0x8 0x2>;
285277
zephyr,pm-device-runtime-auto;
286278
};
287279

@@ -292,7 +284,6 @@
292284
#size-cells = <0>;
293285
interrupts = <7 0>;
294286
status = "disabled";
295-
ambiq,pwrcfg = <&pwrcfg 0x8 0x4>;
296287
zephyr,pm-device-runtime-auto;
297288
};
298289

@@ -303,7 +294,6 @@
303294
#size-cells = <0>;
304295
interrupts = <8 0>;
305296
status = "disabled";
306-
ambiq,pwrcfg = <&pwrcfg 0x8 0x8>;
307297
zephyr,pm-device-runtime-auto;
308298
};
309299

@@ -314,7 +304,6 @@
314304
#size-cells = <0>;
315305
interrupts = <9 0>;
316306
status = "disabled";
317-
ambiq,pwrcfg = <&pwrcfg 0x8 0x10>;
318307
zephyr,pm-device-runtime-auto;
319308
};
320309

@@ -325,7 +314,6 @@
325314
#size-cells = <0>;
326315
interrupts = <10 0>;
327316
status = "disabled";
328-
ambiq,pwrcfg = <&pwrcfg 0x8 0x20>;
329317
zephyr,pm-device-runtime-auto;
330318
};
331319

@@ -336,7 +324,6 @@
336324
#size-cells = <0>;
337325
interrupts = <11 0>;
338326
status = "disabled";
339-
ambiq,pwrcfg = <&pwrcfg 0x8 0x40>;
340327
zephyr,pm-device-runtime-auto;
341328
};
342329

@@ -349,7 +336,6 @@
349336
internal-vref-mv = <1500>;
350337
status = "disabled";
351338
#io-channel-cells = <1>;
352-
ambiq,pwrcfg = <&pwrcfg 0x8 0x200>;
353339
};
354340

355341
mspi0: spi@40020000 {
@@ -359,7 +345,6 @@
359345
#address-cells = <1>;
360346
#size-cells = <0>;
361347
status = "disabled";
362-
ambiq,pwrcfg = <&pwrcfg 0x8 0x800>;
363348
};
364349

365350
rtc0: rtc@40004240 {
@@ -377,7 +362,6 @@
377362
#address-cells = <1>;
378363
#size-cells = <0>;
379364
status = "disabled";
380-
ambiq,pwrcfg = <&pwrcfg 0x8 0x8000>;
381365

382366
bt_hci_apollo: bt-hci@0 {
383367
compatible = "ambiq,bt-hci-spi";

0 commit comments

Comments
 (0)