From f43c654ad0dcb11b2738bbfac9246d09bb1949e5 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 14 Oct 2017 17:47:28 +0200 Subject: spi25: Integrate 4BA support Allow 4-byte addresses for instructions usually used with 3-byte addresses. Decide in which way the 4th byte will be communicated based on the state of the chip (i.e. have we enabled 4BA mode) and a new feature bit for an extended address register. If we are not in 4BA mode and no extended address register is available or the write to it fails, bail out. We cache the state of 4BA mode and the extended address register in the flashctx. Change-Id: I644600beaab9a571b97b67f7516abe571d3460c1 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/22384 Reviewed-by: Stefan Reinauer Tested-by: build bot (Jenkins) --- spi4ba.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'spi4ba.c') diff --git a/spi4ba.c b/spi4ba.c index a44e0674..902f0730 100644 --- a/spi4ba.c +++ b/spi4ba.c @@ -39,12 +39,17 @@ /* Enter 4-bytes addressing mode (without sending WREN before) */ int spi_enter_4ba_b7(struct flashctx *flash) { + int result; const unsigned char cmd[JEDEC_ENTER_4_BYTE_ADDR_MODE_OUTSIZE] = { JEDEC_ENTER_4_BYTE_ADDR_MODE }; msg_trace("-> %s\n", __func__); /* Switch to 4-bytes addressing mode */ - return spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); + result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); + if (!result) + flash->in_4ba_mode = true; + + return result; } /* Enter 4-bytes addressing mode with sending WREN before */ @@ -75,18 +80,25 @@ int spi_enter_4ba_b7_we(struct flashctx *flash) result = spi_send_multicommand(flash, cmds); if (result) msg_cerr("%s failed during command execution\n", __func__); + else + flash->in_4ba_mode = true; return result; } /* Exit 4-bytes addressing mode (without sending WREN before) */ int spi_exit_4ba_e9(struct flashctx *flash) { + int result; const unsigned char cmd[JEDEC_EXIT_4_BYTE_ADDR_MODE_OUTSIZE] = { JEDEC_EXIT_4_BYTE_ADDR_MODE }; msg_trace("-> %s\n", __func__); /* Switch to 3-bytes addressing mode */ - return spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); + result = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL); + if (!result) + flash->in_4ba_mode = false; + + return result; } /* Exit 4-bytes addressing mode with sending WREN before */ @@ -115,9 +127,10 @@ int spi_exit_4ba_e9_we(struct flashctx *flash) /* Switch to 3-bytes addressing mode */ result = spi_send_multicommand(flash, cmds); - if (result) { + if (result) msg_cerr("%s failed during command execution\n", __func__); - } + else + flash->in_4ba_mode = false; return result; } -- cgit v1.2.3