Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions boards/microchip/sam/sama7g54_ek/sama7g54_ek.dts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@
};
};

&flx11 {
mchp,flexcom-mode = <SAM_FLEXCOM_MODE_SPI>;
status = "okay";

spi11: spi@400 {
pinctrl-0 = <&pinctrl_spi11_default>;
pinctrl-names = "default";
cs-gpios = <&piob 6 GPIO_ACTIVE_LOW>;
status = "okay";

nor_flash: sst26vf064@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <10000000>;
size = <DT_SIZE_M(64)>; /* 64 Mbits */
jedec-id = [bf 26 43];
requires-ulbpr;
status = "okay";
};
};
};

&gmac0 {
status = "okay";
pinctrl-names = "default";
Expand Down Expand Up @@ -361,6 +383,16 @@
bias-pull-up;
};
};

pinctrl_spi11_default: spi11_default {
group1 {
pinmux = <PIN_PB3__FLEXCOM11_IO0>,
<PIN_PB4__FLEXCOM11_IO1>,
<PIN_PB5__FLEXCOM11_IO2>,
<PIN_PB6__GPIO>; /* GPIO CS */
bias-pull-up;
};
};
};

&pit64b0 {
Expand Down
1 change: 1 addition & 0 deletions boards/microchip/sam/sama7g54_ek/sama7g54_ek.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ supported:
- pwm
- sdhc
- shell
- spi
- uart
vendor: microchip
41 changes: 40 additions & 1 deletion drivers/spi/spi_sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ LOG_MODULE_REGISTER(spi_sam);
#include <zephyr/sys/util.h>
#include <soc.h>

/* Adapt the hal_microchip for sam series */
#ifdef CONFIG_MICROCHIP_SAM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAK, this must be in the hal. No fixups in Zephyr!

No new defines in HAL, it must go direct in the headers so maybe you need to update the ATDF files.

#undef SPI_CR_SPIEN
#define SPI_CR_SPIEN SPI_CR_SPIEN_Msk
#undef SPI_CR_SPIDIS
#define SPI_CR_SPIDIS SPI_CR_SPIDIS_Msk
#undef SPI_MR_MSTR
#define SPI_MR_MSTR SPI_MR_MSTR_Msk
#undef SPI_MR_MODFDIS
#define SPI_MR_MODFDIS SPI_MR_MODFDIS_Msk
#undef SPI_MR_LLB
#define SPI_MR_LLB SPI_MR_LLB_Msk
#undef SPI_SR_RDRF
#define SPI_SR_RDRF SPI_SR_RDRF_Msk
#undef SPI_SR_TDRE
#define SPI_SR_TDRE SPI_SR_TDRE_Msk
#undef SPI_SR_TXEMPTY
#define SPI_SR_TXEMPTY SPI_SR_TXEMPTY_Msk
#undef SPI_CSR_CPOL
#define SPI_CSR_CPOL SPI_CSR_CPOL_Msk
#undef SPI_CSR_NCPHA
#define SPI_CSR_NCPHA SPI_CSR_NCPHA_Msk
#endif

#define SAM_SPI_CHIP_SELECT_COUNT 4

/* Number of bytes in transfer before using DMA if available */
Expand Down Expand Up @@ -101,6 +125,21 @@ static int spi_sam_configure(const struct device *dev,
uint16_t spi_csr_idx = spi_cs_is_gpio(config) ? 0 : config->slave;
int div;

#ifdef SOC_ATMEL_SAM_MCK_FREQ_HZ
uint32_t rate = SOC_ATMEL_SAM_MCK_FREQ_HZ;
#else
uint32_t rate;
int ret;

ret = clock_control_get_rate(SAM_DT_PMC_CONTROLLER,
(clock_control_subsys_t)&cfg->clock_cfg,
&rate);
if (ret) {
return ret;
}
#endif


if (spi_context_configured(&data->ctx, config)) {
return 0;
}
Expand Down Expand Up @@ -146,7 +185,7 @@ static int spi_sam_configure(const struct device *dev,
}

/* Use the requested or next highest possible frequency */
div = SOC_ATMEL_SAM_MCK_FREQ_HZ / config->frequency;
div = rate / config->frequency;
div = CLAMP(div, 1, UINT8_MAX);
spi_csr |= SPI_CSR_SCBR(div);

Expand Down
11 changes: 11 additions & 0 deletions dts/arm/microchip/sam/sama7g5.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,17 @@
status = "disabled";
};

spi11: spi@400 {
compatible = "atmel,sam-spi";
reg = <0x400 0x200>;
clocks = <&pmc PMC_TYPE_PERIPHERAL 49>;
interrupt-parent = <&gic>;
interrupts = <GIC_SPI 49 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
#address-cells = <1>;
#size-cells = <0>;
status = "disabled";
};

usart11: serial@200 {
compatible = "atmel,sam-usart";
reg = <0x200 0x200>;
Expand Down