diff options
-rw-r--r-- | board/hoho/board.c | 40 | ||||
-rw-r--r-- | board/hoho/board.h | 5 | ||||
-rw-r--r-- | board/hoho/gpio.inc | 1 |
3 files changed, 46 insertions, 0 deletions
diff --git a/board/hoho/board.c b/board/hoho/board.c index b0e3a7d37b..c30cbfd3a2 100644 --- a/board/hoho/board.c +++ b/board/hoho/board.c @@ -26,6 +26,46 @@ void board_config_pre_init(void) STM32_SYSCFG_CFGR1 |= (1 << 9) | (1 << 10);/* Remap USART1 RX/TX DMA */ } +#ifdef CONFIG_SPI_FLASH + +static void board_init_spi2(void) +{ + /* Remap SPI2 to DMA channels 6 and 7 */ + STM32_SYSCFG_CFGR1 |= (1 << 24); + + /* Set pin NSS to general purpose output mode (01b). */ + /* Set pins SCK, MISO, and MOSI to alternate function (10b). */ + STM32_GPIO_MODER(GPIO_B) &= ~0xff000000; + STM32_GPIO_MODER(GPIO_B) |= 0xa9000000; + + /* Set all four pins to alternate function 0 */ + STM32_GPIO_AFRH(GPIO_B) &= ~(0xffff0000); + + /* Set all four pins to output push-pull */ + STM32_GPIO_OTYPER(GPIO_B) &= ~(0xf000); + + /* Set pullup on NSS */ + STM32_GPIO_PUPDR(GPIO_B) |= 0x1000000; + + /* Set all four pins to high speed */ + STM32_GPIO_OSPEEDR(GPIO_B) |= 0xff000000; + + /* Reset SPI2 */ + STM32_RCC_APB1RSTR |= (1 << 14); + STM32_RCC_APB1RSTR &= ~(1 << 14); + + /* Enable clocks to SPI2 module */ + STM32_RCC_APB1ENR |= STM32_RCC_PB1_SPI2; +} + +/* Initialize board. */ +static void board_init(void) +{ + board_init_spi2(); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); +#endif /* CONFIG_SPI_FLASH */ + /* ADC channels */ const struct adc_t adc_channels[] = { /* USB PD CC lines sensing. Converted to mV (3300mV/4096). */ diff --git a/board/hoho/board.h b/board/hoho/board.h index 47fd3a28f4..54b75c9a33 100644 --- a/board/hoho/board.h +++ b/board/hoho/board.h @@ -18,7 +18,12 @@ #define CONFIG_STM_HWTIMER32 #define CONFIG_ADC #define CONFIG_BOARD_PRE_INIT +#define CONFIG_CMD_SPI_FLASH #define CONFIG_I2C +#define CONFIG_SPI_FLASH +#define CONFIG_SPI_FLASH_SIZE 1048576 +#define CONFIG_SPI_MASTER_PORT 2 +#define CONFIG_SPI_CS_GPIO GPIO_PD_MCDP_SPI_CL_L #undef CONFIG_WATCHDOG_HELP #undef CONFIG_LID_SWITCH #undef CONFIG_TASK_PROFILING diff --git a/board/hoho/gpio.inc b/board/hoho/gpio.inc index 98eb079cd6..172be5ef18 100644 --- a/board/hoho/gpio.inc +++ b/board/hoho/gpio.inc @@ -21,6 +21,7 @@ GPIO(PD_MCDP_SPI_WP_L, B, 2, GPIO_OUT_LOW, NULL) GPIO(PD_CC1_TX_DATA, B, 4, GPIO_OUT_LOW, NULL) GPIO(MCDP_I2C_SCL, B, 6, GPIO_INPUT, NULL) GPIO(MCDP_I2C_SDA, B, 7, GPIO_INPUT, NULL) +GPIO(PD_MCDP_SPI_CL_L, B, 12, GPIO_OUT_LOW, NULL) /* Unimplemented signals which we need to emulate for now */ UNIMPLEMENTED(ENTERING_RW) |