Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Add the ustir driver, for SigmaTel STIr4200 USB/...
details: https://anonhg.NetBSD.org/src/rev/cc82e53703e0
branches: trunk
changeset: 520145:cc82e53703e0
user: augustss <augustss%NetBSD.org@localhost>
date: Thu Jan 03 18:54:31 2002 +0000
description:
Add the ustir driver, for SigmaTel STIr4200 USB/IrDA Bridge.
Written by David Sainty <David.Sainty%dtsp.co.nz@localhost>.
diffstat:
sys/dev/usb/files.usb | 8 +-
sys/dev/usb/ustir.c | 1368 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/usb/ustirreg.h | 173 ++++++
3 files changed, 1548 insertions(+), 1 deletions(-)
diffs (truncated from 1571 to 300 lines):
diff -r aa57693bc050 -r cc82e53703e0 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb Thu Jan 03 18:50:54 2002 +0000
+++ b/sys/dev/usb/files.usb Thu Jan 03 18:54:31 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.usb,v 1.38 2002/01/02 03:21:36 augustss Exp $
+# $NetBSD: files.usb,v 1.39 2002/01/03 18:54:32 augustss Exp $
#
# Config file and device description for machine-independent USB code.
# Included by ports that need it. Ports that use it must provide
@@ -104,6 +104,12 @@
file dev/usb/uirda.c uirda
+# SigmaTel IrDA bridge
+device ustir: irbus, irdasir
+attach ustir at uhub
+file dev/usb/ustir.c ustir
+
+
# Misc
# Diamond Multimedia Rio 500
device urio
diff -r aa57693bc050 -r cc82e53703e0 sys/dev/usb/ustir.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/ustir.c Thu Jan 03 18:54:31 2002 +0000
@@ -0,0 +1,1368 @@
+/* $NetBSD: ustir.c,v 1.1 2002/01/03 18:54:31 augustss Exp $ */
+
+/*
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by David Sainty <David.Sainty%dtsp.co.nz@localhost>
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ustir.c,v 1.1 2002/01/03 18:54:31 augustss Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/poll.h>
+#include <sys/select.h>
+#include <sys/proc.h>
+#include <sys/kthread.h>
+
+#ifdef USTIR_DEBUG_IOCTLS
+#include <sys/ioctl.h>
+#include <dev/usb/ustir.h>
+#endif
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/ustirreg.h>
+
+#include <dev/ir/ir.h>
+#include <dev/ir/irdaio.h>
+#include <dev/ir/irframevar.h>
+#include <dev/ir/sir.h>
+
+#ifdef USTIR_DEBUG
+#define DPRINTFN(n,x) if (ustirdebug>(n)) logprintf x
+int ustirdebug = 0;
+#else
+#define DPRINTFN(n,x)
+#endif
+
+/* Max size with framing. */
+#define MAX_USTIR_OUTPUT_FRAME (2*IRDA_MAX_FRAME_SIZE + IRDA_MAX_EBOFS + STIR_OUTPUT_HEADER_SIZE + 4)
+
+#define USTIR_NSPEEDS 9
+struct ustir_speedrec {
+ unsigned int speed;
+ unsigned int config;
+};
+
+Static struct ustir_speedrec const ustir_speeds[USTIR_NSPEEDS] = {
+ { 4000000, STIR_BRMODE_4000000 },
+ { 1152000, STIR_BRMODE_1152000 },
+ { 576000, STIR_BRMODE_576000 },
+ { 115200, STIR_BRMODE_115200 },
+ { 57600, STIR_BRMODE_57600 },
+ { 38400, STIR_BRMODE_38400 },
+ { 19200, STIR_BRMODE_19200 },
+ { 9600, STIR_BRMODE_9600 },
+ { 2400, STIR_BRMODE_2400 }
+};
+
+struct framedefn {
+ unsigned int bof_count;
+ u_int8_t bof_byte;
+
+ u_int8_t esc_byte;
+ u_int8_t esc_xor;
+
+ unsigned int eof_count;
+ u_int8_t eof_byte;
+
+ unsigned int fcs_count;
+ u_int32_t fcs_init;
+ u_int32_t fcs_correct;
+
+ u_int32_t (*fcs_calc)(u_int32_t, u_int8_t const*, size_t);
+};
+
+Static u_int32_t crc_ccitt_16(u_int32_t, u_int8_t const*, size_t);
+
+struct framedefn const framedef_sir = {
+ 1, 0xc0,
+ 0x7d, 0x20,
+ 1, 0xc1,
+ 2, INITFCS, GOODFCS,
+ crc_ccitt_16
+};
+
+enum framefsmstate {
+ FSTATE_END_OF_FRAME,
+ FSTATE_START_OF_FRAME,
+ FSTATE_IN_DATA,
+ FSTATE_IN_END
+};
+
+enum frameresult {
+ FR_IDLE,
+ FR_INPROGRESS,
+ FR_FRAMEOK,
+ FR_FRAMEBADFCS,
+ FR_FRAMEMALFORMED,
+ FR_BUFFEROVERRUN
+};
+
+struct framestate {
+ struct framedefn const *definition;
+
+ u_int8_t *buffer;
+ size_t buflen;
+ size_t bufindex;
+
+ enum framefsmstate fsmstate;
+ u_int escaped;
+ u_int state_index;
+};
+
+#define deframe_isclear(fs) ((fs)->fsmstate == FSTATE_END_OF_FRAME)
+
+Static void deframe_clear(struct framestate*);
+Static void deframe_init(struct framestate*, struct framedefn const*,
+ u_int8_t*, size_t);
+Static enum frameresult deframe_process(struct framestate*, u_int8_t const**,
+ size_t*);
+
+struct ustir_softc {
+ USBBASEDEVICE sc_dev;
+ usbd_device_handle sc_udev;
+ usbd_interface_handle sc_iface;
+
+ u_int8_t *sc_ur_buf; /* Unencapsulated frame */
+ u_int sc_ur_framelen;
+
+ u_int8_t *sc_rd_buf; /* Raw incoming data stream */
+ size_t sc_rd_index;
+ int sc_rd_addr;
+ usbd_pipe_handle sc_rd_pipe;
+ usbd_xfer_handle sc_rd_xfer;
+ u_int sc_rd_count;
+ int sc_rd_readinprogress;
+ u_int sc_rd_expectdataticks;
+ u_char sc_rd_err;
+ struct framestate sc_framestate;
+ struct proc *sc_thread;
+ struct selinfo sc_rd_sel;
+
+ u_int8_t *sc_wr_buf;
+ int sc_wr_addr;
+ usbd_xfer_handle sc_wr_xfer;
+ usbd_pipe_handle sc_wr_pipe;
+ struct selinfo sc_wr_sel;
+
+ enum {
+ udir_input, /* Receiving data */
+ udir_output, /* Transmitting data */
+ udir_stalled, /* Error preventing data flow */
+ udir_idle /* Neither receiving nor transmitting */
+ } sc_direction;
+
+ struct ustir_speedrec const *sc_speedrec;
+
+ struct device *sc_child;
+ struct irda_params sc_params;
+
+ int sc_refcnt;
+ char sc_closing;
+ char sc_dying;
+};
+
+/* True if we cannot safely read data from the device */
+#define USTIR_BLOCK_RX_DATA(sc) ((sc)->sc_ur_framelen != 0)
+
+#define USTIR_WR_TIMEOUT 200
+
+Static int ustir_activate(device_ptr_t self, enum devact act);
+Static int ustir_open(void *h, int flag, int mode, usb_proc_ptr p);
+Static int ustir_close(void *h, int flag, int mode, usb_proc_ptr p);
+Static int ustir_read(void *h, struct uio *uio, int flag);
+Static int ustir_write(void *h, struct uio *uio, int flag);
+Static int ustir_set_params(void *h, struct irda_params *params);
+Static int ustir_get_speeds(void *h, int *speeds);
+Static int ustir_get_turnarounds(void *h, int *times);
+Static int ustir_poll(void *h, int events, usb_proc_ptr p);
+
+#ifdef USTIR_DEBUG_IOCTLS
+Static int ustir_ioctl(void *h, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p);
+#endif
+
+Static struct irframe_methods const ustir_methods = {
+ ustir_open, ustir_close, ustir_read, ustir_write, ustir_poll,
+ ustir_set_params, ustir_get_speeds, ustir_get_turnarounds,
+#ifdef USTIR_DEBUG_IOCTLS
+ ustir_ioctl
+#endif
+};
+
+Static void ustir_rd_cb(usbd_xfer_handle, usbd_private_handle, usbd_status);
+Static usbd_status ustir_start_read(struct ustir_softc*);
+Static void ustir_periodic(struct ustir_softc*);
+Static void ustir_thread(void*);
+
+Static u_int32_t
+crc_ccitt_16(u_int32_t crcinit, u_int8_t const *buf, size_t blen)
+{
+ while (blen-- > 0) {
+ u_int8_t chr;
+ chr = *buf++;
+ crcinit = updateFCS(crcinit, chr);
+ }
+ return crcinit;
+}
+
+static usbd_status
+ustir_read_reg(struct ustir_softc *sc, unsigned int reg, u_int8_t *data)
+{
+ usb_device_request_t req;
+
+ req.bmRequestType = UT_READ_VENDOR_DEVICE;
+ req.bRequest = STIR_CMD_READMULTIREG;
+ USETW(req.wValue, 0);
+ USETW(req.wIndex, reg);
+ USETW(req.wLength, 1);
+
+ return usbd_do_request(sc->sc_udev, &req, data);
+}
+
+static usbd_status
+ustir_write_reg(struct ustir_softc *sc, unsigned int reg, u_int8_t data)
+{
+ usb_device_request_t req;
+
+ req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+ req.bRequest = STIR_CMD_WRITESINGLEREG;
+ USETW(req.wValue, data);
+ USETW(req.wIndex, reg);
+ USETW(req.wLength, 0);
+
+ return usbd_do_request(sc->sc_udev, &req, NULL);
+}
Home |
Main Index |
Thread Index |
Old Index