| 1 |
|
| 2 |
|
| 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> |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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) |
| 25 |
|
| 26 |
static struct spi_sdcard card; |
| 27 |
|
| 28 |
|
| 29 |
static struct mem_region_device spi_mdev = |
| 30 |
MEM_REGION_DEV_RO_INIT((void *)0x20000000, CONFIG_ROM_SIZE); |
| 31 |
|
| 32 |
static ssize_t unleashed_sd_readat(const struct region_device *rdev, void *dest, |
| 33 |
size_t offset, size_t count) |
| 34 |
{ |
| 35 |
spi_sdcard_read(&card, dest, offset, count); |
| 36 |
return count; |
| 37 |
} |
| 38 |
|
| 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, |
| 43 |
}; |
| 44 |
|
| 45 |
static struct mmap_helper_region_device sd_mdev = |
| 46 |
MMAP_HELPER_DEV_INIT(&unleashed_sd_ops, 0, CONFIG_ROM_SIZE, &cbfs_cache); |
| 47 |
|
| 48 |
const struct region_device *boot_device_ro(void) |
| 49 |
{ |
| 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; |
| 57 |
} |
| 58 |
|
| 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 |
| 68 |
}; |
| 69 |
|
| 70 |
void boot_device_init(void) |
| 71 |
{ |
| 72 |
uint32_t m = read32((uint32_t *)FU540_MSEL); |
| 73 |
if (MSEL_SPI0x1(m) || MSEL_SPI0x4(m)) { |
| 74 |
struct spi_slave slave; |
| 75 |
|
| 76 |
spi_setup_slave(0, 0, &slave); |
| 77 |
|
| 78 |
fu540_spi_mmap(&slave, &spi_mmap_config); |
| 79 |
return; |
| 80 |
} |
| 81 |
if (MSEL_SPI2SD(m)) { |
| 82 |
spi_sdcard_init(&card, 2, 0); |
| 83 |
return; |
| 84 |
} |
| 85 |
die("Wrong configuration of MSEL\n"); |
| 86 |
} |