void j720kbd_read(struct j720ssp_softc *sc, char *buf) { int data, count; #ifdef DEBUG u_int32_t oscr; oscr = gettick(); #endif bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000); /* send scan keycode command */ if (j720ssp_readwrite(sc, 1, 0x900, &data) < 0 || data != 0x88) goto out; /* read numbers of scancode available */ if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0) goto out; BIT_INVERT(data); count = data; for(; count; count--) { if (j720ssp_readwrite(sc, 0, 0x8800, &data) < 0) goto out; BIT_INVERT(data); *buf++ = data; } *buf = 0; bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000); #ifdef DEBUG oscr = (u_int32_t)gettick() - oscr; j720sspwaitcnt++; j720sspwaittime += oscr; #endif return; out: *buf = 0; bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000); /* reset SSP */ bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307); delay(100); bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387); printf("j720kbd_read: error %x\n", data); }
int j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in, int *out, int wait) { int timeout; while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_TNF)) continue; timeout = 400000; while (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400) if (--timeout == 0) { DPRINTF(("j720ssp_readwrite: timeout 0\n")); return -1; } if (drainfifo) { while (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE) bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR); delay(wait); } BIT_INVERT(in); bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in << 8); delay(wait); timeout = 100000; while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE)) if (--timeout == 0) { DPRINTF(("j720ssp_readwrite: timeout 1\n")); return -1; } *out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR); BIT_INVERT(*out); return 0; }
int j720lcdparam(void *ctx, int type, long id, void *msg) { struct j720ssp_softc *sc = ctx; int i, s; u_int32_t data[2], len; switch (type) { case CONFIG_HOOK_GET: switch (id) { case CONFIG_HOOK_BRIGHTNESS_MAX: case CONFIG_HOOK_CONTRAST_MAX: *(int *)msg = 255; return 1; case CONFIG_HOOK_BRIGHTNESS: data[0] = 0x6b00; data[1] = 0x8800; len = 2; break; case CONFIG_HOOK_CONTRAST: data[0] = 0x2b00; data[1] = 0x8800; len = 2; break; default: return 0; } break; case CONFIG_HOOK_SET: switch (id) { case CONFIG_HOOK_BRIGHTNESS: if (*(int *)msg >= 0) { data[0] = 0xcb00; data[1] = *(int *)msg; BIT_INVERT(data[1]); data[1] <<= 8; len = 2; } else { /* XXX hack */ data[0] = 0xfb00; len = 1; } break; case CONFIG_HOOK_CONTRAST: data[0] = 0x8b00; data[1] = *(int *)msg; BIT_INVERT(data[1]); data[1] <<= 8; len = 2; break; default: return 0; } } s = splbio(); bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PCR, 0x2000000); for (i = 0; i < len; i++) { if (j720ssp_readwrite(sc, 1, data[i], &data[i]) < 0) goto out; } bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000); splx(s); if (type == CONFIG_HOOK_SET) return 1; BIT_INVERT(data[1]); *(int *)msg = data[1]; return 1; out: bus_space_write_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PSR, 0x2000000); /* reset SSP */ bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x307); delay(100); bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_CR0, 0x387); splx(s); return 0; }