Skip to content

Commit 521a3c0

Browse files
engdoreispamaury
authored andcommitted
[ot] hw/opentitan: ot_usbdev: Initial implementation of the block
Signed-off-by: Douglas Reis <[email protected]> Signed-off-by: Amaury Pouly <[email protected]>
1 parent 75d7ae2 commit 521a3c0

File tree

12 files changed

+900
-9
lines changed

12 files changed

+900
-9
lines changed

docs/opentitan/earlgrey.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ There are two modes to handle address remapping, with different limitations:
269269
* `-device <name>,bus=<bus>,address=<address>` can be used to attach devices at a specific address
270270
to one of the three I2C buses. The buses are named `ot-i2c0`, `ot-i2c1`, and `ot-i2c2`.
271271

272+
### USBDEV
273+
274+
* `-chardev pty,id=usbdev` can be used to connect to the usbdev driver.
275+
* `-global ot-usbdev.vbus-mode=<mode>` can be used to select the VBUS mode.
276+
277+
See the [USBDEV documentation](usbdev.md)] for more details.
278+
272279
## Useful debugging options
273280

274281
### Device log traces

docs/opentitan/usbdev.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenTitan USBDEV
2+
3+
## `usb` Chardev
4+
5+
The USBDEV driver exposes a chardev with ID `usbdev` which can used to control some aspects of the emulation.
6+
Once connected, the driver accepts textual commands.
7+
Each command must end with a newline.
8+
The following commands are recognized:
9+
- `vbus_on`: turn on VBUS, see [#VBUS-handling](VBUS handling) for more details.
10+
- `vbus_off`: turn off VBUS, see [#VBUS-handling](VBUS handling) for more details.
11+
12+
## VBUS handling
13+
14+
On a real machine, the VBUS sense pin is usually connected to the VBUS connector so
15+
that the chip can detect when a cable is plugged. For the purpose of emulation, a different
16+
approach needs to be taken. The driver supports several mode of operations which are controlled
17+
by the `vbus-mode` string property which can be set on the command-line by
18+
`-global ot-usbdev.vbus-mode=<mode>`. The following modes are supported:
19+
20+
- `vbus-override`: in this mode, the VBUS sense pin is entirely managed over the `usbdev` chardev.
21+
By default, the sense pin will be set to level low. The `vbus_on` and `vbus_off` commands
22+
can be used to change the value of the sense pin. Note that in this mode, the VBUS sense signal
23+
will be completely independent of the presence of a USB host.

hw/opentitan/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ config OT_TIMER
191191
config OT_UART
192192
bool
193193

194+
config OT_USBDEV
195+
bool
196+
194197
config OT_UNIMP
195198
bool
196199

hw/opentitan/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ system_ss.add(when: 'CONFIG_OT_UNIMP', if_true: files('ot_unimp.c'))
6161
riscv_ss.add(when: 'CONFIG_OT_VMAPPER', if_true: files('ot_vmapper.c'))
6262

6363
subdir('otbn')
64+
subdir('usbdev')

hw/opentitan/trace-events

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,14 @@ ot_uart_io_read_out(const char *id, uint32_t addr, const char *regname, uint32_t
629629
ot_uart_io_write(const char *id, uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
630630
ot_uart_irqs(const char *id, uint32_t active, uint32_t mask, uint32_t eff) "%s: act:0x%08x msk:0x%08x eff:0x%08x"
631631

632+
# ot_usbdev.c
633+
634+
ot_usbdev_io_read_out(const char *id, uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
635+
ot_usbdev_io_write(const char *id, uint32_t addr, const char *regname, uint32_t val, uint32_t pc) "%s: addr=0x%02x (%s), val=0x%x, pc=0x%x"
636+
ot_usbdev_irqs(const char *id, uint32_t active, uint32_t mask, uint32_t eff) "%s: act:0x%08x msk:0x%08x eff:0x%08x"
637+
ot_usbdev_reset(const char *id, const char *stage) "%s: %s"
638+
ot_usbdev_chr_process_cmd(const char *id, const char *cmd) "%s: %s"
639+
632640
# ot_unimp.c
633641

634642
ot_unimp_irq(const char *id, unsigned ix, bool lvl) "%s: #%u = %u"

hw/opentitan/usbdev/meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
system_ss.add(
2+
when: 'CONFIG_OT_USBDEV',
3+
if_true: files(
4+
'ot_usbdev.c',
5+
'ot_usbdev_state.c'
6+
)
7+
)

0 commit comments

Comments
 (0)