Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (Tentative) USB Audio Driver for ALSA |
| 3 | * |
| 4 | * Mixer control part |
| 5 | * |
| 6 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
| 7 | * |
| 8 | * Many codes borrowed from audio.c by |
| 9 | * Alan Cox (alan@lxorguk.ukuu.org.uk) |
| 10 | * Thomas Sailer (sailer@ife.ee.ethz.ch) |
| 11 | * |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | * |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/bitops.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/list.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/usb.h> |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 35 | #include <linux/usb/audio.h> |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <sound/core.h> |
| 38 | #include <sound/control.h> |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 39 | #include <sound/hwdep.h> |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 40 | #include <sound/info.h> |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 41 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include "usbaudio.h" |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* |
| 46 | */ |
| 47 | |
| 48 | /* ignore error from controls - for debugging */ |
| 49 | /* #define IGNORE_CTL_ERROR */ |
| 50 | |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 51 | /* |
| 52 | * Sound Blaster remote control configuration |
| 53 | * |
| 54 | * format of remote control data: |
| 55 | * Extigy: xx 00 |
| 56 | * Audigy 2 NX: 06 80 xx 00 00 00 |
| 57 | * Live! 24-bit: 06 80 xx yy 22 83 |
| 58 | */ |
| 59 | static const struct rc_config { |
| 60 | u32 usb_id; |
| 61 | u8 offset; |
| 62 | u8 length; |
| 63 | u8 packet_length; |
Phillip Michael Jordan | b9c196e | 2008-08-05 11:01:00 +0200 | [diff] [blame] | 64 | u8 min_packet_length; /* minimum accepted length of the URB result */ |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 65 | u8 mute_mixer_id; |
| 66 | u32 mute_code; |
| 67 | } rc_configs[] = { |
Phillip Michael Jordan | b9c196e | 2008-08-05 11:01:00 +0200 | [diff] [blame] | 68 | { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ |
| 69 | { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ |
| 70 | { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ |
Andrea Borgia | 3195954 | 2009-01-07 22:58:50 +0100 | [diff] [blame] | 71 | { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 74 | #define MAX_ID_ELEMS 256 |
| 75 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 76 | struct usb_mixer_interface { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 77 | struct snd_usb_audio *chip; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 78 | unsigned int ctrlif; |
| 79 | struct list_head list; |
| 80 | unsigned int ignore_ctl_error; |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 81 | struct urb *urb; |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 82 | /* array[MAX_ID_ELEMS], indexed by unit id */ |
| 83 | struct usb_mixer_elem_info **id_elems; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 84 | |
| 85 | /* Sound Blaster remote control stuff */ |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 86 | const struct rc_config *rc_cfg; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 87 | u32 rc_code; |
| 88 | wait_queue_head_t rc_waitq; |
| 89 | struct urb *rc_urb; |
| 90 | struct usb_ctrlrequest *rc_setup_packet; |
| 91 | u8 rc_buffer[6]; |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 92 | |
| 93 | u8 audigy2nx_leds[3]; |
Clemens Ladisch | 468b8fd | 2009-07-13 11:39:29 +0200 | [diff] [blame] | 94 | u8 xonar_u1_status; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | struct usb_audio_term { |
| 99 | int id; |
| 100 | int type; |
| 101 | int channels; |
| 102 | unsigned int chconfig; |
| 103 | int name; |
| 104 | }; |
| 105 | |
| 106 | struct usbmix_name_map; |
| 107 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 108 | struct mixer_build { |
| 109 | struct snd_usb_audio *chip; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 110 | struct usb_mixer_interface *mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | unsigned char *buffer; |
| 112 | unsigned int buflen; |
Jaroslav Kysela | 291186e | 2010-02-16 11:55:18 +0100 | [diff] [blame] | 113 | DECLARE_BITMAP(unitbitmap, MAX_ID_ELEMS); |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 114 | struct usb_audio_term oterm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | const struct usbmix_name_map *map; |
Clemens Ladisch | 8e062ec | 2005-04-22 15:49:52 +0200 | [diff] [blame] | 116 | const struct usbmix_selector_map *selector_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 119 | #define MAX_CHANNELS 10 /* max logical channels */ |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | struct usb_mixer_elem_info { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 122 | struct usb_mixer_interface *mixer; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 123 | struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */ |
| 124 | struct snd_ctl_elem_id *elem_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | unsigned int id; |
| 126 | unsigned int control; /* CS or ICN (high byte) */ |
| 127 | unsigned int cmask; /* channel mask bitmap: 0 = master */ |
| 128 | int channels; |
| 129 | int val_type; |
| 130 | int min, max, res; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 131 | int dBmin, dBmax; |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 132 | int cached; |
| 133 | int cache_val[MAX_CHANNELS]; |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 134 | u8 initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | |
| 138 | enum { |
| 139 | USB_FEATURE_NONE = 0, |
| 140 | USB_FEATURE_MUTE = 1, |
| 141 | USB_FEATURE_VOLUME, |
| 142 | USB_FEATURE_BASS, |
| 143 | USB_FEATURE_MID, |
| 144 | USB_FEATURE_TREBLE, |
| 145 | USB_FEATURE_GEQ, |
| 146 | USB_FEATURE_AGC, |
| 147 | USB_FEATURE_DELAY, |
| 148 | USB_FEATURE_BASSBOOST, |
| 149 | USB_FEATURE_LOUDNESS |
| 150 | }; |
| 151 | |
| 152 | enum { |
| 153 | USB_MIXER_BOOLEAN, |
| 154 | USB_MIXER_INV_BOOLEAN, |
| 155 | USB_MIXER_S8, |
| 156 | USB_MIXER_U8, |
| 157 | USB_MIXER_S16, |
| 158 | USB_MIXER_U16, |
| 159 | }; |
| 160 | |
| 161 | enum { |
| 162 | USB_PROC_UPDOWN = 1, |
| 163 | USB_PROC_UPDOWN_SWITCH = 1, |
| 164 | USB_PROC_UPDOWN_MODE_SEL = 2, |
| 165 | |
| 166 | USB_PROC_PROLOGIC = 2, |
| 167 | USB_PROC_PROLOGIC_SWITCH = 1, |
| 168 | USB_PROC_PROLOGIC_MODE_SEL = 2, |
| 169 | |
| 170 | USB_PROC_3DENH = 3, |
| 171 | USB_PROC_3DENH_SWITCH = 1, |
| 172 | USB_PROC_3DENH_SPACE = 2, |
| 173 | |
| 174 | USB_PROC_REVERB = 4, |
| 175 | USB_PROC_REVERB_SWITCH = 1, |
| 176 | USB_PROC_REVERB_LEVEL = 2, |
| 177 | USB_PROC_REVERB_TIME = 3, |
| 178 | USB_PROC_REVERB_DELAY = 4, |
| 179 | |
| 180 | USB_PROC_CHORUS = 5, |
| 181 | USB_PROC_CHORUS_SWITCH = 1, |
| 182 | USB_PROC_CHORUS_LEVEL = 2, |
| 183 | USB_PROC_CHORUS_RATE = 3, |
| 184 | USB_PROC_CHORUS_DEPTH = 4, |
| 185 | |
| 186 | USB_PROC_DCR = 6, |
| 187 | USB_PROC_DCR_SWITCH = 1, |
| 188 | USB_PROC_DCR_RATIO = 2, |
| 189 | USB_PROC_DCR_MAX_AMP = 3, |
| 190 | USB_PROC_DCR_THRESHOLD = 4, |
| 191 | USB_PROC_DCR_ATTACK = 5, |
| 192 | USB_PROC_DCR_RELEASE = 6, |
| 193 | }; |
| 194 | |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 195 | /*E-mu 0202(0404) eXtension Unit(XU) control*/ |
| 196 | enum { |
| 197 | USB_XU_CLOCK_RATE = 0xe301, |
| 198 | USB_XU_CLOCK_SOURCE = 0xe302, |
| 199 | USB_XU_DIGITAL_IO_STATUS = 0xe303, |
| 200 | USB_XU_DEVICE_OPTIONS = 0xe304, |
| 201 | USB_XU_DIRECT_MONITORING = 0xe305, |
| 202 | USB_XU_METERING = 0xe306 |
| 203 | }; |
| 204 | enum { |
| 205 | USB_XU_CLOCK_SOURCE_SELECTOR = 0x02, /* clock source*/ |
| 206 | USB_XU_CLOCK_RATE_SELECTOR = 0x03, /* clock rate */ |
| 207 | USB_XU_DIGITAL_FORMAT_SELECTOR = 0x01, /* the spdif format */ |
| 208 | USB_XU_SOFT_LIMIT_SELECTOR = 0x03 /* soft limiter */ |
| 209 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * manual mapping of mixer names |
| 213 | * if the mixer topology is too complicated and the parsed names are |
| 214 | * ambiguous, add the entries in usbmixer_maps.c. |
| 215 | */ |
| 216 | #include "usbmixer_maps.c" |
| 217 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 218 | static const struct usbmix_name_map * |
| 219 | find_map(struct mixer_build *state, int unitid, int control) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 221 | const struct usbmix_name_map *p = state->map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 223 | if (!p) |
| 224 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | for (p = state->map; p->id; p++) { |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 227 | if (p->id == unitid && |
| 228 | (!control || !p->control || control == p->control)) |
| 229 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 231 | return NULL; |
| 232 | } |
| 233 | |
| 234 | /* get the mapped name if the unit matches */ |
| 235 | static int |
| 236 | check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen) |
| 237 | { |
| 238 | if (!p || !p->name) |
| 239 | return 0; |
| 240 | |
| 241 | buflen--; |
| 242 | return strlcpy(buf, p->name, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /* check whether the control should be ignored */ |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 246 | static inline int |
| 247 | check_ignored_ctl(const struct usbmix_name_map *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 249 | if (!p || p->name || p->dB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | return 0; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 251 | return 1; |
| 252 | } |
| 253 | |
| 254 | /* dB mapping */ |
| 255 | static inline void check_mapped_dB(const struct usbmix_name_map *p, |
| 256 | struct usb_mixer_elem_info *cval) |
| 257 | { |
| 258 | if (p && p->dB) { |
| 259 | cval->dBmin = p->dB->min; |
| 260 | cval->dBmax = p->dB->max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Clemens Ladisch | 8e062ec | 2005-04-22 15:49:52 +0200 | [diff] [blame] | 264 | /* get the mapped selector source name */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 265 | static int check_mapped_selector_name(struct mixer_build *state, int unitid, |
Clemens Ladisch | 8e062ec | 2005-04-22 15:49:52 +0200 | [diff] [blame] | 266 | int index, char *buf, int buflen) |
| 267 | { |
| 268 | const struct usbmix_selector_map *p; |
| 269 | |
| 270 | if (! state->selector_map) |
| 271 | return 0; |
| 272 | for (p = state->selector_map; p->id; p++) { |
| 273 | if (p->id == unitid && index < p->count) |
| 274 | return strlcpy(buf, p->names[index], buflen); |
| 275 | } |
| 276 | return 0; |
| 277 | } |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /* |
| 280 | * find an audio control unit with the given unit id |
| 281 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 282 | static void *find_audio_control_unit(struct mixer_build *state, unsigned char unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | unsigned char *p; |
| 285 | |
| 286 | p = NULL; |
| 287 | while ((p = snd_usb_find_desc(state->buffer, state->buflen, p, |
| 288 | USB_DT_CS_INTERFACE)) != NULL) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 289 | if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC_EXTENSION_UNIT_V1 && p[3] == unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return p; |
| 291 | } |
| 292 | return NULL; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /* |
| 297 | * copy a string with the given id |
| 298 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 299 | static int snd_usb_copy_string_desc(struct mixer_build *state, int index, char *buf, int maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { |
| 301 | int len = usb_string(state->chip->dev, index, buf, maxlen - 1); |
| 302 | buf[len] = 0; |
| 303 | return len; |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | * convert from the byte/word on usb descriptor to the zero-based integer |
| 308 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 309 | static int convert_signed_value(struct usb_mixer_elem_info *cval, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | { |
| 311 | switch (cval->val_type) { |
| 312 | case USB_MIXER_BOOLEAN: |
| 313 | return !!val; |
| 314 | case USB_MIXER_INV_BOOLEAN: |
| 315 | return !val; |
| 316 | case USB_MIXER_U8: |
| 317 | val &= 0xff; |
| 318 | break; |
| 319 | case USB_MIXER_S8: |
| 320 | val &= 0xff; |
| 321 | if (val >= 0x80) |
| 322 | val -= 0x100; |
| 323 | break; |
| 324 | case USB_MIXER_U16: |
| 325 | val &= 0xffff; |
| 326 | break; |
| 327 | case USB_MIXER_S16: |
| 328 | val &= 0xffff; |
| 329 | if (val >= 0x8000) |
| 330 | val -= 0x10000; |
| 331 | break; |
| 332 | } |
| 333 | return val; |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * convert from the zero-based int to the byte/word for usb descriptor |
| 338 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 339 | static int convert_bytes_value(struct usb_mixer_elem_info *cval, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
| 341 | switch (cval->val_type) { |
| 342 | case USB_MIXER_BOOLEAN: |
| 343 | return !!val; |
| 344 | case USB_MIXER_INV_BOOLEAN: |
| 345 | return !val; |
| 346 | case USB_MIXER_S8: |
| 347 | case USB_MIXER_U8: |
| 348 | return val & 0xff; |
| 349 | case USB_MIXER_S16: |
| 350 | case USB_MIXER_U16: |
| 351 | return val & 0xffff; |
| 352 | } |
| 353 | return 0; /* not reached */ |
| 354 | } |
| 355 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 356 | static int get_relative_value(struct usb_mixer_elem_info *cval, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
| 358 | if (! cval->res) |
| 359 | cval->res = 1; |
| 360 | if (val < cval->min) |
| 361 | return 0; |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 362 | else if (val >= cval->max) |
| 363 | return (cval->max - cval->min + cval->res - 1) / cval->res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | else |
| 365 | return (val - cval->min) / cval->res; |
| 366 | } |
| 367 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 368 | static int get_abs_value(struct usb_mixer_elem_info *cval, int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
| 370 | if (val < 0) |
| 371 | return cval->min; |
| 372 | if (! cval->res) |
| 373 | cval->res = 1; |
| 374 | val *= cval->res; |
| 375 | val += cval->min; |
| 376 | if (val > cval->max) |
| 377 | return cval->max; |
| 378 | return val; |
| 379 | } |
| 380 | |
| 381 | |
| 382 | /* |
| 383 | * retrieve a mixer value |
| 384 | */ |
| 385 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 386 | static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
| 388 | unsigned char buf[2]; |
| 389 | int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; |
| 390 | int timeout = 10; |
| 391 | |
| 392 | while (timeout-- > 0) { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 393 | if (snd_usb_ctl_msg(cval->mixer->chip->dev, |
| 394 | usb_rcvctrlpipe(cval->mixer->chip->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | request, |
| 396 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 397 | validx, cval->mixer->ctrlif | (cval->id << 8), |
Thomas Reitmayr | a04395e | 2007-05-15 11:47:48 +0200 | [diff] [blame] | 398 | buf, val_len, 100) >= val_len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); |
| 400 | return 0; |
| 401 | } |
| 402 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 403 | snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n", |
| 404 | request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | return -EINVAL; |
| 406 | } |
| 407 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 408 | static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 410 | return get_ctl_value(cval, UAC_GET_CUR, validx, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* channel = 0: master, 1 = first channel */ |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 414 | static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval, |
| 415 | int channel, int *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 417 | return get_ctl_value(cval, UAC_GET_CUR, (cval->control << 8) | channel, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 420 | static int get_cur_mix_value(struct usb_mixer_elem_info *cval, |
| 421 | int channel, int index, int *value) |
| 422 | { |
| 423 | int err; |
| 424 | |
| 425 | if (cval->cached & (1 << channel)) { |
| 426 | *value = cval->cache_val[index]; |
| 427 | return 0; |
| 428 | } |
| 429 | err = get_cur_mix_raw(cval, channel, value); |
| 430 | if (err < 0) { |
| 431 | if (!cval->mixer->ignore_ctl_error) |
| 432 | snd_printd(KERN_ERR "cannot get current value for " |
| 433 | "control %d ch %d: err = %d\n", |
| 434 | cval->control, channel, err); |
| 435 | return err; |
| 436 | } |
| 437 | cval->cached |= 1 << channel; |
| 438 | cval->cache_val[index] = *value; |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | /* |
| 444 | * set a mixer value |
| 445 | */ |
| 446 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 447 | static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | unsigned char buf[2]; |
| 450 | int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; |
| 451 | int timeout = 10; |
| 452 | |
| 453 | value_set = convert_bytes_value(cval, value_set); |
| 454 | buf[0] = value_set & 0xff; |
| 455 | buf[1] = (value_set >> 8) & 0xff; |
Viral Mehta | cf3f913 | 2009-04-03 13:08:14 +0530 | [diff] [blame] | 456 | while (timeout-- > 0) |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 457 | if (snd_usb_ctl_msg(cval->mixer->chip->dev, |
| 458 | usb_sndctrlpipe(cval->mixer->chip->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | request, |
| 460 | USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 461 | validx, cval->mixer->ctrlif | (cval->id << 8), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | buf, val_len, 100) >= 0) |
| 463 | return 0; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 464 | snd_printdd(KERN_ERR "cannot set ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d, data = %#x/%#x\n", |
| 465 | request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type, buf[0], buf[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return -EINVAL; |
| 467 | } |
| 468 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 469 | static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 471 | return set_ctl_value(cval, UAC_SET_CUR, validx, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 474 | static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, |
| 475 | int index, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 477 | int err; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 478 | err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel, |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 479 | value); |
| 480 | if (err < 0) |
| 481 | return err; |
| 482 | cval->cached |= 1 << channel; |
| 483 | cval->cache_val[index] = value; |
| 484 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 487 | /* |
| 488 | * TLV callback for mixer volume controls |
| 489 | */ |
| 490 | static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, |
| 491 | unsigned int size, unsigned int __user *_tlv) |
| 492 | { |
| 493 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Takashi Iwai | b8e1c73 | 2009-06-16 14:04:37 +0200 | [diff] [blame] | 494 | DECLARE_TLV_DB_MINMAX(scale, 0, 0); |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 495 | |
| 496 | if (size < sizeof(scale)) |
| 497 | return -ENOMEM; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 498 | scale[2] = cval->dBmin; |
| 499 | scale[3] = cval->dBmax; |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 500 | if (copy_to_user(_tlv, scale, sizeof(scale))) |
| 501 | return -EFAULT; |
| 502 | return 0; |
| 503 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | /* |
| 506 | * parser routines begin here... |
| 507 | */ |
| 508 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 509 | static int parse_audio_unit(struct mixer_build *state, int unitid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | |
| 512 | /* |
| 513 | * check if the input/output channel routing is enabled on the given bitmap. |
| 514 | * used for mixer unit parser |
| 515 | */ |
| 516 | static int check_matrix_bitmap(unsigned char *bmap, int ich, int och, int num_outs) |
| 517 | { |
| 518 | int idx = ich * num_outs + och; |
| 519 | return bmap[idx >> 3] & (0x80 >> (idx & 7)); |
| 520 | } |
| 521 | |
| 522 | |
| 523 | /* |
| 524 | * add an alsa control element |
| 525 | * search and increment the index until an empty slot is found. |
| 526 | * |
| 527 | * if failed, give up and free the control instance. |
| 528 | */ |
| 529 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 530 | static int add_control_to_empty(struct mixer_build *state, struct snd_kcontrol *kctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 532 | struct usb_mixer_elem_info *cval = kctl->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | int err; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 534 | |
| 535 | while (snd_ctl_find_id(state->chip->card, &kctl->id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | kctl->id.index++; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 537 | if ((err = snd_ctl_add(state->chip->card, kctl)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | snd_printd(KERN_ERR "cannot add control (err = %d)\n", err); |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 539 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 541 | cval->elem_id = &kctl->id; |
| 542 | cval->next_id_elem = state->mixer->id_elems[cval->id]; |
| 543 | state->mixer->id_elems[cval->id] = cval; |
| 544 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | |
| 548 | /* |
| 549 | * get a terminal name string |
| 550 | */ |
| 551 | |
| 552 | static struct iterm_name_combo { |
| 553 | int type; |
| 554 | char *name; |
| 555 | } iterm_names[] = { |
| 556 | { 0x0300, "Output" }, |
| 557 | { 0x0301, "Speaker" }, |
| 558 | { 0x0302, "Headphone" }, |
| 559 | { 0x0303, "HMD Audio" }, |
| 560 | { 0x0304, "Desktop Speaker" }, |
| 561 | { 0x0305, "Room Speaker" }, |
| 562 | { 0x0306, "Com Speaker" }, |
| 563 | { 0x0307, "LFE" }, |
| 564 | { 0x0600, "External In" }, |
| 565 | { 0x0601, "Analog In" }, |
| 566 | { 0x0602, "Digital In" }, |
| 567 | { 0x0603, "Line" }, |
| 568 | { 0x0604, "Legacy In" }, |
| 569 | { 0x0605, "IEC958 In" }, |
| 570 | { 0x0606, "1394 DA Stream" }, |
| 571 | { 0x0607, "1394 DV Stream" }, |
| 572 | { 0x0700, "Embedded" }, |
| 573 | { 0x0701, "Noise Source" }, |
| 574 | { 0x0702, "Equalization Noise" }, |
| 575 | { 0x0703, "CD" }, |
| 576 | { 0x0704, "DAT" }, |
| 577 | { 0x0705, "DCC" }, |
| 578 | { 0x0706, "MiniDisk" }, |
| 579 | { 0x0707, "Analog Tape" }, |
| 580 | { 0x0708, "Phonograph" }, |
| 581 | { 0x0709, "VCR Audio" }, |
| 582 | { 0x070a, "Video Disk Audio" }, |
| 583 | { 0x070b, "DVD Audio" }, |
| 584 | { 0x070c, "TV Tuner Audio" }, |
| 585 | { 0x070d, "Satellite Rec Audio" }, |
| 586 | { 0x070e, "Cable Tuner Audio" }, |
| 587 | { 0x070f, "DSS Audio" }, |
| 588 | { 0x0710, "Radio Receiver" }, |
| 589 | { 0x0711, "Radio Transmitter" }, |
| 590 | { 0x0712, "Multi-Track Recorder" }, |
| 591 | { 0x0713, "Synthesizer" }, |
| 592 | { 0 }, |
| 593 | }; |
| 594 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 595 | static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | unsigned char *name, int maxlen, int term_only) |
| 597 | { |
| 598 | struct iterm_name_combo *names; |
| 599 | |
| 600 | if (iterm->name) |
| 601 | return snd_usb_copy_string_desc(state, iterm->name, name, maxlen); |
| 602 | |
| 603 | /* virtual type - not a real terminal */ |
| 604 | if (iterm->type >> 16) { |
| 605 | if (term_only) |
| 606 | return 0; |
| 607 | switch (iterm->type >> 16) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 608 | case UAC_SELECTOR_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | strcpy(name, "Selector"); return 8; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 610 | case UAC_PROCESSING_UNIT_V1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | strcpy(name, "Process Unit"); return 12; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 612 | case UAC_EXTENSION_UNIT_V1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | strcpy(name, "Ext Unit"); return 8; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 614 | case UAC_MIXER_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | strcpy(name, "Mixer"); return 5; |
| 616 | default: |
| 617 | return sprintf(name, "Unit %d", iterm->id); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | switch (iterm->type & 0xff00) { |
| 622 | case 0x0100: |
| 623 | strcpy(name, "PCM"); return 3; |
| 624 | case 0x0200: |
| 625 | strcpy(name, "Mic"); return 3; |
| 626 | case 0x0400: |
| 627 | strcpy(name, "Headset"); return 7; |
| 628 | case 0x0500: |
| 629 | strcpy(name, "Phone"); return 5; |
| 630 | } |
| 631 | |
| 632 | for (names = iterm_names; names->type; names++) |
| 633 | if (names->type == iterm->type) { |
| 634 | strcpy(name, names->name); |
| 635 | return strlen(names->name); |
| 636 | } |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | /* |
| 642 | * parse the source unit recursively until it reaches to a terminal |
| 643 | * or a branched unit. |
| 644 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 645 | static int check_input_term(struct mixer_build *state, int id, struct usb_audio_term *term) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
| 647 | unsigned char *p1; |
| 648 | |
| 649 | memset(term, 0, sizeof(*term)); |
| 650 | while ((p1 = find_audio_control_unit(state, id)) != NULL) { |
| 651 | term->id = id; |
| 652 | switch (p1[2]) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 653 | case UAC_INPUT_TERMINAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | term->type = combine_word(p1 + 4); |
| 655 | term->channels = p1[7]; |
| 656 | term->chconfig = combine_word(p1 + 8); |
| 657 | term->name = p1[11]; |
| 658 | return 0; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 659 | case UAC_FEATURE_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | id = p1[4]; |
| 661 | break; /* continue to parse */ |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 662 | case UAC_MIXER_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | term->type = p1[2] << 16; /* virtual type */ |
| 664 | term->channels = p1[5 + p1[4]]; |
| 665 | term->chconfig = combine_word(p1 + 6 + p1[4]); |
| 666 | term->name = p1[p1[0] - 1]; |
| 667 | return 0; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 668 | case UAC_SELECTOR_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | /* call recursively to retrieve the channel info */ |
| 670 | if (check_input_term(state, p1[5], term) < 0) |
| 671 | return -ENODEV; |
| 672 | term->type = p1[2] << 16; /* virtual type */ |
| 673 | term->id = id; |
| 674 | term->name = p1[9 + p1[0] - 1]; |
| 675 | return 0; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 676 | case UAC_PROCESSING_UNIT_V1: |
| 677 | case UAC_EXTENSION_UNIT_V1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if (p1[6] == 1) { |
| 679 | id = p1[7]; |
| 680 | break; /* continue to parse */ |
| 681 | } |
| 682 | term->type = p1[2] << 16; /* virtual type */ |
| 683 | term->channels = p1[7 + p1[6]]; |
| 684 | term->chconfig = combine_word(p1 + 8 + p1[6]); |
| 685 | term->name = p1[12 + p1[6] + p1[11 + p1[6]]]; |
| 686 | return 0; |
| 687 | default: |
| 688 | return -ENODEV; |
| 689 | } |
| 690 | } |
| 691 | return -ENODEV; |
| 692 | } |
| 693 | |
| 694 | |
| 695 | /* |
| 696 | * Feature Unit |
| 697 | */ |
| 698 | |
| 699 | /* feature unit control information */ |
| 700 | struct usb_feature_control_info { |
| 701 | const char *name; |
| 702 | unsigned int type; /* control type (mute, volume, etc.) */ |
| 703 | }; |
| 704 | |
| 705 | static struct usb_feature_control_info audio_feature_info[] = { |
| 706 | { "Mute", USB_MIXER_INV_BOOLEAN }, |
| 707 | { "Volume", USB_MIXER_S16 }, |
| 708 | { "Tone Control - Bass", USB_MIXER_S8 }, |
| 709 | { "Tone Control - Mid", USB_MIXER_S8 }, |
| 710 | { "Tone Control - Treble", USB_MIXER_S8 }, |
| 711 | { "Graphic Equalizer", USB_MIXER_S8 }, /* FIXME: not implemeted yet */ |
| 712 | { "Auto Gain Control", USB_MIXER_BOOLEAN }, |
| 713 | { "Delay Control", USB_MIXER_U16 }, |
| 714 | { "Bass Boost", USB_MIXER_BOOLEAN }, |
| 715 | { "Loudness", USB_MIXER_BOOLEAN }, |
| 716 | }; |
| 717 | |
| 718 | |
| 719 | /* private_free callback */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 720 | static void usb_mixer_elem_free(struct snd_kcontrol *kctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
Jesper Juhl | 4d57277 | 2005-05-30 17:30:32 +0200 | [diff] [blame] | 722 | kfree(kctl->private_data); |
| 723 | kctl->private_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | |
| 727 | /* |
| 728 | * interface to ALSA control for feature/mixer units |
| 729 | */ |
| 730 | |
| 731 | /* |
| 732 | * retrieve the minimum and maximum values for the specified control |
| 733 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 734 | static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | /* for failsafe */ |
| 737 | cval->min = default_min; |
| 738 | cval->max = cval->min + 1; |
| 739 | cval->res = 1; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 740 | cval->dBmin = cval->dBmax = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | if (cval->val_type == USB_MIXER_BOOLEAN || |
| 743 | cval->val_type == USB_MIXER_INV_BOOLEAN) { |
| 744 | cval->initialized = 1; |
| 745 | } else { |
| 746 | int minchn = 0; |
| 747 | if (cval->cmask) { |
| 748 | int i; |
| 749 | for (i = 0; i < MAX_CHANNELS; i++) |
| 750 | if (cval->cmask & (1 << i)) { |
| 751 | minchn = i + 1; |
| 752 | break; |
| 753 | } |
| 754 | } |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 755 | if (get_ctl_value(cval, UAC_GET_MAX, (cval->control << 8) | minchn, &cval->max) < 0 || |
| 756 | get_ctl_value(cval, UAC_GET_MIN, (cval->control << 8) | minchn, &cval->min) < 0) { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 757 | snd_printd(KERN_ERR "%d:%d: cannot get min/max values for control %d (id %d)\n", |
| 758 | cval->id, cval->mixer->ctrlif, cval->control, cval->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | return -EINVAL; |
| 760 | } |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 761 | if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | cval->res = 1; |
| 763 | } else { |
| 764 | int last_valid_res = cval->res; |
| 765 | |
| 766 | while (cval->res > 1) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 767 | if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | break; |
| 769 | cval->res /= 2; |
| 770 | } |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 771 | if (get_ctl_value(cval, UAC_GET_RES, (cval->control << 8) | minchn, &cval->res) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | cval->res = last_valid_res; |
| 773 | } |
| 774 | if (cval->res == 0) |
| 775 | cval->res = 1; |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 776 | |
| 777 | /* Additional checks for the proper resolution |
| 778 | * |
| 779 | * Some devices report smaller resolutions than actually |
| 780 | * reacting. They don't return errors but simply clip |
| 781 | * to the lower aligned value. |
| 782 | */ |
| 783 | if (cval->min + cval->res < cval->max) { |
| 784 | int last_valid_res = cval->res; |
| 785 | int saved, test, check; |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 786 | get_cur_mix_raw(cval, minchn, &saved); |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 787 | for (;;) { |
| 788 | test = saved; |
| 789 | if (test < cval->max) |
| 790 | test += cval->res; |
| 791 | else |
| 792 | test -= cval->res; |
| 793 | if (test < cval->min || test > cval->max || |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 794 | set_cur_mix_value(cval, minchn, 0, test) || |
| 795 | get_cur_mix_raw(cval, minchn, &check)) { |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 796 | cval->res = last_valid_res; |
| 797 | break; |
| 798 | } |
| 799 | if (test == check) |
| 800 | break; |
| 801 | cval->res *= 2; |
| 802 | } |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 803 | set_cur_mix_value(cval, minchn, 0, saved); |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | cval->initialized = 1; |
| 807 | } |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 808 | |
| 809 | /* USB descriptions contain the dB scale in 1/256 dB unit |
| 810 | * while ALSA TLV contains in 1/100 dB unit |
| 811 | */ |
| 812 | cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256; |
| 813 | cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256; |
| 814 | if (cval->dBmin > cval->dBmax) { |
| 815 | /* something is wrong; assume it's either from/to 0dB */ |
| 816 | if (cval->dBmin < 0) |
| 817 | cval->dBmax = 0; |
| 818 | else if (cval->dBmin > 0) |
| 819 | cval->dBmin = 0; |
| 820 | if (cval->dBmin > cval->dBmax) { |
| 821 | /* totally crap, return an error */ |
| 822 | return -EINVAL; |
| 823 | } |
| 824 | } |
| 825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | /* get a feature/mixer unit info */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 831 | static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 833 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | if (cval->val_type == USB_MIXER_BOOLEAN || |
| 836 | cval->val_type == USB_MIXER_INV_BOOLEAN) |
| 837 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 838 | else |
| 839 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 840 | uinfo->count = cval->channels; |
| 841 | if (cval->val_type == USB_MIXER_BOOLEAN || |
| 842 | cval->val_type == USB_MIXER_INV_BOOLEAN) { |
| 843 | uinfo->value.integer.min = 0; |
| 844 | uinfo->value.integer.max = 1; |
| 845 | } else { |
| 846 | if (! cval->initialized) |
| 847 | get_min_max(cval, 0); |
| 848 | uinfo->value.integer.min = 0; |
Takashi Iwai | 14790f1 | 2006-03-28 17:58:28 +0200 | [diff] [blame] | 849 | uinfo->value.integer.max = |
| 850 | (cval->max - cval->min + cval->res - 1) / cval->res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | /* get the current value from feature/mixer unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 856 | static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 858 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | int c, cnt, val, err; |
| 860 | |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 861 | ucontrol->value.integer.value[0] = cval->min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | if (cval->cmask) { |
| 863 | cnt = 0; |
| 864 | for (c = 0; c < MAX_CHANNELS; c++) { |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 865 | if (!(cval->cmask & (1 << c))) |
| 866 | continue; |
| 867 | err = get_cur_mix_value(cval, c + 1, cnt, &val); |
| 868 | if (err < 0) |
| 869 | return cval->mixer->ignore_ctl_error ? 0 : err; |
| 870 | val = get_relative_value(cval, val); |
| 871 | ucontrol->value.integer.value[cnt] = val; |
| 872 | cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | } |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 874 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } else { |
| 876 | /* master channel */ |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 877 | err = get_cur_mix_value(cval, 0, 0, &val); |
| 878 | if (err < 0) |
| 879 | return cval->mixer->ignore_ctl_error ? 0 : err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | val = get_relative_value(cval, val); |
| 881 | ucontrol->value.integer.value[0] = val; |
| 882 | } |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | /* put the current value to feature/mixer unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 887 | static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 889 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | int c, cnt, val, oval, err; |
| 891 | int changed = 0; |
| 892 | |
| 893 | if (cval->cmask) { |
| 894 | cnt = 0; |
| 895 | for (c = 0; c < MAX_CHANNELS; c++) { |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 896 | if (!(cval->cmask & (1 << c))) |
| 897 | continue; |
| 898 | err = get_cur_mix_value(cval, c + 1, cnt, &oval); |
| 899 | if (err < 0) |
| 900 | return cval->mixer->ignore_ctl_error ? 0 : err; |
| 901 | val = ucontrol->value.integer.value[cnt]; |
| 902 | val = get_abs_value(cval, val); |
| 903 | if (oval != val) { |
| 904 | set_cur_mix_value(cval, c + 1, cnt, val); |
| 905 | changed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | } |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 907 | cnt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
| 909 | } else { |
| 910 | /* master channel */ |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 911 | err = get_cur_mix_value(cval, 0, 0, &oval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | if (err < 0) |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 913 | return cval->mixer->ignore_ctl_error ? 0 : err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | val = ucontrol->value.integer.value[0]; |
| 915 | val = get_abs_value(cval, val); |
| 916 | if (val != oval) { |
Takashi Iwai | 641b487 | 2009-01-15 17:05:24 +0100 | [diff] [blame] | 917 | set_cur_mix_value(cval, 0, 0, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | changed = 1; |
| 919 | } |
| 920 | } |
| 921 | return changed; |
| 922 | } |
| 923 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 924 | static struct snd_kcontrol_new usb_feature_unit_ctl = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 926 | .name = "", /* will be filled later manually */ |
| 927 | .info = mixer_ctl_feature_info, |
| 928 | .get = mixer_ctl_feature_get, |
| 929 | .put = mixer_ctl_feature_put, |
| 930 | }; |
| 931 | |
| 932 | |
| 933 | /* |
| 934 | * build a feature control |
| 935 | */ |
| 936 | |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 937 | static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str) |
| 938 | { |
| 939 | return strlcat(kctl->id.name, str, sizeof(kctl->id.name)); |
| 940 | } |
| 941 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 942 | static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | unsigned int ctl_mask, int control, |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 944 | struct usb_audio_term *iterm, int unitid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | { |
| 946 | unsigned int len = 0; |
| 947 | int mapped_name = 0; |
| 948 | int nameid = desc[desc[0] - 1]; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 949 | struct snd_kcontrol *kctl; |
| 950 | struct usb_mixer_elem_info *cval; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 951 | const struct usbmix_name_map *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
| 953 | control++; /* change from zero-based to 1-based value */ |
| 954 | |
| 955 | if (control == USB_FEATURE_GEQ) { |
| 956 | /* FIXME: not supported yet */ |
| 957 | return; |
| 958 | } |
| 959 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 960 | map = find_map(state, unitid, control); |
| 961 | if (check_ignored_ctl(map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | return; |
| 963 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 964 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | if (! cval) { |
| 966 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 967 | return; |
| 968 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 969 | cval->mixer = state->mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | cval->id = unitid; |
| 971 | cval->control = control; |
| 972 | cval->cmask = ctl_mask; |
| 973 | cval->val_type = audio_feature_info[control-1].type; |
| 974 | if (ctl_mask == 0) |
| 975 | cval->channels = 1; /* master channel */ |
| 976 | else { |
| 977 | int i, c = 0; |
| 978 | for (i = 0; i < 16; i++) |
| 979 | if (ctl_mask & (1 << i)) |
| 980 | c++; |
| 981 | cval->channels = c; |
| 982 | } |
| 983 | |
| 984 | /* get min/max values */ |
| 985 | get_min_max(cval, 0); |
| 986 | |
| 987 | kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); |
| 988 | if (! kctl) { |
| 989 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 990 | kfree(cval); |
| 991 | return; |
| 992 | } |
| 993 | kctl->private_free = usb_mixer_elem_free; |
| 994 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 995 | len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | mapped_name = len != 0; |
| 997 | if (! len && nameid) |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 998 | len = snd_usb_copy_string_desc(state, nameid, |
| 999 | kctl->id.name, sizeof(kctl->id.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
| 1001 | switch (control) { |
| 1002 | case USB_FEATURE_MUTE: |
| 1003 | case USB_FEATURE_VOLUME: |
| 1004 | /* determine the control name. the rule is: |
| 1005 | * - if a name id is given in descriptor, use it. |
| 1006 | * - if the connected input can be determined, then use the name |
| 1007 | * of terminal type. |
| 1008 | * - if the connected output can be determined, use it. |
| 1009 | * - otherwise, anonymous name. |
| 1010 | */ |
| 1011 | if (! len) { |
| 1012 | len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 1); |
| 1013 | if (! len) |
| 1014 | len = get_term_name(state, &state->oterm, kctl->id.name, sizeof(kctl->id.name), 1); |
| 1015 | if (! len) |
| 1016 | len = snprintf(kctl->id.name, sizeof(kctl->id.name), |
| 1017 | "Feature %d", unitid); |
| 1018 | } |
| 1019 | /* determine the stream direction: |
| 1020 | * if the connected output is USB stream, then it's likely a |
| 1021 | * capture stream. otherwise it should be playback (hopefully :) |
| 1022 | */ |
| 1023 | if (! mapped_name && ! (state->oterm.type >> 16)) { |
| 1024 | if ((state->oterm.type & 0xff00) == 0x0100) { |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1025 | len = append_ctl_name(kctl, " Capture"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | } else { |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1027 | len = append_ctl_name(kctl, " Playback"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | } |
| 1029 | } |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1030 | append_ctl_name(kctl, control == USB_FEATURE_MUTE ? |
| 1031 | " Switch" : " Volume"); |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 1032 | if (control == USB_FEATURE_VOLUME) { |
| 1033 | kctl->tlv.c = mixer_vol_tlv; |
| 1034 | kctl->vd[0].access |= |
| 1035 | SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 1036 | SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1037 | check_mapped_dB(map, cval); |
Takashi Iwai | 7bc5ba7e | 2006-07-14 15:18:19 +0200 | [diff] [blame] | 1038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | break; |
| 1040 | |
| 1041 | default: |
| 1042 | if (! len) |
| 1043 | strlcpy(kctl->id.name, audio_feature_info[control-1].name, |
| 1044 | sizeof(kctl->id.name)); |
| 1045 | break; |
| 1046 | } |
| 1047 | |
Alexey Fisher | 2cf313e | 2009-07-22 14:57:54 +0200 | [diff] [blame] | 1048 | /* volume control quirks */ |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 1049 | switch (state->chip->usb_id) { |
| 1050 | case USB_ID(0x0471, 0x0101): |
| 1051 | case USB_ID(0x0471, 0x0104): |
| 1052 | case USB_ID(0x0471, 0x0105): |
| 1053 | case USB_ID(0x0672, 0x1041): |
Alexey Fisher | 2cf313e | 2009-07-22 14:57:54 +0200 | [diff] [blame] | 1054 | /* quirk for UDA1321/N101. |
| 1055 | * note that detection between firmware 2.1.1.7 (N101) |
| 1056 | * and later 2.1.1.21 is not very clear from datasheets. |
| 1057 | * I hope that the min value is -15360 for newer firmware --jk |
| 1058 | */ |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 1059 | if (!strcmp(kctl->id.name, "PCM Playback Volume") && |
| 1060 | cval->min == -15616) { |
Alexey Fisher | 2cf313e | 2009-07-22 14:57:54 +0200 | [diff] [blame] | 1061 | snd_printk(KERN_INFO |
| 1062 | "set volume quirk for UDA1321/N101 chip\n"); |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 1063 | cval->max = -256; |
| 1064 | } |
Alexey Fisher | 2cf313e | 2009-07-22 14:57:54 +0200 | [diff] [blame] | 1065 | break; |
| 1066 | |
| 1067 | case USB_ID(0x046d, 0x09a4): |
| 1068 | if (!strcmp(kctl->id.name, "Mic Capture Volume")) { |
| 1069 | snd_printk(KERN_INFO |
| 1070 | "set volume quirk for QuickCam E3500\n"); |
| 1071 | cval->min = 6080; |
| 1072 | cval->max = 8768; |
| 1073 | cval->res = 192; |
| 1074 | } |
| 1075 | break; |
| 1076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | snd_printdd(KERN_INFO "[%d] FU [%s] ch = %d, val = %d/%d/%d\n", |
| 1080 | cval->id, kctl->id.name, cval->channels, cval->min, cval->max, cval->res); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1081 | add_control_to_empty(state, kctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | /* |
| 1087 | * parse a feature unit |
| 1088 | * |
| 1089 | * most of controlls are defined here. |
| 1090 | */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1091 | static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void *_ftr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
| 1093 | int channels, i, j; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1094 | struct usb_audio_term iterm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | unsigned int master_bits, first_ch_bits; |
| 1096 | int err, csize; |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1097 | struct uac_feature_unit_descriptor *ftr = _ftr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1099 | if (ftr->bLength < 7 || ! (csize = ftr->bControlSize) || ftr->bLength < 7 + csize) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1100 | snd_printk(KERN_ERR "usbaudio: unit %u: invalid UAC_FEATURE_UNIT descriptor\n", unitid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
| 1104 | /* parse the source unit */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1105 | if ((err = parse_audio_unit(state, ftr->bSourceID)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | return err; |
| 1107 | |
| 1108 | /* determine the input source type and name */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1109 | if (check_input_term(state, ftr->bSourceID, &iterm) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | return -EINVAL; |
| 1111 | |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1112 | channels = (ftr->bLength - 7) / csize - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1114 | master_bits = snd_usb_combine_bytes(ftr->controls, csize); |
Javier Kohen | 0c3cee5 | 2009-11-17 15:36:13 +0100 | [diff] [blame] | 1115 | /* master configuration quirks */ |
| 1116 | switch (state->chip->usb_id) { |
| 1117 | case USB_ID(0x08bb, 0x2702): |
| 1118 | snd_printk(KERN_INFO |
| 1119 | "usbmixer: master volume quirk for PCM2702 chip\n"); |
| 1120 | /* disable non-functional volume control */ |
| 1121 | master_bits &= ~(1 << (USB_FEATURE_VOLUME - 1)); |
| 1122 | break; |
| 1123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | if (channels > 0) |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1125 | first_ch_bits = snd_usb_combine_bytes(ftr->controls + csize, csize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | else |
| 1127 | first_ch_bits = 0; |
| 1128 | /* check all control types */ |
| 1129 | for (i = 0; i < 10; i++) { |
| 1130 | unsigned int ch_bits = 0; |
| 1131 | for (j = 0; j < channels; j++) { |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1132 | unsigned int mask = snd_usb_combine_bytes(ftr->controls + csize * (j+1), csize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | if (mask & (1 << i)) |
| 1134 | ch_bits |= (1 << j); |
| 1135 | } |
| 1136 | if (ch_bits & 1) /* the first channel must be set (for ease of programming) */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1137 | build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (master_bits & (1 << i)) |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1139 | build_feature_ctl(state, _ftr, 0, i, &iterm, unitid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | /* |
| 1147 | * Mixer Unit |
| 1148 | */ |
| 1149 | |
| 1150 | /* |
| 1151 | * build a mixer unit control |
| 1152 | * |
| 1153 | * the callbacks are identical with feature unit. |
| 1154 | * input channel number (zero based) is given in control field instead. |
| 1155 | */ |
| 1156 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1157 | static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | int in_pin, int in_ch, int unitid, |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1159 | struct usb_audio_term *iterm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1161 | struct usb_mixer_elem_info *cval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | unsigned int input_pins = desc[4]; |
| 1163 | unsigned int num_outs = desc[5 + input_pins]; |
| 1164 | unsigned int i, len; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1165 | struct snd_kcontrol *kctl; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1166 | const struct usbmix_name_map *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1168 | map = find_map(state, unitid, 0); |
| 1169 | if (check_ignored_ctl(map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | return; |
| 1171 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 1172 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | if (! cval) |
| 1174 | return; |
| 1175 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1176 | cval->mixer = state->mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | cval->id = unitid; |
| 1178 | cval->control = in_ch + 1; /* based on 1 */ |
| 1179 | cval->val_type = USB_MIXER_S16; |
| 1180 | for (i = 0; i < num_outs; i++) { |
| 1181 | if (check_matrix_bitmap(desc + 9 + input_pins, in_ch, i, num_outs)) { |
| 1182 | cval->cmask |= (1 << i); |
| 1183 | cval->channels++; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | /* get min/max values */ |
| 1188 | get_min_max(cval, 0); |
| 1189 | |
| 1190 | kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval); |
| 1191 | if (! kctl) { |
| 1192 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 1193 | kfree(cval); |
| 1194 | return; |
| 1195 | } |
| 1196 | kctl->private_free = usb_mixer_elem_free; |
| 1197 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1198 | len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | if (! len) |
| 1200 | len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); |
| 1201 | if (! len) |
| 1202 | len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1203 | append_ctl_name(kctl, " Volume"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
| 1205 | snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", |
| 1206 | cval->id, kctl->id.name, cval->channels, cval->min, cval->max); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1207 | add_control_to_empty(state, kctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | |
| 1211 | /* |
| 1212 | * parse a mixer unit |
| 1213 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1214 | static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigned char *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1216 | struct usb_audio_term iterm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | int input_pins, num_ins, num_outs; |
| 1218 | int pin, ich, err; |
| 1219 | |
| 1220 | if (desc[0] < 11 || ! (input_pins = desc[4]) || ! (num_outs = desc[5 + input_pins])) { |
| 1221 | snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid); |
| 1222 | return -EINVAL; |
| 1223 | } |
| 1224 | /* no bmControls field (e.g. Maya44) -> ignore */ |
| 1225 | if (desc[0] <= 10 + input_pins) { |
| 1226 | snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | num_ins = 0; |
| 1231 | ich = 0; |
| 1232 | for (pin = 0; pin < input_pins; pin++) { |
| 1233 | err = parse_audio_unit(state, desc[5 + pin]); |
| 1234 | if (err < 0) |
| 1235 | return err; |
| 1236 | err = check_input_term(state, desc[5 + pin], &iterm); |
| 1237 | if (err < 0) |
| 1238 | return err; |
| 1239 | num_ins += iterm.channels; |
| 1240 | for (; ich < num_ins; ++ich) { |
| 1241 | int och, ich_has_controls = 0; |
| 1242 | |
| 1243 | for (och = 0; och < num_outs; ++och) { |
| 1244 | if (check_matrix_bitmap(desc + 9 + input_pins, |
| 1245 | ich, och, num_outs)) { |
| 1246 | ich_has_controls = 1; |
| 1247 | break; |
| 1248 | } |
| 1249 | } |
| 1250 | if (ich_has_controls) |
| 1251 | build_mixer_unit_ctl(state, desc, pin, ich, |
| 1252 | unitid, &iterm); |
| 1253 | } |
| 1254 | } |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
| 1258 | |
| 1259 | /* |
| 1260 | * Processing Unit / Extension Unit |
| 1261 | */ |
| 1262 | |
| 1263 | /* get callback for processing/extension unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1264 | static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1266 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | int err, val; |
| 1268 | |
| 1269 | err = get_cur_ctl_value(cval, cval->control << 8, &val); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1270 | if (err < 0 && cval->mixer->ignore_ctl_error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | ucontrol->value.integer.value[0] = cval->min; |
| 1272 | return 0; |
| 1273 | } |
| 1274 | if (err < 0) |
| 1275 | return err; |
| 1276 | val = get_relative_value(cval, val); |
| 1277 | ucontrol->value.integer.value[0] = val; |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | /* put callback for processing/extension unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1282 | static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1284 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | int val, oval, err; |
| 1286 | |
| 1287 | err = get_cur_ctl_value(cval, cval->control << 8, &oval); |
| 1288 | if (err < 0) { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1289 | if (cval->mixer->ignore_ctl_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | return 0; |
| 1291 | return err; |
| 1292 | } |
| 1293 | val = ucontrol->value.integer.value[0]; |
| 1294 | val = get_abs_value(cval, val); |
| 1295 | if (val != oval) { |
| 1296 | set_cur_ctl_value(cval, cval->control << 8, val); |
| 1297 | return 1; |
| 1298 | } |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | /* alsa control interface for processing/extension unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1303 | static struct snd_kcontrol_new mixer_procunit_ctl = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1305 | .name = "", /* will be filled later */ |
| 1306 | .info = mixer_ctl_feature_info, |
| 1307 | .get = mixer_ctl_procunit_get, |
| 1308 | .put = mixer_ctl_procunit_put, |
| 1309 | }; |
| 1310 | |
| 1311 | |
| 1312 | /* |
| 1313 | * predefined data for processing units |
| 1314 | */ |
| 1315 | struct procunit_value_info { |
| 1316 | int control; |
| 1317 | char *suffix; |
| 1318 | int val_type; |
| 1319 | int min_value; |
| 1320 | }; |
| 1321 | |
| 1322 | struct procunit_info { |
| 1323 | int type; |
| 1324 | char *name; |
| 1325 | struct procunit_value_info *values; |
| 1326 | }; |
| 1327 | |
| 1328 | static struct procunit_value_info updown_proc_info[] = { |
| 1329 | { USB_PROC_UPDOWN_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1330 | { USB_PROC_UPDOWN_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 }, |
| 1331 | { 0 } |
| 1332 | }; |
| 1333 | static struct procunit_value_info prologic_proc_info[] = { |
| 1334 | { USB_PROC_PROLOGIC_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1335 | { USB_PROC_PROLOGIC_MODE_SEL, "Mode Select", USB_MIXER_U8, 1 }, |
| 1336 | { 0 } |
| 1337 | }; |
| 1338 | static struct procunit_value_info threed_enh_proc_info[] = { |
| 1339 | { USB_PROC_3DENH_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1340 | { USB_PROC_3DENH_SPACE, "Spaciousness", USB_MIXER_U8 }, |
| 1341 | { 0 } |
| 1342 | }; |
| 1343 | static struct procunit_value_info reverb_proc_info[] = { |
| 1344 | { USB_PROC_REVERB_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1345 | { USB_PROC_REVERB_LEVEL, "Level", USB_MIXER_U8 }, |
| 1346 | { USB_PROC_REVERB_TIME, "Time", USB_MIXER_U16 }, |
| 1347 | { USB_PROC_REVERB_DELAY, "Delay", USB_MIXER_U8 }, |
| 1348 | { 0 } |
| 1349 | }; |
| 1350 | static struct procunit_value_info chorus_proc_info[] = { |
| 1351 | { USB_PROC_CHORUS_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1352 | { USB_PROC_CHORUS_LEVEL, "Level", USB_MIXER_U8 }, |
| 1353 | { USB_PROC_CHORUS_RATE, "Rate", USB_MIXER_U16 }, |
| 1354 | { USB_PROC_CHORUS_DEPTH, "Depth", USB_MIXER_U16 }, |
| 1355 | { 0 } |
| 1356 | }; |
| 1357 | static struct procunit_value_info dcr_proc_info[] = { |
| 1358 | { USB_PROC_DCR_SWITCH, "Switch", USB_MIXER_BOOLEAN }, |
| 1359 | { USB_PROC_DCR_RATIO, "Ratio", USB_MIXER_U16 }, |
| 1360 | { USB_PROC_DCR_MAX_AMP, "Max Amp", USB_MIXER_S16 }, |
| 1361 | { USB_PROC_DCR_THRESHOLD, "Threshold", USB_MIXER_S16 }, |
| 1362 | { USB_PROC_DCR_ATTACK, "Attack Time", USB_MIXER_U16 }, |
| 1363 | { USB_PROC_DCR_RELEASE, "Release Time", USB_MIXER_U16 }, |
| 1364 | { 0 } |
| 1365 | }; |
| 1366 | |
| 1367 | static struct procunit_info procunits[] = { |
| 1368 | { USB_PROC_UPDOWN, "Up Down", updown_proc_info }, |
| 1369 | { USB_PROC_PROLOGIC, "Dolby Prologic", prologic_proc_info }, |
| 1370 | { USB_PROC_3DENH, "3D Stereo Extender", threed_enh_proc_info }, |
| 1371 | { USB_PROC_REVERB, "Reverb", reverb_proc_info }, |
| 1372 | { USB_PROC_CHORUS, "Chorus", chorus_proc_info }, |
| 1373 | { USB_PROC_DCR, "DCR", dcr_proc_info }, |
| 1374 | { 0 }, |
| 1375 | }; |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 1376 | /* |
| 1377 | * predefined data for extension units |
| 1378 | */ |
| 1379 | static struct procunit_value_info clock_rate_xu_info[] = { |
| 1380 | { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 }, |
| 1381 | { 0 } |
| 1382 | }; |
| 1383 | static struct procunit_value_info clock_source_xu_info[] = { |
| 1384 | { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN }, |
| 1385 | { 0 } |
| 1386 | }; |
| 1387 | static struct procunit_value_info spdif_format_xu_info[] = { |
| 1388 | { USB_XU_DIGITAL_FORMAT_SELECTOR, "SPDIF/AC3", USB_MIXER_BOOLEAN }, |
| 1389 | { 0 } |
| 1390 | }; |
| 1391 | static struct procunit_value_info soft_limit_xu_info[] = { |
| 1392 | { USB_XU_SOFT_LIMIT_SELECTOR, " ", USB_MIXER_BOOLEAN }, |
| 1393 | { 0 } |
| 1394 | }; |
| 1395 | static struct procunit_info extunits[] = { |
| 1396 | { USB_XU_CLOCK_RATE, "Clock rate", clock_rate_xu_info }, |
| 1397 | { USB_XU_CLOCK_SOURCE, "DigitalIn CLK source", clock_source_xu_info }, |
| 1398 | { USB_XU_DIGITAL_IO_STATUS, "DigitalOut format:", spdif_format_xu_info }, |
| 1399 | { USB_XU_DEVICE_OPTIONS, "AnalogueIn Soft Limit", soft_limit_xu_info }, |
| 1400 | { 0 } |
| 1401 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | /* |
| 1403 | * build a processing/extension unit |
| 1404 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1405 | static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned char *dsc, struct procunit_info *list, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | { |
| 1407 | int num_ins = dsc[6]; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1408 | struct usb_mixer_elem_info *cval; |
| 1409 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | int i, err, nameid, type, len; |
| 1411 | struct procunit_info *info; |
| 1412 | struct procunit_value_info *valinfo; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1413 | const struct usbmix_name_map *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | static struct procunit_value_info default_value_info[] = { |
| 1415 | { 0x01, "Switch", USB_MIXER_BOOLEAN }, |
| 1416 | { 0 } |
| 1417 | }; |
| 1418 | static struct procunit_info default_info = { |
| 1419 | 0, NULL, default_value_info |
| 1420 | }; |
| 1421 | |
| 1422 | if (dsc[0] < 13 || dsc[0] < 13 + num_ins || dsc[0] < num_ins + dsc[11 + num_ins]) { |
| 1423 | snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid); |
| 1424 | return -EINVAL; |
| 1425 | } |
| 1426 | |
| 1427 | for (i = 0; i < num_ins; i++) { |
| 1428 | if ((err = parse_audio_unit(state, dsc[7 + i])) < 0) |
| 1429 | return err; |
| 1430 | } |
| 1431 | |
| 1432 | type = combine_word(&dsc[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | for (info = list; info && info->type; info++) |
| 1434 | if (info->type == type) |
| 1435 | break; |
| 1436 | if (! info || ! info->type) |
| 1437 | info = &default_info; |
| 1438 | |
| 1439 | for (valinfo = info->values; valinfo->control; valinfo++) { |
| 1440 | /* FIXME: bitmap might be longer than 8bit */ |
| 1441 | if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1)))) |
| 1442 | continue; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1443 | map = find_map(state, unitid, valinfo->control); |
| 1444 | if (check_ignored_ctl(map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | continue; |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 1446 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | if (! cval) { |
| 1448 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 1449 | return -ENOMEM; |
| 1450 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1451 | cval->mixer = state->mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | cval->id = unitid; |
| 1453 | cval->control = valinfo->control; |
| 1454 | cval->val_type = valinfo->val_type; |
| 1455 | cval->channels = 1; |
| 1456 | |
| 1457 | /* get min/max values */ |
| 1458 | if (type == USB_PROC_UPDOWN && cval->control == USB_PROC_UPDOWN_MODE_SEL) { |
| 1459 | /* FIXME: hard-coded */ |
| 1460 | cval->min = 1; |
| 1461 | cval->max = dsc[15]; |
| 1462 | cval->res = 1; |
| 1463 | cval->initialized = 1; |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 1464 | } else { |
| 1465 | if (type == USB_XU_CLOCK_RATE) { |
| 1466 | /* E-Mu USB 0404/0202/TrackerPre |
| 1467 | * samplerate control quirk |
| 1468 | */ |
| 1469 | cval->min = 0; |
| 1470 | cval->max = 5; |
| 1471 | cval->res = 1; |
| 1472 | cval->initialized = 1; |
| 1473 | } else |
| 1474 | get_min_max(cval, valinfo->min_value); |
| 1475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
| 1477 | kctl = snd_ctl_new1(&mixer_procunit_ctl, cval); |
| 1478 | if (! kctl) { |
| 1479 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 1480 | kfree(cval); |
| 1481 | return -ENOMEM; |
| 1482 | } |
| 1483 | kctl->private_free = usb_mixer_elem_free; |
| 1484 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1485 | if (check_mapped_name(map, kctl->id.name, |
| 1486 | sizeof(kctl->id.name))) |
| 1487 | /* nothing */ ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | else if (info->name) |
| 1489 | strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); |
| 1490 | else { |
| 1491 | nameid = dsc[12 + num_ins + dsc[11 + num_ins]]; |
| 1492 | len = 0; |
| 1493 | if (nameid) |
| 1494 | len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); |
| 1495 | if (! len) |
| 1496 | strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); |
| 1497 | } |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1498 | append_ctl_name(kctl, " "); |
| 1499 | append_ctl_name(kctl, valinfo->suffix); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
| 1501 | snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", |
| 1502 | cval->id, kctl->id.name, cval->channels, cval->min, cval->max); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1503 | if ((err = add_control_to_empty(state, kctl)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | return err; |
| 1505 | } |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
| 1509 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1510 | static int parse_audio_processing_unit(struct mixer_build *state, int unitid, unsigned char *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { |
| 1512 | return build_audio_procunit(state, unitid, desc, procunits, "Processing Unit"); |
| 1513 | } |
| 1514 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1515 | static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | { |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 1517 | return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | /* |
| 1522 | * Selector Unit |
| 1523 | */ |
| 1524 | |
| 1525 | /* info callback for selector unit |
| 1526 | * use an enumerator type for routing |
| 1527 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1528 | static int mixer_ctl_selector_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1530 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | char **itemlist = (char **)kcontrol->private_value; |
| 1532 | |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 1533 | if (snd_BUG_ON(!itemlist)) |
| 1534 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1536 | uinfo->count = 1; |
| 1537 | uinfo->value.enumerated.items = cval->max; |
| 1538 | if ((int)uinfo->value.enumerated.item >= cval->max) |
| 1539 | uinfo->value.enumerated.item = cval->max - 1; |
| 1540 | strcpy(uinfo->value.enumerated.name, itemlist[uinfo->value.enumerated.item]); |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
| 1544 | /* get callback for selector unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1545 | static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1547 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | int val, err; |
| 1549 | |
| 1550 | err = get_cur_ctl_value(cval, 0, &val); |
| 1551 | if (err < 0) { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1552 | if (cval->mixer->ignore_ctl_error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | ucontrol->value.enumerated.item[0] = 0; |
| 1554 | return 0; |
| 1555 | } |
| 1556 | return err; |
| 1557 | } |
| 1558 | val = get_relative_value(cval, val); |
| 1559 | ucontrol->value.enumerated.item[0] = val; |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
| 1563 | /* put callback for selector unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1564 | static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1566 | struct usb_mixer_elem_info *cval = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | int val, oval, err; |
| 1568 | |
| 1569 | err = get_cur_ctl_value(cval, 0, &oval); |
| 1570 | if (err < 0) { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1571 | if (cval->mixer->ignore_ctl_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | return 0; |
| 1573 | return err; |
| 1574 | } |
| 1575 | val = ucontrol->value.enumerated.item[0]; |
| 1576 | val = get_abs_value(cval, val); |
| 1577 | if (val != oval) { |
| 1578 | set_cur_ctl_value(cval, 0, val); |
| 1579 | return 1; |
| 1580 | } |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | /* alsa control interface for selector unit */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1585 | static struct snd_kcontrol_new mixer_selectunit_ctl = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1587 | .name = "", /* will be filled later */ |
| 1588 | .info = mixer_ctl_selector_info, |
| 1589 | .get = mixer_ctl_selector_get, |
| 1590 | .put = mixer_ctl_selector_put, |
| 1591 | }; |
| 1592 | |
| 1593 | |
| 1594 | /* private free callback. |
| 1595 | * free both private_data and private_value |
| 1596 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1597 | static void usb_mixer_selector_elem_free(struct snd_kcontrol *kctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
| 1599 | int i, num_ins = 0; |
| 1600 | |
| 1601 | if (kctl->private_data) { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1602 | struct usb_mixer_elem_info *cval = kctl->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | num_ins = cval->max; |
| 1604 | kfree(cval); |
| 1605 | kctl->private_data = NULL; |
| 1606 | } |
| 1607 | if (kctl->private_value) { |
| 1608 | char **itemlist = (char **)kctl->private_value; |
| 1609 | for (i = 0; i < num_ins; i++) |
| 1610 | kfree(itemlist[i]); |
| 1611 | kfree(itemlist); |
| 1612 | kctl->private_value = 0; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * parse a selector unit |
| 1618 | */ |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1619 | static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsigned char *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | { |
| 1621 | unsigned int num_ins = desc[4]; |
| 1622 | unsigned int i, nameid, len; |
| 1623 | int err; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1624 | struct usb_mixer_elem_info *cval; |
| 1625 | struct snd_kcontrol *kctl; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1626 | const struct usbmix_name_map *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | char **namelist; |
| 1628 | |
Russ Cox | 38977e9 | 2007-08-06 15:37:58 +0200 | [diff] [blame] | 1629 | if (! num_ins || desc[0] < 5 + num_ins) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid); |
| 1631 | return -EINVAL; |
| 1632 | } |
| 1633 | |
| 1634 | for (i = 0; i < num_ins; i++) { |
| 1635 | if ((err = parse_audio_unit(state, desc[5 + i])) < 0) |
| 1636 | return err; |
| 1637 | } |
| 1638 | |
| 1639 | if (num_ins == 1) /* only one ? nonsense! */ |
| 1640 | return 0; |
| 1641 | |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1642 | map = find_map(state, unitid, 0); |
| 1643 | if (check_ignored_ctl(map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | return 0; |
| 1645 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 1646 | cval = kzalloc(sizeof(*cval), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | if (! cval) { |
| 1648 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
| 1649 | return -ENOMEM; |
| 1650 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1651 | cval->mixer = state->mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | cval->id = unitid; |
| 1653 | cval->val_type = USB_MIXER_U8; |
| 1654 | cval->channels = 1; |
| 1655 | cval->min = 1; |
| 1656 | cval->max = num_ins; |
| 1657 | cval->res = 1; |
| 1658 | cval->initialized = 1; |
| 1659 | |
| 1660 | namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL); |
| 1661 | if (! namelist) { |
| 1662 | snd_printk(KERN_ERR "cannot malloc\n"); |
| 1663 | kfree(cval); |
| 1664 | return -ENOMEM; |
| 1665 | } |
| 1666 | #define MAX_ITEM_NAME_LEN 64 |
| 1667 | for (i = 0; i < num_ins; i++) { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1668 | struct usb_audio_term iterm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | len = 0; |
| 1670 | namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL); |
| 1671 | if (! namelist[i]) { |
| 1672 | snd_printk(KERN_ERR "cannot malloc\n"); |
Mariusz Kozlowski | 7fbe3ca | 2007-01-08 11:25:30 +0100 | [diff] [blame] | 1673 | while (i--) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | kfree(namelist[i]); |
| 1675 | kfree(namelist); |
| 1676 | kfree(cval); |
| 1677 | return -ENOMEM; |
| 1678 | } |
Clemens Ladisch | 8e062ec | 2005-04-22 15:49:52 +0200 | [diff] [blame] | 1679 | len = check_mapped_selector_name(state, unitid, i, namelist[i], |
| 1680 | MAX_ITEM_NAME_LEN); |
| 1681 | if (! len && check_input_term(state, desc[5 + i], &iterm) >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | len = get_term_name(state, &iterm, namelist[i], MAX_ITEM_NAME_LEN, 0); |
| 1683 | if (! len) |
| 1684 | sprintf(namelist[i], "Input %d", i); |
| 1685 | } |
| 1686 | |
| 1687 | kctl = snd_ctl_new1(&mixer_selectunit_ctl, cval); |
| 1688 | if (! kctl) { |
| 1689 | snd_printk(KERN_ERR "cannot malloc kcontrol\n"); |
Jesper Juhl | 878b478 | 2006-03-20 11:27:13 +0100 | [diff] [blame] | 1690 | kfree(namelist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | kfree(cval); |
| 1692 | return -ENOMEM; |
| 1693 | } |
| 1694 | kctl->private_value = (unsigned long)namelist; |
| 1695 | kctl->private_free = usb_mixer_selector_elem_free; |
| 1696 | |
| 1697 | nameid = desc[desc[0] - 1]; |
Jaroslav Kysela | c3a3e04 | 2010-02-11 17:50:44 +0100 | [diff] [blame] | 1698 | len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | if (len) |
| 1700 | ; |
| 1701 | else if (nameid) |
| 1702 | snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); |
| 1703 | else { |
| 1704 | len = get_term_name(state, &state->oterm, |
| 1705 | kctl->id.name, sizeof(kctl->id.name), 0); |
| 1706 | if (! len) |
| 1707 | strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); |
| 1708 | |
| 1709 | if ((state->oterm.type & 0xff00) == 0x0100) |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1710 | append_ctl_name(kctl, " Capture Source"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | else |
Takashi Iwai | 08d1e63 | 2009-10-02 14:06:08 +0200 | [diff] [blame] | 1712 | append_ctl_name(kctl, " Playback Source"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", |
| 1716 | cval->id, kctl->id.name, num_ins); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1717 | if ((err = add_control_to_empty(state, kctl)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | return err; |
| 1719 | |
| 1720 | return 0; |
| 1721 | } |
| 1722 | |
| 1723 | |
| 1724 | /* |
| 1725 | * parse an audio unit recursively |
| 1726 | */ |
| 1727 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1728 | static int parse_audio_unit(struct mixer_build *state, int unitid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | { |
| 1730 | unsigned char *p1; |
| 1731 | |
| 1732 | if (test_and_set_bit(unitid, state->unitbitmap)) |
| 1733 | return 0; /* the unit already visited */ |
| 1734 | |
| 1735 | p1 = find_audio_control_unit(state, unitid); |
| 1736 | if (!p1) { |
| 1737 | snd_printk(KERN_ERR "usbaudio: unit %d not found!\n", unitid); |
| 1738 | return -EINVAL; |
| 1739 | } |
| 1740 | |
| 1741 | switch (p1[2]) { |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1742 | case UAC_INPUT_TERMINAL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | return 0; /* NOP */ |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1744 | case UAC_MIXER_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | return parse_audio_mixer_unit(state, unitid, p1); |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1746 | case UAC_SELECTOR_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | return parse_audio_selector_unit(state, unitid, p1); |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1748 | case UAC_FEATURE_UNIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | return parse_audio_feature_unit(state, unitid, p1); |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1750 | case UAC_PROCESSING_UNIT_V1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | return parse_audio_processing_unit(state, unitid, p1); |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1752 | case UAC_EXTENSION_UNIT_V1: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | return parse_audio_extension_unit(state, unitid, p1); |
| 1754 | default: |
| 1755 | snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]); |
| 1756 | return -EINVAL; |
| 1757 | } |
| 1758 | } |
| 1759 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1760 | static void snd_usb_mixer_free(struct usb_mixer_interface *mixer) |
| 1761 | { |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1762 | kfree(mixer->id_elems); |
| 1763 | if (mixer->urb) { |
| 1764 | kfree(mixer->urb->transfer_buffer); |
| 1765 | usb_free_urb(mixer->urb); |
| 1766 | } |
Mariusz Kozlowski | 68df9de | 2006-11-08 15:37:04 +0100 | [diff] [blame] | 1767 | usb_free_urb(mixer->rc_urb); |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1768 | kfree(mixer->rc_setup_packet); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1769 | kfree(mixer); |
| 1770 | } |
| 1771 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1772 | static int snd_usb_mixer_dev_free(struct snd_device *device) |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1773 | { |
| 1774 | struct usb_mixer_interface *mixer = device->device_data; |
| 1775 | snd_usb_mixer_free(mixer); |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | /* |
| 1780 | * create mixer controls |
| 1781 | * |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1782 | * walk through all UAC_OUTPUT_TERMINAL descriptors to search for mixers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | */ |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1784 | static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | { |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1786 | struct uac_output_terminal_descriptor_v1 *desc; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1787 | struct mixer_build state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | int err; |
| 1789 | const struct usbmix_ctl_map *map; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1790 | struct usb_host_interface *hostif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1792 | hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | memset(&state, 0, sizeof(state)); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1794 | state.chip = mixer->chip; |
| 1795 | state.mixer = mixer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | state.buffer = hostif->extra; |
| 1797 | state.buflen = hostif->extralen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
| 1799 | /* check the mapping table */ |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 1800 | for (map = usbmix_ctl_maps; map->id; map++) { |
| 1801 | if (map->id == state.chip->usb_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | state.map = map->map; |
Clemens Ladisch | 8e062ec | 2005-04-22 15:49:52 +0200 | [diff] [blame] | 1803 | state.selector_map = map->selector_map; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1804 | mixer->ignore_ctl_error = map->ignore_ctl_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | break; |
| 1806 | } |
| 1807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
| 1809 | desc = NULL; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 1810 | while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, UAC_OUTPUT_TERMINAL)) != NULL) { |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1811 | if (desc->bLength < 9) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | continue; /* invalid descriptor? */ |
Daniel Mack | 28e1b77 | 2010-02-22 23:49:09 +0100 | [diff] [blame] | 1813 | set_bit(desc->bTerminalID, state.unitbitmap); /* mark terminal ID as visited */ |
| 1814 | state.oterm.id = desc->bTerminalID; |
| 1815 | state.oterm.type = le16_to_cpu(desc->wTerminalType); |
| 1816 | state.oterm.name = desc->iTerminal; |
| 1817 | err = parse_audio_unit(&state, desc->bSourceID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | if (err < 0) |
| 1819 | return err; |
| 1820 | } |
| 1821 | return 0; |
| 1822 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 1823 | |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1824 | static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, |
| 1825 | int unitid) |
| 1826 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1827 | struct usb_mixer_elem_info *info; |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1828 | |
| 1829 | for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem) |
| 1830 | snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 1831 | info->elem_id); |
| 1832 | } |
| 1833 | |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 1834 | static void snd_usb_mixer_dump_cval(struct snd_info_buffer *buffer, |
| 1835 | int unitid, |
| 1836 | struct usb_mixer_elem_info *cval) |
| 1837 | { |
| 1838 | static char *val_types[] = {"BOOLEAN", "INV_BOOLEAN", |
| 1839 | "S8", "U8", "S16", "U16"}; |
| 1840 | snd_iprintf(buffer, " Unit: %i\n", unitid); |
| 1841 | if (cval->elem_id) |
| 1842 | snd_iprintf(buffer, " Control: name=\"%s\", index=%i\n", |
| 1843 | cval->elem_id->name, cval->elem_id->index); |
| 1844 | snd_iprintf(buffer, " Info: id=%i, control=%i, cmask=0x%x, " |
| 1845 | "channels=%i, type=\"%s\"\n", cval->id, |
| 1846 | cval->control, cval->cmask, cval->channels, |
| 1847 | val_types[cval->val_type]); |
| 1848 | snd_iprintf(buffer, " Volume: min=%i, max=%i, dBmin=%i, dBmax=%i\n", |
| 1849 | cval->min, cval->max, cval->dBmin, cval->dBmax); |
| 1850 | } |
| 1851 | |
| 1852 | static void snd_usb_mixer_proc_read(struct snd_info_entry *entry, |
| 1853 | struct snd_info_buffer *buffer) |
| 1854 | { |
| 1855 | struct snd_usb_audio *chip = entry->private_data; |
| 1856 | struct usb_mixer_interface *mixer; |
| 1857 | struct usb_mixer_elem_info *cval; |
| 1858 | int unitid; |
| 1859 | |
| 1860 | list_for_each_entry(mixer, &chip->mixer_list, list) { |
| 1861 | snd_iprintf(buffer, |
Jaroslav Kysela | 7affdc1 | 2010-02-16 11:52:27 +0100 | [diff] [blame] | 1862 | "USB Mixer: usb_id=0x%08x, ctrlif=%i, ctlerr=%i\n", |
| 1863 | chip->usb_id, mixer->ctrlif, |
| 1864 | mixer->ignore_ctl_error); |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 1865 | snd_iprintf(buffer, "Card: %s\n", chip->card->longname); |
| 1866 | for (unitid = 0; unitid < MAX_ID_ELEMS; unitid++) { |
| 1867 | for (cval = mixer->id_elems[unitid]; cval; |
| 1868 | cval = cval->next_id_elem) |
| 1869 | snd_usb_mixer_dump_cval(buffer, unitid, cval); |
| 1870 | } |
| 1871 | } |
| 1872 | } |
| 1873 | |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1874 | static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer, |
| 1875 | int unitid) |
| 1876 | { |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 1877 | if (!mixer->rc_cfg) |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 1878 | return; |
| 1879 | /* unit ids specific to Extigy/Audigy 2 NX: */ |
| 1880 | switch (unitid) { |
| 1881 | case 0: /* remote control */ |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1882 | mixer->rc_urb->dev = mixer->chip->dev; |
| 1883 | usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 1884 | break; |
| 1885 | case 4: /* digital in jack */ |
| 1886 | case 7: /* line in jacks */ |
| 1887 | case 19: /* speaker out jacks */ |
| 1888 | case 20: /* headphones out jack */ |
| 1889 | break; |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 1890 | /* live24ext: 4 = line-in jack */ |
| 1891 | case 3: /* hp-out jack (may actuate Mute) */ |
Andrea Borgia | 3195954 | 2009-01-07 22:58:50 +0100 | [diff] [blame] | 1892 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 1893 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 1894 | snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); |
| 1895 | break; |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 1896 | default: |
| 1897 | snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid); |
| 1898 | break; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1899 | } |
| 1900 | } |
| 1901 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1902 | static void snd_usb_mixer_status_complete(struct urb *urb) |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1903 | { |
| 1904 | struct usb_mixer_interface *mixer = urb->context; |
| 1905 | |
| 1906 | if (urb->status == 0) { |
| 1907 | u8 *buf = urb->transfer_buffer; |
| 1908 | int i; |
| 1909 | |
| 1910 | for (i = urb->actual_length; i >= 2; buf += 2, i -= 2) { |
| 1911 | snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n", |
| 1912 | buf[0], buf[1]); |
| 1913 | /* ignore any notifications not from the control interface */ |
| 1914 | if ((buf[0] & 0x0f) != 0) |
| 1915 | continue; |
| 1916 | if (!(buf[0] & 0x40)) |
| 1917 | snd_usb_mixer_notify_id(mixer, buf[1]); |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1918 | else |
| 1919 | snd_usb_mixer_memory_change(mixer, buf[1]); |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1920 | } |
| 1921 | } |
| 1922 | if (urb->status != -ENOENT && urb->status != -ECONNRESET) { |
| 1923 | urb->dev = mixer->chip->dev; |
| 1924 | usb_submit_urb(urb, GFP_ATOMIC); |
| 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | /* create the handler for the optional status interrupt endpoint */ |
| 1929 | static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer) |
| 1930 | { |
| 1931 | struct usb_host_interface *hostif; |
| 1932 | struct usb_endpoint_descriptor *ep; |
| 1933 | void *transfer_buffer; |
| 1934 | int buffer_length; |
| 1935 | unsigned int epnum; |
| 1936 | |
| 1937 | hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0]; |
| 1938 | /* we need one interrupt input endpoint */ |
| 1939 | if (get_iface_desc(hostif)->bNumEndpoints < 1) |
| 1940 | return 0; |
| 1941 | ep = get_endpoint(hostif, 0); |
Julia Lawall | 913ae5a | 2009-01-03 17:54:53 +0100 | [diff] [blame] | 1942 | if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep)) |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1943 | return 0; |
| 1944 | |
Julia Lawall | 42a6e66 | 2008-12-29 11:23:02 +0100 | [diff] [blame] | 1945 | epnum = usb_endpoint_num(ep); |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 1946 | buffer_length = le16_to_cpu(ep->wMaxPacketSize); |
| 1947 | transfer_buffer = kmalloc(buffer_length, GFP_KERNEL); |
| 1948 | if (!transfer_buffer) |
| 1949 | return -ENOMEM; |
| 1950 | mixer->urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1951 | if (!mixer->urb) { |
| 1952 | kfree(transfer_buffer); |
| 1953 | return -ENOMEM; |
| 1954 | } |
| 1955 | usb_fill_int_urb(mixer->urb, mixer->chip->dev, |
| 1956 | usb_rcvintpipe(mixer->chip->dev, epnum), |
| 1957 | transfer_buffer, buffer_length, |
| 1958 | snd_usb_mixer_status_complete, mixer, ep->bInterval); |
| 1959 | usb_submit_urb(mixer->urb, GFP_KERNEL); |
| 1960 | return 0; |
| 1961 | } |
| 1962 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1963 | static void snd_usb_soundblaster_remote_complete(struct urb *urb) |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1964 | { |
| 1965 | struct usb_mixer_interface *mixer = urb->context; |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 1966 | const struct rc_config *rc = mixer->rc_cfg; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1967 | u32 code; |
| 1968 | |
Phillip Michael Jordan | b9c196e | 2008-08-05 11:01:00 +0200 | [diff] [blame] | 1969 | if (urb->status < 0 || urb->actual_length < rc->min_packet_length) |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1970 | return; |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 1971 | |
| 1972 | code = mixer->rc_buffer[rc->offset]; |
| 1973 | if (rc->length == 2) |
| 1974 | code |= mixer->rc_buffer[rc->offset + 1] << 8; |
| 1975 | |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1976 | /* the Mute button actually changes the mixer control */ |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 1977 | if (code == rc->mute_code) |
| 1978 | snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1979 | mixer->rc_code = code; |
| 1980 | wmb(); |
| 1981 | wake_up(&mixer->rc_waitq); |
| 1982 | } |
| 1983 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 1984 | static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1985 | long count, loff_t *offset) |
| 1986 | { |
| 1987 | struct usb_mixer_interface *mixer = hw->private_data; |
| 1988 | int err; |
| 1989 | u32 rc_code; |
| 1990 | |
Clemens Ladisch | 434b7f5 | 2005-05-02 08:58:31 +0200 | [diff] [blame] | 1991 | if (count != 1 && count != 4) |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 1992 | return -EINVAL; |
| 1993 | err = wait_event_interruptible(mixer->rc_waitq, |
| 1994 | (rc_code = xchg(&mixer->rc_code, 0)) != 0); |
| 1995 | if (err == 0) { |
Clemens Ladisch | 434b7f5 | 2005-05-02 08:58:31 +0200 | [diff] [blame] | 1996 | if (count == 1) |
| 1997 | err = put_user(rc_code, buf); |
| 1998 | else |
| 1999 | err = put_user(rc_code, (u32 __user *)buf); |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2000 | } |
| 2001 | return err < 0 ? err : count; |
| 2002 | } |
| 2003 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2004 | static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2005 | poll_table *wait) |
| 2006 | { |
| 2007 | struct usb_mixer_interface *mixer = hw->private_data; |
| 2008 | |
| 2009 | poll_wait(file, &mixer->rc_waitq, wait); |
| 2010 | return mixer->rc_code ? POLLIN | POLLRDNORM : 0; |
| 2011 | } |
| 2012 | |
| 2013 | static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) |
| 2014 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2015 | struct snd_hwdep *hwdep; |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 2016 | int err, len, i; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2017 | |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 2018 | for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) |
| 2019 | if (rc_configs[i].usb_id == mixer->chip->usb_id) |
| 2020 | break; |
| 2021 | if (i >= ARRAY_SIZE(rc_configs)) |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2022 | return 0; |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 2023 | mixer->rc_cfg = &rc_configs[i]; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2024 | |
Raimonds Cicans | 4d1a70d | 2006-05-05 09:49:53 +0200 | [diff] [blame] | 2025 | len = mixer->rc_cfg->packet_length; |
| 2026 | |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2027 | init_waitqueue_head(&mixer->rc_waitq); |
| 2028 | err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); |
| 2029 | if (err < 0) |
| 2030 | return err; |
| 2031 | snprintf(hwdep->name, sizeof(hwdep->name), |
| 2032 | "%s remote control", mixer->chip->card->shortname); |
| 2033 | hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; |
| 2034 | hwdep->private_data = mixer; |
| 2035 | hwdep->ops.read = snd_usb_sbrc_hwdep_read; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2036 | hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; |
Takashi Iwai | 28b7e34 | 2009-02-05 09:28:08 +0100 | [diff] [blame] | 2037 | hwdep->exclusive = 1; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2038 | |
| 2039 | mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 2040 | if (!mixer->rc_urb) |
| 2041 | return -ENOMEM; |
| 2042 | mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL); |
| 2043 | if (!mixer->rc_setup_packet) { |
| 2044 | usb_free_urb(mixer->rc_urb); |
| 2045 | mixer->rc_urb = NULL; |
| 2046 | return -ENOMEM; |
| 2047 | } |
| 2048 | mixer->rc_setup_packet->bRequestType = |
| 2049 | USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 2050 | mixer->rc_setup_packet->bRequest = UAC_GET_MEM; |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2051 | mixer->rc_setup_packet->wValue = cpu_to_le16(0); |
| 2052 | mixer->rc_setup_packet->wIndex = cpu_to_le16(0); |
| 2053 | mixer->rc_setup_packet->wLength = cpu_to_le16(len); |
| 2054 | usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, |
| 2055 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 2056 | (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len, |
| 2057 | snd_usb_soundblaster_remote_complete, mixer); |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2061 | #define snd_audigy2nx_led_info snd_ctl_boolean_mono_info |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2062 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2063 | static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2064 | { |
| 2065 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 2066 | int index = kcontrol->private_value; |
| 2067 | |
| 2068 | ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index]; |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2072 | static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2073 | { |
| 2074 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 2075 | int index = kcontrol->private_value; |
| 2076 | int value = ucontrol->value.integer.value[0]; |
| 2077 | int err, changed; |
| 2078 | |
| 2079 | if (value > 1) |
| 2080 | return -EINVAL; |
| 2081 | changed = value != mixer->audigy2nx_leds[index]; |
| 2082 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 2083 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, |
| 2084 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 2085 | value, index + 2, NULL, 0, 100); |
| 2086 | if (err < 0) |
| 2087 | return err; |
| 2088 | mixer->audigy2nx_leds[index] = value; |
| 2089 | return changed; |
| 2090 | } |
| 2091 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2092 | static struct snd_kcontrol_new snd_audigy2nx_controls[] = { |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2093 | { |
| 2094 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2095 | .name = "CMSS LED Switch", |
| 2096 | .info = snd_audigy2nx_led_info, |
| 2097 | .get = snd_audigy2nx_led_get, |
| 2098 | .put = snd_audigy2nx_led_put, |
| 2099 | .private_value = 0, |
| 2100 | }, |
| 2101 | { |
| 2102 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2103 | .name = "Power LED Switch", |
| 2104 | .info = snd_audigy2nx_led_info, |
| 2105 | .get = snd_audigy2nx_led_get, |
| 2106 | .put = snd_audigy2nx_led_put, |
| 2107 | .private_value = 1, |
| 2108 | }, |
| 2109 | { |
| 2110 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2111 | .name = "Dolby Digital LED Switch", |
| 2112 | .info = snd_audigy2nx_led_info, |
| 2113 | .get = snd_audigy2nx_led_get, |
| 2114 | .put = snd_audigy2nx_led_put, |
| 2115 | .private_value = 2, |
| 2116 | }, |
| 2117 | }; |
| 2118 | |
| 2119 | static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) |
| 2120 | { |
| 2121 | int i, err; |
| 2122 | |
| 2123 | for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { |
Andrea Borgia | 3195954 | 2009-01-07 22:58:50 +0100 | [diff] [blame] | 2124 | if (i > 1 && /* Live24ext has 2 LEDs only */ |
| 2125 | (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 2126 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2127 | break; |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2128 | err = snd_ctl_add(mixer->chip->card, |
| 2129 | snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); |
| 2130 | if (err < 0) |
| 2131 | return err; |
| 2132 | } |
| 2133 | mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */ |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2137 | static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, |
| 2138 | struct snd_info_buffer *buffer) |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2139 | { |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2140 | static const struct sb_jack { |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2141 | int unitid; |
| 2142 | const char *name; |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2143 | } jacks_audigy2nx[] = { |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2144 | {4, "dig in "}, |
| 2145 | {7, "line in"}, |
| 2146 | {19, "spk out"}, |
| 2147 | {20, "hph out"}, |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2148 | {-1, NULL} |
| 2149 | }, jacks_live24ext[] = { |
| 2150 | {4, "line in"}, /* &1=Line, &2=Mic*/ |
| 2151 | {3, "hph out"}, /* headphones */ |
| 2152 | {0, "RC "}, /* last command, 6 bytes see rc_config above */ |
| 2153 | {-1, NULL} |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2154 | }; |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2155 | const struct sb_jack *jacks; |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2156 | struct usb_mixer_interface *mixer = entry->private_data; |
| 2157 | int i, err; |
| 2158 | u8 buf[3]; |
| 2159 | |
| 2160 | snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2161 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) |
| 2162 | jacks = jacks_audigy2nx; |
Andrea Borgia | 3195954 | 2009-01-07 22:58:50 +0100 | [diff] [blame] | 2163 | else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 2164 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2165 | jacks = jacks_live24ext; |
| 2166 | else |
| 2167 | return; |
| 2168 | |
| 2169 | for (i = 0; jacks[i].name; ++i) { |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2170 | snd_iprintf(buffer, "%s: ", jacks[i].name); |
| 2171 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 2172 | usb_rcvctrlpipe(mixer->chip->dev, 0), |
Daniel Mack | de48c7b | 2010-02-22 23:49:13 +0100 | [diff] [blame] | 2173 | UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2174 | USB_RECIP_INTERFACE, 0, |
| 2175 | jacks[i].unitid << 8, buf, 3, 100); |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2176 | if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2177 | snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); |
| 2178 | else |
| 2179 | snd_iprintf(buffer, "?\n"); |
| 2180 | } |
| 2181 | } |
| 2182 | |
Clemens Ladisch | 468b8fd | 2009-07-13 11:39:29 +0200 | [diff] [blame] | 2183 | static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
| 2184 | struct snd_ctl_elem_value *ucontrol) |
| 2185 | { |
| 2186 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 2187 | |
| 2188 | ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02); |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, |
| 2193 | struct snd_ctl_elem_value *ucontrol) |
| 2194 | { |
| 2195 | struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol); |
| 2196 | u8 old_status, new_status; |
| 2197 | int err, changed; |
| 2198 | |
| 2199 | old_status = mixer->xonar_u1_status; |
| 2200 | if (ucontrol->value.integer.value[0]) |
| 2201 | new_status = old_status | 0x02; |
| 2202 | else |
| 2203 | new_status = old_status & ~0x02; |
| 2204 | changed = new_status != old_status; |
| 2205 | err = snd_usb_ctl_msg(mixer->chip->dev, |
| 2206 | usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, |
| 2207 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 2208 | 50, 0, &new_status, 1, 100); |
| 2209 | if (err < 0) |
| 2210 | return err; |
| 2211 | mixer->xonar_u1_status = new_status; |
| 2212 | return changed; |
| 2213 | } |
| 2214 | |
| 2215 | static struct snd_kcontrol_new snd_xonar_u1_output_switch = { |
| 2216 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2217 | .name = "Digital Playback Switch", |
| 2218 | .info = snd_ctl_boolean_mono_info, |
| 2219 | .get = snd_xonar_u1_switch_get, |
| 2220 | .put = snd_xonar_u1_switch_put, |
| 2221 | }; |
| 2222 | |
| 2223 | static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) |
| 2224 | { |
| 2225 | int err; |
| 2226 | |
| 2227 | err = snd_ctl_add(mixer->chip->card, |
| 2228 | snd_ctl_new1(&snd_xonar_u1_output_switch, mixer)); |
| 2229 | if (err < 0) |
| 2230 | return err; |
| 2231 | mixer->xonar_u1_status = 0x05; |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 2235 | void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2236 | unsigned char samplerate_id) |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 2237 | { |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2238 | struct usb_mixer_interface *mixer; |
| 2239 | struct usb_mixer_elem_info *cval; |
| 2240 | int unitid = 12; /* SamleRate ExtensionUnit ID */ |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 2241 | |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2242 | list_for_each_entry(mixer, &chip->mixer_list, list) { |
| 2243 | cval = mixer->id_elems[unitid]; |
| 2244 | if (cval) { |
| 2245 | set_cur_ctl_value(cval, cval->control << 8, |
| 2246 | samplerate_id); |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 2247 | snd_usb_mixer_notify_id(mixer, unitid); |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2248 | } |
| 2249 | break; |
| 2250 | } |
Sergiy Kovalchuk | 7d2b451 | 2009-12-27 09:13:41 -0800 | [diff] [blame] | 2251 | } |
| 2252 | |
Takashi Iwai | 7a9b806 | 2008-08-13 15:40:53 +0200 | [diff] [blame] | 2253 | int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, |
| 2254 | int ignore_error) |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2255 | { |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 2256 | static struct snd_device_ops dev_ops = { |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2257 | .dev_free = snd_usb_mixer_dev_free |
| 2258 | }; |
| 2259 | struct usb_mixer_interface *mixer; |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2260 | struct snd_info_entry *entry; |
Daniel Mack | 7b8a043 | 2010-02-22 23:49:12 +0100 | [diff] [blame] | 2261 | struct usb_host_interface *host_iface; |
| 2262 | int err, protocol; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2263 | |
| 2264 | strcpy(chip->card->mixername, "USB Mixer"); |
| 2265 | |
Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 2266 | mixer = kzalloc(sizeof(*mixer), GFP_KERNEL); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2267 | if (!mixer) |
| 2268 | return -ENOMEM; |
| 2269 | mixer->chip = chip; |
| 2270 | mixer->ctrlif = ctrlif; |
Takashi Iwai | 7a9b806 | 2008-08-13 15:40:53 +0200 | [diff] [blame] | 2271 | mixer->ignore_ctl_error = ignore_error; |
Jaroslav Kysela | 291186e | 2010-02-16 11:55:18 +0100 | [diff] [blame] | 2272 | mixer->id_elems = kcalloc(MAX_ID_ELEMS, sizeof(*mixer->id_elems), |
| 2273 | GFP_KERNEL); |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 2274 | if (!mixer->id_elems) { |
| 2275 | kfree(mixer); |
| 2276 | return -ENOMEM; |
| 2277 | } |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2278 | |
Daniel Mack | 7b8a043 | 2010-02-22 23:49:12 +0100 | [diff] [blame] | 2279 | host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0]; |
| 2280 | protocol = host_iface->desc.bInterfaceProtocol; |
| 2281 | |
| 2282 | /* FIXME! */ |
| 2283 | if (protocol != UAC_VERSION_1) { |
| 2284 | snd_printk(KERN_WARNING "mixer interface protocol 0x%02x not yet supported\n", |
| 2285 | protocol); |
| 2286 | return 0; |
| 2287 | } |
| 2288 | |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 2289 | if ((err = snd_usb_mixer_controls(mixer)) < 0 || |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2290 | (err = snd_usb_mixer_status_create(mixer)) < 0) |
| 2291 | goto _error; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2292 | |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2293 | if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) |
| 2294 | goto _error; |
| 2295 | |
Timofei Bondarenko | 69b1f1e | 2007-10-30 15:28:14 +0100 | [diff] [blame] | 2296 | if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || |
Andrea Borgia | 3195954 | 2009-01-07 22:58:50 +0100 | [diff] [blame] | 2297 | mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 2298 | mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) { |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2299 | if ((err = snd_audigy2nx_controls_create(mixer)) < 0) |
| 2300 | goto _error; |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2301 | if (!snd_card_proc_new(chip->card, "audigy2nx", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2302 | snd_info_set_text_ops(entry, mixer, |
Clemens Ladisch | aafad56 | 2005-05-10 14:47:38 +0200 | [diff] [blame] | 2303 | snd_audigy2nx_proc_read); |
Clemens Ladisch | b259b10 | 2005-04-29 16:29:28 +0200 | [diff] [blame] | 2304 | } |
| 2305 | |
Clemens Ladisch | 468b8fd | 2009-07-13 11:39:29 +0200 | [diff] [blame] | 2306 | if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) || |
| 2307 | mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) { |
| 2308 | err = snd_xonar_u1_controls_create(mixer); |
| 2309 | if (err < 0) |
| 2310 | goto _error; |
| 2311 | } |
| 2312 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2313 | err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2314 | if (err < 0) |
| 2315 | goto _error; |
Jaroslav Kysela | ebfdeea | 2010-02-16 11:17:09 +0100 | [diff] [blame] | 2316 | |
| 2317 | if (list_empty(&chip->mixer_list) && |
| 2318 | !snd_card_proc_new(chip->card, "usbmixer", &entry)) |
| 2319 | snd_info_set_text_ops(entry, chip, snd_usb_mixer_proc_read); |
| 2320 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2321 | list_add(&mixer->list, &chip->mixer_list); |
| 2322 | return 0; |
Clemens Ladisch | 93446ed | 2005-05-03 08:02:40 +0200 | [diff] [blame] | 2323 | |
| 2324 | _error: |
| 2325 | snd_usb_mixer_free(mixer); |
| 2326 | return err; |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | void snd_usb_mixer_disconnect(struct list_head *p) |
| 2330 | { |
Clemens Ladisch | 6639b6c | 2005-04-29 16:26:14 +0200 | [diff] [blame] | 2331 | struct usb_mixer_interface *mixer; |
| 2332 | |
| 2333 | mixer = list_entry(p, struct usb_mixer_interface, list); |
Mariusz Kozlowski | 68df9de | 2006-11-08 15:37:04 +0100 | [diff] [blame] | 2334 | usb_kill_urb(mixer->urb); |
| 2335 | usb_kill_urb(mixer->rc_urb); |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 2336 | } |