2009-05-12 18:16:35 +04:00
|
|
|
/* $NetBSD: hil_gpib.c,v 1.11 2009/05/12 14:21:58 cegger Exp $ */
|
2003-07-14 19:40:04 +04:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2009-05-12 18:16:35 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: hil_gpib.c,v 1.11 2009/05/12 14:21:58 cegger Exp $");
|
2003-07-14 19:40:04 +04:00
|
|
|
|
2003-06-02 07:48:25 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <dev/gpib/gpibvar.h>
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
int hildebug = 0;
|
|
|
|
#define HDB_FOLLOW 0x01
|
|
|
|
#define HDB_MMAP 0x02
|
|
|
|
#define HDB_MASK 0x04
|
|
|
|
#define HDB_CONFIG 0x08
|
|
|
|
#define HDB_KEYBOARD 0x10
|
|
|
|
#define HDB_IDMODULE 0x20
|
|
|
|
#define HDB_EVENTS 0x80
|
|
|
|
#define DPRINTF(mask, str) if (hildebug & (mask)) printf str
|
|
|
|
#else
|
|
|
|
#define DPRINTF(mask, str) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct hil_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
gpib_chipset_tag_t sc_ic;
|
|
|
|
gpib_handle_t sc_hdl;
|
|
|
|
|
|
|
|
int sc_address; /* GPIB address */
|
|
|
|
int sc_flags;
|
2005-02-27 03:26:58 +03:00
|
|
|
#define HILF_ALIVE 0x01
|
|
|
|
#define HILF_OPEN 0x02
|
2003-06-02 07:48:25 +04:00
|
|
|
#define HILF_UIO 0x04
|
|
|
|
#define HILF_TIMO 0x08
|
|
|
|
#define HILF_DELAY 0x10
|
|
|
|
};
|
|
|
|
|
2009-05-12 18:16:35 +04:00
|
|
|
int hilmatch(device_t, cfdata_t, void *);
|
|
|
|
void hilattach(device_t, device_t, void *);
|
2003-06-02 07:48:25 +04:00
|
|
|
|
|
|
|
const struct cfattach hil_ca = {
|
|
|
|
sizeof(struct hil_softc), hilmatch, hilattach,
|
|
|
|
};
|
|
|
|
|
|
|
|
void hilcallback(void *, int);
|
|
|
|
void hilstart(void *);
|
|
|
|
|
|
|
|
int
|
2009-05-12 18:16:35 +04:00
|
|
|
hilmatch(device_t parent, cfdata_t match, void *aux)
|
2003-06-02 07:48:25 +04:00
|
|
|
{
|
|
|
|
struct gpib_attach_args *ga = aux;
|
|
|
|
u_int8_t *cmd = "SE;";
|
|
|
|
u_int8_t stat;
|
|
|
|
|
|
|
|
if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3)
|
|
|
|
return (0);
|
|
|
|
if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1)
|
|
|
|
return (0);
|
|
|
|
printf("hilmatch: enable status byte 0x%x\n", stat);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-12 18:16:35 +04:00
|
|
|
hilattach(device_t parent, device_t self, void *aux)
|
2003-06-02 07:48:25 +04:00
|
|
|
{
|
2006-03-29 10:28:38 +04:00
|
|
|
struct hil_softc *sc = device_private(self);
|
2003-06-02 07:48:25 +04:00
|
|
|
struct gpib_attach_args *ga = aux;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
sc->sc_ic = ga->ga_ic;
|
|
|
|
sc->sc_address = ga->ga_address;
|
|
|
|
|
|
|
|
if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc,
|
|
|
|
&sc->sc_hdl)) {
|
2008-04-08 11:35:35 +04:00
|
|
|
aprint_error_dev(&sc->sc_dev, "can't register callback\n");
|
2003-06-02 07:48:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_flags = HILF_ALIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hilcallback(void *v, int action)
|
2003-06-02 07:48:25 +04:00
|
|
|
{
|
|
|
|
struct hil_softc *sc = v;
|
|
|
|
|
|
|
|
DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action));
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
case GPIBCBF_START:
|
|
|
|
hilstart(sc);
|
|
|
|
case GPIBCBF_INTR:
|
|
|
|
/* no-op */
|
|
|
|
break;
|
|
|
|
#ifdef DEBUG
|
|
|
|
default:
|
|
|
|
DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n",
|
|
|
|
action));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
hilstart(void *v)
|
2003-06-02 07:48:25 +04:00
|
|
|
{
|
|
|
|
struct hil_softc *sc = v;
|
|
|
|
|
2006-03-28 21:38:24 +04:00
|
|
|
DPRINTF(HDB_FOLLOW, ("hilstart(%x)\n", device_unit(&sc->sc_dev)));
|
2003-06-02 07:48:25 +04:00
|
|
|
|
|
|
|
sc->sc_flags &= ~HILF_DELAY;
|
|
|
|
}
|