| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* USB Audio Driver for ALSA |
| 4 |
* |
| 5 |
* Quirks and vendor-specific extensions for mixer interfaces |
| 6 |
* |
| 7 |
* Copyright (c) 2002 by Takashi Iwai <[email protected]> |
| 8 |
* |
| 9 |
* Many codes borrowed from audio.c by |
| 10 |
* Alan Cox ([email protected]) |
| 11 |
* Thomas Sailer ([email protected]) |
| 12 |
* |
| 13 |
* Audio Advantage Micro II support added by: |
| 14 |
* Przemek Rudy ([email protected]) |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <linux/bitfield.h> |
| 18 |
#include <linux/hid.h> |
| 19 |
#include <linux/init.h> |
| 20 |
#include <linux/input.h> |
| 21 |
#include <linux/math64.h> |
| 22 |
#include <linux/slab.h> |
| 23 |
#include <linux/usb.h> |
| 24 |
#include <linux/usb/audio.h> |
| 25 |
|
| 26 |
#include <sound/asoundef.h> |
| 27 |
#include <sound/core.h> |
| 28 |
#include <sound/control.h> |
| 29 |
#include <sound/hda_verbs.h> |
| 30 |
#include <sound/hwdep.h> |
| 31 |
#include <sound/info.h> |
| 32 |
#include <sound/tlv.h> |
| 33 |
|
| 34 |
#include "usbaudio.h" |
| 35 |
#include "mixer.h" |
| 36 |
#include "mixer_quirks.h" |
| 37 |
#include "mixer_scarlett.h" |
| 38 |
#include "mixer_scarlett2.h" |
| 39 |
#include "mixer_us16x08.h" |
| 40 |
#include "mixer_s1810c.h" |
| 41 |
#include "helper.h" |
| 42 |
#include "fcp.h" |
| 43 |
|
| 44 |
struct std_mono_table { |
| 45 |
unsigned int unitid, control, cmask; |
| 46 |
int val_type; |
| 47 |
const char *name; |
| 48 |
snd_kcontrol_tlv_rw_t *tlv_callback; |
| 49 |
}; |
| 50 |
|
| 51 |
/* This function allows for the creation of standard UAC controls. |
| 52 |
* See the quirks for M-Audio FTUs or Ebox-44. |
| 53 |
* If you don't want to set a TLV callback pass NULL. |
| 54 |
* |
| 55 |
* Since there doesn't seem to be a devices that needs a multichannel |
| 56 |
* version, we keep it mono for simplicity. |
| 57 |
*/ |
| 58 |
static int snd_create_std_mono_ctl_offset(struct usb_mixer_interface *mixer, |
| 59 |
unsigned int unitid, |
| 60 |
unsigned int control, |
| 61 |
unsigned int cmask, |
| 62 |
int val_type, |
| 63 |
unsigned int idx_off, |
| 64 |
const char *name, |
| 65 |
snd_kcontrol_tlv_rw_t *tlv_callback) |
| 66 |
{ |
| 67 |
struct usb_mixer_elem_info *cval; |
| 68 |
struct snd_kcontrol *kctl; |
| 69 |
|
| 70 |
cval = kzalloc_obj(*cval); |
| 71 |
if (!cval) |
| 72 |
return -ENOMEM; |
| 73 |
|
| 74 |
snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); |
| 75 |
cval->val_type = val_type; |
| 76 |
cval->channels = 1; |
| 77 |
cval->control = control; |
| 78 |
cval->cmask = cmask; |
| 79 |
cval->idx_off = idx_off; |
| 80 |
|
| 81 |
/* get_min_max() is called only for integer volumes later, |
| 82 |
* so provide a short-cut for booleans |
| 83 |
*/ |
| 84 |
cval->min = 0; |
| 85 |
cval->max = 1; |
| 86 |
cval->res = 0; |
| 87 |
cval->dBmin = 0; |
| 88 |
cval->dBmax = 0; |
| 89 |
|
| 90 |
/* Create control */ |
| 91 |
kctl = snd_ctl_new1(snd_usb_feature_unit_ctl, cval); |
| 92 |
if (!kctl) { |
| 93 |
kfree(cval); |
| 94 |
return -ENOMEM; |
| 95 |
} |
| 96 |
|
| 97 |
/* Set name */ |
| 98 |
snprintf(kctl->id.name, sizeof(kctl->id.name), name); |
| 99 |
kctl->private_free = snd_usb_mixer_elem_free; |
| 100 |
|
| 101 |
/* set TLV */ |
| 102 |
if (tlv_callback) { |
| 103 |
kctl->tlv.c = tlv_callback; |
| 104 |
kctl->vd[0].access |= |
| 105 |
SNDRV_CTL_ELEM_ACCESS_TLV_READ | |
| 106 |
SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
| 107 |
} |
| 108 |
/* Add control to mixer */ |
| 109 |
return snd_usb_mixer_add_control(&cval->head, kctl); |
| 110 |
} |
| 111 |
|
| 112 |
static int snd_create_std_mono_ctl(struct usb_mixer_interface *mixer, |
| 113 |
unsigned int unitid, |
| 114 |
unsigned int control, |
| 115 |
unsigned int cmask, |
| 116 |
int val_type, |
| 117 |
const char *name, |
| 118 |
snd_kcontrol_tlv_rw_t *tlv_callback) |
| 119 |
{ |
| 120 |
return snd_create_std_mono_ctl_offset(mixer, unitid, control, cmask, |
| 121 |
val_type, 0 /* Offset */, |
| 122 |
name, tlv_callback); |
| 123 |
} |
| 124 |
|
| 125 |
/* |
| 126 |
* Create a set of standard UAC controls from a table |
| 127 |
*/ |
| 128 |
static int snd_create_std_mono_table(struct usb_mixer_interface *mixer, |
| 129 |
const struct std_mono_table *t) |
| 130 |
{ |
| 131 |
int err; |
| 132 |
|
| 133 |
while (t->name) { |
| 134 |
err = snd_create_std_mono_ctl(mixer, t->unitid, t->control, |
| 135 |
t->cmask, t->val_type, t->name, |
| 136 |
t->tlv_callback); |
| 137 |
if (err < 0) |
| 138 |
return err; |
| 139 |
t++; |
| 140 |
} |
| 141 |
|
| 142 |
return 0; |
| 143 |
} |
| 144 |
|
| 145 |
static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer, |
| 146 |
int id, |
| 147 |
usb_mixer_elem_resume_func_t resume, |
| 148 |
const struct snd_kcontrol_new *knew, |
| 149 |
struct usb_mixer_elem_list **listp) |
| 150 |
{ |
| 151 |
struct usb_mixer_elem_list *list; |
| 152 |
struct snd_kcontrol *kctl; |
| 153 |
|
| 154 |
list = kzalloc_obj(*list); |
| 155 |
if (!list) |
| 156 |
return -ENOMEM; |
| 157 |
if (listp) |
| 158 |
*listp = list; |
| 159 |
list->mixer = mixer; |
| 160 |
list->id = id; |
| 161 |
list->resume = resume; |
| 162 |
kctl = snd_ctl_new1(knew, list); |
| 163 |
if (!kctl) { |
| 164 |
kfree(list); |
| 165 |
return -ENOMEM; |
| 166 |
} |
| 167 |
kctl->private_free = snd_usb_mixer_elem_free; |
| 168 |
/* don't use snd_usb_mixer_add_control() here, this is a special list element */ |
| 169 |
return snd_usb_mixer_add_list(list, kctl, false); |
| 170 |
} |
| 171 |
|
| 172 |
/* |
| 173 |
* Sound Blaster remote control configuration |
| 174 |
* |
| 175 |
* format of remote control data: |
| 176 |
* Extigy: xx 00 |
| 177 |
* Audigy 2 NX: 06 80 xx 00 00 00 |
| 178 |
* Live! 24-bit: 06 80 xx yy 22 83 |
| 179 |
*/ |
| 180 |
static const struct rc_config { |
| 181 |
u32 usb_id; |
| 182 |
u8 offset; |
| 183 |
u8 length; |
| 184 |
u8 packet_length; |
| 185 |
u8 min_packet_length; /* minimum accepted length of the URB result */ |
| 186 |
u8 mute_mixer_id; |
| 187 |
u32 mute_code; |
| 188 |
} rc_configs[] = { |
| 189 |
{ USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ |
| 190 |
{ USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ |
| 191 |
{ USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ |
| 192 |
{ USB_ID(0x041e, 0x3042), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 */ |
| 193 |
{ USB_ID(0x041e, 0x30df), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
| 194 |
{ USB_ID(0x041e, 0x3237), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
| 195 |
{ USB_ID(0x041e, 0x3263), 0, 1, 1, 1, 1, 0x000d }, /* Usb X-Fi S51 Pro */ |
| 196 |
{ USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */ |
| 197 |
}; |
| 198 |
|
| 199 |
static void snd_usb_soundblaster_remote_complete(struct urb *urb) |
| 200 |
{ |
| 201 |
struct usb_mixer_interface *mixer = urb->context; |
| 202 |
const struct rc_config *rc = mixer->rc_cfg; |
| 203 |
u32 code; |
| 204 |
|
| 205 |
if (urb->status < 0 || urb->actual_length < rc->min_packet_length) |
| 206 |
return; |
| 207 |
|
| 208 |
code = mixer->rc_buffer[rc->offset]; |
| 209 |
if (rc->length == 2) |
| 210 |
code |= mixer->rc_buffer[rc->offset + 1] << 8; |
| 211 |
|
| 212 |
/* the Mute button actually changes the mixer control */ |
| 213 |
if (code == rc->mute_code) |
| 214 |
snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id); |
| 215 |
mixer->rc_code = code; |
| 216 |
wake_up(&mixer->rc_waitq); |
| 217 |
} |
| 218 |
|
| 219 |
static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, |
| 220 |
long count, loff_t *offset) |
| 221 |
{ |
| 222 |
struct usb_mixer_interface *mixer = hw->private_data; |
| 223 |
int err; |
| 224 |
u32 rc_code; |
| 225 |
|
| 226 |
if (count != 1 && count != 4) |
| 227 |
return -EINVAL; |
| 228 |
err = wait_event_interruptible(mixer->rc_waitq, |
| 229 |
(rc_code = xchg(&mixer->rc_code, 0)) != 0); |
| 230 |
if (err == 0) { |
| 231 |
if (count == 1) |
| 232 |
err = put_user(rc_code, buf); |
| 233 |
else |
| 234 |
err = put_user(rc_code, (u32 __user *)buf); |
| 235 |
} |
| 236 |
return err < 0 ? err : count; |
| 237 |
} |
| 238 |
|
| 239 |
static __poll_t snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file, |
| 240 |
poll_table *wait) |
| 241 |
{ |
| 242 |
struct usb_mixer_interface *mixer = hw->private_data; |
| 243 |
|
| 244 |
poll_wait(file, &mixer->rc_waitq, wait); |
| 245 |
return mixer->rc_code ? EPOLLIN | EPOLLRDNORM : 0; |
| 246 |
} |
| 247 |
|
| 248 |
static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer) |
| 249 |
{ |
| 250 |
struct snd_hwdep *hwdep; |
| 251 |
int err, len, i; |
| 252 |
|
| 253 |
for (i = 0; i < ARRAY_SIZE(rc_configs); ++i) |
| 254 |
if (rc_configs[i].usb_id == mixer->chip->usb_id) |
| 255 |
break; |
| 256 |
if (i >= ARRAY_SIZE(rc_configs)) |
| 257 |
return 0; |
| 258 |
mixer->rc_cfg = &rc_configs[i]; |
| 259 |
|
| 260 |
len = mixer->rc_cfg->packet_length; |
| 261 |
|
| 262 |
init_waitqueue_head(&mixer->rc_waitq); |
| 263 |
err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep); |
| 264 |
if (err < 0) |
| 265 |
return err; |
| 266 |
snprintf(hwdep->name, sizeof(hwdep->name), |
| 267 |
"%s remote control", mixer->chip->card->shortname); |
| 268 |
hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; |
| 269 |
hwdep->private_data = mixer; |
| 270 |
hwdep->ops.read = snd_usb_sbrc_hwdep_read; |
| 271 |
hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; |
| 272 |
hwdep->exclusive = 1; |
| 273 |
|
| 274 |
mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 275 |
if (!mixer->rc_urb) |
| 276 |
return -ENOMEM; |
| 277 |
mixer->rc_setup_packet = kmalloc_obj(*mixer->rc_setup_packet); |
| 278 |
if (!mixer->rc_setup_packet) { |
| 279 |
usb_free_urb(mixer->rc_urb); |
| 280 |
mixer->rc_urb = NULL; |
| 281 |
return -ENOMEM; |
| 282 |
} |
| 283 |
mixer->rc_setup_packet->bRequestType = |
| 284 |
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE; |
| 285 |
mixer->rc_setup_packet->bRequest = UAC_GET_MEM; |
| 286 |
mixer->rc_setup_packet->wValue = cpu_to_le16(0); |
| 287 |
mixer->rc_setup_packet->wIndex = cpu_to_le16(0); |
| 288 |
mixer->rc_setup_packet->wLength = cpu_to_le16(len); |
| 289 |
usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev, |
| 290 |
usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 291 |
(u8 *)mixer->rc_setup_packet, mixer->rc_buffer, len, |
| 292 |
snd_usb_soundblaster_remote_complete, mixer); |
| 293 |
return 0; |
| 294 |
} |
| 295 |
|
| 296 |
#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info |
| 297 |
|
| 298 |
static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 299 |
{ |
| 300 |
ucontrol->value.integer.value[0] = kcontrol->private_value >> 8; |
| 301 |
return 0; |
| 302 |
} |
| 303 |
|
| 304 |
static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer, |
| 305 |
int value, int index) |
| 306 |
{ |
| 307 |
struct snd_usb_audio *chip = mixer->chip; |
| 308 |
int err; |
| 309 |
|
| 310 |
CLASS(snd_usb_lock, pm)(chip); |
| 311 |
if (pm.err < 0) |
| 312 |
return pm.err; |
| 313 |
|
| 314 |
if (chip->usb_id == USB_ID(0x041e, 0x3042) || /* USB X-Fi S51 */ |
| 315 |
chip->usb_id == USB_ID(0x041e, 0x30df)) /* USB X-Fi S51 Pro */ |
| 316 |
err = snd_usb_ctl_msg(chip->dev, |
| 317 |
usb_sndctrlpipe(chip->dev, 0), 0x24, |
| 318 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 319 |
!value, 0, NULL, 0); |
| 320 |
else |
| 321 |
err = snd_usb_ctl_msg(chip->dev, |
| 322 |
usb_sndctrlpipe(chip->dev, 0), 0x24, |
| 323 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 324 |
value, index + 2, NULL, 0); |
| 325 |
return err; |
| 326 |
} |
| 327 |
|
| 328 |
static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, |
| 329 |
struct snd_ctl_elem_value *ucontrol) |
| 330 |
{ |
| 331 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 332 |
struct usb_mixer_interface *mixer = list->mixer; |
| 333 |
int index = kcontrol->private_value & 0xff; |
| 334 |
unsigned int value = ucontrol->value.integer.value[0]; |
| 335 |
int old_value = kcontrol->private_value >> 8; |
| 336 |
int err; |
| 337 |
|
| 338 |
if (value > 1) |
| 339 |
return -EINVAL; |
| 340 |
if (value == old_value) |
| 341 |
return 0; |
| 342 |
kcontrol->private_value = (value << 8) | index; |
| 343 |
err = snd_audigy2nx_led_update(mixer, value, index); |
| 344 |
return err < 0 ? err : 1; |
| 345 |
} |
| 346 |
|
| 347 |
static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list) |
| 348 |
{ |
| 349 |
int priv_value = list->kctl->private_value; |
| 350 |
|
| 351 |
return snd_audigy2nx_led_update(list->mixer, priv_value >> 8, |
| 352 |
priv_value & 0xff); |
| 353 |
} |
| 354 |
|
| 355 |
/* name and private_value are set dynamically */ |
| 356 |
static const struct snd_kcontrol_new snd_audigy2nx_control = { |
| 357 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 358 |
.info = snd_audigy2nx_led_info, |
| 359 |
.get = snd_audigy2nx_led_get, |
| 360 |
.put = snd_audigy2nx_led_put, |
| 361 |
}; |
| 362 |
|
| 363 |
static const char * const snd_audigy2nx_led_names[] = { |
| 364 |
"CMSS LED Switch", |
| 365 |
"Power LED Switch", |
| 366 |
"Dolby Digital LED Switch", |
| 367 |
}; |
| 368 |
|
| 369 |
static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer) |
| 370 |
{ |
| 371 |
int i, err; |
| 372 |
|
| 373 |
for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) { |
| 374 |
struct snd_kcontrol_new knew; |
| 375 |
|
| 376 |
/* USB X-Fi S51 doesn't have a CMSS LED */ |
| 377 |
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042) && i == 0) |
| 378 |
continue; |
| 379 |
/* USB X-Fi S51 Pro doesn't have one either */ |
| 380 |
if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df) && i == 0) |
| 381 |
continue; |
| 382 |
if (i > 1 && /* Live24ext has 2 LEDs only */ |
| 383 |
(mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 384 |
mixer->chip->usb_id == USB_ID(0x041e, 0x3042) || |
| 385 |
mixer->chip->usb_id == USB_ID(0x041e, 0x30df) || |
| 386 |
mixer->chip->usb_id == USB_ID(0x041e, 0x3048))) |
| 387 |
break; |
| 388 |
|
| 389 |
knew = snd_audigy2nx_control; |
| 390 |
knew.name = snd_audigy2nx_led_names[i]; |
| 391 |
knew.private_value = (1 << 8) | i; /* LED on as default */ |
| 392 |
err = add_single_ctl_with_resume(mixer, 0, |
| 393 |
snd_audigy2nx_led_resume, |
| 394 |
&knew, NULL); |
| 395 |
if (err < 0) |
| 396 |
return err; |
| 397 |
} |
| 398 |
return 0; |
| 399 |
} |
| 400 |
|
| 401 |
static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, |
| 402 |
struct snd_info_buffer *buffer) |
| 403 |
{ |
| 404 |
static const struct sb_jack { |
| 405 |
int unitid; |
| 406 |
const char *name; |
| 407 |
} jacks_audigy2nx[] = { |
| 408 |
{4, "dig in "}, |
| 409 |
{7, "line in"}, |
| 410 |
{19, "spk out"}, |
| 411 |
{20, "hph out"}, |
| 412 |
{-1, NULL} |
| 413 |
}, jacks_live24ext[] = { |
| 414 |
{4, "line in"}, /* &1=Line, &2=Mic*/ |
| 415 |
{3, "hph out"}, /* headphones */ |
| 416 |
{0, "RC "}, /* last command, 6 bytes see rc_config above */ |
| 417 |
{-1, NULL} |
| 418 |
}; |
| 419 |
const struct sb_jack *jacks; |
| 420 |
struct usb_mixer_interface *mixer = entry->private_data; |
| 421 |
int i, err; |
| 422 |
u8 buf[3]; |
| 423 |
|
| 424 |
snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); |
| 425 |
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) |
| 426 |
jacks = jacks_audigy2nx; |
| 427 |
else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 428 |
mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 429 |
jacks = jacks_live24ext; |
| 430 |
else |
| 431 |
return; |
| 432 |
|
| 433 |
for (i = 0; jacks[i].name; ++i) { |
| 434 |
snd_iprintf(buffer, "%s: ", jacks[i].name); |
| 435 |
CLASS(snd_usb_lock, pm)(mixer->chip); |
| 436 |
if (pm.err < 0) |
| 437 |
return; |
| 438 |
err = snd_usb_ctl_msg(mixer->chip->dev, |
| 439 |
usb_rcvctrlpipe(mixer->chip->dev, 0), |
| 440 |
UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | |
| 441 |
USB_RECIP_INTERFACE, 0, |
| 442 |
jacks[i].unitid << 8, buf, 3); |
| 443 |
if (err == 3 && (buf[0] == 3 || buf[0] == 6)) |
| 444 |
snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); |
| 445 |
else |
| 446 |
snd_iprintf(buffer, "?\n"); |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
/* EMU0204 */ |
| 451 |
static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, |
| 452 |
struct snd_ctl_elem_info *uinfo) |
| 453 |
{ |
| 454 |
static const char * const texts[2] = {"1/2", "3/4"}; |
| 455 |
|
| 456 |
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 457 |
} |
| 458 |
|
| 459 |
static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol, |
| 460 |
struct snd_ctl_elem_value *ucontrol) |
| 461 |
{ |
| 462 |
ucontrol->value.enumerated.item[0] = kcontrol->private_value; |
| 463 |
return 0; |
| 464 |
} |
| 465 |
|
| 466 |
static int snd_emu0204_ch_switch_update(struct usb_mixer_interface *mixer, |
| 467 |
int value) |
| 468 |
{ |
| 469 |
struct snd_usb_audio *chip = mixer->chip; |
| 470 |
unsigned char buf[2]; |
| 471 |
|
| 472 |
CLASS(snd_usb_lock, pm)(chip); |
| 473 |
if (pm.err < 0) |
| 474 |
return pm.err; |
| 475 |
|
| 476 |
buf[0] = 0x01; |
| 477 |
buf[1] = value ? 0x02 : 0x01; |
| 478 |
return snd_usb_ctl_msg(chip->dev, |
| 479 |
usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, |
| 480 |
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
| 481 |
0x0400, 0x0e00, buf, 2); |
| 482 |
} |
| 483 |
|
| 484 |
static int snd_emu0204_ch_switch_put(struct snd_kcontrol *kcontrol, |
| 485 |
struct snd_ctl_elem_value *ucontrol) |
| 486 |
{ |
| 487 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 488 |
struct usb_mixer_interface *mixer = list->mixer; |
| 489 |
unsigned int value = ucontrol->value.enumerated.item[0]; |
| 490 |
int err; |
| 491 |
|
| 492 |
if (value > 1) |
| 493 |
return -EINVAL; |
| 494 |
|
| 495 |
if (value == kcontrol->private_value) |
| 496 |
return 0; |
| 497 |
|
| 498 |
kcontrol->private_value = value; |
| 499 |
err = snd_emu0204_ch_switch_update(mixer, value); |
| 500 |
return err < 0 ? err : 1; |
| 501 |
} |
| 502 |
|
| 503 |
static int snd_emu0204_ch_switch_resume(struct usb_mixer_elem_list *list) |
| 504 |
{ |
| 505 |
return snd_emu0204_ch_switch_update(list->mixer, |
| 506 |
list->kctl->private_value); |
| 507 |
} |
| 508 |
|
| 509 |
static const struct snd_kcontrol_new snd_emu0204_control = { |
| 510 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 511 |
.name = "Front Jack Channels", |
| 512 |
.info = snd_emu0204_ch_switch_info, |
| 513 |
.get = snd_emu0204_ch_switch_get, |
| 514 |
.put = snd_emu0204_ch_switch_put, |
| 515 |
.private_value = 0, |
| 516 |
}; |
| 517 |
|
| 518 |
static int snd_emu0204_controls_create(struct usb_mixer_interface *mixer) |
| 519 |
{ |
| 520 |
return add_single_ctl_with_resume(mixer, 0, |
| 521 |
snd_emu0204_ch_switch_resume, |
| 522 |
&snd_emu0204_control, NULL); |
| 523 |
} |
| 524 |
|
| 525 |
#if IS_REACHABLE(CONFIG_INPUT) |
| 526 |
/* |
| 527 |
* Sony DualSense controller (PS5) jack detection |
| 528 |
* |
| 529 |
* Since this is an UAC 1 device, it doesn't support jack detection. |
| 530 |
* However, the controller hid-playstation driver reports HP & MIC |
| 531 |
* insert events through a dedicated input device. |
| 532 |
*/ |
| 533 |
|
| 534 |
#define SND_DUALSENSE_JACK_OUT_TERM_ID 3 |
| 535 |
#define SND_DUALSENSE_JACK_IN_TERM_ID 4 |
| 536 |
|
| 537 |
struct dualsense_mixer_elem_info { |
| 538 |
struct usb_mixer_elem_info info; |
| 539 |
struct input_handler ih; |
| 540 |
struct input_device_id id_table[2]; |
| 541 |
bool connected; |
| 542 |
}; |
| 543 |
|
| 544 |
static void snd_dualsense_ih_event(struct input_handle *handle, |
| 545 |
unsigned int type, unsigned int code, |
| 546 |
int value) |
| 547 |
{ |
| 548 |
struct dualsense_mixer_elem_info *mei; |
| 549 |
struct usb_mixer_elem_list *me; |
| 550 |
|
| 551 |
if (type != EV_SW) |
| 552 |
return; |
| 553 |
|
| 554 |
mei = container_of(handle->handler, struct dualsense_mixer_elem_info, ih); |
| 555 |
me = &mei->info.head; |
| 556 |
|
| 557 |
if ((me->id == SND_DUALSENSE_JACK_OUT_TERM_ID && code == SW_HEADPHONE_INSERT) || |
| 558 |
(me->id == SND_DUALSENSE_JACK_IN_TERM_ID && code == SW_MICROPHONE_INSERT)) { |
| 559 |
mei->connected = !!value; |
| 560 |
snd_ctl_notify(me->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 561 |
&me->kctl->id); |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
static bool snd_dualsense_ih_match(struct input_handler *handler, |
| 566 |
struct input_dev *dev) |
| 567 |
{ |
| 568 |
struct dualsense_mixer_elem_info *mei; |
| 569 |
struct usb_device *snd_dev; |
| 570 |
char *input_dev_path, *usb_dev_path; |
| 571 |
size_t usb_dev_path_len; |
| 572 |
bool match = false; |
| 573 |
|
| 574 |
mei = container_of(handler, struct dualsense_mixer_elem_info, ih); |
| 575 |
snd_dev = mei->info.head.mixer->chip->dev; |
| 576 |
|
| 577 |
input_dev_path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL); |
| 578 |
if (!input_dev_path) { |
| 579 |
dev_warn(&snd_dev->dev, "Failed to get input dev path\n"); |
| 580 |
return false; |
| 581 |
} |
| 582 |
|
| 583 |
usb_dev_path = kobject_get_path(&snd_dev->dev.kobj, GFP_KERNEL); |
| 584 |
if (!usb_dev_path) { |
| 585 |
dev_warn(&snd_dev->dev, "Failed to get USB dev path\n"); |
| 586 |
goto free_paths; |
| 587 |
} |
| 588 |
|
| 589 |
/* |
| 590 |
* Ensure the VID:PID matched input device supposedly owned by the |
| 591 |
* hid-playstation driver belongs to the actual hardware handled by |
| 592 |
* the current USB audio device, which implies input_dev_path being |
| 593 |
* a subpath of usb_dev_path. |
| 594 |
* |
| 595 |
* This verification is necessary when there is more than one identical |
| 596 |
* controller attached to the host system. |
| 597 |
*/ |
| 598 |
usb_dev_path_len = strlen(usb_dev_path); |
| 599 |
if (usb_dev_path_len >= strlen(input_dev_path)) |
| 600 |
goto free_paths; |
| 601 |
|
| 602 |
usb_dev_path[usb_dev_path_len] = '/'; |
| 603 |
match = !memcmp(input_dev_path, usb_dev_path, usb_dev_path_len + 1); |
| 604 |
|
| 605 |
free_paths: |
| 606 |
kfree(input_dev_path); |
| 607 |
kfree(usb_dev_path); |
| 608 |
|
| 609 |
return match; |
| 610 |
} |
| 611 |
|
| 612 |
static int snd_dualsense_ih_connect(struct input_handler *handler, |
| 613 |
struct input_dev *dev, |
| 614 |
const struct input_device_id *id) |
| 615 |
{ |
| 616 |
struct input_handle *handle; |
| 617 |
int err; |
| 618 |
|
| 619 |
handle = kzalloc_obj(*handle); |
| 620 |
if (!handle) |
| 621 |
return -ENOMEM; |
| 622 |
|
| 623 |
handle->dev = dev; |
| 624 |
handle->handler = handler; |
| 625 |
handle->name = handler->name; |
| 626 |
|
| 627 |
err = input_register_handle(handle); |
| 628 |
if (err) |
| 629 |
goto err_free; |
| 630 |
|
| 631 |
err = input_open_device(handle); |
| 632 |
if (err) |
| 633 |
goto err_unregister; |
| 634 |
|
| 635 |
return 0; |
| 636 |
|
| 637 |
err_unregister: |
| 638 |
input_unregister_handle(handle); |
| 639 |
err_free: |
| 640 |
kfree(handle); |
| 641 |
return err; |
| 642 |
} |
| 643 |
|
| 644 |
static void snd_dualsense_ih_disconnect(struct input_handle *handle) |
| 645 |
{ |
| 646 |
input_close_device(handle); |
| 647 |
input_unregister_handle(handle); |
| 648 |
kfree(handle); |
| 649 |
} |
| 650 |
|
| 651 |
static void snd_dualsense_ih_start(struct input_handle *handle) |
| 652 |
{ |
| 653 |
struct dualsense_mixer_elem_info *mei; |
| 654 |
struct usb_mixer_elem_list *me; |
| 655 |
int status = -1; |
| 656 |
|
| 657 |
mei = container_of(handle->handler, struct dualsense_mixer_elem_info, ih); |
| 658 |
me = &mei->info.head; |
| 659 |
|
| 660 |
if (me->id == SND_DUALSENSE_JACK_OUT_TERM_ID && |
| 661 |
test_bit(SW_HEADPHONE_INSERT, handle->dev->swbit)) |
| 662 |
status = test_bit(SW_HEADPHONE_INSERT, handle->dev->sw); |
| 663 |
else if (me->id == SND_DUALSENSE_JACK_IN_TERM_ID && |
| 664 |
test_bit(SW_MICROPHONE_INSERT, handle->dev->swbit)) |
| 665 |
status = test_bit(SW_MICROPHONE_INSERT, handle->dev->sw); |
| 666 |
|
| 667 |
if (status >= 0) { |
| 668 |
mei->connected = !!status; |
| 669 |
snd_ctl_notify(me->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 670 |
&me->kctl->id); |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
static int snd_dualsense_jack_get(struct snd_kcontrol *kctl, |
| 675 |
struct snd_ctl_elem_value *ucontrol) |
| 676 |
{ |
| 677 |
struct dualsense_mixer_elem_info *mei = snd_kcontrol_chip(kctl); |
| 678 |
|
| 679 |
ucontrol->value.integer.value[0] = mei->connected; |
| 680 |
|
| 681 |
return 0; |
| 682 |
} |
| 683 |
|
| 684 |
static const struct snd_kcontrol_new snd_dualsense_jack_control = { |
| 685 |
.iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 686 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 687 |
.info = snd_ctl_boolean_mono_info, |
| 688 |
.get = snd_dualsense_jack_get, |
| 689 |
}; |
| 690 |
|
| 691 |
static int snd_dualsense_resume_jack(struct usb_mixer_elem_list *list) |
| 692 |
{ |
| 693 |
snd_ctl_notify(list->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 694 |
&list->kctl->id); |
| 695 |
return 0; |
| 696 |
} |
| 697 |
|
| 698 |
static void snd_dualsense_mixer_elem_free(struct snd_kcontrol *kctl) |
| 699 |
{ |
| 700 |
struct dualsense_mixer_elem_info *mei = snd_kcontrol_chip(kctl); |
| 701 |
|
| 702 |
if (mei->ih.event) |
| 703 |
input_unregister_handler(&mei->ih); |
| 704 |
|
| 705 |
snd_usb_mixer_elem_free(kctl); |
| 706 |
} |
| 707 |
|
| 708 |
static int snd_dualsense_jack_create(struct usb_mixer_interface *mixer, |
| 709 |
const char *name, bool is_output) |
| 710 |
{ |
| 711 |
struct dualsense_mixer_elem_info *mei; |
| 712 |
struct input_device_id *idev_id; |
| 713 |
struct snd_kcontrol *kctl; |
| 714 |
int err; |
| 715 |
|
| 716 |
mei = kzalloc_obj(*mei); |
| 717 |
if (!mei) |
| 718 |
return -ENOMEM; |
| 719 |
|
| 720 |
snd_usb_mixer_elem_init_std(&mei->info.head, mixer, |
| 721 |
is_output ? SND_DUALSENSE_JACK_OUT_TERM_ID : |
| 722 |
SND_DUALSENSE_JACK_IN_TERM_ID); |
| 723 |
|
| 724 |
mei->info.head.resume = snd_dualsense_resume_jack; |
| 725 |
mei->info.val_type = USB_MIXER_BOOLEAN; |
| 726 |
mei->info.channels = 1; |
| 727 |
mei->info.min = 0; |
| 728 |
mei->info.max = 1; |
| 729 |
|
| 730 |
kctl = snd_ctl_new1(&snd_dualsense_jack_control, mei); |
| 731 |
if (!kctl) { |
| 732 |
kfree(mei); |
| 733 |
return -ENOMEM; |
| 734 |
} |
| 735 |
|
| 736 |
strscpy(kctl->id.name, name, sizeof(kctl->id.name)); |
| 737 |
kctl->private_free = snd_dualsense_mixer_elem_free; |
| 738 |
|
| 739 |
err = snd_usb_mixer_add_control(&mei->info.head, kctl); |
| 740 |
if (err) |
| 741 |
return err; |
| 742 |
|
| 743 |
idev_id = &mei->id_table[0]; |
| 744 |
idev_id->flags = INPUT_DEVICE_ID_MATCH_VENDOR | INPUT_DEVICE_ID_MATCH_PRODUCT | |
| 745 |
INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT; |
| 746 |
idev_id->vendor = USB_ID_VENDOR(mixer->chip->usb_id); |
| 747 |
idev_id->product = USB_ID_PRODUCT(mixer->chip->usb_id); |
| 748 |
idev_id->evbit[BIT_WORD(EV_SW)] = BIT_MASK(EV_SW); |
| 749 |
if (is_output) |
| 750 |
idev_id->swbit[BIT_WORD(SW_HEADPHONE_INSERT)] = BIT_MASK(SW_HEADPHONE_INSERT); |
| 751 |
else |
| 752 |
idev_id->swbit[BIT_WORD(SW_MICROPHONE_INSERT)] = BIT_MASK(SW_MICROPHONE_INSERT); |
| 753 |
|
| 754 |
mei->ih.event = snd_dualsense_ih_event; |
| 755 |
mei->ih.match = snd_dualsense_ih_match; |
| 756 |
mei->ih.connect = snd_dualsense_ih_connect; |
| 757 |
mei->ih.disconnect = snd_dualsense_ih_disconnect; |
| 758 |
mei->ih.start = snd_dualsense_ih_start; |
| 759 |
mei->ih.name = name; |
| 760 |
mei->ih.id_table = mei->id_table; |
| 761 |
|
| 762 |
err = input_register_handler(&mei->ih); |
| 763 |
if (err) { |
| 764 |
dev_warn(&mixer->chip->dev->dev, |
| 765 |
"Could not register input handler: %d\n", err); |
| 766 |
mei->ih.event = NULL; |
| 767 |
} |
| 768 |
|
| 769 |
return 0; |
| 770 |
} |
| 771 |
|
| 772 |
static int snd_dualsense_controls_create(struct usb_mixer_interface *mixer) |
| 773 |
{ |
| 774 |
int err; |
| 775 |
|
| 776 |
err = snd_dualsense_jack_create(mixer, "Headphone Jack", true); |
| 777 |
if (err < 0) |
| 778 |
return err; |
| 779 |
|
| 780 |
return snd_dualsense_jack_create(mixer, "Headset Mic Jack", false); |
| 781 |
} |
| 782 |
#endif /* IS_REACHABLE(CONFIG_INPUT) */ |
| 783 |
|
| 784 |
/* ASUS Xonar U1 / U3 controls */ |
| 785 |
|
| 786 |
static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol, |
| 787 |
struct snd_ctl_elem_value *ucontrol) |
| 788 |
{ |
| 789 |
ucontrol->value.integer.value[0] = !!(kcontrol->private_value & 0x02); |
| 790 |
return 0; |
| 791 |
} |
| 792 |
|
| 793 |
static int snd_xonar_u1_switch_update(struct usb_mixer_interface *mixer, |
| 794 |
unsigned char status) |
| 795 |
{ |
| 796 |
struct snd_usb_audio *chip = mixer->chip; |
| 797 |
|
| 798 |
CLASS(snd_usb_lock, pm)(chip); |
| 799 |
if (pm.err < 0) |
| 800 |
return pm.err; |
| 801 |
return snd_usb_ctl_msg(chip->dev, |
| 802 |
usb_sndctrlpipe(chip->dev, 0), 0x08, |
| 803 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 804 |
50, 0, &status, 1); |
| 805 |
} |
| 806 |
|
| 807 |
static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol, |
| 808 |
struct snd_ctl_elem_value *ucontrol) |
| 809 |
{ |
| 810 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 811 |
u8 old_status, new_status; |
| 812 |
int err; |
| 813 |
|
| 814 |
old_status = kcontrol->private_value; |
| 815 |
if (ucontrol->value.integer.value[0]) |
| 816 |
new_status = old_status | 0x02; |
| 817 |
else |
| 818 |
new_status = old_status & ~0x02; |
| 819 |
if (new_status == old_status) |
| 820 |
return 0; |
| 821 |
|
| 822 |
kcontrol->private_value = new_status; |
| 823 |
err = snd_xonar_u1_switch_update(list->mixer, new_status); |
| 824 |
return err < 0 ? err : 1; |
| 825 |
} |
| 826 |
|
| 827 |
static int snd_xonar_u1_switch_resume(struct usb_mixer_elem_list *list) |
| 828 |
{ |
| 829 |
return snd_xonar_u1_switch_update(list->mixer, |
| 830 |
list->kctl->private_value); |
| 831 |
} |
| 832 |
|
| 833 |
static const struct snd_kcontrol_new snd_xonar_u1_output_switch = { |
| 834 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 835 |
.name = "Digital Playback Switch", |
| 836 |
.info = snd_ctl_boolean_mono_info, |
| 837 |
.get = snd_xonar_u1_switch_get, |
| 838 |
.put = snd_xonar_u1_switch_put, |
| 839 |
.private_value = 0x05, |
| 840 |
}; |
| 841 |
|
| 842 |
static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer) |
| 843 |
{ |
| 844 |
return add_single_ctl_with_resume(mixer, 0, |
| 845 |
snd_xonar_u1_switch_resume, |
| 846 |
&snd_xonar_u1_output_switch, NULL); |
| 847 |
} |
| 848 |
|
| 849 |
/* Digidesign Mbox 1 helper functions */ |
| 850 |
|
| 851 |
static int snd_mbox1_is_spdif_synced(struct snd_usb_audio *chip) |
| 852 |
{ |
| 853 |
unsigned char buff[3]; |
| 854 |
int err; |
| 855 |
int is_spdif_synced; |
| 856 |
|
| 857 |
/* Read clock source */ |
| 858 |
err = snd_usb_ctl_msg(chip->dev, |
| 859 |
usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 860 |
USB_DIR_IN | |
| 861 |
USB_TYPE_CLASS | |
| 862 |
USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); |
| 863 |
if (err < 0) |
| 864 |
return err; |
| 865 |
|
| 866 |
/* spdif sync: buff is all zeroes */ |
| 867 |
is_spdif_synced = !(buff[0] | buff[1] | buff[2]); |
| 868 |
return is_spdif_synced; |
| 869 |
} |
| 870 |
|
| 871 |
static int snd_mbox1_set_clk_source(struct snd_usb_audio *chip, int rate_or_zero) |
| 872 |
{ |
| 873 |
/* 2 possibilities: Internal -> expects sample rate |
| 874 |
* S/PDIF sync -> expects rate = 0 |
| 875 |
*/ |
| 876 |
unsigned char buff[3]; |
| 877 |
|
| 878 |
buff[0] = (rate_or_zero >> 0) & 0xff; |
| 879 |
buff[1] = (rate_or_zero >> 8) & 0xff; |
| 880 |
buff[2] = (rate_or_zero >> 16) & 0xff; |
| 881 |
|
| 882 |
/* Set clock source */ |
| 883 |
return snd_usb_ctl_msg(chip->dev, |
| 884 |
usb_sndctrlpipe(chip->dev, 0), 0x1, |
| 885 |
USB_TYPE_CLASS | |
| 886 |
USB_RECIP_ENDPOINT, 0x100, 0x81, buff, 3); |
| 887 |
} |
| 888 |
|
| 889 |
static int snd_mbox1_is_spdif_input(struct snd_usb_audio *chip) |
| 890 |
{ |
| 891 |
/* Hardware gives 2 possibilities: ANALOG Source -> 0x01 |
| 892 |
* S/PDIF Source -> 0x02 |
| 893 |
*/ |
| 894 |
int err; |
| 895 |
unsigned char source[1]; |
| 896 |
|
| 897 |
/* Read input source */ |
| 898 |
err = snd_usb_ctl_msg(chip->dev, |
| 899 |
usb_rcvctrlpipe(chip->dev, 0), 0x81, |
| 900 |
USB_DIR_IN | |
| 901 |
USB_TYPE_CLASS | |
| 902 |
USB_RECIP_INTERFACE, 0x00, 0x500, source, 1); |
| 903 |
if (err < 0) |
| 904 |
return err; |
| 905 |
|
| 906 |
return (source[0] == 2); |
| 907 |
} |
| 908 |
|
| 909 |
static int snd_mbox1_set_input_source(struct snd_usb_audio *chip, int is_spdif) |
| 910 |
{ |
| 911 |
/* NB: Setting the input source to S/PDIF resets the clock source to S/PDIF |
| 912 |
* Hardware expects 2 possibilities: ANALOG Source -> 0x01 |
| 913 |
* S/PDIF Source -> 0x02 |
| 914 |
*/ |
| 915 |
unsigned char buff[1]; |
| 916 |
|
| 917 |
buff[0] = (is_spdif & 1) + 1; |
| 918 |
|
| 919 |
/* Set input source */ |
| 920 |
return snd_usb_ctl_msg(chip->dev, |
| 921 |
usb_sndctrlpipe(chip->dev, 0), 0x1, |
| 922 |
USB_TYPE_CLASS | |
| 923 |
USB_RECIP_INTERFACE, 0x00, 0x500, buff, 1); |
| 924 |
} |
| 925 |
|
| 926 |
/* Digidesign Mbox 1 clock source switch (internal/spdif) */ |
| 927 |
|
| 928 |
static int snd_mbox1_clk_switch_get(struct snd_kcontrol *kctl, |
| 929 |
struct snd_ctl_elem_value *ucontrol) |
| 930 |
{ |
| 931 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
| 932 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 933 |
int err; |
| 934 |
|
| 935 |
CLASS(snd_usb_lock, pm)(chip); |
| 936 |
if (pm.err < 0) |
| 937 |
return pm.err; |
| 938 |
|
| 939 |
err = snd_mbox1_is_spdif_synced(chip); |
| 940 |
if (err < 0) |
| 941 |
return err; |
| 942 |
|
| 943 |
kctl->private_value = err; |
| 944 |
ucontrol->value.enumerated.item[0] = kctl->private_value; |
| 945 |
return 0; |
| 946 |
} |
| 947 |
|
| 948 |
static int snd_mbox1_clk_switch_update(struct usb_mixer_interface *mixer, int is_spdif_sync) |
| 949 |
{ |
| 950 |
struct snd_usb_audio *chip = mixer->chip; |
| 951 |
int err; |
| 952 |
|
| 953 |
CLASS(snd_usb_lock, pm)(chip); |
| 954 |
if (pm.err < 0) |
| 955 |
return pm.err; |
| 956 |
|
| 957 |
err = snd_mbox1_is_spdif_input(chip); |
| 958 |
if (err < 0) |
| 959 |
return err; |
| 960 |
|
| 961 |
err = snd_mbox1_is_spdif_synced(chip); |
| 962 |
if (err < 0) |
| 963 |
return err; |
| 964 |
|
| 965 |
/* FIXME: hardcoded sample rate */ |
| 966 |
err = snd_mbox1_set_clk_source(chip, is_spdif_sync ? 0 : 48000); |
| 967 |
if (err < 0) |
| 968 |
return err; |
| 969 |
|
| 970 |
return snd_mbox1_is_spdif_synced(chip); |
| 971 |
} |
| 972 |
|
| 973 |
static int snd_mbox1_clk_switch_put(struct snd_kcontrol *kctl, |
| 974 |
struct snd_ctl_elem_value *ucontrol) |
| 975 |
{ |
| 976 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
| 977 |
struct usb_mixer_interface *mixer = list->mixer; |
| 978 |
int err; |
| 979 |
bool cur_val, new_val; |
| 980 |
|
| 981 |
cur_val = kctl->private_value; |
| 982 |
new_val = ucontrol->value.enumerated.item[0]; |
| 983 |
if (cur_val == new_val) |
| 984 |
return 0; |
| 985 |
|
| 986 |
kctl->private_value = new_val; |
| 987 |
err = snd_mbox1_clk_switch_update(mixer, new_val); |
| 988 |
return err < 0 ? err : 1; |
| 989 |
} |
| 990 |
|
| 991 |
static int snd_mbox1_clk_switch_info(struct snd_kcontrol *kcontrol, |
| 992 |
struct snd_ctl_elem_info *uinfo) |
| 993 |
{ |
| 994 |
static const char *const texts[2] = { |
| 995 |
"Internal", |
| 996 |
"S/PDIF" |
| 997 |
}; |
| 998 |
|
| 999 |
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 1000 |
} |
| 1001 |
|
| 1002 |
static int snd_mbox1_clk_switch_resume(struct usb_mixer_elem_list *list) |
| 1003 |
{ |
| 1004 |
return snd_mbox1_clk_switch_update(list->mixer, list->kctl->private_value); |
| 1005 |
} |
| 1006 |
|
| 1007 |
/* Digidesign Mbox 1 input source switch (analog/spdif) */ |
| 1008 |
|
| 1009 |
static int snd_mbox1_src_switch_get(struct snd_kcontrol *kctl, |
| 1010 |
struct snd_ctl_elem_value *ucontrol) |
| 1011 |
{ |
| 1012 |
ucontrol->value.enumerated.item[0] = kctl->private_value; |
| 1013 |
return 0; |
| 1014 |
} |
| 1015 |
|
| 1016 |
static int snd_mbox1_src_switch_update(struct usb_mixer_interface *mixer, int is_spdif_input) |
| 1017 |
{ |
| 1018 |
struct snd_usb_audio *chip = mixer->chip; |
| 1019 |
int err; |
| 1020 |
|
| 1021 |
CLASS(snd_usb_lock, pm)(chip); |
| 1022 |
if (pm.err < 0) |
| 1023 |
return pm.err; |
| 1024 |
|
| 1025 |
err = snd_mbox1_is_spdif_input(chip); |
| 1026 |
if (err < 0) |
| 1027 |
return err; |
| 1028 |
|
| 1029 |
err = snd_mbox1_set_input_source(chip, is_spdif_input); |
| 1030 |
if (err < 0) |
| 1031 |
return err; |
| 1032 |
|
| 1033 |
err = snd_mbox1_is_spdif_input(chip); |
| 1034 |
if (err < 0) |
| 1035 |
return err; |
| 1036 |
|
| 1037 |
return snd_mbox1_is_spdif_synced(chip); |
| 1038 |
} |
| 1039 |
|
| 1040 |
static int snd_mbox1_src_switch_put(struct snd_kcontrol *kctl, |
| 1041 |
struct snd_ctl_elem_value *ucontrol) |
| 1042 |
{ |
| 1043 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
| 1044 |
struct usb_mixer_interface *mixer = list->mixer; |
| 1045 |
int err; |
| 1046 |
bool cur_val, new_val; |
| 1047 |
|
| 1048 |
cur_val = kctl->private_value; |
| 1049 |
new_val = ucontrol->value.enumerated.item[0]; |
| 1050 |
if (cur_val == new_val) |
| 1051 |
return 0; |
| 1052 |
|
| 1053 |
kctl->private_value = new_val; |
| 1054 |
err = snd_mbox1_src_switch_update(mixer, new_val); |
| 1055 |
return err < 0 ? err : 1; |
| 1056 |
} |
| 1057 |
|
| 1058 |
static int snd_mbox1_src_switch_info(struct snd_kcontrol *kcontrol, |
| 1059 |
struct snd_ctl_elem_info *uinfo) |
| 1060 |
{ |
| 1061 |
static const char *const texts[2] = { |
| 1062 |
"Analog", |
| 1063 |
"S/PDIF" |
| 1064 |
}; |
| 1065 |
|
| 1066 |
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 1067 |
} |
| 1068 |
|
| 1069 |
static int snd_mbox1_src_switch_resume(struct usb_mixer_elem_list *list) |
| 1070 |
{ |
| 1071 |
return snd_mbox1_src_switch_update(list->mixer, list->kctl->private_value); |
| 1072 |
} |
| 1073 |
|
| 1074 |
static const struct snd_kcontrol_new snd_mbox1_clk_switch = { |
| 1075 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1076 |
.name = "Clock Source", |
| 1077 |
.index = 0, |
| 1078 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1079 |
.info = snd_mbox1_clk_switch_info, |
| 1080 |
.get = snd_mbox1_clk_switch_get, |
| 1081 |
.put = snd_mbox1_clk_switch_put, |
| 1082 |
.private_value = 0 |
| 1083 |
}; |
| 1084 |
|
| 1085 |
static const struct snd_kcontrol_new snd_mbox1_src_switch = { |
| 1086 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1087 |
.name = "Input Source", |
| 1088 |
.index = 1, |
| 1089 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1090 |
.info = snd_mbox1_src_switch_info, |
| 1091 |
.get = snd_mbox1_src_switch_get, |
| 1092 |
.put = snd_mbox1_src_switch_put, |
| 1093 |
.private_value = 0 |
| 1094 |
}; |
| 1095 |
|
| 1096 |
static int snd_mbox1_controls_create(struct usb_mixer_interface *mixer) |
| 1097 |
{ |
| 1098 |
int err; |
| 1099 |
|
| 1100 |
err = add_single_ctl_with_resume(mixer, 0, |
| 1101 |
snd_mbox1_clk_switch_resume, |
| 1102 |
&snd_mbox1_clk_switch, NULL); |
| 1103 |
if (err < 0) |
| 1104 |
return err; |
| 1105 |
|
| 1106 |
return add_single_ctl_with_resume(mixer, 1, |
| 1107 |
snd_mbox1_src_switch_resume, |
| 1108 |
&snd_mbox1_src_switch, NULL); |
| 1109 |
} |
| 1110 |
|
| 1111 |
/* Native Instruments device quirks */ |
| 1112 |
|
| 1113 |
#define _MAKE_NI_CONTROL(bRequest, wIndex) ((bRequest) << 16 | (wIndex)) |
| 1114 |
|
| 1115 |
static int snd_ni_control_init_val(struct usb_mixer_interface *mixer, |
| 1116 |
struct snd_kcontrol *kctl) |
| 1117 |
{ |
| 1118 |
struct usb_device *dev = mixer->chip->dev; |
| 1119 |
unsigned int pval = kctl->private_value; |
| 1120 |
u8 value; |
| 1121 |
int err; |
| 1122 |
|
| 1123 |
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 1124 |
(pval >> 16) & 0xff, |
| 1125 |
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, |
| 1126 |
0, pval & 0xffff, &value, 1); |
| 1127 |
if (err < 0) { |
| 1128 |
dev_err(&dev->dev, |
| 1129 |
"unable to issue vendor read request (ret = %d)", err); |
| 1130 |
return err; |
| 1131 |
} |
| 1132 |
|
| 1133 |
kctl->private_value |= ((unsigned int)value << 24); |
| 1134 |
return 0; |
| 1135 |
} |
| 1136 |
|
| 1137 |
static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol, |
| 1138 |
struct snd_ctl_elem_value *ucontrol) |
| 1139 |
{ |
| 1140 |
ucontrol->value.integer.value[0] = kcontrol->private_value >> 24; |
| 1141 |
return 0; |
| 1142 |
} |
| 1143 |
|
| 1144 |
static int snd_ni_update_cur_val(struct usb_mixer_elem_list *list) |
| 1145 |
{ |
| 1146 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 1147 |
unsigned int pval = list->kctl->private_value; |
| 1148 |
|
| 1149 |
CLASS(snd_usb_lock, pm)(chip); |
| 1150 |
if (pm.err < 0) |
| 1151 |
return pm.err; |
| 1152 |
return usb_control_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), |
| 1153 |
(pval >> 16) & 0xff, |
| 1154 |
USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
| 1155 |
pval >> 24, pval & 0xffff, NULL, 0, 1000); |
| 1156 |
} |
| 1157 |
|
| 1158 |
static int snd_nativeinstruments_control_put(struct snd_kcontrol *kcontrol, |
| 1159 |
struct snd_ctl_elem_value *ucontrol) |
| 1160 |
{ |
| 1161 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 1162 |
u8 oldval = (kcontrol->private_value >> 24) & 0xff; |
| 1163 |
u8 newval = ucontrol->value.integer.value[0]; |
| 1164 |
int err; |
| 1165 |
|
| 1166 |
if (oldval == newval) |
| 1167 |
return 0; |
| 1168 |
|
| 1169 |
kcontrol->private_value &= ~(0xff << 24); |
| 1170 |
kcontrol->private_value |= (unsigned int)newval << 24; |
| 1171 |
err = snd_ni_update_cur_val(list); |
| 1172 |
return err < 0 ? err : 1; |
| 1173 |
} |
| 1174 |
|
| 1175 |
static const struct snd_kcontrol_new snd_nativeinstruments_ta6_mixers[] = { |
| 1176 |
{ |
| 1177 |
.name = "Direct Thru Channel A", |
| 1178 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 1179 |
}, |
| 1180 |
{ |
| 1181 |
.name = "Direct Thru Channel B", |
| 1182 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 1183 |
}, |
| 1184 |
{ |
| 1185 |
.name = "Phono Input Channel A", |
| 1186 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 1187 |
}, |
| 1188 |
{ |
| 1189 |
.name = "Phono Input Channel B", |
| 1190 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 1191 |
}, |
| 1192 |
}; |
| 1193 |
|
| 1194 |
static const struct snd_kcontrol_new snd_nativeinstruments_ta10_mixers[] = { |
| 1195 |
{ |
| 1196 |
.name = "Direct Thru Channel A", |
| 1197 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x03), |
| 1198 |
}, |
| 1199 |
{ |
| 1200 |
.name = "Direct Thru Channel B", |
| 1201 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x05), |
| 1202 |
}, |
| 1203 |
{ |
| 1204 |
.name = "Direct Thru Channel C", |
| 1205 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x07), |
| 1206 |
}, |
| 1207 |
{ |
| 1208 |
.name = "Direct Thru Channel D", |
| 1209 |
.private_value = _MAKE_NI_CONTROL(0x01, 0x09), |
| 1210 |
}, |
| 1211 |
{ |
| 1212 |
.name = "Phono Input Channel A", |
| 1213 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x03), |
| 1214 |
}, |
| 1215 |
{ |
| 1216 |
.name = "Phono Input Channel B", |
| 1217 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x05), |
| 1218 |
}, |
| 1219 |
{ |
| 1220 |
.name = "Phono Input Channel C", |
| 1221 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x07), |
| 1222 |
}, |
| 1223 |
{ |
| 1224 |
.name = "Phono Input Channel D", |
| 1225 |
.private_value = _MAKE_NI_CONTROL(0x02, 0x09), |
| 1226 |
}, |
| 1227 |
}; |
| 1228 |
|
| 1229 |
static int snd_nativeinstruments_create_mixer(struct usb_mixer_interface *mixer, |
| 1230 |
const struct snd_kcontrol_new *kc, |
| 1231 |
unsigned int count) |
| 1232 |
{ |
| 1233 |
int i, err = 0; |
| 1234 |
struct snd_kcontrol_new template = { |
| 1235 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1236 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1237 |
.get = snd_nativeinstruments_control_get, |
| 1238 |
.put = snd_nativeinstruments_control_put, |
| 1239 |
.info = snd_ctl_boolean_mono_info, |
| 1240 |
}; |
| 1241 |
|
| 1242 |
for (i = 0; i < count; i++) { |
| 1243 |
struct usb_mixer_elem_list *list; |
| 1244 |
|
| 1245 |
template.name = kc[i].name; |
| 1246 |
template.private_value = kc[i].private_value; |
| 1247 |
|
| 1248 |
err = add_single_ctl_with_resume(mixer, 0, |
| 1249 |
snd_ni_update_cur_val, |
| 1250 |
&template, &list); |
| 1251 |
if (err < 0) |
| 1252 |
break; |
| 1253 |
snd_ni_control_init_val(mixer, list->kctl); |
| 1254 |
} |
| 1255 |
|
| 1256 |
return err; |
| 1257 |
} |
| 1258 |
|
| 1259 |
/* M-Audio FastTrack Ultra quirks */ |
| 1260 |
/* FTU Effect switch (also used by C400/C600) */ |
| 1261 |
static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol, |
| 1262 |
struct snd_ctl_elem_info *uinfo) |
| 1263 |
{ |
| 1264 |
static const char *const texts[8] = { |
| 1265 |
"Room 1", "Room 2", "Room 3", "Hall 1", |
| 1266 |
"Hall 2", "Plate", "Delay", "Echo" |
| 1267 |
}; |
| 1268 |
|
| 1269 |
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 1270 |
} |
| 1271 |
|
| 1272 |
static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer, |
| 1273 |
struct snd_kcontrol *kctl) |
| 1274 |
{ |
| 1275 |
struct usb_device *dev = mixer->chip->dev; |
| 1276 |
unsigned int pval = kctl->private_value; |
| 1277 |
int err; |
| 1278 |
unsigned char value[2]; |
| 1279 |
|
| 1280 |
value[0] = 0x00; |
| 1281 |
value[1] = 0x00; |
| 1282 |
|
| 1283 |
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, |
| 1284 |
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, |
| 1285 |
pval & 0xff00, |
| 1286 |
snd_usb_ctrl_intf(mixer->hostif) | ((pval & 0xff) << 8), |
| 1287 |
value, 2); |
| 1288 |
if (err < 0) |
| 1289 |
return err; |
| 1290 |
|
| 1291 |
kctl->private_value |= (unsigned int)value[0] << 24; |
| 1292 |
return 0; |
| 1293 |
} |
| 1294 |
|
| 1295 |
static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl, |
| 1296 |
struct snd_ctl_elem_value *ucontrol) |
| 1297 |
{ |
| 1298 |
ucontrol->value.enumerated.item[0] = kctl->private_value >> 24; |
| 1299 |
return 0; |
| 1300 |
} |
| 1301 |
|
| 1302 |
static int snd_ftu_eff_switch_update(struct usb_mixer_elem_list *list) |
| 1303 |
{ |
| 1304 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 1305 |
unsigned int pval = list->kctl->private_value; |
| 1306 |
unsigned char value[2]; |
| 1307 |
|
| 1308 |
value[0] = pval >> 24; |
| 1309 |
value[1] = 0; |
| 1310 |
|
| 1311 |
CLASS(snd_usb_lock, pm)(chip); |
| 1312 |
if (pm.err < 0) |
| 1313 |
return pm.err; |
| 1314 |
return snd_usb_ctl_msg(chip->dev, |
| 1315 |
usb_sndctrlpipe(chip->dev, 0), |
| 1316 |
UAC_SET_CUR, |
| 1317 |
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
| 1318 |
pval & 0xff00, |
| 1319 |
snd_usb_ctrl_intf(list->mixer->hostif) | ((pval & 0xff) << 8), |
| 1320 |
value, 2); |
| 1321 |
} |
| 1322 |
|
| 1323 |
static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl, |
| 1324 |
struct snd_ctl_elem_value *ucontrol) |
| 1325 |
{ |
| 1326 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
| 1327 |
unsigned int pval = list->kctl->private_value; |
| 1328 |
int cur_val, err, new_val; |
| 1329 |
|
| 1330 |
cur_val = pval >> 24; |
| 1331 |
new_val = ucontrol->value.enumerated.item[0]; |
| 1332 |
if (cur_val == new_val) |
| 1333 |
return 0; |
| 1334 |
|
| 1335 |
kctl->private_value &= ~(0xff << 24); |
| 1336 |
kctl->private_value |= new_val << 24; |
| 1337 |
err = snd_ftu_eff_switch_update(list); |
| 1338 |
return err < 0 ? err : 1; |
| 1339 |
} |
| 1340 |
|
| 1341 |
static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, |
| 1342 |
int validx, int bUnitID) |
| 1343 |
{ |
| 1344 |
static struct snd_kcontrol_new template = { |
| 1345 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1346 |
.name = "Effect Program Switch", |
| 1347 |
.index = 0, |
| 1348 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1349 |
.info = snd_ftu_eff_switch_info, |
| 1350 |
.get = snd_ftu_eff_switch_get, |
| 1351 |
.put = snd_ftu_eff_switch_put |
| 1352 |
}; |
| 1353 |
struct usb_mixer_elem_list *list; |
| 1354 |
int err; |
| 1355 |
|
| 1356 |
err = add_single_ctl_with_resume(mixer, bUnitID, |
| 1357 |
snd_ftu_eff_switch_update, |
| 1358 |
&template, &list); |
| 1359 |
if (err < 0) |
| 1360 |
return err; |
| 1361 |
list->kctl->private_value = (validx << 8) | bUnitID; |
| 1362 |
snd_ftu_eff_switch_init(mixer, list->kctl); |
| 1363 |
return 0; |
| 1364 |
} |
| 1365 |
|
| 1366 |
/* Create volume controls for FTU devices*/ |
| 1367 |
static int snd_ftu_create_volume_ctls(struct usb_mixer_interface *mixer) |
| 1368 |
{ |
| 1369 |
char name[64]; |
| 1370 |
unsigned int control, cmask; |
| 1371 |
int in, out, err; |
| 1372 |
|
| 1373 |
const unsigned int id = 5; |
| 1374 |
const int val_type = USB_MIXER_S16; |
| 1375 |
|
| 1376 |
for (out = 0; out < 8; out++) { |
| 1377 |
control = out + 1; |
| 1378 |
for (in = 0; in < 8; in++) { |
| 1379 |
cmask = BIT(in); |
| 1380 |
snprintf(name, sizeof(name), |
| 1381 |
"AIn%d - Out%d Capture Volume", |
| 1382 |
in + 1, out + 1); |
| 1383 |
err = snd_create_std_mono_ctl(mixer, id, control, |
| 1384 |
cmask, val_type, name, |
| 1385 |
&snd_usb_mixer_vol_tlv); |
| 1386 |
if (err < 0) |
| 1387 |
return err; |
| 1388 |
} |
| 1389 |
for (in = 8; in < 16; in++) { |
| 1390 |
cmask = BIT(in); |
| 1391 |
snprintf(name, sizeof(name), |
| 1392 |
"DIn%d - Out%d Playback Volume", |
| 1393 |
in - 7, out + 1); |
| 1394 |
err = snd_create_std_mono_ctl(mixer, id, control, |
| 1395 |
cmask, val_type, name, |
| 1396 |
&snd_usb_mixer_vol_tlv); |
| 1397 |
if (err < 0) |
| 1398 |
return err; |
| 1399 |
} |
| 1400 |
} |
| 1401 |
|
| 1402 |
return 0; |
| 1403 |
} |
| 1404 |
|
| 1405 |
/* This control needs a volume quirk, see mixer.c */ |
| 1406 |
static int snd_ftu_create_effect_volume_ctl(struct usb_mixer_interface *mixer) |
| 1407 |
{ |
| 1408 |
static const char name[] = "Effect Volume"; |
| 1409 |
const unsigned int id = 6; |
| 1410 |
const int val_type = USB_MIXER_U8; |
| 1411 |
const unsigned int control = 2; |
| 1412 |
const unsigned int cmask = 0; |
| 1413 |
|
| 1414 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1415 |
name, snd_usb_mixer_vol_tlv); |
| 1416 |
} |
| 1417 |
|
| 1418 |
/* This control needs a volume quirk, see mixer.c */ |
| 1419 |
static int snd_ftu_create_effect_duration_ctl(struct usb_mixer_interface *mixer) |
| 1420 |
{ |
| 1421 |
static const char name[] = "Effect Duration"; |
| 1422 |
const unsigned int id = 6; |
| 1423 |
const int val_type = USB_MIXER_S16; |
| 1424 |
const unsigned int control = 3; |
| 1425 |
const unsigned int cmask = 0; |
| 1426 |
|
| 1427 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1428 |
name, snd_usb_mixer_vol_tlv); |
| 1429 |
} |
| 1430 |
|
| 1431 |
/* This control needs a volume quirk, see mixer.c */ |
| 1432 |
static int snd_ftu_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) |
| 1433 |
{ |
| 1434 |
static const char name[] = "Effect Feedback Volume"; |
| 1435 |
const unsigned int id = 6; |
| 1436 |
const int val_type = USB_MIXER_U8; |
| 1437 |
const unsigned int control = 4; |
| 1438 |
const unsigned int cmask = 0; |
| 1439 |
|
| 1440 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1441 |
name, NULL); |
| 1442 |
} |
| 1443 |
|
| 1444 |
static int snd_ftu_create_effect_return_ctls(struct usb_mixer_interface *mixer) |
| 1445 |
{ |
| 1446 |
unsigned int cmask; |
| 1447 |
int err, ch; |
| 1448 |
char name[48]; |
| 1449 |
|
| 1450 |
const unsigned int id = 7; |
| 1451 |
const int val_type = USB_MIXER_S16; |
| 1452 |
const unsigned int control = 7; |
| 1453 |
|
| 1454 |
for (ch = 0; ch < 4; ++ch) { |
| 1455 |
cmask = BIT(ch); |
| 1456 |
snprintf(name, sizeof(name), |
| 1457 |
"Effect Return %d Volume", ch + 1); |
| 1458 |
err = snd_create_std_mono_ctl(mixer, id, control, |
| 1459 |
cmask, val_type, name, |
| 1460 |
snd_usb_mixer_vol_tlv); |
| 1461 |
if (err < 0) |
| 1462 |
return err; |
| 1463 |
} |
| 1464 |
|
| 1465 |
return 0; |
| 1466 |
} |
| 1467 |
|
| 1468 |
static int snd_ftu_create_effect_send_ctls(struct usb_mixer_interface *mixer) |
| 1469 |
{ |
| 1470 |
unsigned int cmask; |
| 1471 |
int err, ch; |
| 1472 |
char name[48]; |
| 1473 |
|
| 1474 |
const unsigned int id = 5; |
| 1475 |
const int val_type = USB_MIXER_S16; |
| 1476 |
const unsigned int control = 9; |
| 1477 |
|
| 1478 |
for (ch = 0; ch < 8; ++ch) { |
| 1479 |
cmask = BIT(ch); |
| 1480 |
snprintf(name, sizeof(name), |
| 1481 |
"Effect Send AIn%d Volume", ch + 1); |
| 1482 |
err = snd_create_std_mono_ctl(mixer, id, control, cmask, |
| 1483 |
val_type, name, |
| 1484 |
snd_usb_mixer_vol_tlv); |
| 1485 |
if (err < 0) |
| 1486 |
return err; |
| 1487 |
} |
| 1488 |
for (ch = 8; ch < 16; ++ch) { |
| 1489 |
cmask = BIT(ch); |
| 1490 |
snprintf(name, sizeof(name), |
| 1491 |
"Effect Send DIn%d Volume", ch - 7); |
| 1492 |
err = snd_create_std_mono_ctl(mixer, id, control, cmask, |
| 1493 |
val_type, name, |
| 1494 |
snd_usb_mixer_vol_tlv); |
| 1495 |
if (err < 0) |
| 1496 |
return err; |
| 1497 |
} |
| 1498 |
return 0; |
| 1499 |
} |
| 1500 |
|
| 1501 |
static int snd_ftu_create_mixer(struct usb_mixer_interface *mixer) |
| 1502 |
{ |
| 1503 |
int err; |
| 1504 |
|
| 1505 |
err = snd_ftu_create_volume_ctls(mixer); |
| 1506 |
if (err < 0) |
| 1507 |
return err; |
| 1508 |
|
| 1509 |
err = snd_ftu_create_effect_switch(mixer, 1, 6); |
| 1510 |
if (err < 0) |
| 1511 |
return err; |
| 1512 |
|
| 1513 |
err = snd_ftu_create_effect_volume_ctl(mixer); |
| 1514 |
if (err < 0) |
| 1515 |
return err; |
| 1516 |
|
| 1517 |
err = snd_ftu_create_effect_duration_ctl(mixer); |
| 1518 |
if (err < 0) |
| 1519 |
return err; |
| 1520 |
|
| 1521 |
err = snd_ftu_create_effect_feedback_ctl(mixer); |
| 1522 |
if (err < 0) |
| 1523 |
return err; |
| 1524 |
|
| 1525 |
err = snd_ftu_create_effect_return_ctls(mixer); |
| 1526 |
if (err < 0) |
| 1527 |
return err; |
| 1528 |
|
| 1529 |
err = snd_ftu_create_effect_send_ctls(mixer); |
| 1530 |
if (err < 0) |
| 1531 |
return err; |
| 1532 |
|
| 1533 |
return 0; |
| 1534 |
} |
| 1535 |
|
| 1536 |
void snd_emuusb_set_samplerate(struct snd_usb_audio *chip, |
| 1537 |
unsigned char samplerate_id) |
| 1538 |
{ |
| 1539 |
struct usb_mixer_interface *mixer; |
| 1540 |
struct usb_mixer_elem_info *cval; |
| 1541 |
int err; |
| 1542 |
int unitid = 12; /* SampleRate ExtensionUnit ID */ |
| 1543 |
|
| 1544 |
list_for_each_entry(mixer, &chip->mixer_list, list) { |
| 1545 |
if (mixer->id_elems[unitid]) { |
| 1546 |
cval = mixer_elem_list_to_info(mixer->id_elems[unitid]); |
| 1547 |
err = snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, |
| 1548 |
cval->control << 8, |
| 1549 |
samplerate_id); |
| 1550 |
if (!err) |
| 1551 |
snd_usb_mixer_notify_id(mixer, unitid); |
| 1552 |
break; |
| 1553 |
} |
| 1554 |
} |
| 1555 |
} |
| 1556 |
|
| 1557 |
/* M-Audio Fast Track C400/C600 */ |
| 1558 |
/* C400/C600 volume controls, this control needs a volume quirk, see mixer.c */ |
| 1559 |
static int snd_c400_create_vol_ctls(struct usb_mixer_interface *mixer) |
| 1560 |
{ |
| 1561 |
char name[64]; |
| 1562 |
unsigned int cmask, offset; |
| 1563 |
int out, chan, err; |
| 1564 |
int num_outs = 0; |
| 1565 |
int num_ins = 0; |
| 1566 |
|
| 1567 |
const unsigned int id = 0x40; |
| 1568 |
const int val_type = USB_MIXER_S16; |
| 1569 |
const int control = 1; |
| 1570 |
|
| 1571 |
switch (mixer->chip->usb_id) { |
| 1572 |
case USB_ID(0x0763, 0x2030): |
| 1573 |
num_outs = 6; |
| 1574 |
num_ins = 4; |
| 1575 |
break; |
| 1576 |
case USB_ID(0x0763, 0x2031): |
| 1577 |
num_outs = 8; |
| 1578 |
num_ins = 6; |
| 1579 |
break; |
| 1580 |
} |
| 1581 |
|
| 1582 |
for (chan = 0; chan < num_outs + num_ins; chan++) { |
| 1583 |
for (out = 0; out < num_outs; out++) { |
| 1584 |
if (chan < num_outs) { |
| 1585 |
snprintf(name, sizeof(name), |
| 1586 |
"PCM%d-Out%d Playback Volume", |
| 1587 |
chan + 1, out + 1); |
| 1588 |
} else { |
| 1589 |
snprintf(name, sizeof(name), |
| 1590 |
"In%d-Out%d Playback Volume", |
| 1591 |
chan - num_outs + 1, out + 1); |
| 1592 |
} |
| 1593 |
|
| 1594 |
cmask = (out == 0) ? 0 : BIT(out - 1); |
| 1595 |
offset = chan * num_outs; |
| 1596 |
err = snd_create_std_mono_ctl_offset(mixer, id, control, |
| 1597 |
cmask, val_type, offset, name, |
| 1598 |
&snd_usb_mixer_vol_tlv); |
| 1599 |
if (err < 0) |
| 1600 |
return err; |
| 1601 |
} |
| 1602 |
} |
| 1603 |
|
| 1604 |
return 0; |
| 1605 |
} |
| 1606 |
|
| 1607 |
/* This control needs a volume quirk, see mixer.c */ |
| 1608 |
static int snd_c400_create_effect_volume_ctl(struct usb_mixer_interface *mixer) |
| 1609 |
{ |
| 1610 |
static const char name[] = "Effect Volume"; |
| 1611 |
const unsigned int id = 0x43; |
| 1612 |
const int val_type = USB_MIXER_U8; |
| 1613 |
const unsigned int control = 3; |
| 1614 |
const unsigned int cmask = 0; |
| 1615 |
|
| 1616 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1617 |
name, snd_usb_mixer_vol_tlv); |
| 1618 |
} |
| 1619 |
|
| 1620 |
/* This control needs a volume quirk, see mixer.c */ |
| 1621 |
static int snd_c400_create_effect_duration_ctl(struct usb_mixer_interface *mixer) |
| 1622 |
{ |
| 1623 |
static const char name[] = "Effect Duration"; |
| 1624 |
const unsigned int id = 0x43; |
| 1625 |
const int val_type = USB_MIXER_S16; |
| 1626 |
const unsigned int control = 4; |
| 1627 |
const unsigned int cmask = 0; |
| 1628 |
|
| 1629 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1630 |
name, snd_usb_mixer_vol_tlv); |
| 1631 |
} |
| 1632 |
|
| 1633 |
/* This control needs a volume quirk, see mixer.c */ |
| 1634 |
static int snd_c400_create_effect_feedback_ctl(struct usb_mixer_interface *mixer) |
| 1635 |
{ |
| 1636 |
static const char name[] = "Effect Feedback Volume"; |
| 1637 |
const unsigned int id = 0x43; |
| 1638 |
const int val_type = USB_MIXER_U8; |
| 1639 |
const unsigned int control = 5; |
| 1640 |
const unsigned int cmask = 0; |
| 1641 |
|
| 1642 |
return snd_create_std_mono_ctl(mixer, id, control, cmask, val_type, |
| 1643 |
name, NULL); |
| 1644 |
} |
| 1645 |
|
| 1646 |
static int snd_c400_create_effect_vol_ctls(struct usb_mixer_interface *mixer) |
| 1647 |
{ |
| 1648 |
char name[64]; |
| 1649 |
unsigned int cmask; |
| 1650 |
int chan, err; |
| 1651 |
int num_outs = 0; |
| 1652 |
int num_ins = 0; |
| 1653 |
|
| 1654 |
const unsigned int id = 0x42; |
| 1655 |
const int val_type = USB_MIXER_S16; |
| 1656 |
const int control = 1; |
| 1657 |
|
| 1658 |
switch (mixer->chip->usb_id) { |
| 1659 |
case USB_ID(0x0763, 0x2030): |
| 1660 |
num_outs = 6; |
| 1661 |
num_ins = 4; |
| 1662 |
break; |
| 1663 |
case USB_ID(0x0763, 0x2031): |
| 1664 |
num_outs = 8; |
| 1665 |
num_ins = 6; |
| 1666 |
break; |
| 1667 |
} |
| 1668 |
|
| 1669 |
for (chan = 0; chan < num_outs + num_ins; chan++) { |
| 1670 |
if (chan < num_outs) { |
| 1671 |
snprintf(name, sizeof(name), |
| 1672 |
"Effect Send DOut%d", |
| 1673 |
chan + 1); |
| 1674 |
} else { |
| 1675 |
snprintf(name, sizeof(name), |
| 1676 |
"Effect Send AIn%d", |
| 1677 |
chan - num_outs + 1); |
| 1678 |
} |
| 1679 |
|
| 1680 |
cmask = (chan == 0) ? 0 : BIT(chan - 1); |
| 1681 |
err = snd_create_std_mono_ctl(mixer, id, control, |
| 1682 |
cmask, val_type, name, |
| 1683 |
&snd_usb_mixer_vol_tlv); |
| 1684 |
if (err < 0) |
| 1685 |
return err; |
| 1686 |
} |
| 1687 |
|
| 1688 |
return 0; |
| 1689 |
} |
| 1690 |
|
| 1691 |
static int snd_c400_create_effect_ret_vol_ctls(struct usb_mixer_interface *mixer) |
| 1692 |
{ |
| 1693 |
char name[64]; |
| 1694 |
unsigned int cmask; |
| 1695 |
int chan, err; |
| 1696 |
int num_outs = 0; |
| 1697 |
int offset = 0; |
| 1698 |
|
| 1699 |
const unsigned int id = 0x40; |
| 1700 |
const int val_type = USB_MIXER_S16; |
| 1701 |
const int control = 1; |
| 1702 |
|
| 1703 |
switch (mixer->chip->usb_id) { |
| 1704 |
case USB_ID(0x0763, 0x2030): |
| 1705 |
num_outs = 6; |
| 1706 |
offset = 0x3c; |
| 1707 |
/* { 0x3c, 0x43, 0x3e, 0x45, 0x40, 0x47 } */ |
| 1708 |
break; |
| 1709 |
case USB_ID(0x0763, 0x2031): |
| 1710 |
num_outs = 8; |
| 1711 |
offset = 0x70; |
| 1712 |
/* { 0x70, 0x79, 0x72, 0x7b, 0x74, 0x7d, 0x76, 0x7f } */ |
| 1713 |
break; |
| 1714 |
} |
| 1715 |
|
| 1716 |
for (chan = 0; chan < num_outs; chan++) { |
| 1717 |
snprintf(name, sizeof(name), |
| 1718 |
"Effect Return %d", |
| 1719 |
chan + 1); |
| 1720 |
|
| 1721 |
cmask = (chan == 0) ? 0 : |
| 1722 |
BIT(chan + (chan % 2) * num_outs - 1); |
| 1723 |
err = snd_create_std_mono_ctl_offset(mixer, id, control, |
| 1724 |
cmask, val_type, offset, name, |
| 1725 |
&snd_usb_mixer_vol_tlv); |
| 1726 |
if (err < 0) |
| 1727 |
return err; |
| 1728 |
} |
| 1729 |
|
| 1730 |
return 0; |
| 1731 |
} |
| 1732 |
|
| 1733 |
static int snd_c400_create_mixer(struct usb_mixer_interface *mixer) |
| 1734 |
{ |
| 1735 |
int err; |
| 1736 |
|
| 1737 |
err = snd_c400_create_vol_ctls(mixer); |
| 1738 |
if (err < 0) |
| 1739 |
return err; |
| 1740 |
|
| 1741 |
err = snd_c400_create_effect_vol_ctls(mixer); |
| 1742 |
if (err < 0) |
| 1743 |
return err; |
| 1744 |
|
| 1745 |
err = snd_c400_create_effect_ret_vol_ctls(mixer); |
| 1746 |
if (err < 0) |
| 1747 |
return err; |
| 1748 |
|
| 1749 |
err = snd_ftu_create_effect_switch(mixer, 2, 0x43); |
| 1750 |
if (err < 0) |
| 1751 |
return err; |
| 1752 |
|
| 1753 |
err = snd_c400_create_effect_volume_ctl(mixer); |
| 1754 |
if (err < 0) |
| 1755 |
return err; |
| 1756 |
|
| 1757 |
err = snd_c400_create_effect_duration_ctl(mixer); |
| 1758 |
if (err < 0) |
| 1759 |
return err; |
| 1760 |
|
| 1761 |
err = snd_c400_create_effect_feedback_ctl(mixer); |
| 1762 |
if (err < 0) |
| 1763 |
return err; |
| 1764 |
|
| 1765 |
return 0; |
| 1766 |
} |
| 1767 |
|
| 1768 |
/* |
| 1769 |
* The mixer units for Ebox-44 are corrupt, and even where they |
| 1770 |
* are valid they presents mono controls as L and R channels of |
| 1771 |
* stereo. So we provide a good mixer here. |
| 1772 |
*/ |
| 1773 |
static const struct std_mono_table ebox44_table[] = { |
| 1774 |
{ |
| 1775 |
.unitid = 4, |
| 1776 |
.control = 1, |
| 1777 |
.cmask = 0x0, |
| 1778 |
.val_type = USB_MIXER_INV_BOOLEAN, |
| 1779 |
.name = "Headphone Playback Switch" |
| 1780 |
}, |
| 1781 |
{ |
| 1782 |
.unitid = 4, |
| 1783 |
.control = 2, |
| 1784 |
.cmask = 0x1, |
| 1785 |
.val_type = USB_MIXER_S16, |
| 1786 |
.name = "Headphone A Mix Playback Volume" |
| 1787 |
}, |
| 1788 |
{ |
| 1789 |
.unitid = 4, |
| 1790 |
.control = 2, |
| 1791 |
.cmask = 0x2, |
| 1792 |
.val_type = USB_MIXER_S16, |
| 1793 |
.name = "Headphone B Mix Playback Volume" |
| 1794 |
}, |
| 1795 |
|
| 1796 |
{ |
| 1797 |
.unitid = 7, |
| 1798 |
.control = 1, |
| 1799 |
.cmask = 0x0, |
| 1800 |
.val_type = USB_MIXER_INV_BOOLEAN, |
| 1801 |
.name = "Output Playback Switch" |
| 1802 |
}, |
| 1803 |
{ |
| 1804 |
.unitid = 7, |
| 1805 |
.control = 2, |
| 1806 |
.cmask = 0x1, |
| 1807 |
.val_type = USB_MIXER_S16, |
| 1808 |
.name = "Output A Playback Volume" |
| 1809 |
}, |
| 1810 |
{ |
| 1811 |
.unitid = 7, |
| 1812 |
.control = 2, |
| 1813 |
.cmask = 0x2, |
| 1814 |
.val_type = USB_MIXER_S16, |
| 1815 |
.name = "Output B Playback Volume" |
| 1816 |
}, |
| 1817 |
|
| 1818 |
{ |
| 1819 |
.unitid = 10, |
| 1820 |
.control = 1, |
| 1821 |
.cmask = 0x0, |
| 1822 |
.val_type = USB_MIXER_INV_BOOLEAN, |
| 1823 |
.name = "Input Capture Switch" |
| 1824 |
}, |
| 1825 |
{ |
| 1826 |
.unitid = 10, |
| 1827 |
.control = 2, |
| 1828 |
.cmask = 0x1, |
| 1829 |
.val_type = USB_MIXER_S16, |
| 1830 |
.name = "Input A Capture Volume" |
| 1831 |
}, |
| 1832 |
{ |
| 1833 |
.unitid = 10, |
| 1834 |
.control = 2, |
| 1835 |
.cmask = 0x2, |
| 1836 |
.val_type = USB_MIXER_S16, |
| 1837 |
.name = "Input B Capture Volume" |
| 1838 |
}, |
| 1839 |
|
| 1840 |
{} |
| 1841 |
}; |
| 1842 |
|
| 1843 |
/* Audio Advantage Micro II findings: |
| 1844 |
* |
| 1845 |
* Mapping spdif AES bits to vendor register.bit: |
| 1846 |
* AES0: [0 0 0 0 2.3 2.2 2.1 2.0] - default 0x00 |
| 1847 |
* AES1: [3.3 3.2.3.1.3.0 2.7 2.6 2.5 2.4] - default: 0x01 |
| 1848 |
* AES2: [0 0 0 0 0 0 0 0] |
| 1849 |
* AES3: [0 0 0 0 0 0 x 0] - 'x' bit is set basing on standard usb request |
| 1850 |
* (UAC_EP_CS_ATTR_SAMPLE_RATE) for Audio Devices |
| 1851 |
* |
| 1852 |
* power on values: |
| 1853 |
* r2: 0x10 |
| 1854 |
* r3: 0x20 (b7 is zeroed just before playback (except IEC61937) and set |
| 1855 |
* just after it to 0xa0, presumably it disables/mutes some analog |
| 1856 |
* parts when there is no audio.) |
| 1857 |
* r9: 0x28 |
| 1858 |
* |
| 1859 |
* Optical transmitter on/off: |
| 1860 |
* vendor register.bit: 9.1 |
| 1861 |
* 0 - on (0x28 register value) |
| 1862 |
* 1 - off (0x2a register value) |
| 1863 |
* |
| 1864 |
*/ |
| 1865 |
static int snd_microii_spdif_info(struct snd_kcontrol *kcontrol, |
| 1866 |
struct snd_ctl_elem_info *uinfo) |
| 1867 |
{ |
| 1868 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1869 |
uinfo->count = 1; |
| 1870 |
return 0; |
| 1871 |
} |
| 1872 |
|
| 1873 |
static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 1874 |
struct snd_ctl_elem_value *ucontrol) |
| 1875 |
{ |
| 1876 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 1877 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 1878 |
int err; |
| 1879 |
struct usb_interface *iface; |
| 1880 |
struct usb_host_interface *alts; |
| 1881 |
unsigned int ep; |
| 1882 |
unsigned char data[3]; |
| 1883 |
int rate; |
| 1884 |
|
| 1885 |
CLASS(snd_usb_lock, pm)(chip); |
| 1886 |
if (pm.err < 0) |
| 1887 |
return pm.err; |
| 1888 |
|
| 1889 |
ucontrol->value.iec958.status[0] = kcontrol->private_value & 0xff; |
| 1890 |
ucontrol->value.iec958.status[1] = (kcontrol->private_value >> 8) & 0xff; |
| 1891 |
ucontrol->value.iec958.status[2] = 0x00; |
| 1892 |
|
| 1893 |
/* use known values for that card: interface#1 altsetting#1 */ |
| 1894 |
iface = usb_ifnum_to_if(chip->dev, 1); |
| 1895 |
if (!iface || iface->num_altsetting < 2) |
| 1896 |
return -EINVAL; |
| 1897 |
alts = &iface->altsetting[1]; |
| 1898 |
if (get_iface_desc(alts)->bNumEndpoints < 1) |
| 1899 |
return -EINVAL; |
| 1900 |
ep = get_endpoint(alts, 0)->bEndpointAddress; |
| 1901 |
|
| 1902 |
err = snd_usb_ctl_msg(chip->dev, |
| 1903 |
usb_rcvctrlpipe(chip->dev, 0), |
| 1904 |
UAC_GET_CUR, |
| 1905 |
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, |
| 1906 |
UAC_EP_CS_ATTR_SAMPLE_RATE << 8, |
| 1907 |
ep, |
| 1908 |
data, |
| 1909 |
sizeof(data)); |
| 1910 |
if (err < 0) |
| 1911 |
return err; |
| 1912 |
|
| 1913 |
rate = data[0] | (data[1] << 8) | (data[2] << 16); |
| 1914 |
ucontrol->value.iec958.status[3] = (rate == 48000) ? |
| 1915 |
IEC958_AES3_CON_FS_48000 : IEC958_AES3_CON_FS_44100; |
| 1916 |
|
| 1917 |
return 0; |
| 1918 |
} |
| 1919 |
|
| 1920 |
static int snd_microii_spdif_default_update(struct usb_mixer_elem_list *list) |
| 1921 |
{ |
| 1922 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 1923 |
unsigned int pval = list->kctl->private_value; |
| 1924 |
u8 reg; |
| 1925 |
int err; |
| 1926 |
|
| 1927 |
CLASS(snd_usb_lock, pm)(chip); |
| 1928 |
if (pm.err < 0) |
| 1929 |
return pm.err; |
| 1930 |
|
| 1931 |
reg = ((pval >> 4) & 0xf0) | (pval & 0x0f); |
| 1932 |
err = snd_usb_ctl_msg(chip->dev, |
| 1933 |
usb_sndctrlpipe(chip->dev, 0), |
| 1934 |
UAC_SET_CUR, |
| 1935 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 1936 |
reg, |
| 1937 |
2, |
| 1938 |
NULL, |
| 1939 |
0); |
| 1940 |
if (err < 0) |
| 1941 |
return err; |
| 1942 |
|
| 1943 |
reg = (pval & IEC958_AES0_NONAUDIO) ? 0xa0 : 0x20; |
| 1944 |
reg |= (pval >> 12) & 0x0f; |
| 1945 |
err = snd_usb_ctl_msg(chip->dev, |
| 1946 |
usb_sndctrlpipe(chip->dev, 0), |
| 1947 |
UAC_SET_CUR, |
| 1948 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 1949 |
reg, |
| 1950 |
3, |
| 1951 |
NULL, |
| 1952 |
0); |
| 1953 |
return err; |
| 1954 |
} |
| 1955 |
|
| 1956 |
static int snd_microii_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 1957 |
struct snd_ctl_elem_value *ucontrol) |
| 1958 |
{ |
| 1959 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 1960 |
unsigned int pval, pval_old; |
| 1961 |
int err; |
| 1962 |
|
| 1963 |
pval = kcontrol->private_value; |
| 1964 |
pval_old = pval; |
| 1965 |
pval &= 0xfffff0f0; |
| 1966 |
pval |= (ucontrol->value.iec958.status[1] & 0x0f) << 8; |
| 1967 |
pval |= (ucontrol->value.iec958.status[0] & 0x0f); |
| 1968 |
|
| 1969 |
pval &= 0xffff0fff; |
| 1970 |
pval |= (ucontrol->value.iec958.status[1] & 0xf0) << 8; |
| 1971 |
|
| 1972 |
/* The frequency bits in AES3 cannot be set via register access. */ |
| 1973 |
|
| 1974 |
/* Silently ignore any bits from the request that cannot be set. */ |
| 1975 |
|
| 1976 |
if (pval == pval_old) |
| 1977 |
return 0; |
| 1978 |
|
| 1979 |
kcontrol->private_value = pval; |
| 1980 |
err = snd_microii_spdif_default_update(list); |
| 1981 |
return err < 0 ? err : 1; |
| 1982 |
} |
| 1983 |
|
| 1984 |
static int snd_microii_spdif_mask_get(struct snd_kcontrol *kcontrol, |
| 1985 |
struct snd_ctl_elem_value *ucontrol) |
| 1986 |
{ |
| 1987 |
ucontrol->value.iec958.status[0] = 0x0f; |
| 1988 |
ucontrol->value.iec958.status[1] = 0xff; |
| 1989 |
ucontrol->value.iec958.status[2] = 0x00; |
| 1990 |
ucontrol->value.iec958.status[3] = 0x00; |
| 1991 |
|
| 1992 |
return 0; |
| 1993 |
} |
| 1994 |
|
| 1995 |
static int snd_microii_spdif_switch_get(struct snd_kcontrol *kcontrol, |
| 1996 |
struct snd_ctl_elem_value *ucontrol) |
| 1997 |
{ |
| 1998 |
ucontrol->value.integer.value[0] = !(kcontrol->private_value & 0x02); |
| 1999 |
|
| 2000 |
return 0; |
| 2001 |
} |
| 2002 |
|
| 2003 |
static int snd_microii_spdif_switch_update(struct usb_mixer_elem_list *list) |
| 2004 |
{ |
| 2005 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 2006 |
u8 reg = list->kctl->private_value; |
| 2007 |
|
| 2008 |
CLASS(snd_usb_lock, pm)(chip); |
| 2009 |
if (pm.err < 0) |
| 2010 |
return pm.err; |
| 2011 |
|
| 2012 |
return snd_usb_ctl_msg(chip->dev, |
| 2013 |
usb_sndctrlpipe(chip->dev, 0), |
| 2014 |
UAC_SET_CUR, |
| 2015 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, |
| 2016 |
reg, |
| 2017 |
9, |
| 2018 |
NULL, |
| 2019 |
0); |
| 2020 |
} |
| 2021 |
|
| 2022 |
static int snd_microii_spdif_switch_put(struct snd_kcontrol *kcontrol, |
| 2023 |
struct snd_ctl_elem_value *ucontrol) |
| 2024 |
{ |
| 2025 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 2026 |
u8 reg; |
| 2027 |
int err; |
| 2028 |
|
| 2029 |
reg = ucontrol->value.integer.value[0] ? 0x28 : 0x2a; |
| 2030 |
if (reg == list->kctl->private_value) |
| 2031 |
return 0; |
| 2032 |
|
| 2033 |
kcontrol->private_value = reg; |
| 2034 |
err = snd_microii_spdif_switch_update(list); |
| 2035 |
return err < 0 ? err : 1; |
| 2036 |
} |
| 2037 |
|
| 2038 |
static const struct snd_kcontrol_new snd_microii_mixer_spdif[] = { |
| 2039 |
{ |
| 2040 |
.iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 2041 |
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 2042 |
.info = snd_microii_spdif_info, |
| 2043 |
.get = snd_microii_spdif_default_get, |
| 2044 |
.put = snd_microii_spdif_default_put, |
| 2045 |
.private_value = 0x00000100UL,/* reset value */ |
| 2046 |
}, |
| 2047 |
{ |
| 2048 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2049 |
.iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 2050 |
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), |
| 2051 |
.info = snd_microii_spdif_info, |
| 2052 |
.get = snd_microii_spdif_mask_get, |
| 2053 |
}, |
| 2054 |
{ |
| 2055 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2056 |
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), |
| 2057 |
.info = snd_ctl_boolean_mono_info, |
| 2058 |
.get = snd_microii_spdif_switch_get, |
| 2059 |
.put = snd_microii_spdif_switch_put, |
| 2060 |
.private_value = 0x00000028UL,/* reset value */ |
| 2061 |
} |
| 2062 |
}; |
| 2063 |
|
| 2064 |
static int snd_microii_controls_create(struct usb_mixer_interface *mixer) |
| 2065 |
{ |
| 2066 |
int err, i; |
| 2067 |
static const usb_mixer_elem_resume_func_t resume_funcs[] = { |
| 2068 |
snd_microii_spdif_default_update, |
| 2069 |
NULL, |
| 2070 |
snd_microii_spdif_switch_update |
| 2071 |
}; |
| 2072 |
|
| 2073 |
for (i = 0; i < ARRAY_SIZE(snd_microii_mixer_spdif); ++i) { |
| 2074 |
err = add_single_ctl_with_resume(mixer, 0, |
| 2075 |
resume_funcs[i], |
| 2076 |
&snd_microii_mixer_spdif[i], |
| 2077 |
NULL); |
| 2078 |
if (err < 0) |
| 2079 |
return err; |
| 2080 |
} |
| 2081 |
|
| 2082 |
return 0; |
| 2083 |
} |
| 2084 |
|
| 2085 |
/* Creative Sound Blaster E1 */ |
| 2086 |
|
| 2087 |
static int snd_soundblaster_e1_switch_get(struct snd_kcontrol *kcontrol, |
| 2088 |
struct snd_ctl_elem_value *ucontrol) |
| 2089 |
{ |
| 2090 |
ucontrol->value.integer.value[0] = kcontrol->private_value; |
| 2091 |
return 0; |
| 2092 |
} |
| 2093 |
|
| 2094 |
static int snd_soundblaster_e1_switch_update(struct usb_mixer_interface *mixer, |
| 2095 |
unsigned char state) |
| 2096 |
{ |
| 2097 |
struct snd_usb_audio *chip = mixer->chip; |
| 2098 |
unsigned char buff[2]; |
| 2099 |
|
| 2100 |
buff[0] = 0x02; |
| 2101 |
buff[1] = state ? 0x02 : 0x00; |
| 2102 |
|
| 2103 |
CLASS(snd_usb_lock, pm)(chip); |
| 2104 |
if (pm.err < 0) |
| 2105 |
return pm.err; |
| 2106 |
return snd_usb_ctl_msg(chip->dev, |
| 2107 |
usb_sndctrlpipe(chip->dev, 0), HID_REQ_SET_REPORT, |
| 2108 |
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, |
| 2109 |
0x0202, 3, buff, 2); |
| 2110 |
} |
| 2111 |
|
| 2112 |
static int snd_soundblaster_e1_switch_put(struct snd_kcontrol *kcontrol, |
| 2113 |
struct snd_ctl_elem_value *ucontrol) |
| 2114 |
{ |
| 2115 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 2116 |
unsigned char value = !!ucontrol->value.integer.value[0]; |
| 2117 |
int err; |
| 2118 |
|
| 2119 |
if (kcontrol->private_value == value) |
| 2120 |
return 0; |
| 2121 |
kcontrol->private_value = value; |
| 2122 |
err = snd_soundblaster_e1_switch_update(list->mixer, value); |
| 2123 |
return err < 0 ? err : 1; |
| 2124 |
} |
| 2125 |
|
| 2126 |
static int snd_soundblaster_e1_switch_resume(struct usb_mixer_elem_list *list) |
| 2127 |
{ |
| 2128 |
return snd_soundblaster_e1_switch_update(list->mixer, |
| 2129 |
list->kctl->private_value); |
| 2130 |
} |
| 2131 |
|
| 2132 |
static int snd_soundblaster_e1_switch_info(struct snd_kcontrol *kcontrol, |
| 2133 |
struct snd_ctl_elem_info *uinfo) |
| 2134 |
{ |
| 2135 |
static const char *const texts[2] = { |
| 2136 |
"Mic", "Aux" |
| 2137 |
}; |
| 2138 |
|
| 2139 |
return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts); |
| 2140 |
} |
| 2141 |
|
| 2142 |
static const struct snd_kcontrol_new snd_soundblaster_e1_input_switch = { |
| 2143 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2144 |
.name = "Input Source", |
| 2145 |
.info = snd_soundblaster_e1_switch_info, |
| 2146 |
.get = snd_soundblaster_e1_switch_get, |
| 2147 |
.put = snd_soundblaster_e1_switch_put, |
| 2148 |
.private_value = 0, |
| 2149 |
}; |
| 2150 |
|
| 2151 |
static int snd_soundblaster_e1_switch_create(struct usb_mixer_interface *mixer) |
| 2152 |
{ |
| 2153 |
return add_single_ctl_with_resume(mixer, 0, |
| 2154 |
snd_soundblaster_e1_switch_resume, |
| 2155 |
&snd_soundblaster_e1_input_switch, |
| 2156 |
NULL); |
| 2157 |
} |
| 2158 |
|
| 2159 |
/* |
| 2160 |
* Dell WD15 dock jack detection |
| 2161 |
* |
| 2162 |
* The WD15 contains an ALC4020 USB audio controller and ALC3263 audio codec |
| 2163 |
* from Realtek. It is a UAC 1 device, and UAC 1 does not support jack |
| 2164 |
* detection. Instead, jack detection works by sending HD Audio commands over |
| 2165 |
* vendor-type USB messages. |
| 2166 |
*/ |
| 2167 |
|
| 2168 |
#define HDA_VERB_CMD(V, N, D) (((N) << 20) | ((V) << 8) | (D)) |
| 2169 |
|
| 2170 |
#define REALTEK_HDA_VALUE 0x0038 |
| 2171 |
|
| 2172 |
#define REALTEK_HDA_SET 62 |
| 2173 |
#define REALTEK_MANUAL_MODE 72 |
| 2174 |
#define REALTEK_HDA_GET_OUT 88 |
| 2175 |
#define REALTEK_HDA_GET_IN 89 |
| 2176 |
|
| 2177 |
#define REALTEK_AUDIO_FUNCTION_GROUP 0x01 |
| 2178 |
#define REALTEK_LINE1 0x1a |
| 2179 |
#define REALTEK_VENDOR_REGISTERS 0x20 |
| 2180 |
#define REALTEK_HP_OUT 0x21 |
| 2181 |
|
| 2182 |
#define REALTEK_CBJ_CTRL2 0x50 |
| 2183 |
|
| 2184 |
#define REALTEK_JACK_INTERRUPT_NODE 5 |
| 2185 |
|
| 2186 |
#define REALTEK_MIC_FLAG 0x100 |
| 2187 |
|
| 2188 |
static int realtek_hda_set(struct snd_usb_audio *chip, u32 cmd) |
| 2189 |
{ |
| 2190 |
struct usb_device *dev = chip->dev; |
| 2191 |
__be32 buf = cpu_to_be32(cmd); |
| 2192 |
|
| 2193 |
return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_SET, |
| 2194 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 2195 |
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); |
| 2196 |
} |
| 2197 |
|
| 2198 |
static int realtek_hda_get(struct snd_usb_audio *chip, u32 cmd, u32 *value) |
| 2199 |
{ |
| 2200 |
struct usb_device *dev = chip->dev; |
| 2201 |
int err; |
| 2202 |
__be32 buf = cpu_to_be32(cmd); |
| 2203 |
|
| 2204 |
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_HDA_GET_OUT, |
| 2205 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 2206 |
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); |
| 2207 |
if (err < 0) |
| 2208 |
return err; |
| 2209 |
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), REALTEK_HDA_GET_IN, |
| 2210 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_IN, |
| 2211 |
REALTEK_HDA_VALUE, 0, &buf, sizeof(buf)); |
| 2212 |
if (err < 0) |
| 2213 |
return err; |
| 2214 |
|
| 2215 |
*value = be32_to_cpu(buf); |
| 2216 |
return 0; |
| 2217 |
} |
| 2218 |
|
| 2219 |
static int realtek_ctl_connector_get(struct snd_kcontrol *kcontrol, |
| 2220 |
struct snd_ctl_elem_value *ucontrol) |
| 2221 |
{ |
| 2222 |
struct usb_mixer_elem_info *cval = snd_kcontrol_chip(kcontrol); |
| 2223 |
struct snd_usb_audio *chip = cval->head.mixer->chip; |
| 2224 |
u32 pv = kcontrol->private_value; |
| 2225 |
u32 node_id = pv & 0xff; |
| 2226 |
u32 sense; |
| 2227 |
u32 cbj_ctrl2; |
| 2228 |
bool presence; |
| 2229 |
int err; |
| 2230 |
|
| 2231 |
CLASS(snd_usb_lock, pm)(chip); |
| 2232 |
if (pm.err < 0) |
| 2233 |
return pm.err; |
| 2234 |
err = realtek_hda_get(chip, |
| 2235 |
HDA_VERB_CMD(AC_VERB_GET_PIN_SENSE, node_id, 0), |
| 2236 |
&sense); |
| 2237 |
if (err < 0) |
| 2238 |
return err; |
| 2239 |
if (pv & REALTEK_MIC_FLAG) { |
| 2240 |
err = realtek_hda_set(chip, |
| 2241 |
HDA_VERB_CMD(AC_VERB_SET_COEF_INDEX, |
| 2242 |
REALTEK_VENDOR_REGISTERS, |
| 2243 |
REALTEK_CBJ_CTRL2)); |
| 2244 |
if (err < 0) |
| 2245 |
return err; |
| 2246 |
err = realtek_hda_get(chip, |
| 2247 |
HDA_VERB_CMD(AC_VERB_GET_PROC_COEF, |
| 2248 |
REALTEK_VENDOR_REGISTERS, 0), |
| 2249 |
&cbj_ctrl2); |
| 2250 |
if (err < 0) |
| 2251 |
return err; |
| 2252 |
} |
| 2253 |
|
| 2254 |
presence = sense & AC_PINSENSE_PRESENCE; |
| 2255 |
if (pv & REALTEK_MIC_FLAG) |
| 2256 |
presence = presence && (cbj_ctrl2 & 0x0070) == 0x0070; |
| 2257 |
ucontrol->value.integer.value[0] = presence; |
| 2258 |
return 0; |
| 2259 |
} |
| 2260 |
|
| 2261 |
static const struct snd_kcontrol_new realtek_connector_ctl_ro = { |
| 2262 |
.iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 2263 |
.name = "", /* will be filled later manually */ |
| 2264 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2265 |
.info = snd_ctl_boolean_mono_info, |
| 2266 |
.get = realtek_ctl_connector_get, |
| 2267 |
}; |
| 2268 |
|
| 2269 |
static int realtek_resume_jack(struct usb_mixer_elem_list *list) |
| 2270 |
{ |
| 2271 |
snd_ctl_notify(list->mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 2272 |
&list->kctl->id); |
| 2273 |
return 0; |
| 2274 |
} |
| 2275 |
|
| 2276 |
static int realtek_add_jack(struct usb_mixer_interface *mixer, |
| 2277 |
char *name, u32 val, int unitid, |
| 2278 |
const struct snd_kcontrol_new *kctl_new) |
| 2279 |
{ |
| 2280 |
struct usb_mixer_elem_info *cval; |
| 2281 |
struct snd_kcontrol *kctl; |
| 2282 |
|
| 2283 |
cval = kzalloc_obj(*cval); |
| 2284 |
if (!cval) |
| 2285 |
return -ENOMEM; |
| 2286 |
snd_usb_mixer_elem_init_std(&cval->head, mixer, unitid); |
| 2287 |
cval->head.resume = realtek_resume_jack; |
| 2288 |
cval->val_type = USB_MIXER_BOOLEAN; |
| 2289 |
cval->channels = 1; |
| 2290 |
cval->min = 0; |
| 2291 |
cval->max = 1; |
| 2292 |
kctl = snd_ctl_new1(kctl_new, cval); |
| 2293 |
if (!kctl) { |
| 2294 |
kfree(cval); |
| 2295 |
return -ENOMEM; |
| 2296 |
} |
| 2297 |
kctl->private_value = val; |
| 2298 |
strscpy(kctl->id.name, name, sizeof(kctl->id.name)); |
| 2299 |
kctl->private_free = snd_usb_mixer_elem_free; |
| 2300 |
return snd_usb_mixer_add_control(&cval->head, kctl); |
| 2301 |
} |
| 2302 |
|
| 2303 |
static int dell_dock_mixer_create(struct usb_mixer_interface *mixer) |
| 2304 |
{ |
| 2305 |
int err; |
| 2306 |
struct usb_device *dev = mixer->chip->dev; |
| 2307 |
|
| 2308 |
/* Power down the audio codec to avoid loud pops in the next step. */ |
| 2309 |
realtek_hda_set(mixer->chip, |
| 2310 |
HDA_VERB_CMD(AC_VERB_SET_POWER_STATE, |
| 2311 |
REALTEK_AUDIO_FUNCTION_GROUP, |
| 2312 |
AC_PWRST_D3)); |
| 2313 |
|
| 2314 |
/* |
| 2315 |
* Turn off 'manual mode' in case it was enabled. This removes the need |
| 2316 |
* to power cycle the dock after it was attached to a Windows machine. |
| 2317 |
*/ |
| 2318 |
snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), REALTEK_MANUAL_MODE, |
| 2319 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 2320 |
0, 0, NULL, 0); |
| 2321 |
|
| 2322 |
err = realtek_add_jack(mixer, "Line Out Jack", REALTEK_LINE1, |
| 2323 |
REALTEK_JACK_INTERRUPT_NODE, |
| 2324 |
&realtek_connector_ctl_ro); |
| 2325 |
if (err < 0) |
| 2326 |
return err; |
| 2327 |
err = realtek_add_jack(mixer, "Headphone Jack", REALTEK_HP_OUT, |
| 2328 |
REALTEK_JACK_INTERRUPT_NODE, |
| 2329 |
&realtek_connector_ctl_ro); |
| 2330 |
if (err < 0) |
| 2331 |
return err; |
| 2332 |
err = realtek_add_jack(mixer, "Headset Mic Jack", |
| 2333 |
REALTEK_HP_OUT | REALTEK_MIC_FLAG, |
| 2334 |
REALTEK_JACK_INTERRUPT_NODE, |
| 2335 |
&realtek_connector_ctl_ro); |
| 2336 |
if (err < 0) |
| 2337 |
return err; |
| 2338 |
return 0; |
| 2339 |
} |
| 2340 |
|
| 2341 |
static void dell_dock_init_vol(struct usb_mixer_interface *mixer, int ch, int id) |
| 2342 |
{ |
| 2343 |
struct snd_usb_audio *chip = mixer->chip; |
| 2344 |
u16 buf = 0; |
| 2345 |
|
| 2346 |
snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC_SET_CUR, |
| 2347 |
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, |
| 2348 |
(UAC_FU_VOLUME << 8) | ch, |
| 2349 |
snd_usb_ctrl_intf(mixer->hostif) | (id << 8), |
| 2350 |
&buf, 2); |
| 2351 |
} |
| 2352 |
|
| 2353 |
static int dell_dock_mixer_init(struct usb_mixer_interface *mixer) |
| 2354 |
{ |
| 2355 |
/* fix to 0dB playback volumes */ |
| 2356 |
dell_dock_init_vol(mixer, 1, 16); |
| 2357 |
dell_dock_init_vol(mixer, 2, 16); |
| 2358 |
dell_dock_init_vol(mixer, 1, 19); |
| 2359 |
dell_dock_init_vol(mixer, 2, 19); |
| 2360 |
return 0; |
| 2361 |
} |
| 2362 |
|
| 2363 |
/* |
| 2364 |
* HP Thunderbolt Dock G2 jack detection |
| 2365 |
* |
| 2366 |
* Similar to the Dell WD15/WD19, but with different commands. |
| 2367 |
*/ |
| 2368 |
|
| 2369 |
#define HP_DOCK_JACK_INTERRUPT_NODE 7 |
| 2370 |
|
| 2371 |
#define HP_DOCK_GET 37 |
| 2372 |
|
| 2373 |
#define HP_DOCK_JACK_PRESENCE 0xffb8 |
| 2374 |
#define HP_DOCK_JACK_PRESENCE_BIT BIT(2) |
| 2375 |
|
| 2376 |
#define HP_DOCK_MIC_SENSE 0xf753 |
| 2377 |
#define HP_DOCK_MIC_SENSE_COMPLETE_BIT BIT(4) |
| 2378 |
|
| 2379 |
#define HP_DOCK_MIC_SENSE_MASK (BIT(2) | BIT(1) | BIT(0)) |
| 2380 |
/* #define HP_DOCK_MIC_SENSE_PRESENT 0x2 */ |
| 2381 |
#define HP_DOCK_MIC_SENSE_NOT_PRESENT 0x4 |
| 2382 |
|
| 2383 |
static int hp_dock_ctl_connector_get(struct snd_kcontrol *kcontrol, |
| 2384 |
struct snd_ctl_elem_value *ucontrol) |
| 2385 |
{ |
| 2386 |
struct usb_mixer_elem_info *cval = snd_kcontrol_chip(kcontrol); |
| 2387 |
struct snd_usb_audio *chip = cval->head.mixer->chip; |
| 2388 |
u32 pv = kcontrol->private_value; |
| 2389 |
bool presence; |
| 2390 |
int err; |
| 2391 |
u8 buf; |
| 2392 |
|
| 2393 |
CLASS(snd_usb_lock, pm)(chip); |
| 2394 |
if (pm.err < 0) |
| 2395 |
return pm.err; |
| 2396 |
|
| 2397 |
err = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), |
| 2398 |
HP_DOCK_GET, |
| 2399 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_IN, |
| 2400 |
0, HP_DOCK_JACK_PRESENCE, &buf, sizeof(buf)); |
| 2401 |
if (err < 0) |
| 2402 |
return err; |
| 2403 |
|
| 2404 |
presence = !(buf & HP_DOCK_JACK_PRESENCE_BIT); |
| 2405 |
|
| 2406 |
if (pv && presence) { |
| 2407 |
for (int i = 0; i < 20; i++) { |
| 2408 |
err = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), |
| 2409 |
HP_DOCK_GET, |
| 2410 |
USB_RECIP_DEVICE | USB_TYPE_VENDOR | USB_DIR_IN, |
| 2411 |
0, HP_DOCK_MIC_SENSE, &buf, sizeof(buf)); |
| 2412 |
if (err < 0) |
| 2413 |
return err; |
| 2414 |
|
| 2415 |
/* Mic sense is complete, we have a result. */ |
| 2416 |
if (buf & HP_DOCK_MIC_SENSE_COMPLETE_BIT) |
| 2417 |
break; |
| 2418 |
|
| 2419 |
msleep(100); |
| 2420 |
} |
| 2421 |
|
| 2422 |
/* |
| 2423 |
* If we reach the retry limit without mic sense having |
| 2424 |
* completed, buf will contain HP_DOCK_MIC_SENSE_PRESENT, |
| 2425 |
* thus presence remains true even when detection fails. |
| 2426 |
*/ |
| 2427 |
if ((buf & HP_DOCK_MIC_SENSE_MASK) == HP_DOCK_MIC_SENSE_NOT_PRESENT) |
| 2428 |
presence = false; |
| 2429 |
} |
| 2430 |
ucontrol->value.integer.value[0] = presence; |
| 2431 |
return 0; |
| 2432 |
} |
| 2433 |
|
| 2434 |
static const struct snd_kcontrol_new hp_dock_connector_ctl_ro = { |
| 2435 |
.iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 2436 |
.name = "", /* will be filled later manually */ |
| 2437 |
.access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 2438 |
.info = snd_ctl_boolean_mono_info, |
| 2439 |
.get = hp_dock_ctl_connector_get, |
| 2440 |
}; |
| 2441 |
|
| 2442 |
static int hp_dock_mixer_create(struct usb_mixer_interface *mixer) |
| 2443 |
{ |
| 2444 |
int err; |
| 2445 |
|
| 2446 |
err = realtek_add_jack(mixer, "Headsets Playback Jack", 0, |
| 2447 |
HP_DOCK_JACK_INTERRUPT_NODE, |
| 2448 |
&hp_dock_connector_ctl_ro); |
| 2449 |
if (err < 0) |
| 2450 |
return err; |
| 2451 |
|
| 2452 |
err = realtek_add_jack(mixer, "Headset Capture Jack", 1, |
| 2453 |
HP_DOCK_JACK_INTERRUPT_NODE, |
| 2454 |
&hp_dock_connector_ctl_ro); |
| 2455 |
if (err < 0) |
| 2456 |
return err; |
| 2457 |
|
| 2458 |
return 0; |
| 2459 |
} |
| 2460 |
|
| 2461 |
|
| 2462 |
/* RME Class Compliant device quirks */ |
| 2463 |
|
| 2464 |
#define SND_RME_GET_STATUS1 23 |
| 2465 |
#define SND_RME_GET_CURRENT_FREQ 17 |
| 2466 |
#define SND_RME_CLK_SYSTEM_SHIFT 16 |
| 2467 |
#define SND_RME_CLK_SYSTEM_MASK 0x1f |
| 2468 |
#define SND_RME_CLK_AES_SHIFT 8 |
| 2469 |
#define SND_RME_CLK_SPDIF_SHIFT 12 |
| 2470 |
#define SND_RME_CLK_AES_SPDIF_MASK 0xf |
| 2471 |
#define SND_RME_CLK_SYNC_SHIFT 6 |
| 2472 |
#define SND_RME_CLK_SYNC_MASK 0x3 |
| 2473 |
#define SND_RME_CLK_FREQMUL_SHIFT 18 |
| 2474 |
#define SND_RME_CLK_FREQMUL_MASK 0x7 |
| 2475 |
#define SND_RME_CLK_SYSTEM(x) \ |
| 2476 |
(((x) >> SND_RME_CLK_SYSTEM_SHIFT) & SND_RME_CLK_SYSTEM_MASK) |
| 2477 |
#define SND_RME_CLK_AES(x) \ |
| 2478 |
(((x) >> SND_RME_CLK_AES_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) |
| 2479 |
#define SND_RME_CLK_SPDIF(x) \ |
| 2480 |
(((x) >> SND_RME_CLK_SPDIF_SHIFT) & SND_RME_CLK_AES_SPDIF_MASK) |
| 2481 |
#define SND_RME_CLK_SYNC(x) \ |
| 2482 |
(((x) >> SND_RME_CLK_SYNC_SHIFT) & SND_RME_CLK_SYNC_MASK) |
| 2483 |
#define SND_RME_CLK_FREQMUL(x) \ |
| 2484 |
(((x) >> SND_RME_CLK_FREQMUL_SHIFT) & SND_RME_CLK_FREQMUL_MASK) |
| 2485 |
#define SND_RME_CLK_AES_LOCK 0x1 |
| 2486 |
#define SND_RME_CLK_AES_SYNC 0x4 |
| 2487 |
#define SND_RME_CLK_SPDIF_LOCK 0x2 |
| 2488 |
#define SND_RME_CLK_SPDIF_SYNC 0x8 |
| 2489 |
#define SND_RME_SPDIF_IF_SHIFT 4 |
| 2490 |
#define SND_RME_SPDIF_FORMAT_SHIFT 5 |
| 2491 |
#define SND_RME_BINARY_MASK 0x1 |
| 2492 |
#define SND_RME_SPDIF_IF(x) \ |
| 2493 |
(((x) >> SND_RME_SPDIF_IF_SHIFT) & SND_RME_BINARY_MASK) |
| 2494 |
#define SND_RME_SPDIF_FORMAT(x) \ |
| 2495 |
(((x) >> SND_RME_SPDIF_FORMAT_SHIFT) & SND_RME_BINARY_MASK) |
| 2496 |
|
| 2497 |
static const u32 snd_rme_rate_table[] = { |
| 2498 |
32000, 44100, 48000, 50000, |
| 2499 |
64000, 88200, 96000, 100000, |
| 2500 |
128000, 176400, 192000, 200000, |
| 2501 |
256000, 352800, 384000, 400000, |
| 2502 |
512000, 705600, 768000, 800000 |
| 2503 |
}; |
| 2504 |
|
| 2505 |
/* maximum number of items for AES and S/PDIF rates for above table */ |
| 2506 |
#define SND_RME_RATE_IDX_AES_SPDIF_NUM 12 |
| 2507 |
|
| 2508 |
enum snd_rme_domain { |
| 2509 |
SND_RME_DOMAIN_SYSTEM, |
| 2510 |
SND_RME_DOMAIN_AES, |
| 2511 |
SND_RME_DOMAIN_SPDIF |
| 2512 |
}; |
| 2513 |
|
| 2514 |
enum snd_rme_clock_status { |
| 2515 |
SND_RME_CLOCK_NOLOCK, |
| 2516 |
SND_RME_CLOCK_LOCK, |
| 2517 |
SND_RME_CLOCK_SYNC |
| 2518 |
}; |
| 2519 |
|
| 2520 |
static int snd_rme_read_value(struct snd_usb_audio *chip, |
| 2521 |
unsigned int item, |
| 2522 |
u32 *value) |
| 2523 |
{ |
| 2524 |
struct usb_device *dev = chip->dev; |
| 2525 |
int err; |
| 2526 |
|
| 2527 |
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 2528 |
item, |
| 2529 |
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2530 |
0, 0, |
| 2531 |
value, sizeof(*value)); |
| 2532 |
if (err < 0) |
| 2533 |
dev_err(&dev->dev, |
| 2534 |
"unable to issue vendor read request %d (ret = %d)", |
| 2535 |
item, err); |
| 2536 |
return err; |
| 2537 |
} |
| 2538 |
|
| 2539 |
static int snd_rme_get_status1(struct snd_kcontrol *kcontrol, |
| 2540 |
u32 *status1) |
| 2541 |
{ |
| 2542 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 2543 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 2544 |
|
| 2545 |
*status1 = 0; |
| 2546 |
CLASS(snd_usb_lock, pm)(chip); |
| 2547 |
if (pm.err < 0) |
| 2548 |
return pm.err; |
| 2549 |
return snd_rme_read_value(chip, SND_RME_GET_STATUS1, status1); |
| 2550 |
} |
| 2551 |
|
| 2552 |
static int snd_rme_rate_get(struct snd_kcontrol *kcontrol, |
| 2553 |
struct snd_ctl_elem_value *ucontrol) |
| 2554 |
{ |
| 2555 |
u32 status1; |
| 2556 |
u32 rate = 0; |
| 2557 |
int idx; |
| 2558 |
int err; |
| 2559 |
|
| 2560 |
err = snd_rme_get_status1(kcontrol, &status1); |
| 2561 |
if (err < 0) |
| 2562 |
return err; |
| 2563 |
switch (kcontrol->private_value) { |
| 2564 |
case SND_RME_DOMAIN_SYSTEM: |
| 2565 |
idx = SND_RME_CLK_SYSTEM(status1); |
| 2566 |
if (idx < ARRAY_SIZE(snd_rme_rate_table)) |
| 2567 |
rate = snd_rme_rate_table[idx]; |
| 2568 |
break; |
| 2569 |
case SND_RME_DOMAIN_AES: |
| 2570 |
idx = SND_RME_CLK_AES(status1); |
| 2571 |
if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) |
| 2572 |
rate = snd_rme_rate_table[idx]; |
| 2573 |
break; |
| 2574 |
case SND_RME_DOMAIN_SPDIF: |
| 2575 |
idx = SND_RME_CLK_SPDIF(status1); |
| 2576 |
if (idx < SND_RME_RATE_IDX_AES_SPDIF_NUM) |
| 2577 |
rate = snd_rme_rate_table[idx]; |
| 2578 |
break; |
| 2579 |
default: |
| 2580 |
return -EINVAL; |
| 2581 |
} |
| 2582 |
ucontrol->value.integer.value[0] = rate; |
| 2583 |
return 0; |
| 2584 |
} |
| 2585 |
|
| 2586 |
static int snd_rme_sync_state_get(struct snd_kcontrol *kcontrol, |
| 2587 |
struct snd_ctl_elem_value *ucontrol) |
| 2588 |
{ |
| 2589 |
u32 status1; |
| 2590 |
int idx = SND_RME_CLOCK_NOLOCK; |
| 2591 |
int err; |
| 2592 |
|
| 2593 |
err = snd_rme_get_status1(kcontrol, &status1); |
| 2594 |
if (err < 0) |
| 2595 |
return err; |
| 2596 |
switch (kcontrol->private_value) { |
| 2597 |
case SND_RME_DOMAIN_AES: /* AES */ |
| 2598 |
if (status1 & SND_RME_CLK_AES_SYNC) |
| 2599 |
idx = SND_RME_CLOCK_SYNC; |
| 2600 |
else if (status1 & SND_RME_CLK_AES_LOCK) |
| 2601 |
idx = SND_RME_CLOCK_LOCK; |
| 2602 |
break; |
| 2603 |
case SND_RME_DOMAIN_SPDIF: /* SPDIF */ |
| 2604 |
if (status1 & SND_RME_CLK_SPDIF_SYNC) |
| 2605 |
idx = SND_RME_CLOCK_SYNC; |
| 2606 |
else if (status1 & SND_RME_CLK_SPDIF_LOCK) |
| 2607 |
idx = SND_RME_CLOCK_LOCK; |
| 2608 |
break; |
| 2609 |
default: |
| 2610 |
return -EINVAL; |
| 2611 |
} |
| 2612 |
ucontrol->value.enumerated.item[0] = idx; |
| 2613 |
return 0; |
| 2614 |
} |
| 2615 |
|
| 2616 |
static int snd_rme_spdif_if_get(struct snd_kcontrol *kcontrol, |
| 2617 |
struct snd_ctl_elem_value *ucontrol) |
| 2618 |
{ |
| 2619 |
u32 status1; |
| 2620 |
int err; |
| 2621 |
|
| 2622 |
err = snd_rme_get_status1(kcontrol, &status1); |
| 2623 |
if (err < 0) |
| 2624 |
return err; |
| 2625 |
ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_IF(status1); |
| 2626 |
return 0; |
| 2627 |
} |
| 2628 |
|
| 2629 |
static int snd_rme_spdif_format_get(struct snd_kcontrol *kcontrol, |
| 2630 |
struct snd_ctl_elem_value *ucontrol) |
| 2631 |
{ |
| 2632 |
u32 status1; |
| 2633 |
int err; |
| 2634 |
|
| 2635 |
err = snd_rme_get_status1(kcontrol, &status1); |
| 2636 |
if (err < 0) |
| 2637 |
return err; |
| 2638 |
ucontrol->value.enumerated.item[0] = SND_RME_SPDIF_FORMAT(status1); |
| 2639 |
return 0; |
| 2640 |
} |
| 2641 |
|
| 2642 |
static int snd_rme_sync_source_get(struct snd_kcontrol *kcontrol, |
| 2643 |
struct snd_ctl_elem_value *ucontrol) |
| 2644 |
{ |
| 2645 |
u32 status1; |
| 2646 |
int err; |
| 2647 |
|
| 2648 |
err = snd_rme_get_status1(kcontrol, &status1); |
| 2649 |
if (err < 0) |
| 2650 |
return err; |
| 2651 |
ucontrol->value.enumerated.item[0] = SND_RME_CLK_SYNC(status1); |
| 2652 |
return 0; |
| 2653 |
} |
| 2654 |
|
| 2655 |
static int snd_rme_current_freq_get(struct snd_kcontrol *kcontrol, |
| 2656 |
struct snd_ctl_elem_value *ucontrol) |
| 2657 |
{ |
| 2658 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 2659 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 2660 |
u32 status1; |
| 2661 |
const u64 num = 104857600000000ULL; |
| 2662 |
u32 den; |
| 2663 |
unsigned int freq; |
| 2664 |
int err; |
| 2665 |
|
| 2666 |
CLASS(snd_usb_lock, pm)(chip); |
| 2667 |
if (pm.err < 0) |
| 2668 |
return pm.err; |
| 2669 |
err = snd_rme_read_value(chip, SND_RME_GET_STATUS1, &status1); |
| 2670 |
if (err < 0) |
| 2671 |
return err; |
| 2672 |
err = snd_rme_read_value(chip, SND_RME_GET_CURRENT_FREQ, &den); |
| 2673 |
if (err < 0) |
| 2674 |
return err; |
| 2675 |
freq = (den == 0) ? 0 : div64_u64(num, den); |
| 2676 |
freq <<= SND_RME_CLK_FREQMUL(status1); |
| 2677 |
ucontrol->value.integer.value[0] = freq; |
| 2678 |
return 0; |
| 2679 |
} |
| 2680 |
|
| 2681 |
static int snd_rme_rate_info(struct snd_kcontrol *kcontrol, |
| 2682 |
struct snd_ctl_elem_info *uinfo) |
| 2683 |
{ |
| 2684 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2685 |
uinfo->count = 1; |
| 2686 |
switch (kcontrol->private_value) { |
| 2687 |
case SND_RME_DOMAIN_SYSTEM: |
| 2688 |
uinfo->value.integer.min = 32000; |
| 2689 |
uinfo->value.integer.max = 800000; |
| 2690 |
break; |
| 2691 |
case SND_RME_DOMAIN_AES: |
| 2692 |
case SND_RME_DOMAIN_SPDIF: |
| 2693 |
default: |
| 2694 |
uinfo->value.integer.min = 0; |
| 2695 |
uinfo->value.integer.max = 200000; |
| 2696 |
} |
| 2697 |
uinfo->value.integer.step = 0; |
| 2698 |
return 0; |
| 2699 |
} |
| 2700 |
|
| 2701 |
static int snd_rme_sync_state_info(struct snd_kcontrol *kcontrol, |
| 2702 |
struct snd_ctl_elem_info *uinfo) |
| 2703 |
{ |
| 2704 |
static const char *const sync_states[] = { |
| 2705 |
"No Lock", "Lock", "Sync" |
| 2706 |
}; |
| 2707 |
|
| 2708 |
return snd_ctl_enum_info(uinfo, 1, |
| 2709 |
ARRAY_SIZE(sync_states), sync_states); |
| 2710 |
} |
| 2711 |
|
| 2712 |
static int snd_rme_spdif_if_info(struct snd_kcontrol *kcontrol, |
| 2713 |
struct snd_ctl_elem_info *uinfo) |
| 2714 |
{ |
| 2715 |
static const char *const spdif_if[] = { |
| 2716 |
"Coaxial", "Optical" |
| 2717 |
}; |
| 2718 |
|
| 2719 |
return snd_ctl_enum_info(uinfo, 1, |
| 2720 |
ARRAY_SIZE(spdif_if), spdif_if); |
| 2721 |
} |
| 2722 |
|
| 2723 |
static int snd_rme_spdif_format_info(struct snd_kcontrol *kcontrol, |
| 2724 |
struct snd_ctl_elem_info *uinfo) |
| 2725 |
{ |
| 2726 |
static const char *const optical_type[] = { |
| 2727 |
"Consumer", "Professional" |
| 2728 |
}; |
| 2729 |
|
| 2730 |
return snd_ctl_enum_info(uinfo, 1, |
| 2731 |
ARRAY_SIZE(optical_type), optical_type); |
| 2732 |
} |
| 2733 |
|
| 2734 |
static int snd_rme_sync_source_info(struct snd_kcontrol *kcontrol, |
| 2735 |
struct snd_ctl_elem_info *uinfo) |
| 2736 |
{ |
| 2737 |
static const char *const sync_sources[] = { |
| 2738 |
"Internal", "AES", "SPDIF", "Internal" |
| 2739 |
}; |
| 2740 |
|
| 2741 |
return snd_ctl_enum_info(uinfo, 1, |
| 2742 |
ARRAY_SIZE(sync_sources), sync_sources); |
| 2743 |
} |
| 2744 |
|
| 2745 |
static const struct snd_kcontrol_new snd_rme_controls[] = { |
| 2746 |
{ |
| 2747 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2748 |
.name = "AES Rate", |
| 2749 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2750 |
.info = snd_rme_rate_info, |
| 2751 |
.get = snd_rme_rate_get, |
| 2752 |
.private_value = SND_RME_DOMAIN_AES |
| 2753 |
}, |
| 2754 |
{ |
| 2755 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2756 |
.name = "AES Sync", |
| 2757 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2758 |
.info = snd_rme_sync_state_info, |
| 2759 |
.get = snd_rme_sync_state_get, |
| 2760 |
.private_value = SND_RME_DOMAIN_AES |
| 2761 |
}, |
| 2762 |
{ |
| 2763 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2764 |
.name = "SPDIF Rate", |
| 2765 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2766 |
.info = snd_rme_rate_info, |
| 2767 |
.get = snd_rme_rate_get, |
| 2768 |
.private_value = SND_RME_DOMAIN_SPDIF |
| 2769 |
}, |
| 2770 |
{ |
| 2771 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2772 |
.name = "SPDIF Sync", |
| 2773 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2774 |
.info = snd_rme_sync_state_info, |
| 2775 |
.get = snd_rme_sync_state_get, |
| 2776 |
.private_value = SND_RME_DOMAIN_SPDIF |
| 2777 |
}, |
| 2778 |
{ |
| 2779 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2780 |
.name = "SPDIF Interface", |
| 2781 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2782 |
.info = snd_rme_spdif_if_info, |
| 2783 |
.get = snd_rme_spdif_if_get, |
| 2784 |
}, |
| 2785 |
{ |
| 2786 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2787 |
.name = "SPDIF Format", |
| 2788 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2789 |
.info = snd_rme_spdif_format_info, |
| 2790 |
.get = snd_rme_spdif_format_get, |
| 2791 |
}, |
| 2792 |
{ |
| 2793 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2794 |
.name = "Sync Source", |
| 2795 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2796 |
.info = snd_rme_sync_source_info, |
| 2797 |
.get = snd_rme_sync_source_get |
| 2798 |
}, |
| 2799 |
{ |
| 2800 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2801 |
.name = "System Rate", |
| 2802 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2803 |
.info = snd_rme_rate_info, |
| 2804 |
.get = snd_rme_rate_get, |
| 2805 |
.private_value = SND_RME_DOMAIN_SYSTEM |
| 2806 |
}, |
| 2807 |
{ |
| 2808 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2809 |
.name = "Current Frequency", |
| 2810 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2811 |
.info = snd_rme_rate_info, |
| 2812 |
.get = snd_rme_current_freq_get |
| 2813 |
} |
| 2814 |
}; |
| 2815 |
|
| 2816 |
static int snd_rme_controls_create(struct usb_mixer_interface *mixer) |
| 2817 |
{ |
| 2818 |
int err, i; |
| 2819 |
|
| 2820 |
for (i = 0; i < ARRAY_SIZE(snd_rme_controls); ++i) { |
| 2821 |
err = add_single_ctl_with_resume(mixer, 0, |
| 2822 |
NULL, |
| 2823 |
&snd_rme_controls[i], |
| 2824 |
NULL); |
| 2825 |
if (err < 0) |
| 2826 |
return err; |
| 2827 |
} |
| 2828 |
|
| 2829 |
return 0; |
| 2830 |
} |
| 2831 |
|
| 2832 |
/* |
| 2833 |
* RME Babyface Pro (FS) |
| 2834 |
* |
| 2835 |
* These devices exposes a couple of DSP functions via request to EP0. |
| 2836 |
* Switches are available via control registers, while routing is controlled |
| 2837 |
* by controlling the volume on each possible crossing point. |
| 2838 |
* Volume control is linear, from -inf (dec. 0) to +6dB (dec. 65536) with |
| 2839 |
* 0dB being at dec. 32768. |
| 2840 |
*/ |
| 2841 |
enum { |
| 2842 |
SND_BBFPRO_CTL_REG1 = 0, |
| 2843 |
SND_BBFPRO_CTL_REG2 |
| 2844 |
}; |
| 2845 |
|
| 2846 |
#define SND_BBFPRO_CTL_REG_MASK 1 |
| 2847 |
#define SND_BBFPRO_CTL_IDX_MASK 0xff |
| 2848 |
#define SND_BBFPRO_CTL_IDX_SHIFT 1 |
| 2849 |
#define SND_BBFPRO_CTL_VAL_MASK 1 |
| 2850 |
#define SND_BBFPRO_CTL_VAL_SHIFT 9 |
| 2851 |
#define SND_BBFPRO_CTL_REG1_CLK_MASTER 0 |
| 2852 |
#define SND_BBFPRO_CTL_REG1_CLK_OPTICAL 1 |
| 2853 |
#define SND_BBFPRO_CTL_REG1_SPDIF_PRO 7 |
| 2854 |
#define SND_BBFPRO_CTL_REG1_SPDIF_EMPH 8 |
| 2855 |
#define SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL 10 |
| 2856 |
#define SND_BBFPRO_CTL_REG2_48V_AN1 0 |
| 2857 |
#define SND_BBFPRO_CTL_REG2_48V_AN2 1 |
| 2858 |
#define SND_BBFPRO_CTL_REG2_SENS_IN3 2 |
| 2859 |
#define SND_BBFPRO_CTL_REG2_SENS_IN4 3 |
| 2860 |
#define SND_BBFPRO_CTL_REG2_PAD_AN1 4 |
| 2861 |
#define SND_BBFPRO_CTL_REG2_PAD_AN2 5 |
| 2862 |
|
| 2863 |
#define SND_BBFPRO_MIXER_MAIN_OUT_CH_OFFSET 992 |
| 2864 |
#define SND_BBFPRO_MIXER_IDX_MASK 0x3ff |
| 2865 |
#define SND_BBFPRO_MIXER_VAL_MASK 0x3ffff |
| 2866 |
#define SND_BBFPRO_MIXER_VAL_SHIFT 9 |
| 2867 |
#define SND_BBFPRO_MIXER_VAL_MIN 0 // -inf |
| 2868 |
#define SND_BBFPRO_MIXER_VAL_MAX 65536 // +6dB |
| 2869 |
|
| 2870 |
#define SND_BBFPRO_GAIN_CHANNEL_MASK 0x03 |
| 2871 |
#define SND_BBFPRO_GAIN_CHANNEL_SHIFT 7 |
| 2872 |
#define SND_BBFPRO_GAIN_VAL_MASK 0x7f |
| 2873 |
#define SND_BBFPRO_GAIN_VAL_MIN 0 |
| 2874 |
#define SND_BBFPRO_GAIN_VAL_MIC_MAX 65 |
| 2875 |
#define SND_BBFPRO_GAIN_VAL_LINE_MAX 18 // 9db in 0.5db incraments |
| 2876 |
|
| 2877 |
#define SND_BBFPRO_USBREQ_CTL_REG1 0x10 |
| 2878 |
#define SND_BBFPRO_USBREQ_CTL_REG2 0x17 |
| 2879 |
#define SND_BBFPRO_USBREQ_GAIN 0x1a |
| 2880 |
#define SND_BBFPRO_USBREQ_MIXER 0x12 |
| 2881 |
|
| 2882 |
static int snd_bbfpro_ctl_update(struct usb_mixer_interface *mixer, u8 reg, |
| 2883 |
u8 index, u8 value) |
| 2884 |
{ |
| 2885 |
u16 usb_req, usb_idx, usb_val; |
| 2886 |
struct snd_usb_audio *chip = mixer->chip; |
| 2887 |
|
| 2888 |
CLASS(snd_usb_lock, pm)(chip); |
| 2889 |
if (pm.err < 0) |
| 2890 |
return pm.err; |
| 2891 |
|
| 2892 |
if (reg == SND_BBFPRO_CTL_REG1) { |
| 2893 |
usb_req = SND_BBFPRO_USBREQ_CTL_REG1; |
| 2894 |
if (index == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { |
| 2895 |
usb_idx = 3; |
| 2896 |
usb_val = value ? 3 : 0; |
| 2897 |
} else { |
| 2898 |
usb_idx = BIT(index); |
| 2899 |
usb_val = value ? usb_idx : 0; |
| 2900 |
} |
| 2901 |
} else { |
| 2902 |
usb_req = SND_BBFPRO_USBREQ_CTL_REG2; |
| 2903 |
usb_idx = BIT(index); |
| 2904 |
usb_val = value ? usb_idx : 0; |
| 2905 |
} |
| 2906 |
|
| 2907 |
return snd_usb_ctl_msg(chip->dev, |
| 2908 |
usb_sndctrlpipe(chip->dev, 0), usb_req, |
| 2909 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2910 |
usb_val, usb_idx, NULL, 0); |
| 2911 |
} |
| 2912 |
|
| 2913 |
static int snd_bbfpro_ctl_get(struct snd_kcontrol *kcontrol, |
| 2914 |
struct snd_ctl_elem_value *ucontrol) |
| 2915 |
{ |
| 2916 |
u8 reg, idx, val; |
| 2917 |
int pv; |
| 2918 |
|
| 2919 |
pv = kcontrol->private_value; |
| 2920 |
reg = pv & SND_BBFPRO_CTL_REG_MASK; |
| 2921 |
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; |
| 2922 |
val = kcontrol->private_value >> SND_BBFPRO_CTL_VAL_SHIFT; |
| 2923 |
|
| 2924 |
if ((reg == SND_BBFPRO_CTL_REG1 && |
| 2925 |
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || |
| 2926 |
(reg == SND_BBFPRO_CTL_REG2 && |
| 2927 |
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || |
| 2928 |
idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { |
| 2929 |
ucontrol->value.enumerated.item[0] = val; |
| 2930 |
} else { |
| 2931 |
ucontrol->value.integer.value[0] = val; |
| 2932 |
} |
| 2933 |
return 0; |
| 2934 |
} |
| 2935 |
|
| 2936 |
static int snd_bbfpro_ctl_info(struct snd_kcontrol *kcontrol, |
| 2937 |
struct snd_ctl_elem_info *uinfo) |
| 2938 |
{ |
| 2939 |
u8 reg, idx; |
| 2940 |
int pv; |
| 2941 |
|
| 2942 |
pv = kcontrol->private_value; |
| 2943 |
reg = pv & SND_BBFPRO_CTL_REG_MASK; |
| 2944 |
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; |
| 2945 |
|
| 2946 |
if (reg == SND_BBFPRO_CTL_REG1 && |
| 2947 |
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) { |
| 2948 |
static const char * const texts[2] = { |
| 2949 |
"AutoSync", |
| 2950 |
"Internal" |
| 2951 |
}; |
| 2952 |
return snd_ctl_enum_info(uinfo, 1, 2, texts); |
| 2953 |
} else if (reg == SND_BBFPRO_CTL_REG2 && |
| 2954 |
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || |
| 2955 |
idx == SND_BBFPRO_CTL_REG2_SENS_IN4)) { |
| 2956 |
static const char * const texts[2] = { |
| 2957 |
"-10dBV", |
| 2958 |
"+4dBu" |
| 2959 |
}; |
| 2960 |
return snd_ctl_enum_info(uinfo, 1, 2, texts); |
| 2961 |
} |
| 2962 |
|
| 2963 |
uinfo->count = 1; |
| 2964 |
uinfo->value.integer.min = 0; |
| 2965 |
uinfo->value.integer.max = 1; |
| 2966 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2967 |
return 0; |
| 2968 |
} |
| 2969 |
|
| 2970 |
static int snd_bbfpro_ctl_put(struct snd_kcontrol *kcontrol, |
| 2971 |
struct snd_ctl_elem_value *ucontrol) |
| 2972 |
{ |
| 2973 |
int err; |
| 2974 |
u8 reg, idx; |
| 2975 |
int old_value, pv, val; |
| 2976 |
|
| 2977 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 2978 |
struct usb_mixer_interface *mixer = list->mixer; |
| 2979 |
|
| 2980 |
pv = kcontrol->private_value; |
| 2981 |
reg = pv & SND_BBFPRO_CTL_REG_MASK; |
| 2982 |
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; |
| 2983 |
old_value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; |
| 2984 |
|
| 2985 |
if ((reg == SND_BBFPRO_CTL_REG1 && |
| 2986 |
idx == SND_BBFPRO_CTL_REG1_CLK_OPTICAL) || |
| 2987 |
(reg == SND_BBFPRO_CTL_REG2 && |
| 2988 |
(idx == SND_BBFPRO_CTL_REG2_SENS_IN3 || |
| 2989 |
idx == SND_BBFPRO_CTL_REG2_SENS_IN4))) { |
| 2990 |
val = ucontrol->value.enumerated.item[0]; |
| 2991 |
} else { |
| 2992 |
val = ucontrol->value.integer.value[0]; |
| 2993 |
} |
| 2994 |
|
| 2995 |
if (val > 1) |
| 2996 |
return -EINVAL; |
| 2997 |
|
| 2998 |
if (val == old_value) |
| 2999 |
return 0; |
| 3000 |
|
| 3001 |
kcontrol->private_value = reg |
| 3002 |
| ((idx & SND_BBFPRO_CTL_IDX_MASK) << SND_BBFPRO_CTL_IDX_SHIFT) |
| 3003 |
| ((val & SND_BBFPRO_CTL_VAL_MASK) << SND_BBFPRO_CTL_VAL_SHIFT); |
| 3004 |
|
| 3005 |
err = snd_bbfpro_ctl_update(mixer, reg, idx, val); |
| 3006 |
return err < 0 ? err : 1; |
| 3007 |
} |
| 3008 |
|
| 3009 |
static int snd_bbfpro_ctl_resume(struct usb_mixer_elem_list *list) |
| 3010 |
{ |
| 3011 |
u8 reg, idx; |
| 3012 |
int value, pv; |
| 3013 |
|
| 3014 |
pv = list->kctl->private_value; |
| 3015 |
reg = pv & SND_BBFPRO_CTL_REG_MASK; |
| 3016 |
idx = (pv >> SND_BBFPRO_CTL_IDX_SHIFT) & SND_BBFPRO_CTL_IDX_MASK; |
| 3017 |
value = (pv >> SND_BBFPRO_CTL_VAL_SHIFT) & SND_BBFPRO_CTL_VAL_MASK; |
| 3018 |
|
| 3019 |
return snd_bbfpro_ctl_update(list->mixer, reg, idx, value); |
| 3020 |
} |
| 3021 |
|
| 3022 |
static int snd_bbfpro_gain_update(struct usb_mixer_interface *mixer, |
| 3023 |
u8 channel, u8 gain) |
| 3024 |
{ |
| 3025 |
struct snd_usb_audio *chip = mixer->chip; |
| 3026 |
|
| 3027 |
if (channel < 2) { |
| 3028 |
// XLR preamp: 3-bit fine, 5-bit coarse; special case >60 |
| 3029 |
if (gain < 60) |
| 3030 |
gain = ((gain % 3) << 5) | (gain / 3); |
| 3031 |
else |
| 3032 |
gain = ((gain % 6) << 5) | (60 / 3); |
| 3033 |
} |
| 3034 |
|
| 3035 |
CLASS(snd_usb_lock, pm)(chip); |
| 3036 |
if (pm.err < 0) |
| 3037 |
return pm.err; |
| 3038 |
|
| 3039 |
return snd_usb_ctl_msg(chip->dev, |
| 3040 |
usb_sndctrlpipe(chip->dev, 0), |
| 3041 |
SND_BBFPRO_USBREQ_GAIN, |
| 3042 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 3043 |
gain, channel, NULL, 0); |
| 3044 |
} |
| 3045 |
|
| 3046 |
static int snd_bbfpro_gain_get(struct snd_kcontrol *kcontrol, |
| 3047 |
struct snd_ctl_elem_value *ucontrol) |
| 3048 |
{ |
| 3049 |
int value = kcontrol->private_value & SND_BBFPRO_GAIN_VAL_MASK; |
| 3050 |
|
| 3051 |
ucontrol->value.integer.value[0] = value; |
| 3052 |
return 0; |
| 3053 |
} |
| 3054 |
|
| 3055 |
static int snd_bbfpro_gain_info(struct snd_kcontrol *kcontrol, |
| 3056 |
struct snd_ctl_elem_info *uinfo) |
| 3057 |
{ |
| 3058 |
int pv, channel; |
| 3059 |
|
| 3060 |
pv = kcontrol->private_value; |
| 3061 |
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) & |
| 3062 |
SND_BBFPRO_GAIN_CHANNEL_MASK; |
| 3063 |
|
| 3064 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3065 |
uinfo->count = 1; |
| 3066 |
uinfo->value.integer.min = SND_BBFPRO_GAIN_VAL_MIN; |
| 3067 |
|
| 3068 |
if (channel < 2) |
| 3069 |
uinfo->value.integer.max = SND_BBFPRO_GAIN_VAL_MIC_MAX; |
| 3070 |
else |
| 3071 |
uinfo->value.integer.max = SND_BBFPRO_GAIN_VAL_LINE_MAX; |
| 3072 |
|
| 3073 |
return 0; |
| 3074 |
} |
| 3075 |
|
| 3076 |
static int snd_bbfpro_gain_put(struct snd_kcontrol *kcontrol, |
| 3077 |
struct snd_ctl_elem_value *ucontrol) |
| 3078 |
{ |
| 3079 |
int pv, channel, old_value, value, err; |
| 3080 |
|
| 3081 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 3082 |
struct usb_mixer_interface *mixer = list->mixer; |
| 3083 |
|
| 3084 |
pv = kcontrol->private_value; |
| 3085 |
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) & |
| 3086 |
SND_BBFPRO_GAIN_CHANNEL_MASK; |
| 3087 |
old_value = pv & SND_BBFPRO_GAIN_VAL_MASK; |
| 3088 |
value = ucontrol->value.integer.value[0]; |
| 3089 |
|
| 3090 |
if (value < SND_BBFPRO_GAIN_VAL_MIN) |
| 3091 |
return -EINVAL; |
| 3092 |
|
| 3093 |
if (channel < 2) { |
| 3094 |
if (value > SND_BBFPRO_GAIN_VAL_MIC_MAX) |
| 3095 |
return -EINVAL; |
| 3096 |
} else { |
| 3097 |
if (value > SND_BBFPRO_GAIN_VAL_LINE_MAX) |
| 3098 |
return -EINVAL; |
| 3099 |
} |
| 3100 |
|
| 3101 |
if (value == old_value) |
| 3102 |
return 0; |
| 3103 |
|
| 3104 |
err = snd_bbfpro_gain_update(mixer, channel, value); |
| 3105 |
if (err < 0) |
| 3106 |
return err; |
| 3107 |
|
| 3108 |
kcontrol->private_value = |
| 3109 |
(channel << SND_BBFPRO_GAIN_CHANNEL_SHIFT) | value; |
| 3110 |
return 1; |
| 3111 |
} |
| 3112 |
|
| 3113 |
static int snd_bbfpro_gain_resume(struct usb_mixer_elem_list *list) |
| 3114 |
{ |
| 3115 |
int pv, channel, value; |
| 3116 |
struct snd_kcontrol *kctl = list->kctl; |
| 3117 |
|
| 3118 |
pv = kctl->private_value; |
| 3119 |
channel = (pv >> SND_BBFPRO_GAIN_CHANNEL_SHIFT) & |
| 3120 |
SND_BBFPRO_GAIN_CHANNEL_MASK; |
| 3121 |
value = pv & SND_BBFPRO_GAIN_VAL_MASK; |
| 3122 |
|
| 3123 |
return snd_bbfpro_gain_update(list->mixer, channel, value); |
| 3124 |
} |
| 3125 |
|
| 3126 |
static int snd_bbfpro_vol_update(struct usb_mixer_interface *mixer, u16 index, |
| 3127 |
u32 value) |
| 3128 |
{ |
| 3129 |
struct snd_usb_audio *chip = mixer->chip; |
| 3130 |
u16 idx; |
| 3131 |
u16 usb_idx, usb_val; |
| 3132 |
u32 v; |
| 3133 |
|
| 3134 |
CLASS(snd_usb_lock, pm)(chip); |
| 3135 |
if (pm.err < 0) |
| 3136 |
return pm.err; |
| 3137 |
|
| 3138 |
idx = index & SND_BBFPRO_MIXER_IDX_MASK; |
| 3139 |
// 18 bit linear volume, split so 2 bits end up in index. |
| 3140 |
v = value & SND_BBFPRO_MIXER_VAL_MASK; |
| 3141 |
usb_idx = idx | (v & 0x3) << 14; |
| 3142 |
usb_val = (v >> 2) & 0xffff; |
| 3143 |
|
| 3144 |
return snd_usb_ctl_msg(chip->dev, |
| 3145 |
usb_sndctrlpipe(chip->dev, 0), |
| 3146 |
SND_BBFPRO_USBREQ_MIXER, |
| 3147 |
USB_DIR_OUT | USB_TYPE_VENDOR | |
| 3148 |
USB_RECIP_DEVICE, |
| 3149 |
usb_val, usb_idx, NULL, 0); |
| 3150 |
} |
| 3151 |
|
| 3152 |
static int snd_bbfpro_vol_get(struct snd_kcontrol *kcontrol, |
| 3153 |
struct snd_ctl_elem_value *ucontrol) |
| 3154 |
{ |
| 3155 |
ucontrol->value.integer.value[0] = |
| 3156 |
kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; |
| 3157 |
return 0; |
| 3158 |
} |
| 3159 |
|
| 3160 |
static int snd_bbfpro_vol_info(struct snd_kcontrol *kcontrol, |
| 3161 |
struct snd_ctl_elem_info *uinfo) |
| 3162 |
{ |
| 3163 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3164 |
uinfo->count = 1; |
| 3165 |
uinfo->value.integer.min = SND_BBFPRO_MIXER_VAL_MIN; |
| 3166 |
uinfo->value.integer.max = SND_BBFPRO_MIXER_VAL_MAX; |
| 3167 |
return 0; |
| 3168 |
} |
| 3169 |
|
| 3170 |
static int snd_bbfpro_vol_put(struct snd_kcontrol *kcontrol, |
| 3171 |
struct snd_ctl_elem_value *ucontrol) |
| 3172 |
{ |
| 3173 |
int err; |
| 3174 |
u16 idx; |
| 3175 |
u32 new_val, old_value, uvalue; |
| 3176 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 3177 |
struct usb_mixer_interface *mixer = list->mixer; |
| 3178 |
|
| 3179 |
uvalue = ucontrol->value.integer.value[0]; |
| 3180 |
idx = kcontrol->private_value & SND_BBFPRO_MIXER_IDX_MASK; |
| 3181 |
old_value = kcontrol->private_value >> SND_BBFPRO_MIXER_VAL_SHIFT; |
| 3182 |
|
| 3183 |
if (uvalue > SND_BBFPRO_MIXER_VAL_MAX) |
| 3184 |
return -EINVAL; |
| 3185 |
|
| 3186 |
if (uvalue == old_value) |
| 3187 |
return 0; |
| 3188 |
|
| 3189 |
new_val = uvalue & SND_BBFPRO_MIXER_VAL_MASK; |
| 3190 |
|
| 3191 |
kcontrol->private_value = idx |
| 3192 |
| (new_val << SND_BBFPRO_MIXER_VAL_SHIFT); |
| 3193 |
|
| 3194 |
err = snd_bbfpro_vol_update(mixer, idx, new_val); |
| 3195 |
return err < 0 ? err : 1; |
| 3196 |
} |
| 3197 |
|
| 3198 |
static int snd_bbfpro_vol_resume(struct usb_mixer_elem_list *list) |
| 3199 |
{ |
| 3200 |
int pv = list->kctl->private_value; |
| 3201 |
u16 idx = pv & SND_BBFPRO_MIXER_IDX_MASK; |
| 3202 |
u32 val = (pv >> SND_BBFPRO_MIXER_VAL_SHIFT) |
| 3203 |
& SND_BBFPRO_MIXER_VAL_MASK; |
| 3204 |
return snd_bbfpro_vol_update(list->mixer, idx, val); |
| 3205 |
} |
| 3206 |
|
| 3207 |
// Predfine elements |
| 3208 |
static const struct snd_kcontrol_new snd_bbfpro_ctl_control = { |
| 3209 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3210 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3211 |
.index = 0, |
| 3212 |
.info = snd_bbfpro_ctl_info, |
| 3213 |
.get = snd_bbfpro_ctl_get, |
| 3214 |
.put = snd_bbfpro_ctl_put |
| 3215 |
}; |
| 3216 |
|
| 3217 |
static const struct snd_kcontrol_new snd_bbfpro_gain_control = { |
| 3218 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3219 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3220 |
.index = 0, |
| 3221 |
.info = snd_bbfpro_gain_info, |
| 3222 |
.get = snd_bbfpro_gain_get, |
| 3223 |
.put = snd_bbfpro_gain_put |
| 3224 |
}; |
| 3225 |
|
| 3226 |
static const struct snd_kcontrol_new snd_bbfpro_vol_control = { |
| 3227 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3228 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3229 |
.index = 0, |
| 3230 |
.info = snd_bbfpro_vol_info, |
| 3231 |
.get = snd_bbfpro_vol_get, |
| 3232 |
.put = snd_bbfpro_vol_put |
| 3233 |
}; |
| 3234 |
|
| 3235 |
static int snd_bbfpro_ctl_add(struct usb_mixer_interface *mixer, u8 reg, |
| 3236 |
u8 index, char *name) |
| 3237 |
{ |
| 3238 |
struct snd_kcontrol_new knew = snd_bbfpro_ctl_control; |
| 3239 |
|
| 3240 |
knew.name = name; |
| 3241 |
knew.private_value = (reg & SND_BBFPRO_CTL_REG_MASK) |
| 3242 |
| ((index & SND_BBFPRO_CTL_IDX_MASK) |
| 3243 |
<< SND_BBFPRO_CTL_IDX_SHIFT); |
| 3244 |
|
| 3245 |
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_ctl_resume, |
| 3246 |
&knew, NULL); |
| 3247 |
} |
| 3248 |
|
| 3249 |
static int snd_bbfpro_gain_add(struct usb_mixer_interface *mixer, u8 channel, |
| 3250 |
char *name) |
| 3251 |
{ |
| 3252 |
struct snd_kcontrol_new knew = snd_bbfpro_gain_control; |
| 3253 |
|
| 3254 |
knew.name = name; |
| 3255 |
knew.private_value = channel << SND_BBFPRO_GAIN_CHANNEL_SHIFT; |
| 3256 |
|
| 3257 |
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_gain_resume, |
| 3258 |
&knew, NULL); |
| 3259 |
} |
| 3260 |
|
| 3261 |
static int snd_bbfpro_vol_add(struct usb_mixer_interface *mixer, u16 index, |
| 3262 |
char *name) |
| 3263 |
{ |
| 3264 |
struct snd_kcontrol_new knew = snd_bbfpro_vol_control; |
| 3265 |
|
| 3266 |
knew.name = name; |
| 3267 |
knew.private_value = index & SND_BBFPRO_MIXER_IDX_MASK; |
| 3268 |
|
| 3269 |
return add_single_ctl_with_resume(mixer, 0, snd_bbfpro_vol_resume, |
| 3270 |
&knew, NULL); |
| 3271 |
} |
| 3272 |
|
| 3273 |
static int snd_bbfpro_controls_create(struct usb_mixer_interface *mixer) |
| 3274 |
{ |
| 3275 |
int err, i, o; |
| 3276 |
char name[48]; |
| 3277 |
|
| 3278 |
static const char * const input[] = { |
| 3279 |
"AN1", "AN2", "IN3", "IN4", "AS1", "AS2", "ADAT3", |
| 3280 |
"ADAT4", "ADAT5", "ADAT6", "ADAT7", "ADAT8"}; |
| 3281 |
|
| 3282 |
static const char * const output[] = { |
| 3283 |
"AN1", "AN2", "PH3", "PH4", "AS1", "AS2", "ADAT3", "ADAT4", |
| 3284 |
"ADAT5", "ADAT6", "ADAT7", "ADAT8"}; |
| 3285 |
|
| 3286 |
for (o = 0 ; o < 12 ; ++o) { |
| 3287 |
for (i = 0 ; i < 12 ; ++i) { |
| 3288 |
// Line routing |
| 3289 |
snprintf(name, sizeof(name), |
| 3290 |
"%s-%s-%s Playback Volume", |
| 3291 |
(i < 2 ? "Mic" : "Line"), |
| 3292 |
input[i], output[o]); |
| 3293 |
err = snd_bbfpro_vol_add(mixer, (26 * o + i), name); |
| 3294 |
if (err < 0) |
| 3295 |
return err; |
| 3296 |
|
| 3297 |
// PCM routing... yes, it is output remapping |
| 3298 |
snprintf(name, sizeof(name), |
| 3299 |
"PCM-%s-%s Playback Volume", |
| 3300 |
output[i], output[o]); |
| 3301 |
err = snd_bbfpro_vol_add(mixer, (26 * o + 12 + i), |
| 3302 |
name); |
| 3303 |
if (err < 0) |
| 3304 |
return err; |
| 3305 |
} |
| 3306 |
} |
| 3307 |
|
| 3308 |
// Main out volume |
| 3309 |
for (i = 0 ; i < 12 ; ++i) { |
| 3310 |
snprintf(name, sizeof(name), "Main-Out %s", output[i]); |
| 3311 |
// Main outs are offset to 992 |
| 3312 |
err = snd_bbfpro_vol_add(mixer, |
| 3313 |
i + SND_BBFPRO_MIXER_MAIN_OUT_CH_OFFSET, |
| 3314 |
name); |
| 3315 |
if (err < 0) |
| 3316 |
return err; |
| 3317 |
} |
| 3318 |
|
| 3319 |
// Input gain |
| 3320 |
for (i = 0 ; i < 4 ; ++i) { |
| 3321 |
if (i < 2) |
| 3322 |
snprintf(name, sizeof(name), "Mic-%s Gain", input[i]); |
| 3323 |
else |
| 3324 |
snprintf(name, sizeof(name), "Line-%s Gain", input[i]); |
| 3325 |
|
| 3326 |
err = snd_bbfpro_gain_add(mixer, i, name); |
| 3327 |
if (err < 0) |
| 3328 |
return err; |
| 3329 |
} |
| 3330 |
|
| 3331 |
// Control Reg 1 |
| 3332 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, |
| 3333 |
SND_BBFPRO_CTL_REG1_CLK_OPTICAL, |
| 3334 |
"Sample Clock Source"); |
| 3335 |
if (err < 0) |
| 3336 |
return err; |
| 3337 |
|
| 3338 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, |
| 3339 |
SND_BBFPRO_CTL_REG1_SPDIF_PRO, |
| 3340 |
"IEC958 Pro Mask"); |
| 3341 |
if (err < 0) |
| 3342 |
return err; |
| 3343 |
|
| 3344 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, |
| 3345 |
SND_BBFPRO_CTL_REG1_SPDIF_EMPH, |
| 3346 |
"IEC958 Emphasis"); |
| 3347 |
if (err < 0) |
| 3348 |
return err; |
| 3349 |
|
| 3350 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG1, |
| 3351 |
SND_BBFPRO_CTL_REG1_SPDIF_OPTICAL, |
| 3352 |
"IEC958 Switch"); |
| 3353 |
if (err < 0) |
| 3354 |
return err; |
| 3355 |
|
| 3356 |
// Control Reg 2 |
| 3357 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3358 |
SND_BBFPRO_CTL_REG2_48V_AN1, |
| 3359 |
"Mic-AN1 48V"); |
| 3360 |
if (err < 0) |
| 3361 |
return err; |
| 3362 |
|
| 3363 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3364 |
SND_BBFPRO_CTL_REG2_48V_AN2, |
| 3365 |
"Mic-AN2 48V"); |
| 3366 |
if (err < 0) |
| 3367 |
return err; |
| 3368 |
|
| 3369 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3370 |
SND_BBFPRO_CTL_REG2_SENS_IN3, |
| 3371 |
"Line-IN3 Sens."); |
| 3372 |
if (err < 0) |
| 3373 |
return err; |
| 3374 |
|
| 3375 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3376 |
SND_BBFPRO_CTL_REG2_SENS_IN4, |
| 3377 |
"Line-IN4 Sens."); |
| 3378 |
if (err < 0) |
| 3379 |
return err; |
| 3380 |
|
| 3381 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3382 |
SND_BBFPRO_CTL_REG2_PAD_AN1, |
| 3383 |
"Mic-AN1 PAD"); |
| 3384 |
if (err < 0) |
| 3385 |
return err; |
| 3386 |
|
| 3387 |
err = snd_bbfpro_ctl_add(mixer, SND_BBFPRO_CTL_REG2, |
| 3388 |
SND_BBFPRO_CTL_REG2_PAD_AN2, |
| 3389 |
"Mic-AN2 PAD"); |
| 3390 |
if (err < 0) |
| 3391 |
return err; |
| 3392 |
|
| 3393 |
return 0; |
| 3394 |
} |
| 3395 |
|
| 3396 |
/* |
| 3397 |
* RME Digiface USB |
| 3398 |
*/ |
| 3399 |
|
| 3400 |
#define RME_DIGIFACE_READ_STATUS 17 |
| 3401 |
#define RME_DIGIFACE_STATUS_REG0L 0 |
| 3402 |
#define RME_DIGIFACE_STATUS_REG0H 1 |
| 3403 |
#define RME_DIGIFACE_STATUS_REG1L 2 |
| 3404 |
#define RME_DIGIFACE_STATUS_REG1H 3 |
| 3405 |
#define RME_DIGIFACE_STATUS_REG2L 4 |
| 3406 |
#define RME_DIGIFACE_STATUS_REG2H 5 |
| 3407 |
#define RME_DIGIFACE_STATUS_REG3L 6 |
| 3408 |
#define RME_DIGIFACE_STATUS_REG3H 7 |
| 3409 |
|
| 3410 |
#define RME_DIGIFACE_CTL_REG1 16 |
| 3411 |
#define RME_DIGIFACE_CTL_REG2 18 |
| 3412 |
|
| 3413 |
/* Reg is overloaded, 0-7 for status halfwords or 16 or 18 for control registers */ |
| 3414 |
#define RME_DIGIFACE_REGISTER(reg, mask) (((reg) << 16) | (mask)) |
| 3415 |
#define RME_DIGIFACE_INVERT BIT(31) |
| 3416 |
|
| 3417 |
static int snd_rme_digiface_write_reg(struct snd_kcontrol *kcontrol, int item, u16 mask, u16 val) |
| 3418 |
{ |
| 3419 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 3420 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 3421 |
struct usb_device *dev = chip->dev; |
| 3422 |
int err; |
| 3423 |
|
| 3424 |
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), |
| 3425 |
item, |
| 3426 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 3427 |
val, mask, NULL, 0); |
| 3428 |
if (err < 0) |
| 3429 |
dev_err(&dev->dev, |
| 3430 |
"unable to issue control set request %d (ret = %d)", |
| 3431 |
item, err); |
| 3432 |
return err; |
| 3433 |
} |
| 3434 |
|
| 3435 |
static int snd_rme_digiface_read_status(struct snd_kcontrol *kcontrol, u32 status[4]) |
| 3436 |
{ |
| 3437 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol); |
| 3438 |
struct snd_usb_audio *chip = list->mixer->chip; |
| 3439 |
struct usb_device *dev = chip->dev; |
| 3440 |
__le32 buf[4]; |
| 3441 |
int err; |
| 3442 |
|
| 3443 |
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), |
| 3444 |
RME_DIGIFACE_READ_STATUS, |
| 3445 |
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 3446 |
0, 0, |
| 3447 |
buf, sizeof(buf)); |
| 3448 |
if (err < 0) { |
| 3449 |
dev_err(&dev->dev, |
| 3450 |
"unable to issue status read request (ret = %d)", |
| 3451 |
err); |
| 3452 |
} else { |
| 3453 |
for (int i = 0; i < ARRAY_SIZE(buf); i++) |
| 3454 |
status[i] = le32_to_cpu(buf[i]); |
| 3455 |
} |
| 3456 |
return err; |
| 3457 |
} |
| 3458 |
|
| 3459 |
static int snd_rme_digiface_get_status_val(struct snd_kcontrol *kcontrol) |
| 3460 |
{ |
| 3461 |
int err; |
| 3462 |
u32 status[4]; |
| 3463 |
bool invert = kcontrol->private_value & RME_DIGIFACE_INVERT; |
| 3464 |
u8 reg = (kcontrol->private_value >> 16) & 0xff; |
| 3465 |
u16 mask = kcontrol->private_value & 0xffff; |
| 3466 |
u16 val; |
| 3467 |
|
| 3468 |
err = snd_rme_digiface_read_status(kcontrol, status); |
| 3469 |
if (err < 0) |
| 3470 |
return err; |
| 3471 |
|
| 3472 |
switch (reg) { |
| 3473 |
/* Status register halfwords */ |
| 3474 |
case RME_DIGIFACE_STATUS_REG0L ... RME_DIGIFACE_STATUS_REG3H: |
| 3475 |
break; |
| 3476 |
case RME_DIGIFACE_CTL_REG1: /* Control register 1, present in halfword 3L */ |
| 3477 |
reg = RME_DIGIFACE_STATUS_REG3L; |
| 3478 |
break; |
| 3479 |
case RME_DIGIFACE_CTL_REG2: /* Control register 2, present in halfword 3H */ |
| 3480 |
reg = RME_DIGIFACE_STATUS_REG3H; |
| 3481 |
break; |
| 3482 |
default: |
| 3483 |
return -EINVAL; |
| 3484 |
} |
| 3485 |
|
| 3486 |
if (reg & 1) |
| 3487 |
val = status[reg >> 1] >> 16; |
| 3488 |
else |
| 3489 |
val = status[reg >> 1] & 0xffff; |
| 3490 |
|
| 3491 |
if (invert) |
| 3492 |
val ^= mask; |
| 3493 |
|
| 3494 |
return field_get(mask, val); |
| 3495 |
} |
| 3496 |
|
| 3497 |
static int snd_rme_digiface_rate_get(struct snd_kcontrol *kcontrol, |
| 3498 |
struct snd_ctl_elem_value *ucontrol) |
| 3499 |
{ |
| 3500 |
int freq = snd_rme_digiface_get_status_val(kcontrol); |
| 3501 |
|
| 3502 |
if (freq < 0) |
| 3503 |
return freq; |
| 3504 |
if (freq >= ARRAY_SIZE(snd_rme_rate_table)) |
| 3505 |
return -EIO; |
| 3506 |
|
| 3507 |
ucontrol->value.integer.value[0] = snd_rme_rate_table[freq]; |
| 3508 |
return 0; |
| 3509 |
} |
| 3510 |
|
| 3511 |
static int snd_rme_digiface_enum_get(struct snd_kcontrol *kcontrol, |
| 3512 |
struct snd_ctl_elem_value *ucontrol) |
| 3513 |
{ |
| 3514 |
int val = snd_rme_digiface_get_status_val(kcontrol); |
| 3515 |
|
| 3516 |
if (val < 0) |
| 3517 |
return val; |
| 3518 |
|
| 3519 |
ucontrol->value.enumerated.item[0] = val; |
| 3520 |
return 0; |
| 3521 |
} |
| 3522 |
|
| 3523 |
static int snd_rme_digiface_enum_put(struct snd_kcontrol *kcontrol, |
| 3524 |
struct snd_ctl_elem_value *ucontrol) |
| 3525 |
{ |
| 3526 |
bool invert = kcontrol->private_value & RME_DIGIFACE_INVERT; |
| 3527 |
u8 reg = (kcontrol->private_value >> 16) & 0xff; |
| 3528 |
u16 mask = kcontrol->private_value & 0xffff; |
| 3529 |
u16 val = field_prep(mask, ucontrol->value.enumerated.item[0]); |
| 3530 |
|
| 3531 |
if (invert) |
| 3532 |
val ^= mask; |
| 3533 |
|
| 3534 |
return snd_rme_digiface_write_reg(kcontrol, reg, mask, val); |
| 3535 |
} |
| 3536 |
|
| 3537 |
static int snd_rme_digiface_current_sync_get(struct snd_kcontrol *kcontrol, |
| 3538 |
struct snd_ctl_elem_value *ucontrol) |
| 3539 |
{ |
| 3540 |
int ret = snd_rme_digiface_enum_get(kcontrol, ucontrol); |
| 3541 |
|
| 3542 |
/* 7 means internal for current sync */ |
| 3543 |
if (ucontrol->value.enumerated.item[0] == 7) |
| 3544 |
ucontrol->value.enumerated.item[0] = 0; |
| 3545 |
|
| 3546 |
return ret; |
| 3547 |
} |
| 3548 |
|
| 3549 |
static int snd_rme_digiface_sync_state_get(struct snd_kcontrol *kcontrol, |
| 3550 |
struct snd_ctl_elem_value *ucontrol) |
| 3551 |
{ |
| 3552 |
u32 status[4]; |
| 3553 |
int err; |
| 3554 |
bool valid, sync; |
| 3555 |
|
| 3556 |
err = snd_rme_digiface_read_status(kcontrol, status); |
| 3557 |
if (err < 0) |
| 3558 |
return err; |
| 3559 |
|
| 3560 |
valid = status[0] & BIT(kcontrol->private_value); |
| 3561 |
sync = status[0] & BIT(5 + kcontrol->private_value); |
| 3562 |
|
| 3563 |
if (!valid) |
| 3564 |
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_NOLOCK; |
| 3565 |
else if (!sync) |
| 3566 |
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_LOCK; |
| 3567 |
else |
| 3568 |
ucontrol->value.enumerated.item[0] = SND_RME_CLOCK_SYNC; |
| 3569 |
return 0; |
| 3570 |
} |
| 3571 |
|
| 3572 |
static int snd_rme_digiface_format_info(struct snd_kcontrol *kcontrol, |
| 3573 |
struct snd_ctl_elem_info *uinfo) |
| 3574 |
{ |
| 3575 |
static const char *const format[] = { |
| 3576 |
"ADAT", "S/PDIF" |
| 3577 |
}; |
| 3578 |
|
| 3579 |
return snd_ctl_enum_info(uinfo, 1, |
| 3580 |
ARRAY_SIZE(format), format); |
| 3581 |
} |
| 3582 |
|
| 3583 |
static int snd_rme_digiface_sync_source_info(struct snd_kcontrol *kcontrol, |
| 3584 |
struct snd_ctl_elem_info *uinfo) |
| 3585 |
{ |
| 3586 |
static const char *const sync_sources[] = { |
| 3587 |
"Internal", "Input 1", "Input 2", "Input 3", "Input 4" |
| 3588 |
}; |
| 3589 |
|
| 3590 |
return snd_ctl_enum_info(uinfo, 1, |
| 3591 |
ARRAY_SIZE(sync_sources), sync_sources); |
| 3592 |
} |
| 3593 |
|
| 3594 |
static int snd_rme_digiface_rate_info(struct snd_kcontrol *kcontrol, |
| 3595 |
struct snd_ctl_elem_info *uinfo) |
| 3596 |
{ |
| 3597 |
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3598 |
uinfo->count = 1; |
| 3599 |
uinfo->value.integer.min = 0; |
| 3600 |
uinfo->value.integer.max = 200000; |
| 3601 |
uinfo->value.integer.step = 0; |
| 3602 |
return 0; |
| 3603 |
} |
| 3604 |
|
| 3605 |
static const struct snd_kcontrol_new snd_rme_digiface_controls[] = { |
| 3606 |
{ |
| 3607 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3608 |
.name = "Input 1 Sync", |
| 3609 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3610 |
.info = snd_rme_sync_state_info, |
| 3611 |
.get = snd_rme_digiface_sync_state_get, |
| 3612 |
.private_value = 0, |
| 3613 |
}, |
| 3614 |
{ |
| 3615 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3616 |
.name = "Input 1 Format", |
| 3617 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3618 |
.info = snd_rme_digiface_format_info, |
| 3619 |
.get = snd_rme_digiface_enum_get, |
| 3620 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0H, BIT(0)) | |
| 3621 |
RME_DIGIFACE_INVERT, |
| 3622 |
}, |
| 3623 |
{ |
| 3624 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3625 |
.name = "Input 1 Rate", |
| 3626 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3627 |
.info = snd_rme_digiface_rate_info, |
| 3628 |
.get = snd_rme_digiface_rate_get, |
| 3629 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(3, 0)), |
| 3630 |
}, |
| 3631 |
{ |
| 3632 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3633 |
.name = "Input 2 Sync", |
| 3634 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3635 |
.info = snd_rme_sync_state_info, |
| 3636 |
.get = snd_rme_digiface_sync_state_get, |
| 3637 |
.private_value = 1, |
| 3638 |
}, |
| 3639 |
{ |
| 3640 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3641 |
.name = "Input 2 Format", |
| 3642 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3643 |
.info = snd_rme_digiface_format_info, |
| 3644 |
.get = snd_rme_digiface_enum_get, |
| 3645 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, BIT(13)) | |
| 3646 |
RME_DIGIFACE_INVERT, |
| 3647 |
}, |
| 3648 |
{ |
| 3649 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3650 |
.name = "Input 2 Rate", |
| 3651 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3652 |
.info = snd_rme_digiface_rate_info, |
| 3653 |
.get = snd_rme_digiface_rate_get, |
| 3654 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(7, 4)), |
| 3655 |
}, |
| 3656 |
{ |
| 3657 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3658 |
.name = "Input 3 Sync", |
| 3659 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3660 |
.info = snd_rme_sync_state_info, |
| 3661 |
.get = snd_rme_digiface_sync_state_get, |
| 3662 |
.private_value = 2, |
| 3663 |
}, |
| 3664 |
{ |
| 3665 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3666 |
.name = "Input 3 Format", |
| 3667 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3668 |
.info = snd_rme_digiface_format_info, |
| 3669 |
.get = snd_rme_digiface_enum_get, |
| 3670 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, BIT(14)) | |
| 3671 |
RME_DIGIFACE_INVERT, |
| 3672 |
}, |
| 3673 |
{ |
| 3674 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3675 |
.name = "Input 3 Rate", |
| 3676 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3677 |
.info = snd_rme_digiface_rate_info, |
| 3678 |
.get = snd_rme_digiface_rate_get, |
| 3679 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(11, 8)), |
| 3680 |
}, |
| 3681 |
{ |
| 3682 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3683 |
.name = "Input 4 Sync", |
| 3684 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3685 |
.info = snd_rme_sync_state_info, |
| 3686 |
.get = snd_rme_digiface_sync_state_get, |
| 3687 |
.private_value = 3, |
| 3688 |
}, |
| 3689 |
{ |
| 3690 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3691 |
.name = "Input 4 Format", |
| 3692 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3693 |
.info = snd_rme_digiface_format_info, |
| 3694 |
.get = snd_rme_digiface_enum_get, |
| 3695 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, GENMASK(15, 12)) | |
| 3696 |
RME_DIGIFACE_INVERT, |
| 3697 |
}, |
| 3698 |
{ |
| 3699 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3700 |
.name = "Input 4 Rate", |
| 3701 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3702 |
.info = snd_rme_digiface_rate_info, |
| 3703 |
.get = snd_rme_digiface_rate_get, |
| 3704 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1L, GENMASK(3, 0)), |
| 3705 |
}, |
| 3706 |
{ |
| 3707 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3708 |
.name = "Output 1 Format", |
| 3709 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3710 |
.info = snd_rme_digiface_format_info, |
| 3711 |
.get = snd_rme_digiface_enum_get, |
| 3712 |
.put = snd_rme_digiface_enum_put, |
| 3713 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(0)), |
| 3714 |
}, |
| 3715 |
{ |
| 3716 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3717 |
.name = "Output 2 Format", |
| 3718 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3719 |
.info = snd_rme_digiface_format_info, |
| 3720 |
.get = snd_rme_digiface_enum_get, |
| 3721 |
.put = snd_rme_digiface_enum_put, |
| 3722 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(1)), |
| 3723 |
}, |
| 3724 |
{ |
| 3725 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3726 |
.name = "Output 3 Format", |
| 3727 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3728 |
.info = snd_rme_digiface_format_info, |
| 3729 |
.get = snd_rme_digiface_enum_get, |
| 3730 |
.put = snd_rme_digiface_enum_put, |
| 3731 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(3)), |
| 3732 |
}, |
| 3733 |
{ |
| 3734 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3735 |
.name = "Output 4 Format", |
| 3736 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3737 |
.info = snd_rme_digiface_format_info, |
| 3738 |
.get = snd_rme_digiface_enum_get, |
| 3739 |
.put = snd_rme_digiface_enum_put, |
| 3740 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG2, BIT(4)), |
| 3741 |
}, |
| 3742 |
{ |
| 3743 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3744 |
.name = "Sync Source", |
| 3745 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 3746 |
.info = snd_rme_digiface_sync_source_info, |
| 3747 |
.get = snd_rme_digiface_enum_get, |
| 3748 |
.put = snd_rme_digiface_enum_put, |
| 3749 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG1, GENMASK(2, 0)), |
| 3750 |
}, |
| 3751 |
{ |
| 3752 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3753 |
.name = "Current Sync Source", |
| 3754 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3755 |
.info = snd_rme_digiface_sync_source_info, |
| 3756 |
.get = snd_rme_digiface_current_sync_get, |
| 3757 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG0L, GENMASK(12, 10)), |
| 3758 |
}, |
| 3759 |
{ |
| 3760 |
/* |
| 3761 |
* This is writeable, but it is only set by the PCM rate. |
| 3762 |
* Mixer apps currently need to drive the mixer using raw USB requests, |
| 3763 |
* so they can also change this that way to configure the rate for |
| 3764 |
* stand-alone operation when the PCM is closed. |
| 3765 |
*/ |
| 3766 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3767 |
.name = "System Rate", |
| 3768 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3769 |
.info = snd_rme_rate_info, |
| 3770 |
.get = snd_rme_digiface_rate_get, |
| 3771 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_CTL_REG1, GENMASK(6, 3)), |
| 3772 |
}, |
| 3773 |
{ |
| 3774 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 3775 |
.name = "Current Rate", |
| 3776 |
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 3777 |
.info = snd_rme_rate_info, |
| 3778 |
.get = snd_rme_digiface_rate_get, |
| 3779 |
.private_value = RME_DIGIFACE_REGISTER(RME_DIGIFACE_STATUS_REG1H, GENMASK(7, 4)), |
| 3780 |
} |
| 3781 |
}; |
| 3782 |
|
| 3783 |
static int snd_rme_digiface_controls_create(struct usb_mixer_interface *mixer) |
| 3784 |
{ |
| 3785 |
int err, i; |
| 3786 |
|
| 3787 |
for (i = 0; i < ARRAY_SIZE(snd_rme_digiface_controls); ++i) { |
| 3788 |
err = add_single_ctl_with_resume(mixer, 0, |
| 3789 |
NULL, |
| 3790 |
&snd_rme_digiface_controls[i], |
| 3791 |
NULL); |
| 3792 |
if (err < 0) |
| 3793 |
return err; |
| 3794 |
} |
| 3795 |
|
| 3796 |
return 0; |
| 3797 |
} |
| 3798 |
|
| 3799 |
/* |
| 3800 |
* Pioneer DJ / AlphaTheta DJM Mixers |
| 3801 |
* |
| 3802 |
* These devices generally have options for soft-switching the playback and |
| 3803 |
* capture sources in addition to the recording level. Although different |
| 3804 |
* devices have different configurations, there seems to be canonical values |
| 3805 |
* for specific capture/playback types: See the definitions of these below. |
| 3806 |
* |
| 3807 |
* The wValue is masked with the stereo channel number. e.g. Setting Ch2 to |
| 3808 |
* capture phono would be 0x0203. Capture, playback and capture level have |
| 3809 |
* different wIndexes. |
| 3810 |
*/ |
| 3811 |
|
| 3812 |
// Capture types |
| 3813 |
#define SND_DJM_CAP_LINE 0x00 |
| 3814 |
#define SND_DJM_CAP_CDLINE 0x01 |
| 3815 |
#define SND_DJM_CAP_DIGITAL 0x02 |
| 3816 |
#define SND_DJM_CAP_PHONO 0x03 |
| 3817 |
#define SND_DJM_CAP_PREFADER 0x05 |
| 3818 |
#define SND_DJM_CAP_PFADER 0x06 |
| 3819 |
#define SND_DJM_CAP_XFADERA 0x07 |
| 3820 |
#define SND_DJM_CAP_XFADERB 0x08 |
| 3821 |
#define SND_DJM_CAP_MIC 0x09 |
| 3822 |
#define SND_DJM_CAP_AUX 0x0d |
| 3823 |
#define SND_DJM_CAP_RECOUT 0x0a |
| 3824 |
#define SND_DJM_CAP_RECOUT_NOMIC 0x0e |
| 3825 |
#define SND_DJM_CAP_NONE 0x0f |
| 3826 |
#define SND_DJM_CAP_FXSEND 0x10 |
| 3827 |
#define SND_DJM_CAP_CH1PFADER 0x11 |
| 3828 |
#define SND_DJM_CAP_CH2PFADER 0x12 |
| 3829 |
#define SND_DJM_CAP_CH3PFADER 0x13 |
| 3830 |
#define SND_DJM_CAP_CH4PFADER 0x14 |
| 3831 |
#define SND_DJM_CAP_EXT1SEND 0x21 |
| 3832 |
#define SND_DJM_CAP_EXT2SEND 0x22 |
| 3833 |
#define SND_DJM_CAP_CH1PREFADER 0x31 |
| 3834 |
#define SND_DJM_CAP_CH2PREFADER 0x32 |
| 3835 |
#define SND_DJM_CAP_CH3PREFADER 0x33 |
| 3836 |
#define SND_DJM_CAP_CH4PREFADER 0x34 |
| 3837 |
|
| 3838 |
// Playback types |
| 3839 |
#define SND_DJM_PB_CH1 0x00 |
| 3840 |
#define SND_DJM_PB_CH2 0x01 |
| 3841 |
#define SND_DJM_PB_AUX 0x04 |
| 3842 |
|
| 3843 |
#define SND_DJM_WINDEX_CAP 0x8002 |
| 3844 |
#define SND_DJM_WINDEX_CAPLVL 0x8003 |
| 3845 |
#define SND_DJM_WINDEX_PB 0x8016 |
| 3846 |
|
| 3847 |
// kcontrol->private_value layout |
| 3848 |
#define SND_DJM_VALUE_MASK 0x0000ffff |
| 3849 |
#define SND_DJM_GROUP_MASK 0x00ff0000 |
| 3850 |
#define SND_DJM_DEVICE_MASK 0xff000000 |
| 3851 |
#define SND_DJM_GROUP_SHIFT 16 |
| 3852 |
#define SND_DJM_DEVICE_SHIFT 24 |
| 3853 |
|
| 3854 |
// device table index |
| 3855 |
// used for the snd_djm_devices table, so please update accordingly |
| 3856 |
#define SND_DJM_250MK2_IDX 0x0 |
| 3857 |
#define SND_DJM_750_IDX 0x1 |
| 3858 |
#define SND_DJM_850_IDX 0x2 |
| 3859 |
#define SND_DJM_900NXS2_IDX 0x3 |
| 3860 |
#define SND_DJM_750MK2_IDX 0x4 |
| 3861 |
#define SND_DJM_450_IDX 0x5 |
| 3862 |
#define SND_DJM_A9_IDX 0x6 |
| 3863 |
#define SND_DJM_V10_IDX 0x7 |
| 3864 |
|
| 3865 |
#define SND_DJM_CTL(_name, suffix, _default_value, _windex) { \ |
| 3866 |
.name = _name, \ |
| 3867 |
.options = snd_djm_opts_##suffix, \ |
| 3868 |
.noptions = ARRAY_SIZE(snd_djm_opts_##suffix), \ |
| 3869 |
.default_value = _default_value, \ |
| 3870 |
.wIndex = _windex } |
| 3871 |
|
| 3872 |
#define SND_DJM_DEVICE(suffix) { \ |
| 3873 |
.controls = snd_djm_ctls_##suffix, \ |
| 3874 |
.ncontrols = ARRAY_SIZE(snd_djm_ctls_##suffix) } |
| 3875 |
|
| 3876 |
struct snd_djm_device { |
| 3877 |
const char *name; |
| 3878 |
const struct snd_djm_ctl *controls; |
| 3879 |
size_t ncontrols; |
| 3880 |
}; |
| 3881 |
|
| 3882 |
struct snd_djm_ctl { |
| 3883 |
const char *name; |
| 3884 |
const u16 *options; |
| 3885 |
size_t noptions; |
| 3886 |
u16 default_value; |
| 3887 |
u16 wIndex; |
| 3888 |
}; |
| 3889 |
|
| 3890 |
static const char *snd_djm_get_label_caplevel_common(u16 wvalue) |
| 3891 |
{ |
| 3892 |
switch (wvalue) { |
| 3893 |
case 0x0000: return "-19dB"; |
| 3894 |
case 0x0100: return "-15dB"; |
| 3895 |
case 0x0200: return "-10dB"; |
| 3896 |
case 0x0300: return "-5dB"; |
| 3897 |
default: return NULL; |
| 3898 |
} |
| 3899 |
}; |
| 3900 |
|
| 3901 |
// Models like DJM-A9 or DJM-V10 have different capture levels than others |
| 3902 |
static const char *snd_djm_get_label_caplevel_high(u16 wvalue) |
| 3903 |
{ |
| 3904 |
switch (wvalue) { |
| 3905 |
case 0x0000: return "+15dB"; |
| 3906 |
case 0x0100: return "+12dB"; |
| 3907 |
case 0x0200: return "+9dB"; |
| 3908 |
case 0x0300: return "+6dB"; |
| 3909 |
case 0x0400: return "+3dB"; |
| 3910 |
case 0x0500: return "0dB"; |
| 3911 |
default: return NULL; |
| 3912 |
} |
| 3913 |
}; |
| 3914 |
|
| 3915 |
static const char *snd_djm_get_label_cap_common(u16 wvalue) |
| 3916 |
{ |
| 3917 |
switch (wvalue & 0x00ff) { |
| 3918 |
case SND_DJM_CAP_LINE: return "Control Tone LINE"; |
| 3919 |
case SND_DJM_CAP_CDLINE: return "Control Tone CD/LINE"; |
| 3920 |
case SND_DJM_CAP_DIGITAL: return "Control Tone DIGITAL"; |
| 3921 |
case SND_DJM_CAP_PHONO: return "Control Tone PHONO"; |
| 3922 |
case SND_DJM_CAP_PFADER: return "Post Fader"; |
| 3923 |
case SND_DJM_CAP_XFADERA: return "Cross Fader A"; |
| 3924 |
case SND_DJM_CAP_XFADERB: return "Cross Fader B"; |
| 3925 |
case SND_DJM_CAP_MIC: return "Mic"; |
| 3926 |
case SND_DJM_CAP_RECOUT: return "Rec Out"; |
| 3927 |
case SND_DJM_CAP_RECOUT_NOMIC: return "Rec Out without Mic"; |
| 3928 |
case SND_DJM_CAP_AUX: return "Aux"; |
| 3929 |
case SND_DJM_CAP_NONE: return "None"; |
| 3930 |
case SND_DJM_CAP_FXSEND: return "FX SEND"; |
| 3931 |
case SND_DJM_CAP_CH1PREFADER: return "Pre Fader Ch1"; |
| 3932 |
case SND_DJM_CAP_CH2PREFADER: return "Pre Fader Ch2"; |
| 3933 |
case SND_DJM_CAP_CH3PREFADER: return "Pre Fader Ch3"; |
| 3934 |
case SND_DJM_CAP_CH4PREFADER: return "Pre Fader Ch4"; |
| 3935 |
case SND_DJM_CAP_CH1PFADER: return "Post Fader Ch1"; |
| 3936 |
case SND_DJM_CAP_CH2PFADER: return "Post Fader Ch2"; |
| 3937 |
case SND_DJM_CAP_CH3PFADER: return "Post Fader Ch3"; |
| 3938 |
case SND_DJM_CAP_CH4PFADER: return "Post Fader Ch4"; |
| 3939 |
case SND_DJM_CAP_EXT1SEND: return "EXT1 SEND"; |
| 3940 |
case SND_DJM_CAP_EXT2SEND: return "EXT2 SEND"; |
| 3941 |
default: return NULL; |
| 3942 |
} |
| 3943 |
}; |
| 3944 |
|
| 3945 |
// The DJM-850 has different values for CD/LINE and LINE capture |
| 3946 |
// control options than the other DJM declared in this file. |
| 3947 |
static const char *snd_djm_get_label_cap_850(u16 wvalue) |
| 3948 |
{ |
| 3949 |
switch (wvalue & 0x00ff) { |
| 3950 |
case 0x00: return "Control Tone CD/LINE"; |
| 3951 |
case 0x01: return "Control Tone LINE"; |
| 3952 |
default: return snd_djm_get_label_cap_common(wvalue); |
| 3953 |
} |
| 3954 |
}; |
| 3955 |
|
| 3956 |
static const char *snd_djm_get_label_caplevel(u8 device_idx, u16 wvalue) |
| 3957 |
{ |
| 3958 |
switch (device_idx) { |
| 3959 |
case SND_DJM_A9_IDX: return snd_djm_get_label_caplevel_high(wvalue); |
| 3960 |
case SND_DJM_V10_IDX: return snd_djm_get_label_caplevel_high(wvalue); |
| 3961 |
default: return snd_djm_get_label_caplevel_common(wvalue); |
| 3962 |
} |
| 3963 |
}; |
| 3964 |
|
| 3965 |
static const char *snd_djm_get_label_cap(u8 device_idx, u16 wvalue) |
| 3966 |
{ |
| 3967 |
switch (device_idx) { |
| 3968 |
case SND_DJM_850_IDX: return snd_djm_get_label_cap_850(wvalue); |
| 3969 |
default: return snd_djm_get_label_cap_common(wvalue); |
| 3970 |
} |
| 3971 |
}; |
| 3972 |
|
| 3973 |
static const char *snd_djm_get_label_pb(u16 wvalue) |
| 3974 |
{ |
| 3975 |
switch (wvalue & 0x00ff) { |
| 3976 |
case SND_DJM_PB_CH1: return "Ch1"; |
| 3977 |
case SND_DJM_PB_CH2: return "Ch2"; |
| 3978 |
case SND_DJM_PB_AUX: return "Aux"; |
| 3979 |
default: return NULL; |
| 3980 |
} |
| 3981 |
}; |
| 3982 |
|
| 3983 |
static const char *snd_djm_get_label(u8 device_idx, u16 wvalue, u16 windex) |
| 3984 |
{ |
| 3985 |
switch (windex) { |
| 3986 |
case SND_DJM_WINDEX_CAPLVL: return snd_djm_get_label_caplevel(device_idx, wvalue); |
| 3987 |
case SND_DJM_WINDEX_CAP: return snd_djm_get_label_cap(device_idx, wvalue); |
| 3988 |
case SND_DJM_WINDEX_PB: return snd_djm_get_label_pb(wvalue); |
| 3989 |
default: return NULL; |
| 3990 |
} |
| 3991 |
}; |
| 3992 |
|
| 3993 |
// common DJM capture level option values |
| 3994 |
static const u16 snd_djm_opts_cap_level[] = { |
| 3995 |
0x0000, 0x0100, 0x0200, 0x0300 }; |
| 3996 |
|
| 3997 |
// DJM-250MK2 |
| 3998 |
static const u16 snd_djm_opts_250mk2_cap1[] = { |
| 3999 |
0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a }; |
| 4000 |
|
| 4001 |
static const u16 snd_djm_opts_250mk2_cap2[] = { |
| 4002 |
0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a }; |
| 4003 |
|
| 4004 |
static const u16 snd_djm_opts_250mk2_cap3[] = { |
| 4005 |
0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d }; |
| 4006 |
|
| 4007 |
static const u16 snd_djm_opts_250mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; |
| 4008 |
static const u16 snd_djm_opts_250mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; |
| 4009 |
static const u16 snd_djm_opts_250mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; |
| 4010 |
|
| 4011 |
static const struct snd_djm_ctl snd_djm_ctls_250mk2[] = { |
| 4012 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4013 |
SND_DJM_CTL("Input 1 Capture Switch", 250mk2_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4014 |
SND_DJM_CTL("Input 2 Capture Switch", 250mk2_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4015 |
SND_DJM_CTL("Input 3 Capture Switch", 250mk2_cap3, 0, SND_DJM_WINDEX_CAP), |
| 4016 |
SND_DJM_CTL("Output 1 Playback Switch", 250mk2_pb1, 0, SND_DJM_WINDEX_PB), |
| 4017 |
SND_DJM_CTL("Output 2 Playback Switch", 250mk2_pb2, 1, SND_DJM_WINDEX_PB), |
| 4018 |
SND_DJM_CTL("Output 3 Playback Switch", 250mk2_pb3, 2, SND_DJM_WINDEX_PB) |
| 4019 |
}; |
| 4020 |
|
| 4021 |
// DJM-450 |
| 4022 |
static const u16 snd_djm_opts_450_cap1[] = { |
| 4023 |
0x0103, 0x0100, 0x0106, 0x0107, 0x0108, 0x0109, 0x010d, 0x010a }; |
| 4024 |
|
| 4025 |
static const u16 snd_djm_opts_450_cap2[] = { |
| 4026 |
0x0203, 0x0200, 0x0206, 0x0207, 0x0208, 0x0209, 0x020d, 0x020a }; |
| 4027 |
|
| 4028 |
static const u16 snd_djm_opts_450_cap3[] = { |
| 4029 |
0x030a, 0x0311, 0x0312, 0x0307, 0x0308, 0x0309, 0x030d }; |
| 4030 |
|
| 4031 |
static const u16 snd_djm_opts_450_pb1[] = { 0x0100, 0x0101, 0x0104 }; |
| 4032 |
static const u16 snd_djm_opts_450_pb2[] = { 0x0200, 0x0201, 0x0204 }; |
| 4033 |
static const u16 snd_djm_opts_450_pb3[] = { 0x0300, 0x0301, 0x0304 }; |
| 4034 |
|
| 4035 |
static const struct snd_djm_ctl snd_djm_ctls_450[] = { |
| 4036 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4037 |
SND_DJM_CTL("Input 1 Capture Switch", 450_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4038 |
SND_DJM_CTL("Input 2 Capture Switch", 450_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4039 |
SND_DJM_CTL("Input 3 Capture Switch", 450_cap3, 0, SND_DJM_WINDEX_CAP), |
| 4040 |
SND_DJM_CTL("Output 1 Playback Switch", 450_pb1, 0, SND_DJM_WINDEX_PB), |
| 4041 |
SND_DJM_CTL("Output 2 Playback Switch", 450_pb2, 1, SND_DJM_WINDEX_PB), |
| 4042 |
SND_DJM_CTL("Output 3 Playback Switch", 450_pb3, 2, SND_DJM_WINDEX_PB) |
| 4043 |
}; |
| 4044 |
|
| 4045 |
// DJM-750 |
| 4046 |
static const u16 snd_djm_opts_750_cap1[] = { |
| 4047 |
0x0101, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; |
| 4048 |
static const u16 snd_djm_opts_750_cap2[] = { |
| 4049 |
0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; |
| 4050 |
static const u16 snd_djm_opts_750_cap3[] = { |
| 4051 |
0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; |
| 4052 |
static const u16 snd_djm_opts_750_cap4[] = { |
| 4053 |
0x0401, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; |
| 4054 |
|
| 4055 |
static const struct snd_djm_ctl snd_djm_ctls_750[] = { |
| 4056 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4057 |
SND_DJM_CTL("Input 1 Capture Switch", 750_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4058 |
SND_DJM_CTL("Input 2 Capture Switch", 750_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4059 |
SND_DJM_CTL("Input 3 Capture Switch", 750_cap3, 0, SND_DJM_WINDEX_CAP), |
| 4060 |
SND_DJM_CTL("Input 4 Capture Switch", 750_cap4, 0, SND_DJM_WINDEX_CAP) |
| 4061 |
}; |
| 4062 |
|
| 4063 |
// DJM-850 |
| 4064 |
static const u16 snd_djm_opts_850_cap1[] = { |
| 4065 |
0x0100, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a, 0x010f }; |
| 4066 |
static const u16 snd_djm_opts_850_cap2[] = { |
| 4067 |
0x0200, 0x0201, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020f }; |
| 4068 |
static const u16 snd_djm_opts_850_cap3[] = { |
| 4069 |
0x0300, 0x0301, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030f }; |
| 4070 |
static const u16 snd_djm_opts_850_cap4[] = { |
| 4071 |
0x0400, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040f }; |
| 4072 |
|
| 4073 |
static const struct snd_djm_ctl snd_djm_ctls_850[] = { |
| 4074 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4075 |
SND_DJM_CTL("Input 1 Capture Switch", 850_cap1, 1, SND_DJM_WINDEX_CAP), |
| 4076 |
SND_DJM_CTL("Input 2 Capture Switch", 850_cap2, 0, SND_DJM_WINDEX_CAP), |
| 4077 |
SND_DJM_CTL("Input 3 Capture Switch", 850_cap3, 0, SND_DJM_WINDEX_CAP), |
| 4078 |
SND_DJM_CTL("Input 4 Capture Switch", 850_cap4, 1, SND_DJM_WINDEX_CAP) |
| 4079 |
}; |
| 4080 |
|
| 4081 |
// DJM-900NXS2 |
| 4082 |
static const u16 snd_djm_opts_900nxs2_cap1[] = { |
| 4083 |
0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; |
| 4084 |
static const u16 snd_djm_opts_900nxs2_cap2[] = { |
| 4085 |
0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; |
| 4086 |
static const u16 snd_djm_opts_900nxs2_cap3[] = { |
| 4087 |
0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; |
| 4088 |
static const u16 snd_djm_opts_900nxs2_cap4[] = { |
| 4089 |
0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; |
| 4090 |
static const u16 snd_djm_opts_900nxs2_cap5[] = { |
| 4091 |
0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; |
| 4092 |
|
| 4093 |
static const struct snd_djm_ctl snd_djm_ctls_900nxs2[] = { |
| 4094 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4095 |
SND_DJM_CTL("Input 1 Capture Switch", 900nxs2_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4096 |
SND_DJM_CTL("Input 2 Capture Switch", 900nxs2_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4097 |
SND_DJM_CTL("Input 3 Capture Switch", 900nxs2_cap3, 2, SND_DJM_WINDEX_CAP), |
| 4098 |
SND_DJM_CTL("Input 4 Capture Switch", 900nxs2_cap4, 2, SND_DJM_WINDEX_CAP), |
| 4099 |
SND_DJM_CTL("Input 5 Capture Switch", 900nxs2_cap5, 3, SND_DJM_WINDEX_CAP) |
| 4100 |
}; |
| 4101 |
|
| 4102 |
// DJM-750MK2 |
| 4103 |
static const u16 snd_djm_opts_750mk2_cap1[] = { |
| 4104 |
0x0100, 0x0102, 0x0103, 0x0106, 0x0107, 0x0108, 0x0109, 0x010a }; |
| 4105 |
static const u16 snd_djm_opts_750mk2_cap2[] = { |
| 4106 |
0x0200, 0x0202, 0x0203, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a }; |
| 4107 |
static const u16 snd_djm_opts_750mk2_cap3[] = { |
| 4108 |
0x0300, 0x0302, 0x0303, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a }; |
| 4109 |
static const u16 snd_djm_opts_750mk2_cap4[] = { |
| 4110 |
0x0400, 0x0402, 0x0403, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a }; |
| 4111 |
static const u16 snd_djm_opts_750mk2_cap5[] = { |
| 4112 |
0x0507, 0x0508, 0x0509, 0x050a, 0x0511, 0x0512, 0x0513, 0x0514 }; |
| 4113 |
|
| 4114 |
static const u16 snd_djm_opts_750mk2_pb1[] = { 0x0100, 0x0101, 0x0104 }; |
| 4115 |
static const u16 snd_djm_opts_750mk2_pb2[] = { 0x0200, 0x0201, 0x0204 }; |
| 4116 |
static const u16 snd_djm_opts_750mk2_pb3[] = { 0x0300, 0x0301, 0x0304 }; |
| 4117 |
|
| 4118 |
static const struct snd_djm_ctl snd_djm_ctls_750mk2[] = { |
| 4119 |
SND_DJM_CTL("Master Input Level Capture Switch", cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4120 |
SND_DJM_CTL("Input 1 Capture Switch", 750mk2_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4121 |
SND_DJM_CTL("Input 2 Capture Switch", 750mk2_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4122 |
SND_DJM_CTL("Input 3 Capture Switch", 750mk2_cap3, 2, SND_DJM_WINDEX_CAP), |
| 4123 |
SND_DJM_CTL("Input 4 Capture Switch", 750mk2_cap4, 2, SND_DJM_WINDEX_CAP), |
| 4124 |
SND_DJM_CTL("Input 5 Capture Switch", 750mk2_cap5, 3, SND_DJM_WINDEX_CAP), |
| 4125 |
SND_DJM_CTL("Output 1 Playback Switch", 750mk2_pb1, 0, SND_DJM_WINDEX_PB), |
| 4126 |
SND_DJM_CTL("Output 2 Playback Switch", 750mk2_pb2, 1, SND_DJM_WINDEX_PB), |
| 4127 |
SND_DJM_CTL("Output 3 Playback Switch", 750mk2_pb3, 2, SND_DJM_WINDEX_PB) |
| 4128 |
}; |
| 4129 |
|
| 4130 |
// DJM-A9 |
| 4131 |
static const u16 snd_djm_opts_a9_cap_level[] = { |
| 4132 |
0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500 }; |
| 4133 |
static const u16 snd_djm_opts_a9_cap1[] = { |
| 4134 |
0x0107, 0x0108, 0x0109, 0x010a, 0x010e, |
| 4135 |
0x111, 0x112, 0x113, 0x114, 0x0131, 0x132, 0x133, 0x134 }; |
| 4136 |
static const u16 snd_djm_opts_a9_cap2[] = { |
| 4137 |
0x0201, 0x0202, 0x0203, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, 0x020a, 0x020e }; |
| 4138 |
static const u16 snd_djm_opts_a9_cap3[] = { |
| 4139 |
0x0301, 0x0302, 0x0303, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a, 0x030e }; |
| 4140 |
static const u16 snd_djm_opts_a9_cap4[] = { |
| 4141 |
0x0401, 0x0402, 0x0403, 0x0405, 0x0406, 0x0407, 0x0408, 0x0409, 0x040a, 0x040e }; |
| 4142 |
static const u16 snd_djm_opts_a9_cap5[] = { |
| 4143 |
0x0501, 0x0502, 0x0503, 0x0505, 0x0506, 0x0507, 0x0508, 0x0509, 0x050a, 0x050e }; |
| 4144 |
|
| 4145 |
static const struct snd_djm_ctl snd_djm_ctls_a9[] = { |
| 4146 |
SND_DJM_CTL("Master Input Level Capture Switch", a9_cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4147 |
SND_DJM_CTL("Master Input Capture Switch", a9_cap1, 3, SND_DJM_WINDEX_CAP), |
| 4148 |
SND_DJM_CTL("Input 1 Capture Switch", a9_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4149 |
SND_DJM_CTL("Input 2 Capture Switch", a9_cap3, 2, SND_DJM_WINDEX_CAP), |
| 4150 |
SND_DJM_CTL("Input 3 Capture Switch", a9_cap4, 2, SND_DJM_WINDEX_CAP), |
| 4151 |
SND_DJM_CTL("Input 4 Capture Switch", a9_cap5, 2, SND_DJM_WINDEX_CAP) |
| 4152 |
}; |
| 4153 |
|
| 4154 |
// DJM-V10 |
| 4155 |
static const u16 snd_djm_opts_v10_cap_level[] = { |
| 4156 |
0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500 |
| 4157 |
}; |
| 4158 |
|
| 4159 |
static const u16 snd_djm_opts_v10_cap1[] = { |
| 4160 |
0x0103, |
| 4161 |
0x0100, 0x0102, 0x0106, 0x0110, 0x0107, |
| 4162 |
0x0108, 0x0109, 0x010a, 0x0121, 0x0122 |
| 4163 |
}; |
| 4164 |
|
| 4165 |
static const u16 snd_djm_opts_v10_cap2[] = { |
| 4166 |
0x0200, 0x0202, 0x0206, 0x0210, 0x0207, |
| 4167 |
0x0208, 0x0209, 0x020a, 0x0221, 0x0222 |
| 4168 |
}; |
| 4169 |
|
| 4170 |
static const u16 snd_djm_opts_v10_cap3[] = { |
| 4171 |
0x0303, |
| 4172 |
0x0300, 0x0302, 0x0306, 0x0310, 0x0307, |
| 4173 |
0x0308, 0x0309, 0x030a, 0x0321, 0x0322 |
| 4174 |
}; |
| 4175 |
|
| 4176 |
static const u16 snd_djm_opts_v10_cap4[] = { |
| 4177 |
0x0403, |
| 4178 |
0x0400, 0x0402, 0x0406, 0x0410, 0x0407, |
| 4179 |
0x0408, 0x0409, 0x040a, 0x0421, 0x0422 |
| 4180 |
}; |
| 4181 |
|
| 4182 |
static const u16 snd_djm_opts_v10_cap5[] = { |
| 4183 |
0x0500, 0x0502, 0x0506, 0x0510, 0x0507, |
| 4184 |
0x0508, 0x0509, 0x050a, 0x0521, 0x0522 |
| 4185 |
}; |
| 4186 |
|
| 4187 |
static const u16 snd_djm_opts_v10_cap6[] = { |
| 4188 |
0x0603, |
| 4189 |
0x0600, 0x0602, 0x0606, 0x0610, 0x0607, |
| 4190 |
0x0608, 0x0609, 0x060a, 0x0621, 0x0622 |
| 4191 |
}; |
| 4192 |
|
| 4193 |
static const struct snd_djm_ctl snd_djm_ctls_v10[] = { |
| 4194 |
SND_DJM_CTL("Master Input Level Capture Switch", v10_cap_level, 0, SND_DJM_WINDEX_CAPLVL), |
| 4195 |
SND_DJM_CTL("Input 1 Capture Switch", v10_cap1, 2, SND_DJM_WINDEX_CAP), |
| 4196 |
SND_DJM_CTL("Input 2 Capture Switch", v10_cap2, 2, SND_DJM_WINDEX_CAP), |
| 4197 |
SND_DJM_CTL("Input 3 Capture Switch", v10_cap3, 0, SND_DJM_WINDEX_CAP), |
| 4198 |
SND_DJM_CTL("Input 4 Capture Switch", v10_cap4, 0, SND_DJM_WINDEX_CAP), |
| 4199 |
SND_DJM_CTL("Input 5 Capture Switch", v10_cap5, 0, SND_DJM_WINDEX_CAP), |
| 4200 |
SND_DJM_CTL("Input 6 Capture Switch", v10_cap6, 0, SND_DJM_WINDEX_CAP) |
| 4201 |
// playback channels are fixed and controlled by hardware knobs on the mixer |
| 4202 |
}; |
| 4203 |
|
| 4204 |
static const struct snd_djm_device snd_djm_devices[] = { |
| 4205 |
[SND_DJM_250MK2_IDX] = SND_DJM_DEVICE(250mk2), |
| 4206 |
[SND_DJM_750_IDX] = SND_DJM_DEVICE(750), |
| 4207 |
[SND_DJM_850_IDX] = SND_DJM_DEVICE(850), |
| 4208 |
[SND_DJM_900NXS2_IDX] = SND_DJM_DEVICE(900nxs2), |
| 4209 |
[SND_DJM_750MK2_IDX] = SND_DJM_DEVICE(750mk2), |
| 4210 |
[SND_DJM_450_IDX] = SND_DJM_DEVICE(450), |
| 4211 |
[SND_DJM_A9_IDX] = SND_DJM_DEVICE(a9), |
| 4212 |
[SND_DJM_V10_IDX] = SND_DJM_DEVICE(v10), |
| 4213 |
}; |
| 4214 |
|
| 4215 |
static int snd_djm_controls_info(struct snd_kcontrol *kctl, |
| 4216 |
struct snd_ctl_elem_info *info) |
| 4217 |
{ |
| 4218 |
unsigned long private_value = kctl->private_value; |
| 4219 |
u8 device_idx = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; |
| 4220 |
u8 ctl_idx = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; |
| 4221 |
const struct snd_djm_device *device = &snd_djm_devices[device_idx]; |
| 4222 |
const char *name; |
| 4223 |
const struct snd_djm_ctl *ctl; |
| 4224 |
size_t noptions; |
| 4225 |
|
| 4226 |
if (ctl_idx >= device->ncontrols) |
| 4227 |
return -EINVAL; |
| 4228 |
|
| 4229 |
ctl = &device->controls[ctl_idx]; |
| 4230 |
noptions = ctl->noptions; |
| 4231 |
if (info->value.enumerated.item >= noptions) |
| 4232 |
info->value.enumerated.item = noptions - 1; |
| 4233 |
|
| 4234 |
name = snd_djm_get_label(device_idx, |
| 4235 |
ctl->options[info->value.enumerated.item], |
| 4236 |
ctl->wIndex); |
| 4237 |
if (!name) |
| 4238 |
return -EINVAL; |
| 4239 |
|
| 4240 |
strscpy(info->value.enumerated.name, name, sizeof(info->value.enumerated.name)); |
| 4241 |
info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4242 |
info->count = 1; |
| 4243 |
info->value.enumerated.items = noptions; |
| 4244 |
return 0; |
| 4245 |
} |
| 4246 |
|
| 4247 |
static int snd_djm_controls_update(struct usb_mixer_interface *mixer, |
| 4248 |
u8 device_idx, u8 group, u16 value) |
| 4249 |
{ |
| 4250 |
const struct snd_djm_device *device = &snd_djm_devices[device_idx]; |
| 4251 |
|
| 4252 |
if (group >= device->ncontrols || value >= device->controls[group].noptions) |
| 4253 |
return -EINVAL; |
| 4254 |
|
| 4255 |
CLASS(snd_usb_lock, pm)(mixer->chip); |
| 4256 |
if (pm.err) |
| 4257 |
return pm.err; |
| 4258 |
|
| 4259 |
return snd_usb_ctl_msg(mixer->chip->dev, |
| 4260 |
usb_sndctrlpipe(mixer->chip->dev, 0), |
| 4261 |
USB_REQ_SET_FEATURE, |
| 4262 |
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 4263 |
device->controls[group].options[value], |
| 4264 |
device->controls[group].wIndex, |
| 4265 |
NULL, 0); |
| 4266 |
} |
| 4267 |
|
| 4268 |
static int snd_djm_controls_get(struct snd_kcontrol *kctl, |
| 4269 |
struct snd_ctl_elem_value *elem) |
| 4270 |
{ |
| 4271 |
elem->value.enumerated.item[0] = kctl->private_value & SND_DJM_VALUE_MASK; |
| 4272 |
return 0; |
| 4273 |
} |
| 4274 |
|
| 4275 |
static int snd_djm_controls_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *elem) |
| 4276 |
{ |
| 4277 |
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kctl); |
| 4278 |
struct usb_mixer_interface *mixer = list->mixer; |
| 4279 |
unsigned long private_value = kctl->private_value; |
| 4280 |
|
| 4281 |
u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; |
| 4282 |
u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; |
| 4283 |
u16 value = elem->value.enumerated.item[0]; |
| 4284 |
|
| 4285 |
kctl->private_value = (((unsigned long)device << SND_DJM_DEVICE_SHIFT) | |
| 4286 |
(group << SND_DJM_GROUP_SHIFT) | |
| 4287 |
value); |
| 4288 |
|
| 4289 |
return snd_djm_controls_update(mixer, device, group, value); |
| 4290 |
} |
| 4291 |
|
| 4292 |
static int snd_djm_controls_resume(struct usb_mixer_elem_list *list) |
| 4293 |
{ |
| 4294 |
unsigned long private_value = list->kctl->private_value; |
| 4295 |
u8 device = (private_value & SND_DJM_DEVICE_MASK) >> SND_DJM_DEVICE_SHIFT; |
| 4296 |
u8 group = (private_value & SND_DJM_GROUP_MASK) >> SND_DJM_GROUP_SHIFT; |
| 4297 |
u16 value = (private_value & SND_DJM_VALUE_MASK); |
| 4298 |
|
| 4299 |
return snd_djm_controls_update(list->mixer, device, group, value); |
| 4300 |
} |
| 4301 |
|
| 4302 |
static int snd_djm_controls_create(struct usb_mixer_interface *mixer, |
| 4303 |
const u8 device_idx) |
| 4304 |
{ |
| 4305 |
int err, i; |
| 4306 |
u16 value; |
| 4307 |
|
| 4308 |
const struct snd_djm_device *device = &snd_djm_devices[device_idx]; |
| 4309 |
|
| 4310 |
struct snd_kcontrol_new knew = { |
| 4311 |
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 4312 |
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 4313 |
.index = 0, |
| 4314 |
.info = snd_djm_controls_info, |
| 4315 |
.get = snd_djm_controls_get, |
| 4316 |
.put = snd_djm_controls_put |
| 4317 |
}; |
| 4318 |
|
| 4319 |
for (i = 0; i < device->ncontrols; i++) { |
| 4320 |
value = device->controls[i].default_value; |
| 4321 |
knew.name = device->controls[i].name; |
| 4322 |
knew.private_value = |
| 4323 |
((unsigned long)device_idx << SND_DJM_DEVICE_SHIFT) | |
| 4324 |
(i << SND_DJM_GROUP_SHIFT) | |
| 4325 |
value; |
| 4326 |
err = snd_djm_controls_update(mixer, device_idx, i, value); |
| 4327 |
if (err) |
| 4328 |
return err; |
| 4329 |
err = add_single_ctl_with_resume(mixer, 0, snd_djm_controls_resume, |
| 4330 |
&knew, NULL); |
| 4331 |
if (err) |
| 4332 |
return err; |
| 4333 |
} |
| 4334 |
return 0; |
| 4335 |
} |
| 4336 |
|
| 4337 |
int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) |
| 4338 |
{ |
| 4339 |
int err = 0; |
| 4340 |
|
| 4341 |
err = snd_usb_soundblaster_remote_init(mixer); |
| 4342 |
if (err < 0) |
| 4343 |
return err; |
| 4344 |
|
| 4345 |
switch (mixer->chip->usb_id) { |
| 4346 |
/* Tascam US-16x08 */ |
| 4347 |
case USB_ID(0x0644, 0x8047): |
| 4348 |
err = snd_us16x08_controls_create(mixer); |
| 4349 |
break; |
| 4350 |
case USB_ID(0x041e, 0x3020): |
| 4351 |
case USB_ID(0x041e, 0x3040): |
| 4352 |
case USB_ID(0x041e, 0x3042): |
| 4353 |
case USB_ID(0x041e, 0x30df): |
| 4354 |
case USB_ID(0x041e, 0x3048): |
| 4355 |
err = snd_audigy2nx_controls_create(mixer); |
| 4356 |
if (err < 0) |
| 4357 |
break; |
| 4358 |
snd_card_ro_proc_new(mixer->chip->card, "audigy2nx", |
| 4359 |
mixer, snd_audigy2nx_proc_read); |
| 4360 |
break; |
| 4361 |
|
| 4362 |
/* EMU0204 */ |
| 4363 |
case USB_ID(0x041e, 0x3f19): |
| 4364 |
err = snd_emu0204_controls_create(mixer); |
| 4365 |
break; |
| 4366 |
|
| 4367 |
#if IS_REACHABLE(CONFIG_INPUT) |
| 4368 |
case USB_ID(0x054c, 0x0ce6): /* Sony DualSense controller (PS5) */ |
| 4369 |
case USB_ID(0x054c, 0x0df2): /* Sony DualSense Edge controller (PS5) */ |
| 4370 |
err = snd_dualsense_controls_create(mixer); |
| 4371 |
break; |
| 4372 |
#endif /* IS_REACHABLE(CONFIG_INPUT) */ |
| 4373 |
|
| 4374 |
case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */ |
| 4375 |
case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C400 */ |
| 4376 |
err = snd_c400_create_mixer(mixer); |
| 4377 |
break; |
| 4378 |
|
| 4379 |
case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra */ |
| 4380 |
case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */ |
| 4381 |
err = snd_ftu_create_mixer(mixer); |
| 4382 |
break; |
| 4383 |
|
| 4384 |
case USB_ID(0x0b05, 0x1739): /* ASUS Xonar U1 */ |
| 4385 |
case USB_ID(0x0b05, 0x1743): /* ASUS Xonar U1 (2) */ |
| 4386 |
case USB_ID(0x0b05, 0x17a0): /* ASUS Xonar U3 */ |
| 4387 |
err = snd_xonar_u1_controls_create(mixer); |
| 4388 |
break; |
| 4389 |
|
| 4390 |
case USB_ID(0x0d8c, 0x0103): /* Audio Advantage Micro II */ |
| 4391 |
err = snd_microii_controls_create(mixer); |
| 4392 |
break; |
| 4393 |
|
| 4394 |
case USB_ID(0x0dba, 0x1000): /* Digidesign Mbox 1 */ |
| 4395 |
err = snd_mbox1_controls_create(mixer); |
| 4396 |
break; |
| 4397 |
|
| 4398 |
case USB_ID(0x17cc, 0x1011): /* Traktor Audio 6 */ |
| 4399 |
err = snd_nativeinstruments_create_mixer(/* checkpatch hack */ |
| 4400 |
mixer, |
| 4401 |
snd_nativeinstruments_ta6_mixers, |
| 4402 |
ARRAY_SIZE(snd_nativeinstruments_ta6_mixers)); |
| 4403 |
break; |
| 4404 |
|
| 4405 |
case USB_ID(0x17cc, 0x1021): /* Traktor Audio 10 */ |
| 4406 |
err = snd_nativeinstruments_create_mixer(/* checkpatch hack */ |
| 4407 |
mixer, |
| 4408 |
snd_nativeinstruments_ta10_mixers, |
| 4409 |
ARRAY_SIZE(snd_nativeinstruments_ta10_mixers)); |
| 4410 |
break; |
| 4411 |
|
| 4412 |
case USB_ID(0x200c, 0x1018): /* Electrix Ebox-44 */ |
| 4413 |
/* detection is disabled in mixer_maps.c */ |
| 4414 |
err = snd_create_std_mono_table(mixer, ebox44_table); |
| 4415 |
break; |
| 4416 |
|
| 4417 |
case USB_ID(0x1235, 0x8010): /* Focusrite Forte */ |
| 4418 |
err = snd_forte_controls_create(mixer); |
| 4419 |
break; |
| 4420 |
case USB_ID(0x1235, 0x8012): /* Focusrite Scarlett 6i6 */ |
| 4421 |
case USB_ID(0x1235, 0x8002): /* Focusrite Scarlett 8i6 */ |
| 4422 |
case USB_ID(0x1235, 0x8004): /* Focusrite Scarlett 18i6 */ |
| 4423 |
case USB_ID(0x1235, 0x8014): /* Focusrite Scarlett 18i8 */ |
| 4424 |
case USB_ID(0x1235, 0x800c): /* Focusrite Scarlett 18i20 */ |
| 4425 |
err = snd_scarlett_controls_create(mixer); |
| 4426 |
break; |
| 4427 |
|
| 4428 |
case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */ |
| 4429 |
case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */ |
| 4430 |
case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */ |
| 4431 |
case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */ |
| 4432 |
case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */ |
| 4433 |
case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */ |
| 4434 |
case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */ |
| 4435 |
case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */ |
| 4436 |
case USB_ID(0x1235, 0x8215): /* Focusrite Scarlett 18i20 3rd Gen */ |
| 4437 |
case USB_ID(0x1235, 0x8216): /* Focusrite Vocaster One */ |
| 4438 |
case USB_ID(0x1235, 0x8217): /* Focusrite Vocaster Two */ |
| 4439 |
case USB_ID(0x1235, 0x8218): /* Focusrite Scarlett Solo 4th Gen */ |
| 4440 |
case USB_ID(0x1235, 0x8219): /* Focusrite Scarlett 2i2 4th Gen */ |
| 4441 |
case USB_ID(0x1235, 0x821a): /* Focusrite Scarlett 4i4 4th Gen */ |
| 4442 |
case USB_ID(0x1235, 0x8206): /* Focusrite Clarett 2Pre USB */ |
| 4443 |
case USB_ID(0x1235, 0x8207): /* Focusrite Clarett 4Pre USB */ |
| 4444 |
case USB_ID(0x1235, 0x8208): /* Focusrite Clarett 8Pre USB */ |
| 4445 |
case USB_ID(0x1235, 0x820a): /* Focusrite Clarett+ 2Pre */ |
| 4446 |
case USB_ID(0x1235, 0x820b): /* Focusrite Clarett+ 4Pre */ |
| 4447 |
case USB_ID(0x1235, 0x820c): /* Focusrite Clarett+ 8Pre */ |
| 4448 |
err = snd_scarlett2_init(mixer); |
| 4449 |
break; |
| 4450 |
|
| 4451 |
case USB_ID(0x1235, 0x821b): /* Focusrite Scarlett 16i16 4th Gen */ |
| 4452 |
case USB_ID(0x1235, 0x821c): /* Focusrite Scarlett 18i16 4th Gen */ |
| 4453 |
case USB_ID(0x1235, 0x821d): /* Focusrite Scarlett 18i20 4th Gen */ |
| 4454 |
err = snd_fcp_init(mixer); |
| 4455 |
break; |
| 4456 |
|
| 4457 |
case USB_ID(0x041e, 0x323b): /* Creative Sound Blaster E1 */ |
| 4458 |
err = snd_soundblaster_e1_switch_create(mixer); |
| 4459 |
break; |
| 4460 |
case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ |
| 4461 |
err = dell_dock_mixer_create(mixer); |
| 4462 |
if (err < 0) |
| 4463 |
break; |
| 4464 |
err = dell_dock_mixer_init(mixer); |
| 4465 |
break; |
| 4466 |
case USB_ID(0x0bda, 0x402e): /* Dell WD19 dock */ |
| 4467 |
err = dell_dock_mixer_create(mixer); |
| 4468 |
break; |
| 4469 |
|
| 4470 |
case USB_ID(0x2a39, 0x3fd2): /* RME ADI-2 Pro */ |
| 4471 |
case USB_ID(0x2a39, 0x3fd3): /* RME ADI-2 DAC */ |
| 4472 |
case USB_ID(0x2a39, 0x3fd4): /* RME */ |
| 4473 |
err = snd_rme_controls_create(mixer); |
| 4474 |
break; |
| 4475 |
|
| 4476 |
case USB_ID(0x194f, 0x010c): /* Presonus Studio 1810c */ |
| 4477 |
err = snd_sc1810_init_mixer(mixer); |
| 4478 |
break; |
| 4479 |
case USB_ID(0x194f, 0x010d): /* Presonus Studio 1824c */ |
| 4480 |
err = snd_sc1810_init_mixer(mixer); |
| 4481 |
break; |
| 4482 |
case USB_ID(0x2a39, 0x3fb0): /* RME Babyface Pro FS */ |
| 4483 |
err = snd_bbfpro_controls_create(mixer); |
| 4484 |
break; |
| 4485 |
case USB_ID(0x2a39, 0x3f8c): /* RME Digiface USB */ |
| 4486 |
case USB_ID(0x2a39, 0x3fa0): /* RME Digiface USB (alternate) */ |
| 4487 |
err = snd_rme_digiface_controls_create(mixer); |
| 4488 |
break; |
| 4489 |
case USB_ID(0x2b73, 0x0017): /* Pioneer DJ DJM-250MK2 */ |
| 4490 |
err = snd_djm_controls_create(mixer, SND_DJM_250MK2_IDX); |
| 4491 |
break; |
| 4492 |
case USB_ID(0x2b73, 0x0013): /* Pioneer DJ DJM-450 */ |
| 4493 |
err = snd_djm_controls_create(mixer, SND_DJM_450_IDX); |
| 4494 |
break; |
| 4495 |
case USB_ID(0x08e4, 0x017f): /* Pioneer DJ DJM-750 */ |
| 4496 |
err = snd_djm_controls_create(mixer, SND_DJM_750_IDX); |
| 4497 |
break; |
| 4498 |
case USB_ID(0x2b73, 0x001b): /* Pioneer DJ DJM-750MK2 */ |
| 4499 |
err = snd_djm_controls_create(mixer, SND_DJM_750MK2_IDX); |
| 4500 |
break; |
| 4501 |
case USB_ID(0x08e4, 0x0163): /* Pioneer DJ DJM-850 */ |
| 4502 |
err = snd_djm_controls_create(mixer, SND_DJM_850_IDX); |
| 4503 |
break; |
| 4504 |
case USB_ID(0x2b73, 0x000a): /* Pioneer DJ DJM-900NXS2 */ |
| 4505 |
err = snd_djm_controls_create(mixer, SND_DJM_900NXS2_IDX); |
| 4506 |
break; |
| 4507 |
case USB_ID(0x2b73, 0x003c): /* Pioneer DJ / AlphaTheta DJM-A9 */ |
| 4508 |
err = snd_djm_controls_create(mixer, SND_DJM_A9_IDX); |
| 4509 |
break; |
| 4510 |
case USB_ID(0x2b73, 0x0034): /* Pioneer DJ DJM-V10 */ |
| 4511 |
err = snd_djm_controls_create(mixer, SND_DJM_V10_IDX); |
| 4512 |
break; |
| 4513 |
case USB_ID(0x03f0, 0x0269): /* HP TB Dock G2 */ |
| 4514 |
err = hp_dock_mixer_create(mixer); |
| 4515 |
break; |
| 4516 |
} |
| 4517 |
|
| 4518 |
return err; |
| 4519 |
} |
| 4520 |
|
| 4521 |
void snd_usb_mixer_resume_quirk(struct usb_mixer_interface *mixer) |
| 4522 |
{ |
| 4523 |
switch (mixer->chip->usb_id) { |
| 4524 |
case USB_ID(0x0bda, 0x4014): /* Dell WD15 dock */ |
| 4525 |
dell_dock_mixer_init(mixer); |
| 4526 |
break; |
| 4527 |
} |
| 4528 |
} |
| 4529 |
|
| 4530 |
void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer, |
| 4531 |
int unitid) |
| 4532 |
{ |
| 4533 |
if (!mixer->rc_cfg) |
| 4534 |
return; |
| 4535 |
/* unit ids specific to Extigy/Audigy 2 NX: */ |
| 4536 |
switch (unitid) { |
| 4537 |
case 0: /* remote control */ |
| 4538 |
mixer->rc_urb->dev = mixer->chip->dev; |
| 4539 |
usb_submit_urb(mixer->rc_urb, GFP_ATOMIC); |
| 4540 |
break; |
| 4541 |
case 4: /* digital in jack */ |
| 4542 |
case 7: /* line in jacks */ |
| 4543 |
case 19: /* speaker out jacks */ |
| 4544 |
case 20: /* headphones out jack */ |
| 4545 |
break; |
| 4546 |
/* live24ext: 4 = line-in jack */ |
| 4547 |
case 3: /* hp-out jack (may actuate Mute) */ |
| 4548 |
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) || |
| 4549 |
mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) |
| 4550 |
snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); |
| 4551 |
break; |
| 4552 |
default: |
| 4553 |
usb_audio_dbg(mixer->chip, "memory change in unknown unit %d\n", unitid); |
| 4554 |
break; |
| 4555 |
} |
| 4556 |
} |
| 4557 |
|
| 4558 |
static void snd_dragonfly_quirk_db_scale(struct usb_mixer_interface *mixer, |
| 4559 |
struct usb_mixer_elem_info *cval, |
| 4560 |
struct snd_kcontrol *kctl) |
| 4561 |
{ |
| 4562 |
/* Approximation using 10 ranges based on output measurement on hw v1.2. |
| 4563 |
* This seems close to the cubic mapping e.g. alsamixer uses. |
| 4564 |
*/ |
| 4565 |
static const DECLARE_TLV_DB_RANGE(scale, |
| 4566 |
0, 1, TLV_DB_MINMAX_ITEM(-5300, -4970), |
| 4567 |
2, 5, TLV_DB_MINMAX_ITEM(-4710, -4160), |
| 4568 |
6, 7, TLV_DB_MINMAX_ITEM(-3884, -3710), |
| 4569 |
8, 14, TLV_DB_MINMAX_ITEM(-3443, -2560), |
| 4570 |
15, 16, TLV_DB_MINMAX_ITEM(-2475, -2324), |
| 4571 |
17, 19, TLV_DB_MINMAX_ITEM(-2228, -2031), |
| 4572 |
20, 26, TLV_DB_MINMAX_ITEM(-1910, -1393), |
| 4573 |
27, 31, TLV_DB_MINMAX_ITEM(-1322, -1032), |
| 4574 |
32, 40, TLV_DB_MINMAX_ITEM(-968, -490), |
| 4575 |
41, 50, TLV_DB_MINMAX_ITEM(-441, 0), |
| 4576 |
); |
| 4577 |
|
| 4578 |
if (cval->min == 0 && cval->max == 50) { |
| 4579 |
usb_audio_info(mixer->chip, "applying DragonFly dB scale quirk (0-50 variant)\n"); |
| 4580 |
kctl->tlv.p = scale; |
| 4581 |
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 4582 |
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
| 4583 |
|
| 4584 |
} else if (cval->min == 0 && cval->max <= 1000) { |
| 4585 |
/* Some other clearly broken DragonFly variant. |
| 4586 |
* At least a 0..53 variant (hw v1.0) exists. |
| 4587 |
*/ |
| 4588 |
usb_audio_info(mixer->chip, "ignoring too narrow dB range on a DragonFly device"); |
| 4589 |
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; |
| 4590 |
} |
| 4591 |
} |
| 4592 |
|
| 4593 |
/* |
| 4594 |
* Some Plantronics headsets have control names that don't meet ALSA naming |
| 4595 |
* standards. This function fixes nonstandard source names. By the time |
| 4596 |
* this function is called the control name should look like one of these: |
| 4597 |
* "source names Playback Volume" |
| 4598 |
* "source names Playback Switch" |
| 4599 |
* "source names Capture Volume" |
| 4600 |
* "source names Capture Switch" |
| 4601 |
* If any of the trigger words are found in the name then the name will |
| 4602 |
* be changed to: |
| 4603 |
* "Headset Playback Volume" |
| 4604 |
* "Headset Playback Switch" |
| 4605 |
* "Headset Capture Volume" |
| 4606 |
* "Headset Capture Switch" |
| 4607 |
* depending on the current suffix. |
| 4608 |
*/ |
| 4609 |
static void snd_fix_plt_name(struct snd_usb_audio *chip, |
| 4610 |
struct snd_ctl_elem_id *id) |
| 4611 |
{ |
| 4612 |
/* no variant of "Sidetone" should be added to this list */ |
| 4613 |
static const char * const trigger[] = { |
| 4614 |
"Earphone", "Microphone", "Receive", "Transmit" |
| 4615 |
}; |
| 4616 |
static const char * const suffix[] = { |
| 4617 |
" Playback Volume", " Playback Switch", |
| 4618 |
" Capture Volume", " Capture Switch" |
| 4619 |
}; |
| 4620 |
int i; |
| 4621 |
|
| 4622 |
for (i = 0; i < ARRAY_SIZE(trigger); i++) |
| 4623 |
if (strstr(id->name, trigger[i])) |
| 4624 |
goto triggered; |
| 4625 |
usb_audio_dbg(chip, "no change in %s\n", id->name); |
| 4626 |
return; |
| 4627 |
|
| 4628 |
triggered: |
| 4629 |
for (i = 0; i < ARRAY_SIZE(suffix); i++) |
| 4630 |
if (strstr(id->name, suffix[i])) { |
| 4631 |
usb_audio_dbg(chip, "fixing kctl name %s\n", id->name); |
| 4632 |
snprintf(id->name, sizeof(id->name), "Headset%s", |
| 4633 |
suffix[i]); |
| 4634 |
return; |
| 4635 |
} |
| 4636 |
usb_audio_dbg(chip, "something wrong in kctl name %s\n", id->name); |
| 4637 |
} |
| 4638 |
|
| 4639 |
void snd_usb_mixer_fu_apply_quirk(struct usb_mixer_interface *mixer, |
| 4640 |
struct usb_mixer_elem_info *cval, int unitid, |
| 4641 |
struct snd_kcontrol *kctl) |
| 4642 |
{ |
| 4643 |
switch (mixer->chip->usb_id) { |
| 4644 |
case USB_ID(0x21b4, 0x0081): /* AudioQuest DragonFly */ |
| 4645 |
if (unitid == 7 && cval->control == UAC_FU_VOLUME) |
| 4646 |
snd_dragonfly_quirk_db_scale(mixer, cval, kctl); |
| 4647 |
break; |
| 4648 |
} |
| 4649 |
|
| 4650 |
/* lowest playback value is muted on some devices */ |
| 4651 |
if (mixer->chip->quirk_flags & QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE) |
| 4652 |
if (strstr(kctl->id.name, "Playback")) { |
| 4653 |
usb_audio_info(mixer->chip, |
| 4654 |
"applying playback min mute quirk\n"); |
| 4655 |
cval->min_mute = 1; |
| 4656 |
} |
| 4657 |
|
| 4658 |
/* lowest capture value is muted on some devices */ |
| 4659 |
if (mixer->chip->quirk_flags & QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE) |
| 4660 |
if (strstr(kctl->id.name, "Capture")) { |
| 4661 |
usb_audio_info(mixer->chip, |
| 4662 |
"applying capture min mute quirk\n"); |
| 4663 |
cval->min_mute = 1; |
| 4664 |
} |
| 4665 |
/* ALSA-ify some Plantronics headset control names */ |
| 4666 |
if (USB_ID_VENDOR(mixer->chip->usb_id) == 0x047f && |
| 4667 |
(cval->control == UAC_FU_MUTE || cval->control == UAC_FU_VOLUME)) |
| 4668 |
snd_fix_plt_name(mixer->chip, &kctl->id); |
| 4669 |
} |