Skip to content

Commit

Permalink
drivers: spi: Add SPI device support for Apollo3 SoCs
Browse files Browse the repository at this point in the history
This commit adds spi device support for Apollo3 SoCs.

Signed-off-by: Hao Luo <[email protected]>
  • Loading branch information
AlessandroLuo committed Aug 28, 2024
1 parent fba0a47 commit 2737c1c
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 17 deletions.
6 changes: 5 additions & 1 deletion boards/ambiq/apollo3_evb/apollo3_evb-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
bias-pull-up;
};
};

spis0_default: spis0_default {
group1 {
pinmux = <SLSCK_P0>, <SLMISO_P2>, <SLMOSI_P1>, <SLNCE_P3>;
};
};
spi0_default: spi0_default {
group1 {
pinmux = <M0SCK_P5>, <M0MISO_P6>, <M0MOSI_P7>;
Expand Down
6 changes: 5 additions & 1 deletion boards/ambiq/apollo3p_evb/apollo3p_evb-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@
bias-pull-up;
};
};

spis0_default: spis0_default {
group1 {
pinmux = <SLSCK_P0>, <SLMISO_P2>, <SLMOSI_P1>, <SLNCE_P3>;
};
};
spi0_default: spi0_default {
group1 {
pinmux = <M0SCK_P5>, <M0MISO_P6>, <M0MOSI_P7>;
Expand Down
3 changes: 2 additions & 1 deletion drivers/spi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ zephyr_library_sources_ifdef(CONFIG_SPI_PW spi_pw.c)
zephyr_library_sources_ifdef(CONFIG_SPI_SMARTBOND spi_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_SPI_OPENTITAN spi_opentitan.c)
zephyr_library_sources_ifdef(CONFIG_SPI_NUMAKER spi_numaker.c)
zephyr_library_sources_ifdef(CONFIG_SPI_AMBIQ spi_ambiq.c)
zephyr_library_sources_ifdef(CONFIG_SPI_AMBIQ_SPIM spi_ambiq_spim.c)
zephyr_library_sources_ifdef(CONFIG_SPI_AMBIQ_SPIS spi_ambiq_spis.c)
zephyr_library_sources_ifdef(CONFIG_SPI_AMBIQ_BLEIF spi_ambiq_bleif.c)
zephyr_library_sources_ifdef(CONFIG_SPI_RPI_PICO_PIO spi_rpi_pico_pio.c)
zephyr_library_sources_ifdef(CONFIG_SPI_MCHP_MSS spi_mchp_mss.c)
Expand Down
24 changes: 17 additions & 7 deletions drivers/spi/Kconfig.ambiq
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
# SPDX-License-Identifier: Apache-2.0
#

menuconfig SPI_AMBIQ
bool "AMBIQ SPI driver"
menuconfig SPI_AMBIQ_SPIM
bool "AMBIQ SPI Controller driver"
default y
depends on DT_HAS_AMBIQ_SPI_ENABLED
select GPIO
select AMBIQ_HAL
select AMBIQ_HAL_USE_SPI
select AMBIQ_HAL_USE_SPIM
help
Enable driver for Ambiq SPI.
Enable driver for Ambiq SPI in Controller mode.

if SPI_AMBIQ
if SPI_AMBIQ_SPIM

config SPI_AMBIQ_DMA
bool "AMBIQ APOLLO SPI DMA Support"
depends on SPI_AMBIQ
depends on SPI_AMBIQ_SPIM
help
Enable DMA for Ambiq SPI.

Expand All @@ -31,7 +31,17 @@ config SPI_DMA_TCB_BUFFER_SIZE
help
DMA Transfer Control Buffer size in words

endif # SPI_AMBIQ
endif # SPI_AMBIQ_SPIM

config SPI_AMBIQ_SPIS
bool "AMBIQ SPI Target driver"
default y
depends on DT_HAS_AMBIQ_SPIS_ENABLED
select GPIO
select AMBIQ_HAL
select AMBIQ_HAL_USE_SPIS
help
Enable driver for Ambiq SPI in Target mode.

config SPI_AMBIQ_BLEIF
bool "AMBIQ SPI-BLEIF driver"
Expand Down
6 changes: 2 additions & 4 deletions drivers/spi/spi_ambiq.c → drivers/spi/spi_ambiq_spim.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ typedef void (*spi_context_update_trx)(struct spi_context *ctx, uint8_t dfs, uin

#define SPI_WORD_SIZE 8

#define SPI_CS_INDEX 3

#ifdef CONFIG_SPI_AMBIQ_DMA
static __aligned(32) struct {
__aligned(32) uint32_t buf[CONFIG_SPI_DMA_TCB_BUFFER_SIZE];
Expand Down Expand Up @@ -144,7 +142,7 @@ static int spi_config(const struct device *dev, const struct spi_config *config)
}

if (config->operation & SPI_OP_MODE_SLAVE) {
LOG_ERR("Slave mode not supported");
LOG_ERR("Target mode not supported");
return -ENOTSUP;
}
if (config->operation & SPI_MODE_LOOP) {
Expand All @@ -157,7 +155,7 @@ static int spi_config(const struct device *dev, const struct spi_config *config)
return -ENOTSUP;
}

/* Select slower of two: SPI bus frequency for SPI device or SPI master clock frequency */
/* Select slower of two: SPI bus frequency for SPI target or SPI controller clock frequency */

Check warning on line 158 in drivers/spi/spi_ambiq_spim.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE_COMMENT

drivers/spi/spi_ambiq_spim.c:158 line length of 102 exceeds 100 columns
data->iom_cfg.ui32ClockFreq =

Check notice on line 159 in drivers/spi/spi_ambiq_spim.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/spi/spi_ambiq_spim.c:159 - /* Select slower of two: SPI bus frequency for SPI target or SPI controller clock frequency */ + /* Select slower of two: SPI bus frequency for SPI target or SPI controller clock frequency + */
(config->frequency ? MIN(config->frequency, cfg->clock_freq) : cfg->clock_freq);
ctx->config = config;
Expand Down
Loading

0 comments on commit 2737c1c

Please sign in to comment.