Skip to content

Commit ae2222f

Browse files
committed
drivers: mfd: Add ambiq iom binding file
This commit adds ambiq iom binding file to consolidate spi and i2c that share the same IO Master module on Apollo MCUs Signed-off-by: Hao Luo <hluo@ambiq.com>
1 parent 2be9a29 commit ae2222f

18 files changed

+620
-540
lines changed

boards/ambiq/apollo3_evb/apollo3_evb.dts

+17-13
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,25 @@
139139
status = "okay";
140140
};
141141

142-
&spi0 {
143-
pinctrl-0 = <&spi0_default>;
144-
pinctrl-names = "default";
145-
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
146-
clock-frequency = <DT_FREQ_M(1)>;
147-
status = "okay";
142+
&iom0 {
143+
spi0: spi {
144+
pinctrl-0 = <&spi0_default>;
145+
pinctrl-names = "default";
146+
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
147+
clock-frequency = <DT_FREQ_M(1)>;
148+
status = "okay";
149+
};
148150
};
149151

150-
&i2c3 {
151-
pinctrl-0 = <&i2c3_default>;
152-
pinctrl-names = "default";
153-
clock-frequency = <I2C_BITRATE_STANDARD>;
154-
scl-gpios = <&gpio32_63 10 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
155-
sda-gpios = <&gpio32_63 11 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
156-
status = "okay";
152+
&iom3 {
153+
i2c3: i2c {
154+
pinctrl-0 = <&i2c3_default>;
155+
pinctrl-names = "default";
156+
clock-frequency = <I2C_BITRATE_STANDARD>;
157+
scl-gpios = <&gpio32_63 10 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
158+
sda-gpios = <&gpio32_63 11 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
159+
status = "okay";
160+
};
157161
};
158162

159163
&counter0 {

boards/ambiq/apollo3_evb/apollo3_evb_connector.dtsi

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@
6363
};
6464
};
6565

66-
ambiq_spi0: &spi0 {};
67-
ambiq_i2c3: &i2c3 {};
66+
ambiq_spi0: &iom0 {};
67+
ambiq_i2c3: &iom3 {};

boards/ambiq/apollo3p_evb/apollo3p_evb.dts

+17-13
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,25 @@
117117
status = "okay";
118118
};
119119

120-
&spi0 {
121-
pinctrl-0 = <&spi0_default>;
122-
pinctrl-names = "default";
123-
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
124-
clock-frequency = <DT_FREQ_M(1)>;
125-
status = "okay";
120+
&iom0 {
121+
spi0: spi {
122+
pinctrl-0 = <&spi0_default>;
123+
pinctrl-names = "default";
124+
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
125+
clock-frequency = <DT_FREQ_M(1)>;
126+
status = "okay";
127+
};
126128
};
127129

128-
&i2c3 {
129-
pinctrl-0 = <&i2c3_default>;
130-
pinctrl-names = "default";
131-
clock-frequency = <I2C_BITRATE_STANDARD>;
132-
scl-gpios = <&gpio32_63 10 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
133-
sda-gpios = <&gpio32_63 11 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
134-
status = "okay";
130+
&iom3 {
131+
i2c3: i2c {
132+
pinctrl-0 = <&i2c3_default>;
133+
pinctrl-names = "default";
134+
clock-frequency = <I2C_BITRATE_STANDARD>;
135+
scl-gpios = <&gpio32_63 10 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
136+
sda-gpios = <&gpio32_63 11 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
137+
status = "okay";
138+
};
135139
};
136140

137141
&counter0 {

boards/ambiq/apollo3p_evb/apollo3p_evb_connector.dtsi

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@
8888
};
8989
};
9090

91-
ambiq_spi0: &spi0 {};
92-
ambiq_i2c3: &i2c3 {};
91+
ambiq_spi0: &iom0 {};
92+
ambiq_i2c3: &iom3 {};

boards/ambiq/apollo4p_blue_kxr_evb/apollo4p_blue_kxr_evb.dts

+23-17
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,33 @@
8989
status = "okay";
9090
};
9191

92-
&i2c0 {
93-
pinctrl-0 = <&i2c0_default>;
94-
pinctrl-names = "default";
95-
clock-frequency = <I2C_BITRATE_STANDARD>;
96-
scl-gpios = <&gpio0_31 5 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
97-
sda-gpios = <&gpio0_31 6 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
98-
status = "okay";
92+
&iom0 {
93+
i2c0: i2c {
94+
pinctrl-0 = <&i2c0_default>;
95+
pinctrl-names = "default";
96+
clock-frequency = <I2C_BITRATE_STANDARD>;
97+
scl-gpios = <&gpio0_31 5 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
98+
sda-gpios = <&gpio0_31 6 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
99+
status = "okay";
100+
};
99101
};
100102

101-
&spi1 {
102-
pinctrl-0 = <&spi1_default>;
103-
pinctrl-names = "default";
104-
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
105-
clock-frequency = <DT_FREQ_M(1)>;
106-
status = "okay";
103+
&iom1 {
104+
spi1: spi {
105+
pinctrl-0 = <&spi1_default>;
106+
pinctrl-names = "default";
107+
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
108+
clock-frequency = <DT_FREQ_M(1)>;
109+
status = "okay";
110+
};
107111
};
108112

109-
&spi4 {
110-
pinctrl-0 = <&spi4_default>;
111-
pinctrl-names = "default";
112-
status = "okay";
113+
&iom4 {
114+
spi4: spi {
115+
pinctrl-0 = <&spi4_default>;
116+
pinctrl-names = "default";
117+
status = "okay";
118+
};
113119
};
114120

115121
&mspi0 {

boards/ambiq/apollo4p_evb/apollo4p_evb.dts

+17-13
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,25 @@
9494
status = "okay";
9595
};
9696

97-
&iom0_i2c {
98-
pinctrl-0 = <&i2c0_default>;
99-
pinctrl-names = "default";
100-
clock-frequency = <I2C_BITRATE_STANDARD>;
101-
scl-gpios = <&gpio0_31 5 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
102-
sda-gpios = <&gpio0_31 6 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
103-
status = "okay";
97+
&iom0 {
98+
i2c0: i2c {
99+
pinctrl-0 = <&i2c0_default>;
100+
pinctrl-names = "default";
101+
clock-frequency = <I2C_BITRATE_STANDARD>;
102+
scl-gpios = <&gpio0_31 5 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
103+
sda-gpios = <&gpio0_31 6 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>;
104+
status = "okay";
105+
};
104106
};
105107

106-
&iom1_spi {
107-
pinctrl-0 = <&spi1_default>;
108-
pinctrl-names = "default";
109-
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
110-
clock-frequency = <1000000>;
111-
status = "okay";
108+
&iom1 {
109+
spi1: spi {
110+
pinctrl-0 = <&spi1_default>;
111+
pinctrl-names = "default";
112+
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
113+
clock-frequency = <1000000>;
114+
status = "okay";
115+
};
112116
};
113117

114118
&mspi0 {

boards/ambiq/apollo4p_evb/apollo4p_evb_connector.dtsi

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,4 @@
118118
};
119119
};
120120

121-
spi1: &iom1_spi {};
121+
spi1: &iom1 {};

boards/rakwireless/rak11720/rak11720.dts

+38-32
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,48 @@
105105
status = "okay";
106106
};
107107

108-
&i2c2 {
109-
compatible = "ambiq,i2c";
110-
pinctrl-0 = <&i2c2_default>;
111-
pinctrl-names = "default";
112-
clock-frequency = <I2C_BITRATE_STANDARD>;
113-
status = "okay";
108+
&iom2 {
109+
i2c2: i2c {
110+
compatible = "ambiq,i2c";
111+
pinctrl-0 = <&i2c2_default>;
112+
pinctrl-names = "default";
113+
clock-frequency = <I2C_BITRATE_STANDARD>;
114+
status = "okay";
115+
};
114116
};
115117

116-
&spi0 {
117-
compatible = "ambiq,spi";
118-
pinctrl-0 = <&spi0_default>;
119-
pinctrl-names = "default";
120-
cs-gpios = <&gpio0_31 1 GPIO_ACTIVE_LOW>;
121-
clock-frequency = <DT_FREQ_M(1)>;
122-
status = "okay";
118+
&iom0 {
119+
spi0: spi {
120+
compatible = "ambiq,spi";
121+
pinctrl-0 = <&spi0_default>;
122+
pinctrl-names = "default";
123+
cs-gpios = <&gpio0_31 1 GPIO_ACTIVE_LOW>;
124+
clock-frequency = <DT_FREQ_M(1)>;
125+
status = "okay";
126+
};
123127
};
124128

125-
&spi1 {
126-
compatible = "ambiq,spi";
127-
status = "okay";
128-
pinctrl-0 = <&spi1_default>;
129-
pinctrl-names = "default";
130-
clock-frequency = <DT_FREQ_M(1)>;
131-
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
132-
133-
lora: lora@0 {
134-
compatible = "semtech,sx1262";
135-
reg = <0>;
136-
reset-gpios = <&gpio0_31 17 GPIO_ACTIVE_LOW>;
137-
busy-gpios = <&gpio0_31 16 GPIO_ACTIVE_HIGH>;
138-
dio1-gpios = <&gpio0_31 15 GPIO_ACTIVE_HIGH>;
139-
antenna-enable-gpios = <&gpio0_31 18 GPIO_ACTIVE_LOW>;
140-
dio2-tx-enable;
141-
dio3-tcxo-voltage = <SX126X_DIO3_TCXO_3V3>;
142-
tcxo-power-startup-delay-ms = <5>;
143-
spi-max-frequency = <DT_FREQ_M(1)>;
129+
&iom1 {
130+
spi1: spi {
131+
compatible = "ambiq,spi";
132+
status = "okay";
133+
pinctrl-0 = <&spi1_default>;
134+
pinctrl-names = "default";
135+
clock-frequency = <DT_FREQ_M(1)>;
136+
cs-gpios = <&gpio0_31 11 GPIO_ACTIVE_LOW>;
137+
138+
lora: lora@0 {
139+
compatible = "semtech,sx1262";
140+
reg = <0>;
141+
reset-gpios = <&gpio0_31 17 GPIO_ACTIVE_LOW>;
142+
busy-gpios = <&gpio0_31 16 GPIO_ACTIVE_HIGH>;
143+
dio1-gpios = <&gpio0_31 15 GPIO_ACTIVE_HIGH>;
144+
antenna-enable-gpios = <&gpio0_31 18 GPIO_ACTIVE_LOW>;
145+
dio2-tx-enable;
146+
dio3-tcxo-voltage = <SX126X_DIO3_TCXO_3V3>;
147+
tcxo-power-startup-delay-ms = <5>;
148+
spi-max-frequency = <DT_FREQ_M(1)>;
149+
};
144150
};
145151
};
146152

drivers/i2c/i2c_ambiq.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ static int i2c_ambiq_write(const struct device *dev, struct i2c_msg *msg, uint16
247247
static int i2c_ambiq_configure(const struct device *dev, uint32_t dev_config)
248248
{
249249
struct i2c_ambiq_data *data = dev->data;
250-
const struct i2c_ambiq_config *cfg = dev->config;
251250

252251
if (!(I2C_MODE_CONTROLLER & dev_config)) {
253252
return -EINVAL;
@@ -268,6 +267,8 @@ static int i2c_ambiq_configure(const struct device *dev, uint32_t dev_config)
268267
}
269268

270269
#ifdef CONFIG_I2C_AMBIQ_DMA
270+
const struct i2c_ambiq_config *cfg = dev->config;
271+
271272
data->iom_cfg.pNBTxnBuf = i2c_dma_tcb_buf[cfg->inst_idx].buf;
272273
data->iom_cfg.ui32NBTxnBufLength = CONFIG_I2C_DMA_TCB_BUFFER_SIZE;
273274
#endif
@@ -287,7 +288,7 @@ static int i2c_ambiq_transfer(const struct device *dev, struct i2c_msg *msgs, ui
287288
return 0;
288289
}
289290

290-
#ifdef CONFIG_DCACHE
291+
#if defined(CONFIG_I2C_AMBIQ_DMA) && defined(CONFIG_DCACHE)
291292
if (!i2c_buf_set_in_nocache(msgs, num_msgs)) {
292293
return -EFAULT;
293294
}
@@ -490,17 +491,18 @@ static int i2c_ambiq_pm_action(const struct device *dev, enum pm_device_action a
490491
PINCTRL_DT_INST_DEFINE(n); \
491492
static void i2c_irq_config_func_##n(void) \
492493
{ \
493-
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), i2c_ambiq_isr, \
494-
DEVICE_DT_INST_GET(n), 0); \
495-
irq_enable(DT_INST_IRQN(n)); \
494+
IRQ_CONNECT(DT_IRQN(DT_INST_PARENT(n)), DT_IRQ(DT_INST_PARENT(n), priority), \
495+
i2c_ambiq_isr, DEVICE_DT_INST_GET(n), 0); \
496+
irq_enable(DT_IRQN(DT_INST_PARENT(n))); \
496497
}; \
497498
static struct i2c_ambiq_data i2c_ambiq_data##n = { \
498499
.bus_sem = Z_SEM_INITIALIZER(i2c_ambiq_data##n.bus_sem, 1, 1), \
499500
.transfer_sem = Z_SEM_INITIALIZER(i2c_ambiq_data##n.transfer_sem, 0, 1)}; \
500501
static const struct i2c_ambiq_config i2c_ambiq_config##n = { \
501-
.base = DT_INST_REG_ADDR(n), \
502-
.size = DT_INST_REG_SIZE(n), \
503-
.inst_idx = (DT_INST_REG_ADDR(n) - IOM0_BASE) / (IOM1_BASE - IOM0_BASE), \
502+
.base = DT_REG_ADDR(DT_INST_PARENT(n)), \
503+
.size = DT_REG_SIZE(DT_INST_PARENT(n)), \
504+
.inst_idx = \
505+
(DT_REG_ADDR(DT_INST_PARENT(n)) - IOM0_BASE) / (IOM1_BASE - IOM0_BASE), \
504506
.bitrate = DT_INST_PROP(n, clock_frequency), \
505507
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
506508
.irq_config_func = i2c_irq_config_func_##n, \

drivers/spi/spi_ambiq_bleif.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ static DEVICE_API(spi, spi_ambiq_driver_api) = {
165165
static int spi_ambiq_init(const struct device *dev)
166166
{
167167
struct spi_ambiq_data *data = dev->data;
168-
const struct spi_ambiq_config *cfg = dev->config;
169168
int ret;
170169

171170
#if defined(CONFIG_SPI_AMBIQ_BLEIF_TIMING_TRACE)
171+
const struct spi_ambiq_config *cfg = dev->config;
172+
172173
ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
173174
if (ret) {
174175
return ret;

drivers/spi/spi_ambiq_spic.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ static int spi_ambiq_transceive(const struct device *dev, const struct spi_confi
443443
return 0;
444444
}
445445

446-
#ifdef CONFIG_DCACHE
446+
#if defined(CONFIG_SPI_AMBIQ_DMA) && defined(CONFIG_DCACHE)
447447
if ((tx_bufs != NULL && !spi_buf_set_in_nocache(tx_bufs)) ||
448448
(rx_bufs != NULL && !spi_buf_set_in_nocache(rx_bufs))) {
449449
return -EFAULT;
@@ -567,18 +567,19 @@ static int spi_ambiq_pm_action(const struct device *dev, enum pm_device_action a
567567
PINCTRL_DT_INST_DEFINE(n); \
568568
static void spi_irq_config_func_##n(void) \
569569
{ \
570-
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), spi_ambiq_isr, \
571-
DEVICE_DT_INST_GET(n), 0); \
572-
irq_enable(DT_INST_IRQN(n)); \
570+
IRQ_CONNECT(DT_IRQN(DT_INST_PARENT(n)), DT_IRQ(DT_INST_PARENT(n), priority), \
571+
spi_ambiq_isr, DEVICE_DT_INST_GET(n), 0); \
572+
irq_enable(DT_IRQN(DT_INST_PARENT(n))); \
573573
}; \
574574
static struct spi_ambiq_data spi_ambiq_data##n = { \
575575
SPI_CONTEXT_INIT_LOCK(spi_ambiq_data##n, ctx), \
576576
SPI_CONTEXT_INIT_SYNC(spi_ambiq_data##n, ctx), \
577577
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(n), ctx)}; \
578578
static const struct spi_ambiq_config spi_ambiq_config##n = { \
579-
.base = DT_INST_REG_ADDR(n), \
580-
.size = DT_INST_REG_SIZE(n), \
581-
.inst_idx = (DT_INST_REG_ADDR(n) - IOM0_BASE) / (IOM1_BASE - IOM0_BASE), \
579+
.base = DT_REG_ADDR(DT_INST_PARENT(n)), \
580+
.size = DT_REG_SIZE(DT_INST_PARENT(n)), \
581+
.inst_idx = \
582+
(DT_REG_ADDR(DT_INST_PARENT(n)) - IOM0_BASE) / (IOM1_BASE - IOM0_BASE), \
582583
.clock_freq = DT_INST_PROP(n, clock_frequency), \
583584
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
584585
.irq_config_func = spi_irq_config_func_##n}; \

0 commit comments

Comments
 (0)