Skip to content

device: sam9x60: add flexcom spi support #186

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ else
BUILD_DATE := $(shell $(DATE) "$(DATE_FMT)")
endif
endif
export VERSION := v4.0.11-rc1
export VERSION := v4.0.11-rc2
REVISION :=
ifdef NIX_SHELL
SCMINFO := $(shell (host-utilities/setlocalversion))
Expand Down
6 changes: 6 additions & 0 deletions device/sam9x60/Config.in.device
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ config SAM9X60
select CPU_HAS_WDT2
select CPU_HAS_SCLK_BYPASS
select CPU_HAS_AES
select CPU_HAS_SPI
select CPU_HAS_SPI_IOSET
select CPU_HAS_FLEXCOM0
select CPU_HAS_FLEXCOM1
select CPU_HAS_FLEXCOM2
Expand All @@ -33,5 +35,9 @@ config SAM9X60
select ALLOW_CRYSTAL_24_000MHZ
select SUPPORT_BUS_SPEED_200MHZ
select CPU_HAS_XDMAC
select ALLOW_BOOT_FROM_DATAFLASH_CS0
select ALLOW_BOOT_FROM_DATAFLASH_CS1
select ALLOW_BOOT_FROM_DATAFLASH_CS2
select ALLOW_BOOT_FROM_DATAFLASH_CS3
bool "SAM9X60"

66 changes: 64 additions & 2 deletions device/sam9x60/sam9x60.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ __attribute__((weak)) void wilc_pwrseq();

#define FLEXCOM_USART_INDEX (CONFIG_CONSOLE_INDEX - 1)

#if defined(CONFIG_TWI) || CONFIG_CONSOLE_INDEX != 0
#if defined(CONFIG_TWI) || CONFIG_CONSOLE_INDEX != 0 || defined(CONFIG_SPI)
static struct at91_flexcom flexcoms[] = {
{AT91C_ID_FLEXCOM0, FLEXCOM_TWI, AT91C_BASE_FLEXCOM0},
{AT91C_ID_FLEXCOM1, FLEXCOM_TWI, AT91C_BASE_FLEXCOM1},
Expand Down Expand Up @@ -279,6 +279,68 @@ void twi_init()
}
#endif

#if defined CONFIG_SPI
void at91_spi0_hw_init()
{
const struct pio_desc flx_pins[][5] = {
{ // FLEXCOM0
{"FLX_IO0", AT91C_PIN_PA(0), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO1", AT91C_PIN_PA(1), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO2", AT91C_PIN_PA(4), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
},
{ // FLEXCOM1
{"FLX_IO0", AT91C_PIN_PA(5), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO1", AT91C_PIN_PA(6), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO2", AT91C_PIN_PC(29), 0, PIO_DEFAULT, PIO_PERIPH_C},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
},
{ // FLEXCOM2
{"FLX_IO0", AT91C_PIN_PA(7), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO1", AT91C_PIN_PA(8), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO2", AT91C_PIN_PB(2), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
},
{ // FLEXCOM3
{"FLX_IO0", AT91C_PIN_PC(22), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO1", AT91C_PIN_PC(23), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO2", AT91C_PIN_PC(26), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
},
{ // FLEXCOM4
{"FLX_IO0", AT91C_PIN_PA(12), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO1", AT91C_PIN_PA(11), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO2", AT91C_PIN_PA(13), 0, PIO_DEFAULT, PIO_PERIPH_A},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
},
{ // FLEXCOM5
{"FLX_IO0", AT91C_PIN_PA(22), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO1", AT91C_PIN_PA(21), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO2", AT91C_PIN_PA(23), 0, PIO_DEFAULT, PIO_PERIPH_B},
{"FLX_IO3", CONFIG_SYS_SPI_PCS, 1, PIO_DEFAULT, PIO_OUTPUT},
{(char *)0, 0, 0, PIO_DEFAULT, PIO_PERIPH_A},
}
};

if (CONFIG_CONSOLE_INDEX == CONFIG_SPI_BUS + 1) {
dbg_very_loud("\nFLEXCOM %d is used in UART mode, config to SPI mode ignored!\n\n", CONFIG_SPI_BUS);
return;
}

pio_configure(flx_pins[CONFIG_SPI_BUS]);

pmc_enable_periph_clock(flexcoms[CONFIG_SPI_BUS].id, PMC_PERIPH_CLK_DIVIDER_NA);

flexcoms[CONFIG_SPI_BUS].mode = FLEXCOM_SPI;
flexcom_init(CONFIG_SPI_BUS);
}
#endif

void hw_init(void)
{
unsigned int reg;
Expand All @@ -302,7 +364,7 @@ void hw_init(void)
pmc_mck_cfg_set(0, BOARD_PRESCALER_PLLA,
AT91C_PMC_PRES | AT91C_PMC_MDIV | AT91C_PMC_CSS);

#if defined(CONFIG_TWI) || CONFIG_CONSOLE_INDEX != 0
#if defined(CONFIG_TWI) || CONFIG_CONSOLE_INDEX != 0 || defined(CONFIG_SPI)
flexcoms_init(flexcoms);
#endif

Expand Down
72 changes: 68 additions & 4 deletions device/sam9x60/sam9x60_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,74 @@
#define CONFIG_SYS_SPI_CLOCK AT91C_SPI_CLK
#define CONFIG_SYS_SPI_MODE SPI_MODE0

#if defined(CONFIG_SPI_BUS0)
#define CONFIG_SYS_BASE_SPI AT91C_BASE_SPI0
#elif defined(CONFIG_SPI_BUS1)
#define CONFIG_SYS_BASE_SPI AT91C_BASE_SPI1
#if defined(CONFIG_SPI)
#include "flexcom.h"
#define CONFIG_SYS_BASE_SPI flexcom_get_regmap(CONFIG_SPI_BUS)
#if CONFIG_SPI_BUS == 0
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(3)
#elif defined(CONFIG_SPI_BOOT_CS1)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(2)
#else
#error "Invalid SPI chip select configuration!"
#endif
#elif CONFIG_SPI_BUS == 1
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PC(28)
#elif defined(CONFIG_SPI_BOOT_CS1)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PC(27)
#else
#error "Invalid SPI chip select configuration!"
#endif
#elif CONFIG_SPI_BUS == 2
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PB(1)
#elif defined(CONFIG_SPI_BOOT_CS1)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PB(0)
#else
#error "Invalid SPI chip select configuration!"
#endif
#elif CONFIG_SPI_BUS == 3
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PC(25)
#elif defined(CONFIG_SPI_BOOT_CS1)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PC(24)
#else
#error "Invalid SPI chip select configuration!"
#endif
#elif CONFIG_SPI_BUS == 4
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(14)
#elif defined(CONFIG_SPI_BOOT_CS1) && CONFIG_SPI_IOSET == 1
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(7)
#elif defined(CONFIG_SPI_BOOT_CS1) && CONFIG_SPI_IOSET == 2
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(0)
#elif defined(CONFIG_SPI_BOOT_CS2) && CONFIG_SPI_IOSET == 1
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(1)
#elif defined(CONFIG_SPI_BOOT_CS2) && CONFIG_SPI_IOSET == 2
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(8)
#elif defined(CONFIG_SPI_BOOT_CS3)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PB(3)
#else
#error "Invalid SPI chip select configuration!"
#endif
#elif CONFIG_SPI_BUS == 5
#if defined(CONFIG_SPI_BOOT_CS0)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(8)
#elif defined(CONFIG_SPI_BOOT_CS1) && CONFIG_SPI_IOSET == 1
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(0)
#elif defined(CONFIG_SPI_BOOT_CS1) && CONFIG_SPI_IOSET == 2
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(7)
#elif defined(CONFIG_SPI_BOOT_CS2)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(31)
#elif defined(CONFIG_SPI_BOOT_CS3)
#define CONFIG_SYS_SPI_PCS AT91C_PIN_PA(30)
#else
#error "Invalid SPI chip select configuration!"
#endif
#else
#error "Invalid SPI bus configuration!"
#endif
#endif

#if defined(CONFIG_QSPI)
Expand Down