shithub: riscv

Download patch

ref: 11e12ea0c07086313bba07308e78ec1574730cd7
parent: 67750a093ffbcd597fd8e98ec48648e5631a9b6e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Feb 23 13:02:02 EST 2022

nusb/cam: use setalt()

--- a/sys/src/cmd/nusb/cam/video.c
+++ b/sys/src/cmd/nusb/cam/video.c
@@ -190,7 +190,7 @@
 	c->abort = 1;
 	free(fbuf);
 	closedev(c->ep);
-	usbcmd(c->dev, 0x01, Rsetiface, 0, c->iface->id, nil, 0);
+	setalt(c->dev, c->iface);
 	c->ep = nil;
 	c->active = 0;
 	c->abort = 0;
@@ -198,7 +198,7 @@
 }
 
 static Ep*
-selaltc(Cam *c, ProbeControl *pc, Ep *ep)
+selbw(Cam *c, ProbeControl *pc, Ep *ep)
 {
 	uvlong bw, bw1, minbw;
 	Format *fo;
@@ -206,7 +206,8 @@
 	Ep *mink;
 
 	if(getframedesc(c, pc->bFormatIndex, pc->bFrameIndex, &fo, &f) < 0){
-		werrstr("selaltc: PROBE_CONTROL returned invalid bFormatIndex,bFrameIndex=%d,%d", pc->bFormatIndex, pc->bFrameIndex);
+		werrstr("selaltc: PROBE_CONTROL returned invalid bFormatIndex,bFrameIndex=%d,%d",
+			pc->bFormatIndex, pc->bFrameIndex);
 		return nil;
 	}
 	mink = nil;
@@ -218,8 +219,8 @@
 		bw1 = ep->maxpkt * ep->ntds * 8 * 1000 * 8;
 		if(bw1 >= bw) {
 			if(mink == nil || bw1 < minbw){
-				minbw = bw1;
 				mink = ep;
+				minbw = bw1;
 			}
 		}
 	}
@@ -227,10 +228,6 @@
 		werrstr("device does not have enough bandwidth (need %lld bit/s)", bw);
 		return nil;
 	}
-	if(usbcmd(c->dev, 0x01, Rsetiface, mink->iface->alt, mink->iface->id, nil, 0) < 0){
-		werrstr("selaltc: SET_INTERFACE(%d, %d): %r", ep->iface->id, ep->iface->alt);
-		return nil;
-	}
 	return mink;
 }
 
@@ -275,22 +272,22 @@
 	}
 	if(getconverter(f) == nil) goto err;
 	d = c->dev;
-	if(usbcmd(d, 0x01, Rsetiface, 0, c->iface->id, nil, 0) < 0) goto err;
+	if(setalt(d, c->iface) < 0) goto err;
 	if(usbcmd(d, 0x21, SET_CUR, VS_PROBE_CONTROL << 8, c->iface->id, (uchar *) &c->pc, sizeof(ProbeControl)) < sizeof(ProbeControl)) goto err;
 	if(usbcmd(d, 0xA1, GET_CUR, VS_PROBE_CONTROL << 8, c->iface->id, (uchar *) &c->pc, sizeof(ProbeControl)) < 0) goto err;
 	if(usbcmd(d, 0x21, SET_CUR, VS_COMMIT_CONTROL << 8, c->iface->id, (uchar *) &c->pc, sizeof(ProbeControl)) < sizeof(ProbeControl)) goto err;
-	e = selaltc(c, &c->pc, d->usb->ep[c->hdr->bEndpointAddress & Epmax]);
-	if(e == nil)
-		goto err;
+	e = selbw(c, &c->pc, d->usb->ep[c->hdr->bEndpointAddress & Epmax]);
+	if(e == nil || setalt(c->dev, e->iface) < 0)
+		return nil;
 	c->ep = openep(d, e);
 	if(c->ep == nil){
-		usbcmd(d, 0x01, Rsetiface, 0, c->iface->id, nil, 0);
+		setalt(d, c->iface);
 		goto err;
 	}
 	devctl(c->ep, "uframes 1");
 	if(opendevdata(c->ep, OREAD) < 0){
-		usbcmd(d, 0x01, Rsetiface, 0, c->iface->id, nil, 0);
 		closedev(c->ep);
+		setalt(d, c->iface);
 		goto err;
 	}
 	mkframes(c);