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 a driver for the Rio 500 MP3 player.



details:   https://anonhg.NetBSD.org/src/rev/fde7eff67f37
branches:  trunk
changeset: 484900:fde7eff67f37
user:      augustss <augustss%NetBSD.org@localhost>
date:      Fri Apr 14 14:20:02 2000 +0000

description:
Add a driver for the Rio 500 MP3 player.
XXX This driver might go away again, since you can do it all with ugen.
XXX But this driver is compatible with the Linux driver so there are
XXX programs for it.

diffstat:

 sys/dev/usb/files.usb |    7 +-
 sys/dev/usb/urio.c    |  592 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 598 insertions(+), 1 deletions(-)

diffs (truncated from 617 to 300 lines):

diff -r cdc50450af1d -r fde7eff67f37 sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Fri Apr 14 14:18:40 2000 +0000
+++ b/sys/dev/usb/files.usb     Fri Apr 14 14:20:02 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.19 2000/04/09 18:23:23 augustss Exp $
+#      $NetBSD: files.usb,v 1.20 2000/04/14 14:20:02 augustss Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -73,6 +73,11 @@
 attach ums at uhub
 file   dev/usb/ums.c                   ums
 
+# Diamond Multimedia Rio 500
+device urio
+attach urio at uhub
+file   dev/usb/urio.c                  urio            needs-flag
+
 # Handspring Visor
 device uvisor: ucombus
 attach uvisor at uhub
diff -r cdc50450af1d -r fde7eff67f37 sys/dev/usb/urio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/urio.c        Fri Apr 14 14:20:02 2000 +0000
@@ -0,0 +1,592 @@
+/*     $NetBSD: urio.c,v 1.1 2000/04/14 14:20:02 augustss Exp $        */
+
+/*
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (augustss%carlstedt.se@localhost) at
+ * Carlstedt Research & Technology.
+ *
+ * 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.
+ */
+
+/*
+ * The inspiration and information for this driver comes from the
+ * FreeBSD driver written by Iwasa Kazmi.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#elif defined(__FreeBSD__)
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/ioccom.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/filio.h>
+#endif
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/select.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/poll.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+
+#include <dev/usb/usbdevs.h>
+#include <dev/usb/urio.h>
+
+#ifdef URIO_DEBUG
+#define DPRINTF(x)     if (uriodebug) logprintf x
+#define DPRINTFN(n,x)  if (uriodebug>(n)) logprintf x
+int    uriodebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+cdev_decl(urio);
+#elif defined(__FreeBSD__)
+d_open_t  urioopen;
+d_close_t urioclose;
+d_read_t  urioread;
+d_write_t uriowrite;
+d_ioctl_t urioioctl;
+
+#define URIO_CDEV_MAJOR        143
+
+static struct cdevsw urio_cdevsw = {
+       urioopen,       urioclose,      urioread,       uriowrite,
+       urioioctl,      nopoll,         nommap,         nostrategy,
+       "urio",         URIO_CDEV_MAJOR,nodump,         nopsize,
+       0,              -1
+};
+#endif  /* defined(__FreeBSD__) */
+
+#define URIO_CONFIG_NO         1
+#define URIO_IFACE_IDX         0
+
+
+#define        URIO_BSIZE      4096
+
+
+struct urio_softc {
+       USBBASEDEVICE           sc_dev;
+       usbd_device_handle      sc_udev;
+       usbd_interface_handle   sc_iface;
+
+       int                     sc_in_addr;
+       usbd_pipe_handle        sc_in_pipe;
+       int                     sc_out_addr;
+       usbd_pipe_handle        sc_out_pipe;
+
+       int                     sc_refcnt;
+       char                    sc_dying;
+};
+
+#define URIOUNIT(n) (minor(n))
+
+#define URIO_RW_TIMEOUT 4000   /* ms */
+
+USB_DECLARE_DRIVER(urio);
+
+USB_MATCH(urio)
+{
+       USB_MATCH_START(urio, uaa);
+
+       DPRINTFN(50,("urio_match\n"));
+
+       if (uaa->iface != NULL)
+               return (UMATCH_NONE);
+
+       if (uaa->vendor == USB_VENDOR_DIAMOND &&
+           uaa->product == USB_PRODUCT_DIAMOND_RIO500USB)
+               return (UMATCH_VENDOR_PRODUCT);
+       else
+               return (UMATCH_NONE);
+}
+
+USB_ATTACH(urio)
+{
+       USB_ATTACH_START(urio, sc, uaa);
+       usbd_device_handle      dev = uaa->device;
+       usbd_interface_handle   iface;
+       char                    devinfo[1024];
+       usbd_status             err;
+       usb_endpoint_descriptor_t *ed;
+       u_int8_t                epcount;
+       int                     i;
+
+       DPRINTFN(10,("urio_attach: sc=%p\n", sc));
+
+       usbd_devinfo(dev, 0, devinfo);
+       USB_ATTACH_SETUP;
+       printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
+
+       err = usbd_set_config_no(dev, URIO_CONFIG_NO, 0);
+       if (err) {
+               printf("%s: setting config no failed\n",
+                   USBDEVNAME(sc->sc_dev));
+               USB_ATTACH_ERROR_RETURN;
+       }
+
+       err = usbd_device2interface_handle(dev, URIO_IFACE_IDX, &iface);
+       if (err) {
+               printf("%s: getting interface handle failed\n",
+                   USBDEVNAME(sc->sc_dev));
+               USB_ATTACH_ERROR_RETURN;
+       }
+
+       sc->sc_udev = dev;
+       sc->sc_iface = iface;
+
+       epcount = 0;
+       (void)usbd_endpoint_count(iface, &epcount);
+
+       sc->sc_in_addr = -1;
+       sc->sc_out_addr = -1;
+       for (i = 0; i < epcount; i++) {
+               ed = usbd_interface2endpoint_descriptor(iface, i);
+               if (ed == NULL) {
+                       printf("%s: couldn't get ep %d\n",
+                           USBDEVNAME(sc->sc_dev), i);
+                       USB_ATTACH_ERROR_RETURN;
+               }
+               if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
+                   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
+                       sc->sc_in_addr = ed->bEndpointAddress;
+               } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
+                          UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
+                       sc->sc_out_addr = ed->bEndpointAddress;
+               }
+       }
+       if (sc->sc_in_addr == -1 || sc->sc_out_addr == -1) {
+               printf("%s: missing endpoint\n", USBDEVNAME(sc->sc_dev));
+               USB_ATTACH_ERROR_RETURN;
+       }
+
+#if defined(__FreeBSD__)
+       /* XXX no error trapping, no storing of dev_t */
+       (void)make_dev(&urio_cdevsw, device_get_unit(self),
+                      UID_ROOT, GID_OPERATOR,
+                      0644, "urio%d", device_get_unit(self));
+#endif /* defined(__FreeBSD__) */
+
+       DPRINTFN(10, ("urio_attach: %p\n", sc->sc_udev));
+
+       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
+                          USBDEV(sc->sc_dev));
+
+       USB_ATTACH_SUCCESS_RETURN;
+}
+
+USB_DETACH(urio)
+{
+       USB_DETACH_START(urio, sc);
+       int s;
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+       int maj, mn;
+
+       DPRINTF(("urio_detach: sc=%p flags=%d\n", sc, flags));
+#elif defined(__FreeBSD__)
+       DPRINTF(("urio_detach: sc=%p\n", sc));
+#endif
+
+       sc->sc_dying = 1;
+       /* Abort all pipes.  Causes processes waiting for transfer to wake. */
+       if (sc->sc_in_pipe != NULL) {
+               usbd_abort_pipe(sc->sc_in_pipe);
+               usbd_close_pipe(sc->sc_in_pipe);
+               sc->sc_in_pipe = NULL;
+       }
+       if (sc->sc_out_pipe != NULL) {
+               usbd_abort_pipe(sc->sc_out_pipe);
+               usbd_close_pipe(sc->sc_out_pipe);
+               sc->sc_out_pipe = NULL;
+       }
+
+       s = splusb();
+       if (--sc->sc_refcnt >= 0) {
+               /* Wait for processes to go away. */
+               usb_detach_wait(USBDEV(sc->sc_dev));
+       }
+       splx(s);
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+       /* locate the major number */
+       for (maj = 0; maj < nchrdev; maj++)
+               if (cdevsw[maj].d_open == urioopen)
+                       break;
+
+       /* Nuke the vnodes for any open instances (calls close). */
+       mn = self->dv_unit;
+       vdevgone(maj, mn, mn, VCHR);
+#elif defined(__FreeBSD__)
+       /* XXX not implemented yet */
+#endif
+
+       usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
+                          USBDEV(sc->sc_dev));
+
+       return (0);
+}
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+int
+urio_activate(self, act)
+       device_ptr_t self;
+       enum devact act;



Home | Main Index | Thread Index | Old Index