From d31b1091e724b9d5934b7e8d3911abbe04b4afcd Mon Sep 17 00:00:00 2001 From: Ronald G Minnich Date: Thu, 15 Feb 2024 22:28:01 -0800 Subject: mb/sifive/sifive-unmatched: add support for spi1 x4 mode Tested on an unmatched, both SPI1 x1 and x4 work now. Change-Id: Ida7f195eb6e4fc85018ceb83cf317595127c4af5 Signed-off-by: Ronald G Minnich Reviewed-on: https://review.coreboot.org/c/coreboot/+/81031 Tested-by: build bot (Jenkins) Reviewed-by: Philipp Hug Reviewed-by: Felix Singer --- src/mainboard/sifive/hifive-unmatched/cbfs_spi.c | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/mainboard/sifive/hifive-unmatched/cbfs_spi.c b/src/mainboard/sifive/hifive-unmatched/cbfs_spi.c index 787d8e7af3..f47da22626 100644 --- a/src/mainboard/sifive/hifive-unmatched/cbfs_spi.c +++ b/src/mainboard/sifive/hifive-unmatched/cbfs_spi.c @@ -116,15 +116,34 @@ void boot_device_init(void) if (spi_flash_init_done == true) return; - uint32_t m = read32((uint32_t *)FU740_MSEL); + uint32_t m = read32((uint32_t *)FU740_MSEL) & 0xf; + printk(BIOS_DEBUG, "%s MSEL %#x\n", __func__, m); + + // We have not yet found a way to reliably program the + // on-board SPI part (sifive neglected to put a diode on vcc ...) + // Once we work that out, we can test this code. + // It is left here as a hint of what needs to be done. // Pass the information of the flash read operation to the spi controller - //.pad_cnt = 6, - if (MSEL_SPI0x4(m) || MSEL_SPI1x4(m)) { + if (MSEL_SPI0x4(m)) { + die("SPI0x4 is not supported yet"); //config.ffmt_config.data_proto = FU740_SPI_PROTO_Q; //config.ffmt_config.cmd_code = 0x6B; // Quad output read //.cmd_code = 0xec, + //.pad_cnt = 6, } - if (MSEL_SPI1x1(m)) { + if (MSEL_SPI1x4(m)) { + printk(BIOS_DEBUG, "%s SPI1x4 1\n", __func__); + fu740_spi_configs[1].ffmt_config.data_proto = FU740_SPI_PROTO_Q; + fu740_spi_configs[1].ffmt_config.cmd_code = 0x6b; // quad + if (spi_flash_probe(1, 0, &spi_flash)) { + printk(BIOS_EMERG, "SPI1x4 failed to init SPI flash\n"); + return; + } + if (fu740_spi_setup(&spi_flash.spi) == -1) { + printk(BIOS_EMERG, "SPI1x4 failed to configure mmap for SPI flash\n"); + } + printk(BIOS_DEBUG, "%s SPI1x4 2\n", __func__); + } else if (MSEL_SPI1x1(m)) { printk(BIOS_DEBUG, "%s 1\n", __func__); fu740_spi_configs[1].ffmt_config.data_proto = FU740_SPI_PROTO_S; fu740_spi_configs[1].ffmt_config.cmd_code = 0x03; // Normal read @@ -133,17 +152,12 @@ void boot_device_init(void) printk(BIOS_EMERG, "failed to init SPI flash\n"); return; } - // initialize soc spi controller - //if (fu740_spi_setup(&spi1_flash.spi) == -1) { - // printk(BIOS_EMERG, "failed to configure mmap for SPI flash\n"); - //} - //hexdump((void*)0x10041000, 0x100); - //hexdump((void*)0x30000000, 0x100); printk(BIOS_DEBUG, "%s 2\n", __func__); } else if (MSEL_SPI2SD(m)) { spi_sdcard_init(&spi2_sdcard, 2, 0); } else { - die("Wrong configuration of MSEL\n"); + printk(BIOS_EMERG, "MSEL: %#02x: ", m); + die("unsupported configuration of MSEL\n"); } spi_flash_init_done = true; -- cgit v1.2.3