coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
spi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <assert.h>
5 #include <spi_flash.h>
6 #include <soc/addressmap.h>
8 #include <soc/gpio.h>
9 #include <soc/spi.h>
10 
12  {
13  .regs = (void *)SPI_BASE,
14  .cs_gpio = GPIO(MSDC2_CMD),
15  }
16 };
17 
18 void mtk_spi_set_gpio_pinmux(unsigned int bus,
19  enum spi_pad_mask pad_select)
20 {
21  /* TODO: implement support for other pads when needed */
22  assert(pad_select == SPI_PAD1_MASK);
23  gpio_set_mode(GPIO(MSDC2_DAT2), PAD_MSDC2_DAT2_FUNC_SPI_CK_1);
24  gpio_set_mode(GPIO(MSDC2_DAT3), PAD_MSDC2_DAT3_FUNC_SPI_MI_1);
25  gpio_set_mode(GPIO(MSDC2_CLK), PAD_MSDC2_CLK_FUNC_SPI_MO_1);
26  gpio_set_mode(GPIO(MSDC2_CMD), 0);
27 }
28 
29 static const struct spi_ctrlr spi_flash_ctrlr = {
30  .max_xfer_size = 65535,
31  .flash_probe = mtk_spi_flash_probe,
32 };
33 
34 const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = {
35  {
36  .ctrlr = &spi_ctrlr,
37  .bus_start = 0,
38  .bus_end = SPI_BUS_NUMBER - 1,
39  },
40  {
41  .ctrlr = &spi_flash_ctrlr,
42  .bus_start = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS,
43  .bus_end = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS,
44  },
45 };
46 
#define assert(statement)
Definition: assert.h:74
#define ARRAY_SIZE(a)
Definition: helpers.h:12
@ GPIO
Definition: chip.h:84
int mtk_spi_flash_probe(const struct spi_slave *spi, struct spi_flash *flash)
const struct spi_ctrlr_buses spi_ctrlr_bus_map[]
Definition: spi.c:401
const size_t spi_ctrlr_bus_map_count
Definition: spi.c:408
void gpio_set_mode(gpio_t gpio, int mode)
Definition: gpio.c:45
const struct spi_ctrlr spi_ctrlr
Definition: spi.c:261
@ SPI_BASE
Definition: addressmap.h:37
#define SPI_BUS_NUMBER
Definition: spi.h:8
struct mtk_spi_bus spi_bus[SPI_BUS_NUMBER]
Definition: spi.c:11
static const struct spi_ctrlr spi_flash_ctrlr
Definition: spi.c:29
void mtk_spi_set_gpio_pinmux(unsigned int bus, enum spi_pad_mask pad_select)
Definition: spi.c:18
spi_pad_mask
Definition: spi_common.h:45
@ SPI_PAD1_MASK
Definition: spi_common.h:47
Definition: device.h:76
gpio_t cs_gpio
Definition: spi_common.h:77
struct mtk_spi_regs * regs
Definition: spi_common.h:74
const struct spi_ctrlr * ctrlr
Definition: spi-generic.h:175
uint32_t max_xfer_size
Definition: spi-generic.h:158