1 /* $NetBSD: hil_gpib.c,v 1.10 2009/05/12 12:13:21 cegger Exp $ */
4 __KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.10 2009/05/12 12:13:21 cegger Exp $");
8 #include <sys/callout.h>
10 #include <sys/device.h>
12 #include <dev/gpib/gpibvar.h>
16 #define HDB_FOLLOW 0x01
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
25 #define DPRINTF(mask, str) /* nothing */
30 gpib_chipset_tag_t sc_ic
;
33 int sc_address
; /* GPIB address */
35 #define HILF_ALIVE 0x01
36 #define HILF_OPEN 0x02
38 #define HILF_TIMO 0x08
39 #define HILF_DELAY 0x10
42 int hilmatch(device_t
, cfdata_t
, void *);
43 void hilattach(device_t
, device_t
, void *);
45 const struct cfattach hil_ca
= {
46 sizeof(struct hil_softc
), hilmatch
, hilattach
,
49 void hilcallback(void *, int);
50 void hilstart(void *);
53 hilmatch(device_t parent
, cfdata_t match
, void *aux
)
55 struct gpib_attach_args
*ga
= aux
;
56 u_int8_t
*cmd
= "SE;";
59 if (gpibsend(ga
->ga_ic
, ga
->ga_address
, -1, cmd
, 3) != 3)
61 if (gpibrecv(ga
->ga_ic
, ga
->ga_address
, -1, &stat
, 1) != 1)
63 printf("hilmatch: enable status byte 0x%x\n", stat
);
68 hilattach(device_t parent
, device_t self
, void *aux
)
70 struct hil_softc
*sc
= device_private(self
);
71 struct gpib_attach_args
*ga
= aux
;
75 sc
->sc_ic
= ga
->ga_ic
;
76 sc
->sc_address
= ga
->ga_address
;
78 if (gpibregister(sc
->sc_ic
, sc
->sc_address
, hilcallback
, sc
,
80 aprint_error_dev(&sc
->sc_dev
, "can't register callback\n");
84 sc
->sc_flags
= HILF_ALIVE
;
88 hilcallback(void *v
, int action
)
90 struct hil_softc
*sc
= v
;
92 DPRINTF(HDB_FOLLOW
, ("hilcallback: v=%p, action=%d\n", v
, action
));
102 DPRINTF(HDB_FOLLOW
, ("hilcallback: unknown action %d\n",
112 struct hil_softc
*sc
= v
;
114 DPRINTF(HDB_FOLLOW
, ("hilstart(%x)\n", device_unit(&sc
->sc_dev
)));
116 sc
->sc_flags
&= ~HILF_DELAY
;