Skip to content

Commit 5f6e84e

Browse files
committed
[ot] hw/opentitan: clkmgr,spi_host: earlgrey-1.0.0 backcompat defs
Earlgrey 1.0.0 uses SPI Host V2, not V3, which has breaking changes to the size and locations of the field in the SPI Host command register. This can just be adapted by changing the field definitions; the command length in earlgrey-1.0.0 is smaller and so the rest of the code is backwards-compatible. For the clkmgr, there was a known RTL bug in 1.0.0 where the jitter enable register was not actually protected by its respective REGWEN register. This replicates that behaviour for correct testing on the earlgrey-1.0.0 branch. Signed-off-by: Alex Jones <alex.jones@lowrisc.org>
1 parent 3d24136 commit 5f6e84e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

hw/opentitan/ot_clkmgr.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#define PARAM_NUM_HINTABLE_CLOCKS 4u
4646
#define PARAM_NUM_ALERTS 2u
4747

48+
/* undef to build for `master`, not for Earlgrey 1.0 */
49+
#define OT_IS_EARLGREY_V1_0_0
50+
4851
/* clang-format off */
4952
REG32(ALERT_TEST, 0x0u)
5053
FIELD(ALERT_TEST, RECOV_FAULT, 0u, 1u)
@@ -341,13 +344,22 @@ static void ot_clkmgr_write(void *opaque, hwaddr addr, uint64_t val64,
341344
s->regs[reg] &= val32;
342345
break;
343346
case R_JITTER_ENABLE:
344-
if (s->regs[R_JITTER_REGWEN]) {
347+
#ifdef OT_IS_EARLGREY_V1_0_0
348+
/*
349+
* There is a known bug in Earlgrey 1.0.0, where the Clkmgr Jitter Enable
350+
* REGWEN was not properly connected, meaning it is unused here.
351+
*/
352+
val32 &= R_JITTER_ENABLE_VAL_MASK;
353+
s->regs[reg] = val32;
354+
#else
355+
if (s->regs[R_JITTER_REGWEN]) {
345356
val32 &= R_JITTER_ENABLE_VAL_MASK;
346357
s->regs[reg] = val32;
347358
} else {
348359
qemu_log_mask(LOG_GUEST_ERROR,
349360
"%s: JITTER_ENABLE protected w/ REGWEN\n", __func__);
350361
}
362+
#endif
351363
break;
352364
case R_CLK_ENABLES:
353365
val32 &= CLK_ENABLES_MASK;

hw/opentitan/ot_spi_host.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
#define RXFIFO_LEN 256U /* bytes */
6767
#define CMDFIFO_LEN 4U /* slots */
6868

69+
/* undef to build for `master`, not for Earlgrey 1.0 */
70+
#define OT_IS_EARLGREY_V1_0_0
71+
6972
/* ------------------------------------------------------------------------ */
7073
/* Register definitions */
7174
/* ------------------------------------------------------------------------ */
@@ -110,10 +113,17 @@ REG32(CONFIGOPTS, 0x18u)
110113
REG32(CSID, 0x1cu)
111114
FIELD(CSID, CSID, 0u, 32u)
112115
REG32(COMMAND, 0x20u)
116+
#ifdef OT_IS_EARLGREY_V1_0_0
117+
FIELD(COMMAND, LEN, 0u, 9u)
118+
FIELD(COMMAND, CSAAT, 9u, 1u)
119+
FIELD(COMMAND, SPEED, 10u, 2u)
120+
FIELD(COMMAND, DIRECTION, 12u, 2u)
121+
#else
113122
FIELD(COMMAND, CSAAT, 0u, 1u)
114123
FIELD(COMMAND, SPEED, 1u, 2u)
115124
FIELD(COMMAND, DIRECTION, 3u, 2u)
116125
FIELD(COMMAND, LEN, 5u, 20u)
126+
#endif
117127
REG32(RXDATA, 0x24u)
118128
REG32(TXDATA, 0x28u)
119129
REG32(ERROR_ENABLE, 0x2cu)

0 commit comments

Comments
 (0)