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