5 #if defined(OPENTITAN_IS_EARLGREY)
6 #include "dt/dt_usbdev.h"
9 #include "usbdev_regs.h"
10 #elif defined(OPENTITAN_IS_DARJEELING)
13 #error "rstmgr_sw_rst_ctrl_test does not support this top"
16 #include "dt/dt_i2c.h"
17 #include "dt/dt_rstmgr.h"
18 #include "dt/dt_spi_device.h"
19 #include "dt/dt_spi_host.h"
29 #include "sw/device/lib/testing/test_framework/check.h"
33 #include "spi_device_regs.h"
34 #include "spi_host_regs.h"
36 OTTF_DEFINE_TEST_CONFIG();
75 #define MAKE_INIT_FUNC(ip_) \
76 void ip_##_init(void *ip_, int32_t dt) { \
77 CHECK_DIF_OK(dif##_##ip_##_init_from_dt((dt_##ip_##_t)dt, ip_)); \
80 #define MAKE_BASE_ADDR_FUNC(ip_) \
81 uintptr_t ip_##_base_addr(int32_t dt, int32_t reg_block) { \
82 return dt_##ip_##_reg_block((dt_##ip_##_t)dt, \
83 (dt_##ip_##_reg_block_t)reg_block); \
86 #define MAKE_RSTMGR_RESET_FUNC(ip_) \
87 dt_reset_t ip_##_rstmgr_reset(int32_t dt, int32_t device_reset) { \
88 return dt_##ip_##_reset((dt_##ip_##_t)dt, \
89 (dt_##ip_##_reset_t)device_reset); \
92 #define MAKE_TEST_FUNCS(ip_) \
93 MAKE_INIT_FUNC(ip_); \
94 MAKE_BASE_ADDR_FUNC(ip_); \
95 MAKE_RSTMGR_RESET_FUNC(ip_);
97 #if defined(OT_HAS_USBDEV)
98 MAKE_TEST_FUNCS(usbdev);
101 MAKE_TEST_FUNCS(spi_device);
102 MAKE_TEST_FUNCS(spi_host);
103 MAKE_TEST_FUNCS(i2c);
105 static void spi_device_config(
void *dif) {
106 uintptr_t handle_address =
117 static void spi_host0_config(
void *dif) {
120 .peripheral_clock_freq_hz = 1000000,
134 #if defined(OPENTITAN_IS_EARLGREY)
135 static void spi_host1_config(
void *dif) {
137 .spi_clock = 2500000,
138 .peripheral_clock_freq_hz = 5000000,
151 #elif defined(OPENTITAN_IS_DARJEELING)
154 #error "rstmgr_sw_rst_ctrl_test does not support this top"
157 static void i2c0_config(
void *dif) {
159 .scl_time_high_cycles = 3326,
160 .scl_time_low_cycles = 2224,
165 #if defined(OPENTITAN_IS_EARLGREY)
166 static void i2c1_config(
void *dif) {
174 static void i2c2_config(
void *dif) {
176 .start_signal_setup_cycles = 5525,
177 .start_signal_hold_cycles = 6636,
181 #elif defined(OPENTITAN_IS_DARJEELING)
184 #error "rstmgr_sw_rst_ctrl_test does not support this top"
188 static dif_spi_host_t spi_host0;
189 static dif_i2c_t i2c0;
191 #if defined(OPENTITAN_IS_EARLGREY)
192 static dif_spi_host_t spi_host1;
193 static dif_usbdev_t usbdev;
194 static dif_i2c_t i2c1;
195 static dif_i2c_t i2c2;
196 #elif defined(OPENTITAN_IS_DARJEELING)
200 #error "rstmgr_sw_rst_ctrl_test does not support this top"
203 typedef struct test {
262 static const test_t kPeripherals[] = {
264 .
name =
"SPI_DEVICE",
265 .get_base_address = spi_device_base_addr,
266 .dt = (dt_spi_device_t)0,
267 .reg_block = kDtSpiDeviceRegBlockCore,
268 .offset = SPI_DEVICE_CFG_REG_OFFSET,
270 .init = spi_device_init,
271 .config = spi_device_config,
272 .program_val = 0x3f0c,
273 .reset_index = kDtSpiDeviceResetRst,
274 .get_rstmgr_rst_index = spi_device_rstmgr_reset,
278 .get_base_address = spi_host_base_addr,
279 .dt = (dt_spi_host_t)0,
280 .reg_block = kDtSpiHostRegBlockCore,
281 .offset = SPI_HOST_CONFIGOPTS_REG_OFFSET,
283 .init = spi_host_init,
284 .config = spi_host0_config,
285 .program_val = 0x3210000,
286 .reset_index = kDtSpiHostResetRst,
287 .get_rstmgr_rst_index = spi_host_rstmgr_reset,
289 #if defined(OPENTITAN_IS_EARLGREY)
292 .get_base_address = spi_host_base_addr,
293 .dt = (dt_spi_host_t)1,
294 .reg_block = kDtSpiHostRegBlockCore,
295 .offset = SPI_HOST_CONFIGOPTS_REG_OFFSET,
297 .init = spi_host_init,
298 .config = spi_host1_config,
299 .program_val = 0x6540000,
300 .reset_index = kDtSpiHostResetRst,
301 .get_rstmgr_rst_index = spi_host_rstmgr_reset,
305 .get_base_address = usbdev_base_addr,
306 .dt = (dt_usbdev_t)0,
307 .reg_block = kDtUsbdevRegBlockCore,
308 .offset = USBDEV_EP_OUT_ENABLE_REG_OFFSET,
312 .reset_index = kDtUsbdevResetRst,
313 .get_rstmgr_rst_index = usbdev_rstmgr_reset,
315 #elif defined(OPENTITAN_IS_DARJEELING)
318 #error "rstmgr_sw_rst_ctrl_test does not support this top"
322 .get_base_address = i2c_base_addr,
323 .reg_block = kDtI2cRegBlockCore,
325 .offset = I2C_TIMING0_REG_OFFSET,
328 .config = i2c0_config,
329 .program_val = 0x8b00cfe,
330 .reset_index = kDtI2cResetRst,
331 .get_rstmgr_rst_index = i2c_rstmgr_reset,
333 #if defined(OPENTITAN_IS_EARLGREY)
336 .get_base_address = i2c_base_addr,
338 .reg_block = kDtI2cRegBlockCore,
339 .offset = I2C_TIMING1_REG_OFFSET,
342 .config = i2c1_config,
343 .program_val = 0x114010d8,
344 .reset_index = kDtI2cResetRst,
345 .get_rstmgr_rst_index = i2c_rstmgr_reset,
349 .get_base_address = i2c_base_addr,
351 .reg_block = kDtI2cRegBlockCore,
352 .offset = I2C_TIMING2_REG_OFFSET,
355 .config = i2c2_config,
356 .program_val = 0x19ec1595,
357 .reset_index = kDtI2cResetRst,
358 .get_rstmgr_rst_index = i2c_rstmgr_reset,
360 #elif defined(OPENTITAN_IS_DARJEELING)
363 #error "rstmgr_sw_rst_ctrl_test does not support this top"
370 static uint32_t read_test_reg(
const test_t *
test) {
377 CHECK_DIF_OK(dif_rstmgr_init_from_dt(kDtRstmgrAon, &rstmgr));
379 #if defined(OT_HAS_USBDEV)
382 dt_reset_t reset = dt_usbdev_reset((dt_usbdev_t)0, kDtUsbdevResetRst);
383 size_t sw_reset_index;
390 uint32_t reset_vals[
ARRAYSIZE(kPeripherals)];
391 for (
size_t i = 0; i <
ARRAYSIZE(kPeripherals); ++i) {
392 if (kPeripherals[i].init != NULL) {
393 kPeripherals[i].
init(kPeripherals[i].dif, kPeripherals[i].dt);
395 reset_vals[i] = read_test_reg(&kPeripherals[i]);
396 LOG_INFO(
"reset_val for %s is 0x%08x", kPeripherals[i].name, reset_vals[i]);
399 for (
size_t i = 0; i <
ARRAYSIZE(kPeripherals); ++i) {
400 if (kPeripherals[i].config != NULL) {
401 kPeripherals[i].
config(kPeripherals[i].dif);
404 kPeripherals[i].dt, kPeripherals[i].reg_block);
406 kPeripherals[i].program_val);
411 uint32_t got = read_test_reg(&kPeripherals[i]);
412 LOG_INFO(
"programmed value : 0x%x", got);
415 for (
size_t i = 0; i <
ARRAYSIZE(kPeripherals); ++i) {
417 kPeripherals[i].dt, kPeripherals[i].reset_index);
418 size_t sw_reset_index;
424 uint32_t got = read_test_reg(&kPeripherals[i]);
425 CHECK(got == reset_vals[i],
426 "after configure: reset_val for %s mismatch: want 0x%x, got 0x%x",
427 kPeripherals[i].name, reset_vals[i], got);