Lines Matching refs:sc

153 	struct cmx_softc *sc = device_get_softc(dev);
154 sc->dev = dev;
155 sc->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
169 struct cmx_softc *sc = device_get_softc(dev);
174 sc->ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
175 &sc->ioport_rid, RF_ACTIVE);
176 if (!sc->ioport) {
180 sc->bst = rman_get_bustag(sc->ioport);
181 sc->bsh = rman_get_bushandle(sc->ioport);
184 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
185 &sc->irq_rid, RF_ACTIVE);
186 if (!sc->irq) {
190 if ((rv = bus_setup_intr(dev, sc->irq, INTR_TYPE_TTY,
191 cmx_intr, sc, &sc->ih)) != 0) {
197 mtx_init(&sc->mtx, device_get_nameunit(dev),
200 callout_init_mtx(&sc->ch, &sc->mtx, 0);
211 struct cmx_softc *sc = device_get_softc(dev);
213 mtx_destroy(&sc->mtx);
216 if (sc->ih) {
217 bus_teardown_intr(dev, sc->irq, sc->ih);
218 sc->ih = NULL;
220 if (sc->irq) {
222 sc->irq_rid, sc->irq);
223 sc->irq = NULL;
227 if (sc->ioport) {
229 sc->ioport_rid, sc->ioport);
231 sc->ioport_rid, sc->ioport);
232 sc->ioport = NULL;
244 struct cmx_softc *sc = device_get_softc(dev);
246 if (!sc || sc->dying)
249 sc->cdev = make_dev(&cmx_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
251 if (!sc->cdev) {
255 sc->cdev->si_drv1 = sc;
268 struct cmx_softc *sc = device_get_softc(dev);
272 sc->dying = 1;
274 CMX_LOCK(sc);
275 if (sc->polling) {
276 DEBUG_printf(sc->dev, "disabling polling\n");
277 callout_stop(&sc->ch);
278 sc->polling = 0;
279 CMX_UNLOCK(sc);
280 callout_drain(&sc->ch);
281 selwakeuppri(&sc->sel, PZERO);
283 CMX_UNLOCK(sc);
286 wakeup(sc);
287 destroy_dev(sc->cdev);
304 cmx_wait_BSR(struct cmx_softc *sc, uint8_t flags, int test)
309 if (cmx_test_BSR(sc, flags, test))
313 for (int i = 0; i * WAIT_TICKS < sc->timeout; i++) {
314 if (cmx_test_BSR(sc, flags, test))
316 rv = tsleep(sc, PWAIT|PCATCH, "cmx", WAIT_TICKS);
320 * case sc->dying is always 1.
322 if (sc->dying)
340 cmx_sync_write_SCR(struct cmx_softc *sc, uint8_t val)
344 if ((rv = cmx_wait_BSR(sc, BSR_BULK_OUT_FULL, 0)) != 0) {
348 cmx_write_SCR(sc, val);
350 if ((rv = cmx_wait_BSR(sc, BSR_BULK_OUT_FULL, 0)) != 0) {
395 struct cmx_softc *sc = xsc;
398 CMX_LOCK(sc);
399 if (sc->polling && !sc->dying) {
400 bsr = cmx_read_BSR(sc);
401 DEBUG_printf(sc->dev, "BSR=%b\n", bsr, BSRBITS);
403 sc->polling = 0;
404 selwakeuppri(&sc->sel, PZERO);
406 callout_reset(&sc->ch, POLL_TICKS, cmx_tick, sc);
409 CMX_UNLOCK(sc);
419 struct cmx_softc *sc = cdev->si_drv1;
421 if (sc == NULL || sc->dying)
424 CMX_LOCK(sc);
425 if (sc->open) {
426 CMX_UNLOCK(sc);
429 sc->open = 1;
430 CMX_UNLOCK(sc);
432 DEBUG_printf(sc->dev, "open (flags=%b thread=%p)\n",
443 struct cmx_softc *sc = cdev->si_drv1;
445 if (sc == NULL || sc->dying)
448 CMX_LOCK(sc);
449 if (!sc->open) {
450 CMX_UNLOCK(sc);
453 if (sc->polling) {
454 DEBUG_printf(sc->dev, "disabling polling\n");
455 callout_stop(&sc->ch);
456 sc->polling = 0;
457 CMX_UNLOCK(sc);
458 callout_drain(&sc->ch);
459 selwakeuppri(&sc->sel, PZERO);
460 CMX_LOCK(sc);
462 sc->open = 0;
463 CMX_UNLOCK(sc);
465 DEBUG_printf(sc->dev, "close (flags=%b thread=%p)\n",
480 struct cmx_softc *sc = cdev->si_drv1;
485 if (sc == NULL || sc->dying)
488 DEBUG_printf(sc->dev, "called (len=%d flag=%b)\n",
491 CMX_LOCK(sc);
492 if (sc->polling) {
493 DEBUG_printf(sc->dev, "disabling polling\n");
494 callout_stop(&sc->ch);
495 sc->polling = 0;
496 CMX_UNLOCK(sc);
497 callout_drain(&sc->ch);
498 selwakeuppri(&sc->sel, PZERO);
500 CMX_UNLOCK(sc);
512 if (cmx_test_BSR(sc, BSR_BULK_IN_FULL, 0)) {
518 if ((rv = cmx_wait_BSR(sc, BSR_BULK_IN_FULL, 1)) != 0) {
521 sc->buf[i] = cmx_read_DTR(sc);
522 DEBUG_printf(sc->dev, "buf[%02x]=%02x\n", i, sc->buf[i]);
526 (0x000000FF&((char)sc->buf[1])) +
527 (0x0000FF00&((char)sc->buf[2] << 8)) +
528 (0x00FF0000&((char)sc->buf[3] << 16)) +
529 (0xFF000000&((char)sc->buf[4] << 24));
530 DEBUG_printf(sc->dev, "msgsz=%lu\n", bytes_left);
538 amnt = MIN(bytes_left, sizeof(sc->buf));
541 if ((rv = cmx_wait_BSR(sc, BSR_BULK_IN_FULL, 1))!=0) {
544 sc->buf[i] = cmx_read_DTR(sc);
545 DEBUG_printf(sc->dev, "buf[%02x]=%02x\n",
546 i, sc->buf[i]);
549 if ((rv = uiomove(sc->buf, amnt, uio)) != 0) {
550 DEBUG_printf(sc->dev, "uiomove failed (%d)\n", rv);
559 if ((rv = cmx_wait_BSR(sc, BSR_BULK_IN_FULL, 1)) != 0) {
563 if ((rv = cmx_sync_write_SCR(sc, SCR_READER_TO_HOST_DONE)) != 0) {
567 uc = cmx_read_DTR(sc);
568 DEBUG_printf(sc->dev, "success (DTR=%02x)\n", uc);
581 struct cmx_softc *sc = cdev->si_drv1;
584 if (sc == NULL || sc->dying)
587 DEBUG_printf(sc->dev, "called (len=%d flag=%b)\n",
598 if ((rv = cmx_sync_write_SCR(sc, SCR_HOST_TO_READER_START)) != 0) {
602 sc->timeout = 0;
604 amnt = MIN(uio->uio_resid, sizeof(sc->buf));
606 if ((rv = uiomove(sc->buf, amnt, uio)) != 0) {
607 DEBUG_printf(sc->dev, "uiomove failed (%d)\n", rv);
609 sc->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
610 cmx_sync_write_SCR(sc, SCR_HOST_TO_READER_DONE);
614 if (sc->timeout == 0) {
615 sc->timeout = cmx_timeout_by_cmd(sc->buf[0]);
616 DEBUG_printf(sc->dev, "cmd=%02x timeout=%lu\n",
617 sc->buf[0], sc->timeout);
621 if ((rv = cmx_wait_BSR(sc, BSR_BULK_OUT_FULL, 0))!=0) {
624 cmx_write_DTR(sc, sc->buf[i]);
625 DEBUG_printf(sc->dev, "buf[%02x]=%02x\n",
626 i, sc->buf[i]);
630 if ((rv = cmx_sync_write_SCR(sc, SCR_HOST_TO_READER_DONE)) != 0) {
634 DEBUG_printf(sc->dev, "success\n");
641 * set sc->polling.
646 struct cmx_softc *sc = cdev->si_drv1;
650 if (sc == NULL || sc->dying)
653 bsr = cmx_read_BSR(sc);
654 DEBUG_printf(sc->dev, "called (events=%b BSR=%b)\n",
662 selrecord(td, &sc->sel);
663 CMX_LOCK(sc);
664 if (!sc->polling) {
665 DEBUG_printf(sc->dev, "enabling polling\n");
666 sc->polling = 1;
667 callout_reset(&sc->ch, POLL_TICKS,
668 cmx_tick, sc);
670 DEBUG_printf(sc->dev, "already polling\n");
672 CMX_UNLOCK(sc);
676 DEBUG_printf(sc->dev, "success (revents=%b)\n", revents, POLLBITS);
689 struct cmx_softc *sc = (struct cmx_softc *)arg;
691 if (sc == NULL || sc->dying)
694 DEBUG_printf(sc->dev, "received interrupt (SCR=%b BSR=%b)\n",
695 cmx_read_SCR(sc), SCRBITS,
696 cmx_read_BSR(sc), BSRBITS);