ref: f24038d601ebe23a213ca1eaf2cf2faa47c22873
parent: 4607b1874088ef29c769b880ea472fa4897715fa
author: Keegan Saunders <keegan@undefinedbehaviour.org>
date: Thu Oct 12 18:54:02 EDT 2023
nusb/kb: fix Glorious Model O mouse Ensure we are using the DWC OTG before enabling the workaround. Otherwise, we risk breaking devices which don't like a Setidle of 8<<8.
--- a/sys/src/cmd/nusb/kb/kb.c
+++ b/sys/src/cmd/nusb/kb/kb.c
@@ -25,6 +25,7 @@
Awakemsg = 0xdeaddead,
Diemsg = 0xbeefbeef,
Rawon = 0x0defaced,
+ Dwcidle = 8,
};
char user[] = "kb";
@@ -38,6 +39,8 @@
int minfd;
int kinfd;
+ int idle;
+
Channel *repeatc; /* only for keyboard */
/* report descriptor */
@@ -364,14 +367,8 @@
{
int proto;
+ usbcmd(f->dev, Rh2d|Rclass|Riface, Setidle, f->idle<<8, iface->id, nil, 0);
- /*
- * DWC OTG controller misses some split transaction inputs.
- * Set nonzero idle time to return more frequent reports
- * of keyboard state, to avoid losing key up/down events.
- */
- usbcmd(f->dev, Rh2d|Rclass|Riface, Setidle, 8<<8, iface->id, nil, 0);
-
f->nrep = usbcmd(f->dev, Rd2h|Rstd|Riface, Rgetdesc, Dreport<<8, iface->id,
f->rep, sizeof(f->rep));
if(f->nrep > 0){
@@ -967,6 +964,8 @@
hdsetup(Dev *d, Ep *ep)
{
Hiddev *f;
+ uchar desc[512];
+ int n;
f = emallocz(sizeof(Hiddev), 1);
f->minfd = -1;
@@ -973,6 +972,17 @@
f->kinfd = -1;
incref(d);
f->dev = d;
+ /*
+ * DWC OTG controller misses some split transaction inputs.
+ * Set nonzero idle time to return more frequent reports
+ * of keyboard state, to avoid losing key up/down events.
+ */
+ n = read(d->cfd, desc, sizeof(desc) - 1);
+ if(n > 0){
+ desc[n] = 0;
+ if(strstr((char*)desc, "dwcotg") != nil)
+ f->idle = Dwcidle;
+ }
if(setproto(f, ep->iface) < 0){
fprint(2, "%s: %s: setproto: %r\n", argv0, d->dir);
goto Err;