Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport [sival, spi] Passthru #23044

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hw/top_earlgrey/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ silicon(
name = "silicon_owner_sival_rom_ext",
testonly = True,
args = [
"--rcfile=",
"--rcfile=__builtin__/hyperdebug_teacup.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an error.
--rcfile=... tells opentitantool which user-level config file to read, which contains commandline options like --interface=foo that the user would like set by default.

As far as I recall, --rcfile cannot parse a JSON file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right. I'll file a PR fixing it.

"--logging=info",
"--interface={interface}",
],
Expand Down
5 changes: 2 additions & 3 deletions hw/top_earlgrey/data/ip/chip_spi_device_testplan.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
"SPI_DEVICE.MODE.PASSTHROUGH.CMD_FILTER",
]
tests: ["chip_sw_spi_device_pass_through"]
bazel: []
bazel: ["//sw/device/tests:spi_passthru_test"]
}

{
name: chip_sw_spi_device_pass_through_flash_model
desc: '''Verify the command filtering mechanism in passthrough mode.
Expand All @@ -80,7 +79,7 @@
"SPI_DEVICE.HW.LANES",
"SPI_DEVICE.MODE.PASSTHROUGH.CMD_FILTER",
]
tests: []
tests: ["//sw/device/tests:spi_passthru_test"]
}
{
name: chip_sw_spi_device_pass_through_collision
Expand Down
2 changes: 1 addition & 1 deletion hw/top_earlgrey/data/ip/chip_spi_host_testplan.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
stage: V3
si_stage: SV3
lc_states: ["PROD"]
tests: []
tests: ["//sw/device/tests:spi_passthru_test"]
}
{
name: chip_sw_spi_host_configuration
Expand Down
20 changes: 15 additions & 5 deletions sw/device/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4199,11 +4199,14 @@ opentitan_test(
""",
test_harness = "//sw/host/tests/chip/spi_passthru",
),
exec_env = {
"//hw/top_earlgrey:fpga_cw310_test_rom": None,
"//hw/top_earlgrey:fpga_cw310_sival_rom_ext": "hyper310",
"//hw/top_earlgrey:fpga_hyper310_rom_ext": "hyper310",
},
exec_env = dicts.add(
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
{
"//hw/top_earlgrey:fpga_cw310_test_rom": None,
"//hw/top_earlgrey:fpga_cw310_sival_rom_ext": "hyper310",
"//hw/top_earlgrey:fpga_hyper310_rom_ext": "hyper310",
},
),
hyper310 = cw310_params(
tags = ["manual"], # TODO: QE bit handling
test_cmd = """
Expand All @@ -4212,9 +4215,16 @@ opentitan_test(
""",
test_harness = "//sw/host/tests/chip/spi_passthru",
),
silicon = silicon_params(
test_cmd = """
--bootstrap="{firmware}"
""",
test_harness = "//sw/host/tests/chip/spi_passthru",
),
deps = [
"//sw/device/lib/arch:device",
"//sw/device/lib/dif:gpio",
"//sw/device/lib/dif:pinmux",
"//sw/device/lib/dif:spi_device",
"//sw/device/lib/testing:spi_device_testutils",
"//sw/device/lib/testing:spi_flash_testutils",
Expand Down
35 changes: 35 additions & 0 deletions sw/device/tests/spi_passthru_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "sw/device/lib/arch/device.h"
#include "sw/device/lib/base/status.h"
#include "sw/device/lib/dif/dif_pinmux.h"
#include "sw/device/lib/dif/dif_spi_device.h"
#include "sw/device/lib/dif/dif_spi_host.h"
#include "sw/device/lib/runtime/log.h"
Expand Down Expand Up @@ -240,6 +241,40 @@ status_t command_processor(ujson_t *uj) {
}

bool test_main(void) {
if (kDeviceType == kDeviceSilicon) {
// On teacup board, we need to enable pull-ups on the pins connected to `WP`
// and `HOLD`.
dif_pinmux_t pinmux;
mmio_region_t base_addr =
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR);
CHECK_DIF_OK(dif_pinmux_init(base_addr, &pinmux));

dif_pinmux_pad_attr_t out_attr;
dif_pinmux_pad_attr_t in_attr = {
.slew_rate = 1,
.drive_strength = 3,
.flags = kDifPinmuxPadAttrPullResistorEnable |
kDifPinmuxPadAttrPullResistorUp};

CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyDirectPadsSpiHost0Sck,
kDifPinmuxPadKindDio, in_attr, &out_attr));
CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyDirectPadsSpiHost0Sd0,
kDifPinmuxPadKindDio, in_attr, &out_attr));
CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyDirectPadsSpiHost0Sd1,
kDifPinmuxPadKindDio, in_attr, &out_attr));

CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyDirectPadsSpiHost0Sd2,
kDifPinmuxPadKindDio, in_attr, &out_attr));

CHECK_DIF_OK(
dif_pinmux_pad_write_attrs(&pinmux, kTopEarlgreyDirectPadsSpiHost0Sd3,
kDifPinmuxPadKindDio, in_attr, &out_attr));
}

const uint32_t spi_host_clock_freq_hz =
(uint32_t)kClockFreqHiSpeedPeripheralHz;
CHECK_DIF_OK(dif_spi_host_init(
Expand Down
10 changes: 5 additions & 5 deletions sw/host/opentitanlib/src/app/config/hyperdebug_teacup.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@
{
"name": "SPI_TPM",
"pins": [
{
"name": "SPI_MUX_SEL",
"level": true,
},
{
"name": "SPI_MUX_SEL",
"level": true
},
{
"name": "SPI1_SCK",
"mode": "Alternate"
Expand All @@ -417,5 +417,5 @@
}
]
}
],
]
}