11.13Sthorpej/* $NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $ */ 21.2Slukem 31.2Slukem#include <sys/cdefs.h> 41.13Sthorpej__KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.13 2020/05/25 19:01:15 thorpej Exp $"); 51.2Slukem 61.1Sgmcgarry#include <sys/param.h> 71.1Sgmcgarry#include <sys/systm.h> 81.1Sgmcgarry#include <sys/callout.h> 91.1Sgmcgarry#include <sys/conf.h> 101.1Sgmcgarry#include <sys/device.h> 111.1Sgmcgarry 121.1Sgmcgarry#include <dev/gpib/gpibvar.h> 131.1Sgmcgarry 141.1Sgmcgarry#ifdef DEBUG 151.1Sgmcgarryint hildebug = 0; 161.1Sgmcgarry#define HDB_FOLLOW 0x01 171.1Sgmcgarry#define HDB_MMAP 0x02 181.1Sgmcgarry#define HDB_MASK 0x04 191.1Sgmcgarry#define HDB_CONFIG 0x08 201.1Sgmcgarry#define HDB_KEYBOARD 0x10 211.1Sgmcgarry#define HDB_IDMODULE 0x20 221.1Sgmcgarry#define HDB_EVENTS 0x80 231.1Sgmcgarry#define DPRINTF(mask, str) if (hildebug & (mask)) printf str 241.1Sgmcgarry#else 251.1Sgmcgarry#define DPRINTF(mask, str) /* nothing */ 261.1Sgmcgarry#endif 271.1Sgmcgarry 281.1Sgmcgarrystruct hil_softc { 291.1Sgmcgarry gpib_chipset_tag_t sc_ic; 301.1Sgmcgarry gpib_handle_t sc_hdl; 311.1Sgmcgarry 321.1Sgmcgarry int sc_address; /* GPIB address */ 331.1Sgmcgarry int sc_flags; 341.3Sperry#define HILF_ALIVE 0x01 351.3Sperry#define HILF_OPEN 0x02 361.1Sgmcgarry#define HILF_UIO 0x04 371.1Sgmcgarry#define HILF_TIMO 0x08 381.1Sgmcgarry#define HILF_DELAY 0x10 391.1Sgmcgarry}; 401.1Sgmcgarry 411.13Sthorpejstatic int hilmatch(device_t, cfdata_t, void *); 421.13Sthorpejstatic void hilattach(device_t, device_t, void *); 431.1Sgmcgarry 441.13SthorpejCFATTACH_DECL_NEW(hil_gpib, 451.13Sthorpej sizeof(struct hil_softc), 461.13Sthorpej hilmatch, 471.13Sthorpej hilattach, 481.13Sthorpej NULL, 491.13Sthorpej NULL); 501.1Sgmcgarry 511.13Sthorpejstatic void hilcallback(void *, int); 521.13Sthorpejstatic void hilstart(void *); 531.1Sgmcgarry 541.13Sthorpejstatic int 551.11Sceggerhilmatch(device_t parent, cfdata_t match, void *aux) 561.1Sgmcgarry{ 571.1Sgmcgarry struct gpib_attach_args *ga = aux; 581.1Sgmcgarry u_int8_t *cmd = "SE;"; 591.1Sgmcgarry u_int8_t stat; 601.1Sgmcgarry 611.1Sgmcgarry if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3) 621.1Sgmcgarry return (0); 631.1Sgmcgarry if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1) 641.1Sgmcgarry return (0); 651.1Sgmcgarry printf("hilmatch: enable status byte 0x%x\n", stat); 661.1Sgmcgarry return (1); 671.1Sgmcgarry} 681.1Sgmcgarry 691.13Sthorpejstatic void 701.11Sceggerhilattach(device_t parent, device_t self, void *aux) 711.1Sgmcgarry{ 721.6Sthorpej struct hil_softc *sc = device_private(self); 731.1Sgmcgarry struct gpib_attach_args *ga = aux; 741.1Sgmcgarry 751.1Sgmcgarry printf("\n"); 761.1Sgmcgarry 771.1Sgmcgarry sc->sc_ic = ga->ga_ic; 781.1Sgmcgarry sc->sc_address = ga->ga_address; 791.1Sgmcgarry 801.1Sgmcgarry if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc, 811.1Sgmcgarry &sc->sc_hdl)) { 821.12Schs aprint_error_dev(self, "can't register callback\n"); 831.1Sgmcgarry return; 841.1Sgmcgarry } 851.1Sgmcgarry 861.1Sgmcgarry sc->sc_flags = HILF_ALIVE; 871.1Sgmcgarry} 881.1Sgmcgarry 891.13Sthorpejstatic void 901.8Sdslhilcallback(void *v, int action) 911.1Sgmcgarry{ 921.1Sgmcgarry struct hil_softc *sc = v; 931.1Sgmcgarry 941.1Sgmcgarry DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action)); 951.1Sgmcgarry 961.1Sgmcgarry switch (action) { 971.1Sgmcgarry case GPIBCBF_START: 981.1Sgmcgarry hilstart(sc); 991.1Sgmcgarry case GPIBCBF_INTR: 1001.1Sgmcgarry /* no-op */ 1011.1Sgmcgarry break; 1021.1Sgmcgarry#ifdef DEBUG 1031.1Sgmcgarry default: 1041.1Sgmcgarry DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n", 1051.1Sgmcgarry action)); 1061.1Sgmcgarry break; 1071.1Sgmcgarry#endif 1081.1Sgmcgarry } 1091.1Sgmcgarry} 1101.1Sgmcgarry 1111.13Sthorpejstatic void 1121.8Sdslhilstart(void *v) 1131.1Sgmcgarry{ 1141.1Sgmcgarry struct hil_softc *sc = v; 1151.1Sgmcgarry 1161.12Schs DPRINTF(HDB_FOLLOW, ("hilstart\n")); 1171.1Sgmcgarry 1181.1Sgmcgarry sc->sc_flags &= ~HILF_DELAY; 1191.1Sgmcgarry} 120