hil_gpib.c revision 1.8
1/*	$NetBSD: hil_gpib.c,v 1.8 2009/03/14 15:36:17 dsl Exp $	*/
2
3#include <sys/cdefs.h>
4__KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.8 2009/03/14 15:36:17 dsl 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
15int     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
28struct  hil_softc {
29	struct device sc_dev;
30	gpib_chipset_tag_t sc_ic;
31	gpib_handle_t sc_hdl;
32
33	int	sc_address;		 /* GPIB address */
34	int     sc_flags;
35#define HILF_ALIVE	0x01
36#define HILF_OPEN	0x02
37#define HILF_UIO	0x04
38#define HILF_TIMO	0x08
39#define HILF_DELAY	0x10
40};
41
42int     hilmatch(struct device *, struct cfdata *, void *);
43void    hilattach(struct device *, struct device *, void *);
44
45const struct cfattach hil_ca = {
46	sizeof(struct hil_softc), hilmatch, hilattach,
47};
48
49void	hilcallback(void *, int);
50void	hilstart(void *);
51
52int
53hilmatch(struct device *parent, struct cfdata *match, void *aux)
54{
55	struct gpib_attach_args *ga = aux;
56	u_int8_t *cmd = "SE;";
57	u_int8_t stat;
58
59	if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3)
60		return (0);
61	if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1)
62		return (0);
63	printf("hilmatch: enable status byte 0x%x\n", stat);
64	return (1);
65}
66
67void
68hilattach(parent, self, aux)
69	struct device *parent, *self;
70	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(&sc->sc_dev, "can't register callback\n");
83		return;
84	}
85
86	sc->sc_flags = HILF_ALIVE;
87}
88
89void
90hilcallback(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
111void
112hilstart(void *v)
113{
114	struct hil_softc *sc = v;
115
116	DPRINTF(HDB_FOLLOW, ("hilstart(%x)\n", device_unit(&sc->sc_dev)));
117
118	sc->sc_flags &= ~HILF_DELAY;
119}
120