Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb An EXPERIMENTAL audio driver. It still needs wo...



details:   https://anonhg.NetBSD.org/src/rev/294511891ba3
branches:  trunk
changeset: 476196:294511891ba3
user:      augustss <augustss%NetBSD.org@localhost>
date:      Thu Sep 09 12:28:25 1999 +0000

description:
An EXPERIMENTAL audio driver.  It still needs work, e.g., in the mixer
part to give reasonable names to the mixer controls.

diffstat:

 sys/dev/usb/uaudio.c    |  2052 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/uaudioreg.h |   272 ++++++
 2 files changed, 2324 insertions(+), 0 deletions(-)

diffs (truncated from 2332 to 300 lines):

diff -r 2c113739d1b2 -r 294511891ba3 sys/dev/usb/uaudio.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/uaudio.c      Thu Sep 09 12:28:25 1999 +0000
@@ -0,0 +1,2052 @@
+/*     $NetBSD: uaudio.c,v 1.1 1999/09/09 12:28:25 augustss Exp $      */
+
+/*
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Author: Lennart Augustsson <augustss%carlstedt.se@localhost>
+ *         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.
+ */
+
+/*
+ * USB audio specs: http://www.teleport.com/~usb/data/Audio10.pdf
+ *                  http://www.teleport.com/~usb/data/Frmts10.pdf
+ *                  http://www.teleport.com/~usb/data/Termt10.pdf
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/tty.h>
+#include <sys/file.h>
+#include <sys/select.h>
+#include <sys/proc.h>
+#include <sys/vnode.h>
+#include <sys/device.h>
+#include <sys/poll.h>
+
+#include <sys/audioio.h>
+#include <dev/audio_if.h>
+#include <dev/mulaw.h>
+#include <dev/auconv.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usb_quirks.h>
+
+#include <dev/usb/uaudioreg.h>
+
+#ifdef USB_DEBUG
+#define DPRINTF(x)     if (uaudiodebug) logprintf x
+#define DPRINTFN(n,x)  if (uaudiodebug>(n)) logprintf x
+int    uaudiodebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+#define UAUDIO_NCHANBUFS 5     /* number of outstanding request */
+#define UAUDIO_NFRAMES   20    /* ms of sound in each request */
+
+
+#define MIX_MAX_CHAN 8
+struct mixerctl {
+       u_int16_t       wValue[MIX_MAX_CHAN]; /* using nchan */
+       u_int16_t       wIndex;
+       u_int8_t        nchan;
+       u_int8_t        type;
+#define MIX_ON_OFF     1
+#define MIX_SIGNED_16  2
+#define MIX_UNSIGNED_16        3
+#define MIX_SIGNED_8   4
+#define MIX_SIZE(n) ((n) == MIX_SIGNED_16 || (n) == MIX_UNSIGNED_16 ? 2 : 1)
+#define MIX_UNSIGNED(n) ((n) == MIX_UNSIGNED_16)
+       int             minval, maxval;
+       u_int8_t        class;
+       char            ctlname[MAX_AUDIO_DEV_LEN];
+       char            *ctlunit;
+};
+#define MAKE(h,l) (((h) << 8) | (l))
+
+struct as_info {
+       u_int8_t        alt;
+       u_int8_t        encoding;
+       usb_interface_descriptor_t *idesc;
+       usb_endpoint_descriptor_audio_t *edesc;
+       struct usb_audio_streaming_type1_descriptor *asf1desc;
+};
+
+struct chan {
+       int     terminal;       /* terminal id */
+       void    (*intr) __P((void *));  /* dma completion intr handler */
+       void    *arg;           /* arg for intr() */
+       usbd_pipe_handle pipe;
+
+       u_int   sample_size;
+       u_int   sample_rate;
+       u_int   bytes_per_frame;
+       u_int   fraction;       /* fraction/1000 is the extra samples/frame */
+       u_int   residue;        /* accumulates the fractional samples */
+
+       u_char  *start;         /* upper layer buffer start */
+       u_char  *end;           /* upper layer buffer end */
+       u_char  *cur;           /* current position in upper layer buffer */
+       int     blksize;        /* chunk size to report up */
+       int     transferred;    /* transferred bytes not reported up */
+
+       int     curchanbuf;
+       struct chanbuf {
+               struct chan         *chan;
+               usbd_request_handle reqh;
+               u_char              *buffer;
+               u_int16_t           sizes[UAUDIO_NFRAMES];
+               u_int16_t           size;
+       } chanbufs[UAUDIO_NCHANBUFS];
+};
+
+struct uaudio_softc {
+       USBBASEDEVICE sc_dev;           /* base device */
+       usbd_device_handle sc_udev;     /* USB device */
+
+       int     sc_ac_iface;    /* Audio Control interface */
+       int     sc_as_iface;    /* Audio Streaming interface */
+       usbd_interface_handle   sc_ac_ifaceh;
+       usbd_interface_handle   sc_as_ifaceh;
+
+       struct chan sc_pchan;
+       struct chan sc_rchan;
+
+       int     sc_curaltidx;
+
+       int     sc_nullalt;
+
+       struct as_info *sc_alts;
+       int     sc_nalts;
+       int     sc_props;
+
+       int     sc_altflags;
+#define HAS_8     0x01
+#define HAS_16    0x02
+#define HAS_8U    0x04
+#define HAS_ALAW  0x08
+#define HAS_MULAW 0x10
+
+       struct mixerctl *sc_ctls;
+       int     sc_nctls;
+
+       device_ptr_t sc_audiodev;
+       char    sc_dying;
+};
+
+#define UAC_OUTPUT 0
+#define UAC_INPUT  1
+#define UAC_EQUAL  2
+
+usbd_status uaudio_identify_ac __P((struct uaudio_softc *sc,
+                                   usb_config_descriptor_t *cdesc));
+usbd_status uaudio_identify_as __P((struct uaudio_softc *sc,
+                                   usb_config_descriptor_t *cdesc));
+usbd_status uaudio_process_as __P((struct uaudio_softc *sc, char *buf,
+                                  int *offsp, int size,
+                                  usb_interface_descriptor_t *id));
+
+void uaudio_add_alt __P((struct uaudio_softc *sc, struct as_info *ai));
+
+usb_interface_descriptor_t *uaudio_find_iface 
+       __P((char *buf, int size, int *offsp, int subtype));
+
+void uaudio_mixer_add_ctl __P((struct uaudio_softc *sc, struct mixerctl *mp));
+char *uaudio_id_name __P((struct uaudio_softc *sc, usb_descriptor_t **dps, 
+                         int id));
+struct usb_audio_cluster uaudio_get_cluster __P((int id, 
+                                                usb_descriptor_t **dps));
+void uaudio_add_input __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                          usb_descriptor_t **dps));
+void uaudio_add_output __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                           usb_descriptor_t **dps));
+void uaudio_add_mixer __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                          usb_descriptor_t **dps));
+void uaudio_add_selector __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                             usb_descriptor_t **dps));
+void uaudio_add_feature __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                            usb_descriptor_t **dps));
+void uaudio_add_processing __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                               usb_descriptor_t **dps));
+void uaudio_add_extension __P((struct uaudio_softc *sc, usb_descriptor_t *v, 
+                              usb_descriptor_t **dps));
+usbd_status uaudio_identify __P((struct uaudio_softc *sc, 
+                                usb_config_descriptor_t *cdesc));
+
+int uaudio_signext __P((int type, int val));
+int uaudio_value2bsd __P((struct mixerctl *mc, int val));
+int uaudio_bsd2value __P((struct mixerctl *mc, int val));
+int uaudio_get __P((struct uaudio_softc *sc, int type, int which, int wValue, 
+                   int wIndex, int len));
+int uaudio_ctl_get __P((struct uaudio_softc *sc, int which, 
+                       struct mixerctl *mc, int chan));
+void uaudio_set __P((struct uaudio_softc *sc, int type, int which, int wValue, 
+                   int wIndex, int len, int val));
+void uaudio_ctl_set __P((struct uaudio_softc *sc, int which, 
+                        struct mixerctl *mc, int chan, int val));
+
+usbd_status    uaudio_set_speed __P((struct uaudio_softc *, int, u_int));
+
+usbd_status uaudio_chan_open __P((struct uaudio_softc *sc, struct chan *ch));
+void   uaudio_chan_close __P((struct uaudio_softc *sc, struct chan *ch));
+usbd_status uaudio_chan_alloc_buffers __P((struct uaudio_softc *, struct chan *));
+void   uaudio_chan_free_buffers __P((struct uaudio_softc *, struct chan *));
+void   uaudio_chan_set_param __P((struct chan *ch, struct audio_params *param,
+                                  u_char *start, u_char *end, int blksize));
+void   uaudio_chan_transfer __P((struct chan *ch));
+void   uaudio_chan_pintr __P((usbd_request_handle reqh, 
+                              usbd_private_handle priv, usbd_status status));
+
+
+
+int    uaudio_open __P((void *, int));
+void   uaudio_close __P((void *));
+int    uaudio_drain __P((void *));
+int    uaudio_query_encoding __P((void *, struct audio_encoding *));
+int    uaudio_set_params __P((void *, int, int, 
+                              struct audio_params *, struct audio_params *));
+int    uaudio_round_blocksize __P((void *, int));
+int    uaudio_trigger_output __P((void *, void *, void *, int, 
+                                  void (*)(void *), void *,
+                                  struct audio_params *));
+int    uaudio_trigger_input  __P((void *, void *, void *, int, 
+                                  void (*)(void *), void *,
+                                  struct audio_params *));
+int    uaudio_halt_in_dma __P((void *));
+int    uaudio_halt_out_dma __P((void *));
+int    uaudio_getdev __P((void *, struct audio_device *));
+int    uaudio_mixer_set_port __P((void *, mixer_ctrl_t *));
+int    uaudio_mixer_get_port __P((void *, mixer_ctrl_t *));
+int    uaudio_query_devinfo __P((void *, mixer_devinfo_t *));
+int    uaudio_get_props __P((void *));
+
+struct audio_hw_if uaudio_hw_if = {
+       uaudio_open,
+       uaudio_close,
+       uaudio_drain,
+       uaudio_query_encoding,
+       uaudio_set_params,
+       uaudio_round_blocksize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       uaudio_halt_out_dma,
+       uaudio_halt_in_dma,
+       NULL,
+       uaudio_getdev,
+       NULL,
+       uaudio_mixer_set_port,
+       uaudio_mixer_get_port,
+       uaudio_query_devinfo,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       uaudio_get_props,
+       uaudio_trigger_output,
+       uaudio_trigger_input,
+};
+
+struct audio_device uaudio_device = {
+       "USB audio",
+       "",
+       "uaudio"
+};
+
+USB_DECLARE_DRIVER(uaudio);
+
+USB_MATCH(uaudio)



Home | Main Index | Thread Index | Old Index