From: kettenis Date: Sat, 16 Dec 2017 21:09:38 +0000 (+0000) Subject: Add support for 1-byte reads and writes. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9072ca2b4acbf251cdc524551ea69ddc75c3966f;p=openbsd Add support for 1-byte reads and writes. --- diff --git a/sys/dev/fdt/rsbvar.h b/sys/dev/fdt/rsbvar.h index 60060ef5193..72ddd1088d8 100644 --- a/sys/dev/fdt/rsbvar.h +++ b/sys/dev/fdt/rsbvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rsbvar.h,v 1.1 2017/12/16 10:22:13 kettenis Exp $ */ +/* $OpenBSD: rsbvar.h,v 1.2 2017/12/16 21:09:38 kettenis Exp $ */ /* * Copyright (c) 2017 Mark kettenis * @@ -25,5 +25,7 @@ struct rsb_attach_args { int rsb_print(void *, const char *); +uint8_t rsb_read_1(void *, uint8_t, uint8_t); uint16_t rsb_read_2(void *, uint8_t, uint8_t); +void rsb_write_1(void *, uint8_t, uint8_t, uint8_t); void rsb_write_2(void *, uint8_t, uint8_t, uint16_t); diff --git a/sys/dev/fdt/sxirsb.c b/sys/dev/fdt/sxirsb.c index b9809cfa325..6136e2a4359 100644 --- a/sys/dev/fdt/sxirsb.c +++ b/sys/dev/fdt/sxirsb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxirsb.c,v 1.1 2017/12/16 10:22:13 kettenis Exp $ */ +/* $OpenBSD: sxirsb.c,v 1.2 2017/12/16 21:09:38 kettenis Exp $ */ /* * Copyright (c) 2017 Mark kettenis * @@ -236,17 +236,12 @@ sxirsb_rta(uint16_t da) return 0; } -uint16_t -rsb_read_2(void *cookie, uint8_t rta, uint8_t addr) +int +sxirsb_do_trans(struct sxirsb_softc *sc) { - struct sxirsb_softc *sc = cookie; uint16_t stat; int timo; - HWRITE4(sc, RSB_CMD, RD16); - HWRITE4(sc, RSB_DAR, rta << 16); - HWRITE4(sc, RSB_AR, addr); - HSET4(sc, RSB_CTRL, RSB_CTRL_START_TRANS); for (timo = 1000; timo > 0; timo--) { if ((HREAD4(sc, RSB_CTRL) & RSB_CTRL_START_TRANS) == 0) @@ -255,36 +250,79 @@ rsb_read_2(void *cookie, uint8_t rta, uint8_t addr) } stat = HREAD4(sc, RSB_STAT); HWRITE4(sc, RSB_STAT, stat); - if (timo == 0 || stat != RSB_STAT_TRANS_OVER) { - printf(": RD16 failed for run-time address 0x%02x\n", rta); + if (stat != RSB_STAT_TRANS_OVER) + return EIO; + if (timo == 0) + return ETIMEDOUT; + return 0; +} + +uint8_t +rsb_read_1(void *cookie, uint8_t rta, uint8_t addr) +{ + struct sxirsb_softc *sc = cookie; + + HWRITE4(sc, RSB_CMD, RD8); + HWRITE4(sc, RSB_DAR, rta << 16); + HWRITE4(sc, RSB_AR, addr); + + if (sxirsb_do_trans(sc)) { + printf("%s: RD8 failed for run-time address 0x%02x\n", + sc->sc_dev.dv_xname, rta); + return 0xff; + } + + return HREAD4(sc, RSB_DATA); +} + +uint16_t +rsb_read_2(void *cookie, uint8_t rta, uint8_t addr) +{ + struct sxirsb_softc *sc = cookie; + + HWRITE4(sc, RSB_CMD, RD16); + HWRITE4(sc, RSB_DAR, rta << 16); + HWRITE4(sc, RSB_AR, addr); + + if (sxirsb_do_trans(sc)) { + printf("%s: RD16 failed for run-time address 0x%02x\n", + sc->sc_dev.dv_xname, rta); return 0xff; } return HREAD4(sc, RSB_DATA); } +void +rsb_write_1(void *cookie, uint8_t rta, uint8_t addr, uint8_t data) +{ + struct sxirsb_softc *sc = cookie; + + HWRITE4(sc, RSB_CMD, WR8); + HWRITE4(sc, RSB_DAR, rta << 16); + HWRITE4(sc, RSB_AR, addr); + HWRITE4(sc, RSB_DATA, data); + + if (sxirsb_do_trans(sc)) { + printf("%s: WR8 failed for run-time address 0x%02x\n", + sc->sc_dev.dv_xname, rta); + return; + } +} + void rsb_write_2(void *cookie, uint8_t rta, uint8_t addr, uint16_t data) { struct sxirsb_softc *sc = cookie; - uint16_t stat; - int timo; HWRITE4(sc, RSB_CMD, WR16); HWRITE4(sc, RSB_DAR, rta << 16); HWRITE4(sc, RSB_AR, addr); HWRITE4(sc, RSB_DATA, data); - HSET4(sc, RSB_CTRL, RSB_CTRL_START_TRANS); - for (timo = 1000; timo > 0; timo--) { - if ((HREAD4(sc, RSB_CTRL) & RSB_CTRL_START_TRANS) == 0) - break; - delay(10); - } - stat = HREAD4(sc, RSB_STAT); - HWRITE4(sc, RSB_STAT, stat); - if (timo == 0 || stat != RSB_STAT_TRANS_OVER) { - printf(": WR16 failed for run-time address 0x%02x\n", rta); + if (sxirsb_do_trans(sc)) { + printf("%s: WR16 failed for run-time address 0x%02x\n", + sc->sc_dev.dv_xname, rta); return; } }