Skip to content

Support external USB devices#1520

Merged
NiLuJe merged 19 commits into
koreader:masterfrom
lykahb:external-keyboard
Oct 29, 2022
Merged

Support external USB devices#1520
NiLuJe merged 19 commits into
koreader:masterfrom
lykahb:external-keyboard

Conversation

@lykahb

@lykahb lykahb commented Sep 21, 2022

Copy link
Copy Markdown
Contributor

This is required for koreader/koreader#9540.

With this change a reader can have a USB role of either host or device. The existing event CODE_FAKE_USB_PLUG_IN/OUT has been renamed to CODE_FAKE_USB_HOST_PLUG_IN/OUT to indicate that reader is plugged to a host. A new event CODE_FAKE_USB_DEVICE_PLUG_IN/OUT is emitted when a device is connected to reader (which is in the host mode).

I added the function to close a single device to input.c closeInputDevice. I also extracted computation of nfds into a function to avoid duplicating the logic once more in the closeInputDevice. Perhaps it makes sense to export it to lua, but it wouldn't have usage yet.

The size of inputfds is increased from 4 to 8 to accommodate the external devices. On kobo there are already three default inputs. Connecting an external keyboard may bring in several inputs with keyboard capabilities.


This change is Reviewable

@NiLuJe

NiLuJe commented Sep 21, 2022

Copy link
Copy Markdown
Member

Looks sensible at first blush, will need more sleep to properly review ;).

(Also, the uevent path is probably device-specific to some extent, but given how limited OTG support actually is OOB, it's probably fine for now ;)).

Comment thread ffi/posix_h.lua
@lykahb

lykahb commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

Thanks NiLuJe. What's your opinion on the constants names? I aimed to match the current style. Another variant I thought of would be more descriptive but also more verbose:

CODE_FAKE_USB_PLUGGED_IN_TO_HOST / CODE_FAKE_USB_PLUGGED_OUT_OF_HOST
CODE_FAKE_USB_DEVICE_PLUGGED_IN / CODE_FAKE_USB_DEVICE_PLUGGED_OUT

@NiLuJe

NiLuJe commented Sep 21, 2022

Copy link
Copy Markdown
Member

Thanks NiLuJe. What's your opinion on the constants names? I aimed to match the current style. Another variant I thought of would be more descriptive but also more verbose:

CODE_FAKE_USB_PLUGGED_IN_TO_HOST / CODE_FAKE_USB_PLUGGED_OUT_OF_HOST
CODE_FAKE_USB_DEVICE_PLUGGED_IN / CODE_FAKE_USB_DEVICE_PLUGGED_OUT

That's indeed potentially less confusing, and verbosity's never bothered me ;o).

@NiLuJe

NiLuJe commented Sep 21, 2022

Copy link
Copy Markdown
Member

Random related thought, since I've never dealt with OTG, well, anywhere: does https://github.com/koreader/KoboUSBMS understand what's happening if you try to start an USBMS session w/ OTG enabled?

@Frenzie

Frenzie commented Sep 21, 2022

Copy link
Copy Markdown
Member

Same.

@lykahb

lykahb commented Sep 21, 2022

Copy link
Copy Markdown
Contributor Author

When the OTG is enabled, USBMS fails after connecting to a computer with "The device is plugged into a plain power source, not a USB host!".

I fixed that in the koreader PR - it restores the default USB role of "device" on exit now.

@NiLuJe

NiLuJe commented Sep 22, 2022

Copy link
Copy Markdown
Member

I fixed that in the koreader PR - it restores the default USB role of "device" on exit now.

Good idea ;).

I hope USBMS still fails when it's just a keyboard plugged in, though :D.

@lykahb

lykahb commented Sep 22, 2022

Copy link
Copy Markdown
Contributor Author

Yeah, by the time USBMS is started, the USB role would be device.

So, if the reader in OTG mode is capable of supplying power, the power would be off now and it would be as if nothing is connected. USBMS would wait for 30s and exit on timeout. Likely, only some readers with Android have powered OTG.

If OTG does not supply power, a keyboard must be connected through a Y-shaped cable along with the power source. USBMS would detect the power source and fail with "The device is plugged into a plain power source, not a USB host!".

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r2, 6 of 6 files at r3, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @lykahb)


input/input.c line 172 at r3 (raw file):

    lua_settop(L, 0);
    // Pass the fd to Lua, we might need it for FFI ioctl shenanigans
    lua_pushinteger(L, inputfds[fd_idx]);

I'd fold the increment in there (i.e., inputfds[fd_idx++]).


input/input.c line 181 at r3 (raw file):

}

static int closeInputDevice(size_t fd_idx_to_close)

ssize_t


input/input.c line 185 at r3 (raw file):

    // Right now, we close everything, but, in the future, we may want to keep *some* slots open.
    // Note that doing that would (currently) require making sure those slots are at the start of the array,
    // in ascending fd number order, and that the array itself isn't sparse.

Duplicated comment ;).

Code quote:

    // Right now, we close everything, but, in the future, we may want to keep *some* slots open.
    // Note that doing that would (currently) require making sure those slots are at the start of the array,
    // in ascending fd number order, and that the array itself isn't sparse.

input/input.c line 200 at r3 (raw file):

    inputfds[fd_idx - 1] = -1;
    fd_idx--;

In a similar vein, I'd fold the decrement in there. inputfds[--fd_idx] = -1;

Code quote:

    inputfds[fd_idx - 1] = -1;
    fd_idx--;

input/input.c line 203 at r3 (raw file):

    computeNfds();
    printf("[ko-input] Closed input device with idx=%d, fd=%d\n", fd_idx_to_close, fd);

The format token for ssize_t is %zd ;).

@NiLuJe

NiLuJe commented Oct 14, 2022

Copy link
Copy Markdown
Member

(Minor nits, but looks sounds!)

@NiLuJe

NiLuJe commented Oct 27, 2022

Copy link
Copy Markdown
Member

For archeological purposes, output of env -i uevent env on sunxi (Elipsa), after a charger (CDP) unplug, then a keyboard plug-in, then a switch to OTG via echo "usb_host" >| /sys/devices/platform/soc/usbc0/otg_role (standard role is usb_device, c.f., set_otg_role @ drivers/usb/sunxi_usb/manager/usbc0_platform.c:

uevent feed
ACTION=change
DEVPATH=/devices/platform/soc/twi2/i2c-2/2-0032/ricoh619-battery/power_supply/battery
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=battery
POWER_SUPPLY_STATUS=Full
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_VOLTAGE_NOW=4134300
POWER_SUPPLY_CURRENT_NOW=2701
POWER_SUPPLY_CAPACITY=100
POWER_SUPPLY_TEMP=510
POWER_SUPPLY_TIME_TO_EMPTY_NOW=3241200
POWER_SUPPLY_TIME_TO_FULL_NOW=3932100
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_HEALTH=Good
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3600
SEQNUM=1548
ACTION=change
DEVPATH=/devices/platform/soc/twi2/i2c-2/2-0032/ricoh619-battery/power_supply/battery
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=battery
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_VOLTAGE_NOW=4134300
POWER_SUPPLY_CURRENT_NOW=2701
POWER_SUPPLY_CAPACITY=100
POWER_SUPPLY_TEMP=510
POWER_SUPPLY_TIME_TO_EMPTY_NOW=3241200
POWER_SUPPLY_TIME_TO_FULL_NOW=3932100
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_HEALTH=Good
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3600
SEQNUM=1549
ACTION=remove
DEVPATH=/devices/platform/usb_plug
SUBSYSTEM=platform
DRIVER=usb_plug
OF_NAME=usb_plug
OF_FULLNAME=/usb_plug
OF_COMPATIBLE_0=usb_plug
OF_COMPATIBLE_N=1
MODALIAS=of:Nusb_plugT<NULL>Cusb_plug
SEQNUM=1550
ACTION=change
DEVPATH=/devices/platform/soc/twi2/i2c-2/2-0032/ricoh619-battery/power_supply/battery
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=battery
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_VOLTAGE_NOW=4162300
POWER_SUPPLY_CURRENT_NOW=2697
POWER_SUPPLY_CAPACITY=100
POWER_SUPPLY_TEMP=510
POWER_SUPPLY_TIME_TO_EMPTY_NOW=46920
POWER_SUPPLY_TIME_TO_FULL_NOW=3932100
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_HEALTH=Good
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3600
SEQNUM=1551
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ehci0-controller/usb1
SUBSYSTEM=usb
MAJOR=189
MINOR=0
DEVNAME=bus/usb/001/001
DEVTYPE=usb_device
PRODUCT=1d6b/2/409
TYPE=9/0/0
BUSNUM=001
DEVNUM=001
SEQNUM=1552
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ehci0-controller/usb1/1-0:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1d6b/2/409
TYPE=9/0/0
INTERFACE=9/0/0
MODALIAS=usb:v1D6Bp0002d0409dc09dsc00dp00ic09isc00ip00in00
SEQNUM=1553
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2
SUBSYSTEM=usb
MAJOR=189
MINOR=128
DEVNAME=bus/usb/002/001
DEVTYPE=usb_device
PRODUCT=1d6b/1/409
TYPE=9/0/0
BUSNUM=002
DEVNUM=001
SEQNUM=1554
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-0:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1d6b/1/409
TYPE=9/0/0
INTERFACE=9/0/0
MODALIAS=usb:v1D6Bp0001d0409dc09dsc00dp00ic09isc00ip00in00
SEQNUM=1555
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1
SUBSYSTEM=usb
MAJOR=189
MINOR=129
DEVNAME=bus/usb/002/002
DEVTYPE=usb_device
PRODUCT=1532/118/200
TYPE=0/0/0
BUSNUM=002
DEVNUM=002
SEQNUM=1556
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/1/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc01ip01in00
SEQNUM=1557
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input0
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1558
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input0"
UNIQ=""
PROP=0
EV=120013
KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
MSC=10
LED=7
MODALIAS=input:b0003v1532p0118e0111-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8C,8E,96,98,9E,9F,A1,A3,A4,A5,A6,AD,B0,B1,B2,B3,B4,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw
SEQNUM=1559
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::numlock
SUBSYSTEM=leds
SEQNUM=1560
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::capslock
SUBSYSTEM=leds
SEQNUM=1561
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::scrolllock
SUBSYSTEM=leds
SEQNUM=1562
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/event4
SUBSYSTEM=input
MAJOR=13
MINOR=68
DEVNAME=input/event4
SEQNUM=1563
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/hidraw/hidraw0
SUBSYSTEM=hidraw
MAJOR=246
MINOR=0
DEVNAME=hidraw0
SEQNUM=1564
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip01in01
SEQNUM=1565
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input1
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1566
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/input/input8
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input1"
UNIQ=""
PROP=0
EV=10001f
KEY=3007f 0 0 0 0 483ffff 17aff32d bf544446 0 0 1 130c13 b17c007 ffbf7bfa d941dfff febeffdf ffefffff ffffffff fffffffe
REL=40
ABS=ffffff01 0
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,3,4,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8B,8C,8E,8F,90,96,98,9B,9C,9E,9F,A1,A3,A4,A5,A6,A7,A8,A9,AB,AC,AD,AE,B0,B1,B2,B3,B4,B5,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,CE,CF,D0,D1,D2,D4,D8,D9,DB,E0,E1,E4,EA,EB,F0,F1,F4,100,161,162,166,16A,16E,172,174,176,178,179,17A,17B,17C,17D,17F,180,182,183,185,188,189,18C,18D,18E,18F,190,191,192,193,195,197,198,199,19A,19C,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA,1AB,1AC,1AD,1AE,1AF,1B0,1B1,1B7,1BA,240,241,242,243,244,245,246,250,251,r6,a20,28,29,2A,2B,2C,2D,2E,2F,30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,m4,lsfw
SEQNUM=1567
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/input/input8/event5
SUBSYSTEM=input
MAJOR=13
MINOR=69
DEVNAME=input/event5
SEQNUM=1568
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/hidraw/hidraw1
SUBSYSTEM=hidraw
MAJOR=246
MINOR=1
DEVNAME=hidraw1
SEQNUM=1569
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/2
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip02in02
SEQNUM=1570
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input2
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1571
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/input/input9
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input2"
UNIQ=""
PROP=0
EV=17
KEY=70000 0 0 0 0 0 0 0 0
REL=103
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,4,k110,111,112,r0,1,8,am4,lsfw
SEQNUM=1572
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/input/input9/event6
SUBSYSTEM=input
MAJOR=13
MINOR=70
DEVNAME=input/event6
SEQNUM=1573
ACTION=add
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/hidraw/hidraw2
SUBSYSTEM=hidraw
MAJOR=246
MINOR=2
DEVNAME=hidraw2
SEQNUM=1574

(Excuse the chatty gaming keyboard, I was too lazy to remove the PS/2 adapter on my other, tamer spare keyboard ;p. Keycap LEDs work, though, which is probably another nice way of ruining battery life ;p).

@NiLuJe

NiLuJe commented Oct 27, 2022

Copy link
Copy Markdown
Member

Unplug (w/o a manual role swap):

uevent feed
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::numlock
SUBSYSTEM=leds
SEQNUM=1583
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::capslock
SUBSYSTEM=leds
SEQNUM=1584
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/input7::scrolllock
SUBSYSTEM=leds
SEQNUM=1585
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7/event4
SUBSYSTEM=input
MAJOR=13
MINOR=68
DEVNAME=input/event4
SEQNUM=1586
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/input/input7
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input0"
UNIQ=""
PROP=0
EV=120013
KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
MSC=10
LED=7
MODALIAS=input:b0003v1532p0118e0111-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8C,8E,96,98,9E,9F,A1,A3,A4,A5,A6,AD,B0,B1,B2,B3,B4,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw
SEQNUM=1587
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004/hidraw/hidraw0
SUBSYSTEM=hidraw
MAJOR=246
MINOR=0
DEVNAME=hidraw0
SEQNUM=1588
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0004
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input0
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1589
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/1/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc01ip01in00
SEQNUM=1590
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/input/input8/event5
SUBSYSTEM=input
MAJOR=13
MINOR=69
DEVNAME=input/event5
SEQNUM=1591
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/input/input8
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input1"
UNIQ=""
PROP=0
EV=10001f
KEY=3007f 0 0 0 0 483ffff 17aff32d bf544446 0 0 1 130c13 b17c007 ffbf7bfa d941dfff febeffdf ffefffff ffffffff fffffffe
REL=40
ABS=ffffff01 0
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,3,4,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8B,8C,8E,8F,90,96,98,9B,9C,9E,9F,A1,A3,A4,A5,A6,A7,A8,A9,AB,AC,AD,AE,B0,B1,B2,B3,B4,B5,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,CE,CF,D0,D1,D2,D4,D8,D9,DB,E0,E1,E4,EA,EB,F0,F1,F4,100,161,162,166,16A,16E,172,174,176,178,179,17A,17B,17C,17D,17F,180,182,183,185,188,189,18C,18D,18E,18F,190,191,192,193,195,197,198,199,19A,19C,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA,1AB,1AC,1AD,1AE,1AF,1B0,1B1,1B7,1BA,240,241,242,243,244,245,246,250,251,r6,a20,28,29,2A,2B,2C,2D,2E,2F,30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,m4,lsfw
SEQNUM=1592
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005/hidraw/hidraw1
SUBSYSTEM=hidraw
MAJOR=246
MINOR=1
DEVNAME=hidraw1
SEQNUM=1593
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0005
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input1
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1594
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip01in01
SEQNUM=1595
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/input/input9/event6
SUBSYSTEM=input
MAJOR=13
MINOR=70
DEVNAME=input/event6
SEQNUM=1596
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/input/input9
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input2"
UNIQ=""
PROP=0
EV=17
KEY=70000 0 0 0 0 0 0 0 0
REL=103
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,4,k110,111,112,r0,1,8,am4,lsfw
SEQNUM=1597
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006/hidraw/hidraw2
SUBSYSTEM=hidraw
MAJOR=246
MINOR=2
DEVNAME=hidraw2
SEQNUM=1598
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0006
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input2
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1599
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/2
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip02in02
SEQNUM=1600
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1
SUBSYSTEM=usb
MAJOR=189
MINOR=129
DEVNAME=bus/usb/002/002
DEVTYPE=usb_device
PRODUCT=1532/118/200
TYPE=0/0/0
BUSNUM=002
DEVNUM=002
SEQNUM=1601

The role toggle stays put after unplug, FWIW.

@NiLuJe

NiLuJe commented Oct 27, 2022

Copy link
Copy Markdown
Member

Removal by role swap (LEDs stay on, which isn't the case when plugging in @ usb_device role):

uevent feed
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ehci0-controller/usb1/1-0:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1d6b/2/409
TYPE=9/0/0
INTERFACE=9/0/0
MODALIAS=usb:v1D6Bp0002d0409dc09dsc00dp00ic09isc00ip00in00
SEQNUM=1623
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ehci0-controller/usb1
SUBSYSTEM=usb
MAJOR=189
MINOR=0
DEVNAME=bus/usb/001/001
DEVTYPE=usb_device
OF_NAME=ehci0-controller
OF_FULLNAME=/soc@03000000/ehci0-controller@0x05101000
OF_COMPATIBLE_0=allwinner,sunxi-ehci0
OF_COMPATIBLE_N=1
PRODUCT=1d6b/2/409
TYPE=9/0/0
BUSNUM=001
DEVNUM=001
SEQNUM=1624
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/input/input10/input10::numlock
SUBSYSTEM=leds
SEQNUM=1625
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/input/input10/input10::capslock
SUBSYSTEM=leds
SEQNUM=1626
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/input/input10/input10::scrolllock
SUBSYSTEM=leds
SEQNUM=1627
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/input/input10/event4
SUBSYSTEM=input
MAJOR=13
MINOR=68
DEVNAME=input/event4
SEQNUM=1628
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/input/input10
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input0"
UNIQ=""
PROP=0
EV=120013
KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
MSC=10
LED=7
MODALIAS=input:b0003v1532p0118e0111-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8C,8E,96,98,9E,9F,A1,A3,A4,A5,A6,AD,B0,B1,B2,B3,B4,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,sfw
SEQNUM=1629
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007/hidraw/hidraw0
SUBSYSTEM=hidraw
MAJOR=246
MINOR=0
DEVNAME=hidraw0
SEQNUM=1630
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0/0003:1532:0118.0007
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input0
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1631
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/1/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc01ip01in00
SEQNUM=1632
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0008/input/input11/event5
SUBSYSTEM=input
MAJOR=13
MINOR=69
DEVNAME=input/event5
SEQNUM=1633
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0008/input/input11
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input1"
UNIQ=""
PROP=0
EV=10001f
KEY=3007f 0 0 0 0 483ffff 17aff32d bf544446 0 0 1 130c13 b17c007 ffbf7bfa d941dfff febeffdf ffefffff ffffffff fffffffe
REL=40
ABS=ffffff01 0
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,3,4,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8B,8C,8E,8F,90,96,98,9B,9C,9E,9F,A1,A3,A4,A5,A6,A7,A8,A9,AB,AC,AD,AE,B0,B1,B2,B3,B4,B5,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,CE,CF,D0,D1,D2,D4,D8,D9,DB,E0,E1,E4,EA,EB,F0,F1,F4,100,161,162,166,16A,16E,172,174,176,178,179,17A,17B,17C,17D,17F,180,182,183,185,188,189,18C,18D,18E,18F,190,191,192,193,195,197,198,199,19A,19C,1A0,1A1,1A2,1A3,1A4,1A5,1A6,1A7,1A8,1A9,1AA,1AB,1AC,1AD,1AE,1AF,1B0,1B1,1B7,1BA,240,241,242,243,244,245,246,250,251,r6,a20,28,29,2A,2B,2C,2D,2E,2F,30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,m4,lsfw
SEQNUM=1634
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0008/hidraw/hidraw1
SUBSYSTEM=hidraw
MAJOR=246
MINOR=1
DEVNAME=hidraw1
SEQNUM=1635
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1/0003:1532:0118.0008
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input1
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1636
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.1
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/1
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip01in01
SEQNUM=1637
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0009/input/input12/event6
SUBSYSTEM=input
MAJOR=13
MINOR=70
DEVNAME=input/event6
SEQNUM=1638
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0009/input/input12
SUBSYSTEM=input
PRODUCT=3/1532/118/111
NAME="Razer Razer DeathStalker"
PHYS="usb-sunxi-ohci-1/input2"
UNIQ=""
PROP=0
EV=17
KEY=70000 0 0 0 0 0 0 0 0
REL=103
MSC=10
MODALIAS=input:b0003v1532p0118e0111-e0,1,2,4,k110,111,112,r0,1,8,am4,lsfw
SEQNUM=1639
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0009/hidraw/hidraw2
SUBSYSTEM=hidraw
MAJOR=246
MINOR=2
DEVNAME=hidraw2
SEQNUM=1640
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2/0003:1532:0118.0009
SUBSYSTEM=hid
HID_ID=0003:00001532:00000118
HID_NAME=Razer Razer DeathStalker
HID_PHYS=usb-sunxi-ohci-1/input2
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001532p00000118
SEQNUM=1641
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1/2-1:1.2
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1532/118/200
TYPE=0/0/0
INTERFACE=3/0/2
MODALIAS=usb:v1532p0118d0200dc00dsc00dp00ic03isc00ip02in02
SEQNUM=1642
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-1
SUBSYSTEM=usb
MAJOR=189
MINOR=130
DEVNAME=bus/usb/002/003
DEVTYPE=usb_device
PRODUCT=1532/118/200
TYPE=0/0/0
BUSNUM=002
DEVNUM=003
SEQNUM=1643
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2/2-0:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
PRODUCT=1d6b/1/409
TYPE=9/0/0
INTERFACE=9/0/0
MODALIAS=usb:v1D6Bp0001d0409dc09dsc00dp00ic09isc00ip00in00
SEQNUM=1644
ACTION=remove
DEVPATH=/devices/platform/soc/5101000.ohci0-controller/usb2
SUBSYSTEM=usb
MAJOR=189
MINOR=128
DEVNAME=bus/usb/002/001
DEVTYPE=usb_device
OF_NAME=ohci0-controller
OF_FULLNAME=/soc@03000000/ohci0-controller@0x05101400
OF_COMPATIBLE_0=allwinner,sunxi-ohci0
OF_COMPATIBLE_N=1
PRODUCT=1d6b/1/409
TYPE=9/0/0
BUSNUM=002
DEVNUM=001
SEQNUM=1645

@lykahb

lykahb commented Oct 27, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for testing. The keyboard logic does nothing with LED's now. It is actually quite difficult to manipulate them. So, the difference in how their state changes must come from the keyboard firmware. Likely, if plugging it simply into a power bank would have the same effect as plugging into a device that has usb device mode.

Yes, the role toggle does not change after unplugging. Otherwise, every time before plugging in the keyboard a user would have to enable OTG again.

Should hopefully trigger less noise, because there's a lot of usb
shenanigans going on ;).

Also, it might just pickup BT keyboards if we ever handle those one day.

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @lykahb)

@NiLuJe

NiLuJe commented Oct 28, 2022

Copy link
Copy Markdown
Member

20c88ad seems like a cleaner approach to me, but I haven't actually tested anything yet ;).

Thoughts?

@lykahb

lykahb commented Oct 28, 2022

Copy link
Copy Markdown
Contributor Author

Yeah, a check on subsystem is cleaner. I can check if it still works on Kobo Libra 2.

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @lykahb)

We don't do anything with it reight now, but it should ultimately allow
us not to have to walk the entirely of /sys/class/input to find what was
just plugged in ;).

a.k.a, poor man's udev ;p.
Almost everything goes through with a PLATFORMSOC_DEVPATH prefix,
whereas input subsystems events are few and far between ;).

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @lykahb)

@NiLuJe NiLuJe merged commit 1b3a23e into koreader:master Oct 29, 2022
NiLuJe added a commit to lykahb/koreader that referenced this pull request Oct 29, 2022
NiLuJe added a commit to NiLuJe/koreader that referenced this pull request Oct 29, 2022
NiLuJe added a commit to koreader/koreader that referenced this pull request Oct 29, 2022
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants