| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <assert.h> |
| 9 |
#include <console/console.h> |
| 10 |
#include <device/mmio.h> |
| 11 |
#include <gpio.h> |
| 12 |
#include <spi_flash.h> |
| 13 |
#include <soc/addressmap.h> |
| 14 |
#include <soc/flash_controller_common.h> |
| 15 |
#include <soc/spi.h> |
| 16 |
|
| 17 |
struct mtk_spi_bus spi_bus[SPI_BUS_NUMBER] = { |
| 18 |
{ |
| 19 |
.regs = (void *)SPI0_BASE, |
| 20 |
.cs_gpio = GPIO(SPI0_CSB), |
| 21 |
}, |
| 22 |
{ |
| 23 |
.regs = (void *)SPI1_BASE, |
| 24 |
.cs_gpio = GPIO(SPI1_CSB), |
| 25 |
}, |
| 26 |
{ |
| 27 |
.regs = (void *)SPI2_BASE, |
| 28 |
.cs_gpio = GPIO(SPI2_CSB), |
| 29 |
}, |
| 30 |
{ |
| 31 |
.regs = (void *)SPI3_BASE, |
| 32 |
.cs_gpio = GPIO(SPI3_CSB), |
| 33 |
}, |
| 34 |
{ |
| 35 |
.regs = (void *)SPI4_BASE, |
| 36 |
.cs_gpio = GPIO(EINT11), |
| 37 |
}, |
| 38 |
{ |
| 39 |
.regs = (void *)SPI5_BASE, |
| 40 |
.cs_gpio = GPIO(SPI5_CSB), |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
static const struct pad_func pad0_funcs[SPI_BUS_NUMBER][4] = { |
| 45 |
{ |
| 46 |
PAD_FUNC_DOWN(SPI0_MI, SPI0_MI_A), |
| 47 |
PAD_FUNC_GPIO(SPI0_CSB), |
| 48 |
PAD_FUNC_DOWN(SPI0_MO, SPI0_MO_A), |
| 49 |
PAD_FUNC_DOWN(SPI0_CLK, SPI0_CLK_A), |
| 50 |
}, |
| 51 |
{ |
| 52 |
PAD_FUNC_DOWN(SPI1_MI, SPI1_MI_A), |
| 53 |
PAD_FUNC_GPIO(SPI1_CSB), |
| 54 |
PAD_FUNC_DOWN(SPI1_MO, SPI1_MO_A), |
| 55 |
PAD_FUNC_DOWN(SPI1_CLK, SPI1_CLK_A), |
| 56 |
}, |
| 57 |
{ |
| 58 |
PAD_FUNC_DOWN(SPI2_MI, SPI2_MI_A), |
| 59 |
PAD_FUNC_GPIO(SPI2_CSB), |
| 60 |
PAD_FUNC_DOWN(SPI2_MO, SPI2_MO_A), |
| 61 |
PAD_FUNC_DOWN(SPI2_CK, SPI2_CLK_A), |
| 62 |
}, |
| 63 |
{ |
| 64 |
PAD_FUNC_DOWN(SPI3_MI, SPI3_MI), |
| 65 |
PAD_FUNC_GPIO(SPI3_CSB), |
| 66 |
PAD_FUNC_DOWN(SPI3_MO, SPI3_MO), |
| 67 |
PAD_FUNC_DOWN(SPI3_CLK, SPI3_CLK), |
| 68 |
}, |
| 69 |
{ |
| 70 |
PAD_FUNC_DOWN(EINT13, SPI4_MI_A), |
| 71 |
PAD_FUNC_GPIO(EINT11), |
| 72 |
PAD_FUNC_DOWN(EINT12, SPI4_MO_A), |
| 73 |
PAD_FUNC_DOWN(EINT10, SPI4_CLK_A), |
| 74 |
}, |
| 75 |
{ |
| 76 |
PAD_FUNC_DOWN(SPI5_MI, SPI5_MI), |
| 77 |
PAD_FUNC_GPIO(SPI5_CSB), |
| 78 |
PAD_FUNC_DOWN(SPI5_MO, SPI5_MO), |
| 79 |
PAD_FUNC_DOWN(SPI5_CLK, SPI5_CLK), |
| 80 |
}, |
| 81 |
}; |
| 82 |
|
| 83 |
static const struct pad_func pad1_funcs[SPI_BUS_NUMBER][4] = { |
| 84 |
{ |
| 85 |
PAD_FUNC_DOWN(EINT3, SPI0_MI_B), |
| 86 |
PAD_FUNC_GPIO(EINT1), |
| 87 |
PAD_FUNC_DOWN(EINT2, SPI0_MO_B), |
| 88 |
PAD_FUNC_DOWN(EINT0, SPI0_CLK_B), |
| 89 |
}, |
| 90 |
{ |
| 91 |
PAD_FUNC_DOWN(EINT9, SPI1_MI_B), |
| 92 |
PAD_FUNC_GPIO(EINT7), |
| 93 |
PAD_FUNC_DOWN(EINT8, SPI1_MO_B), |
| 94 |
PAD_FUNC_DOWN(EINT6, SPI1_CLK_B), |
| 95 |
}, |
| 96 |
{ |
| 97 |
PAD_FUNC_DOWN(CAM_PDN1, SPI2_MI_B), |
| 98 |
PAD_FUNC_GPIO(CAM_PDN0), |
| 99 |
PAD_FUNC_DOWN(CAM_RST0, SPI2_MO_B), |
| 100 |
PAD_FUNC_DOWN(EINT18, SPI2_CLK_B), |
| 101 |
}, |
| 102 |
{ |
| 103 |
}, |
| 104 |
{ |
| 105 |
PAD_FUNC_DOWN(I2S2_DI, SPI4_MI_B), |
| 106 |
PAD_FUNC_GPIO(I2S2_BCK), |
| 107 |
PAD_FUNC_DOWN(I2S2_LRCK, SPI4_MO_B), |
| 108 |
PAD_FUNC_DOWN(I2S2_MCK, SPI4_CLK_B), |
| 109 |
}, |
| 110 |
{ |
| 111 |
}, |
| 112 |
}; |
| 113 |
|
| 114 |
static const struct pad_func nor_pinmux[SPI_NOR_GPIO_SET_NUM][4] = { |
| 115 |
|
| 116 |
[SPI_NOR_GPIO_SET0] = { |
| 117 |
PAD_FUNC(SPI0_CLK, SPINOR_CK, GPIO_PULL_DOWN), |
| 118 |
PAD_FUNC(SPI0_CSB, SPINOR_CS, GPIO_PULL_UP), |
| 119 |
PAD_FUNC(SPI0_MO, SPINOR_IO0, GPIO_PULL_DOWN), |
| 120 |
PAD_FUNC(SPI0_MI, SPINOR_IO1, GPIO_PULL_DOWN), |
| 121 |
}, |
| 122 |
|
| 123 |
[SPI_NOR_GPIO_SET1] = { |
| 124 |
PAD_FUNC(TDM_RX_BCK, SPINOR_CK, GPIO_PULL_DOWN), |
| 125 |
PAD_FUNC(TDM_RX_MCLK, SPINOR_CS, GPIO_PULL_UP), |
| 126 |
PAD_FUNC(TDM_RX_DATA0, SPINOR_IO0, GPIO_PULL_DOWN), |
| 127 |
PAD_FUNC(TDM_RX_DATA1, SPINOR_IO1, GPIO_PULL_DOWN), |
| 128 |
}, |
| 129 |
}; |
| 130 |
|
| 131 |
void mtk_snfc_init(int gpio_set) |
| 132 |
{ |
| 133 |
const struct pad_func *ptr = NULL; |
| 134 |
|
| 135 |
assert(gpio_set < SPI_NOR_GPIO_SET_NUM); |
| 136 |
|
| 137 |
ptr = nor_pinmux[gpio_set]; |
| 138 |
for (size_t i = 0; i < ARRAY_SIZE(nor_pinmux[gpio_set]); i++) { |
| 139 |
gpio_set_pull(ptr[i].gpio, GPIO_PULL_ENABLE, ptr[i].select); |
| 140 |
gpio_set_mode(ptr[i].gpio, ptr[i].func); |
| 141 |
|
| 142 |
if (gpio_set_driving(ptr[i].gpio, GPIO_DRV_8_MA) < 0) |
| 143 |
printk(BIOS_WARNING, |
| 144 |
"%s: failed to set pin drive to 8 mA for %d\n", |
| 145 |
__func__, ptr[i].gpio.id); |
| 146 |
else |
| 147 |
printk(BIOS_DEBUG, "%s: got pin drive: %#x\n", __func__, |
| 148 |
gpio_get_driving(ptr[i].gpio)); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
void mtk_spi_set_gpio_pinmux(unsigned int bus, enum spi_pad_mask pad_select) |
| 153 |
{ |
| 154 |
assert(bus < SPI_BUS_NUMBER); |
| 155 |
const struct pad_func *ptr; |
| 156 |
|
| 157 |
if (pad_select == SPI_PAD0_MASK) { |
| 158 |
ptr = pad0_funcs[bus]; |
| 159 |
} else { |
| 160 |
assert((bus == 0 || bus == 1 || bus == 2 || bus == 4) && |
| 161 |
pad_select == SPI_PAD1_MASK); |
| 162 |
ptr = pad1_funcs[bus]; |
| 163 |
} |
| 164 |
for (int i = 0; i < 4; i++) |
| 165 |
gpio_set_mode(ptr[i].gpio, ptr[i].func); |
| 166 |
} |
| 167 |
|
| 168 |
static const struct spi_ctrlr spi_flash_ctrlr = { |
| 169 |
.max_xfer_size = 65535, |
| 170 |
.flash_probe = mtk_spi_flash_probe, |
| 171 |
}; |
| 172 |
|
| 173 |
const struct spi_ctrlr_buses spi_ctrlr_bus_map[] = { |
| 174 |
{ |
| 175 |
.ctrlr = &spi_ctrlr, |
| 176 |
.bus_start = 0, |
| 177 |
.bus_end = SPI_BUS_NUMBER - 1, |
| 178 |
}, |
| 179 |
{ |
| 180 |
.ctrlr = &spi_flash_ctrlr, |
| 181 |
.bus_start = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, |
| 182 |
.bus_end = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, |
| 183 |
}, |
| 184 |
}; |
| 185 |
|
| 186 |
const size_t spi_ctrlr_bus_map_count = ARRAY_SIZE(spi_ctrlr_bus_map); |