1 /* $NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $ */ 2 3 #include <sys/cdefs.h> 4 __KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $"); 5 6 #include <sys/param.h> 7 #include <sys/systm.h> 8 #include <sys/callout.h> 9 #include <sys/conf.h> 10 #include <sys/device.h> 11 12 #include <dev/gpib/gpibvar.h> 13 14 #ifdef DEBUG 15 int hildebug = 0; 16 #define HDB_FOLLOW 0x01 17 #define HDB_MMAP 0x02 18 #define HDB_MASK 0x04 19 #define HDB_CONFIG 0x08 20 #define HDB_KEYBOARD 0x10 21 #define HDB_IDMODULE 0x20 22 #define HDB_EVENTS 0x80 23 #define DPRINTF(mask, str) if (hildebug & (mask)) printf str 24 #else 25 #define DPRINTF(mask, str) /* nothing */ 26 #endif 27 28 struct hil_softc { 29 gpib_chipset_tag_t sc_ic; 30 gpib_handle_t sc_hdl; 31 32 int sc_address; /* GPIB address */ 33 int sc_flags; 34 #define HILF_ALIVE 0x01 35 #define HILF_OPEN 0x02 36 #define HILF_UIO 0x04 37 #define HILF_TIMO 0x08 38 #define HILF_DELAY 0x10 39 }; 40 41 static int hilmatch(device_t, cfdata_t, void *); 42 static void hilattach(device_t, device_t, void *); 43 44 CFATTACH_DECL_NEW(hil_gpib, 45 sizeof(struct hil_softc), 46 hilmatch, 47 hilattach, 48 NULL, 49 NULL); 50 51 static void hilcallback(void *, int); 52 static void hilstart(void *); 53 54 static int 55 hilmatch(device_t parent, cfdata_t match, void *aux) 56 { 57 struct gpib_attach_args *ga = aux; 58 u_int8_t *cmd = "SE;"; 59 u_int8_t stat; 60 61 if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3) 62 return (0); 63 if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1) 64 return (0); 65 printf("hilmatch: enable status byte 0x%x\n", stat); 66 return (1); 67 } 68 69 static void 70 hilattach(device_t parent, device_t self, void *aux) 71 { 72 struct hil_softc *sc = device_private(self); 73 struct gpib_attach_args *ga = aux; 74 75 printf("\n"); 76 77 sc->sc_ic = ga->ga_ic; 78 sc->sc_address = ga->ga_address; 79 80 if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc, 81 &sc->sc_hdl)) { 82 aprint_error_dev(self, "can't register callback\n"); 83 return; 84 } 85 86 sc->sc_flags = HILF_ALIVE; 87 } 88 89 static void 90 hilcallback(void *v, int action) 91 { 92 struct hil_softc *sc = v; 93 94 DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action)); 95 96 switch (action) { 97 case GPIBCBF_START: 98 hilstart(sc); 99 case GPIBCBF_INTR: 100 /* no-op */ 101 break; 102 #ifdef DEBUG 103 default: 104 DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n", 105 action)); 106 break; 107 #endif 108 } 109 } 110 111 static void 112 hilstart(void *v) 113 { 114 struct hil_softc *sc = v; 115 116 DPRINTF(HDB_FOLLOW, ("hilstart\n")); 117 118 sc->sc_flags &= ~HILF_DELAY; 119 } 120