PERFORCE change 132100 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Sun Dec 30 06:43:11 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=132100
Change 132100 by hselasky at hselasky_laptop001 on 2007/12/30 14:42:52
New function "uchcom_do_request". Handle
control transfer errors centrally instead
of everywhere in the code. When a read-
control transfer fails we simply return
0x00 for data. Else we don't care except
for printing out an error message.
Optionally we could nicely loop in
"uchcom_do_request" until the request
succeeds.
Affected files ...
.. //depot/projects/usb/src/sys/dev/usb/uchcom.c#8 edit
Differences ...
==== //depot/projects/usb/src/sys/dev/usb/uchcom.c#8 (text+ko) ====
@@ -398,7 +398,37 @@
* low level i/o
*/
-static usbd_status
+static void
+uchcom_do_request(struct uchcom_softc *sc,
+ usb_device_request_t *req, void *data)
+{
+ uint16_t length;
+ uint16_t actlen;
+ usbd_status_t err;
+
+ length = UGETW(req->wLength);
+ actlen = 0;
+
+ if (ucom_cfg_is_gone(&(sc->sc_ucom))) {
+ goto done;
+ }
+ err = usbd_do_request_flags(sc->sc_udev, &Giant, req,
+ data, USBD_SHORT_XFER_OK, &actlen, 1000);
+
+ if (err) {
+ DPRINTFN(-1, "device request failed, err=%s "
+ "(ignored)\n", usbd_errstr(err));
+ }
+done:
+ if (length != actlen) {
+ if (req->bmRequestType & UT_READ) {
+ bzero(USBD_ADD_BYTES(data,actlen), length - actlen);
+ }
+ }
+ return;
+}
+
+static void
uchcom_ctrl_write(struct uchcom_softc *sc, uint8_t reqno,
uint16_t value, uint16_t index)
{
@@ -410,13 +440,13 @@
USETW(req.wIndex, index);
USETW(req.wLength, 0);
- return (usbd_do_request(sc->sc_ucom.sc_udev, &req, 0));
+ uchcom_do_request(sc, &req, NULL);
+ return;
}
-static usbd_status
+static void
uchcom_ctrl_read(struct uchcom_softc *sc, uint8_t reqno,
- uint16_t value, uint16_t index, void *buf, int buflen,
- int *actlen)
+ uint16_t value, uint16_t index, void *buf, uint16_t buflen)
{
usb_device_request_t req;
@@ -424,47 +454,43 @@
req.bRequest = reqno;
USETW(req.wValue, value);
USETW(req.wIndex, index);
- USETW(req.wLength, (uint16_t)buflen);
+ USETW(req.wLength, buflen);
- return (usbd_do_request_flags(sc->sc_ucom.sc_udev, &req, buf,
- USBD_SHORT_XFER_OK, actlen,
- USBD_DEFAULT_TIMEOUT));
+ uchcom_do_request(sc, &req, buf);
+ return;
}
-static usbd_status
+static void
uchcom_write_reg(struct uchcom_softc *sc,
uint8_t reg1, uint8_t val1, uint8_t reg2, uint8_t val2)
{
- DPRINTF(("uchcom: write reg 0x%02X<-0x%02X, 0x%02X<-0x%02X\n",
+ DPRINTFN(0, "0x%02X<-0x%02X, 0x%02X<-0x%02X\n",
(unsigned)reg1, (unsigned)val1,
- (unsigned)reg2, (unsigned)val2));
- return (uchcom_ctrl_write(
+ (unsigned)reg2, (unsigned)val2);
+ uchcom_ctrl_write(
sc, UCHCOM_REQ_WRITE_REG,
- reg1|((uint16_t)reg2<<8), val1|((uint16_t)val2<<8)));
+ reg1|((uint16_t)reg2<<8), val1|((uint16_t)val2<<8));
+ return;
}
-static usbd_status
+static void
uchcom_read_reg(struct uchcom_softc *sc,
uint8_t reg1, uint8_t *rval1, uint8_t reg2, uint8_t *rval2)
{
uint8_t buf[UCHCOM_INPUT_BUF_SIZE];
- usbd_status err;
- int actin;
- err = uchcom_ctrl_read(
+ uchcom_ctrl_read(
sc, UCHCOM_REQ_READ_REG,
- reg1|((uint16_t)reg2<<8), 0, buf, sizeof buf, &actin);
- if (err)
- return (err);
+ reg1|((uint16_t)reg2<<8), 0, buf, sizeof(buf));
- DPRINTF(("uchcom: read reg 0x%02X->0x%02X, 0x%02X->0x%02X\n",
+ DPRINTFN(0, "0x%02X->0x%02X, 0x%02X->0x%02X\n",
(unsigned)reg1, (unsigned)buf[0],
- (unsigned)reg2, (unsigned)buf[1]));
+ (unsigned)reg2, (unsigned)buf[1]);
if (rval1) *rval1 = buf[0];
if (rval2) *rval2 = buf[1];
- return (USBD_NORMAL_COMPLETION);
+ return;
}
static usbd_status
@@ -472,12 +498,9 @@
{
uint8_t buf[UCHCOM_INPUT_BUF_SIZE];
usbd_status err;
- int actin;
- err = uchcom_ctrl_read(
- sc, UCHCOM_REQ_GET_VERSION, 0, 0, buf, sizeof buf, &actin);
- if (err)
- return (err);
+ uchcom_ctrl_read(
+ sc, UCHCOM_REQ_GET_VERSION, 0, 0, buf, sizeof(buf));
if (rver) *rver = buf[0];
@@ -487,19 +510,19 @@
static usbd_status
uchcom_get_status(struct uchcom_softc *sc, uint8_t *rval)
{
- return (uchcom_read_reg(sc, UCHCOM_REG_STAT1, rval, UCHCOM_REG_STAT2, NULL));
+ uchcom_read_reg(sc, UCHCOM_REG_STAT1, rval, UCHCOM_REG_STAT2, NULL);
}
static usbd_status
uchcom_set_dtrrts_10(struct uchcom_softc *sc, uint8_t val)
{
- return (uchcom_write_reg(sc, UCHCOM_REG_STAT1, val, UCHCOM_REG_STAT1, val));
+ uchcom_write_reg(sc, UCHCOM_REG_STAT1, val, UCHCOM_REG_STAT1, val);
}
static usbd_status
uchcom_set_dtrrts_20(struct uchcom_softc *sc, uint8_t val)
{
- return (uchcom_ctrl_write(sc, UCHCOM_REQ_SET_DTRRTS, val, 0));
+ uchcom_ctrl_write(sc, UCHCOM_REQ_SET_DTRRTS, val, 0);
}
@@ -580,9 +603,7 @@
usbd_status err;
uint8_t brk1, brk2;
- err = uchcom_read_reg(sc, UCHCOM_REG_BREAK1, &brk1, UCHCOM_REG_BREAK2, &brk2);
- if (err)
- return (EIO);
+ uchcom_read_reg(sc, UCHCOM_REG_BREAK1, &brk1, UCHCOM_REG_BREAK2, &brk2);
if (onoff) {
/* on - clear bits */
brk1 &= ~UCHCOM_BRK1_MASK;
@@ -592,9 +613,7 @@
brk1 |= UCHCOM_BRK1_MASK;
brk2 |= UCHCOM_BRK2_MASK;
}
- err = uchcom_write_reg(sc, UCHCOM_REG_BREAK1, brk1, UCHCOM_REG_BREAK2, brk2);
- if (err)
- return (EIO);
+ uchcom_write_reg(sc, UCHCOM_REG_BREAK1, brk1, UCHCOM_REG_BREAK2, brk2);
return (0);
}
@@ -647,17 +666,12 @@
if (uchcom_calc_divider_settings(&dv, rate))
return (EINVAL);
- if ((err = uchcom_write_reg(sc,
+ uchcom_write_reg(sc,
UCHCOM_REG_BPS_PRE, dv.dv_prescaler,
- UCHCOM_REG_BPS_DIV, dv.dv_div)) ||
- (err = uchcom_write_reg(sc,
+ UCHCOM_REG_BPS_DIV, dv.dv_div);
+ uchcom_write_reg(sc,
UCHCOM_REG_BPS_MOD, dv.dv_mod,
- UCHCOM_REG_BPS_PAD, 0))) {
- device_printf(sc->sc_ucom.sc_dev, " cannot set DTE rate: %s\n",
- usbd_errstr(err));
- return (EIO);
- }
-
+ UCHCOM_REG_BPS_PAD, 0);
return (0);
}
@@ -667,12 +681,7 @@
usbd_status err;
uint8_t lcr1 = 0, lcr2 = 0;
- err = uchcom_read_reg(sc, UCHCOM_REG_LCR1, &lcr1, UCHCOM_REG_LCR2, &lcr2);
- if (err) {
- device_printf(sc->sc_ucom.sc_dev, " cannot get LCR: %s\n",
- usbd_errstr(err));
- return (EIO);
- }
+ uchcom_read_reg(sc, UCHCOM_REG_LCR1, &lcr1, UCHCOM_REG_LCR2, &lcr2);
lcr1 &= ~UCHCOM_LCR1_MASK;
lcr2 &= ~UCHCOM_LCR2_MASK;
@@ -703,12 +712,7 @@
lcr2 |= UCHCOM_LCR2_PAREVEN;
}
- err = uchcom_write_reg(sc, UCHCOM_REG_LCR1, lcr1, UCHCOM_REG_LCR2, lcr2);
- if (err) {
- device_printf(sc->sc_ucom.sc_dev, "cannot set LCR: %s\n",
- usbd_errstr(err));
- return (EIO);
- }
+ uchcom_write_reg(sc, UCHCOM_REG_LCR1, lcr1, UCHCOM_REG_LCR2, lcr2);
return (0);
}
@@ -716,17 +720,9 @@
static int
uchcom_clear_chip(struct uchcom_softc *sc)
{
- usbd_status err;
-
DPRINTF(("%s: clear\n", USBDEVNAME(sc->sc_dev)));
- err = uchcom_ctrl_write(sc, UCHCOM_REQ_RESET, 0, 0);
- if (err) {
- device_printf(sc->sc_ucom.sc_dev, "cannot clear: %s\n",
- usbd_errstr(err));
- return (EIO);
- }
-
- return (0);
+ uchcom_ctrl_write(sc, UCHCOM_REQ_RESET, 0, 0);
+ return;
}
static int
@@ -736,17 +732,11 @@
uint8_t lcr1, lcr2, pre, div, mod;
uint16_t val=0, idx=0;
- err = uchcom_read_reg(sc, UCHCOM_REG_LCR1, &lcr1, UCHCOM_REG_LCR2, &lcr2);
- if (err)
- goto failed;
+ uchcom_read_reg(sc, UCHCOM_REG_LCR1, &lcr1, UCHCOM_REG_LCR2, &lcr2);
- err = uchcom_read_reg(sc, UCHCOM_REG_BPS_PRE, &pre, UCHCOM_REG_BPS_DIV, &div);
- if (err)
- goto failed;
+ uchcom_read_reg(sc, UCHCOM_REG_BPS_PRE, &pre, UCHCOM_REG_BPS_DIV, &div);
- err = uchcom_read_reg(sc, UCHCOM_REG_BPS_MOD, &mod, UCHCOM_REG_BPS_PAD, NULL);
- if (err)
- goto failed;
+ uchcom_read_reg(sc, UCHCOM_REG_BPS_MOD, &mod, UCHCOM_REG_BPS_PAD, NULL);
val |= (uint16_t)(lcr1&0xF0) << 8;
val |= 0x01;
@@ -762,9 +752,7 @@
DPRINTF(("%s: reset v=0x%04X, i=0x%04X\n",
USBDEVNAME(sc->sc_dev), val, idx));
- err = uchcom_ctrl_write(sc, UCHCOM_REQ_RESET, val, idx);
- if (err)
- goto failed;
+ uchcom_ctrl_write(sc, UCHCOM_REQ_RESET, val, idx);
return (0);
More information about the p4-projects
mailing list