Skip to content

Commit b7c3b04

Browse files
committed
[ot] hw/opentitan: ot_spi_device: move address size to own function
Also renames `ADDR_MODE_ADDR*` variants to `ADDR_MODE_*` Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 3b0066f commit b7c3b04

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

hw/opentitan/ot_spi_device.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ typedef enum {
362362
} OtSpiDeviceMode;
363363

364364
typedef enum {
365-
ADDR_MODE_ADDRDISABLED,
366-
ADDR_MODE_ADDRCFG,
367-
ADDR_MODE_ADDR3B,
368-
ADDR_MODE_ADDR4B,
365+
ADDR_MODE_DISABLED,
366+
ADDR_MODE_CFG,
367+
ADDR_MODE_3B,
368+
ADDR_MODE_4B,
369369
} OtSpiDeviceAddrMode;
370370

371371
typedef enum {
@@ -769,6 +769,24 @@ static bool ot_spi_device_is_mailbox_en(const OtSPIDeviceState *s)
769769
return (bool)(s->spi_regs[R_CFG] & R_CFG_MAILBOX_EN_MASK);
770770
}
771771

772+
static unsigned int ot_spi_device_get_address_size(const OtSPIDeviceState *s,
773+
OtSpiDeviceAddrMode mode)
774+
{
775+
switch (mode) {
776+
case ADDR_MODE_CFG:
777+
return ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
778+
case ADDR_MODE_4B:
779+
return 4u;
780+
case ADDR_MODE_3B:
781+
return 3u;
782+
case ADDR_MODE_DISABLED:
783+
return 0;
784+
default:
785+
g_assert_not_reached();
786+
break;
787+
}
788+
}
789+
772790
static bool
773791
ot_spi_device_is_mailbox_match(const OtSPIDeviceState *s, uint32_t addr)
774792
{
@@ -1243,25 +1261,9 @@ static void ot_spi_device_flash_decode_sw_command(OtSPIDeviceState *s)
12431261
{
12441262
SpiDeviceFlash *f = &s->flash;
12451263

1246-
unsigned addr_count;
1247-
uint32_t addr_mode = SHARED_FIELD_EX32(f->cmd_info, CMD_INFO_ADDR_MODE);
1248-
switch ((int)addr_mode) {
1249-
case ADDR_MODE_ADDRDISABLED:
1250-
addr_count = 0;
1251-
break;
1252-
case ADDR_MODE_ADDRCFG:
1253-
addr_count = ot_spi_device_is_addr4b_en(s) ? 4u : 3u;
1254-
break;
1255-
case ADDR_MODE_ADDR3B:
1256-
addr_count = 3u;
1257-
break;
1258-
case ADDR_MODE_ADDR4B:
1259-
addr_count = 4u;
1260-
break;
1261-
default:
1262-
g_assert_not_reached();
1263-
break;
1264-
}
1264+
unsigned int addr_count = ot_spi_device_get_address_size(
1265+
s, (OtSpiDeviceAddrMode)SHARED_FIELD_EX32(f->cmd_info,
1266+
CMD_INFO_ADDR_MODE));
12651267

12661268
f->pos = 0;
12671269
if (addr_count != 0) {

0 commit comments

Comments
 (0)