Skip to content

Commit 693c5d0

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 e0eaa56 commit 693c5d0

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
@@ -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,
@@ -847,6 +840,25 @@ static bool ot_spi_device_is_mailbox_en(const OtSPIDeviceState *s)
847840
return (bool)(s->spi_regs[R_CFG] & R_CFG_MAILBOX_EN_MASK);
848841
}
849842

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

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

0 commit comments

Comments
 (0)