Skip to content

Commit 8b0a02a

Browse files
committed
[ot] hw/opentitan: ot_spi_device: move address size to own function
... and removes `OtSpiDeviceAddrMode`. `ot_spi_device_get_command_address_size` now returns the size of the address field in the current command, using the value in `cmd_info` and the current 4B enable state. Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent e4c52bd commit 8b0a02a

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,6 @@ typedef enum {
362362
CTRL_MODE_INVALID,
363363
} OtSpiDeviceMode;
364364

365-
typedef enum {
366-
ADDR_MODE_ADDRDISABLED,
367-
ADDR_MODE_ADDRCFG,
368-
ADDR_MODE_ADDR3B,
369-
ADDR_MODE_ADDR4B,
370-
} OtSpiDeviceAddrMode;
371-
372365
typedef enum {
373366
SPI_BUS_IDLE,
374367
SPI_BUS_FLASH,
@@ -771,6 +764,25 @@ static bool ot_spi_device_is_mailbox_en(const OtSPIDeviceState *s)
771764
return (bool)(s->spi_regs[R_CFG] & R_CFG_MAILBOX_EN_MASK);
772765
}
773766

767+
static unsigned
768+
ot_spi_device_get_command_address_size(const OtSPIDeviceState *s)
769+
{
770+
const SpiDeviceFlash *f = &s->flash;
771+
772+
switch (SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE)) {
773+
case 0: /* AddrDisabled */
774+
return 0u;
775+
case 0x1u: /* AddrCfg */
776+
return ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
777+
case 0x2u: /* Addr3B */
778+
return 3u;
779+
case 0x3u: /* Addr4B */
780+
return 4u;
781+
default:
782+
g_assert_not_reached();
783+
}
784+
}
785+
774786
static bool
775787
ot_spi_device_is_mailbox_match(const OtSPIDeviceState *s, uint32_t addr)
776788
{
@@ -1229,29 +1241,10 @@ static void ot_spi_device_flash_decode_sw_command(OtSPIDeviceState *s)
12291241
{
12301242
SpiDeviceFlash *f = &s->flash;
12311243

1232-
unsigned addr_count;
1233-
uint32_t addr_mode = SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE);
1234-
switch ((int)addr_mode) {
1235-
case ADDR_MODE_ADDRDISABLED:
1236-
addr_count = 0;
1237-
break;
1238-
case ADDR_MODE_ADDRCFG:
1239-
addr_count = ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
1240-
break;
1241-
case ADDR_MODE_ADDR3B:
1242-
addr_count = 3u;
1243-
break;
1244-
case ADDR_MODE_ADDR4B:
1245-
addr_count = 4u;
1246-
break;
1247-
default:
1248-
g_assert_not_reached();
1249-
break;
1250-
}
1251-
1244+
unsigned addr_size = ot_spi_device_get_command_address_size(s);
12521245
f->pos = 0;
1253-
if (addr_count != 0) {
1254-
f->len = addr_count;
1246+
if (addr_size != 0) {
1247+
f->len = addr_size;
12551248
FLASH_CHANGE_STATE(s, UP_ADDR);
12561249
} else if (f->cmd_info & CMD_INFO_DUMMY_EN_MASK) {
12571250
f->len = 1u;

0 commit comments

Comments
 (0)