Skip to content

Commit b939d82

Browse files
zhangqiang4sysopenci
authored andcommitted
usb: adapt otg switch config to new role switch driver
New role switch driver exposes a port sysfs file and the platform device name includes a dynamically allocated id, e.g. intel_xhci_usb_sw.1.auto Assumptions: Currently only one role switch device is allowed which means only one passthrough or virtual xhci controller. This assumption is similar to the device mode controller name dwc3.0.auto. These platform device IDs are allocated dynamically and may change with a different board device configuration. Tracked-On: OAM-131966 Signed-off-by: Qiang4 Zhang <qiang4.zhang@intel.com>
1 parent 2eb0aef commit b939d82

6 files changed

Lines changed: 15 additions & 8 deletions

File tree

groups/usb-init/true/init.recovery.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ on boot
44
insmod ${ro.vendor.boot.moduleslocation}/xhci-hcd.ko
55
insmod ${ro.vendor.boot.moduleslocation}/xhci-pci.ko
66
on property:sys.usb.ffs.ready=1
7-
write /sys/class/usb_role/intel_xhci_usb_sw-role-switch/role "device"
7+
write /sys/class/usb_role/intel_xhci_usb_sw.1.auto-role-switch/role "device"

groups/usb-otg-switch/doc.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ enable SW OTG port switching.
1010
--- false
1111
empty dir.
1212

13+
--- parameters
14+
- port: select the port to switch (0 based index)
15+
1316
--- default
1417
when not explicitly selected in mixin spec file, the default option will be used.
1518

groups/usb-otg-switch/true/init.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on property:sys.boot_completed=1
55
setprop vendor.sys.usb.role device
66

77
on property:vendor.sys.usb.role=host
8-
exec - system system -- /vendor/bin/usb_otg_switch.sh h
8+
exec - system system -- /vendor/bin/usb_otg_switch.sh h {{port}}
99

1010
on property:vendor.sys.usb.role=device
11-
exec - system system -- /vendor/bin/usb_otg_switch.sh p
11+
exec - system system -- /vendor/bin/usb_otg_switch.sh p {{port}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[defaults]
22
ioc = false
3+
port = 4
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/sys/devices/pci0000:00/0000:00:*.0/intel_xhci_usb_sw/usb_role/intel_xhci_usb_sw-role-switch role 0664 system system
1+
/sys/devices/pci0000:00/0000:00:*.0/intel_xhci_usb_sw*/usb_role/intel_xhci_usb_sw*-role-switch role 0664 system system
2+
/sys/devices/pci0000:00/0000:00:*.0/intel_xhci_usb_sw* port 0664 system system

groups/usb-otg-switch/true/usb_otg_switch.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ if [[ $1 = "h" ]]; then
77
case "$KERNEL_VERSION" in
88
4.4*) echo h > /sys/bus/platform/devices/intel-cht-otg.0/mux_state ;;
99
4.9*) echo h > /sys/bus/platform/drivers/intel_usb_dr_phy/intel_usb_dr_phy.0/mux_state ;;
10-
*) echo "host" > /sys/class/usb_role/intel_xhci_usb_sw-role-switch/role ;;
10+
*) for role in `ls /sys/bus/platform/devices/intel_xhci_usb_sw*/port`; do echo $2 > $role; done
11+
for role in `ls /sys/class/usb_role/intel_xhci_usb_sw*-role-switch/role`; do echo host > $role; done;;
1112
esac
1213

1314
elif [[ $1 = "p" ]]; then
1415
case "$KERNEL_VERSION" in
1516
4.4*) echo p > /sys/bus/platform/devices/intel-cht-otg.0/mux_state ;;
1617
4.9*) echo p > /sys/bus/platform/drivers/intel_usb_dr_phy/intel_usb_dr_phy.0/mux_state ;;
17-
*) echo "device" > /sys/class/usb_role/intel_xhci_usb_sw-role-switch/role ;;
18+
*) for role in `ls /sys/bus/platform/devices/intel_xhci_usb_sw*/port`; do echo $2 > $role; done
19+
for role in `ls /sys/class/usb_role/intel_xhci_usb_sw*-role-switch/role`; do echo device > $role; done;;
1820
esac
1921

2022
else
2123
echo "Please input h to swith to USB OTG mode"
22-
echo "usb_otg_switch.sh h"
24+
echo "usb_otg_switch.sh h <port>"
2325
echo "Please input p to swith USB device mode"
24-
echo "usb_otg_switch.sh p"
26+
echo "usb_otg_switch.sh p <port>"
2527
fi

0 commit comments

Comments
 (0)