1 /* $NetBSD: hil_gpib.c,v 1.12 2012/10/27 17:18:16 chs Exp $ */ 2 3 #include <sys/cdefs.h> 4 __KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.12 2012/10/27 17:18:16 chs 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 int hilmatch(device_t, cfdata_t, void *); 42 void hilattach(device_t, device_t, void *); 43 44 const struct cfattach hil_ca = { 45 sizeof(struct hil_softc), hilmatch, hilattach, 46 }; 47 48 void hilcallback(void *, int); 49 void hilstart(void *); 50 51 int 52 hilmatch(device_t parent, cfdata_t match, void *aux) 53 { 54 struct gpib_attach_args *ga = aux; 55 u_int8_t *cmd = "SE;"; 56 u_int8_t stat; 57 58 if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3) 59 return (0); 60 if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1) 61 return (0); 62 printf("hilmatch: enable status byte 0x%x\n", stat); 63 return (1); 64 } 65 66 void 67 hilattach(device_t parent, device_t self, void *aux) 68 { 69 struct hil_softc *sc = device_private(self); 70 struct gpib_attach_args *ga = aux; 71 72 printf("\n"); 73 74 sc->sc_ic = ga->ga_ic; 75 sc->sc_address = ga->ga_address; 76 77 if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc, 78 &sc->sc_hdl)) { 79 aprint_error_dev(self, "can't register callback\n"); 80 return; 81 } 82 83 sc->sc_flags = HILF_ALIVE; 84 } 85 86 void 87 hilcallback(void *v, int action) 88 { 89 struct hil_softc *sc = v; 90 91 DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action)); 92 93 switch (action) { 94 case GPIBCBF_START: 95 hilstart(sc); 96 case GPIBCBF_INTR: 97 /* no-op */ 98 break; 99 #ifdef DEBUG 100 default: 101 DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n", 102 action)); 103 break; 104 #endif 105 } 106 } 107 108 void 109 hilstart(void *v) 110 { 111 struct hil_softc *sc = v; 112 113 DPRINTF(HDB_FOLLOW, ("hilstart\n")); 114 115 sc->sc_flags &= ~HILF_DELAY; 116 } 117