Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci Add driver for the Toshiba's Oboe IrDA chip. Fr...
details: https://anonhg.NetBSD.org/src/rev/4b8277940db5
branches: trunk
changeset: 518613:4b8277940db5
user: augustss <augustss%NetBSD.org@localhost>
date: Sun Dec 02 16:30:30 2001 +0000
description:
Add driver for the Toshiba's Oboe IrDA chip. From Jan Sparud.
diffstat:
sys/dev/pci/files.pci | 8 +-
sys/dev/pci/oboe.c | 718 ++++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/pci/oboereg.h | 160 +++++++++++
3 files changed, 885 insertions(+), 1 deletions(-)
diffs (truncated from 905 to 300 lines):
diff -r 0273e5edd903 -r 4b8277940db5 sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci Sun Dec 02 16:29:25 2001 +0000
+++ b/sys/dev/pci/files.pci Sun Dec 02 16:30:30 2001 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.145 2001/11/28 10:21:23 lukem Exp $
+# $NetBSD: files.pci,v 1.146 2001/12/02 16:30:30 augustss Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -476,3 +476,9 @@
file dev/pci/isic_pci_elsa_qs1p.c isic_pci
file dev/pci/isic_pci_avm_fritz_pci.c isic_pci
+
+# IrDA devices
+# Toshiba Fast Infrared Type O IrDA driver
+device oboe: irbus
+attach oboe at pci
+file dev/pci/oboe.c oboe
diff -r 0273e5edd903 -r 4b8277940db5 sys/dev/pci/oboe.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/oboe.c Sun Dec 02 16:30:30 2001 +0000
@@ -0,0 +1,718 @@
+/* $NetBSD: oboe.c,v 1.1 2001/12/02 16:30:30 augustss Exp $ */
+
+/*-
+ * Copyright (c) 2000 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * 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 SIR/FIR driver.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/tty.h>
+#include <sys/vnode.h>
+#include <sys/poll.h>
+
+#include <dev/ir/ir.h>
+#include <dev/ir/irdaio.h>
+#include <dev/ir/irframevar.h>
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcivar.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+#include <uvm/uvm_extern.h>
+
+#include <dev/pci/oboereg.h>
+
+int oboe_match(struct device *parent, struct cfdata *match, void *aux);
+void oboe_attach(struct device *parent, struct device *self, void *aux);
+int oboe_activate(struct device *self, enum devact act);
+int oboe_detach(struct device *self, int flags);
+
+int oboe_open(void *h, int flag, int mode, struct proc *p);
+int oboe_close(void *h, int flag, int mode, struct proc *p);
+int oboe_read(void *h, struct uio *uio, int flag);
+int oboe_write(void *h, struct uio *uio, int flag);
+int oboe_set_params(void *h, struct irda_params *params);
+int oboe_reset_params(void *h);
+int oboe_get_speeds(void *h, int *speeds);
+int oboe_get_turnarounds(void *h, int *times);
+int oboe_poll(void *h, int events, struct proc *p);
+
+#define OBOE_DEBUG_XXX
+
+#ifdef OBOE_DEBUG
+#define DPRINTF(x) if (oboedebug) printf x
+int oboedebug = 1;
+#else
+#define DPRINTF(x)
+#endif
+
+struct oboe_dma;
+
+struct oboe_softc {
+ struct device sc_dev;
+ struct device *sc_child;
+ struct pci_attach_args sc_pa;
+ pci_intr_handle_t * sc_ih;
+ unsigned int sc_revision; /* PCI Revision ID */
+ /* I/O Base device */
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+ bus_dma_tag_t sc_dmatag;
+ struct selinfo sc_rsel;
+
+ 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;
+
+ 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 *);
+
+struct oboe_dma {
+ bus_dmamap_t map;
+ caddr_t addr;
+ bus_dma_segment_t segs[1];
+ int nsegs;
+ size_t size;
+ struct oboe_dma *next;
+};
+
+#define DMAADDR(p) ((p)->map->dm_segs[0].ds_addr)
+#define KERNADDR(p) ((void *)((p)->addr))
+
+static int oboe_alloc_taskfile(struct oboe_softc *);
+static void oboe_init_taskfile(struct oboe_softc *);
+static void oboe_startchip(struct oboe_softc *);
+static void oboe_stopchip(struct oboe_softc *);
+static void oboe_setbaud(struct oboe_softc *, int);
+
+struct cfattach oboe_ca = {
+ sizeof(struct oboe_softc), oboe_match, oboe_attach,
+ oboe_detach, oboe_activate
+};
+
+struct irframe_methods oboe_methods = {
+ oboe_open, oboe_close, oboe_read, oboe_write, oboe_poll,
+ oboe_set_params, oboe_reset_params, oboe_get_speeds,
+ oboe_get_turnarounds
+};
+
+int
+oboe_match(struct device *parent, struct cfdata *match, void *aux)
+{
+ struct pci_attach_args *pa = aux;
+
+ if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TOSHIBA2 &&
+ PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TOSHIBA2_OBOE)
+ return (1);
+ return 0;
+}
+
+void
+oboe_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct oboe_softc *sc = (struct oboe_softc *)self;
+ struct pci_attach_args *pa = aux;
+ pci_intr_handle_t ih;
+ struct ir_attach_args ia;
+ const char *intrstring;
+
+ sc->sc_revision = PCI_REVISION(pa->pa_class);
+ printf(": Toshiba Fast Infrared Type O, revision %d\n",
+ sc->sc_revision);
+
+ /* Map I/O registers. */
+ if (pci_mapreg_map(pa, IO_BAR, PCI_MAPREG_TYPE_IO, 0,
+ &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
+ printf("%s: can't map I/O space\n", sc->sc_dev.dv_xname);
+ return;
+ }
+
+ sc->sc_dmatag = pa->pa_dmat;
+
+ ia.ia_type = IR_TYPE_IRFRAME;
+ ia.ia_methods = &oboe_methods;
+ ia.ia_handle = sc;
+
+ sc->sc_state = 0;
+ sc->sc_speed = IRDA_SPEED_9600;
+
+ /* Enable the device */
+ pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+ pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
+ PCI_COMMAND_MASTER_ENABLE);
+
+ /* Reset the device; bail out upon failure. */
+ if (oboe_reset(sc) != 0) {
+ printf("%s: can't reset\n", sc->sc_dev.dv_xname);
+ return;
+ }
+ /* Map and establish the interrupt. */
+ if (pci_intr_map(pa, &ih)) {
+ printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
+ return;
+ }
+ intrstring = pci_intr_string(pa->pa_pc, ih);
+ sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_IR, oboe_intr, sc);
+ if (sc->sc_ih == NULL) {
+ printf("%s: couldn't establish interrupt",
+ sc->sc_dev.dv_xname);
+ if (intrstring != NULL)
+ printf(" at %s", intrstring);
+ printf("\n");
+ return;
+ }
+ printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstring);
+
+ sc->sc_txs = 0;
+ sc->sc_rxs = 0;
+
+ sc->sc_speeds =
+ IRDA_SPEED_2400 | IRDA_SPEED_9600 | IRDA_SPEED_19200 |
+ IRDA_SPEED_38400 | IRDA_SPEED_57600 | IRDA_SPEED_115200 |
+ IRDA_SPEED_576000 | IRDA_SPEED_1152000 | IRDA_SPEED_4000000;
+
+ oboe_alloc_taskfile(sc);
+
+ sc->sc_child = config_found((void *)sc, &ia, ir_print);
+}
+
+int
+oboe_activate(struct device *self, enum devact act)
+{
+ struct oboe_softc *sc = (struct oboe_softc *)self;
+ int error;
+
+ DPRINTF(("%s: sc=%p\n", __FUNCTION__, sc));
+
+ switch (act) {
+ case DVACT_ACTIVATE:
+ return (EOPNOTSUPP);
+ break;
+
+ case DVACT_DEACTIVATE:
+ if (sc->sc_child)
+ error = config_deactivate(sc->sc_child);
+ else
+ error = 0;
+ break;
+ }
+ return (error);
+}
+
+int
+oboe_detach(struct device *self, int flags)
+{
+#if 0
+ struct oboe_softc *sc = (struct oboe_softc *)self;
+#endif
+ DPRINTF(("%s: sc=%p\n", __FUNCTION__, sc));
+ return (0);
+}
+
+int
Home |
Main Index |
Thread Index |
Old Index