mainboard/intel/avenuecity_crb: Update full IIO configuration
[coreboot2.git] / src / mainboard / sifive / hifive-unleashed / media.c
bloba225dda9e921a59b38c5c45d5eef2d92bb550782
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <boot_device.h>
4 #include <cbfs.h>
5 #include <symbols.h>
6 #include <device/mmio.h>
7 #include <soc/addressmap.h>
8 #include <soc/spi.h>
9 #include <soc/clock.h>
10 #include <console/console.h>
11 #include <spi_sdcard.h>
13 /* follow is the FSBL boot device defined by ZSBL of sifive
14 * FSBL replaced by bootblock of coreboot
15 * MSEL_SPInx1 -> test if boot from memory-mapped on SPIn
16 * MSEL_SPInx4 -> test if boot from memory-mapped on QPIn
17 * MSEL_SPInSD -> test if boot from sdcard mount on SPIn */
18 #define MSEL_SPI0x1(m) (((m) == 5) || ((m) == 14))
19 #define MSEL_SPI0x4(m) (((m) == 6) || ((m) == 10) || ((m) == 15))
20 #define MSEL_SPI1x1(m) ((m) == 12)
21 #define MSEL_SPI1x4(m) (((m) == 7) || ((m) == 13))
22 #define MSEL_SPI1SD(m) ((m) == 8)
23 #define MSEL_SPI2x1(m) ((m) == 9)
24 #define MSEL_SPI2SD(m) ((m) == 11)
26 static struct spi_sdcard card;
28 /* At 0x20000000: A 256MiB long memory-mapped view of the flash at QSPI0 */
29 static struct mem_region_device spi_mdev =
30 MEM_REGION_DEV_RO_INIT((void *)0x20000000, CONFIG_ROM_SIZE);
32 static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest,
33 size_t offset, size_t count)
35 spi_sdcard_read(&card, dest, offset, count);
36 return count;
39 static const struct region_device_ops unleashed_sd_ops = {
40 .mmap = mmap_helper_rdev_mmap,
41 .munmap = mmap_helper_rdev_munmap,
42 .readat = unleashed_sd_readat,
45 static struct mmap_helper_region_device sd_mdev =
46 MMAP_HELPER_DEV_INIT(&unleashed_sd_ops, 0, CONFIG_ROM_SIZE, &cbfs_cache);
48 const struct region_device *boot_device_ro(void)
50 uint32_t m = read32((uint32_t *)FU540_MSEL);
51 if (MSEL_SPI0x1(m) || MSEL_SPI0x4(m))
52 return &spi_mdev.rdev;
53 if (MSEL_SPI2SD(m))
54 return &sd_mdev.rdev;
55 die("Wrong configuration of MSEL\n");
56 return NULL;
59 static const struct fu540_spi_mmap_config spi_mmap_config = {
60 .cmd_en = 1,
61 .addr_len = 4,
62 .pad_cnt = 6,
63 .cmd_proto = FU540_SPI_PROTO_S,
64 .addr_proto = FU540_SPI_PROTO_Q,
65 .data_proto = FU540_SPI_PROTO_Q,
66 .cmd_code = 0xec,
67 .pad_code = 0
70 void boot_device_init(void)
72 uint32_t m = read32((uint32_t *)FU540_MSEL);
73 if (MSEL_SPI0x1(m) || MSEL_SPI0x4(m)) {
74 struct spi_slave slave;
75 /* initialize spi controller */
76 spi_setup_slave(0, 0, &slave);
77 /* map flash to memory space */
78 fu540_spi_mmap(&slave, &spi_mmap_config);
79 return;
81 if (MSEL_SPI2SD(m)) {
82 spi_sdcard_init(&card, 2, 0);
83 return;
85 die("Wrong configuration of MSEL\n");