Skip to content

Commit 3d5a51b

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 3d5a51b

File tree

9 files changed

+820
-9
lines changed

9 files changed

+820
-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-override=<mode>` can be used to enable VBUS override node.
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 two modes of operations which are controlled
17+
by the `vbus-override` property which can be set on the command-line by
18+
`-global ot-usbdev.vbus-override=<mode>`. The following modes are supported:
19+
20+
- `vbus-override=on`: 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.
24+
- `vbus-override=off`: in this mode, the `vbus_on` and `vbus_off` commands control a virtual ``VBUS
25+
enable'' gate. The VBUS sense pin will be reported as level high if and only if the VBUS enable gate
26+
is enable **and** a USB host is connected to the driver. By default, the VBUS gate is disabled.

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
@@ -57,6 +57,7 @@ system_ss.add(when: 'CONFIG_OT_SRAM_CTRL', if_true: files('ot_sram_ctrl.c'))
5757
system_ss.add(when: 'CONFIG_OT_TIMER', if_true: files('ot_timer.c'))
5858
system_ss.add(when: 'CONFIG_OT_UART', if_true: files('ot_uart.c'))
5959
system_ss.add(when: 'CONFIG_OT_UNIMP', if_true: files('ot_unimp.c'))
60+
system_ss.add(when: 'CONFIG_OT_USBDEV', if_true: files('ot_usbdev.c'))
6061

6162
riscv_ss.add(when: 'CONFIG_OT_VMAPPER', if_true: files('ot_vmapper.c'))
6263

0 commit comments

Comments
 (0)