usb_ac.c revision 88447a05f537aabe9a1bc3d5313f22581ec992a7
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* AUDIO CONTROL Driver:
* This driver is derived from the legacy SADA streams-based usb_ac driver
* and serves as an intermediate measure before the full conversion to the
* to the Boomer framework in a follow-on phase of the Boomer project, which
* will utilize more comprehensive USB audio features as well. Multiplexor
* plumbing functionality that used to be in the usb_ac_dacf DACF module is
* now located here.
*
* usb_ac is a multiplexor that sits on top of usb_as and hid and is
* responsible for (1) providing the entry points to audio mixer framework,
* (2) passing control commands to and from usb_as and hid and (3) processing
*
* 1. Mixer entry points are: usb_ac_setup(), usb_ac_teardown(),
* usb_ac_set_config(), usb_ac_set_format(), usb_ac_start_play(),
* usb_ac_pause_play(), usb_ac_stop_play, usb_ac_start_record(),
* usb_ac_stop_record().
* 2. usb_ac is a streams driver that passes streams messages down to
* usb_as that selects the correct alternate with passed format
* 3. usb_ac handles the set_config command through the default pipe
* of sound control interface of the audio device in a synchronous
* manner.
*
* Serialization: A competing thread can't be allowed to interfere with
* (1) pipe, (2) streams state.
* So we need some kind of serialization among the asynchronous
* threads that can run in the driver. The serialization is mostly
* etc. Once a routine takes control, it checks if the resource (pipe or
* stream or dev state) is still accessible. If so, it proceeds with
* its job and until it completes, no other thread requiring the same
* resource can run.
*
* PM model in usb_ac: Raise power during attach. If a device is not at full
* power, raise power in the entry points. After the command is over,
* pm_idle_component() is called. The power is lowered in detach().
*/
#include <sys/ndi_impldefs.h>
/* for getting the minor node info from hid */
#include "audio_shim.h"
/* debug support */
/*
* wait period in seconds for the HID message processing thread
* used primarily to check when the stream has closed
*/
/*
* table for converting term types of input and output terminals
* to SADA port types (pretty rough mapping)
*/
static struct {
} usb_ac_term_type_map[] = {
{ 0, 0 }
};
/*
* Module linkage routines for the kernel
*/
static int usb_ac_power(dev_info_t *, int, int);
/* plumbing */
uchar_t);
uint_t);
/* module entry points */
int usb_ac_open(dev_info_t *);
void usb_ac_close(dev_info_t *);
/* registration */
static int usb_ac_get_curr_n_channels(usb_ac_state_t *, int);
/* descriptor handling */
static int usb_ac_handle_descriptors(usb_ac_state_t *);
static void usb_ac_free_all_units(usb_ac_state_t *);
static void usb_ac_setup_connections(usb_ac_state_t *);
/* power management */
static int usb_ac_pwrlvl0(usb_ac_state_t *);
static int usb_ac_pwrlvl1(usb_ac_state_t *);
static int usb_ac_pwrlvl2(usb_ac_state_t *);
static int usb_ac_pwrlvl3(usb_ac_state_t *);
static void usb_ac_pm_busy_component(usb_ac_state_t *);
static void usb_ac_pm_idle_component(usb_ac_state_t *);
/* event handling */
static int usb_ac_disconnect_event_cb(dev_info_t *);
static int usb_ac_reconnect_event_cb(dev_info_t *);
static int usb_ac_cpr_suspend(dev_info_t *);
static void usb_ac_cpr_resume(dev_info_t *);
static usb_event_t usb_ac_events = {
};
/* misc. support */
static void usb_ac_serialize_access(usb_ac_state_t *);
static void usb_ac_release_access(usb_ac_state_t *);
static void usb_ac_show_traverse_path(usb_ac_state_t *);
int);
int, short *);
int, void *);
static int usb_ac_send_format_cmd(audiohdl_t, int, int, int, int, int);
static int usb_ac_do_setup(audiohdl_t, int);
static void usb_ac_do_teardown(audiohdl_t, int);
static void usb_ac_do_stop_play(audiohdl_t);
static void usb_ac_do_stop_record(audiohdl_t);
/* Mixer entry points */
static int usb_ac_setup(audiohdl_t, int);
static void usb_ac_teardown(audiohdl_t, int);
static int usb_ac_set_config(audiohdl_t, int, int, int, int);
static int usb_ac_set_format(audiohdl_t, int, int, int, int, int);
static int usb_ac_start_play(audiohdl_t);
static void usb_ac_stop_play(audiohdl_t);
static int usb_ac_start_record(audiohdl_t);
static void usb_ac_stop_record(audiohdl_t);
static int usb_ac_restore_audio_state(usb_ac_state_t *, int);
/*
* Mux
*/
static int usb_ac_mux_walk_siblings(usb_ac_state_t *);
static void usb_ac_print_reg_data(usb_ac_state_t *,
static int usb_ac_setup_plumbed(usb_ac_state_t *, int, int, int);
static int usb_ac_mixer_registration(usb_ac_state_t *);
static void usb_ac_hold_siblings(usb_ac_state_t *);
static int usb_ac_online_siblings(usb_ac_state_t *);
static void usb_ac_rele_siblings(usb_ac_state_t *);
static int usb_ac_mux_plumbing(usb_ac_state_t *);
static void usb_ac_mux_plumbing_tq(void *);
static int usb_ac_mux_unplumbing(usb_ac_state_t *);
static void usb_ac_mux_unplumbing_tq(void *);
static int usb_ac_plumb(usb_ac_plumbed_t *);
static void usb_ac_unplumb(usb_ac_plumbed_t *);
static void usb_ac_reader(void *);
static int usb_ac_do_plumbing(usb_ac_state_t *);
static int usb_ac_do_unplumbing(usb_ac_state_t *);
/* just generic, USB Audio, 1.0 spec-compliant */
static audio_device_t usb_dev_info =
{ {"USB Audio"}, {"1.0"}, {"external"} };
/*
* mixer registration data
*/
static am_ad_entry_t usb_ac_entry = {
usb_ac_setup, /* ad_setup() */
usb_ac_teardown, /* ad_teardown() */
usb_ac_set_config, /* ad_set_config() */
usb_ac_set_format, /* ad_set_format() */
usb_ac_start_play, /* ad_start_play() */
usb_ac_stop_play, /* ad_stop_play() */
usb_ac_start_record, /* ad_start_record() */
usb_ac_stop_record, /* ad_stop_record() */
};
/* anchor for soft state structures */
void *usb_ac_statep;
/*
* DDI Structures
*/
/* Device operations structure */
static struct dev_ops usb_ac_dev_ops = {
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
NULL, /* devo_getinfo */
nulldev, /* devo_identify - obsolete */
nulldev, /* devo_probe - not needed */
usb_ac_attach, /* devo_attach */
usb_ac_detach, /* devo_detach */
nodev, /* devo_reset */
NULL, /* devi_cb_ops */
NULL, /* devo_busb_ac_ops */
usb_ac_power, /* devo_power */
ddi_quiesce_not_needed, /* devo_quiesce */
};
/* Linkage structure for loadable drivers */
static struct modldrv usb_ac_modldrv = {
&mod_driverops, /* drv_modops */
"USB Audio Control Driver", /* drv_linkinfo */
&usb_ac_dev_ops /* drv_dev_ops */
};
/* Module linkage structure */
static struct modlinkage usb_ac_modlinkage = {
MODREV_1, /* ml_rev */
(void *)&usb_ac_modldrv, /* ml_linkage */
NULL /* NULL terminates the list */
};
/* standard entry points */
int
_init(void)
{
int rval;
/* initialize the soft state */
return (rval);
}
}
return (rval);
}
int
_fini(void)
{
int rval;
/* Free the soft state internal structures */
}
return (rval);
}
int
{
}
#define INIT_PROCESS_CNT 3
static int
{
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
/*
* wait until all processes are started from main.
* USB enumerates early in boot (ie. consconfig time).
* If the plumbing takes place early, the file descriptors
* are owned by the init process and can never be closed anymore
* Consequently, hot removal is not possible and the dips
* never go away. By waiting some time, e.g. INIT_PROCESS_CNT,
* the problem is avoided.
*/
if (nproc < INIT_PROCESS_CNT) {
"usb_ac%d attach too early", instance);
return (DDI_FAILURE);
}
/*
* Allocate soft state information.
*/
goto fail;
}
/*
* get soft state space and initialize
*/
goto fail;
}
/* get log handle */
0);
"usb_client_attach failed");
return (DDI_FAILURE);
}
USB_PARSE_LVL_IF, 0) != USB_SUCCESS) {
"usb_get_dev_data failed");
return (DDI_FAILURE);
}
/* initialize mutex & cv */
"audio_sup_register failed");
goto fail;
}
/* save softstate pointer in audio handle */
/* parse all class specific descriptors */
goto fail;
}
/* we no longer need the descr tree */
/* we are online */
/*
* safe guard the postattach to be executed
* only two states arepossible: plumbed / unplumbed
*/
/* create components to power manage this device */
/* Register for events */
"usb_ac_attach: couldn't register for events");
goto fail;
}
"usb_ac_attach: End");
/* report device */
goto fail;
return (DDI_SUCCESS);
fail:
if (uacp) {
"attach failed");
/* wait for plumbing thread to finish */
}
}
return (DDI_FAILURE);
}
static int
{
int rval = USB_FAILURE;
char *nm = "usb_ac_detach";
switch (cmd) {
case DDI_DETACH:
/* wait for plumbing thread to finish */
/* do not allow detach if still busy */
if (uacp->usb_ac_busy_count) {
return (USB_FAILURE);
}
/*
* call am_unregister() to stop calls into our driver from
* the framework; can fail if the framework is still busy
*/
dinfo("%s: %s - am_unregister failed, "
"framework still busy\n",
return (USB_FAILURE);
}
}
/*
* unplumb to stop activity from other modules, then
* cleanup, which will also teardown audio framework state
*/
if (rval != USB_SUCCESS) {
}
case DDI_SUSPEND:
default:
return (DDI_FAILURE);
}
}
/*
* usb_ac_cleanup:
* cleanup on attach failure and detach
*/
static int
{
int rval = USB_FAILURE;
/*
* deregister with audio framework, if it fails we are hosed
* and we probably don't want to plumb again
*/
if (uacp->usb_ac_audiohdl) {
if (uacp->usb_ac_registered_with_mixer) {
return (rval);
}
} else {
}
return (rval);
}
} else {
}
/*
* Disable the event callbacks, after this point, event
* callbacks will never get called. Note we shouldn't hold
* the mutex while unregistering events because there may be a
* competing event callback thread. Event callbacks are done
* with ndi mutex held and this can cause a potential deadlock.
*/
if (uacpm->acpm_wakeup_enabled) {
if (rval != USB_SUCCESS) {
"usb_ac_cleanup: disable remote "
"wakeup failed, rval=%d", rval);
}
} else {
}
}
if (uacpm) {
}
/* free descriptors */
"usb_ac_cleanup: Ending");
return (USB_SUCCESS);
}
int
{
return (0);
}
void
{
if (uacp->usb_ac_busy_count > 0)
}
/*
* usb_ac_read_msg:
* Handle asynchronous response from opened streams
*/
static int
{
int error = DDI_SUCCESS;
int val;
char val1;
"usb_ac_read_msg: mp=0x%p, instance=%d", (void *)mp,
/*
* typically an M_CTL is used between modules but in order to pass
* through the streamhead, an M_PROTO type must be used instead
*/
case M_PROTO:
case M_ERROR:
switch (plumb_infop->acp_driver) {
case USB_AH_PLUMBED:
"message from hid, instance=%d",
if (uacp->usb_ac_registered_with_mixer) {
/* Handle relative volume change */
case USB_AUDIO_VOL_CHANGE:
/* prevent unplumbing */
if (uacp->usb_ac_plumbing_state ==
(void) am_hw_state_change(
mutex_enter(&uacp->
}
/* FALLTHRU */
case USB_AUDIO_MUTE:
default:
break;
}
} else {
}
break;
default:
"message from unknown module(%s)",
}
break;
default:
}
"usb_ac_read_msg: done");
return (error);
}
/*
* Power Management
* usb_ac_power:
* power entry point
*/
static int
{
int rval = DDI_FAILURE;
"usb_ac_power: illegal level=%d pwr_states=%d",
goto done;
}
switch (level) {
case USB_DEV_OS_PWR_OFF:
break;
case USB_DEV_OS_PWR_1:
break;
case USB_DEV_OS_PWR_2:
break;
case USB_DEV_OS_FULL_PWR:
break;
}
done:
}
/*
* functions to handle power transition for various levels
* These functions act as place holders to issue USB commands
* to the devices to change their power levels
* Level 0 = Device is powered off
* Level 3 = Device if full powered
* Level 1,2 = Intermediate power level of the device as implemented
* by the hardware.
* Note that Level 0 is OS power-off and Level 3 is OS full-power.
*/
static int
{
int rval;
switch (uacp->usb_ac_dev_state) {
case USB_DEV_ONLINE:
/* Deny the powerdown request if the device is busy */
if (uacpm->acpm_pm_busy != 0) {
return (USB_FAILURE);
}
/* Issue USB D3 command to the device here */
/* FALLTHRU */
case USB_DEV_DISCONNECTED:
case USB_DEV_SUSPENDED:
case USB_DEV_PWRED_DOWN:
default:
return (USB_SUCCESS);
}
}
/* ARGSUSED */
static int
{
int rval;
/* Issue USB D2 command to the device here */
return (USB_FAILURE);
}
/* ARGSUSED */
static int
{
int rval;
return (USB_FAILURE);
}
static int
{
int rval;
switch (uacp->usb_ac_dev_state) {
case USB_DEV_PWRED_DOWN:
/* Issue USB D0 command to the device here */
/* FALLTHRU */
case USB_DEV_ONLINE:
/* we are already in full power */
/* FALLTHRU */
case USB_DEV_DISCONNECTED:
case USB_DEV_SUSPENDED:
return (USB_SUCCESS);
default:
"usb_ac_pwerlvl3: Illegal dev_state");
return (USB_FAILURE);
}
}
static void
{
"usb_ac_create_pm_components: begin");
/* Allocate the state structure */
uacpm->acpm_capabilities = 0;
USB_SUCCESS) {
"remote Wakeup enabled");
}
} else {
if (uacpm) {
}
"pm not enabled");
}
"usb_ac_create_pm_components: end");
}
/*
* usb_ac_get_plumb_info:
* Get plumb_info pointer that matches module "name"
* If name = "usb_as", match the direction also (record or play)
*/
static usb_ac_plumbed_t *
{
int n;
for (n = 0; n < USB_AC_MAX_PLUMBED; n++) {
continue;
}
continue;
}
/* Match direction */
break;
}
break;
}
}
if (n < USB_AC_MAX_PLUMBED) {
}
return (plumb_infop);
}
/*
* usb_ac_get_featureID:
* find out if there is at least one feature unit that supports
* the request controls.
* Return featureID or USB_AC_ID_NONE.
*/
static uint_t
{
}
/*
* usb_ac_feature_unit_check:
* check if a feature unit can support the required channel
* and control combination. Return USB_SUCCESS or USB_FAILURE.
* Called for each matching unit from usb_ac_traverse_connections.
*/
/*ARGSUSED*/
static int
{
int n_channel_controls;
"usb_ac_feature_unit_check: ID=%d ch=%d cntrl=%d",
/*
* check if this control is supported on this channel
*/
if (feature_descrp->bControlSize == 0) {
} else {
"#controls: %d index=%d", n_channel_controls,
if (channel > n_channel_controls) {
} else {
/*
* we only support MUTE and VOLUME
* which are in the first byte
*/
"control: 0x%x",
control) == 0) {
}
}
}
"usb_ac_feature_unit_check: dir=%d featureID=0x%x",
return ((featureID != USB_AC_ID_NONE) ?
}
/*
* Descriptor Management
*
* usb_ac_handle_descriptors:
* extract interesting descriptors from the config cloud
*/
static int
{
int rval = USB_FAILURE;
"config=%ld, interface=%d",
/* find USB_AUDIO_CS_INTERFACE type descriptor */
continue;
}
break;
}
}
"cannot find descriptor type %d", USB_AUDIO_CS_INTERFACE);
return (rval);
}
(void *)&descr, sizeof (usb_audio_cs_if_descr_t));
/* is this a sane header descriptor */
if (!((len >= CS_AC_IF_HEADER_SIZE) &&
"invalid header");
return (rval);
}
"header: type=0x%x subtype=0x%x bcdADC=0x%x\n\t"
"total=0x%x InCol=0x%x",
/*
* we read descriptors by index and store them in ID array.
* the actual parsing is done in usb_ac_add_unit_descriptor()
*/
continue;
}
/* add to ID array */
cvs->cvs_buf_len);
}
rval = USB_SUCCESS;
/* determine port types */
"input port types=0x%x output port types =0x%x",
return (rval);
}
/*
* usb_ac_setup_connections:
* build a matrix reflecting all connections
*/
static void
{
/* allocate array for unit types for quick reference */
KM_SLEEP);
/* allocate array for traversal path */
KM_SLEEP);
/* allocate the connection matrix and set it up */
/* trick to create a 2 dimensional array */
for (i = 0; i < uacp->usb_ac_max_unit; i++) {
p[i] = a + i * uacp->usb_ac_max_unit;
}
uacp->usb_ac_connections = p;
uacp->usb_ac_connections_a = a;
/* traverse all units and set connections */
"traversing unit=0x%x type=0x%x",
/* store type in the first unused column */
/* save the Unit ID in the unit it points to */
case USB_AUDIO_FEATURE_UNIT:
{
"sourceID=0x%x type=0x%x", d->bSourceID,
if (d->bSourceID != 0) {
}
break;
}
{
"sourceID=0x%x type=0x%x", d->bSourceID,
if (d->bSourceID != 0) {
}
break;
}
case USB_AUDIO_MIXER_UNIT:
{
int n_sourceID = d->bNrInPins;
int id;
"sourceID=0x%x type=0x%x c=%d",
d->baSourceID[id],
if (d->baSourceID[id] != 0) {
B_FALSE);
}
}
break;
}
case USB_AUDIO_SELECTOR_UNIT:
{
int n_sourceID = d->bNrInPins;
int id;
"sourceID=0x%x type=0x%x",
d->baSourceID[id],
if (d->baSourceID[id] != 0) {
B_FALSE);
}
}
break;
}
{
int n_sourceID = d->bNrInPins;
int id;
"sourceID=0x%x type=0x%x",
d->baSourceID[id],
if (d->baSourceID[id] != 0) {
B_FALSE);
}
}
break;
}
case USB_AUDIO_EXTENSION_UNIT:
{
int n_sourceID = d->bNrInPins;
int id;
"sourceID=0x%x type=0x%x",
d->baSourceID[id],
if (d->baSourceID[id] != 0) {
B_TRUE);
}
}
break;
}
case USB_AUDIO_INPUT_TERMINAL:
break;
default:
/*
* Ignore the rest because they are not support yet
*/
break;
}
}
#ifdef DEBUG
/* display topology in log buffer */
{
uint_t i, j, l;
char *buf;
"unit types:");
/* two strings so they won't be replaced accidentily by tab */
}
}
uacp->usb_ac_unit_type[i]);
}
"adjacency matrix:");
}
}
}
}
}
#endif
}
/*
* usb_ac_add_unit_descriptor:
* take the parsed descriptor in the buffer and store it in the ID unit
* array. we grow the unit array if the ID exceeds the current max
*/
static void
{
void *descr;
int len;
char *format;
"usb_ac_add_unit_descriptor: 0x%x 0x%x 0x%x",
/* doubling the length should allow for padding */
switch (buffer[2]) {
case USB_AUDIO_INPUT_TERMINAL:
break;
break;
case USB_AUDIO_MIXER_UNIT:
break;
case USB_AUDIO_SELECTOR_UNIT:
break;
case USB_AUDIO_FEATURE_UNIT:
break;
break;
case USB_AUDIO_EXTENSION_UNIT:
break;
default:
/* ignore this descriptor */
return;
}
/* ignore this descriptor */
return;
}
switch (buffer[2]) {
case USB_AUDIO_INPUT_TERMINAL:
{
"input term: type=0x%x sub=0x%x termid=0x%x\n\t"
"termtype=0x%x assoc=0x%x #ch=%d "
"chconf=0x%x ich=0x%x iterm=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
d->bTerminalID, d->wTerminalType,
d->bAssocTerminal, d->bNrChannels,
d->wChannelConfig, d->iChannelNames,
d->iTerminal);
break;
}
{
"output term: type=0x%x sub=0x%x termid=0x%x\n\t"
"termtype=0x%x assoc=0x%x sourceID=0x%x iterm=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
d->bTerminalID, d->wTerminalType,
d->bAssocTerminal, d->bSourceID,
d->iTerminal);
break;
}
case USB_AUDIO_MIXER_UNIT:
{
"mixer unit: type=0x%x sub=0x%x unitid=0x%x\n\t"
"#pins=0x%x sourceid[0]=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
break;
}
case USB_AUDIO_SELECTOR_UNIT:
{
"selector unit: type=0x%x sub=0x%x unitid=0x%x\n\t"
"#pins=0x%x sourceid[0]=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
break;
}
case USB_AUDIO_FEATURE_UNIT:
{
"feature unit: type=0x%x sub=0x%x unitid=0x%x\n\t"
"sourceid=0x%x size=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
break;
}
{
"processing unit: type=0x%x sub=0x%x unitid=0x%x\n\t"
"#pins=0x%x sourceid[0]=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
break;
}
case USB_AUDIO_EXTENSION_UNIT:
{
"mixer unit: type=0x%x sub=0x%x unitid=0x%x\n\t"
"#pins=0x%x sourceid[0]=0x%x",
d->bDescriptorType, d->bDescriptorSubType,
break;
}
default:
break;
}
}
/*
* usb_ac_alloc_unit:
* check if the unit ID is less than max_unit in which case no
* extra entries are needed. If more entries are needed, copy over
* the existing array into a new larger array
*/
static void
{
"usb_ac_alloc_unit: unit=%d", unit);
if (uacp->usb_ac_units) {
/* existing array is big enough */
return;
}
}
/* allocate two extra ones */
unit += 2;
sizeof (usb_ac_unit_list_t), KM_SLEEP);
if (old) {
}
}
/*
* usb_ac_free_all_units:
* free the entire unit list
*/
static void
{
return;
}
if (unitp) {
if (unitp->acu_descriptor) {
}
}
}
sizeof (usb_ac_unit_list_t));
}
/*
* usb_ac_lookup_port_type:
* map term type to port type
* default just return LINE_IN + LINE_OUT
*/
static int
{
uint_t i;
for (i = 0; ; i++) {
if (usb_ac_term_type_map[i].term_type == 0) {
break;
}
return (usb_ac_term_type_map[i].port_type);
}
}
return (AUDIO_LINE_IN|AUDIO_LINE_OUT);
}
/*
* usb_ac_update_port:
* called for each terminal
*/
/*ARGSUSED*/
static int
{
if (dir & AUDIO_PLAY) {
"usb_ac_update_port: dir=%d type=0x%x port type=%d",
} else {
"usb_ac_update_port: dir=%d type=0x%x port type=%d",
}
return (USB_SUCCESS);
}
/*
* usb_ac_map_termtype_to_port:
* starting from a streaming termtype find all
* input or output terminals and OR into uacp->usb_ac_input_ports
* or uacp->usb_ac_output_ports;
*/
static void
{
"usb_ac_map_term_to_port: dir=%d", dir);
}
/*
* usb_ac_set_port:
* find a selector port (record side only) and set the
* input to the matching pin
*/
static uint_t
{
/* we only support the selector for the record side */
if (dir & AUDIO_RECORD) {
"usb_ac_set_port: id=%d count=%d port=%d",
}
return (USB_SUCCESS);
}
/*
* usb_ac_match_port:
* given the requested port type, find a correspondig term type
* Called from usb_ac_traverse_all_units()
*/
/*ARGSUSED*/
static int
{
"usb_ac_match_port: id=%d dir=%d port=%d",
if (dir & AUDIO_PLAY) {
"usb_ac_match_port: "
"dir=%d type=0x%x port_type=%d port=%d",
} else {
"usb_ac_match_port: "
"dir=%d type=0x%x port_type=%d port=%d",
}
}
/*
* usb_ac_set_selector:
* Called from usb_ac_traverse_all_units()
* Find the correct pin and set selector to this pin
*/
/*ARGSUSED*/
static int
{
int n_sourceID = d->bNrInPins;
int rval = USB_FAILURE;
"usb_ac_set_selector: id=%d dir=%d port=%d",
/*
* for each pin, find a term type that matches the
* requested port type
*/
if (d->baSourceID[pin] == 0) {
break;
}
break;
} else {
continue;
}
}
/* find units connected to this unit */
if (unit != USB_AC_ID_NONE) {
break;
}
}
if (unit != USB_AC_ID_NONE) {
/* pins are 1-based */
USB_DEV_REQ_RCPT_IF, /* bmRequestType */
USB_AUDIO_SET_CUR, /* bRequest */
0, /* wValue */
/* feature unit and id */
1, /* wLength */
&data,
USB_FLAGS_SLEEP) == USB_SUCCESS) {
rval = USB_SUCCESS;
} else {
"set current pin selection failed");
}
} else {
"usb_ac_set_selector: nothing found");
}
return (rval);
}
/*
* usb_ac_set_control:
* apply func to all units of search_target type for both the
* requested channel and master channel
*/
static uint_t
{
"usb_ac_set_control: dir=%d type=%d ch=%d cntl=%d",
if ((channel != 0) &&
(all_or_one == USB_AC_FIND_ALL))) {
/* try master channel */
channel = 0;
}
return (id);
}
/*
* usb_ac_traverse_all_units:
* traverse all units starting with all IT or OT depending on direction.
* If no unit is found for the particular channel, try master channel
* If a matching unit is found, apply the function passed by
* the caller
*/
static uint_t
{
"usb_ac_traverse_all_units: "
"dir=%d type=%d ch=%d cntl=%d all=%d depth=%d",
/* keep track of recursion */
if ((*depth)++ > USB_AC_MAX_DEPTH) {
"Unit topology too complex, giving up");
return (USB_AC_ID_NONE);
}
/* is this an IT or OT? */
continue;
}
/* start at streaming term types */
if (dir & AUDIO_PLAY) {
if (d->wTerminalType !=
continue;
}
} else {
if (d->wTerminalType !=
continue;
}
}
/* find units connected to this unit */
if ((all_or_one == USB_AC_FIND_ONE) &&
(id != USB_AC_ID_NONE)) {
break;
}
}
(*depth)--;
}
/*
* usb_ac_set_monitor_gain_control:
* search for a feature unit between output terminal (OT) and
* input terminal. We are looking for a path between
* for example a microphone and a speaker through a feature unit
* and mixer
*/
static uint_t
{
"usb_ac_set_monitor_gain_control: dir=%d type=%d ch=%d cntl=%d",
/* is this an OT and not stream type? */
(d->wTerminalType != USB_AUDIO_TERM_TYPE_STREAMING)) {
/* find units connected to this unit */
if ((all_or_one == USB_AC_FIND_ONE) &&
(id != USB_AC_ID_NONE)) {
break;
}
}
}
return (id);
}
/*
*/
static void
{
"usb_ac_push_unit_id: pushing %d at %d", unit,
}
static void
{
"usb_ac_push_unit_id: popping %d at %d", unit,
}
/*
* usb_ac_show_traverse_path:
* display entire path, just for debugging
*/
static void
{
int i;
for (i = 0; i < uacp->usb_ac_traverse_path_index; i++) {
"traverse path %d: unit=%d type=%d",
i, uacp->usb_ac_traverse_path[i],
}
}
/*
* usb_ac_check_path:
* check for a specified type in the traverse path
*/
static int
{
int i;
for (i = 0; i < uacp->usb_ac_traverse_path_index; i++) {
return (USB_SUCCESS);
}
}
return (USB_FAILURE);
}
/*
* usb_ac_traverse_connections:
* traverse all units and for each unit with the right type, call
* func. If the func returns a success and search == USB_AC_FIND_ONE,
* we are done. If all is set then we continue until we terminate
* and input or output terminal.
* For audio play, we traverse columns starting from an input terminal
* to an output terminal while for record we traverse rows from output
* terminal to input terminal.
*/
static uint_t
{
"usb_ac_traverse_connections: "
"start=%d dir=%d type=%d ch=%d cntl=%d all=%d depth=%d",
all_or_one, *depth);
/* keep track of recursion depth */
if ((*depth)++ > USB_AC_MAX_DEPTH) {
"Unit topology too complex, giving up");
return (USB_AC_ID_NONE);
}
if (entry) {
"start=%d unit=%d entry=%d type=%d "
"done=%d found=%d",
/* did we find a matching type? */
"match: dir=%d unit=%d type=%d",
/* yes, no apply function to this unit */
(*count)++;
"func returned success, "
"unit=%d all=%d", unit,
/* are we done? */
if (all_or_one == USB_AC_FIND_ONE) {
break;
}
}
}
/* did we find the terminating unit */
continue;
}
if ((id != USB_AC_ID_NONE) &&
(all_or_one == USB_AC_FIND_ONE)) {
break;
}
}
}
(*depth)--;
}
/*
* Event Management
*
* usb_ac_disconnect_event_cb:
* The device has been disconnected. we either wait for
* detach or a reconnect event.
*/
static int
{
char *nm = "usb_ac_disconnect_event_cb";
/* setting to disconnect state will prevent replumbing */
if (uacp->usb_ac_busy_count) {
"device was disconnected while busy. "
"Data may have been lost");
}
return (USB_SUCCESS);
}
/*
* usb_ac_cpr_suspend:
*/
static int
{
"usb_ac_cpr_suspend: Begin");
"usb_ac_cpr_suspend: End");
return (USB_SUCCESS);
}
/*
* usb_ac_reconnect_event_cb:
* The device was disconnected but this instance not detached, probably
* because the device was busy.
* if the same device, continue with restoring state
* We should either be in the unplumbed state or the plumbed open
* state.
*/
static int
{
char *nm = "usb_ac_reconnect_event_cb";
/* check the plumbing state */
if (uacp->usb_ac_plumbing_state ==
}
if (uacp->usb_ac_busy_count) {
"busy device has been reconnected");
}
return (USB_SUCCESS);
}
/*
* usb_ac_cpr_resume:
* Restore device state
*/
static void
{
"usb_ac_cpr_resume");
}
/*
* usb_ac_restore_device_state:
* Set original configuration of the device
* enable wrq - this starts new transactions on the control pipe
*/
static void
{
int rval;
"usb_ac_restore_device_state:");
/* Check if we are talking to the same device */
/* change the device state from suspended to disconnected */
return;
}
if (uacpm) {
if (uacpm->acpm_wakeup_enabled) {
USB_REMOTE_WAKEUP_ENABLE)) != USB_SUCCESS) {
"usb_ac_restore_device_state: "
"remote wakeup "
"enable failed, rval=%d", rval);
}
}
}
/* prevent unplumbing */
(void) usb_ac_restore_audio_state(uacp, 0);
}
}
/*
* usb_ac_am_restore_state
*/
static void
usb_ac_am_restore_state(void *arg)
{
"usb_ac_am_restore_state: Begin");
if (uacp->usb_ac_plumbing_state ==
/*
* allow hid and usb_as to restore themselves
* (some handshake would have been preferable though)
*/
}
/* allow unplumbing */
"usb_ac_am_restore_state: End");
}
/*
* usb_ac_restore_audio_state:
*/
static int
{
"usb_ac_restore_audio_state: flag=%d", flag);
switch (uacp->usb_ac_plumbing_state) {
case USB_AC_STATE_PLUMBED:
break;
case USB_AC_STATE_UNPLUMBED:
return (USB_SUCCESS);
default:
return (USB_FAILURE);
}
/*
* increment busy_count again, it will be decremented
* in usb_ac_am_restore_state
*/
if (flag & USB_FLAGS_SLEEP) {
usb_ac_am_restore_state((void *)uacp);
} else {
return (USB_FAILURE);
}
}
return (USB_SUCCESS);
}
/*
* Mixer Callback Management
* NOTE: all mixer callbacks are serialized. we cannot be closed while
* we are in the middle of a callback. There needs to be a
* teardown first. We cannot be unplumbed as long as we are
* still open.
*
* usb_ac_setup:
* Send setup to usb_as if the first setup
* Check power is done in usb_ac_send_as_cmd()
*/
static int
{
int rval = AUDIO_SUCCESS;
return (AUDIO_FAILURE);
}
if (flag & AUDIO_PLAY) {
}
}
}
/*
* usb_ac_do_setup:
* Wrapper function for usb_ac_setup which can be called
* either from audio framework for usb_ac_set_format
*/
static int
{
int dir;
/*
* Handle multiple setup calls. Pass the setup call to usb_as only
* the first time so isoc pipe will be opened only once
*/
if (streams_infop->acs_setup_teardown_count++) {
"usb_ac_do_setup: more than one setup, cnt=%d",
return (USB_SUCCESS);
}
/* Send setup command to usb_as */
USB_SUCCESS) {
"usb_ac_do_setup: failure");
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
* usb_ac_teardown:
* Send teardown to usb_as if the last teardown
* Check power is done in usb_ac_send_as_cmd()
* NOTE: allow teardown when disconnected
*/
static void
{
if (flag & AUDIO_PLAY) {
}
if (flag & AUDIO_RECORD) {
}
}
/*
* usb_ac_do_teardown()
* Check power is done in usb_ac_send_as_cmd()
*/
static void
{
int dir;
/* There should be at least one matching setup call */
/*
* only this is the last teardown so that isoc pipe is closed
* only once
*/
if (--(streams_infop->acs_setup_teardown_count)) {
"cnt=%d",
return;
}
/* Send teardown command to usb_as */
(void *)NULL) != USB_SUCCESS) {
"usb_ac_do_teardown: failure");
return;
}
"usb_ac_do_teardown: End");
}
/*
* usb_ac_set_config:
* This routine will send control commands to get the max
* and min gain balance, calculate the gain to be set from the
* arguments and send another control command to set it.
* Check power is done here since we will access the default pipe
*/
static int
{
char *what;
int rval = AUDIO_FAILURE;
uchar_t n_channels = 0;
short muteval;
return (AUDIO_FAILURE);
}
return (AUDIO_FAILURE);
}
switch (command) {
case AM_SET_GAIN:
/*
* Set the gain for a channel. The audio mixer calculates the
* impact, if any, on the channel's gain.
*
* 0 <= gain <= AUDIO_MAX_GAIN
*
* arg1 --> gain
* arg2 --> channel #, 0 == left, 1 == right
*/
what = "gain";
/*
* We service the set_config command when the device is
* plumbed and opened.
*/
if (channel > n_channels) {
"usb_ac_set_config: channel(%d) passed is "
goto done;
}
count = 0;
/*
* If feature unit id could not be found, it probably means
* and we just return success if we haven't completed
* the registration with the mixer yet
*/
if (count == 0) {
"mixer=%d, no featureID, arg1=%d",
} else {
}
break;
case AM_SET_PORT:
what = "port";
break;
case AM_SET_MONITOR_GAIN:
what = "monitor gain";
dir = AUDIO_RECORD;
/*
* We service the set_config command when the device is
* plumbed and opened.
*/
if (channel > n_channels) {
"usb_ac_set_config: channel(%d) passed is "
goto done;
}
count = 0;
/*
* always return success since we told the mixer
* we always support this and sdtaudiocontrol displays
* monitor gain regardless.
*/
break;
case AM_OUTPUT_MUTE:
what = "mute";
/*
* arg1 != 0 --> mute
* arg1 == 0 --> unmute
* arg2 --> not used
*/
count = 0;
break;
case AM_MIC_BOOST:
what = "mic boost";
break;
default:
what = "unknown";
}
done:
/* Now it's safe to release access to other routines */
return (rval);
}
/*
* usb_ac_set_monitor_gain:
* called for each output terminal which supports
* from usb_ac_traverse_connections
*/
static int
{
"usb_ac_set_monitor_gain: ");
"id=%d dir=%d ch=%d cntl=%d gain=%d type=%d term type=0x%x",
/* log how we got here */
/* we only care about the ITs connected to real hw inputs */
switch (d->wTerminalType) {
return (USB_FAILURE);
default:
break;
}
/*
* we can only do this if the microphone is mixed into the
* audio output so look for a mixer first
*/
USB_SUCCESS) {
int i, id;
/* now look for a feature unit */
i--) {
case USB_AUDIO_MIXER_UNIT:
/* the FU should be before the mixer */
return (USB_FAILURE);
case USB_AUDIO_FEATURE_UNIT:
/*
* now set the volume
*/
/* try master channel */
USB_SUCCESS) {
return (USB_FAILURE);
}
}
return (USB_SUCCESS);
default:
continue;
}
}
}
return (USB_FAILURE);
}
/*
* usb_ac_set_gain is called for each feature unit which supports
* the requested controls from usb_ac_traverse_connections
* we still need to check whether this unit supports the requested
* control.
*/
static int
{
"usb_ac_set_gain: id=%d dir=%d ch=%d cntl=%d gain=%d",
return (USB_FAILURE);
}
"usb_ac_set_gain: getting max gain failed");
return (USB_FAILURE);
}
"usb_ac_set_gain: getting min gain failed");
return (USB_FAILURE);
}
"usb_ac_set_gain: getting cur gain failed");
return (USB_FAILURE);
}
/*
* Set the gain for a channel. The audio mixer calculates the
* impact, if any, on the channel's gain.
*
* 0 <= gain <= AUDIO_MAX_GAIN
*
* channel #, 0 == left, 1 == right
*/
if (gain == 0) {
} else {
}
"usb_ac_set_gain: ch=%d dir=%d max=%d min=%d gain=%d",
featureID) != USB_SUCCESS) {
"usb_ac_set_gain: setting volume failed");
return (USB_FAILURE);
}
"usb_ac_set_gain: getting cur gain failed");
}
"usb_ac_set_gain done: "
return (USB_SUCCESS);
}
/*
* usb_ac_set_format
* This mixer callback initiates a command to be sent to
* usb_as to select an alternate with the passed characteristics
* and also to set the sample frequency.
* Note that this may be called when a playing is going on in
* the streaming interface. To handle that, first stop
* command, send the set_format command down and then reopen
* after a set_format command. (2) Check power is done in
* usb_ac_send_as_cmd().
*/
static int
{
int dir;
int rval;
return (AUDIO_FAILURE);
}
if (plumb_infop == NULL) {
"usb_ac_set_format: no plumb info");
return (AUDIO_FAILURE);
}
/* isoc pipe not open and playing is not in progress */
if (streams_infop->acs_setup_teardown_count == 0) {
return ((rval == USB_SUCCESS) ?
}
/* isoc pipe is open and playing might be in progress */
/* Keep a copy of the old format */
sizeof (usb_audio_formats_t));
if (dir == AUDIO_PLAY) {
} else if (dir == AUDIO_RECORD) {
}
/* This blocks until the current isoc xfer is over */
/*
* Setting new alternate has failed, try restoring
* old one.
* If there is a bandwidth failure, hang around
* till bandwidth is available. Also we know that
* there is a matching alternate, so that can't fail.
*/
USB_FAILURE) {
/* We closed the pipe; reopen it */
return (AUDIO_FAILURE);
}
}
/* This should block until successful */
return (AUDIO_SUCCESS);
}
/*
* usb_ac_get_curr_n_channels:
* Return no. of channels from the current format table
*/
static int
{
}
/*
* usb_ac_get_cur_format:
* Get format for the current alternate
*/
static usb_audio_formats_t *
{
if (plumb_infop == NULL) {
"usb_ac_get_curr_format: no plumb info");
return (NULL);
}
return (&streams_infop->acs_cur_fmt);
}
/*
* usb_ac_send_format_cmd
* Sets format and get alternate setting that matches with
* the format from the usb_as playing or recording interface
* Send the set sample freq command down to usb_as.
*/
static int
{
return (USB_FAILURE);
}
"usb_ac_send_format_cmd: plumb_infop=0x%p, streams_infop=0x%p",
(void *)plumb_infop, (void *)streams_infop);
/* save format info */
/*
* Set format for the streaming interface with lower write queue
* This boils down to set_alternate interface command in
* usb_as and the reply mp contains the currently active
* alternate number that is stored in the as_req structure
*/
"usb_ac_send_format_cmd: failed");
return (USB_FAILURE);
} else {
/* store matching alternate number */
}
/* Set the sample rate */
&sample) != USB_SUCCESS) {
"usb_ac_send_format_cmd: setting format failed");
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
* usb_ac_start_play
* Send a start_play command down to usb_as
* Check power is done in usb_ac_send_as_cmd()
*/
static int
{
return (AUDIO_FAILURE);
}
"usb_ac_start_play: plumb_infop=0x%p, streams_infop=0x%p",
(void *)plumb_infop, (void *)streams_infop);
/* Check for continuous sample rate done in usb_as */
samples++;
}
/* Send setup command to usb_as */
(void *)&play_req) != USB_SUCCESS) {
"usb_ac_start_play: failure");
return (AUDIO_FAILURE);
}
return (AUDIO_SUCCESS);
}
/*
* usb_ac_stop_play:
* Wrapper function for usb_ac_do_stop_play and gets
* called from mixer framework.
*/
static void
{
return;
}
}
/*
* usb_ac_do_pause_play:
* Send a pause_play command to usb_as.
* Check power is done in usb_ac_send_as_cmd()
*/
static void
{
/* Send setup command to usb_as */
(void *)NULL) != USB_SUCCESS) {
"usb_ac_do_pause_play: failure");
}
}
/*
* usb_ac_start_record:
* Sends a start record command down to usb_as.
* Check power is done in usb_ac_send_as_cmd()
*/
static int
{
return (AUDIO_FAILURE);
}
/* Send setup command to usb_as */
(void *)&ahdl) != USB_SUCCESS) {
"usb_ac_start_record: failure");
return (AUDIO_FAILURE);
}
return (AUDIO_SUCCESS);
}
/*
* usb_ac_stop_record:
* Wrapper function for usb_ac_do_stop_record and is
* called form mixer framework.
*/
static void
{
}
/*
* usb_ac_do_stop_record:
* Sends a stop_record command down.
* Check power is done in usb_ac_send_as_cmd()
*/
static void
{
/* Send setup command to usb_as */
NULL) != USB_SUCCESS) {
"usb_ac_do_stop_record: failure");
}
}
/*
* Helper Functions for Mixer callbacks
*
* usb_ac_get_maxmin_volume:
* Send USBA command down to get the maximum or minimum gain balance
* Calculate min or max gain balance and return that. Return
* USB_FAILURE for failure cases
*/
static int
{
"usb_ac_get_maxmin_volume: channel=%d, cmd=%d dir=%d",
USB_DEV_REQ_RCPT_IF, /* bmRequestType */
cmd, /* bRequest */
/* feature unit and id */
2, /* wLength */
&data,
USB_FLAGS_SLEEP) != USB_SUCCESS) {
"usb_ac_get_maxmin_volume: failed, "
"cr=%d, cb=0x%x cmd=%d, data=0x%p",
return (USB_FAILURE);
}
"usb_ac_get_maxmin_volume: max_or_min=0x%x", *max_or_minp);
return (USB_SUCCESS);
}
/*
* usb_ac_set_volume:
* Send USBA command down to set the gain balance
*/
static int
int feature_unitID)
{
int rval = USB_FAILURE;
"usb_ac_set_volume: channel=%d gain=%d dir=%d FU=%d",
/* Construct the mblk_t from gain for sending to USBA */
if ((rval = usb_pipe_sync_ctrl_xfer(
USB_DEV_REQ_RCPT_IF, /* bmRequestType */
USB_AUDIO_SET_CUR, /* bRequest */
/* feature unit and id */
2, /* wLength */
&data, 0,
"usb_ac_set_volume: failed, cr=%d cb=0x%x",
}
return (rval);
}
/*
* usb_ac_set_mute is called for each unit that supports the
* requested control from usb_ac_traverse_connections
*/
static int
{
int rval = USB_FAILURE;
return (USB_FAILURE);
}
/* Construct the mblk_t for sending to USBA */
if ((rval = usb_pipe_sync_ctrl_xfer(
USB_DEV_REQ_RCPT_IF, /* bmRequestType */
USB_AUDIO_SET_CUR, /* bRequest */
/* feature unit and id */
1, /* wLength */
&data,
0, /* attributes */
}
return (rval);
}
/*
* usb_ac_send_as_cmd:
* Allocate message blk, send a command down to usb_as,
* wait for the reply and free the message
*
* although not really needed to raise power if sending to as
* it seems better to ensure that both interfaces are at full power
*/
static int
{
int rv;
int rval;
char *nm = "usb_ac_send_as_cmd";
if (rv != 0) {
rv);
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
*/
static void
{
}
static void
{
}
static void
{
"usb_ac_pm_busy_component: %d",
DDI_SUCCESS) {
"usb_ac_pm_busy_component failed: %d",
}
}
}
static void
{
DDI_SUCCESS) {
"usb_ac_pm_idle_component: %d",
}
}
}
/*
* handle read from plumbed drivers
*/
static void
usb_ac_reader(void *argp)
{
int rv;
timestruc_t tv = {0};
"%s%d read from %s%d, rv=%d",
}
}
/*
* setup threads to read from the other usb modules that may send unsolicited
* or asynchronous messages, which is only hid currently
*/
static int
{
int acp_inst;
char *acp_name;
char tq_nm[128];
int rv = USB_FAILURE;
char *nm = "usb_ac_plumb";
rv = USB_SUCCESS;
goto OUT;
}
goto OUT;
DDI_SLEEP) != DDI_SUCCESS)
goto OUT;
rv = USB_SUCCESS;
OUT:
return (rv);
}
static void
usb_ac_mux_plumbing_tq(void *arg)
{
}
static int
{
char tq_nm[128];
int rv = USB_FAILURE;
"usb_ac_do_plumbing: ddi_taskq_create failed");
goto OUT;
}
DDI_SLEEP) != DDI_SUCCESS) {
"usb_ac_do_plumbing: ddi_taskq_dispatch failed");
goto OUT;
}
rv = USB_SUCCESS;
OUT:
return (rv);
}
static void
usb_ac_mux_unplumbing_tq(void *arg)
{
}
static int
{
int rv = USB_FAILURE;
return (USB_SUCCESS);
"usb_ac_do_unplumbing: ddi_taskq_dispatch failed");
goto OUT;
}
rv = USB_SUCCESS;
OUT:
}
return (rv);
}
/*
* teardown threads to the other usb modules
* and clear structures as part of unplumbing
*/
static void
{
int acp_inst;
char *nm = "usb_ac_unplumb";
char *acp_name;
}
/*
* we bzero the streams info and plumbed structure
* since there is no guarantee that the next plumbing
* will be identical
*/
/* bzero the relevant plumbing structure */
}
}
/*ARGSUSED*/
static int
{
char *nm = "usb_ac_mux_plumbing";
/* get the usb_ac dip */
/* Access to the global variables is synchronized */
dinfo("%s: audio streams driver already plumbed\n",
return (USB_SUCCESS);
}
/* usb_as and hid should be attached but double check */
return (USB_FAILURE);
}
/* bring the device to full power */
/* avoid dips disappearing while we are plumbing */
/*
* walk all siblings and create the usb_ac<->usb_as and
* usb_ac<->hid streams. return of 0 indicates no or
*/
if (usb_ac_mux_walk_siblings(uacp) == 0) {
/* pretend that we are plumbed so we can unplumb */
(void) usb_ac_mux_unplumbing(uacp);
return (USB_FAILURE);
}
/* restore state if we have already registered with the mixer */
if (uacp->usb_ac_registered_with_mixer) {
dinfo("%s: already registered with mixer, restoring state\n",
(void) usb_ac_mux_unplumbing(uacp);
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
static int
{
int inst;
int i;
int maxlinked = 0;
char *nm = "usb_ac_mux_unplumbing";
return (USB_SUCCESS);
}
/* usb_ac might not have anything plumbed yet */
return (USB_SUCCESS);
}
/* do not allow detach if still busy */
if (uacp->usb_ac_busy_count) {
return (USB_FAILURE);
}
/* close ac-as and ac-hid streams */
for (i = 0; i < maxlinked; i++) {
/*
* we must save members of usb_ac_plumbed[] before calling
* usb_ac_unplumb() because it clears the structure
*/
continue;
}
/* must close stream first before destroying thread */
}
}
/* Wait till all activity in the default pipe has drained */
return (USB_SUCCESS);
}
/*
* walk all siblings and create the ac<->as and ac<->hid streams
*/
static int
{
int drv_instance;
char *drv_name;
int error;
int count = 0;
char *nm = "usb_ac_mux_walk_siblings";
/* ignore own dip */
continue;
}
/* ignore other dip other than usb_as and hid */
} else {
continue;
}
if (!i_ddi_devi_attached(child_dip)) {
continue;
}
if (DEVI_IS_DEVICE_REMOVED(child_dip)) {
continue;
}
if (error == 0) {
}
if (error) {
dinfo("%s: open of devt=(%d, 0x%x) failed error=%d\n",
return (0);
}
/* get registration data */
USB_SUCCESS) {
dinfo("%s: usb_ac_get_reg_data failed on "
return (0);
}
int rval;
/* push usb_ah module on top of hid */
if (error) {
dinfo("%s: ldi_ioctl I_PUSH failed on "
/* skip plumbing the hid driver */
continue;
}
} else {
/* should not be here */
dinfo("%s: %s - unknown module %s%d\n",
count--;
/* skip plumbing an unknown module */
continue;
}
if (error != USB_SUCCESS) {
dinfo("%s: %s - usb_ac_plumb failed for %s%d\n",
return (0);
}
count++;
}
count);
return (count);
}
/*
* usb_ac_find_default_port:
*/
static int
{
int i;
for (i = 0; i < 32; i++) {
if (port & (1 << i)) {
return (1 << i);
}
}
return (0);
}
/*
* Register with mixer only after first plumbing.
* Also do not register if earlier reg data
* couldn't be received from at least one
* streaming interface
*/
static int
{
char *nm = "usb_ac_mixer_registration";
dinfo("%s: %s infp=0x%p, dflts=0x%p, already registered=%d\n",
if (uacp->usb_ac_registered_with_mixer) {
return (USB_SUCCESS);
}
for (n = 0; n < USB_AC_MAX_AS_PLUMBED; n++) {
break;
}
}
/* Haven't found a streaming interface; fail mixer registration */
if (n > USB_AC_MAX_AS_PLUMBED) {
dinfo("%s: %s - no streaming interface found\n",
return (USB_FAILURE);
}
dflts->monitor_gain = 0;
dflts->hw_features = 0;
/*
* Fill out streaming interface specific stuff
* Note that we handle only one playing and one recording
* streaming interface at the most
*/
for (n = 0; n < USB_AC_MAX_AS_PLUMBED; n++) {
continue;
}
continue;
}
dinfo("%s: %s [%d] - setting format on %s%d\n",
/* set first format so get_featureID can be succeed */
/* check if any channel supports vol. control for this fmt */
USB_AUDIO_VOLUME_CONTROL)) != -1) {
ddtl("%s: %s [%d] - dir=%d featureID=%d\n",
break;
}
}
ddtl("%s: %s [%d] - mode=%d chs=%d default_gain=%d id=%d\n",
nplay++;
/* no support for mixer unit */
} else {
nrec++;
}
}
}
/* the rest */
return (USB_FAILURE);
}
return (USB_SUCCESS);
}
/*
* get registration data from usb_as driver unless we already
* have 2 registrations
*/
static int
{
char *nm = "usb_ac_get_reg_data";
/* if already registered, just setup data structures again */
if (uacp->usb_ac_registered_with_mixer) {
}
for (n = 0; n < USB_AC_MAX_AS_PLUMBED; n ++) {
/*
* We haven't received registration data
* from n-th streaming interface in the array
*/
break;
}
}
if (n >= USB_AC_MAX_AS_PLUMBED) {
dwarn("%s: More than 2 streaming interfaces (play "
return (USB_FAILURE);
}
/* take the stream reg struct with the same index */
(void *)streams_reg, n);
dinfo("%s: %s - ldi_ioctl failed for mixer registration, "
return (USB_FAILURE);
} else {
dinfo("%s: %s - usb_ac_streams[%d]: "
"play" : "record"));
return (rval);
}
}
/*
* setup plumbed and stream info structure, either initially or
* after replumbing
* On replumbing, str_idx and reg_idx are -1
*/
static int
int reg_idx)
{
int i;
char *nm = "usb_ac_setup_plumbed";
if (str_idx == -1) {
/* find a free streams info structure */
for (i = 0; i < USB_AC_MAX_AS_PLUMBED; i++) {
break;
}
}
ASSERT(i < USB_AC_MAX_AS_PLUMBED);
str_idx = i;
}
if (reg_idx == -1) {
/*
* find the corresponding registration structure, match
* on interface number and not on dip since dip may have
* changed
*/
for (i = 0; i < USB_AC_MAX_AS_PLUMBED; i++) {
break;
}
}
if (i == USB_AC_MAX_AS_PLUMBED) {
dinfo("%s: %s - no corresponding registration "
return (USB_FAILURE);
}
reg_idx = i;
}
return (USB_SUCCESS);
}
/*
* function to dump registration data
*/
static void
{
int n;
"usb_ac_print_reg_data: Begin valid=%d, play=%d, "
"n_formats=%d, compat srs ptr=0x%p",
for (n = 0; n < reg->reg_n_formats; n++) {
"format%d: alt=%d chns=%d prec=%d enc=%d", n,
}
"combinations: %d %d %d %d %d %d %d %d",
for (n = 0; n < USB_AS_N_FORMATS; n++) {
"reg_formats[%d] ptr=0x%p", n,
(void *)®->reg_formats[n]);
}
for (n = 0; n < USB_AS_N_CHANNELS; n++) {
}
for (n = 0; n < USB_AS_N_COMBINATIONS; n++) {
"reg_combinations[%d] ptr=0x%p", n,
(void *)®->reg_combinations[n]);
}
"usb_ac_print_reg_data: End");
}
static int
{
int rval = USB_SUCCESS;
char *nm = "usb_ac_online_siblings";
/* Online the child_dip of usb_as and hid, if not already */
NDI_SUCCESS) {
dinfo("%s: failed to online device %s%d\n",
/* only onlining usb_as is fatal */
"usb_as") == 0) {
rval = USB_FAILURE;
break;
}
}
}
}
return (rval);
}
/*
* hold all audio children before or after plumbing
* online usb_as and hid, if not already
*/
static void
{
int circ;
char *nm = "usb_ac_hold_siblings";
/* hold all siblings and ourselves */
/* hold the children */
}
}
/*
* release all audio children before or after plumbing
*/
static void
{
int circ;
char *nm = "usb_ac_rele_siblings";
/* release all siblings and ourselves */
}
}