@@ -15,12 +15,22 @@ LOG_MODULE_REGISTER(spi_sam0);
1515#include <soc.h>
1616#include <drivers/dma.h>
1717
18+ #ifndef SERCOM_SPI_CTRLA_MODE_SPI_MASTER_Val
19+ #define SERCOM_SPI_CTRLA_MODE_SPI_MASTER_Val (0x3)
20+ #endif
21+
1822/* Device constant configuration parameters */
1923struct spi_sam0_config {
2024 SercomSpi * regs ;
2125 u32_t pads ;
26+ #ifdef MCLK
27+ volatile u32_t * mclk ;
28+ u32_t mclk_mask ;
29+ u16_t gclk_core_id ;
30+ #else
2231 u32_t pm_apbcmask ;
2332 u16_t gclk_clkctrl_id ;
33+ #endif
2434#ifdef CONFIG_SPI_ASYNC
2535 u8_t tx_dma_request ;
2636 u8_t tx_dma_channel ;
@@ -669,12 +679,21 @@ static int spi_sam0_init(struct device *dev)
669679 struct spi_sam0_data * data = dev -> driver_data ;
670680 SercomSpi * regs = cfg -> regs ;
671681
682+ #ifdef MCLK
683+ /* Enable the GCLK */
684+ GCLK -> PCHCTRL [cfg -> gclk_core_id ].reg = GCLK_PCHCTRL_GEN_GCLK0 |
685+ GCLK_PCHCTRL_CHEN ;
686+
687+ /* Enable the MCLK */
688+ * cfg -> mclk |= cfg -> mclk_mask ;
689+ #else
672690 /* Enable the GCLK */
673691 GCLK -> CLKCTRL .reg = cfg -> gclk_clkctrl_id | GCLK_CLKCTRL_GEN_GCLK0 |
674692 GCLK_CLKCTRL_CLKEN ;
675693
676694 /* Enable SERCOM clock in PM */
677695 PM -> APBCMASK .reg |= cfg -> pm_apbcmask ;
696+ #endif
678697
679698 /* Disable all SPI interrupts */
680699 regs -> INTENCLR .reg = SERCOM_SPI_INTENCLR_MASK ;
@@ -740,6 +759,12 @@ static const struct spi_driver_api spi_sam0_driver_api = {
740759#ifndef DT_ATMEL_SAM0_SPI_SERCOM_5_RXDMA
741760#define DT_ATMEL_SAM0_SPI_SERCOM_5_RXDMA 0xFF
742761#endif
762+ #ifndef DT_ATMEL_SAM0_SPI_SERCOM_6_TXDMA
763+ #define DT_ATMEL_SAM0_SPI_SERCOM_6_TXDMA 0xFF
764+ #endif
765+ #ifndef DT_ATMEL_SAM0_SPI_SERCOM_7_RXDMA
766+ #define DT_ATMEL_SAM0_SPI_SERCOM_7_RXDMA 0xFF
767+ #endif
743768
744769#define SPI_SAM0_DMA_CHANNELS (n ) \
745770 .tx_dma_request = SERCOM##n##_DMAC_ID_TX, \
@@ -754,6 +779,16 @@ static const struct spi_driver_api spi_sam0_driver_api = {
754779 SERCOM_SPI_CTRLA_DIPO(DT_ATMEL_SAM0_SPI_SERCOM_##n##_DIPO) | \
755780 SERCOM_SPI_CTRLA_DOPO(DT_ATMEL_SAM0_SPI_SERCOM_##n##_DOPO)
756781
782+ #ifdef MCLK
783+ #define SPI_SAM0_DEFINE_CONFIG (n ) \
784+ static const struct spi_sam0_config spi_sam0_config_##n = { \
785+ .regs = (SercomSpi *)DT_ATMEL_SAM0_SPI_SERCOM_##n##_BASE_ADDRESS,\
786+ .mclk = MCLK_SERCOM##n, \
787+ .mclk_mask = MCLK_SERCOM##n##_MASK, \
788+ .gclk_core_id = SERCOM##n##_GCLK_ID_CORE, \
789+ .pads = SPI_SAM0_SERCOM_PADS(n) \
790+ }
791+ #else
757792#define SPI_SAM0_DEFINE_CONFIG (n ) \
758793 static const struct spi_sam0_config spi_sam0_config_##n = { \
759794 .regs = (SercomSpi *)DT_ATMEL_SAM0_SPI_SERCOM_##n##_BASE_ADDRESS,\
@@ -762,6 +797,7 @@ static const struct spi_driver_api spi_sam0_driver_api = {
762797 .pads = SPI_SAM0_SERCOM_PADS(n), \
763798 SPI_SAM0_DMA_CHANNELS(n) \
764799 }
800+ #endif /* MCLK */
765801
766802#define SPI_SAM0_DEVICE_INIT (n ) \
767803 SPI_SAM0_DEFINE_CONFIG(n); \
@@ -798,3 +834,11 @@ SPI_SAM0_DEVICE_INIT(4);
798834#if DT_ATMEL_SAM0_SPI_SERCOM_5_BASE_ADDRESS
799835SPI_SAM0_DEVICE_INIT (5 );
800836#endif
837+
838+ #if DT_ATMEL_SAM0_SPI_SERCOM_6_BASE_ADDRESS
839+ SPI_SAM0_DEVICE_INIT (6 );
840+ #endif
841+
842+ #if DT_ATMEL_SAM0_SPI_SERCOM_7_BASE_ADDRESS
843+ SPI_SAM0_DEVICE_INIT (7 );
844+ #endif
0 commit comments