Skip to content

Commit 26131ba

Browse files
Glauber Maroto Ferreiracfriedt
authored andcommitted
esp32: drivers: spi: driver refactoring
in preparation to support other esp32-family socs on top of existing driver. Signed-off-by: Glauber Maroto Ferreira <[email protected]>
1 parent fb16329 commit 26131ba

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341
/drivers/spi/ @tbursztyka
342342
/drivers/spi/*b91* @yurvyn
343343
/drivers/spi/spi_rv32m1_lpspi* @karstenkoenig
344+
/drivers/spi/*esp32* @glaubermaroto
344345
/drivers/timer/apic_timer.c @dcpleung @nashif
345346
/drivers/timer/apic_tsc.c @andyross
346347
/drivers/timer/arm_arch_timer.c @carlocaione

drivers/spi/spi_esp32_spim.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL);
3131
#define CSEL_IDX_2 HSPICS0_OUT_IDX
3232
#define CSEL_IDX_3 VSPICS0_OUT_IDX
3333

34-
#define INST_2_ESPRESSIF_ESP32_SPI_IRQ_0 13
35-
#define INST_3_ESPRESSIF_ESP32_SPI_IRQ_0 17
36-
3734
static bool spi_esp32_transfer_ongoing(struct spi_esp32_data *data)
3835
{
3936
return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx);
@@ -125,6 +122,7 @@ static int spi_esp32_init(const struct device *dev)
125122
}
126123

127124
static int spi_esp32_configure_pin(gpio_pin_t pin, int pin_sig,
125+
bool use_iomux,
128126
gpio_flags_t pin_mode)
129127
{
130128
const char *device_name = gpio_esp32_get_gpio_for_pin(pin);
@@ -142,10 +140,12 @@ static int spi_esp32_configure_pin(gpio_pin_t pin, int pin_sig,
142140
return -EIO;
143141
}
144142

145-
ret = gpio_pin_configure(gpio, pin, pin_mode);
146-
if (ret < 0) {
147-
LOG_ERR("SPI pin configuration failed");
148-
return ret;
143+
if (use_iomux) {
144+
ret = gpio_pin_configure(gpio, pin, pin_mode);
145+
if (ret < 0) {
146+
LOG_ERR("SPI pin configuration failed");
147+
return ret;
148+
}
149149
}
150150

151151
if (pin_mode == GPIO_INPUT) {
@@ -207,14 +207,17 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev,
207207

208208
spi_esp32_configure_pin(cfg->pins.miso,
209209
cfg->signals.miso_s,
210+
cfg->use_iomux,
210211
GPIO_INPUT);
211212

212213
spi_esp32_configure_pin(cfg->pins.mosi,
213214
cfg->signals.mosi_s,
215+
cfg->use_iomux,
214216
GPIO_OUTPUT_LOW);
215217

216218
spi_esp32_configure_pin(cfg->pins.sclk,
217219
cfg->signals.sclk_s,
220+
cfg->use_iomux,
218221
GPIO_OUTPUT);
219222

220223
if (ctx->config->cs == NULL) {
@@ -224,6 +227,7 @@ static int IRAM_ATTR spi_esp32_configure(const struct device *dev,
224227

225228
spi_esp32_configure_pin(cfg->pins.csel,
226229
cfg->signals.csel_s,
230+
cfg->use_iomux,
227231
GPIO_OUTPUT | GPIO_ACTIVE_LOW);
228232
}
229233

@@ -366,6 +370,12 @@ static const struct spi_driver_api spi_api = {
366370
.release = spi_esp32_release
367371
};
368372

373+
#ifdef CONFIG_SOC_ESP32
374+
#define GET_AS_CS(idx) .as_cs = DT_PROP(DT_NODELABEL(spi##idx), clk_as_cs),
375+
#else
376+
#define GET_AS_CS(idx)
377+
#endif
378+
369379
#define ESP32_SPI_INIT(idx) \
370380
\
371381
static struct spi_esp32_data spi_data_##idx = { \
@@ -376,7 +386,7 @@ static const struct spi_driver_api spi_api = {
376386
}, \
377387
.dev_config = { \
378388
.half_duplex = DT_PROP(DT_NODELABEL(spi##idx), half_duplex), \
379-
.as_cs = DT_PROP(DT_NODELABEL(spi##idx), clk_as_cs), \
389+
GET_AS_CS(idx) \
380390
.positive_cs = DT_PROP(DT_NODELABEL(spi##idx), positive_cs), \
381391
.no_compensate = DT_PROP(DT_NODELABEL(spi##idx), dummy_comp), \
382392
.sio = DT_PROP(DT_NODELABEL(spi##idx), sio) \
@@ -391,6 +401,7 @@ static const struct spi_driver_api spi_api = {
391401
.duty_cycle = 0, \
392402
.input_delay_ns = 0, \
393403
.irq_source = DT_IRQN(DT_NODELABEL(spi##idx)), \
404+
.use_iomux = DT_PROP(DT_NODELABEL(spi##idx), use_iomux), \
394405
.signals = { \
395406
.miso_s = MISO_IDX_##idx, \
396407
.mosi_s = MOSI_IDX_##idx, \

drivers/spi/spi_esp32_spim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct spi_esp32_config {
2525
int duty_cycle;
2626
int input_delay_ns;
2727
int irq_source;
28+
bool use_iomux;
2829

2930
clock_control_subsys_t clock_subsys;
3031

dts/bindings/spi/espressif,esp32-spi.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ properties:
3131
description: chip select pin
3232
required: true
3333

34+
use-iomux:
35+
type: boolean
36+
required: false
37+
description: |
38+
Support IO muxing for the target SPI peripheral pins
39+
40+
Some SPI interfaces are not allowed to mux its pins
41+
3442
half-duplex:
3543
type: boolean
3644
required: false

dts/xtensa/espressif/esp32.dtsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
label = "SPI_2";
200200
clocks = <&rtc ESP32_HSPI_MODULE>;
201201
status = "disabled";
202+
use-iomux;
202203
};
203204

204205
spi3: spi@3ff65000 {
@@ -209,6 +210,7 @@
209210
label = "SPI_3";
210211
clocks = <&rtc ESP32_VSPI_MODULE>;
211212
status = "disabled";
213+
use-iomux;
212214
};
213215

214216
timer0: counter@3ff5f000 {

0 commit comments

Comments
 (0)