Skip to content

Commit 0eedbc8

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 99015c5 commit 0eedbc8

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,6 @@ typedef enum {
375375
CTRL_MODE_INVALID,
376376
} OtSpiDeviceMode;
377377

378-
typedef enum {
379-
ADDR_MODE_ADDRDISABLED,
380-
ADDR_MODE_ADDRCFG,
381-
ADDR_MODE_ADDR3B,
382-
ADDR_MODE_ADDR4B,
383-
} OtSpiDeviceAddrMode;
384-
385378
typedef enum {
386379
SPI_BUS_IDLE,
387380
SPI_BUS_FLASH,
@@ -845,6 +838,25 @@ static bool ot_spi_device_is_mailbox_en(const OtSPIDeviceState *s)
845838
return (bool)(s->spi_regs[R_CFG] & R_CFG_MAILBOX_EN_MASK);
846839
}
847840

841+
static unsigned
842+
ot_spi_device_get_command_address_size(const OtSPIDeviceState *s)
843+
{
844+
const SpiDeviceFlash *f = &s->flash;
845+
846+
switch (SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE)) {
847+
case 0x0u: /* AddrDisabled */
848+
return 0u;
849+
case 0x1u: /* AddrCfg */
850+
return ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
851+
case 0x2u: /* Addr3B */
852+
return 3u;
853+
case 0x3u: /* Addr4B */
854+
return 4u;
855+
default:
856+
g_assert_not_reached();
857+
}
858+
}
859+
848860
static bool
849861
ot_spi_device_is_mailbox_match(const OtSPIDeviceState *s, uint32_t addr)
850862
{
@@ -1303,29 +1315,10 @@ static void ot_spi_device_flash_decode_sw_command(OtSPIDeviceState *s)
13031315
{
13041316
SpiDeviceFlash *f = &s->flash;
13051317

1306-
unsigned addr_count;
1307-
uint32_t addr_mode = SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE);
1308-
switch ((int)addr_mode) {
1309-
case ADDR_MODE_ADDRDISABLED:
1310-
addr_count = 0;
1311-
break;
1312-
case ADDR_MODE_ADDRCFG:
1313-
addr_count = ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
1314-
break;
1315-
case ADDR_MODE_ADDR3B:
1316-
addr_count = 3u;
1317-
break;
1318-
case ADDR_MODE_ADDR4B:
1319-
addr_count = 4u;
1320-
break;
1321-
default:
1322-
g_assert_not_reached();
1323-
break;
1324-
}
1325-
1326-
f->pos = 0;
1327-
if (addr_count != 0) {
1328-
f->len = addr_count;
1318+
unsigned addr_size = ot_spi_device_get_command_address_size(s);
1319+
f->pos = 0u;
1320+
if (addr_size != 0u) {
1321+
f->len = addr_size;
13291322
FLASH_CHANGE_STATE(s, UP_ADDR);
13301323
} else if (f->cmd_info & CMD_INFO_DUMMY_EN_MASK) {
13311324
f->len = 1u;

0 commit comments

Comments
 (0)