Skip to content

sdwire-cli on Linux silently fails to switch to "target" if power management is not "auto" #31

Description

@jroush-ipg

Report

I am using an SDWire3 with sdwire-cli 0.3.1. The SDWire3 host side works normally, but initially I was unable to switch the SD card to the target side. In target mode, the separate SD card reader connected to the target did not detect a card at all.

I tested multiple target-side SD card readers and observed the same behavior.

After some investigation, I found that target switching depends on the Linux USB runtime power-management setting for the SDWire3 device. When /dev/.../power/control is set to "auto" (instead of "on"), then sdwire CLI reliably switches the SD card between host and target.

Based on the instructions for manually controlling the mux, this is a known requirement. However, it is apparently not checked or enforced by sdwire-cli. On my system, the default power-management setting for the SDWire3 is "on". More to the point, sdwire-cli does not detect or report the failure to switch to "target" mode.

System Specs

$ uname -r
7.1.4-arch1-1

$ head -n3 /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch

$ sudo lshw -short
H/W path                 Device          Class          Description
===================================================================
                                         system         30GUS0VU00 (LENOVO_MT_30GU_BU_Think_FM_ThinkStation P3 Tower)
...
/0/28                                    memory         64GiB System Memory
...
/0/40                                    processor      13th Gen Intel(R) Core(TM) i9-13900
/0/100                                   bridge         Raptor Lake-S Host Bridge/DRAM Controller
...
/0/100/14                                bus            600 Series Chipset Family USB 3.2 Gen 2x2 (20Gbs) XHCI Host Controller
...
/0/100/14/1              usb2            bus            xHCI Host Controller
...
/0/100/14/1/8            scsi8           storage        USB3.0-CRW   # <-- SDWire3, in "host" mode
...

Observed behavior

With the SDWire3 freshly connected:

$ sudo test-sdwire/bin/sdwire --version
sdwire, version 0.3.1

$ sudo test-sdwire/bin/sdwire state
Serial                        	State
20120501030900000.8           	Host

$ sudo test-sdwire/bin/sdwire switch target

$ sudo test-sdwire/bin/sdwire state
Serial                        	State
20120501030900000.8           	Target

Despite the CLI reporting Target, the target-side SD reader did not detect an SD card.

I located the SDWire3 USB device (0bda:0316) in sysfs:

$ cat /sys/bus/usb/devices/2-8/idProduct
0316

$ cat /sys/bus/usb/devices/2-8/idVendor
0bda

$ cat /sys/bus/usb/devices/2-8/power/runtime_status
active

$ cat /sys/bus/usb/devices/2-8/power/control
on

Switching between host and target using the CLI did not change the runtime status:

$ sudo sdwire switch host

$ cat /sys/bus/usb/devices/2-8/power/runtime_status
active

$ sudo sdwire switch target

$ cat /sys/bus/usb/devices/2-8/power/runtime_status
active

My understanding is that the runtime status is the key to controlling the power-suspend functionality of the RTS5306E.
If SDWire3 is in "target" mode, the runtime_status should be "suspended".

I then enabled USB autosuspend:

$ echo 0 | sudo tee /sys/bus/usb/devices/2-8/power/autosuspend_delay_ms
$ echo auto | sudo tee /sys/bus/usb/devices/2-8/power/control

Immediately after this, the target-side SD reader detected the SD card successfully.
I was then able to use sdwire to switch back and forth between "host" and "target" modes reliably for as long as the SDWire3 remained plugged in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions