From 3f7bf3201f45d0f1885034d17deaf852a1c9b87e Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Mon, 11 Apr 2005 01:49:51 +0000 Subject: Handle commands failure correctly. --- sys/arch/sparc/dev/tctrl.c | 61 +++++++++++++++++++++++++++++-------------- sys/arch/sparc/dev/ts102reg.h | 18 ++++++++----- 2 files changed, 52 insertions(+), 27 deletions(-) (limited to 'sys') diff --git a/sys/arch/sparc/dev/tctrl.c b/sys/arch/sparc/dev/tctrl.c index 3f76cf2660c..d8a9a2fff72 100644 --- a/sys/arch/sparc/dev/tctrl.c +++ b/sys/arch/sparc/dev/tctrl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tctrl.c,v 1.10 2005/03/29 16:26:44 miod Exp $ */ +/* $OpenBSD: tctrl.c,v 1.11 2005/04/11 01:49:50 miod Exp $ */ /* $NetBSD: tctrl.c,v 1.2 1999/08/11 00:46:06 matt Exp $ */ /*- @@ -147,6 +147,7 @@ struct tctrl_softc { u_int sc_cmdlen; u_int sc_rspoff; u_int sc_rsplen; + u_int sc_rspack; u_int sc_bellfreq; u_int sc_bellvol; @@ -168,7 +169,7 @@ void tctrl_lcd(struct tctrl_softc *, int, int); u_int8_t tctrl_read_data(struct tctrl_softc *); void tctrl_read_event_status(void *); void tctrl_read_ext_status(struct tctrl_softc *); -void tctrl_request(struct tctrl_softc *, struct tctrl_req *); +int tctrl_request(struct tctrl_softc *, struct tctrl_req *); void tctrl_tft(struct tctrl_softc *); void tctrl_write_data(struct tctrl_softc *, u_int8_t); @@ -320,7 +321,7 @@ again: d = tctrl_read_data(sc); switch (sc->sc_state) { case TCTRL_IDLE: - if (d == 0xfa) { + if (d == TS102_UCTRL_INTR) { /* external event */ timeout_add(&sc->sc_tmo, 1); } else { @@ -329,25 +330,38 @@ again: } goto again; case TCTRL_ACK: - if (d != 0xfe) { - printf("%s: (op=0x%02x): unexpected ack value (0x%02x)\n", - sc->sc_dev.dv_xname, sc->sc_op, d); - } #ifdef TCTRLDEBUG printf(" ack=0x%02x", d); #endif - sc->sc_rsplen--; - sc->sc_rspoff = 0; - sc->sc_state = sc->sc_rsplen ? TCTRL_DATA : TCTRL_IDLE; - sc->sc_wantdata = sc->sc_rsplen ? 1 : 0; + switch (d) { + case TS102_UCTRL_ACK: + sc->sc_rspack = 1; + sc->sc_rsplen--; + sc->sc_rspoff = 0; + sc->sc_state = + sc->sc_rsplen ? TCTRL_DATA : TCTRL_IDLE; + sc->sc_wantdata = sc->sc_rsplen ? 1 : 0; #ifdef TCTRLDEBUG - if (sc->sc_rsplen > 0) { - printf(" [data(%u)]", sc->sc_rsplen); - } else { - printf(" [idle]\n"); - } + if (sc->sc_rsplen > 0) { + printf(" [data(%u)]", sc->sc_rsplen); + } else { + printf(" [idle]\n"); + } #endif - goto again; + goto again; + default: + printf("%s: (op=0x%02x): unexpected return value (0x%02x)\n", + sc->sc_dev.dv_xname, sc->sc_op, d); + /* FALLTHROUGH */ + case TS102_UCTRL_NACK: + printf("%s: command %x failed\n", + sc->sc_dev.dv_xname, sc->sc_op); + sc->sc_rspack = 0; + sc->sc_wantdata = 0; + sc->sc_state = TCTRL_IDLE; + break; + } + break; case TCTRL_DATA: sc->sc_rspbuf[sc->sc_rspoff++] = d; #ifdef TCTRLDEBUG @@ -637,10 +651,10 @@ tctrl_lcd(struct tctrl_softc *sc, int mask, int value) tctrl_request(sc, &req); } -void +int tctrl_request(struct tctrl_softc *sc, struct tctrl_req *req) { - int s; + int s, rv; while (sc->sc_wantdata != 0) { DELAY(1); @@ -659,8 +673,15 @@ tctrl_request(struct tctrl_softc *sc, struct tctrl_req *req) } while (sc->sc_state != TCTRL_IDLE); sc->sc_wantdata = 0; /* just in case... */ - bcopy(sc->sc_rspbuf, req->rspbuf, sc->sc_rsplen); + + rv = sc->sc_rspack; + if (rv != 0) + bcopy(sc->sc_rspbuf, req->rspbuf, sc->sc_rsplen); + else + bzero(req->rspbuf, req->rsplen); /* safety */ splx(s); + + return (rv); } void diff --git a/sys/arch/sparc/dev/ts102reg.h b/sys/arch/sparc/dev/ts102reg.h index e42a2ecf4e0..3cfeede9f92 100644 --- a/sys/arch/sparc/dev/ts102reg.h +++ b/sys/arch/sparc/dev/ts102reg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ts102reg.h,v 1.4 2005/03/29 16:26:44 miod Exp $ */ +/* $OpenBSD: ts102reg.h,v 1.5 2005/04/11 01:49:50 miod Exp $ */ /* $NetBSD: ts102reg.h,v 1.7 2002/09/29 23:23:58 wiz Exp $ */ /*- @@ -174,7 +174,7 @@ struct uctrl_regs { #define TS102_UCTRL_STS_TXNF_STA 0x02 /* transmit FIFO not full */ #define TS102_UCTRL_STS_RXNE_STA 0x04 /* receive FIFO not empty */ #define TS102_UCTRL_STS_RXO_STA 0x08 /* receive FIFO overflow */ -#define TS102_UCTRL_STS_MASK 0x0F /* Only 4 bits significant */ +#define TS102_UCTRL_STS_MASK 0x0f /* Only 4 bits significant */ enum ts102_opcode { /* Argument Returned */ TS102_OP_RD_SERIAL_NUM=0x01, /* none ack + 4 bytes */ @@ -346,12 +346,16 @@ enum ts102_opcode { /* Argument Returned */ TS102_OP_ADMIN_VRFY_USER_PASS=0x71, /* len ack + status */ TS102_OP_ADMIN_GET_SYSTEM_PASS=0x72, /* none ack + <7bytekey> */ TS102_OP_ADMIN_VRFY_SYSTEM_PASS=0x73, /* len ack + status */ - TS102_OP_RD_INT_CHARGE_LEVEL=0x7a, /* ack + 2 byte */ - TS102_OP_RD_EXT_CHARGE_LEVEL=0x7b, /* ack + 2 byte */ + TS102_OP_RD_INT_CHARGE_LEVEL=0x7a, /* ack + 2 byte */ + TS102_OP_RD_EXT_CHARGE_LEVEL=0x7b, /* ack + 2 byte */ #define TS102_CHARGE_UNKNOWN 0xfa - TS102_OP_SLEEP=0x80, /* supposedly sleeps, not sure */ - TS102_OP_ADMIN_POWER_OFF=0x82, /* len none */ - TS102_OP_ADMIN_POWER_RESTART=0x83, /* msb,xx,lsb none */ + TS102_OP_SLEEP=0x80, /* supposedly sleeps, not sure */ + TS102_OP_ADMIN_POWER_OFF=0x82, /* len none */ + TS102_OP_ADMIN_POWER_RESTART=0x83, /* msb,xx,lsb none */ }; +#define TS102_UCTRL_ACK 0xfe +#define TS102_UCTRL_NACK 0xfc +#define TS102_UCTRL_INTR 0xfa + #endif /* _SPARC_DEV_TS102REG_H */ -- cgit v1.2.3