Lines Matching refs:sc

103 int	send_device_cmd(struct hil_softc *sc, u_int device, u_int cmd);
110 #define hil_process_pending(sc) wakeup(&(sc)->sc_pending) argument
113 hilwait(struct hil_softc *sc) in hilwait() argument
119 if ((bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT) & in hilwait()
128 hildatawait(struct hil_softc *sc) in hildatawait() argument
134 if ((bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT) & in hildatawait()
147 hil_attach(struct hil_softc *sc, int *hil_is_console) in hil_attach() argument
154 sc->sc_cmdending = 0; in hil_attach()
155 sc->sc_actdev = sc->sc_cmddev = 0; in hil_attach()
156 sc->sc_cmddone = 0; in hil_attach()
157 sc->sc_cmdbp = sc->sc_cmdbuf; in hil_attach()
158 sc->sc_pollbp = sc->sc_pollbuf; in hil_attach()
159 sc->sc_console = hil_is_console; in hil_attach()
199 struct hil_softc *sc = v; in hil_attach_deferred() local
203 sc->sc_status = HIL_STATUS_BUSY; in hil_attach_deferred()
210 send_hil_cmd(sc, HIL_WRITELPCTRL, &db, 1, NULL); in hil_attach_deferred()
217 if (bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT) & in hil_attach_deferred()
219 db = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in hil_attach_deferred()
230 if (send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db) == 0) { in hil_attach_deferred()
237 sc->sc_dev.dv_xname); in hil_attach_deferred()
244 printf("%s: no devices\n", sc->sc_dev.dv_xname); in hil_attach_deferred()
245 sc->sc_pending = 0; in hil_attach_deferred()
253 if (kthread_create(hil_thread, sc, &sc->sc_thread, in hil_attach_deferred()
254 sc->sc_dev.dv_xname) != 0) { in hil_attach_deferred()
256 sc->sc_dev.dv_xname); in hil_attach_deferred()
263 send_hil_cmd(sc, HIL_INTON, NULL, 0, NULL); in hil_attach_deferred()
268 sc->sc_status = HIL_STATUS_READY; in hil_attach_deferred()
269 hil_process_pending(sc); in hil_attach_deferred()
279 struct hil_softc *sc = v; in hil_intr() local
285 stat = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT); in hil_intr()
294 c = bus_space_read_1(sc->sc_bst, sc->sc_bsh, in hil_intr()
298 hil_process_int(sc, stat, c); in hil_intr()
300 if (sc->sc_status != HIL_STATUS_BUSY) in hil_intr()
301 hil_process_pending(sc); in hil_intr()
307 hil_process_int(struct hil_softc *sc, u_int8_t stat, u_int8_t c) in hil_process_int() argument
314 sc->sc_cmddone = 1; in hil_process_int()
317 sc->sc_pending = HIL_PENDING_RECONFIG; in hil_process_int()
320 sc->sc_pending = HIL_PENDING_UNPLUGGED; in hil_process_int()
327 dev = sc->sc_devices[sc->sc_actdev]; in hil_process_int()
330 sc->sc_pollbp - sc->sc_pollbuf, in hil_process_int()
331 sc->sc_pollbuf); in hil_process_int()
333 sc->sc_cmdending = 1; in hil_process_int()
335 sc->sc_actdev = 0; in hil_process_int()
338 sc->sc_actdev = (c & HIL_DEVMASK); in hil_process_int()
339 sc->sc_pollbp = sc->sc_pollbuf; in hil_process_int()
341 if (sc->sc_cmddev == (c & HIL_DEVMASK)) { in hil_process_int()
342 sc->sc_cmdbp = sc->sc_cmdbuf; in hil_process_int()
343 sc->sc_actdev = 0; in hil_process_int()
349 if (sc->sc_actdev != 0) /* Collecting poll data */ in hil_process_int()
350 *sc->sc_pollbp++ = c; in hil_process_int()
352 if (sc->sc_cmddev != 0) { /* Collecting cmd data */ in hil_process_int()
353 if (sc->sc_cmdending) { in hil_process_int()
354 sc->sc_cmddone = 1; in hil_process_int()
355 sc->sc_cmdending = 0; in hil_process_int()
357 *sc->sc_cmdbp++ = c; in hil_process_int()
369 hil_process_poll(struct hil_softc *sc, u_int8_t stat, u_int8_t c) in hil_process_poll() argument
376 sc->sc_cmddone = 1; in hil_process_poll()
384 sc->sc_pending = HIL_PENDING_RECONFIG; in hil_process_poll()
392 send_hil_cmd(sc, HIL_WRITEKBDSADR, &db, in hil_process_poll()
401 sc->sc_pending = HIL_PENDING_UNPLUGGED; in hil_process_poll()
409 sc->sc_cmdending = 1; in hil_process_poll()
411 sc->sc_actdev = 0; in hil_process_poll()
415 sc->sc_actdev = (c & HIL_DEVMASK); in hil_process_poll()
416 sc->sc_pollbp = sc->sc_pollbuf; in hil_process_poll()
419 if (sc->sc_cmddev == (c & HIL_DEVMASK)) { in hil_process_poll()
420 sc->sc_cmdbp = sc->sc_cmdbuf; in hil_process_poll()
421 sc->sc_actdev = 0; in hil_process_poll()
427 if (sc->sc_actdev != 0) /* Collecting poll data */ in hil_process_poll()
430 if (sc->sc_cmddev != 0) { /* Discarding cmd data */ in hil_process_poll()
431 if (sc->sc_cmdending) { in hil_process_poll()
432 sc->sc_cmddone = 1; in hil_process_poll()
433 sc->sc_cmdending = 0; in hil_process_poll()
446 struct hil_softc *sc = arg; in hil_thread() local
451 if (sc->sc_pending == 0) { in hil_thread()
453 tsleep_nsec(&sc->sc_pending, PWAIT, "hil_event", in hil_thread()
458 switch (sc->sc_pending) { in hil_thread()
460 sc->sc_pending = 0; in hil_thread()
461 hilconfig(sc, sc->sc_maxdev); in hil_thread()
464 sc->sc_pending = 0; in hil_thread()
465 hilempty(sc); in hil_thread()
489 hilconfig(struct hil_softc *sc, u_int knowndevs) in hilconfig() argument
501 send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db); in hilconfig()
502 sc->sc_maxdev = db & LPS_DEVMASK; in hilconfig()
504 printf("%s: %d device(s)\n", sc->sc_dev.dv_xname, sc->sc_maxdev); in hilconfig()
511 send_hil_cmd(sc, HIL_WRITEKBDSADR, &db, 1, NULL); in hilconfig()
516 for (id = knowndevs + 1; id <= sc->sc_maxdev; id++) { in hilconfig()
520 if (send_device_cmd(sc, id, HIL_IDENTIFY) != 0) { in hilconfig()
522 sc->sc_dev.dv_xname, id); in hilconfig()
526 len = sc->sc_cmdbp - sc->sc_cmdbuf; in hilconfig()
530 sc->sc_dev.dv_xname, id); in hilconfig()
537 if (sc->sc_cmdbuf[0] >= hd->minid && in hilconfig()
538 sc->sc_cmdbuf[0] <= hd->maxid) { in hilconfig()
540 ha.ha_console = *sc->sc_console; in hilconfig()
545 bcopy(sc->sc_cmdbuf, ha.ha_info, len); in hilconfig()
547 sc->sc_devices[id] = (struct hildev_softc *) in hilconfig()
548 config_found_sm(&sc->sc_dev, &ha, hildevprint, in hilconfig()
556 if (sc->sc_devices[id] != NULL && in hilconfig()
559 *sc->sc_console = 1; in hilconfig()
567 for (id = sc->sc_maxdev + 1; id < NHILD; id++) { in hilconfig()
568 if (sc->sc_devices[id] != NULL) in hilconfig()
569 config_detach((struct device *)sc->sc_devices[id], in hilconfig()
571 sc->sc_devices[id] = NULL; in hilconfig()
574 sc->sc_cmdbp = sc->sc_cmdbuf; in hilconfig()
584 hilempty(struct hil_softc *sc) in hilempty() argument
596 if (send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db) == 0) { in hilempty()
606 sc->sc_maxdev = 0; in hilempty()
609 send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db); in hilempty()
610 oldmaxdev = sc->sc_maxdev; in hilempty()
611 sc->sc_maxdev = db & LPS_DEVMASK; in hilempty()
613 if (sc->sc_maxdev != 0) { in hilempty()
618 hilconfig(sc, oldmaxdev); in hilempty()
627 for (id = sc->sc_maxdev + 1; id < NHILD; id++) { in hilempty()
628 if (sc->sc_devices[id] != NULL) in hilempty()
629 config_detach((struct device *)sc->sc_devices[id], in hilempty()
631 sc->sc_devices[id] = NULL; in hilempty()
634 sc->sc_cmdbp = sc->sc_cmdbuf; in hilempty()
648 send_hil_cmd(struct hil_softc *sc, u_int cmd, u_int8_t *data, u_int dlen, in send_hil_cmd() argument
656 if (hilwait(sc) == 0) { in send_hil_cmd()
658 printf("%s: no answer from the loop\n", sc->sc_dev.dv_xname); in send_hil_cmd()
664 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, cmd); in send_hil_cmd()
666 hilwait(sc); in send_hil_cmd()
667 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, *data++); in send_hil_cmd()
672 if (hildatawait(sc) == 0) { in send_hil_cmd()
675 sc->sc_dev.dv_xname); in send_hil_cmd()
679 status = bus_space_read_1(sc->sc_bst, sc->sc_bsh, in send_hil_cmd()
681 *rdata = bus_space_read_1(sc->sc_bst, sc->sc_bsh, in send_hil_cmd()
700 send_device_cmd(struct hil_softc *sc, u_int device, u_int cmd) in send_device_cmd() argument
705 polloff(sc); in send_device_cmd()
707 sc->sc_cmdbp = sc->sc_cmdbuf; in send_device_cmd()
708 sc->sc_cmddev = device; in send_device_cmd()
710 if (hilwait(sc) == 0) { in send_device_cmd()
713 sc->sc_dev.dv_xname, device); in send_device_cmd()
722 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_STARTCMD); in send_device_cmd()
723 hilwait(sc); in send_device_cmd()
724 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, 8 + device); in send_device_cmd()
725 hilwait(sc); in send_device_cmd()
726 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, cmd); in send_device_cmd()
727 hilwait(sc); in send_device_cmd()
728 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, HIL_TIMEOUT); in send_device_cmd()
733 hilwait(sc); in send_device_cmd()
734 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_TRIGGER); in send_device_cmd()
735 sc->sc_cmddone = 0; in send_device_cmd()
737 if (hildatawait(sc) == 0) { in send_device_cmd()
740 sc->sc_dev.dv_xname, device); in send_device_cmd()
745 status = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT); in send_device_cmd()
746 c = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in send_device_cmd()
748 hil_process_int(sc, status, c); in send_device_cmd()
749 } while (sc->sc_cmddone == 0); in send_device_cmd()
751 sc->sc_cmddev = 0; in send_device_cmd()
753 pollon(sc); in send_device_cmd()
761 struct hil_softc *sc = (struct hil_softc *)dev->sc_dev.dv_parent; in send_hildev_cmd() local
766 if ((rc = send_device_cmd(sc, dev->sc_code, cmd)) == 0) { in send_hildev_cmd()
771 *outlen = min(*outlen, sc->sc_cmdbp - sc->sc_cmdbuf); in send_hildev_cmd()
772 bcopy(sc->sc_cmdbuf, outbuf, *outlen); in send_hildev_cmd()
784 polloff(struct hil_softc *sc) in polloff() argument
788 if (hilwait(sc) == 0) in polloff()
794 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_SETARR); in polloff()
795 hilwait(sc); in polloff()
796 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, 0); in polloff()
801 hilwait(sc); in polloff()
802 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_READLPCTRL); in polloff()
803 hildatawait(sc); in polloff()
804 db = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in polloff()
806 hilwait(sc); in polloff()
807 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_WRITELPCTRL); in polloff()
808 hilwait(sc); in polloff()
809 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, db); in polloff()
815 hilwait(sc); in polloff()
816 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_READBUSY); in polloff()
817 hildatawait(sc); in polloff()
818 db = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in polloff()
821 sc->sc_cmddone = 0; in polloff()
822 sc->sc_cmddev = 0; in polloff()
826 pollon(struct hil_softc *sc) in pollon() argument
830 if (hilwait(sc) == 0) in pollon()
836 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_READLPCTRL); in pollon()
837 hildatawait(sc); in pollon()
838 db = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in pollon()
840 hilwait(sc); in pollon()
841 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_WRITELPCTRL); in pollon()
842 hilwait(sc); in pollon()
843 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, db); in pollon()
848 hilwait(sc); in pollon()
849 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_CMD, HIL_SETARR); in pollon()
850 hilwait(sc); in pollon()
851 bus_space_write_1(sc->sc_bst, sc->sc_bsh, HILP_DATA, 0); in pollon()
856 hil_set_poll(struct hil_softc *sc, int on) in hil_set_poll() argument
859 pollon(sc); in hil_set_poll()
861 hil_process_pending(sc); in hil_set_poll()
862 send_hil_cmd(sc, HIL_INTON, NULL, 0, NULL); in hil_set_poll()
869 struct hil_softc *sc = (struct hil_softc *)dev->sc_dev.dv_parent; in hil_poll_data() local
872 s = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_STAT); in hil_poll_data()
876 c = bus_space_read_1(sc->sc_bst, sc->sc_bsh, HILP_DATA); in hil_poll_data()
879 if (hil_process_poll(sc, s, c)) { in hil_poll_data()
881 if (sc->sc_actdev == dev->sc_code) { in hil_poll_data()