1*fb81b038Sthorpej /* $NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $ */
2a62911e9Slukem
3a62911e9Slukem #include <sys/cdefs.h>
4*fb81b038Sthorpej __KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $");
5a62911e9Slukem
65c3ec26cSgmcgarry #include <sys/param.h>
75c3ec26cSgmcgarry #include <sys/systm.h>
85c3ec26cSgmcgarry #include <sys/callout.h>
95c3ec26cSgmcgarry #include <sys/conf.h>
105c3ec26cSgmcgarry #include <sys/device.h>
115c3ec26cSgmcgarry
125c3ec26cSgmcgarry #include <dev/gpib/gpibvar.h>
135c3ec26cSgmcgarry
145c3ec26cSgmcgarry #ifdef DEBUG
155c3ec26cSgmcgarry int hildebug = 0;
165c3ec26cSgmcgarry #define HDB_FOLLOW 0x01
175c3ec26cSgmcgarry #define HDB_MMAP 0x02
185c3ec26cSgmcgarry #define HDB_MASK 0x04
195c3ec26cSgmcgarry #define HDB_CONFIG 0x08
205c3ec26cSgmcgarry #define HDB_KEYBOARD 0x10
215c3ec26cSgmcgarry #define HDB_IDMODULE 0x20
225c3ec26cSgmcgarry #define HDB_EVENTS 0x80
235c3ec26cSgmcgarry #define DPRINTF(mask, str) if (hildebug & (mask)) printf str
245c3ec26cSgmcgarry #else
255c3ec26cSgmcgarry #define DPRINTF(mask, str) /* nothing */
265c3ec26cSgmcgarry #endif
275c3ec26cSgmcgarry
285c3ec26cSgmcgarry struct hil_softc {
295c3ec26cSgmcgarry gpib_chipset_tag_t sc_ic;
305c3ec26cSgmcgarry gpib_handle_t sc_hdl;
315c3ec26cSgmcgarry
325c3ec26cSgmcgarry int sc_address; /* GPIB address */
335c3ec26cSgmcgarry int sc_flags;
345c3ec26cSgmcgarry #define HILF_ALIVE 0x01
355c3ec26cSgmcgarry #define HILF_OPEN 0x02
365c3ec26cSgmcgarry #define HILF_UIO 0x04
375c3ec26cSgmcgarry #define HILF_TIMO 0x08
385c3ec26cSgmcgarry #define HILF_DELAY 0x10
395c3ec26cSgmcgarry };
405c3ec26cSgmcgarry
41*fb81b038Sthorpej static int hilmatch(device_t, cfdata_t, void *);
42*fb81b038Sthorpej static void hilattach(device_t, device_t, void *);
435c3ec26cSgmcgarry
44*fb81b038Sthorpej CFATTACH_DECL_NEW(hil_gpib,
45*fb81b038Sthorpej sizeof(struct hil_softc),
46*fb81b038Sthorpej hilmatch,
47*fb81b038Sthorpej hilattach,
48*fb81b038Sthorpej NULL,
49*fb81b038Sthorpej NULL);
505c3ec26cSgmcgarry
51*fb81b038Sthorpej static void hilcallback(void *, int);
52*fb81b038Sthorpej static void hilstart(void *);
535c3ec26cSgmcgarry
54*fb81b038Sthorpej static int
hilmatch(device_t parent,cfdata_t match,void * aux)55529e91fcScegger hilmatch(device_t parent, cfdata_t match, void *aux)
565c3ec26cSgmcgarry {
575c3ec26cSgmcgarry struct gpib_attach_args *ga = aux;
585c3ec26cSgmcgarry u_int8_t *cmd = "SE;";
595c3ec26cSgmcgarry u_int8_t stat;
605c3ec26cSgmcgarry
615c3ec26cSgmcgarry if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3)
625c3ec26cSgmcgarry return (0);
635c3ec26cSgmcgarry if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1)
645c3ec26cSgmcgarry return (0);
655c3ec26cSgmcgarry printf("hilmatch: enable status byte 0x%x\n", stat);
665c3ec26cSgmcgarry return (1);
675c3ec26cSgmcgarry }
685c3ec26cSgmcgarry
69*fb81b038Sthorpej static void
hilattach(device_t parent,device_t self,void * aux)70529e91fcScegger hilattach(device_t parent, device_t self, void *aux)
715c3ec26cSgmcgarry {
7292c7bba3Sthorpej struct hil_softc *sc = device_private(self);
735c3ec26cSgmcgarry struct gpib_attach_args *ga = aux;
745c3ec26cSgmcgarry
755c3ec26cSgmcgarry printf("\n");
765c3ec26cSgmcgarry
775c3ec26cSgmcgarry sc->sc_ic = ga->ga_ic;
785c3ec26cSgmcgarry sc->sc_address = ga->ga_address;
795c3ec26cSgmcgarry
805c3ec26cSgmcgarry if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc,
815c3ec26cSgmcgarry &sc->sc_hdl)) {
82cbab9cadSchs aprint_error_dev(self, "can't register callback\n");
835c3ec26cSgmcgarry return;
845c3ec26cSgmcgarry }
855c3ec26cSgmcgarry
865c3ec26cSgmcgarry sc->sc_flags = HILF_ALIVE;
875c3ec26cSgmcgarry }
885c3ec26cSgmcgarry
89*fb81b038Sthorpej static void
hilcallback(void * v,int action)90454af1c0Sdsl hilcallback(void *v, int action)
915c3ec26cSgmcgarry {
925c3ec26cSgmcgarry struct hil_softc *sc = v;
935c3ec26cSgmcgarry
945c3ec26cSgmcgarry DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action));
955c3ec26cSgmcgarry
965c3ec26cSgmcgarry switch (action) {
975c3ec26cSgmcgarry case GPIBCBF_START:
985c3ec26cSgmcgarry hilstart(sc);
995c3ec26cSgmcgarry case GPIBCBF_INTR:
1005c3ec26cSgmcgarry /* no-op */
1015c3ec26cSgmcgarry break;
1025c3ec26cSgmcgarry #ifdef DEBUG
1035c3ec26cSgmcgarry default:
1045c3ec26cSgmcgarry DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n",
1055c3ec26cSgmcgarry action));
1065c3ec26cSgmcgarry break;
1075c3ec26cSgmcgarry #endif
1085c3ec26cSgmcgarry }
1095c3ec26cSgmcgarry }
1105c3ec26cSgmcgarry
111*fb81b038Sthorpej static void
hilstart(void * v)112454af1c0Sdsl hilstart(void *v)
1135c3ec26cSgmcgarry {
1145c3ec26cSgmcgarry struct hil_softc *sc = v;
1155c3ec26cSgmcgarry
116cbab9cadSchs DPRINTF(HDB_FOLLOW, ("hilstart\n"));
1175c3ec26cSgmcgarry
1185c3ec26cSgmcgarry sc->sc_flags &= ~HILF_DELAY;
1195c3ec26cSgmcgarry }
120