/* XXXXFVDL THIS DRIVER IS BROKEN FOR NON-i386 -- vtophys() usage */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jan Sparud.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Toshiba OBOE IrDA SIR/FIR driver.
*
* Based on information from the Linux driver, thus the magic hex numbers.
*/
static int oboe_match(device_t parent, cfdata_t match, void *aux);
static void oboe_attach(device_t parent, device_t self, void *aux);
static int oboe_detach(device_t self, int flags);
static int oboe_open(void *h, int flag, int mode, struct lwp *l);
static int oboe_close(void *h, int flag, int mode, struct lwp *l);
static int oboe_read(void *h, struct uio *uio, int flag);
static int oboe_write(void *h, struct uio *uio, int flag);
static int oboe_set_params(void *h, struct irda_params *params);
static int oboe_get_speeds(void *h, int *speeds);
static int oboe_get_turnarounds(void *h, int *times);
static int oboe_poll(void *h, int events, struct lwp *l);
static int oboe_kqfilter(void *h, struct knote *kn);
#ifdef OBOE_DEBUG
#define DPRINTF(x) if (oboedebug) printf x
int oboedebug = 1;
#else
#define DPRINTF(x)
#endif
int sc_state;
#define OBOE_RSLP 0x01 /* waiting for data (read) */
#define OBOE_WSLP 0x02 /* waiting for data (write) */
#define OBOE_CLOSING 0x04 /* waiting for output to drain */
int sc_speeds;
int sc_flags;
int sc_speed;
int sc_ebofs;
struct oboe_dma *sc_dmas;
struct OboeTaskFile *sc_taskfile; /* The taskfile */
u_char * sc_xmit_bufs[TX_SLOTS];
u_char * sc_recv_bufs[RX_SLOTS];
void * sc_xmit_stores[TX_SLOTS];
void * sc_recv_stores[RX_SLOTS];
int sc_txs; /* Current transmit slot number */
int sc_rxs; /* Current receive slot number */
int sc_saved; /* number of saved frames */
int sc_lens[RX_SLOTS];
int sc_txpending;
/* Statistics */
int sc_txpackets;
int sc_rxpackets;
int sc_txerrors;
int sc_rxerrors;
};
static int oboe_intr(void *handle);
static int oboe_reset(struct oboe_softc *);
if (!(irqstat & 0xf8))
return (0); /* Not for me? */
DPRINTF(("oboe_intr stat=0x%x\n", irqstat));
OUTB(sc, irqstat, OBOE_ISR);
if (irqstat & OBOE_ISR_RXDONE) {
while (sc->sc_taskfile->recv[sc->sc_rxs].control == 0) {
int len = sc->sc_taskfile->recv[sc->sc_rxs].len;
if (sc->sc_saved == RX_SLOTS) {
DPRINTF(("oboe_intr: all buffers filled\n"));
return 0;
}
if (len > 2)
len -= 2; /* JSP: skip check sum? */
DPRINTF(("oboe_intr: moving %d bytes to %p\n", len,
sc->sc_recv_stores[sc->sc_rxs]));
memcpy(sc->sc_recv_stores[sc->sc_rxs],
sc->sc_recv_bufs[sc->sc_rxs],
len);
sc->sc_lens[sc->sc_rxs] = len;
sc->sc_saved++;
#if 0
(void)b_to_q(sc->sc_recv_bufs[sc->sc_rxs],
len, &sc->sc_q);
#endif
sc->sc_taskfile->recv[sc->sc_rxs].control = 0x83;
sc->sc_taskfile->recv[sc->sc_rxs].len = 0x0;
sc->sc_rxs = (sc->sc_rxs + 1) % RX_SLOTS;
DPRINTF(("oboe_intr new rxs=%d\n", sc->sc_rxs));
}
DPRINTF(("oboe_intr no more frames available\n"));
if (sc->sc_state & OBOE_RSLP) {
DPRINTF(("oboe_intr changing state to ~OBOE_RSLP\n"));
sc->sc_state &= ~OBOE_RSLP;
DPRINTF(("oboe_intr: waking up reader\n"));
wakeup(&sc->sc_rxs);
}
selnotify(&sc->sc_rsel, 0, 0);
DPRINTF(("oboe_intr returning\n"));
}
if (irqstat & OBOE_ISR_TXDONE) {
DPRINTF(("oboe_intr: write done\n"));
sc->sc_txpending--;
sc->sc_txpackets++;