summaryrefslogtreecommitdiffstats
path: root/sys/dev/usb
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2009-02-23 21:19:18 +0000
committerthompsa <thompsa@FreeBSD.org>2009-02-23 21:19:18 +0000
commitd44ed63bdcbe993e6e25d0944b090d02af2186a5 (patch)
tree14628d3e034de731d2ddebaf5b9d40f93c9506eb /sys/dev/usb
parent644f63d68b32643bf09dda1bb1cd0e102f4fbf43 (diff)
downloadFreeBSD-src-d44ed63bdcbe993e6e25d0944b090d02af2186a5.zip
FreeBSD-src-d44ed63bdcbe993e6e25d0944b090d02af2186a5.tar.gz
Move the uaudio and ata-usb drivers into their correct locations.
Diffstat (limited to 'sys/dev/usb')
-rw-r--r--sys/dev/usb/sound/uaudio.c3750
-rw-r--r--sys/dev/usb/sound/uaudio.h63
-rw-r--r--sys/dev/usb/sound/uaudio_pcm.c234
-rw-r--r--sys/dev/usb/sound/uaudio_reg.h406
-rw-r--r--sys/dev/usb/storage/ata-usb.c1102
5 files changed, 0 insertions, 5555 deletions
diff --git a/sys/dev/usb/sound/uaudio.c b/sys/dev/usb/sound/uaudio.c
deleted file mode 100644
index b79e398..0000000
--- a/sys/dev/usb/sound/uaudio.c
+++ /dev/null
@@ -1,3750 +0,0 @@
-/* $NetBSD: uaudio.c,v 1.91 2004/11/05 17:46:14 kent Exp $ */
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Lennart Augustsson (lennart@augustsson.net) 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.
- */
-
-/*
- * USB audio specs: http://www.usb.org/developers/devclass_docs/audio10.pdf
- * http://www.usb.org/developers/devclass_docs/frmts10.pdf
- * http://www.usb.org/developers/devclass_docs/termt10.pdf
- */
-
-/*
- * Also merged:
- * $NetBSD: uaudio.c,v 1.94 2005/01/15 15:19:53 kent Exp $
- * $NetBSD: uaudio.c,v 1.95 2005/01/16 06:02:19 dsainty Exp $
- * $NetBSD: uaudio.c,v 1.96 2005/01/16 12:46:00 kent Exp $
- * $NetBSD: uaudio.c,v 1.97 2005/02/24 08:19:38 martin Exp $
- */
-
-#include "usbdevs.h"
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_mfunc.h>
-#include <dev/usb/usb_error.h>
-
-#define USB_DEBUG_VAR uaudio_debug
-
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_lookup.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_parse.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_mbuf.h>
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_dynamic.h>
-
-#include <dev/usb/quirk/usb_quirk.h>
-#include <dev/usb/sound/uaudio_reg.h>
-#include <dev/usb/sound/uaudio.h>
-
-#include <sys/reboot.h> /* for bootverbose */
-
-#include <dev/sound/pcm/sound.h>
-#include <dev/sound/chip.h>
-#include "feeder_if.h"
-
-static int uaudio_default_rate = 96000;
-static int uaudio_default_bits = 32;
-static int uaudio_default_channels = 2;
-
-#if USB_DEBUG
-static int uaudio_debug = 0;
-
-SYSCTL_NODE(_hw_usb2, OID_AUTO, uaudio, CTLFLAG_RW, 0, "USB uaudio");
-SYSCTL_INT(_hw_usb2_uaudio, OID_AUTO, debug, CTLFLAG_RW,
- &uaudio_debug, 0, "uaudio debug level");
-SYSCTL_INT(_hw_usb2_uaudio, OID_AUTO, default_rate, CTLFLAG_RW,
- &uaudio_default_rate, 0, "uaudio default sample rate");
-SYSCTL_INT(_hw_usb2_uaudio, OID_AUTO, default_bits, CTLFLAG_RW,
- &uaudio_default_bits, 0, "uaudio default sample bits");
-SYSCTL_INT(_hw_usb2_uaudio, OID_AUTO, default_channels, CTLFLAG_RW,
- &uaudio_default_channels, 0, "uaudio default sample channels");
-#endif
-
-#define UAUDIO_MINFRAMES 16 /* must be factor of 8 due HS-USB */
-#define UAUDIO_NCHANBUFS 2 /* number of outstanding request */
-#define UAUDIO_RECURSE_LIMIT 24 /* rounds */
-
-#define MAKE_WORD(h,l) (((h) << 8) | (l))
-#define BIT_TEST(bm,bno) (((bm)[(bno) / 8] >> (7 - ((bno) % 8))) & 1)
-
-struct uaudio_mixer_node {
- int32_t minval;
- int32_t maxval;
-#define MIX_MAX_CHAN 8
- int32_t wValue[MIX_MAX_CHAN]; /* using nchan */
- uint32_t delta;
- uint32_t mul;
- uint32_t ctl;
-
- uint16_t wData[MIX_MAX_CHAN]; /* using nchan */
- uint16_t wIndex;
-
- uint8_t update[(MIX_MAX_CHAN + 7) / 8];
- uint8_t nchan;
- uint8_t type;
-#define MIX_ON_OFF 1
-#define MIX_SIGNED_16 2
-#define MIX_UNSIGNED_16 3
-#define MIX_SIGNED_8 4
-#define MIX_SELECTOR 5
-#define MIX_UNKNOWN 6
-#define MIX_SIZE(n) ((((n) == MIX_SIGNED_16) || \
- ((n) == MIX_UNSIGNED_16)) ? 2 : 1)
-#define MIX_UNSIGNED(n) ((n) == MIX_UNSIGNED_16)
-
-#define MAX_SELECTOR_INPUT_PIN 256
- uint8_t slctrtype[MAX_SELECTOR_INPUT_PIN];
- uint8_t class;
-
- struct uaudio_mixer_node *next;
-};
-
-struct uaudio_chan {
- struct pcmchan_caps pcm_cap; /* capabilities */
-
- struct snd_dbuf *pcm_buf;
- const struct usb2_config *usb2_cfg;
- struct mtx *pcm_mtx; /* lock protecting this structure */
- struct uaudio_softc *priv_sc;
- struct pcm_channel *pcm_ch;
- struct usb2_xfer *xfer[UAUDIO_NCHANBUFS];
- const struct usb2_audio_streaming_interface_descriptor *p_asid;
- const struct usb2_audio_streaming_type1_descriptor *p_asf1d;
- const struct usb2_audio_streaming_endpoint_descriptor *p_sed;
- const usb2_endpoint_descriptor_audio_t *p_ed1;
- const usb2_endpoint_descriptor_audio_t *p_ed2;
- const struct uaudio_format *p_fmt;
-
- uint8_t *buf; /* pointer to buffer */
- uint8_t *start; /* upper layer buffer start */
- uint8_t *end; /* upper layer buffer end */
- uint8_t *cur; /* current position in upper layer
- * buffer */
-
- uint32_t intr_size; /* in bytes */
- uint32_t block_size;
- uint32_t sample_rate;
- uint32_t format;
- uint32_t pcm_format[2];
-
- uint16_t bytes_per_frame;
-
- uint8_t valid;
- uint8_t iface_index;
- uint8_t iface_alt_index;
-};
-
-#define UMIDI_N_TRANSFER 4 /* units */
-#define UMIDI_CABLES_MAX 16 /* units */
-#define UMIDI_BULK_SIZE 1024 /* bytes */
-
-struct umidi_sub_chan {
- struct usb2_fifo_sc fifo;
- uint8_t *temp_cmd;
- uint8_t temp_0[4];
- uint8_t temp_1[4];
- uint8_t state;
-#define UMIDI_ST_UNKNOWN 0 /* scan for command */
-#define UMIDI_ST_1PARAM 1
-#define UMIDI_ST_2PARAM_1 2
-#define UMIDI_ST_2PARAM_2 3
-#define UMIDI_ST_SYSEX_0 4
-#define UMIDI_ST_SYSEX_1 5
-#define UMIDI_ST_SYSEX_2 6
-
- uint8_t read_open:1;
- uint8_t write_open:1;
- uint8_t unused:6;
-};
-
-struct umidi_chan {
-
- struct umidi_sub_chan sub[UMIDI_CABLES_MAX];
- struct mtx mtx;
-
- struct usb2_xfer *xfer[UMIDI_N_TRANSFER];
-
- uint8_t iface_index;
- uint8_t iface_alt_index;
-
- uint8_t flags;
-#define UMIDI_FLAG_READ_STALL 0x01
-#define UMIDI_FLAG_WRITE_STALL 0x02
-
- uint8_t read_open_refcount;
- uint8_t write_open_refcount;
-
- uint8_t curr_cable;
- uint8_t max_cable;
- uint8_t valid;
-};
-
-struct uaudio_softc {
- struct sbuf sc_sndstat;
- struct sndcard_func sc_sndcard_func;
- struct uaudio_chan sc_rec_chan;
- struct uaudio_chan sc_play_chan;
- struct umidi_chan sc_midi_chan;
-
- struct usb2_device *sc_udev;
- struct usb2_xfer *sc_mixer_xfer[1];
- struct uaudio_mixer_node *sc_mixer_root;
- struct uaudio_mixer_node *sc_mixer_curr;
-
- uint32_t sc_mix_info;
- uint32_t sc_recsrc_info;
-
- uint16_t sc_audio_rev;
- uint16_t sc_mixer_count;
-
- uint8_t sc_sndstat_valid;
- uint8_t sc_mixer_iface_index;
- uint8_t sc_mixer_iface_no;
- uint8_t sc_mixer_chan;
- uint8_t sc_pcm_registered:1;
- uint8_t sc_mixer_init:1;
- uint8_t sc_uq_audio_swap_lr:1;
- uint8_t sc_uq_au_inp_async:1;
- uint8_t sc_uq_au_no_xu:1;
- uint8_t sc_uq_bad_adc:1;
-};
-
-struct uaudio_search_result {
- uint8_t bit_input[(256 + 7) / 8];
- uint8_t bit_output[(256 + 7) / 8];
- uint8_t bit_visited[(256 + 7) / 8];
- uint8_t recurse_level;
- uint8_t id_max;
-};
-
-struct uaudio_terminal_node {
- union {
- const struct usb2_descriptor *desc;
- const struct usb2_audio_input_terminal *it;
- const struct usb2_audio_output_terminal *ot;
- const struct usb2_audio_mixer_unit_0 *mu;
- const struct usb2_audio_selector_unit *su;
- const struct usb2_audio_feature_unit *fu;
- const struct usb2_audio_processing_unit_0 *pu;
- const struct usb2_audio_extension_unit_0 *eu;
- } u;
- struct uaudio_search_result usr;
- struct uaudio_terminal_node *root;
-};
-
-struct uaudio_format {
- uint16_t wFormat;
- uint8_t bPrecision;
- uint32_t freebsd_fmt;
- const char *description;
-};
-
-static const struct uaudio_format uaudio_formats[] = {
-
- {UA_FMT_PCM8, 8, AFMT_U8, "8-bit U-LE PCM"},
- {UA_FMT_PCM8, 16, AFMT_U16_LE, "16-bit U-LE PCM"},
- {UA_FMT_PCM8, 24, AFMT_U24_LE, "24-bit U-LE PCM"},
- {UA_FMT_PCM8, 32, AFMT_U32_LE, "32-bit U-LE PCM"},
-
- {UA_FMT_PCM, 8, AFMT_S8, "8-bit S-LE PCM"},
- {UA_FMT_PCM, 16, AFMT_S16_LE, "16-bit S-LE PCM"},
- {UA_FMT_PCM, 24, AFMT_S24_LE, "24-bit S-LE PCM"},
- {UA_FMT_PCM, 32, AFMT_S32_LE, "32-bit S-LE PCM"},
-
- {UA_FMT_ALAW, 8, AFMT_A_LAW, "8-bit A-Law"},
- {UA_FMT_MULAW, 8, AFMT_MU_LAW, "8-bit mu-Law"},
-
- {0, 0, 0, NULL}
-};
-
-#define UAC_OUTPUT 0
-#define UAC_INPUT 1
-#define UAC_EQUAL 2
-#define UAC_RECORD 3
-#define UAC_NCLASSES 4
-
-#if USB_DEBUG
-static const char *uac_names[] = {
- "outputs", "inputs", "equalization", "record"
-};
-
-#endif
-
-/* prototypes */
-
-static device_probe_t uaudio_probe;
-static device_attach_t uaudio_attach;
-static device_detach_t uaudio_detach;
-
-static usb2_callback_t uaudio_chan_play_callback;
-static usb2_callback_t uaudio_chan_record_callback;
-static usb2_callback_t uaudio_mixer_write_cfg_callback;
-static usb2_callback_t umidi_read_clear_stall_callback;
-static usb2_callback_t umidi_bulk_read_callback;
-static usb2_callback_t umidi_write_clear_stall_callback;
-static usb2_callback_t umidi_bulk_write_callback;
-
-static void uaudio_chan_fill_info_sub(struct uaudio_softc *,
- struct usb2_device *, uint32_t, uint16_t, uint8_t, uint8_t);
-static void uaudio_chan_fill_info(struct uaudio_softc *,
- struct usb2_device *);
-static void uaudio_mixer_add_ctl_sub(struct uaudio_softc *,
- struct uaudio_mixer_node *);
-static void uaudio_mixer_add_ctl(struct uaudio_softc *,
- struct uaudio_mixer_node *);
-static void uaudio_mixer_add_input(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_output(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_mixer(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_selector(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static uint32_t uaudio_mixer_feature_get_bmaControls(
- const struct usb2_audio_feature_unit *, uint8_t);
-static void uaudio_mixer_add_feature(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_processing_updown(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_processing(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static void uaudio_mixer_add_extension(struct uaudio_softc *,
- const struct uaudio_terminal_node *, int);
-static struct usb2_audio_cluster uaudio_mixer_get_cluster(uint8_t,
- const struct uaudio_terminal_node *);
-static uint16_t uaudio_mixer_determine_class(const struct uaudio_terminal_node *,
- struct uaudio_mixer_node *);
-static uint16_t uaudio_mixer_feature_name(const struct uaudio_terminal_node *,
- struct uaudio_mixer_node *);
-static const struct uaudio_terminal_node *uaudio_mixer_get_input(
- const struct uaudio_terminal_node *, uint8_t);
-static const struct uaudio_terminal_node *uaudio_mixer_get_output(
- const struct uaudio_terminal_node *, uint8_t);
-static void uaudio_mixer_find_inputs_sub(struct uaudio_terminal_node *,
- const uint8_t *, uint8_t, struct uaudio_search_result *);
-static void uaudio_mixer_find_outputs_sub(struct uaudio_terminal_node *,
- uint8_t, uint8_t, struct uaudio_search_result *);
-static void uaudio_mixer_fill_info(struct uaudio_softc *,
- struct usb2_device *, void *);
-static uint16_t uaudio_mixer_get(struct usb2_device *, uint8_t,
- struct uaudio_mixer_node *);
-static void uaudio_mixer_ctl_set(struct uaudio_softc *,
- struct uaudio_mixer_node *, uint8_t, int32_t val);
-static usb2_error_t uaudio_set_speed(struct usb2_device *, uint8_t, uint32_t);
-static int uaudio_mixer_signext(uint8_t, int);
-static int uaudio_mixer_bsd2value(struct uaudio_mixer_node *, int32_t val);
-static const void *uaudio_mixer_verify_desc(const void *, uint32_t);
-static void uaudio_mixer_init(struct uaudio_softc *);
-static uint8_t umidi_convert_to_usb(struct umidi_sub_chan *, uint8_t, uint8_t);
-static struct umidi_sub_chan *umidi_sub_by_fifo(struct usb2_fifo *);
-static void umidi_start_read(struct usb2_fifo *);
-static void umidi_stop_read(struct usb2_fifo *);
-static void umidi_start_write(struct usb2_fifo *);
-static void umidi_stop_write(struct usb2_fifo *);
-static int umidi_open(struct usb2_fifo *, int, struct thread *);
-static int umidi_ioctl(struct usb2_fifo *, u_long cmd, void *, int, struct thread *);
-static void umidi_close(struct usb2_fifo *, int, struct thread *);
-static void umidi_init(device_t dev);
-static int32_t umidi_probe(device_t dev);
-static int32_t umidi_detach(device_t dev);
-
-#if USB_DEBUG
-static void uaudio_chan_dump_ep_desc(
- const usb2_endpoint_descriptor_audio_t *);
-static void uaudio_mixer_dump_cluster(uint8_t,
- const struct uaudio_terminal_node *);
-static const char *uaudio_mixer_get_terminal_name(uint16_t);
-#endif
-
-static const struct usb2_config
- uaudio_cfg_record[UAUDIO_NCHANBUFS] = {
- [0] = {
- .type = UE_ISOCHRONOUS,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_IN,
- .mh.bufsize = 0, /* use "wMaxPacketSize * frames" */
- .mh.frames = UAUDIO_MINFRAMES,
- .mh.flags = {.short_xfer_ok = 1,},
- .mh.callback = &uaudio_chan_record_callback,
- },
-
- [1] = {
- .type = UE_ISOCHRONOUS,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_IN,
- .mh.bufsize = 0, /* use "wMaxPacketSize * frames" */
- .mh.frames = UAUDIO_MINFRAMES,
- .mh.flags = {.short_xfer_ok = 1,},
- .mh.callback = &uaudio_chan_record_callback,
- },
-};
-
-static const struct usb2_config
- uaudio_cfg_play[UAUDIO_NCHANBUFS] = {
- [0] = {
- .type = UE_ISOCHRONOUS,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_OUT,
- .mh.bufsize = 0, /* use "wMaxPacketSize * frames" */
- .mh.frames = UAUDIO_MINFRAMES,
- .mh.flags = {.short_xfer_ok = 1,},
- .mh.callback = &uaudio_chan_play_callback,
- },
-
- [1] = {
- .type = UE_ISOCHRONOUS,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_OUT,
- .mh.bufsize = 0, /* use "wMaxPacketSize * frames" */
- .mh.frames = UAUDIO_MINFRAMES,
- .mh.flags = {.short_xfer_ok = 1,},
- .mh.callback = &uaudio_chan_play_callback,
- },
-};
-
-static const struct usb2_config
- uaudio_mixer_config[1] = {
- [0] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = (sizeof(struct usb2_device_request) + 4),
- .mh.callback = &uaudio_mixer_write_cfg_callback,
- .mh.timeout = 1000, /* 1 second */
- },
-};
-
-static const
-uint8_t umidi_cmd_to_len[16] = {
- [0x0] = 0, /* reserved */
- [0x1] = 0, /* reserved */
- [0x2] = 2, /* bytes */
- [0x3] = 3, /* bytes */
- [0x4] = 3, /* bytes */
- [0x5] = 1, /* bytes */
- [0x6] = 2, /* bytes */
- [0x7] = 3, /* bytes */
- [0x8] = 3, /* bytes */
- [0x9] = 3, /* bytes */
- [0xA] = 3, /* bytes */
- [0xB] = 3, /* bytes */
- [0xC] = 2, /* bytes */
- [0xD] = 2, /* bytes */
- [0xE] = 3, /* bytes */
- [0xF] = 1, /* bytes */
-};
-
-static const struct usb2_config
- umidi_config[UMIDI_N_TRANSFER] = {
- [0] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_OUT,
- .mh.bufsize = UMIDI_BULK_SIZE,
- .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
- .mh.callback = &umidi_bulk_write_callback,
- },
-
- [1] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_IN,
- .mh.bufsize = UMIDI_BULK_SIZE,
- .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
- .mh.callback = &umidi_bulk_read_callback,
- },
-
- [2] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &umidi_write_clear_stall_callback,
- .mh.timeout = 1000, /* 1 second */
- .mh.interval = 50, /* 50ms */
- },
-
- [3] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &umidi_read_clear_stall_callback,
- .mh.timeout = 1000, /* 1 second */
- .mh.interval = 50, /* 50ms */
- },
-};
-
-static devclass_t uaudio_devclass;
-
-static device_method_t uaudio_methods[] = {
- DEVMETHOD(device_probe, uaudio_probe),
- DEVMETHOD(device_attach, uaudio_attach),
- DEVMETHOD(device_detach, uaudio_detach),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- {0, 0}
-};
-
-static driver_t uaudio_driver = {
- .name = "uaudio",
- .methods = uaudio_methods,
- .size = sizeof(struct uaudio_softc),
-};
-
-static int
-uaudio_probe(device_t dev)
-{
- struct usb2_attach_arg *uaa = device_get_ivars(dev);
-
- if (uaa->usb2_mode != USB_MODE_HOST)
- return (ENXIO);
-
- if (uaa->use_generic == 0)
- return (ENXIO);
-
- /* trigger on the control interface */
-
- if ((uaa->info.bInterfaceClass == UICLASS_AUDIO) &&
- (uaa->info.bInterfaceSubClass == UISUBCLASS_AUDIOCONTROL)) {
- if (usb2_test_quirk(uaa, UQ_BAD_AUDIO))
- return (ENXIO);
- else
- return (0);
- }
- return (ENXIO);
-}
-
-static int
-uaudio_attach(device_t dev)
-{
- struct usb2_attach_arg *uaa = device_get_ivars(dev);
- struct uaudio_softc *sc = device_get_softc(dev);
- struct usb2_interface_descriptor *id;
- device_t child;
-
- sc->sc_play_chan.priv_sc = sc;
- sc->sc_rec_chan.priv_sc = sc;
- sc->sc_udev = uaa->device;
-
- if (usb2_test_quirk(uaa, UQ_AUDIO_SWAP_LR))
- sc->sc_uq_audio_swap_lr = 1;
-
- if (usb2_test_quirk(uaa, UQ_AU_INP_ASYNC))
- sc->sc_uq_au_inp_async = 1;
-
- if (usb2_test_quirk(uaa, UQ_AU_NO_XU))
- sc->sc_uq_au_no_xu = 1;
-
- if (usb2_test_quirk(uaa, UQ_BAD_ADC))
- sc->sc_uq_bad_adc = 1;
-
- umidi_init(dev);
-
- device_set_usb2_desc(dev);
-
- id = usb2_get_interface_descriptor(uaa->iface);
-
- uaudio_chan_fill_info(sc, uaa->device);
-
- uaudio_mixer_fill_info(sc, uaa->device, id);
-
- sc->sc_mixer_iface_index = uaa->info.bIfaceIndex;
- sc->sc_mixer_iface_no = uaa->info.bIfaceNum;
-
- DPRINTF("audio rev %d.%02x\n",
- sc->sc_audio_rev >> 8,
- sc->sc_audio_rev & 0xff);
-
- DPRINTF("%d mixer controls\n",
- sc->sc_mixer_count);
-
- if (sc->sc_play_chan.valid) {
- device_printf(dev, "Play: %d Hz, %d ch, %s format\n",
- sc->sc_play_chan.sample_rate,
- sc->sc_play_chan.p_asf1d->bNrChannels,
- sc->sc_play_chan.p_fmt->description);
- } else {
- device_printf(dev, "No playback!\n");
- }
-
- if (sc->sc_rec_chan.valid) {
- device_printf(dev, "Record: %d Hz, %d ch, %s format\n",
- sc->sc_rec_chan.sample_rate,
- sc->sc_rec_chan.p_asf1d->bNrChannels,
- sc->sc_rec_chan.p_fmt->description);
- } else {
- device_printf(dev, "No recording!\n");
- }
-
- if (sc->sc_midi_chan.valid) {
-
- if (umidi_probe(dev)) {
- goto detach;
- }
- device_printf(dev, "MIDI sequencer\n");
- } else {
- device_printf(dev, "No midi sequencer\n");
- }
-
- DPRINTF("doing child attach\n");
-
- /* attach the children */
-
- sc->sc_sndcard_func.func = SCF_PCM;
-
- child = device_add_child(dev, "pcm", -1);
-
- if (child == NULL) {
- DPRINTF("out of memory\n");
- goto detach;
- }
- device_set_ivars(child, &sc->sc_sndcard_func);
-
- if (bus_generic_attach(dev)) {
- DPRINTF("child attach failed\n");
- goto detach;
- }
- return (0); /* success */
-
-detach:
- uaudio_detach(dev);
- return (ENXIO);
-}
-
-static void
-uaudio_pcm_setflags(device_t dev, uint32_t flags)
-{
- pcm_setflags(dev, pcm_getflags(dev) | flags);
-}
-
-int
-uaudio_attach_sub(device_t dev, kobj_class_t mixer_class, kobj_class_t chan_class)
-{
- struct uaudio_softc *sc = device_get_softc(device_get_parent(dev));
- char status[SND_STATUSLEN];
-
- uaudio_mixer_init(sc);
-
- if (sc->sc_uq_audio_swap_lr) {
- DPRINTF("hardware has swapped left and right\n");
- uaudio_pcm_setflags(dev, SD_F_PSWAPLR);
- }
- if (!(sc->sc_mix_info & SOUND_MASK_PCM)) {
-
- DPRINTF("emulating master volume\n");
-
- /*
- * Emulate missing pcm mixer controller
- * through FEEDER_VOLUME
- */
- uaudio_pcm_setflags(dev, SD_F_SOFTPCMVOL);
- }
- if (mixer_init(dev, mixer_class, sc)) {
- goto detach;
- }
- sc->sc_mixer_init = 1;
-
- snprintf(status, sizeof(status), "at ? %s", PCM_KLDSTRING(snd_uaudio));
-
- if (pcm_register(dev, sc,
- sc->sc_play_chan.valid ? 1 : 0,
- sc->sc_rec_chan.valid ? 1 : 0)) {
- goto detach;
- }
- sc->sc_pcm_registered = 1;
-
- if (sc->sc_play_chan.valid) {
- pcm_addchan(dev, PCMDIR_PLAY, chan_class, sc);
- }
- if (sc->sc_rec_chan.valid) {
- pcm_addchan(dev, PCMDIR_REC, chan_class, sc);
- }
- pcm_setstatus(dev, status);
-
- return (0); /* success */
-
-detach:
- uaudio_detach_sub(dev);
- return (ENXIO);
-}
-
-int
-uaudio_detach_sub(device_t dev)
-{
- struct uaudio_softc *sc = device_get_softc(device_get_parent(dev));
- int error = 0;
-
-repeat:
- if (sc->sc_pcm_registered) {
- error = pcm_unregister(dev);
- } else {
- if (sc->sc_mixer_init) {
- error = mixer_uninit(dev);
- }
- }
-
- if (error) {
- device_printf(dev, "Waiting for sound application to exit!\n");
- usb2_pause_mtx(NULL, 2 * hz);
- goto repeat; /* try again */
- }
- return (0); /* success */
-}
-
-static int
-uaudio_detach(device_t dev)
-{
- struct uaudio_softc *sc = device_get_softc(dev);
-
- if (bus_generic_detach(dev)) {
- DPRINTF("detach failed!\n");
- }
- sbuf_delete(&sc->sc_sndstat);
- sc->sc_sndstat_valid = 0;
-
- umidi_detach(dev);
-
- return (0);
-}
-
-/*========================================================================*
- * AS - Audio Stream - routines
- *========================================================================*/
-
-#if USB_DEBUG
-static void
-uaudio_chan_dump_ep_desc(const usb2_endpoint_descriptor_audio_t *ed)
-{
- if (ed) {
- DPRINTF("endpoint=%p bLength=%d bDescriptorType=%d \n"
- "bEndpointAddress=%d bmAttributes=0x%x \n"
- "wMaxPacketSize=%d bInterval=%d \n"
- "bRefresh=%d bSynchAddress=%d\n",
- ed, ed->bLength, ed->bDescriptorType,
- ed->bEndpointAddress, ed->bmAttributes,
- UGETW(ed->wMaxPacketSize), ed->bInterval,
- ed->bRefresh, ed->bSynchAddress);
- }
-}
-
-#endif
-
-static void
-uaudio_chan_fill_info_sub(struct uaudio_softc *sc, struct usb2_device *udev,
- uint32_t rate, uint16_t fps, uint8_t channels,
- uint8_t bit_resolution)
-{
- struct usb2_descriptor *desc = NULL;
- const struct usb2_audio_streaming_interface_descriptor *asid = NULL;
- const struct usb2_audio_streaming_type1_descriptor *asf1d = NULL;
- const struct usb2_audio_streaming_endpoint_descriptor *sed = NULL;
- const usb2_endpoint_descriptor_audio_t *ed1 = NULL;
- const usb2_endpoint_descriptor_audio_t *ed2 = NULL;
- struct usb2_config_descriptor *cd = usb2_get_config_descriptor(udev);
- struct usb2_interface_descriptor *id;
- const struct uaudio_format *p_fmt;
- struct uaudio_chan *chan;
- uint16_t curidx = 0xFFFF;
- uint16_t lastidx = 0xFFFF;
- uint16_t alt_index = 0;
- uint16_t wFormat;
- uint8_t ep_dir;
- uint8_t ep_type;
- uint8_t ep_sync;
- uint8_t bChannels;
- uint8_t bBitResolution;
- uint8_t x;
- uint8_t audio_if = 0;
- uint8_t sample_size;
-
- while ((desc = usb2_desc_foreach(cd, desc))) {
-
- if ((desc->bDescriptorType == UDESC_INTERFACE) &&
- (desc->bLength >= sizeof(*id))) {
-
- id = (void *)desc;
-
- if (id->bInterfaceNumber != lastidx) {
- lastidx = id->bInterfaceNumber;
- curidx++;
- alt_index = 0;
-
- } else {
- alt_index++;
- }
-
- if ((id->bInterfaceClass == UICLASS_AUDIO) &&
- (id->bInterfaceSubClass == UISUBCLASS_AUDIOSTREAM)) {
- audio_if = 1;
- } else {
- audio_if = 0;
- }
-
- if ((id->bInterfaceClass == UICLASS_AUDIO) &&
- (id->bInterfaceSubClass == UISUBCLASS_MIDISTREAM)) {
-
- /*
- * XXX could allow multiple MIDI interfaces
- * XXX
- */
-
- if ((sc->sc_midi_chan.valid == 0) &&
- usb2_get_iface(udev, curidx)) {
- sc->sc_midi_chan.iface_index = curidx;
- sc->sc_midi_chan.iface_alt_index = alt_index;
- sc->sc_midi_chan.valid = 1;
- }
- }
- asid = NULL;
- asf1d = NULL;
- ed1 = NULL;
- ed2 = NULL;
- sed = NULL;
- }
- if ((desc->bDescriptorType == UDESC_CS_INTERFACE) &&
- (desc->bDescriptorSubtype == AS_GENERAL) &&
- (desc->bLength >= sizeof(*asid))) {
- if (asid == NULL) {
- asid = (void *)desc;
- }
- }
- if ((desc->bDescriptorType == UDESC_CS_INTERFACE) &&
- (desc->bDescriptorSubtype == FORMAT_TYPE) &&
- (desc->bLength >= sizeof(*asf1d))) {
- if (asf1d == NULL) {
- asf1d = (void *)desc;
- if (asf1d->bFormatType != FORMAT_TYPE_I) {
- DPRINTFN(11, "ignored bFormatType = %d\n",
- asf1d->bFormatType);
- asf1d = NULL;
- continue;
- }
- if (asf1d->bLength < (sizeof(*asf1d) +
- (asf1d->bSamFreqType == 0) ? 6 :
- (asf1d->bSamFreqType * 3))) {
- DPRINTFN(11, "'asf1d' descriptor is too short\n");
- asf1d = NULL;
- continue;
- }
- }
- }
- if ((desc->bDescriptorType == UDESC_ENDPOINT) &&
- (desc->bLength >= sizeof(*ed1))) {
- if (ed1 == NULL) {
- ed1 = (void *)desc;
- if (UE_GET_XFERTYPE(ed1->bmAttributes) != UE_ISOCHRONOUS) {
- ed1 = NULL;
- }
- } else {
- if (ed2 == NULL) {
- ed2 = (void *)desc;
- if (UE_GET_XFERTYPE(ed2->bmAttributes) != UE_ISOCHRONOUS) {
- ed2 = NULL;
- continue;
- }
- if (ed2->bSynchAddress != 0) {
- DPRINTFN(11, "invalid endpoint: bSynchAddress != 0\n");
- ed2 = NULL;
- continue;
- }
- if (ed2->bEndpointAddress != ed1->bSynchAddress) {
- DPRINTFN(11, "invalid endpoint addresses: "
- "ep[0]->bSynchAddress=0x%x "
- "ep[1]->bEndpointAddress=0x%x\n",
- ed1->bSynchAddress,
- ed2->bEndpointAddress);
- ed2 = NULL;
- continue;
- }
- }
- }
- }
- if ((desc->bDescriptorType == UDESC_CS_ENDPOINT) &&
- (desc->bDescriptorSubtype == AS_GENERAL) &&
- (desc->bLength >= sizeof(*sed))) {
- if (sed == NULL) {
- sed = (void *)desc;
- }
- }
- if (audio_if && asid && asf1d && ed1 && sed) {
-
- ep_dir = UE_GET_DIR(ed1->bEndpointAddress);
- ep_type = UE_GET_ISO_TYPE(ed1->bmAttributes);
- ep_sync = 0;
-
- if ((sc->sc_uq_au_inp_async) &&
- (ep_dir == UE_DIR_IN) && (ep_type == UE_ISO_ADAPT)) {
- ep_type = UE_ISO_ASYNC;
- }
- if ((ep_dir == UE_DIR_IN) && (ep_type == UE_ISO_ADAPT)) {
- ep_sync = 1;
- }
- if ((ep_dir != UE_DIR_IN) && (ep_type == UE_ISO_ASYNC)) {
- ep_sync = 1;
- }
- /* Ignore sync endpoint information until further. */
-#if 0
- if (ep_sync && (!ed2)) {
- continue;
- }
- /*
- * we can't handle endpoints that need a sync pipe
- * yet
- */
-
- if (ep_sync) {
- DPRINTF("skipped sync interface\n");
- audio_if = 0;
- continue;
- }
-#endif
-
- wFormat = UGETW(asid->wFormatTag);
- bChannels = asf1d->bNrChannels;
- bBitResolution = asf1d->bBitResolution;
-
- if (asf1d->bSamFreqType == 0) {
- DPRINTFN(16, "Sample rate: %d-%dHz\n",
- UA_SAMP_LO(asf1d), UA_SAMP_HI(asf1d));
-
- if ((rate >= UA_SAMP_LO(asf1d)) &&
- (rate <= UA_SAMP_HI(asf1d))) {
- goto found_rate;
- }
- } else {
-
- for (x = 0; x < asf1d->bSamFreqType; x++) {
- DPRINTFN(16, "Sample rate = %dHz\n",
- UA_GETSAMP(asf1d, x));
-
- if (rate == UA_GETSAMP(asf1d, x)) {
- goto found_rate;
- }
- }
- }
-
- audio_if = 0;
- continue;
-
- found_rate:
-
- for (p_fmt = uaudio_formats;
- p_fmt->wFormat;
- p_fmt++) {
- if ((p_fmt->wFormat == wFormat) &&
- (p_fmt->bPrecision == bBitResolution)) {
- goto found_format;
- }
- }
-
- audio_if = 0;
- continue;
-
- found_format:
-
- if ((bChannels == channels) &&
- (bBitResolution == bit_resolution)) {
-
- chan = (ep_dir == UE_DIR_IN) ?
- &sc->sc_rec_chan :
- &sc->sc_play_chan;
-
- if ((chan->valid == 0) && usb2_get_iface(udev, curidx)) {
-
- chan->valid = 1;
-#if USB_DEBUG
- uaudio_chan_dump_ep_desc(ed1);
- uaudio_chan_dump_ep_desc(ed2);
-
- if (sed->bmAttributes & UA_SED_FREQ_CONTROL) {
- DPRINTFN(2, "FREQ_CONTROL\n");
- }
- if (sed->bmAttributes & UA_SED_PITCH_CONTROL) {
- DPRINTFN(2, "PITCH_CONTROL\n");
- }
-#endif
- DPRINTF("Sample rate = %dHz, channels = %d, "
- "bits = %d, format = %s\n", rate, channels,
- bit_resolution, p_fmt->description);
-
- chan->sample_rate = rate;
- chan->p_asid = asid;
- chan->p_asf1d = asf1d;
- chan->p_ed1 = ed1;
- chan->p_ed2 = ed2;
- chan->p_fmt = p_fmt;
- chan->p_sed = sed;
- chan->iface_index = curidx;
- chan->iface_alt_index = alt_index;
-
- if (ep_dir == UE_DIR_IN)
- chan->usb2_cfg =
- uaudio_cfg_record;
- else
- chan->usb2_cfg =
- uaudio_cfg_play;
-
- sample_size = ((chan->p_asf1d->bNrChannels *
- chan->p_asf1d->bBitResolution) / 8);
-
- /*
- * NOTE: "chan->bytes_per_frame"
- * should not be zero!
- */
- chan->bytes_per_frame = ((rate / fps) * sample_size);
-
- if (sc->sc_sndstat_valid) {
- sbuf_printf(&sc->sc_sndstat, "\n\t"
- "mode %d.%d:(%s) %dch, %d/%dbit, %s, %dHz",
- curidx, alt_index,
- (ep_dir == UE_DIR_IN) ? "input" : "output",
- asf1d->bNrChannels, asf1d->bBitResolution,
- asf1d->bSubFrameSize * 8,
- p_fmt->description, rate);
- }
- }
- }
- audio_if = 0;
- continue;
- }
- }
-}
-
-static void
-uaudio_chan_fill_info(struct uaudio_softc *sc, struct usb2_device *udev)
-{
- uint32_t rate = uaudio_default_rate;
- uint32_t z;
- uint16_t fps = usb2_get_isoc_fps(udev);
- uint8_t bits = uaudio_default_bits;
- uint8_t y;
- uint8_t channels = uaudio_default_channels;
- uint8_t x;
-
- bits -= (bits % 8);
- if ((bits == 0) || (bits > 32)) {
- /* set a valid value */
- bits = 32;
- }
- rate -= (rate % fps);
- if ((rate == 0) || (rate > 192000)) {
- /* set a valid value */
- rate = 192000 - (192000 % fps);
- }
- if ((channels == 0) || (channels > 2)) {
- /* set a valid value */
- channels = 2;
- }
- if (sbuf_new(&sc->sc_sndstat, NULL, 4096, SBUF_AUTOEXTEND)) {
- sc->sc_sndstat_valid = 1;
- }
- /* try to search for a valid config */
-
- for (x = channels; x; x--) {
- for (y = bits; y; y -= 8) {
- for (z = rate; z; z -= fps) {
- uaudio_chan_fill_info_sub(sc, udev, z, fps, x, y);
-
- if (sc->sc_rec_chan.valid &&
- sc->sc_play_chan.valid) {
- goto done;
- }
- }
- }
- }
-
-done:
- if (sc->sc_sndstat_valid) {
- sbuf_finish(&sc->sc_sndstat);
- }
-}
-
-static void
-uaudio_chan_play_callback(struct usb2_xfer *xfer)
-{
- struct uaudio_chan *ch = xfer->priv_sc;
- uint32_t *p_len = xfer->frlengths;
- uint32_t total;
- uint32_t blockcount;
- uint32_t n;
- uint32_t offset;
-
- /* allow dynamic sizing of play buffer */
- total = ch->intr_size;
-
- /* allow dynamic sizing of play buffer */
- blockcount = total / ch->bytes_per_frame;
-
- /* align units */
- blockcount -= (blockcount % UAUDIO_MINFRAMES);
-
- /* range check - min */
- if (blockcount == 0) {
- blockcount = UAUDIO_MINFRAMES;
- }
- /* range check - max */
- if (blockcount > xfer->max_frame_count) {
- blockcount = xfer->max_frame_count;
- }
- /* compute the total length */
- total = blockcount * ch->bytes_per_frame;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-tr_transferred:
- if (xfer->actlen < xfer->sumlen) {
- DPRINTF("short transfer, "
- "%d of %d bytes\n", xfer->actlen, total);
- }
- chn_intr(ch->pcm_ch);
-
- case USB_ST_SETUP:
- if (ch->bytes_per_frame > xfer->max_frame_size) {
- DPRINTF("bytes per transfer, %d, "
- "exceeds maximum, %d!\n",
- ch->bytes_per_frame,
- xfer->max_frame_size);
- break;
- }
- /* setup frame length */
- xfer->nframes = blockcount;
- for (n = 0; n != blockcount; n++) {
- p_len[n] = ch->bytes_per_frame;
- }
-
- if (ch->end == ch->start) {
- DPRINTF("no buffer!\n");
- break;
- }
- DPRINTFN(6, "transfer %d bytes\n", total);
-
- offset = 0;
-
- while (total > 0) {
-
- n = (ch->end - ch->cur);
- if (n > total) {
- n = total;
- }
- usb2_copy_in(xfer->frbuffers, offset, ch->cur, n);
-
- total -= n;
- ch->cur += n;
- offset += n;
-
- if (ch->cur >= ch->end) {
- ch->cur = ch->start;
- }
- }
-
- usb2_start_hardware(xfer);
- break;
-
- default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- break;
- }
- goto tr_transferred;
- }
-}
-
-static void
-uaudio_chan_record_callback(struct usb2_xfer *xfer)
-{
- struct uaudio_chan *ch = xfer->priv_sc;
- uint32_t *p_len = xfer->frlengths;
- uint32_t n;
- uint32_t m;
- uint32_t total;
- uint32_t blockcount;
- uint32_t offset0;
- uint32_t offset1;
-
- /* allow dynamic sizing of play buffer */
- total = ch->intr_size;
-
- /* allow dynamic sizing of play buffer */
- blockcount = total / ch->bytes_per_frame;
-
- /* align units */
- blockcount -= (blockcount % UAUDIO_MINFRAMES);
-
- /* range check - min */
- if (blockcount == 0) {
- blockcount = UAUDIO_MINFRAMES;
- }
- /* range check - max */
- if (blockcount > xfer->max_frame_count) {
- blockcount = xfer->max_frame_count;
- }
- /* compute the total length */
- total = blockcount * ch->bytes_per_frame;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-tr_transferred:
- if (xfer->actlen < total) {
- DPRINTF("short transfer, "
- "%d of %d bytes\n", xfer->actlen, total);
- } else {
- DPRINTFN(6, "transferred %d bytes\n", xfer->actlen);
- }
-
- offset0 = 0;
-
- for (n = 0; n != xfer->nframes; n++) {
-
- offset1 = offset0;
-
- while (p_len[n] > 0) {
-
- m = (ch->end - ch->cur);
-
- if (m > p_len[n]) {
- m = p_len[n];
- }
- usb2_copy_out(xfer->frbuffers, offset1, ch->cur, m);
-
- p_len[n] -= m;
- offset1 += m;
- ch->cur += m;
-
- if (ch->cur >= ch->end) {
- ch->cur = ch->start;
- }
- }
-
- offset0 += ch->bytes_per_frame;
- }
-
- chn_intr(ch->pcm_ch);
-
- case USB_ST_SETUP:
- if (ch->bytes_per_frame > xfer->max_frame_size) {
- DPRINTF("bytes per transfer, %d, "
- "exceeds maximum, %d!\n",
- ch->bytes_per_frame,
- xfer->max_frame_size);
- return;
- }
- xfer->nframes = blockcount;
- for (n = 0; n != xfer->nframes; n++) {
- p_len[n] = ch->bytes_per_frame;
- }
-
- if (ch->end == ch->start) {
- DPRINTF("no buffer!\n");
- return;
- }
- usb2_start_hardware(xfer);
- return;
-
- default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- return;
- }
- goto tr_transferred;
- }
-}
-
-void *
-uaudio_chan_init(struct uaudio_softc *sc, struct snd_dbuf *b,
- struct pcm_channel *c, int dir)
-{
- struct uaudio_chan *ch = ((dir == PCMDIR_PLAY) ?
- &sc->sc_play_chan : &sc->sc_rec_chan);
- uint32_t buf_size;
- uint8_t endpoint;
- uint8_t iface_index;
- uint8_t alt_index;
- usb2_error_t err;
-
- /* compute required buffer size */
- buf_size = (ch->bytes_per_frame * UAUDIO_MINFRAMES);
-
- /* setup interrupt interval */
- ch->intr_size = buf_size;
-
- /* double buffering */
- buf_size *= 2;
-
- ch->buf = malloc(buf_size, M_DEVBUF, M_WAITOK | M_ZERO);
- if (ch->buf == NULL) {
- goto error;
- }
- if (sndbuf_setup(b, ch->buf, buf_size) != 0) {
- goto error;
- }
- ch->start = ch->buf;
- ch->end = ch->buf + buf_size;
- ch->cur = ch->buf;
- ch->pcm_ch = c;
- ch->pcm_mtx = c->lock;
- ch->pcm_buf = b;
-
- if (ch->pcm_mtx == NULL) {
- DPRINTF("ERROR: PCM channels does not have a mutex!\n");
- goto error;
- }
- /* setup play/record format */
-
- ch->pcm_cap.fmtlist = ch->pcm_format;
-
- ch->pcm_format[0] = 0;
- ch->pcm_format[1] = 0;
-
- ch->pcm_cap.minspeed = ch->sample_rate;
- ch->pcm_cap.maxspeed = ch->sample_rate;
-
- ch->pcm_cap.fmtlist[0] = ch->p_fmt->freebsd_fmt;
-
- if (ch->p_asf1d->bNrChannels == 2) {
- ch->pcm_cap.fmtlist[0] |= AFMT_STEREO;
- }
- ch->pcm_cap.fmtlist[1] = 0;
-
-
- /* set alternate interface corresponding to the mode */
-
- endpoint = ch->p_ed1->bEndpointAddress;
- iface_index = ch->iface_index;
- alt_index = ch->iface_alt_index;
-
- DPRINTF("endpoint=0x%02x, speed=%d, iface=%d alt=%d\n",
- endpoint, ch->sample_rate, iface_index, alt_index);
-
- err = usb2_set_alt_interface_index(sc->sc_udev, iface_index, alt_index);
- if (err) {
- DPRINTF("setting of alternate index failed: %s!\n",
- usb2_errstr(err));
- goto error;
- }
- usb2_set_parent_iface(sc->sc_udev, iface_index, sc->sc_mixer_iface_index);
-
- /*
- * If just one sampling rate is supported,
- * no need to call "uaudio_set_speed()".
- * Roland SD-90 freezes by a SAMPLING_FREQ_CONTROL request.
- */
- if (ch->p_asf1d->bSamFreqType != 1) {
- if (uaudio_set_speed(sc->sc_udev, endpoint, ch->sample_rate)) {
- /*
- * If the endpoint is adaptive setting the speed may
- * fail.
- */
- DPRINTF("setting of sample rate failed! (continuing anyway)\n");
- }
- }
- if (usb2_transfer_setup(sc->sc_udev, &iface_index, ch->xfer,
- ch->usb2_cfg, UAUDIO_NCHANBUFS, ch, ch->pcm_mtx)) {
- DPRINTF("could not allocate USB transfers!\n");
- goto error;
- }
- return (ch);
-
-error:
- uaudio_chan_free(ch);
- return (NULL);
-}
-
-int
-uaudio_chan_free(struct uaudio_chan *ch)
-{
- if (ch->buf != NULL) {
- free(ch->buf, M_DEVBUF);
- ch->buf = NULL;
- }
- usb2_transfer_unsetup(ch->xfer, UAUDIO_NCHANBUFS);
-
- ch->valid = 0;
-
- return (0);
-}
-
-int
-uaudio_chan_set_param_blocksize(struct uaudio_chan *ch, uint32_t blocksize)
-{
- uaudio_chan_set_param_fragments(ch, blocksize, 0 - 1);
-
- return (ch->block_size);
-}
-
-int
-uaudio_chan_set_param_fragments(struct uaudio_chan *ch, uint32_t blocksize,
- uint32_t blockcount)
-{
- /* we only support one size */
- blocksize = ch->intr_size;
- blockcount = 2;
-
- if ((sndbuf_getblksz(ch->pcm_buf) != blocksize) ||
- (sndbuf_getblkcnt(ch->pcm_buf) != blockcount)) {
- DPRINTFN(1, "resizing to %u x "
- "%u bytes\n", blockcount, blocksize);
- if (sndbuf_resize(ch->pcm_buf, blockcount, blocksize)) {
- DPRINTFN(0, "failed to resize sound buffer, count=%u, "
- "size=%u\n", blockcount, blocksize);
- }
- }
- ch->block_size = sndbuf_getblksz(ch->pcm_buf);
-
- return (1);
-}
-
-int
-uaudio_chan_set_param_speed(struct uaudio_chan *ch, uint32_t speed)
-{
- if (speed != ch->sample_rate) {
- DPRINTF("rate conversion required\n");
- }
- return (ch->sample_rate);
-}
-
-int
-uaudio_chan_getptr(struct uaudio_chan *ch)
-{
- return (ch->cur - ch->start);
-}
-
-struct pcmchan_caps *
-uaudio_chan_getcaps(struct uaudio_chan *ch)
-{
- return (&ch->pcm_cap);
-}
-
-int
-uaudio_chan_set_param_format(struct uaudio_chan *ch, uint32_t format)
-{
- ch->format = format;
- return (0);
-}
-
-int
-uaudio_chan_start(struct uaudio_chan *ch)
-{
- ch->cur = ch->start;
-
-#if (UAUDIO_NCHANBUFS != 2)
-#error "please update code"
-#endif
- if (ch->xfer[0]) {
- usb2_transfer_start(ch->xfer[0]);
- }
- if (ch->xfer[1]) {
- usb2_transfer_start(ch->xfer[1]);
- }
- return (0);
-}
-
-int
-uaudio_chan_stop(struct uaudio_chan *ch)
-{
-#if (UAUDIO_NCHANBUFS != 2)
-#error "please update code"
-#endif
- usb2_transfer_stop(ch->xfer[0]);
- usb2_transfer_stop(ch->xfer[1]);
- return (0);
-}
-
-/*========================================================================*
- * AC - Audio Controller - routines
- *========================================================================*/
-
-static void
-uaudio_mixer_add_ctl_sub(struct uaudio_softc *sc, struct uaudio_mixer_node *mc)
-{
- struct uaudio_mixer_node *p_mc_new =
- malloc(sizeof(*p_mc_new), M_USBDEV, M_WAITOK);
-
- if (p_mc_new) {
- bcopy(mc, p_mc_new, sizeof(*p_mc_new));
- p_mc_new->next = sc->sc_mixer_root;
- sc->sc_mixer_root = p_mc_new;
- sc->sc_mixer_count++;
- } else {
- DPRINTF("out of memory\n");
- }
-}
-
-static void
-uaudio_mixer_add_ctl(struct uaudio_softc *sc, struct uaudio_mixer_node *mc)
-{
- int32_t res;
-
- if (mc->class < UAC_NCLASSES) {
- DPRINTF("adding %s.%d\n",
- uac_names[mc->class], mc->ctl);
- } else {
- DPRINTF("adding %d\n", mc->ctl);
- }
-
- mc->delta = 0;
- if (mc->type == MIX_ON_OFF) {
- mc->minval = 0;
- mc->maxval = 1;
- } else if (mc->type == MIX_SELECTOR) {
-
- } else {
-
- /* determine min and max values */
-
- mc->minval = uaudio_mixer_get(sc->sc_udev, GET_MIN, mc);
-
- mc->minval = uaudio_mixer_signext(mc->type, mc->minval);
-
- mc->maxval = uaudio_mixer_get(sc->sc_udev, GET_MAX, mc);
-
- mc->maxval = 1 + uaudio_mixer_signext(mc->type, mc->maxval);
-
- mc->mul = mc->maxval - mc->minval;
- if (mc->mul == 0) {
- mc->mul = 1;
- }
- res = uaudio_mixer_get(sc->sc_udev, GET_RES, mc);
- if (res > 0) {
- mc->delta = ((res * 255) + (mc->mul / 2)) / mc->mul;
- }
- }
-
- if (mc->maxval < mc->minval) {
- mc->maxval = mc->minval;
- }
- uaudio_mixer_add_ctl_sub(sc, mc);
-
-#if USB_DEBUG
- if (uaudio_debug > 2) {
- uint8_t i;
-
- for (i = 0; i < mc->nchan; i++) {
- DPRINTF("[mix] wValue=%04x\n", mc->wValue[0]);
- }
- DPRINTF("[mix] wIndex=%04x type=%d ctl='%d' "
- "min=%d max=%d\n",
- mc->wIndex, mc->type, mc->ctl,
- mc->minval, mc->maxval);
- }
-#endif
-}
-
-static void
-uaudio_mixer_add_input(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
-#if USB_DEBUG
- const struct usb2_audio_input_terminal *d = iot[id].u.it;
-
- DPRINTFN(3, "bTerminalId=%d wTerminalType=0x%04x "
- "bAssocTerminal=%d bNrChannels=%d wChannelConfig=%d "
- "iChannelNames=%d\n",
- d->bTerminalId, UGETW(d->wTerminalType), d->bAssocTerminal,
- d->bNrChannels, UGETW(d->wChannelConfig),
- d->iChannelNames);
-#endif
-}
-
-static void
-uaudio_mixer_add_output(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
-#if USB_DEBUG
- const struct usb2_audio_output_terminal *d = iot[id].u.ot;
-
- DPRINTFN(3, "bTerminalId=%d wTerminalType=0x%04x "
- "bAssocTerminal=%d bSourceId=%d iTerminal=%d\n",
- d->bTerminalId, UGETW(d->wTerminalType), d->bAssocTerminal,
- d->bSourceId, d->iTerminal);
-#endif
-}
-
-static void
-uaudio_mixer_add_mixer(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- struct uaudio_mixer_node mix;
-
- const struct usb2_audio_mixer_unit_0 *d0 = iot[id].u.mu;
- const struct usb2_audio_mixer_unit_1 *d1;
-
- uint32_t bno; /* bit number */
- uint32_t p; /* bit number accumulator */
- uint32_t mo; /* matching outputs */
- uint32_t mc; /* matching channels */
- uint32_t ichs; /* input channels */
- uint32_t ochs; /* output channels */
- uint32_t c;
- uint32_t chs; /* channels */
- uint32_t i;
- uint32_t o;
-
- DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
- d0->bUnitId, d0->bNrInPins);
-
- /* compute the number of input channels */
-
- ichs = 0;
- for (i = 0; i < d0->bNrInPins; i++) {
- ichs += (uaudio_mixer_get_cluster(d0->baSourceId[i], iot)
- .bNrChannels);
- }
-
- d1 = (const void *)(d0->baSourceId + d0->bNrInPins);
-
- /* and the number of output channels */
-
- ochs = d1->bNrChannels;
-
- DPRINTFN(3, "ichs=%d ochs=%d\n", ichs, ochs);
-
- bzero(&mix, sizeof(mix));
-
- mix.wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
- uaudio_mixer_determine_class(&iot[id], &mix);
- mix.type = MIX_SIGNED_16;
-
- if (uaudio_mixer_verify_desc(d0, ((ichs * ochs) + 7) / 8) == NULL) {
- return;
- }
- for (p = i = 0; i < d0->bNrInPins; i++) {
- chs = uaudio_mixer_get_cluster(d0->baSourceId[i], iot).bNrChannels;
- mc = 0;
- for (c = 0; c < chs; c++) {
- mo = 0;
- for (o = 0; o < ochs; o++) {
- bno = ((p + c) * ochs) + o;
- if (BIT_TEST(d1->bmControls, bno)) {
- mo++;
- }
- }
- if (mo == 1) {
- mc++;
- }
- }
- if ((mc == chs) && (chs <= MIX_MAX_CHAN)) {
-
- /* repeat bit-scan */
-
- mc = 0;
- for (c = 0; c < chs; c++) {
- for (o = 0; o < ochs; o++) {
- bno = ((p + c) * ochs) + o;
- if (BIT_TEST(d1->bmControls, bno)) {
- mix.wValue[mc++] = MAKE_WORD(p + c + 1, o + 1);
- }
- }
- }
- mix.nchan = chs;
- uaudio_mixer_add_ctl(sc, &mix);
- } else {
- /* XXX */
- }
- p += chs;
- }
-}
-
-static void
-uaudio_mixer_add_selector(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- const struct usb2_audio_selector_unit *d = iot[id].u.su;
- struct uaudio_mixer_node mix;
- uint16_t i;
-
- DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
- d->bUnitId, d->bNrInPins);
-
- if (d->bNrInPins == 0) {
- return;
- }
- bzero(&mix, sizeof(mix));
-
- mix.wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
- mix.wValue[0] = MAKE_WORD(0, 0);
- uaudio_mixer_determine_class(&iot[id], &mix);
- mix.nchan = 1;
- mix.type = MIX_SELECTOR;
-
- mix.ctl = SOUND_MIXER_NRDEVICES;
- mix.minval = 1;
- mix.maxval = d->bNrInPins;
-
- if (mix.maxval > MAX_SELECTOR_INPUT_PIN) {
- mix.maxval = MAX_SELECTOR_INPUT_PIN;
- }
- mix.mul = (mix.maxval - mix.minval);
- for (i = 0; i < MAX_SELECTOR_INPUT_PIN; i++) {
- mix.slctrtype[i] = SOUND_MIXER_NRDEVICES;
- }
-
- for (i = 0; i < mix.maxval; i++) {
- mix.slctrtype[i] = uaudio_mixer_feature_name
- (&iot[d->baSourceId[i]], &mix);
- }
-
- mix.class = 0; /* not used */
-
- uaudio_mixer_add_ctl(sc, &mix);
-}
-
-static uint32_t
-uaudio_mixer_feature_get_bmaControls(const struct usb2_audio_feature_unit *d,
- uint8_t index)
-{
- uint32_t temp = 0;
- uint32_t offset = (index * d->bControlSize);
-
- if (d->bControlSize > 0) {
- temp |= d->bmaControls[offset];
- if (d->bControlSize > 1) {
- temp |= d->bmaControls[offset + 1] << 8;
- if (d->bControlSize > 2) {
- temp |= d->bmaControls[offset + 2] << 16;
- if (d->bControlSize > 3) {
- temp |= d->bmaControls[offset + 3] << 24;
- }
- }
- }
- }
- return (temp);
-}
-
-static void
-uaudio_mixer_add_feature(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- const struct usb2_audio_feature_unit *d = iot[id].u.fu;
- struct uaudio_mixer_node mix;
- uint32_t fumask;
- uint32_t mmask;
- uint32_t cmask;
- uint16_t mixernumber;
- uint8_t nchan;
- uint8_t chan;
- uint8_t ctl;
- uint8_t i;
-
- if (d->bControlSize == 0) {
- return;
- }
- bzero(&mix, sizeof(mix));
-
- nchan = (d->bLength - 7) / d->bControlSize;
- mmask = uaudio_mixer_feature_get_bmaControls(d, 0);
- cmask = 0;
-
- if (nchan == 0) {
- return;
- }
- /* figure out what we can control */
-
- for (chan = 1; chan < nchan; chan++) {
- DPRINTFN(10, "chan=%d mask=%x\n",
- chan, uaudio_mixer_feature_get_bmaControls(d, chan));
-
- cmask |= uaudio_mixer_feature_get_bmaControls(d, chan);
- }
-
- if (nchan > MIX_MAX_CHAN) {
- nchan = MIX_MAX_CHAN;
- }
- mix.wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
-
- for (ctl = 1; ctl <= LOUDNESS_CONTROL; ctl++) {
-
- fumask = FU_MASK(ctl);
-
- DPRINTFN(5, "ctl=%d fumask=0x%04x\n",
- ctl, fumask);
-
- if (mmask & fumask) {
- mix.nchan = 1;
- mix.wValue[0] = MAKE_WORD(ctl, 0);
- } else if (cmask & fumask) {
- mix.nchan = nchan - 1;
- for (i = 1; i < nchan; i++) {
- if (uaudio_mixer_feature_get_bmaControls(d, i) & fumask)
- mix.wValue[i - 1] = MAKE_WORD(ctl, i);
- else
- mix.wValue[i - 1] = -1;
- }
- } else {
- continue;
- }
-
- mixernumber = uaudio_mixer_feature_name(&iot[id], &mix);
-
- switch (ctl) {
- case MUTE_CONTROL:
- mix.type = MIX_ON_OFF;
- mix.ctl = SOUND_MIXER_NRDEVICES;
- break;
-
- case VOLUME_CONTROL:
- mix.type = MIX_SIGNED_16;
- mix.ctl = mixernumber;
- break;
-
- case BASS_CONTROL:
- mix.type = MIX_SIGNED_8;
- mix.ctl = SOUND_MIXER_BASS;
- break;
-
- case MID_CONTROL:
- mix.type = MIX_SIGNED_8;
- mix.ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
- break;
-
- case TREBLE_CONTROL:
- mix.type = MIX_SIGNED_8;
- mix.ctl = SOUND_MIXER_TREBLE;
- break;
-
- case GRAPHIC_EQUALIZER_CONTROL:
- continue; /* XXX don't add anything */
- break;
-
- case AGC_CONTROL:
- mix.type = MIX_ON_OFF;
- mix.ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
- break;
-
- case DELAY_CONTROL:
- mix.type = MIX_UNSIGNED_16;
- mix.ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
- break;
-
- case BASS_BOOST_CONTROL:
- mix.type = MIX_ON_OFF;
- mix.ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
- break;
-
- case LOUDNESS_CONTROL:
- mix.type = MIX_ON_OFF;
- mix.ctl = SOUND_MIXER_LOUD; /* Is this correct ? */
- break;
-
- default:
- mix.type = MIX_UNKNOWN;
- break;
- }
-
- if (mix.type != MIX_UNKNOWN) {
- uaudio_mixer_add_ctl(sc, &mix);
- }
- }
-}
-
-static void
-uaudio_mixer_add_processing_updown(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- const struct usb2_audio_processing_unit_0 *d0 = iot[id].u.pu;
- const struct usb2_audio_processing_unit_1 *d1 =
- (const void *)(d0->baSourceId + d0->bNrInPins);
- const struct usb2_audio_processing_unit_updown *ud =
- (const void *)(d1->bmControls + d1->bControlSize);
- struct uaudio_mixer_node mix;
- uint8_t i;
-
- if (uaudio_mixer_verify_desc(d0, sizeof(*ud)) == NULL) {
- return;
- }
- if (uaudio_mixer_verify_desc(d0, sizeof(*ud) + (2 * ud->bNrModes))
- == NULL) {
- return;
- }
- DPRINTFN(3, "bUnitId=%d bNrModes=%d\n",
- d0->bUnitId, ud->bNrModes);
-
- if (!(d1->bmControls[0] & UA_PROC_MASK(UD_MODE_SELECT_CONTROL))) {
- DPRINTF("no mode select\n");
- return;
- }
- bzero(&mix, sizeof(mix));
-
- mix.wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
- mix.nchan = 1;
- mix.wValue[0] = MAKE_WORD(UD_MODE_SELECT_CONTROL, 0);
- uaudio_mixer_determine_class(&iot[id], &mix);
- mix.type = MIX_ON_OFF; /* XXX */
-
- for (i = 0; i < ud->bNrModes; i++) {
- DPRINTFN(3, "i=%d bm=0x%x\n", i, UGETW(ud->waModes[i]));
- /* XXX */
- }
-
- uaudio_mixer_add_ctl(sc, &mix);
-}
-
-static void
-uaudio_mixer_add_processing(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- const struct usb2_audio_processing_unit_0 *d0 = iot[id].u.pu;
- const struct usb2_audio_processing_unit_1 *d1 =
- (const void *)(d0->baSourceId + d0->bNrInPins);
- struct uaudio_mixer_node mix;
- uint16_t ptype;
-
- bzero(&mix, sizeof(mix));
-
- ptype = UGETW(d0->wProcessType);
-
- DPRINTFN(3, "wProcessType=%d bUnitId=%d "
- "bNrInPins=%d\n", ptype, d0->bUnitId, d0->bNrInPins);
-
- if (d1->bControlSize == 0) {
- return;
- }
- if (d1->bmControls[0] & UA_PROC_ENABLE_MASK) {
- mix.wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
- mix.nchan = 1;
- mix.wValue[0] = MAKE_WORD(XX_ENABLE_CONTROL, 0);
- uaudio_mixer_determine_class(&iot[id], &mix);
- mix.type = MIX_ON_OFF;
- uaudio_mixer_add_ctl(sc, &mix);
- }
- switch (ptype) {
- case UPDOWNMIX_PROCESS:
- uaudio_mixer_add_processing_updown(sc, iot, id);
- break;
-
- case DOLBY_PROLOGIC_PROCESS:
- case P3D_STEREO_EXTENDER_PROCESS:
- case REVERBATION_PROCESS:
- case CHORUS_PROCESS:
- case DYN_RANGE_COMP_PROCESS:
- default:
- DPRINTF("unit %d, type=%d is not implemented\n",
- d0->bUnitId, ptype);
- break;
- }
-}
-
-static void
-uaudio_mixer_add_extension(struct uaudio_softc *sc,
- const struct uaudio_terminal_node *iot, int id)
-{
- const struct usb2_audio_extension_unit_0 *d0 = iot[id].u.eu;
- const struct usb2_audio_extension_unit_1 *d1 =
- (const void *)(d0->baSourceId + d0->bNrInPins);
- struct uaudio_mixer_node mix;
-
- DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
- d0->bUnitId, d0->bNrInPins);
-
- if (sc->sc_uq_au_no_xu) {
- return;
- }
- if (d1->bControlSize == 0) {
- return;
- }
- if (d1->bmControls[0] & UA_EXT_ENABLE_MASK) {
-
- bzero(&mix, sizeof(mix));
-
- mix.wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
- mix.nchan = 1;
- mix.wValue[0] = MAKE_WORD(UA_EXT_ENABLE, 0);
- uaudio_mixer_determine_class(&iot[id], &mix);
- mix.type = MIX_ON_OFF;
-
- uaudio_mixer_add_ctl(sc, &mix);
- }
-}
-
-static const void *
-uaudio_mixer_verify_desc(const void *arg, uint32_t len)
-{
- const struct usb2_audio_mixer_unit_1 *d1;
- const struct usb2_audio_extension_unit_1 *e1;
- const struct usb2_audio_processing_unit_1 *u1;
-
- union {
- const struct usb2_descriptor *desc;
- const struct usb2_audio_input_terminal *it;
- const struct usb2_audio_output_terminal *ot;
- const struct usb2_audio_mixer_unit_0 *mu;
- const struct usb2_audio_selector_unit *su;
- const struct usb2_audio_feature_unit *fu;
- const struct usb2_audio_processing_unit_0 *pu;
- const struct usb2_audio_extension_unit_0 *eu;
- } u;
-
- u.desc = arg;
-
- if (u.desc == NULL) {
- goto error;
- }
- if (u.desc->bDescriptorType != UDESC_CS_INTERFACE) {
- goto error;
- }
- switch (u.desc->bDescriptorSubtype) {
- case UDESCSUB_AC_INPUT:
- len += sizeof(*u.it);
- break;
-
- case UDESCSUB_AC_OUTPUT:
- len += sizeof(*u.ot);
- break;
-
- case UDESCSUB_AC_MIXER:
- len += sizeof(*u.mu);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += u.mu->bNrInPins;
-
- if (u.desc->bLength < len) {
- goto error;
- }
- d1 = (const void *)(u.mu->baSourceId + u.mu->bNrInPins);
-
- len += sizeof(*d1);
- break;
-
- case UDESCSUB_AC_SELECTOR:
- len += sizeof(*u.su);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += u.su->bNrInPins;
- break;
-
- case UDESCSUB_AC_FEATURE:
- len += (sizeof(*u.fu) + 1);
- break;
-
- case UDESCSUB_AC_PROCESSING:
- len += sizeof(*u.pu);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += u.pu->bNrInPins;
-
- if (u.desc->bLength < len) {
- goto error;
- }
- u1 = (const void *)(u.pu->baSourceId + u.pu->bNrInPins);
-
- len += sizeof(*u1);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += u1->bControlSize;
-
- break;
-
- case UDESCSUB_AC_EXTENSION:
- len += sizeof(*u.eu);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += u.eu->bNrInPins;
-
- if (u.desc->bLength < len) {
- goto error;
- }
- e1 = (const void *)(u.eu->baSourceId + u.eu->bNrInPins);
-
- len += sizeof(*e1);
-
- if (u.desc->bLength < len) {
- goto error;
- }
- len += e1->bControlSize;
- break;
-
- default:
- goto error;
- }
-
- if (u.desc->bLength < len) {
- goto error;
- }
- return (u.desc);
-
-error:
- if (u.desc) {
- DPRINTF("invalid descriptor, type=%d, "
- "sub_type=%d, len=%d of %d bytes\n",
- u.desc->bDescriptorType,
- u.desc->bDescriptorSubtype,
- u.desc->bLength, len);
- }
- return (NULL);
-}
-
-#if USB_DEBUG
-static void
-uaudio_mixer_dump_cluster(uint8_t id, const struct uaudio_terminal_node *iot)
-{
- static const char *channel_names[16] = {
- "LEFT", "RIGHT", "CENTER", "LFE",
- "LEFT_SURROUND", "RIGHT_SURROUND", "LEFT_CENTER", "RIGHT_CENTER",
- "SURROUND", "LEFT_SIDE", "RIGHT_SIDE", "TOP",
- "RESERVED12", "RESERVED13", "RESERVED14", "RESERVED15",
- };
- uint16_t cc;
- uint8_t i;
- const struct usb2_audio_cluster cl = uaudio_mixer_get_cluster(id, iot);
-
- cc = UGETW(cl.wChannelConfig);
-
- DPRINTF("cluster: bNrChannels=%u iChannelNames=%u wChannelConfig="
- "0x%04x:\n", cl.iChannelNames, cl.bNrChannels, cc);
-
- for (i = 0; cc; i++) {
- if (cc & 1) {
- DPRINTF(" - %s\n", channel_names[i]);
- }
- cc >>= 1;
- }
-}
-
-#endif
-
-static struct usb2_audio_cluster
-uaudio_mixer_get_cluster(uint8_t id, const struct uaudio_terminal_node *iot)
-{
- struct usb2_audio_cluster r;
- const struct usb2_descriptor *dp;
- uint8_t i;
-
- for (i = 0; i < UAUDIO_RECURSE_LIMIT; i++) { /* avoid infinite loops */
- dp = iot[id].u.desc;
- if (dp == NULL) {
- goto error;
- }
- switch (dp->bDescriptorSubtype) {
- case UDESCSUB_AC_INPUT:
- r.bNrChannels = iot[id].u.it->bNrChannels;
- r.wChannelConfig[0] = iot[id].u.it->wChannelConfig[0];
- r.wChannelConfig[1] = iot[id].u.it->wChannelConfig[1];
- r.iChannelNames = iot[id].u.it->iChannelNames;
- goto done;
-
- case UDESCSUB_AC_OUTPUT:
- id = iot[id].u.ot->bSourceId;
- break;
-
- case UDESCSUB_AC_MIXER:
- r = *(const struct usb2_audio_cluster *)
- &iot[id].u.mu->baSourceId[iot[id].u.mu->
- bNrInPins];
- goto done;
-
- case UDESCSUB_AC_SELECTOR:
- if (iot[id].u.su->bNrInPins > 0) {
- /* XXX This is not really right */
- id = iot[id].u.su->baSourceId[0];
- }
- break;
-
- case UDESCSUB_AC_FEATURE:
- id = iot[id].u.fu->bSourceId;
- break;
-
- case UDESCSUB_AC_PROCESSING:
- r = *((const struct usb2_audio_cluster *)
- &iot[id].u.pu->baSourceId[iot[id].u.pu->
- bNrInPins]);
- goto done;
-
- case UDESCSUB_AC_EXTENSION:
- r = *((const struct usb2_audio_cluster *)
- &iot[id].u.eu->baSourceId[iot[id].u.eu->
- bNrInPins]);
- goto done;
-
- default:
- goto error;
- }
- }
-error:
- DPRINTF("bad data\n");
- bzero(&r, sizeof(r));
-done:
- return (r);
-}
-
-#if USB_DEBUG
-
-struct uaudio_tt_to_string {
- uint16_t terminal_type;
- const char *desc;
-};
-
-static const struct uaudio_tt_to_string uaudio_tt_to_string[] = {
-
- /* USB terminal types */
- {UAT_UNDEFINED, "UAT_UNDEFINED"},
- {UAT_STREAM, "UAT_STREAM"},
- {UAT_VENDOR, "UAT_VENDOR"},
-
- /* input terminal types */
- {UATI_UNDEFINED, "UATI_UNDEFINED"},
- {UATI_MICROPHONE, "UATI_MICROPHONE"},
- {UATI_DESKMICROPHONE, "UATI_DESKMICROPHONE"},
- {UATI_PERSONALMICROPHONE, "UATI_PERSONALMICROPHONE"},
- {UATI_OMNIMICROPHONE, "UATI_OMNIMICROPHONE"},
- {UATI_MICROPHONEARRAY, "UATI_MICROPHONEARRAY"},
- {UATI_PROCMICROPHONEARR, "UATI_PROCMICROPHONEARR"},
-
- /* output terminal types */
- {UATO_UNDEFINED, "UATO_UNDEFINED"},
- {UATO_SPEAKER, "UATO_SPEAKER"},
- {UATO_HEADPHONES, "UATO_HEADPHONES"},
- {UATO_DISPLAYAUDIO, "UATO_DISPLAYAUDIO"},
- {UATO_DESKTOPSPEAKER, "UATO_DESKTOPSPEAKER"},
- {UATO_ROOMSPEAKER, "UATO_ROOMSPEAKER"},
- {UATO_COMMSPEAKER, "UATO_COMMSPEAKER"},
- {UATO_SUBWOOFER, "UATO_SUBWOOFER"},
-
- /* bidir terminal types */
- {UATB_UNDEFINED, "UATB_UNDEFINED"},
- {UATB_HANDSET, "UATB_HANDSET"},
- {UATB_HEADSET, "UATB_HEADSET"},
- {UATB_SPEAKERPHONE, "UATB_SPEAKERPHONE"},
- {UATB_SPEAKERPHONEESUP, "UATB_SPEAKERPHONEESUP"},
- {UATB_SPEAKERPHONEECANC, "UATB_SPEAKERPHONEECANC"},
-
- /* telephony terminal types */
- {UATT_UNDEFINED, "UATT_UNDEFINED"},
- {UATT_PHONELINE, "UATT_PHONELINE"},
- {UATT_TELEPHONE, "UATT_TELEPHONE"},
- {UATT_DOWNLINEPHONE, "UATT_DOWNLINEPHONE"},
-
- /* external terminal types */
- {UATE_UNDEFINED, "UATE_UNDEFINED"},
- {UATE_ANALOGCONN, "UATE_ANALOGCONN"},
- {UATE_LINECONN, "UATE_LINECONN"},
- {UATE_LEGACYCONN, "UATE_LEGACYCONN"},
- {UATE_DIGITALAUIFC, "UATE_DIGITALAUIFC"},
- {UATE_SPDIF, "UATE_SPDIF"},
- {UATE_1394DA, "UATE_1394DA"},
- {UATE_1394DV, "UATE_1394DV"},
-
- /* embedded function terminal types */
- {UATF_UNDEFINED, "UATF_UNDEFINED"},
- {UATF_CALIBNOISE, "UATF_CALIBNOISE"},
- {UATF_EQUNOISE, "UATF_EQUNOISE"},
- {UATF_CDPLAYER, "UATF_CDPLAYER"},
- {UATF_DAT, "UATF_DAT"},
- {UATF_DCC, "UATF_DCC"},
- {UATF_MINIDISK, "UATF_MINIDISK"},
- {UATF_ANALOGTAPE, "UATF_ANALOGTAPE"},
- {UATF_PHONOGRAPH, "UATF_PHONOGRAPH"},
- {UATF_VCRAUDIO, "UATF_VCRAUDIO"},
- {UATF_VIDEODISCAUDIO, "UATF_VIDEODISCAUDIO"},
- {UATF_DVDAUDIO, "UATF_DVDAUDIO"},
- {UATF_TVTUNERAUDIO, "UATF_TVTUNERAUDIO"},
- {UATF_SATELLITE, "UATF_SATELLITE"},
- {UATF_CABLETUNER, "UATF_CABLETUNER"},
- {UATF_DSS, "UATF_DSS"},
- {UATF_RADIORECV, "UATF_RADIORECV"},
- {UATF_RADIOXMIT, "UATF_RADIOXMIT"},
- {UATF_MULTITRACK, "UATF_MULTITRACK"},
- {UATF_SYNTHESIZER, "UATF_SYNTHESIZER"},
-
- /* unknown */
- {0x0000, "UNKNOWN"},
-};
-
-static const char *
-uaudio_mixer_get_terminal_name(uint16_t terminal_type)
-{
- const struct uaudio_tt_to_string *uat = uaudio_tt_to_string;
-
- while (uat->terminal_type) {
- if (uat->terminal_type == terminal_type) {
- break;
- }
- uat++;
- }
- if (uat->terminal_type == 0) {
- DPRINTF("unknown terminal type (0x%04x)", terminal_type);
- }
- return (uat->desc);
-}
-
-#endif
-
-static uint16_t
-uaudio_mixer_determine_class(const struct uaudio_terminal_node *iot,
- struct uaudio_mixer_node *mix)
-{
- uint16_t terminal_type = 0x0000;
- const struct uaudio_terminal_node *input[2];
- const struct uaudio_terminal_node *output[2];
-
- input[0] = uaudio_mixer_get_input(iot, 0);
- input[1] = uaudio_mixer_get_input(iot, 1);
-
- output[0] = uaudio_mixer_get_output(iot, 0);
- output[1] = uaudio_mixer_get_output(iot, 1);
-
- /*
- * check if there is only
- * one output terminal:
- */
- if (output[0] && (!output[1])) {
- terminal_type = UGETW(output[0]->u.ot->wTerminalType);
- }
- /*
- * If the only output terminal is USB,
- * the class is UAC_RECORD.
- */
- if ((terminal_type & 0xff00) == (UAT_UNDEFINED & 0xff00)) {
-
- mix->class = UAC_RECORD;
- if (input[0] && (!input[1])) {
- terminal_type = UGETW(input[0]->u.it->wTerminalType);
- } else {
- terminal_type = 0;
- }
- goto done;
- }
- /*
- * if the unit is connected to just
- * one input terminal, the
- * class is UAC_INPUT:
- */
- if (input[0] && (!input[1])) {
- mix->class = UAC_INPUT;
- terminal_type = UGETW(input[0]->u.it->wTerminalType);
- goto done;
- }
- /*
- * Otherwise, the class is UAC_OUTPUT.
- */
- mix->class = UAC_OUTPUT;
-done:
- return (terminal_type);
-}
-
-struct uaudio_tt_to_feature {
- uint16_t terminal_type;
- uint16_t feature;
-};
-
-static const struct uaudio_tt_to_feature uaudio_tt_to_feature[] = {
-
- {UAT_STREAM, SOUND_MIXER_PCM},
-
- {UATI_MICROPHONE, SOUND_MIXER_MIC},
- {UATI_DESKMICROPHONE, SOUND_MIXER_MIC},
- {UATI_PERSONALMICROPHONE, SOUND_MIXER_MIC},
- {UATI_OMNIMICROPHONE, SOUND_MIXER_MIC},
- {UATI_MICROPHONEARRAY, SOUND_MIXER_MIC},
- {UATI_PROCMICROPHONEARR, SOUND_MIXER_MIC},
-
- {UATO_SPEAKER, SOUND_MIXER_SPEAKER},
- {UATO_DESKTOPSPEAKER, SOUND_MIXER_SPEAKER},
- {UATO_ROOMSPEAKER, SOUND_MIXER_SPEAKER},
- {UATO_COMMSPEAKER, SOUND_MIXER_SPEAKER},
-
- {UATE_ANALOGCONN, SOUND_MIXER_LINE},
- {UATE_LINECONN, SOUND_MIXER_LINE},
- {UATE_LEGACYCONN, SOUND_MIXER_LINE},
-
- {UATE_DIGITALAUIFC, SOUND_MIXER_ALTPCM},
- {UATE_SPDIF, SOUND_MIXER_ALTPCM},
- {UATE_1394DA, SOUND_MIXER_ALTPCM},
- {UATE_1394DV, SOUND_MIXER_ALTPCM},
-
- {UATF_CDPLAYER, SOUND_MIXER_CD},
-
- {UATF_SYNTHESIZER, SOUND_MIXER_SYNTH},
-
- {UATF_VIDEODISCAUDIO, SOUND_MIXER_VIDEO},
- {UATF_DVDAUDIO, SOUND_MIXER_VIDEO},
- {UATF_TVTUNERAUDIO, SOUND_MIXER_VIDEO},
-
- /* telephony terminal types */
- {UATT_UNDEFINED, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
- {UATT_PHONELINE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
- {UATT_TELEPHONE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
- {UATT_DOWNLINEPHONE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
-
- {UATF_RADIORECV, SOUND_MIXER_RADIO},
- {UATF_RADIOXMIT, SOUND_MIXER_RADIO},
-
- {UAT_UNDEFINED, SOUND_MIXER_VOLUME},
- {UAT_VENDOR, SOUND_MIXER_VOLUME},
- {UATI_UNDEFINED, SOUND_MIXER_VOLUME},
-
- /* output terminal types */
- {UATO_UNDEFINED, SOUND_MIXER_VOLUME},
- {UATO_DISPLAYAUDIO, SOUND_MIXER_VOLUME},
- {UATO_SUBWOOFER, SOUND_MIXER_VOLUME},
- {UATO_HEADPHONES, SOUND_MIXER_VOLUME},
-
- /* bidir terminal types */
- {UATB_UNDEFINED, SOUND_MIXER_VOLUME},
- {UATB_HANDSET, SOUND_MIXER_VOLUME},
- {UATB_HEADSET, SOUND_MIXER_VOLUME},
- {UATB_SPEAKERPHONE, SOUND_MIXER_VOLUME},
- {UATB_SPEAKERPHONEESUP, SOUND_MIXER_VOLUME},
- {UATB_SPEAKERPHONEECANC, SOUND_MIXER_VOLUME},
-
- /* external terminal types */
- {UATE_UNDEFINED, SOUND_MIXER_VOLUME},
-
- /* embedded function terminal types */
- {UATF_UNDEFINED, SOUND_MIXER_VOLUME},
- {UATF_CALIBNOISE, SOUND_MIXER_VOLUME},
- {UATF_EQUNOISE, SOUND_MIXER_VOLUME},
- {UATF_DAT, SOUND_MIXER_VOLUME},
- {UATF_DCC, SOUND_MIXER_VOLUME},
- {UATF_MINIDISK, SOUND_MIXER_VOLUME},
- {UATF_ANALOGTAPE, SOUND_MIXER_VOLUME},
- {UATF_PHONOGRAPH, SOUND_MIXER_VOLUME},
- {UATF_VCRAUDIO, SOUND_MIXER_VOLUME},
- {UATF_SATELLITE, SOUND_MIXER_VOLUME},
- {UATF_CABLETUNER, SOUND_MIXER_VOLUME},
- {UATF_DSS, SOUND_MIXER_VOLUME},
- {UATF_MULTITRACK, SOUND_MIXER_VOLUME},
- {0xffff, SOUND_MIXER_VOLUME},
-
- /* default */
- {0x0000, SOUND_MIXER_VOLUME},
-};
-
-static uint16_t
-uaudio_mixer_feature_name(const struct uaudio_terminal_node *iot,
- struct uaudio_mixer_node *mix)
-{
- const struct uaudio_tt_to_feature *uat = uaudio_tt_to_feature;
- uint16_t terminal_type = uaudio_mixer_determine_class(iot, mix);
-
- if ((mix->class == UAC_RECORD) && (terminal_type == 0)) {
- return (SOUND_MIXER_IMIX);
- }
- while (uat->terminal_type) {
- if (uat->terminal_type == terminal_type) {
- break;
- }
- uat++;
- }
-
- DPRINTF("terminal_type=%s (0x%04x) -> %d\n",
- uaudio_mixer_get_terminal_name(terminal_type),
- terminal_type, uat->feature);
-
- return (uat->feature);
-}
-
-const static struct uaudio_terminal_node *
-uaudio_mixer_get_input(const struct uaudio_terminal_node *iot, uint8_t index)
-{
- struct uaudio_terminal_node *root = iot->root;
- uint8_t n;
-
- n = iot->usr.id_max;
- do {
- if (iot->usr.bit_input[n / 8] & (1 << (n % 8))) {
- if (!index--) {
- return (root + n);
- }
- }
- } while (n--);
-
- return (NULL);
-}
-
-const static struct uaudio_terminal_node *
-uaudio_mixer_get_output(const struct uaudio_terminal_node *iot, uint8_t index)
-{
- struct uaudio_terminal_node *root = iot->root;
- uint8_t n;
-
- n = iot->usr.id_max;
- do {
- if (iot->usr.bit_output[n / 8] & (1 << (n % 8))) {
- if (!index--) {
- return (root + n);
- }
- }
- } while (n--);
-
- return (NULL);
-}
-
-static void
-uaudio_mixer_find_inputs_sub(struct uaudio_terminal_node *root,
- const uint8_t *p_id, uint8_t n_id,
- struct uaudio_search_result *info)
-{
- struct uaudio_terminal_node *iot;
- uint8_t n;
- uint8_t i;
-
- if (info->recurse_level >= UAUDIO_RECURSE_LIMIT) {
- return;
- }
- info->recurse_level++;
-
- for (n = 0; n < n_id; n++) {
-
- i = p_id[n];
-
- if (info->bit_visited[i / 8] & (1 << (i % 8))) {
- /* don't go into a circle */
- DPRINTF("avoided going into a circle at id=%d!\n", i);
- continue;
- } else {
- info->bit_visited[i / 8] |= (1 << (i % 8));
- }
-
- iot = (root + i);
-
- if (iot->u.desc == NULL) {
- continue;
- }
- switch (iot->u.desc->bDescriptorSubtype) {
- case UDESCSUB_AC_INPUT:
- info->bit_input[i / 8] |= (1 << (i % 8));
- break;
-
- case UDESCSUB_AC_FEATURE:
- uaudio_mixer_find_inputs_sub
- (root, &iot->u.fu->bSourceId, 1, info);
- break;
-
- case UDESCSUB_AC_OUTPUT:
- uaudio_mixer_find_inputs_sub
- (root, &iot->u.ot->bSourceId, 1, info);
- break;
-
- case UDESCSUB_AC_MIXER:
- uaudio_mixer_find_inputs_sub
- (root, iot->u.mu->baSourceId,
- iot->u.mu->bNrInPins, info);
- break;
-
- case UDESCSUB_AC_SELECTOR:
- uaudio_mixer_find_inputs_sub
- (root, iot->u.su->baSourceId,
- iot->u.su->bNrInPins, info);
- break;
-
- case UDESCSUB_AC_PROCESSING:
- uaudio_mixer_find_inputs_sub
- (root, iot->u.pu->baSourceId,
- iot->u.pu->bNrInPins, info);
- break;
-
- case UDESCSUB_AC_EXTENSION:
- uaudio_mixer_find_inputs_sub
- (root, iot->u.eu->baSourceId,
- iot->u.eu->bNrInPins, info);
- break;
-
- case UDESCSUB_AC_HEADER:
- default:
- break;
- }
- }
- info->recurse_level--;
-}
-
-static void
-uaudio_mixer_find_outputs_sub(struct uaudio_terminal_node *root, uint8_t id,
- uint8_t n_id, struct uaudio_search_result *info)
-{
- struct uaudio_terminal_node *iot = (root + id);
- uint8_t j;
-
- j = n_id;
- do {
- if ((j != id) && ((root + j)->u.desc) &&
- ((root + j)->u.desc->bDescriptorSubtype == UDESCSUB_AC_OUTPUT)) {
-
- /*
- * "j" (output) <--- virtual wire <--- "id" (input)
- *
- * if "j" has "id" on the input, then "id" have "j" on
- * the output, because they are connected:
- */
- if ((root + j)->usr.bit_input[id / 8] & (1 << (id % 8))) {
- iot->usr.bit_output[j / 8] |= (1 << (j % 8));
- }
- }
- } while (j--);
-}
-
-static void
-uaudio_mixer_fill_info(struct uaudio_softc *sc, struct usb2_device *udev,
- void *desc)
-{
- const struct usb2_audio_control_descriptor *acdp;
- struct usb2_config_descriptor *cd = usb2_get_config_descriptor(udev);
- const struct usb2_descriptor *dp;
- const struct usb2_audio_unit *au;
- struct uaudio_terminal_node *iot = NULL;
- uint16_t wTotalLen;
- uint8_t ID_max = 0; /* inclusive */
- uint8_t i;
-
- desc = usb2_desc_foreach(cd, desc);
-
- if (desc == NULL) {
- DPRINTF("no Audio Control header\n");
- goto done;
- }
- acdp = desc;
-
- if ((acdp->bLength < sizeof(*acdp)) ||
- (acdp->bDescriptorType != UDESC_CS_INTERFACE) ||
- (acdp->bDescriptorSubtype != UDESCSUB_AC_HEADER)) {
- DPRINTF("invalid Audio Control header\n");
- goto done;
- }
- /* "wTotalLen" is allowed to be corrupt */
- wTotalLen = UGETW(acdp->wTotalLength) - acdp->bLength;
-
- /* get USB audio revision */
- sc->sc_audio_rev = UGETW(acdp->bcdADC);
-
- DPRINTFN(3, "found AC header, vers=%03x, len=%d\n",
- sc->sc_audio_rev, wTotalLen);
-
- if (sc->sc_audio_rev != UAUDIO_VERSION) {
-
- if (sc->sc_uq_bad_adc) {
-
- } else {
- DPRINTF("invalid audio version\n");
- goto done;
- }
- }
- iot = malloc(sizeof(struct uaudio_terminal_node) * 256, M_TEMP,
- M_WAITOK | M_ZERO);
-
- if (iot == NULL) {
- DPRINTF("no memory!\n");
- goto done;
- }
- while ((desc = usb2_desc_foreach(cd, desc))) {
-
- dp = desc;
-
- if (dp->bLength > wTotalLen) {
- break;
- } else {
- wTotalLen -= dp->bLength;
- }
-
- au = uaudio_mixer_verify_desc(dp, 0);
-
- if (au) {
- iot[au->bUnitId].u.desc = (const void *)au;
- if (au->bUnitId > ID_max) {
- ID_max = au->bUnitId;
- }
- }
- }
-
- DPRINTF("Maximum ID=%d\n", ID_max);
-
- /*
- * determine sourcing inputs for
- * all nodes in the tree:
- */
- i = ID_max;
- do {
- uaudio_mixer_find_inputs_sub(iot, &i, 1, &((iot + i)->usr));
- } while (i--);
-
- /*
- * determine outputs for
- * all nodes in the tree:
- */
- i = ID_max;
- do {
- uaudio_mixer_find_outputs_sub(iot, i, ID_max, &((iot + i)->usr));
- } while (i--);
-
- /* set "id_max" and "root" */
-
- i = ID_max;
- do {
- (iot + i)->usr.id_max = ID_max;
- (iot + i)->root = iot;
- } while (i--);
-
-#if USB_DEBUG
- i = ID_max;
- do {
- uint8_t j;
-
- if (iot[i].u.desc == NULL) {
- continue;
- }
- DPRINTF("id %d:\n", i);
-
- switch (iot[i].u.desc->bDescriptorSubtype) {
- case UDESCSUB_AC_INPUT:
- DPRINTF(" - AC_INPUT type=%s\n",
- uaudio_mixer_get_terminal_name
- (UGETW(iot[i].u.it->wTerminalType)));
- uaudio_mixer_dump_cluster(i, iot);
- break;
-
- case UDESCSUB_AC_OUTPUT:
- DPRINTF(" - AC_OUTPUT type=%s "
- "src=%d\n", uaudio_mixer_get_terminal_name
- (UGETW(iot[i].u.ot->wTerminalType)),
- iot[i].u.ot->bSourceId);
- break;
-
- case UDESCSUB_AC_MIXER:
- DPRINTF(" - AC_MIXER src:\n");
- for (j = 0; j < iot[i].u.mu->bNrInPins; j++) {
- DPRINTF(" - %d\n", iot[i].u.mu->baSourceId[j]);
- }
- uaudio_mixer_dump_cluster(i, iot);
- break;
-
- case UDESCSUB_AC_SELECTOR:
- DPRINTF(" - AC_SELECTOR src:\n");
- for (j = 0; j < iot[i].u.su->bNrInPins; j++) {
- DPRINTF(" - %d\n", iot[i].u.su->baSourceId[j]);
- }
- break;
-
- case UDESCSUB_AC_FEATURE:
- DPRINTF(" - AC_FEATURE src=%d\n", iot[i].u.fu->bSourceId);
- break;
-
- case UDESCSUB_AC_PROCESSING:
- DPRINTF(" - AC_PROCESSING src:\n");
- for (j = 0; j < iot[i].u.pu->bNrInPins; j++) {
- DPRINTF(" - %d\n", iot[i].u.pu->baSourceId[j]);
- }
- uaudio_mixer_dump_cluster(i, iot);
- break;
-
- case UDESCSUB_AC_EXTENSION:
- DPRINTF(" - AC_EXTENSION src:\n");
- for (j = 0; j < iot[i].u.eu->bNrInPins; j++) {
- DPRINTF("%d ", iot[i].u.eu->baSourceId[j]);
- }
- uaudio_mixer_dump_cluster(i, iot);
- break;
-
- default:
- DPRINTF("unknown audio control (subtype=%d)\n",
- iot[i].u.desc->bDescriptorSubtype);
- }
-
- DPRINTF("Inputs to this ID are:\n");
-
- j = ID_max;
- do {
- if (iot[i].usr.bit_input[j / 8] & (1 << (j % 8))) {
- DPRINTF(" -- ID=%d\n", j);
- }
- } while (j--);
-
- DPRINTF("Outputs from this ID are:\n");
-
- j = ID_max;
- do {
- if (iot[i].usr.bit_output[j / 8] & (1 << (j % 8))) {
- DPRINTF(" -- ID=%d\n", j);
- }
- } while (j--);
-
- } while (i--);
-#endif
-
- /*
- * scan the config to create a linked
- * list of "mixer" nodes:
- */
-
- i = ID_max;
- do {
- dp = iot[i].u.desc;
-
- if (dp == NULL) {
- continue;
- }
- DPRINTFN(11, "id=%d subtype=%d\n",
- i, dp->bDescriptorSubtype);
-
- switch (dp->bDescriptorSubtype) {
- case UDESCSUB_AC_HEADER:
- DPRINTF("unexpected AC header\n");
- break;
-
- case UDESCSUB_AC_INPUT:
- uaudio_mixer_add_input(sc, iot, i);
- break;
-
- case UDESCSUB_AC_OUTPUT:
- uaudio_mixer_add_output(sc, iot, i);
- break;
-
- case UDESCSUB_AC_MIXER:
- uaudio_mixer_add_mixer(sc, iot, i);
- break;
-
- case UDESCSUB_AC_SELECTOR:
- uaudio_mixer_add_selector(sc, iot, i);
- break;
-
- case UDESCSUB_AC_FEATURE:
- uaudio_mixer_add_feature(sc, iot, i);
- break;
-
- case UDESCSUB_AC_PROCESSING:
- uaudio_mixer_add_processing(sc, iot, i);
- break;
-
- case UDESCSUB_AC_EXTENSION:
- uaudio_mixer_add_extension(sc, iot, i);
- break;
-
- default:
- DPRINTF("bad AC desc subtype=0x%02x\n",
- dp->bDescriptorSubtype);
- break;
- }
-
- } while (i--);
-
-done:
- if (iot) {
- free(iot, M_TEMP);
- }
-}
-
-static uint16_t
-uaudio_mixer_get(struct usb2_device *udev, uint8_t what,
- struct uaudio_mixer_node *mc)
-{
- struct usb2_device_request req;
- uint16_t val;
- uint16_t len = MIX_SIZE(mc->type);
- uint8_t data[4];
- usb2_error_t err;
-
- if (mc->wValue[0] == -1) {
- return (0);
- }
- req.bmRequestType = UT_READ_CLASS_INTERFACE;
- req.bRequest = what;
- USETW(req.wValue, mc->wValue[0]);
- USETW(req.wIndex, mc->wIndex);
- USETW(req.wLength, len);
-
- err = usb2_do_request(udev, &Giant, &req, data);
- if (err) {
- DPRINTF("err=%s\n", usb2_errstr(err));
- return (0);
- }
- if (len < 1) {
- data[0] = 0;
- }
- if (len < 2) {
- data[1] = 0;
- }
- val = (data[0] | (data[1] << 8));
-
- DPRINTFN(3, "val=%d\n", val);
-
- return (val);
-}
-
-static void
-uaudio_mixer_write_cfg_callback(struct usb2_xfer *xfer)
-{
- struct usb2_device_request req;
- struct uaudio_softc *sc = xfer->priv_sc;
- struct uaudio_mixer_node *mc = sc->sc_mixer_curr;
- uint16_t len;
- uint8_t repeat = 1;
- uint8_t update;
- uint8_t chan;
- uint8_t buf[2];
-
- DPRINTF("\n");
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-tr_transferred:
- case USB_ST_SETUP:
-tr_setup:
-
- if (mc == NULL) {
- mc = sc->sc_mixer_root;
- sc->sc_mixer_curr = mc;
- sc->sc_mixer_chan = 0;
- repeat = 0;
- }
- while (mc) {
- while (sc->sc_mixer_chan < mc->nchan) {
-
- len = MIX_SIZE(mc->type);
-
- chan = sc->sc_mixer_chan;
-
- sc->sc_mixer_chan++;
-
- update = ((mc->update[chan / 8] & (1 << (chan % 8))) &&
- (mc->wValue[chan] != -1));
-
- mc->update[chan / 8] &= ~(1 << (chan % 8));
-
- if (update) {
-
- req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
- req.bRequest = SET_CUR;
- USETW(req.wValue, mc->wValue[chan]);
- USETW(req.wIndex, mc->wIndex);
- USETW(req.wLength, len);
-
- if (len > 0) {
- buf[0] = (mc->wData[chan] & 0xFF);
- }
- if (len > 1) {
- buf[1] = (mc->wData[chan] >> 8) & 0xFF;
- }
- usb2_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
- usb2_copy_in(xfer->frbuffers + 1, 0, buf, len);
-
- xfer->frlengths[0] = sizeof(req);
- xfer->frlengths[1] = len;
- xfer->nframes = xfer->frlengths[1] ? 2 : 1;
- usb2_start_hardware(xfer);
- return;
- }
- }
-
- mc = mc->next;
- sc->sc_mixer_curr = mc;
- sc->sc_mixer_chan = 0;
- }
-
- if (repeat) {
- goto tr_setup;
- }
- break;
-
- default: /* Error */
- DPRINTF("error=%s\n", usb2_errstr(xfer->error));
- if (xfer->error == USB_ERR_CANCELLED) {
- /* do nothing - we are detaching */
- break;
- }
- goto tr_transferred;
- }
-}
-
-static usb2_error_t
-uaudio_set_speed(struct usb2_device *udev, uint8_t endpt, uint32_t speed)
-{
- struct usb2_device_request req;
- uint8_t data[3];
-
- DPRINTFN(6, "endpt=%d speed=%u\n", endpt, speed);
-
- req.bmRequestType = UT_WRITE_CLASS_ENDPOINT;
- req.bRequest = SET_CUR;
- USETW2(req.wValue, SAMPLING_FREQ_CONTROL, 0);
- USETW(req.wIndex, endpt);
- USETW(req.wLength, 3);
- data[0] = speed;
- data[1] = speed >> 8;
- data[2] = speed >> 16;
-
- return (usb2_do_request(udev, &Giant, &req, data));
-}
-
-static int
-uaudio_mixer_signext(uint8_t type, int val)
-{
- if (!MIX_UNSIGNED(type)) {
- if (MIX_SIZE(type) == 2) {
- val = (int16_t)val;
- } else {
- val = (int8_t)val;
- }
- }
- return (val);
-}
-
-static int
-uaudio_mixer_bsd2value(struct uaudio_mixer_node *mc, int32_t val)
-{
- if (mc->type == MIX_ON_OFF) {
- val = (val != 0);
- } else if (mc->type == MIX_SELECTOR) {
- if ((val < mc->minval) ||
- (val > mc->maxval)) {
- val = mc->minval;
- }
- } else {
- val = (((val + (mc->delta / 2)) * mc->mul) / 255) + mc->minval;
- }
-
- DPRINTFN(6, "type=0x%03x val=%d min=%d max=%d val=%d\n",
- mc->type, val, mc->minval, mc->maxval, val);
- return (val);
-}
-
-static void
-uaudio_mixer_ctl_set(struct uaudio_softc *sc, struct uaudio_mixer_node *mc,
- uint8_t chan, int32_t val)
-{
- val = uaudio_mixer_bsd2value(mc, val);
-
- mc->update[chan / 8] |= (1 << (chan % 8));
- mc->wData[chan] = val;
-
- /* start the transfer, if not already started */
-
- usb2_transfer_start(sc->sc_mixer_xfer[0]);
-}
-
-static void
-uaudio_mixer_init(struct uaudio_softc *sc)
-{
- struct uaudio_mixer_node *mc;
- int32_t i;
-
- for (mc = sc->sc_mixer_root; mc;
- mc = mc->next) {
-
- if (mc->ctl != SOUND_MIXER_NRDEVICES) {
- /*
- * Set device mask bits. See
- * /usr/include/machine/soundcard.h
- */
- sc->sc_mix_info |= (1 << mc->ctl);
- }
- if ((mc->ctl == SOUND_MIXER_NRDEVICES) &&
- (mc->type == MIX_SELECTOR)) {
-
- for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
- if (mc->slctrtype[i - 1] == SOUND_MIXER_NRDEVICES) {
- continue;
- }
- sc->sc_recsrc_info |= 1 << mc->slctrtype[i - 1];
- }
- }
- }
-}
-
-int
-uaudio_mixer_init_sub(struct uaudio_softc *sc, struct snd_mixer *m)
-{
- DPRINTF("\n");
-
- if (usb2_transfer_setup(sc->sc_udev, &sc->sc_mixer_iface_index,
- sc->sc_mixer_xfer, uaudio_mixer_config, 1, sc,
- mixer_get_lock(m))) {
- DPRINTFN(0, "could not allocate USB "
- "transfer for audio mixer!\n");
- return (ENOMEM);
- }
- if (!(sc->sc_mix_info & SOUND_MASK_VOLUME)) {
- mix_setparentchild(m, SOUND_MIXER_VOLUME, SOUND_MASK_PCM);
- mix_setrealdev(m, SOUND_MIXER_VOLUME, SOUND_MIXER_NONE);
- }
- mix_setdevs(m, sc->sc_mix_info);
- mix_setrecdevs(m, sc->sc_recsrc_info);
- return (0);
-}
-
-int
-uaudio_mixer_uninit_sub(struct uaudio_softc *sc)
-{
- DPRINTF("\n");
-
- usb2_transfer_unsetup(sc->sc_mixer_xfer, 1);
-
- return (0);
-}
-
-void
-uaudio_mixer_set(struct uaudio_softc *sc, unsigned type,
- unsigned left, unsigned right)
-{
- struct uaudio_mixer_node *mc;
-
- for (mc = sc->sc_mixer_root; mc;
- mc = mc->next) {
-
- if (mc->ctl == type) {
- if (mc->nchan == 2) {
- /* set Right */
- uaudio_mixer_ctl_set(sc, mc, 1, (int)(right * 255) / 100);
- }
- /* set Left or Mono */
- uaudio_mixer_ctl_set(sc, mc, 0, (int)(left * 255) / 100);
- }
- }
-}
-
-uint32_t
-uaudio_mixer_setrecsrc(struct uaudio_softc *sc, uint32_t src)
-{
- struct uaudio_mixer_node *mc;
- uint32_t mask;
- uint32_t temp;
- int32_t i;
-
- for (mc = sc->sc_mixer_root; mc;
- mc = mc->next) {
-
- if ((mc->ctl == SOUND_MIXER_NRDEVICES) &&
- (mc->type == MIX_SELECTOR)) {
-
- /* compute selector mask */
-
- mask = 0;
- for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
- mask |= (1 << mc->slctrtype[i - 1]);
- }
-
- temp = mask & src;
- if (temp == 0) {
- continue;
- }
- /* find the first set bit */
- temp = (-temp) & temp;
-
- /* update "src" */
- src &= ~mask;
- src |= temp;
-
- for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
- if (temp != (1 << mc->slctrtype[i - 1])) {
- continue;
- }
- uaudio_mixer_ctl_set(sc, mc, 0, i);
- break;
- }
- }
- }
- return (src);
-}
-
-/*========================================================================*
- * MIDI support routines
- *========================================================================*/
-
-static void
-umidi_read_clear_stall_callback(struct usb2_xfer *xfer)
-{
- struct umidi_chan *chan = xfer->priv_sc;
- struct usb2_xfer *xfer_other = chan->xfer[1];
-
- if (usb2_clear_stall_callback(xfer, xfer_other)) {
- DPRINTF("stall cleared\n");
- chan->flags &= ~UMIDI_FLAG_READ_STALL;
- usb2_transfer_start(xfer_other);
- }
-}
-
-static void
-umidi_bulk_read_callback(struct usb2_xfer *xfer)
-{
- struct umidi_chan *chan = xfer->priv_sc;
- struct umidi_sub_chan *sub;
- uint8_t buf[1];
- uint8_t cmd_len;
- uint8_t cn;
- uint16_t pos;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-
- DPRINTF("actlen=%d bytes\n", xfer->actlen);
-
- if (xfer->actlen == 0) {
- /* should not happen */
- goto tr_error;
- }
- pos = 0;
-
- while (xfer->actlen >= 4) {
-
- usb2_copy_out(xfer->frbuffers, pos, buf, 1);
-
- cmd_len = umidi_cmd_to_len[buf[0] & 0xF]; /* command length */
- cn = buf[0] >> 4; /* cable number */
- sub = &chan->sub[cn];
-
- if (cmd_len && (cn < chan->max_cable) && sub->read_open) {
- usb2_fifo_put_data(sub->fifo.fp[USB_FIFO_RX], xfer->frbuffers,
- pos + 1, cmd_len, 1);
- } else {
- /* ignore the command */
- }
-
- xfer->actlen -= 4;
- pos += 4;
- }
-
- case USB_ST_SETUP:
- DPRINTF("start\n");
-
- if (chan->flags & UMIDI_FLAG_READ_STALL) {
- usb2_transfer_start(chan->xfer[3]);
- return;
- }
- xfer->frlengths[0] = xfer->max_data_length;
- usb2_start_hardware(xfer);
- return;
-
- default:
-tr_error:
-
- DPRINTF("error=%s\n", usb2_errstr(xfer->error));
-
- if (xfer->error != USB_ERR_CANCELLED) {
- /* try to clear stall first */
- chan->flags |= UMIDI_FLAG_READ_STALL;
- usb2_transfer_start(chan->xfer[3]);
- }
- return;
-
- }
-}
-
-static void
-umidi_write_clear_stall_callback(struct usb2_xfer *xfer)
-{
- struct umidi_chan *chan = xfer->priv_sc;
- struct usb2_xfer *xfer_other = chan->xfer[0];
-
- if (usb2_clear_stall_callback(xfer, xfer_other)) {
- DPRINTF("stall cleared\n");
- chan->flags &= ~UMIDI_FLAG_WRITE_STALL;
- usb2_transfer_start(xfer_other);
- }
-}
-
-/*
- * The following statemachine, that converts MIDI commands to
- * USB MIDI packets, derives from Linux's usbmidi.c, which
- * was written by "Clemens Ladisch":
- *
- * Returns:
- * 0: No command
- * Else: Command is complete
- */
-static uint8_t
-umidi_convert_to_usb(struct umidi_sub_chan *sub, uint8_t cn, uint8_t b)
-{
- uint8_t p0 = (cn << 4);
-
- if (b >= 0xf8) {
- sub->temp_0[0] = p0 | 0x0f;
- sub->temp_0[1] = b;
- sub->temp_0[2] = 0;
- sub->temp_0[3] = 0;
- sub->temp_cmd = sub->temp_0;
- return (1);
-
- } else if (b >= 0xf0) {
- switch (b) {
- case 0xf0: /* system exclusive begin */
- sub->temp_1[1] = b;
- sub->state = UMIDI_ST_SYSEX_1;
- break;
- case 0xf1: /* MIDI time code */
- case 0xf3: /* song select */
- sub->temp_1[1] = b;
- sub->state = UMIDI_ST_1PARAM;
- break;
- case 0xf2: /* song position pointer */
- sub->temp_1[1] = b;
- sub->state = UMIDI_ST_2PARAM_1;
- break;
- case 0xf4: /* unknown */
- case 0xf5: /* unknown */
- sub->state = UMIDI_ST_UNKNOWN;
- break;
- case 0xf6: /* tune request */
- sub->temp_1[0] = p0 | 0x05;
- sub->temp_1[1] = 0xf6;
- sub->temp_1[2] = 0;
- sub->temp_1[3] = 0;
- sub->temp_cmd = sub->temp_1;
- sub->state = UMIDI_ST_UNKNOWN;
- return (1);
-
- case 0xf7: /* system exclusive end */
- switch (sub->state) {
- case UMIDI_ST_SYSEX_0:
- sub->temp_1[0] = p0 | 0x05;
- sub->temp_1[1] = 0xf7;
- sub->temp_1[2] = 0;
- sub->temp_1[3] = 0;
- sub->temp_cmd = sub->temp_1;
- sub->state = UMIDI_ST_UNKNOWN;
- return (1);
- case UMIDI_ST_SYSEX_1:
- sub->temp_1[0] = p0 | 0x06;
- sub->temp_1[2] = 0xf7;
- sub->temp_1[3] = 0;
- sub->temp_cmd = sub->temp_1;
- sub->state = UMIDI_ST_UNKNOWN;
- return (1);
- case UMIDI_ST_SYSEX_2:
- sub->temp_1[0] = p0 | 0x07;
- sub->temp_1[3] = 0xf7;
- sub->temp_cmd = sub->temp_1;
- sub->state = UMIDI_ST_UNKNOWN;
- return (1);
- }
- sub->state = UMIDI_ST_UNKNOWN;
- break;
- }
- } else if (b >= 0x80) {
- sub->temp_1[1] = b;
- if ((b >= 0xc0) && (b <= 0xdf)) {
- sub->state = UMIDI_ST_1PARAM;
- } else {
- sub->state = UMIDI_ST_2PARAM_1;
- }
- } else { /* b < 0x80 */
- switch (sub->state) {
- case UMIDI_ST_1PARAM:
- if (sub->temp_1[1] < 0xf0) {
- p0 |= sub->temp_1[1] >> 4;
- } else {
- p0 |= 0x02;
- sub->state = UMIDI_ST_UNKNOWN;
- }
- sub->temp_1[0] = p0;
- sub->temp_1[2] = b;
- sub->temp_1[3] = 0;
- sub->temp_cmd = sub->temp_1;
- return (1);
- case UMIDI_ST_2PARAM_1:
- sub->temp_1[2] = b;
- sub->state = UMIDI_ST_2PARAM_2;
- break;
- case UMIDI_ST_2PARAM_2:
- if (sub->temp_1[1] < 0xf0) {
- p0 |= sub->temp_1[1] >> 4;
- sub->state = UMIDI_ST_2PARAM_1;
- } else {
- p0 |= 0x03;
- sub->state = UMIDI_ST_UNKNOWN;
- }
- sub->temp_1[0] = p0;
- sub->temp_1[3] = b;
- sub->temp_cmd = sub->temp_1;
- return (1);
- case UMIDI_ST_SYSEX_0:
- sub->temp_1[1] = b;
- sub->state = UMIDI_ST_SYSEX_1;
- break;
- case UMIDI_ST_SYSEX_1:
- sub->temp_1[2] = b;
- sub->state = UMIDI_ST_SYSEX_2;
- break;
- case UMIDI_ST_SYSEX_2:
- sub->temp_1[0] = p0 | 0x04;
- sub->temp_1[3] = b;
- sub->temp_cmd = sub->temp_1;
- sub->state = UMIDI_ST_SYSEX_0;
- return (1);
- }
- }
- return (0);
-}
-
-static void
-umidi_bulk_write_callback(struct usb2_xfer *xfer)
-{
- struct umidi_chan *chan = xfer->priv_sc;
- struct umidi_sub_chan *sub;
- uint32_t actlen;
- uint16_t total_length;
- uint8_t buf;
- uint8_t start_cable;
- uint8_t tr_any;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
- DPRINTF("actlen=%d bytes\n", xfer->actlen);
-
- case USB_ST_SETUP:
-
- DPRINTF("start\n");
-
- if (chan->flags & UMIDI_FLAG_WRITE_STALL) {
- usb2_transfer_start(chan->xfer[2]);
- return;
- }
- total_length = 0; /* reset */
-
- start_cable = chan->curr_cable;
-
- tr_any = 0;
-
- while (1) {
-
- /* round robin de-queueing */
-
- sub = &chan->sub[chan->curr_cable];
-
- if (sub->write_open) {
- usb2_fifo_get_data(sub->fifo.fp[USB_FIFO_TX],
- xfer->frbuffers, total_length,
- 1, &actlen, 0);
- } else {
- actlen = 0;
- }
-
- if (actlen) {
- usb2_copy_out(xfer->frbuffers, total_length, &buf, 1);
-
- tr_any = 1;
-
- DPRINTF("byte=0x%02x\n", buf);
-
- if (umidi_convert_to_usb(sub, chan->curr_cable, buf)) {
-
- DPRINTF("sub= %02x %02x %02x %02x\n",
- sub->temp_cmd[0], sub->temp_cmd[1],
- sub->temp_cmd[2], sub->temp_cmd[3]);
-
- usb2_copy_in(xfer->frbuffers, total_length,
- sub->temp_cmd, 4);
-
- total_length += 4;
-
- if (total_length >= UMIDI_BULK_SIZE) {
- break;
- }
- } else {
- continue;
- }
- }
- chan->curr_cable++;
- if (chan->curr_cable >= chan->max_cable) {
- chan->curr_cable = 0;
- }
- if (chan->curr_cable == start_cable) {
- if (tr_any == 0) {
- break;
- }
- tr_any = 0;
- }
- }
-
- if (total_length) {
- xfer->frlengths[0] = total_length;
- usb2_start_hardware(xfer);
- }
- return;
-
- default: /* Error */
-
- DPRINTF("error=%s\n", usb2_errstr(xfer->error));
-
- if (xfer->error != USB_ERR_CANCELLED) {
- /* try to clear stall first */
- chan->flags |= UMIDI_FLAG_WRITE_STALL;
- usb2_transfer_start(chan->xfer[2]);
- }
- return;
-
- }
-}
-
-static struct umidi_sub_chan *
-umidi_sub_by_fifo(struct usb2_fifo *fifo)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
- struct umidi_sub_chan *sub;
- uint32_t n;
-
- for (n = 0; n < UMIDI_CABLES_MAX; n++) {
- sub = &chan->sub[n];
- if ((sub->fifo.fp[USB_FIFO_RX] == fifo) ||
- (sub->fifo.fp[USB_FIFO_TX] == fifo)) {
- return (sub);
- }
- }
-
- panic("%s:%d cannot find usb2_fifo!\n",
- __FILE__, __LINE__);
-
- return (NULL);
-}
-
-static void
-umidi_start_read(struct usb2_fifo *fifo)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
-
- usb2_transfer_start(chan->xfer[1]);
-}
-
-static void
-umidi_stop_read(struct usb2_fifo *fifo)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
- struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
-
- DPRINTF("\n");
-
- sub->read_open = 0;
-
- if (--(chan->read_open_refcount) == 0) {
- /*
- * XXX don't stop the read transfer here, hence that causes
- * problems with some MIDI adapters
- */
- DPRINTF("(stopping read transfer)\n");
- }
-}
-
-static void
-umidi_start_write(struct usb2_fifo *fifo)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
-
- usb2_transfer_start(chan->xfer[0]);
-}
-
-static void
-umidi_stop_write(struct usb2_fifo *fifo)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
- struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
-
- DPRINTF("\n");
-
- sub->write_open = 0;
-
- if (--(chan->write_open_refcount) == 0) {
- DPRINTF("(stopping write transfer)\n");
- usb2_transfer_stop(chan->xfer[2]);
- usb2_transfer_stop(chan->xfer[0]);
- }
-}
-
-static int
-umidi_open(struct usb2_fifo *fifo, int fflags, struct thread *td)
-{
- struct umidi_chan *chan = fifo->priv_sc0;
- struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
-
- if (fflags & FREAD) {
- if (usb2_fifo_alloc_buffer(fifo, 4, (1024 / 4))) {
- return (ENOMEM);
- }
- mtx_lock(fifo->priv_mtx);
- chan->read_open_refcount++;
- sub->read_open = 1;
- mtx_unlock(fifo->priv_mtx);
- }
- if (fflags & FWRITE) {
- if (usb2_fifo_alloc_buffer(fifo, 32, (1024 / 32))) {
- return (ENOMEM);
- }
- /* clear stall first */
- mtx_lock(fifo->priv_mtx);
- chan->flags |= UMIDI_FLAG_WRITE_STALL;
- chan->write_open_refcount++;
- sub->write_open = 1;
-
- /* reset */
- sub->state = UMIDI_ST_UNKNOWN;
- mtx_unlock(fifo->priv_mtx);
- }
- return (0); /* success */
-}
-
-static void
-umidi_close(struct usb2_fifo *fifo, int fflags, struct thread *td)
-{
- if (fflags & FREAD) {
- usb2_fifo_free_buffer(fifo);
- }
- if (fflags & FWRITE) {
- usb2_fifo_free_buffer(fifo);
- }
-}
-
-
-static int
-umidi_ioctl(struct usb2_fifo *fifo, u_long cmd, void *data,
- int fflags, struct thread *td)
-{
- return (ENODEV);
-}
-
-static void
-umidi_init(device_t dev)
-{
- struct uaudio_softc *sc = device_get_softc(dev);
- struct umidi_chan *chan = &sc->sc_midi_chan;
-
- mtx_init(&chan->mtx, "umidi lock", NULL, MTX_DEF | MTX_RECURSE);
-}
-
-static struct usb2_fifo_methods umidi_fifo_methods = {
- .f_start_read = &umidi_start_read,
- .f_start_write = &umidi_start_write,
- .f_stop_read = &umidi_stop_read,
- .f_stop_write = &umidi_stop_write,
- .f_open = &umidi_open,
- .f_close = &umidi_close,
- .f_ioctl = &umidi_ioctl,
- .basename[0] = "umidi",
-};
-
-static int32_t
-umidi_probe(device_t dev)
-{
- struct uaudio_softc *sc = device_get_softc(dev);
- struct usb2_attach_arg *uaa = device_get_ivars(dev);
- struct umidi_chan *chan = &sc->sc_midi_chan;
- struct umidi_sub_chan *sub;
- int unit = device_get_unit(dev);
- int error;
- uint32_t n;
-
- if (usb2_set_alt_interface_index(sc->sc_udev, chan->iface_index,
- chan->iface_alt_index)) {
- DPRINTF("setting of alternate index failed!\n");
- goto detach;
- }
- usb2_set_parent_iface(sc->sc_udev, chan->iface_index, sc->sc_mixer_iface_index);
-
- error = usb2_transfer_setup(uaa->device, &chan->iface_index,
- chan->xfer, umidi_config, UMIDI_N_TRANSFER,
- chan, &chan->mtx);
- if (error) {
- DPRINTF("error=%s\n", usb2_errstr(error));
- goto detach;
- }
- if ((chan->max_cable > UMIDI_CABLES_MAX) ||
- (chan->max_cable == 0)) {
- chan->max_cable = UMIDI_CABLES_MAX;
- }
- /* set interface permissions */
- usb2_set_iface_perm(sc->sc_udev, chan->iface_index,
- UID_ROOT, GID_OPERATOR, 0644);
-
- for (n = 0; n < chan->max_cable; n++) {
-
- sub = &chan->sub[n];
-
- error = usb2_fifo_attach(sc->sc_udev, chan, &chan->mtx,
- &umidi_fifo_methods, &sub->fifo, unit, n,
- chan->iface_index);
- if (error) {
- goto detach;
- }
- }
-
- mtx_lock(&chan->mtx);
-
- /* clear stall first */
- chan->flags |= UMIDI_FLAG_READ_STALL;
-
- /*
- * NOTE: at least one device will not work properly unless
- * the BULK pipe is open all the time.
- */
- usb2_transfer_start(chan->xfer[1]);
-
- mtx_unlock(&chan->mtx);
-
- return (0); /* success */
-
-detach:
- return (ENXIO); /* failure */
-}
-
-static int32_t
-umidi_detach(device_t dev)
-{
- struct uaudio_softc *sc = device_get_softc(dev);
- struct umidi_chan *chan = &sc->sc_midi_chan;
- uint32_t n;
-
- for (n = 0; n < UMIDI_CABLES_MAX; n++) {
- usb2_fifo_detach(&chan->sub[n].fifo);
- }
-
- mtx_lock(&chan->mtx);
-
- usb2_transfer_stop(chan->xfer[3]);
- usb2_transfer_stop(chan->xfer[1]);
-
- mtx_unlock(&chan->mtx);
-
- usb2_transfer_unsetup(chan->xfer, UMIDI_N_TRANSFER);
-
- mtx_destroy(&chan->mtx);
-
- return (0);
-}
-
-DRIVER_MODULE(uaudio, ushub, uaudio_driver, uaudio_devclass, NULL, 0);
-MODULE_DEPEND(uaudio, usb, 1, 1, 1);
-MODULE_DEPEND(uaudio, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
-MODULE_VERSION(uaudio, 1);
diff --git a/sys/dev/usb/sound/uaudio.h b/sys/dev/usb/sound/uaudio.h
deleted file mode 100644
index e763c6d..0000000
--- a/sys/dev/usb/sound/uaudio.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 2000-2002 Hiroyuki Aizu <aizu@navi.org>
- *
- * 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 AUTHOR 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 AUTHOR 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.
- */
-
-/* prototypes from "uaudio.c" used by "uaudio_pcm.c" */
-
-struct uaudio_chan;
-struct uaudio_softc;
-struct snd_dbuf;
-struct snd_mixer;
-struct pcm_channel;
-
-extern int uaudio_attach_sub(device_t dev, kobj_class_t mixer_class,
- kobj_class_t chan_class);
-extern int uaudio_detach_sub(device_t dev);
-extern void *uaudio_chan_init(struct uaudio_softc *sc, struct snd_dbuf *b,
- struct pcm_channel *c, int dir);
-extern int uaudio_chan_free(struct uaudio_chan *ch);
-extern int uaudio_chan_set_param_blocksize(struct uaudio_chan *ch,
- uint32_t blocksize);
-extern int uaudio_chan_set_param_fragments(struct uaudio_chan *ch,
- uint32_t blocksize, uint32_t blockcount);
-extern int uaudio_chan_set_param_speed(struct uaudio_chan *ch,
- uint32_t speed);
-extern int uaudio_chan_getptr(struct uaudio_chan *ch);
-extern struct pcmchan_caps *uaudio_chan_getcaps(struct uaudio_chan *ch);
-extern int uaudio_chan_set_param_format(struct uaudio_chan *ch,
- uint32_t format);
-extern int uaudio_chan_start(struct uaudio_chan *ch);
-extern int uaudio_chan_stop(struct uaudio_chan *ch);
-extern int uaudio_mixer_init_sub(struct uaudio_softc *sc,
- struct snd_mixer *m);
-extern int uaudio_mixer_uninit_sub(struct uaudio_softc *sc);
-extern void uaudio_mixer_set(struct uaudio_softc *sc, unsigned type,
- unsigned left, unsigned right);
-extern uint32_t uaudio_mixer_setrecsrc(struct uaudio_softc *sc, uint32_t src);
-
-int uaudio_get_vendor(device_t dev);
-int uaudio_get_product(device_t dev);
-int uaudio_get_release(device_t dev);
diff --git a/sys/dev/usb/sound/uaudio_pcm.c b/sys/dev/usb/sound/uaudio_pcm.c
deleted file mode 100644
index a9d3a48..0000000
--- a/sys/dev/usb/sound/uaudio_pcm.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 2000-2002 Hiroyuki Aizu <aizu@navi.org>
- * Copyright (c) 2006 Hans Petter Selasky
- *
- * 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 AUTHOR 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 AUTHOR 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/soundcard.h>
-#include <dev/sound/pcm/sound.h>
-#include <dev/sound/chip.h>
-
-#include <dev/usb/sound/uaudio.h>
-
-#include "mixer_if.h"
-
-/************************************************************/
-static void *
-ua_chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b, struct pcm_channel *c, int dir)
-{
- return (uaudio_chan_init(devinfo, b, c, dir));
-}
-
-static int
-ua_chan_free(kobj_t obj, void *data)
-{
- return (uaudio_chan_free(data));
-}
-
-static int
-ua_chan_setformat(kobj_t obj, void *data, uint32_t format)
-{
- /*
- * At this point, no need to query as we
- * shouldn't select an unsorted format
- */
- return (uaudio_chan_set_param_format(data, format));
-}
-
-static int
-ua_chan_setspeed(kobj_t obj, void *data, uint32_t speed)
-{
- return (uaudio_chan_set_param_speed(data, speed));
-}
-
-static int
-ua_chan_setblocksize(kobj_t obj, void *data, uint32_t blocksize)
-{
- return (uaudio_chan_set_param_blocksize(data, blocksize));
-}
-
-static int
-ua_chan_setfragments(kobj_t obj, void *data, uint32_t blocksize, uint32_t blockcount)
-{
- return (uaudio_chan_set_param_fragments(data, blocksize, blockcount));
-}
-
-static int
-ua_chan_trigger(kobj_t obj, void *data, int go)
-{
- if (!PCMTRIG_COMMON(go)) {
- return (0);
- }
- if (go == PCMTRIG_START) {
- return (uaudio_chan_start(data));
- } else {
- return (uaudio_chan_stop(data));
- }
-}
-
-static int
-ua_chan_getptr(kobj_t obj, void *data)
-{
- return (uaudio_chan_getptr(data));
-}
-
-static struct pcmchan_caps *
-ua_chan_getcaps(kobj_t obj, void *data)
-{
- return (uaudio_chan_getcaps(data));
-}
-
-static kobj_method_t ua_chan_methods[] = {
- KOBJMETHOD(channel_init, ua_chan_init),
- KOBJMETHOD(channel_free, ua_chan_free),
- KOBJMETHOD(channel_setformat, ua_chan_setformat),
- KOBJMETHOD(channel_setspeed, ua_chan_setspeed),
- KOBJMETHOD(channel_setblocksize, ua_chan_setblocksize),
- KOBJMETHOD(channel_setfragments, ua_chan_setfragments),
- KOBJMETHOD(channel_trigger, ua_chan_trigger),
- KOBJMETHOD(channel_getptr, ua_chan_getptr),
- KOBJMETHOD(channel_getcaps, ua_chan_getcaps),
- {0, 0}
-};
-
-CHANNEL_DECLARE(ua_chan);
-
-/************************************************************/
-static int
-ua_mixer_init(struct snd_mixer *m)
-{
- return (uaudio_mixer_init_sub(mix_getdevinfo(m), m));
-}
-
-static int
-ua_mixer_set(struct snd_mixer *m, unsigned type, unsigned left, unsigned right)
-{
- struct mtx *mtx = mixer_get_lock(m);
- uint8_t do_unlock;
-
- if (mtx_owned(mtx)) {
- do_unlock = 0;
- } else {
- do_unlock = 1;
- mtx_lock(mtx);
- }
- uaudio_mixer_set(mix_getdevinfo(m), type, left, right);
- if (do_unlock) {
- mtx_unlock(mtx);
- }
- return (left | (right << 8));
-}
-
-static int
-ua_mixer_setrecsrc(struct snd_mixer *m, uint32_t src)
-{
- struct mtx *mtx = mixer_get_lock(m);
- int retval;
- uint8_t do_unlock;
-
- if (mtx_owned(mtx)) {
- do_unlock = 0;
- } else {
- do_unlock = 1;
- mtx_lock(mtx);
- }
- retval = uaudio_mixer_setrecsrc(mix_getdevinfo(m), src);
- if (do_unlock) {
- mtx_unlock(mtx);
- }
- return (retval);
-}
-
-static int
-ua_mixer_uninit(struct snd_mixer *m)
-{
- return (uaudio_mixer_uninit_sub(mix_getdevinfo(m)));
-}
-
-static kobj_method_t ua_mixer_methods[] = {
- KOBJMETHOD(mixer_init, ua_mixer_init),
- KOBJMETHOD(mixer_uninit, ua_mixer_uninit),
- KOBJMETHOD(mixer_set, ua_mixer_set),
- KOBJMETHOD(mixer_setrecsrc, ua_mixer_setrecsrc),
-
- {0, 0}
-};
-
-MIXER_DECLARE(ua_mixer);
-/************************************************************/
-
-
-static int
-ua_probe(device_t dev)
-{
- struct sndcard_func *func;
-
- /* the parent device has already been probed */
-
- func = device_get_ivars(dev);
-
- if ((func == NULL) ||
- (func->func != SCF_PCM)) {
- return (ENXIO);
- }
- device_set_desc(dev, "USB audio");
-
- return (BUS_PROBE_DEFAULT);
-}
-
-static int
-ua_attach(device_t dev)
-{
- return (uaudio_attach_sub(dev, &ua_mixer_class, &ua_chan_class));
-}
-
-static int
-ua_detach(device_t dev)
-{
- return (uaudio_detach_sub(dev));
-}
-
-/************************************************************/
-
-static device_method_t ua_pcm_methods[] = {
- /* Device interface */
- DEVMETHOD(device_probe, ua_probe),
- DEVMETHOD(device_attach, ua_attach),
- DEVMETHOD(device_detach, ua_detach),
-
- {0, 0}
-};
-
-static driver_t ua_pcm_driver = {
- "pcm",
- ua_pcm_methods,
- PCM_SOFTC_SIZE,
-};
-
-DRIVER_MODULE(ua_pcm, uaudio, ua_pcm_driver, pcm_devclass, 0, 0);
-MODULE_DEPEND(ua_pcm, uaudio, 1, 1, 1);
-MODULE_DEPEND(ua_pcm, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
-MODULE_VERSION(ua_pcm, 1);
diff --git a/sys/dev/usb/sound/uaudio_reg.h b/sys/dev/usb/sound/uaudio_reg.h
deleted file mode 100644
index 2bf68a1..0000000
--- a/sys/dev/usb/sound/uaudio_reg.h
+++ /dev/null
@@ -1,406 +0,0 @@
-/* $NetBSD: uaudioreg.h,v 1.12 2004/11/05 19:08:29 kent Exp $ */
-/* $FreeBSD$ */
-
-/*-
- * Copyright (c) 1999 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Lennart Augustsson (lennart@augustsson.net) 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.
- */
-
-#define UAUDIO_VERSION 0x100
-
-#define UDESC_CS_CONFIG 0x22
-#define UDESC_CS_STRING 0x23
-#define UDESC_CS_INTERFACE 0x24
-#define UDESC_CS_ENDPOINT 0x25
-
-#define UDESCSUB_AC_HEADER 1
-#define UDESCSUB_AC_INPUT 2
-#define UDESCSUB_AC_OUTPUT 3
-#define UDESCSUB_AC_MIXER 4
-#define UDESCSUB_AC_SELECTOR 5
-#define UDESCSUB_AC_FEATURE 6
-#define UDESCSUB_AC_PROCESSING 7
-#define UDESCSUB_AC_EXTENSION 8
-
-/* The first fields are identical to struct usb2_endpoint_descriptor */
-typedef struct {
- uByte bLength;
- uByte bDescriptorType;
- uByte bEndpointAddress;
- uByte bmAttributes;
- uWord wMaxPacketSize;
- uByte bInterval;
- /*
- * The following two entries are only used by the Audio Class.
- * And according to the specs the Audio Class is the only one
- * allowed to extend the endpoint descriptor.
- * Who knows what goes on in the minds of the people in the USB
- * standardization? :-(
- */
- uByte bRefresh;
- uByte bSynchAddress;
-} __packed usb2_endpoint_descriptor_audio_t;
-
-struct usb2_audio_control_descriptor {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uWord bcdADC;
- uWord wTotalLength;
- uByte bInCollection;
- uByte baInterfaceNr[1];
-} __packed;
-
-struct usb2_audio_streaming_interface_descriptor {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bTerminalLink;
- uByte bDelay;
- uWord wFormatTag;
-} __packed;
-
-struct usb2_audio_streaming_endpoint_descriptor {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bmAttributes;
-#define UA_SED_FREQ_CONTROL 0x01
-#define UA_SED_PITCH_CONTROL 0x02
-#define UA_SED_MAXPACKETSONLY 0x80
- uByte bLockDelayUnits;
- uWord wLockDelay;
-} __packed;
-
-struct usb2_audio_streaming_type1_descriptor {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bFormatType;
- uByte bNrChannels;
- uByte bSubFrameSize;
- uByte bBitResolution;
- uByte bSamFreqType;
-#define UA_SAMP_CONTNUOUS 0
- uByte tSamFreq[0];
-#define UA_GETSAMP(p, n) (((p)->tSamFreq[((n)*3)+0]) | \
- ((p)->tSamFreq[((n)*3)+1] << 8) | \
- ((p)->tSamFreq[((n)*3)+2] << 16))
-#define UA_SAMP_LO(p) UA_GETSAMP(p, 0)
-#define UA_SAMP_HI(p) UA_GETSAMP(p, 1)
-} __packed;
-
-struct usb2_audio_cluster {
- uByte bNrChannels;
- uWord wChannelConfig;
-#define UA_CHANNEL_LEFT 0x0001
-#define UA_CHANNEL_RIGHT 0x0002
-#define UA_CHANNEL_CENTER 0x0004
-#define UA_CHANNEL_LFE 0x0008
-#define UA_CHANNEL_L_SURROUND 0x0010
-#define UA_CHANNEL_R_SURROUND 0x0020
-#define UA_CHANNEL_L_CENTER 0x0040
-#define UA_CHANNEL_R_CENTER 0x0080
-#define UA_CHANNEL_SURROUND 0x0100
-#define UA_CHANNEL_L_SIDE 0x0200
-#define UA_CHANNEL_R_SIDE 0x0400
-#define UA_CHANNEL_TOP 0x0800
- uByte iChannelNames;
-} __packed;
-
-/* Shared by all units and terminals */
-struct usb2_audio_unit {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
-};
-
-/* UDESCSUB_AC_INPUT */
-struct usb2_audio_input_terminal {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bTerminalId;
- uWord wTerminalType;
- uByte bAssocTerminal;
- uByte bNrChannels;
- uWord wChannelConfig;
- uByte iChannelNames;
-/* uByte iTerminal; */
-} __packed;
-
-/* UDESCSUB_AC_OUTPUT */
-struct usb2_audio_output_terminal {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bTerminalId;
- uWord wTerminalType;
- uByte bAssocTerminal;
- uByte bSourceId;
- uByte iTerminal;
-} __packed;
-
-/* UDESCSUB_AC_MIXER */
-struct usb2_audio_mixer_unit_0 {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
- uByte bNrInPins;
- uByte baSourceId[0]; /* [bNrInPins] */
- /* struct usb2_audio_mixer_unit_1 */
-} __packed;
-struct usb2_audio_mixer_unit_1 {
- uByte bNrChannels;
- uWord wChannelConfig;
- uByte iChannelNames;
- uByte bmControls[0]; /* [see source code] */
- /* uByte iMixer; */
-} __packed;
-
-/* UDESCSUB_AC_SELECTOR */
-struct usb2_audio_selector_unit {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
- uByte bNrInPins;
- uByte baSourceId[0]; /* [bNrInPins] */
- /* uByte iSelector; */
-} __packed;
-
-/* UDESCSUB_AC_FEATURE */
-struct usb2_audio_feature_unit {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
- uByte bSourceId;
- uByte bControlSize;
- uByte bmaControls[0]; /* [bControlSize * x] */
- /* uByte iFeature; */
-} __packed;
-
-/* UDESCSUB_AC_PROCESSING */
-struct usb2_audio_processing_unit_0 {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
- uWord wProcessType;
- uByte bNrInPins;
- uByte baSourceId[0]; /* [bNrInPins] */
- /* struct usb2_audio_processing_unit_1 */
-} __packed;
-struct usb2_audio_processing_unit_1 {
- uByte bNrChannels;
- uWord wChannelConfig;
- uByte iChannelNames;
- uByte bControlSize;
- uByte bmControls[0]; /* [bControlSize] */
-#define UA_PROC_ENABLE_MASK 1
-} __packed;
-
-struct usb2_audio_processing_unit_updown {
- uByte iProcessing;
- uByte bNrModes;
- uWord waModes[0]; /* [bNrModes] */
-} __packed;
-
-/* UDESCSUB_AC_EXTENSION */
-struct usb2_audio_extension_unit_0 {
- uByte bLength;
- uByte bDescriptorType;
- uByte bDescriptorSubtype;
- uByte bUnitId;
- uWord wExtensionCode;
- uByte bNrInPins;
- uByte baSourceId[0]; /* [bNrInPins] */
- /* struct usb2_audio_extension_unit_1 */
-} __packed;
-struct usb2_audio_extension_unit_1 {
- uByte bNrChannels;
- uWord wChannelConfig;
- uByte iChannelNames;
- uByte bControlSize;
- uByte bmControls[0]; /* [bControlSize] */
-#define UA_EXT_ENABLE_MASK 1
-#define UA_EXT_ENABLE 1
- /* uByte iExtension; */
-} __packed;
-
-/* USB terminal types */
-#define UAT_UNDEFINED 0x0100
-#define UAT_STREAM 0x0101
-#define UAT_VENDOR 0x01ff
-/* input terminal types */
-#define UATI_UNDEFINED 0x0200
-#define UATI_MICROPHONE 0x0201
-#define UATI_DESKMICROPHONE 0x0202
-#define UATI_PERSONALMICROPHONE 0x0203
-#define UATI_OMNIMICROPHONE 0x0204
-#define UATI_MICROPHONEARRAY 0x0205
-#define UATI_PROCMICROPHONEARR 0x0206
-/* output terminal types */
-#define UATO_UNDEFINED 0x0300
-#define UATO_SPEAKER 0x0301
-#define UATO_HEADPHONES 0x0302
-#define UATO_DISPLAYAUDIO 0x0303
-#define UATO_DESKTOPSPEAKER 0x0304
-#define UATO_ROOMSPEAKER 0x0305
-#define UATO_COMMSPEAKER 0x0306
-#define UATO_SUBWOOFER 0x0307
-/* bidir terminal types */
-#define UATB_UNDEFINED 0x0400
-#define UATB_HANDSET 0x0401
-#define UATB_HEADSET 0x0402
-#define UATB_SPEAKERPHONE 0x0403
-#define UATB_SPEAKERPHONEESUP 0x0404
-#define UATB_SPEAKERPHONEECANC 0x0405
-/* telephony terminal types */
-#define UATT_UNDEFINED 0x0500
-#define UATT_PHONELINE 0x0501
-#define UATT_TELEPHONE 0x0502
-#define UATT_DOWNLINEPHONE 0x0503
-/* external terminal types */
-#define UATE_UNDEFINED 0x0600
-#define UATE_ANALOGCONN 0x0601
-#define UATE_DIGITALAUIFC 0x0602
-#define UATE_LINECONN 0x0603
-#define UATE_LEGACYCONN 0x0604
-#define UATE_SPDIF 0x0605
-#define UATE_1394DA 0x0606
-#define UATE_1394DV 0x0607
-/* embedded function terminal types */
-#define UATF_UNDEFINED 0x0700
-#define UATF_CALIBNOISE 0x0701
-#define UATF_EQUNOISE 0x0702
-#define UATF_CDPLAYER 0x0703
-#define UATF_DAT 0x0704
-#define UATF_DCC 0x0705
-#define UATF_MINIDISK 0x0706
-#define UATF_ANALOGTAPE 0x0707
-#define UATF_PHONOGRAPH 0x0708
-#define UATF_VCRAUDIO 0x0709
-#define UATF_VIDEODISCAUDIO 0x070a
-#define UATF_DVDAUDIO 0x070b
-#define UATF_TVTUNERAUDIO 0x070c
-#define UATF_SATELLITE 0x070d
-#define UATF_CABLETUNER 0x070e
-#define UATF_DSS 0x070f
-#define UATF_RADIORECV 0x0710
-#define UATF_RADIOXMIT 0x0711
-#define UATF_MULTITRACK 0x0712
-#define UATF_SYNTHESIZER 0x0713
-
-
-#define SET_CUR 0x01
-#define GET_CUR 0x81
-#define SET_MIN 0x02
-#define GET_MIN 0x82
-#define SET_MAX 0x03
-#define GET_MAX 0x83
-#define SET_RES 0x04
-#define GET_RES 0x84
-#define SET_MEM 0x05
-#define GET_MEM 0x85
-#define GET_STAT 0xff
-
-#define MUTE_CONTROL 0x01
-#define VOLUME_CONTROL 0x02
-#define BASS_CONTROL 0x03
-#define MID_CONTROL 0x04
-#define TREBLE_CONTROL 0x05
-#define GRAPHIC_EQUALIZER_CONTROL 0x06
-#define AGC_CONTROL 0x07
-#define DELAY_CONTROL 0x08
-#define BASS_BOOST_CONTROL 0x09
-#define LOUDNESS_CONTROL 0x0a
-
-#define FU_MASK(u) (1 << ((u)-1))
-
-#define MASTER_CHAN 0
-
-#define AS_GENERAL 1
-#define FORMAT_TYPE 2
-#define FORMAT_SPECIFIC 3
-
-#define UA_FMT_PCM 1
-#define UA_FMT_PCM8 2
-#define UA_FMT_IEEE_FLOAT 3
-#define UA_FMT_ALAW 4
-#define UA_FMT_MULAW 5
-#define UA_FMT_MPEG 0x1001
-#define UA_FMT_AC3 0x1002
-
-#define SAMPLING_FREQ_CONTROL 0x01
-#define PITCH_CONTROL 0x02
-
-#define FORMAT_TYPE_UNDEFINED 0
-#define FORMAT_TYPE_I 1
-#define FORMAT_TYPE_II 2
-#define FORMAT_TYPE_III 3
-
-#define UA_PROC_MASK(n) (1<< ((n)-1))
-#define PROCESS_UNDEFINED 0
-#define XX_ENABLE_CONTROL 1
-#define UPDOWNMIX_PROCESS 1
-#define UD_ENABLE_CONTROL 1
-#define UD_MODE_SELECT_CONTROL 2
-#define DOLBY_PROLOGIC_PROCESS 2
-#define DP_ENABLE_CONTROL 1
-#define DP_MODE_SELECT_CONTROL 2
-#define P3D_STEREO_EXTENDER_PROCESS 3
-#define P3D_ENABLE_CONTROL 1
-#define P3D_SPACIOUSNESS_CONTROL 2
-#define REVERBATION_PROCESS 4
-#define RV_ENABLE_CONTROL 1
-#define RV_LEVEL_CONTROL 2
-#define RV_TIME_CONTROL 3
-#define RV_FEEDBACK_CONTROL 4
-#define CHORUS_PROCESS 5
-#define CH_ENABLE_CONTROL 1
-#define CH_LEVEL_CONTROL 2
-#define CH_RATE_CONTROL 3
-#define CH_DEPTH_CONTROL 4
-#define DYN_RANGE_COMP_PROCESS 6
-#define DR_ENABLE_CONTROL 1
-#define DR_COMPRESSION_RATE_CONTROL 2
-#define DR_MAXAMPL_CONTROL 3
-#define DR_THRESHOLD_CONTROL 4
-#define DR_ATTACK_TIME_CONTROL 5
-#define DR_RELEASE_TIME_CONTROL 6
diff --git a/sys/dev/usb/storage/ata-usb.c b/sys/dev/usb/storage/ata-usb.c
deleted file mode 100644
index 01ce320..0000000
--- a/sys/dev/usb/storage/ata-usb.c
+++ /dev/null
@@ -1,1102 +0,0 @@
-/*-
- * Copyright (c) 2006 - 2008 Søren Schmidt <sos@FreeBSD.org>
- * All rights reserved.
- *
- * Copyright (c) 2006 Hans Petter Selasky
- * All rights reserved.
- *
- * 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,
- * without modification, immediately at the beginning of the file.
- * 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 AUTHOR ``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 AUTHOR 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>
-__FBSDID("$FreeBSD$");
-
-#include "usbdevs.h"
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_mfunc.h>
-#include <dev/usb/usb_error.h>
-
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-
-#include <sys/ata.h>
-#include <sys/bio.h>
-#include <sys/sema.h>
-#include <sys/taskqueue.h>
-#include <vm/uma.h>
-
-#include <dev/ata/ata-all.h>
-#include <ata_if.h>
-
-#define ATAUSB_BULK_SIZE (1<<17)
-
-/* Command Block Wrapper */
-struct bbb_cbw {
- uint8_t signature[4];
-#define CBWSIGNATURE 0x43425355
-
- uint8_t tag[4];
- uint8_t transfer_length[4];
- uint8_t flags;
-#define CBWFLAGS_OUT 0x00
-#define CBWFLAGS_IN 0x80
-
- uint8_t lun;
- uint8_t length;
-#define CBWCDBLENGTH 16
-
- uint8_t cdb[CBWCDBLENGTH];
-} __packed;
-
-/* Command Status Wrapper */
-struct bbb_csw {
- uint8_t signature[4];
-#define CSWSIGNATURE 0x53425355
-
- uint8_t tag[4];
- uint8_t residue[4];
- uint8_t status;
-#define CSWSTATUS_GOOD 0x0
-#define CSWSTATUS_FAILED 0x1
-#define CSWSTATUS_PHASE 0x2
-} __packed;
-
-/* USB-ATA 'controller' softc */
-struct atausb2_softc {
- struct bbb_cbw cbw;
- struct bbb_csw csw;
- struct mtx locked_mtx;
-
- struct ata_channel *locked_ch;
- struct ata_channel *restart_ch;
- struct ata_request *ata_request;
-
-#define ATAUSB_T_BBB_RESET1 0
-#define ATAUSB_T_BBB_RESET2 1
-#define ATAUSB_T_BBB_RESET3 2
-#define ATAUSB_T_BBB_COMMAND 3
-#define ATAUSB_T_BBB_DATA_READ 4
-#define ATAUSB_T_BBB_DATA_RD_CS 5
-#define ATAUSB_T_BBB_DATA_WRITE 6
-#define ATAUSB_T_BBB_DATA_WR_CS 7
-#define ATAUSB_T_BBB_STATUS 8
-#define ATAUSB_T_BBB_MAX 9
-
-#define ATAUSB_T_MAX ATAUSB_T_BBB_MAX
-
- struct usb2_xfer *xfer[ATAUSB_T_MAX];
- caddr_t ata_data;
- device_t dev;
-
- uint32_t timeout;
- uint32_t ata_donecount;
- uint32_t ata_bytecount;
-
- uint8_t last_xfer_no;
- uint8_t usb2_speed;
- uint8_t intr_stalled;
- uint8_t maxlun;
- uint8_t iface_no;
- uint8_t status_try;
-};
-
-static const int atausbdebug = 0;
-
-/* prototypes */
-
-static device_probe_t atausb2_probe;
-static device_attach_t atausb2_attach;
-static device_detach_t atausb2_detach;
-
-static usb2_callback_t atausb2_t_bbb_reset1_callback;
-static usb2_callback_t atausb2_t_bbb_reset2_callback;
-static usb2_callback_t atausb2_t_bbb_reset3_callback;
-static usb2_callback_t atausb2_t_bbb_command_callback;
-static usb2_callback_t atausb2_t_bbb_data_read_callback;
-static usb2_callback_t atausb2_t_bbb_data_rd_cs_callback;
-static usb2_callback_t atausb2_t_bbb_data_write_callback;
-static usb2_callback_t atausb2_t_bbb_data_wr_cs_callback;
-static usb2_callback_t atausb2_t_bbb_status_callback;
-static usb2_callback_t atausb2_tr_error;
-
-static void atausb2_cancel_request(struct atausb2_softc *sc);
-static void atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no);
-static void atausb2_t_bbb_data_clear_stall_callback(struct usb2_xfer *xfer, uint8_t next_xfer, uint8_t stall_xfer);
-static int ata_usbchannel_begin_transaction(struct ata_request *request);
-static int ata_usbchannel_end_transaction(struct ata_request *request);
-
-static device_probe_t ata_usbchannel_probe;
-static device_attach_t ata_usbchannel_attach;
-static device_detach_t ata_usbchannel_detach;
-
-static ata_setmode_t ata_usbchannel_setmode;
-static ata_locking_t ata_usbchannel_locking;
-
-/*
- * USB frontend part
- */
-
-struct usb2_config atausb2_config[ATAUSB_T_BBB_MAX] = {
-
- [ATAUSB_T_BBB_RESET1] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_reset1_callback,
- .mh.timeout = 5000, /* 5 seconds */
- .mh.interval = 500, /* 500 milliseconds */
- },
-
- [ATAUSB_T_BBB_RESET2] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_reset2_callback,
- .mh.timeout = 5000, /* 5 seconds */
- .mh.interval = 50, /* 50 milliseconds */
- },
-
- [ATAUSB_T_BBB_RESET3] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_reset3_callback,
- .mh.timeout = 5000, /* 5 seconds */
- .mh.interval = 50, /* 50 milliseconds */
- },
-
- [ATAUSB_T_BBB_COMMAND] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_OUT,
- .mh.bufsize = sizeof(struct bbb_cbw),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_command_callback,
- .mh.timeout = 5000, /* 5 seconds */
- },
-
- [ATAUSB_T_BBB_DATA_READ] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_IN,
- .mh.bufsize = ATAUSB_BULK_SIZE,
- .mh.flags = {.proxy_buffer = 1,.short_xfer_ok = 1,},
- .mh.callback = &atausb2_t_bbb_data_read_callback,
- .mh.timeout = 0, /* overwritten later */
- },
-
- [ATAUSB_T_BBB_DATA_RD_CS] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_data_rd_cs_callback,
- .mh.timeout = 5000, /* 5 seconds */
- },
-
- [ATAUSB_T_BBB_DATA_WRITE] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_OUT,
- .mh.bufsize = ATAUSB_BULK_SIZE,
- .mh.flags = {.proxy_buffer = 1,.short_xfer_ok = 1,},
- .mh.callback = &atausb2_t_bbb_data_write_callback,
- .mh.timeout = 0, /* overwritten later */
- },
-
- [ATAUSB_T_BBB_DATA_WR_CS] = {
- .type = UE_CONTROL,
- .endpoint = 0x00, /* Control pipe */
- .direction = UE_DIR_ANY,
- .mh.bufsize = sizeof(struct usb2_device_request),
- .mh.flags = {},
- .mh.callback = &atausb2_t_bbb_data_wr_cs_callback,
- .mh.timeout = 5000, /* 5 seconds */
- },
-
- [ATAUSB_T_BBB_STATUS] = {
- .type = UE_BULK,
- .endpoint = UE_ADDR_ANY,
- .direction = UE_DIR_IN,
- .mh.bufsize = sizeof(struct bbb_csw),
- .mh.flags = {.short_xfer_ok = 1,},
- .mh.callback = &atausb2_t_bbb_status_callback,
- .mh.timeout = 5000, /* ms */
- },
-};
-
-static devclass_t atausb2_devclass;
-
-static device_method_t atausb2_methods[] = {
- DEVMETHOD(device_probe, atausb2_probe),
- DEVMETHOD(device_attach, atausb2_attach),
- DEVMETHOD(device_detach, atausb2_detach),
- {0, 0}
-};
-
-static driver_t atausb2_driver = {
- .name = "atausb",
- .methods = atausb2_methods,
- .size = sizeof(struct atausb2_softc),
-};
-
-DRIVER_MODULE(atausb, ushub, atausb2_driver, atausb2_devclass, 0, 0);
-MODULE_DEPEND(atausb, usb, 1, 1, 1);
-MODULE_VERSION(atausb, 1);
-
-static int
-atausb2_probe(device_t dev)
-{
- struct usb2_attach_arg *uaa = device_get_ivars(dev);
- struct usb2_interface_descriptor *id;
-
- if (uaa->usb2_mode != USB_MODE_HOST) {
- return (ENXIO);
- }
- if (uaa->use_generic == 0) {
- /* give other drivers a try first */
- return (ENXIO);
- }
- id = usb2_get_interface_descriptor(uaa->iface);
- if ((!id) || (id->bInterfaceClass != UICLASS_MASS)) {
- return (ENXIO);
- }
- switch (id->bInterfaceSubClass) {
- case UISUBCLASS_QIC157:
- case UISUBCLASS_RBC:
- case UISUBCLASS_SCSI:
- case UISUBCLASS_SFF8020I:
- case UISUBCLASS_SFF8070I:
- case UISUBCLASS_UFI:
- switch (id->bInterfaceProtocol) {
- case UIPROTO_MASS_CBI:
- case UIPROTO_MASS_CBI_I:
- case UIPROTO_MASS_BBB:
- case UIPROTO_MASS_BBB_OLD:
- return (0);
- default:
- return (0);
- }
- break;
- default:
- return (0);
- }
-}
-
-static int
-atausb2_attach(device_t dev)
-{
- struct atausb2_softc *sc = device_get_softc(dev);
- struct usb2_attach_arg *uaa = device_get_ivars(dev);
- struct usb2_interface_descriptor *id;
- const char *proto, *subclass;
- struct usb2_device_request request;
- uint16_t i;
- uint8_t maxlun;
- uint8_t has_intr;
- int err;
-
- device_set_usb2_desc(dev);
-
- sc->dev = dev;
- sc->maxlun = 0;
- sc->locked_ch = NULL;
- sc->restart_ch = NULL;
- sc->usb2_speed = usb2_get_speed(uaa->device);
- mtx_init(&sc->locked_mtx, "ATAUSB lock", NULL, (MTX_DEF | MTX_RECURSE));
-
- id = usb2_get_interface_descriptor(uaa->iface);
- switch (id->bInterfaceProtocol) {
- case UIPROTO_MASS_BBB:
- case UIPROTO_MASS_BBB_OLD:
- proto = "Bulk-Only";
- break;
- case UIPROTO_MASS_CBI:
- proto = "CBI";
- break;
- case UIPROTO_MASS_CBI_I:
- proto = "CBI with CCI";
- break;
- default:
- proto = "Unknown";
- }
-
- switch (id->bInterfaceSubClass) {
- case UISUBCLASS_RBC:
- subclass = "RBC";
- break;
- case UISUBCLASS_QIC157:
- case UISUBCLASS_SFF8020I:
- case UISUBCLASS_SFF8070I:
- subclass = "ATAPI";
- break;
- case UISUBCLASS_SCSI:
- subclass = "SCSI";
- break;
- case UISUBCLASS_UFI:
- subclass = "UFI";
- break;
- default:
- subclass = "Unknown";
- }
-
- has_intr = (id->bInterfaceProtocol == UIPROTO_MASS_CBI_I);
- sc->iface_no = id->bInterfaceNumber;
-
- device_printf(dev, "using %s over %s\n", subclass, proto);
- if (strcmp(proto, "Bulk-Only") ||
- (strcmp(subclass, "ATAPI") && strcmp(subclass, "SCSI"))) {
- goto detach;
- }
- err = usb2_transfer_setup(uaa->device, &uaa->info.bIfaceIndex,
- sc->xfer, atausb2_config, ATAUSB_T_BBB_MAX, sc,
- &sc->locked_mtx);
-
- /* skip reset first time */
- sc->last_xfer_no = ATAUSB_T_BBB_COMMAND;
-
- if (err) {
- device_printf(sc->dev, "could not setup required "
- "transfers, %s\n", usb2_errstr(err));
- goto detach;
- }
- /* get number of devices so we can add matching channels */
- request.bmRequestType = UT_READ_CLASS_INTERFACE;
- request.bRequest = 0xfe; /* GET_MAX_LUN; */
- USETW(request.wValue, 0);
- USETW(request.wIndex, sc->iface_no);
- USETW(request.wLength, sizeof(maxlun));
- err = usb2_do_request(uaa->device, &Giant, &request, &maxlun);
-
- if (err) {
- if (bootverbose) {
- device_printf(sc->dev, "get maxlun not supported %s\n",
- usb2_errstr(err));
- }
- } else {
- sc->maxlun = maxlun;
- if (bootverbose) {
- device_printf(sc->dev, "maxlun=%d\n", sc->maxlun);
- }
- }
-
- /* ata channels are children to this USB control device */
- for (i = 0; i <= sc->maxlun; i++) {
- if (!device_add_child(sc->dev, "ata",
- devclass_find_free_unit(ata_devclass, 2))) {
- device_printf(sc->dev, "failed to attach ata child device\n");
- goto detach;
- }
- }
- bus_generic_attach(sc->dev);
-
- return (0);
-
-detach:
- atausb2_detach(dev);
- return (ENXIO);
-}
-
-static int
-atausb2_detach(device_t dev)
-{
- struct atausb2_softc *sc = device_get_softc(dev);
- device_t *children;
- int nchildren, i;
-
- /* teardown our statemachine */
-
- usb2_transfer_unsetup(sc->xfer, ATAUSB_T_MAX);
-
- /* detach & delete all children, if any */
-
- if (!device_get_children(dev, &children, &nchildren)) {
- for (i = 0; i < nchildren; i++) {
- device_delete_child(dev, children[i]);
- }
- free(children, M_TEMP);
- }
- mtx_destroy(&sc->locked_mtx);
- return (0);
-}
-
-static void
-atausb2_transfer_start(struct atausb2_softc *sc, uint8_t xfer_no)
-{
- if (atausbdebug) {
- device_printf(sc->dev, "BBB transfer %d\n", xfer_no);
- }
- if (sc->xfer[xfer_no]) {
- sc->last_xfer_no = xfer_no;
- usb2_transfer_start(sc->xfer[xfer_no]);
- } else {
- atausb2_cancel_request(sc);
- }
-}
-
-static void
-atausb2_t_bbb_reset1_callback(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
- struct usb2_device_request req;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
- atausb2_transfer_start(sc, ATAUSB_T_BBB_RESET2);
- return;
-
- case USB_ST_SETUP:
- req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
- req.bRequest = 0xff; /* bulk-only reset */
- USETW(req.wValue, 0);
- req.wIndex[0] = sc->iface_no;
- req.wIndex[1] = 0;
- USETW(req.wLength, 0);
-
- usb2_copy_in(xfer->frbuffers, 0, &req, sizeof(req));
-
- xfer->frlengths[0] = sizeof(req);
- xfer->nframes = 1;
- usb2_start_hardware(xfer);
- return;
-
- default: /* Error */
- atausb2_tr_error(xfer);
- return;
-
- }
-}
-
-static void
-atausb2_t_bbb_reset2_callback(struct usb2_xfer *xfer)
-{
- atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_RESET3,
- ATAUSB_T_BBB_DATA_READ);
-}
-
-static void
-atausb2_t_bbb_reset3_callback(struct usb2_xfer *xfer)
-{
- atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_COMMAND,
- ATAUSB_T_BBB_DATA_WRITE);
-}
-
-static void
-atausb2_t_bbb_data_clear_stall_callback(struct usb2_xfer *xfer,
- uint8_t next_xfer,
- uint8_t stall_xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-tr_transferred:
- atausb2_transfer_start(sc, next_xfer);
- return;
-
- case USB_ST_SETUP:
- if (usb2_clear_stall_callback(xfer, sc->xfer[stall_xfer])) {
- goto tr_transferred;
- }
- return;
-
- default: /* Error */
- atausb2_tr_error(xfer);
- return;
-
- }
-}
-
-static void
-atausb2_t_bbb_command_callback(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
- struct ata_request *request = sc->ata_request;
- struct ata_channel *ch;
- uint32_t tag;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
- atausb2_transfer_start
- (sc, ((request->flags & ATA_R_READ) ? ATAUSB_T_BBB_DATA_READ :
- (request->flags & ATA_R_WRITE) ? ATAUSB_T_BBB_DATA_WRITE :
- ATAUSB_T_BBB_STATUS));
- return;
-
- case USB_ST_SETUP:
-
- sc->status_try = 0;
-
- if (request) {
- ch = device_get_softc(request->parent);
-
- sc->timeout = (request->timeout * 1000) + 5000;
-
- tag = UGETDW(sc->cbw.tag) + 1;
-
- USETDW(sc->cbw.signature, CBWSIGNATURE);
- USETDW(sc->cbw.tag, tag);
- USETDW(sc->cbw.transfer_length, request->bytecount);
- sc->cbw.flags = (request->flags & ATA_R_READ) ? CBWFLAGS_IN : CBWFLAGS_OUT;
- sc->cbw.lun = ch->unit;
- sc->cbw.length = 16;
- bzero(sc->cbw.cdb, 16);
- bcopy(request->u.atapi.ccb, sc->cbw.cdb, 12); /* XXX SOS */
-
- usb2_copy_in(xfer->frbuffers, 0, &sc->cbw, sizeof(sc->cbw));
-
- xfer->frlengths[0] = sizeof(sc->cbw);
- usb2_start_hardware(xfer);
- }
- return;
-
- default: /* Error */
- atausb2_tr_error(xfer);
- return;
-
- }
-}
-
-static void
-atausb2_t_bbb_data_read_callback(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
- uint32_t max_bulk = xfer->max_data_length;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-
- usb2_copy_out(xfer->frbuffers, 0,
- sc->ata_data, xfer->actlen);
-
- sc->ata_bytecount -= xfer->actlen;
- sc->ata_data += xfer->actlen;
- sc->ata_donecount += xfer->actlen;
-
- if (xfer->actlen < xfer->sumlen) {
- /* short transfer */
- sc->ata_bytecount = 0;
- }
- case USB_ST_SETUP:
-
- if (atausbdebug > 1) {
- device_printf(sc->dev, "%s: max_bulk=%d, ata_bytecount=%d\n",
- __FUNCTION__, max_bulk, sc->ata_bytecount);
- }
- if (sc->ata_bytecount == 0) {
- atausb2_transfer_start(sc, ATAUSB_T_BBB_STATUS);
- return;
- }
- if (max_bulk > sc->ata_bytecount) {
- max_bulk = sc->ata_bytecount;
- }
- xfer->timeout = sc->timeout;
- xfer->frlengths[0] = max_bulk;
-
- usb2_start_hardware(xfer);
- return;
-
- default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- atausb2_tr_error(xfer);
- } else {
- atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
- }
- return;
-
- }
-}
-
-static void
-atausb2_t_bbb_data_rd_cs_callback(struct usb2_xfer *xfer)
-{
- atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
- ATAUSB_T_BBB_DATA_READ);
-}
-
-static void
-atausb2_t_bbb_data_write_callback(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
- uint32_t max_bulk = xfer->max_data_length;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-
- sc->ata_bytecount -= xfer->actlen;
- sc->ata_data += xfer->actlen;
- sc->ata_donecount += xfer->actlen;
-
- case USB_ST_SETUP:
-
- if (atausbdebug > 1) {
- device_printf(sc->dev, "%s: max_bulk=%d, ata_bytecount=%d\n",
- __FUNCTION__, max_bulk, sc->ata_bytecount);
- }
- if (sc->ata_bytecount == 0) {
- atausb2_transfer_start(sc, ATAUSB_T_BBB_STATUS);
- return;
- }
- if (max_bulk > sc->ata_bytecount) {
- max_bulk = sc->ata_bytecount;
- }
- xfer->timeout = sc->timeout;
- xfer->frlengths[0] = max_bulk;
-
- usb2_copy_in(xfer->frbuffers, 0,
- sc->ata_data, max_bulk);
-
- usb2_start_hardware(xfer);
- return;
-
- default: /* Error */
- if (xfer->error == USB_ERR_CANCELLED) {
- atausb2_tr_error(xfer);
- } else {
- atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_WR_CS);
- }
- return;
-
- }
-}
-
-static void
-atausb2_t_bbb_data_wr_cs_callback(struct usb2_xfer *xfer)
-{
- atausb2_t_bbb_data_clear_stall_callback(xfer, ATAUSB_T_BBB_STATUS,
- ATAUSB_T_BBB_DATA_WRITE);
-}
-
-static void
-atausb2_t_bbb_status_callback(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
- struct ata_request *request = sc->ata_request;
- uint32_t residue;
-
- switch (USB_GET_STATE(xfer)) {
- case USB_ST_TRANSFERRED:
-
- if (xfer->actlen < sizeof(sc->csw)) {
- bzero(&sc->csw, sizeof(sc->csw));
- }
- usb2_copy_out(xfer->frbuffers, 0, &sc->csw, xfer->actlen);
-
- if (request->flags & (ATA_R_READ | ATA_R_WRITE)) {
- request->donecount = sc->ata_donecount;
- }
- residue = UGETDW(sc->csw.residue);
-
- if (!residue) {
- residue = (request->bytecount - request->donecount);
- }
- if (residue > request->bytecount) {
- if (atausbdebug) {
- device_printf(sc->dev, "truncating residue from %d "
- "to %d bytes\n", residue,
- request->bytecount);
- }
- residue = request->bytecount;
- }
- /* check CSW and handle eventual error */
- if (UGETDW(sc->csw.signature) != CSWSIGNATURE) {
- if (atausbdebug) {
- device_printf(sc->dev, "bad CSW signature 0x%08x != 0x%08x\n",
- UGETDW(sc->csw.signature), CSWSIGNATURE);
- }
- goto tr_error;
- } else if (UGETDW(sc->csw.tag) != UGETDW(sc->cbw.tag)) {
- if (atausbdebug) {
- device_printf(sc->dev, "bad CSW tag %d != %d\n",
- UGETDW(sc->csw.tag), UGETDW(sc->cbw.tag));
- }
- goto tr_error;
- } else if (sc->csw.status > CSWSTATUS_PHASE) {
- if (atausbdebug) {
- device_printf(sc->dev, "bad CSW status %d > %d\n",
- sc->csw.status, CSWSTATUS_PHASE);
- }
- goto tr_error;
- } else if (sc->csw.status == CSWSTATUS_PHASE) {
- if (atausbdebug) {
- device_printf(sc->dev, "phase error residue = %d\n", residue);
- }
- goto tr_error;
- } else if (request->donecount > request->bytecount) {
- if (atausbdebug) {
- device_printf(sc->dev, "buffer overrun %d > %d\n",
- request->donecount, request->bytecount);
- }
- goto tr_error;
- } else if (sc->csw.status == CSWSTATUS_FAILED) {
- if (atausbdebug) {
- device_printf(sc->dev, "CSWSTATUS_FAILED\n");
- }
- request->error = ATA_E_ATAPI_SENSE_MASK;
- }
- sc->last_xfer_no = ATAUSB_T_BBB_COMMAND;
-
- sc->ata_request = NULL;
-
- /* drop the USB transfer lock while doing the ATA interrupt */
- mtx_unlock(&sc->locked_mtx);
-
- ata_interrupt(device_get_softc(request->parent));
-
- mtx_lock(&sc->locked_mtx);
- return;
-
- case USB_ST_SETUP:
- xfer->frlengths[0] = xfer->max_data_length;
- usb2_start_hardware(xfer);
- return;
-
- default:
-tr_error:
- if ((xfer->error == USB_ERR_CANCELLED) ||
- (sc->status_try)) {
- atausb2_tr_error(xfer);
- } else {
- sc->status_try = 1;
- atausb2_transfer_start(sc, ATAUSB_T_BBB_DATA_RD_CS);
- }
- return;
-
- }
-}
-
-static void
-atausb2_cancel_request(struct atausb2_softc *sc)
-{
- struct ata_request *request;
-
- mtx_assert(&sc->locked_mtx, MA_OWNED);
-
- request = sc->ata_request;
- sc->ata_request = NULL;
- sc->last_xfer_no = ATAUSB_T_BBB_RESET1;
-
- if (request) {
- request->error = ATA_E_ATAPI_SENSE_MASK;
-
- mtx_unlock(&sc->locked_mtx);
-
- ata_interrupt(device_get_softc(request->parent));
-
- mtx_lock(&sc->locked_mtx);
- }
-}
-
-static void
-atausb2_tr_error(struct usb2_xfer *xfer)
-{
- struct atausb2_softc *sc = xfer->priv_sc;
-
- if (xfer->error != USB_ERR_CANCELLED) {
-
- if (atausbdebug) {
- device_printf(sc->dev, "transfer failed, %s, in state %d "
- "-> BULK reset\n", usb2_errstr(xfer->error),
- sc->last_xfer_no);
- }
- }
- atausb2_cancel_request(sc);
-}
-
-/*
- * ATA backend part
- */
-struct atapi_inquiry {
- uint8_t device_type;
- uint8_t device_modifier;
- uint8_t version;
- uint8_t response_format;
- uint8_t length;
- uint8_t reserved[2];
- uint8_t flags;
- uint8_t vendor[8];
- uint8_t product[16];
- uint8_t revision[4];
- /* uint8_t crap[60]; */
-} __packed;
-
-static int
-ata_usbchannel_begin_transaction(struct ata_request *request)
-{
- struct atausb2_softc *sc =
- device_get_softc(device_get_parent(request->parent));
- int error;
-
- if (atausbdebug > 1) {
- device_printf(request->dev, "begin_transaction %s\n",
- ata_cmd2str(request));
- }
- mtx_lock(&sc->locked_mtx);
-
- /* sanity, just in case */
- if (sc->ata_request) {
- device_printf(request->dev, "begin is busy, "
- "state = %d\n", sc->last_xfer_no);
- request->result = EBUSY;
- error = ATA_OP_FINISHED;
- goto done;
- }
- /*
- * XXX SOS convert the request into the format used, only BBB for
- * now
- */
-
- /* ATA/ATAPI IDENTIFY needs special treatment */
- if (!(request->flags & ATA_R_ATAPI)) {
- if (request->u.ata.command != ATA_ATAPI_IDENTIFY) {
- device_printf(request->dev, "%s unsupported\n",
- ata_cmd2str(request));
- request->result = EIO;
- error = ATA_OP_FINISHED;
- goto done;
- }
- request->flags |= ATA_R_ATAPI;
- bzero(request->u.atapi.ccb, 16);
- request->u.atapi.ccb[0] = ATAPI_INQUIRY;
- request->u.atapi.ccb[4] = 255; /* sizeof(struct
- * atapi_inquiry); */
- request->data += 256; /* arbitrary offset into ata_param */
- request->bytecount = 255; /* sizeof(struct
- * atapi_inquiry); */
- }
- if (sc->xfer[sc->last_xfer_no]) {
-
- sc->ata_request = request;
- sc->ata_bytecount = request->bytecount;
- sc->ata_data = request->data;
- sc->ata_donecount = 0;
-
- usb2_transfer_start(sc->xfer[sc->last_xfer_no]);
- error = ATA_OP_CONTINUES;
- } else {
- request->result = EIO;
- error = ATA_OP_FINISHED;
- }
-
-done:
- mtx_unlock(&sc->locked_mtx);
- return (error);
-}
-
-static int
-ata_usbchannel_end_transaction(struct ata_request *request)
-{
- if (atausbdebug > 1) {
- device_printf(request->dev, "end_transaction %s\n",
- ata_cmd2str(request));
- }
- /*
- * XXX SOS convert the request from the format used, only BBB for
- * now
- */
-
- /* ATA/ATAPI IDENTIFY needs special treatment */
- if ((request->flags & ATA_R_ATAPI) &&
- (request->u.atapi.ccb[0] == ATAPI_INQUIRY)) {
- struct ata_device *atadev = device_get_softc(request->dev);
- struct atapi_inquiry *inquiry = (struct atapi_inquiry *)request->data;
- uint16_t *ptr;
-
- /* convert inquiry data into simple ata_param like format */
- atadev->param.config = ATA_PROTO_ATAPI | ATA_PROTO_ATAPI_12;
- atadev->param.config |= (inquiry->device_type & 0x1f) << 8;
- bzero(atadev->param.model, sizeof(atadev->param.model));
- strncpy(atadev->param.model, inquiry->vendor, 8);
- strcpy(atadev->param.model, " ");
- strncpy(atadev->param.model, inquiry->product, 16);
- ptr = (uint16_t *)(atadev->param.model + sizeof(atadev->param.model));
- while (--ptr >= (uint16_t *)atadev->param.model) {
- *ptr = ntohs(*ptr);
- }
- strncpy(atadev->param.revision, inquiry->revision, 4);
- ptr = (uint16_t *)(atadev->param.revision + sizeof(atadev->param.revision));
- while (--ptr >= (uint16_t *)atadev->param.revision) {
- *ptr = ntohs(*ptr);
- }
- request->result = 0;
- }
- return (ATA_OP_FINISHED);
-}
-
-static int
-ata_usbchannel_probe(device_t dev)
-{
- struct ata_channel *ch = device_get_softc(dev);
- device_t *children;
- int count, i;
- char buffer[32];
-
- /* take care of green memory */
- bzero(ch, sizeof(struct ata_channel));
-
- /* find channel number on this controller */
- if (!device_get_children(device_get_parent(dev), &children, &count)) {
- for (i = 0; i < count; i++) {
- if (children[i] == dev)
- ch->unit = i;
- }
- free(children, M_TEMP);
- }
- snprintf(buffer, sizeof(buffer), "USB lun %d", ch->unit);
- device_set_desc_copy(dev, buffer);
-
- return (0);
-}
-
-static int
-ata_usbchannel_attach(device_t dev)
-{
- struct ata_channel *ch = device_get_softc(dev);
-
- /* initialize the softc basics */
- ch->dev = dev;
- ch->state = ATA_IDLE;
- ch->hw.begin_transaction = ata_usbchannel_begin_transaction;
- ch->hw.end_transaction = ata_usbchannel_end_transaction;
- ch->hw.status = NULL;
- ch->hw.command = NULL;
- bzero(&ch->state_mtx, sizeof(struct mtx));
- mtx_init(&ch->state_mtx, "ATA state lock", NULL, MTX_DEF);
- bzero(&ch->queue_mtx, sizeof(struct mtx));
- mtx_init(&ch->queue_mtx, "ATA queue lock", NULL, MTX_DEF);
- TAILQ_INIT(&ch->ata_queue);
-
- /* XXX SOS reset the controller HW, the channel and device(s) */
- /* ATA_RESET(dev); */
-
- /* probe and attach device on this channel */
- ch->devices = ATA_ATAPI_MASTER;
- if (!ata_delayed_attach) {
- ata_identify(dev);
- }
- return (0);
-}
-
-static int
-ata_usbchannel_detach(device_t dev)
-{
- struct ata_channel *ch = device_get_softc(dev);
- device_t *children;
- int nchildren, i;
-
- /* detach & delete all children */
- if (!device_get_children(dev, &children, &nchildren)) {
- for (i = 0; i < nchildren; i++)
- if (children[i])
- device_delete_child(dev, children[i]);
- free(children, M_TEMP);
- }
- mtx_destroy(&ch->state_mtx);
- mtx_destroy(&ch->queue_mtx);
- return (0);
-}
-
-static void
-ata_usbchannel_setmode(device_t parent, device_t dev)
-{
- struct atausb2_softc *sc = device_get_softc(GRANDPARENT(dev));
- struct ata_device *atadev = device_get_softc(dev);
-
- if (sc->usb2_speed == USB_SPEED_HIGH)
- atadev->mode = ATA_USB2;
- else
- atadev->mode = ATA_USB1;
-}
-
-static int
-ata_usbchannel_locking(device_t dev, int flags)
-{
- struct atausb2_softc *sc = device_get_softc(device_get_parent(dev));
- struct ata_channel *ch = device_get_softc(dev);
- int res = -1;
-
- mtx_lock(&sc->locked_mtx);
- switch (flags) {
- case ATA_LF_LOCK:
- if (sc->locked_ch == NULL)
- sc->locked_ch = ch;
- if (sc->locked_ch != ch)
- sc->restart_ch = ch;
- break;
-
- case ATA_LF_UNLOCK:
- if (sc->locked_ch == ch) {
- sc->locked_ch = NULL;
- if (sc->restart_ch) {
- ch = sc->restart_ch;
- sc->restart_ch = NULL;
- mtx_unlock(&sc->locked_mtx);
- ata_start(ch->dev);
- return (res);
- }
- }
- break;
-
- case ATA_LF_WHICH:
- break;
- }
- if (sc->locked_ch) {
- res = sc->locked_ch->unit;
- }
- mtx_unlock(&sc->locked_mtx);
- return (res);
-}
-
-static device_method_t ata_usbchannel_methods[] = {
- /* device interface */
- DEVMETHOD(device_probe, ata_usbchannel_probe),
- DEVMETHOD(device_attach, ata_usbchannel_attach),
- DEVMETHOD(device_detach, ata_usbchannel_detach),
-
- /* ATA methods */
- DEVMETHOD(ata_setmode, ata_usbchannel_setmode),
- DEVMETHOD(ata_locking, ata_usbchannel_locking),
- /* DEVMETHOD(ata_reset, ata_usbchannel_reset), */
-
- {0, 0}
-};
-
-static driver_t ata_usbchannel_driver = {
- "ata",
- ata_usbchannel_methods,
- sizeof(struct ata_channel),
-};
-
-DRIVER_MODULE(ata, atausb, ata_usbchannel_driver, ata_devclass, 0, 0);
-MODULE_DEPEND(atausb, ata, 1, 1, 1);
OpenPOWER on IntegriCloud