Skip to content

Commit c32ae97

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 bd3014f commit c32ae97

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
@@ -358,13 +358,6 @@ typedef enum {
358358
CTRL_MODE_INVALID,
359359
} OtSpiDeviceMode;
360360

361-
typedef enum {
362-
ADDR_MODE_ADDRDISABLED,
363-
ADDR_MODE_ADDRCFG,
364-
ADDR_MODE_ADDR3B,
365-
ADDR_MODE_ADDR4B,
366-
} OtSpiDeviceAddrMode;
367-
368361
typedef enum {
369362
SPI_BUS_IDLE,
370363
SPI_BUS_FLASH,
@@ -809,6 +802,25 @@ static bool ot_spi_device_is_mailbox_en(const OtSPIDeviceState *s)
809802
return (bool)(s->spi_regs[R_CFG] & R_CFG_MAILBOX_EN_MASK);
810803
}
811804

805+
static unsigned
806+
ot_spi_device_get_command_address_size(const OtSPIDeviceState *s)
807+
{
808+
const SpiDeviceFlash *f = &s->flash;
809+
810+
switch (SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE)) {
811+
case 0x0u: /* AddrDisabled */
812+
return 0u;
813+
case 0x1u: /* AddrCfg */
814+
return ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
815+
case 0x2u: /* Addr3B */
816+
return 3u;
817+
case 0x3u: /* Addr4B */
818+
return 4u;
819+
default:
820+
g_assert_not_reached();
821+
}
822+
}
823+
812824
static bool
813825
ot_spi_device_is_mailbox_match(const OtSPIDeviceState *s, uint32_t addr)
814826
{
@@ -1280,29 +1292,10 @@ static void ot_spi_device_flash_decode_sw_command(OtSPIDeviceState *s)
12801292
{
12811293
SpiDeviceFlash *f = &s->flash;
12821294

1283-
unsigned addr_count;
1284-
uint32_t addr_mode = SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE);
1285-
switch ((int)addr_mode) {
1286-
case ADDR_MODE_ADDRDISABLED:
1287-
addr_count = 0;
1288-
break;
1289-
case ADDR_MODE_ADDRCFG:
1290-
addr_count = ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
1291-
break;
1292-
case ADDR_MODE_ADDR3B:
1293-
addr_count = 3u;
1294-
break;
1295-
case ADDR_MODE_ADDR4B:
1296-
addr_count = 4u;
1297-
break;
1298-
default:
1299-
g_assert_not_reached();
1300-
break;
1301-
}
1302-
1303-
f->pos = 0;
1304-
if (addr_count != 0) {
1305-
f->len = addr_count;
1295+
unsigned addr_size = ot_spi_device_get_command_address_size(s);
1296+
f->pos = 0u;
1297+
if (addr_size != 0u) {
1298+
f->len = addr_size;
13061299
FLASH_CHANGE_STATE(s, UP_ADDR);
13071300
} else if (f->cmd_info & CMD_INFO_DUMMY_EN_MASK) {
13081301
f->len = 1u;

0 commit comments

Comments
 (0)