aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/usbmixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/usb/usbmixer.c')
-rw-r--r--sound/usb/usbmixer.c425
1 files changed, 11 insertions, 414 deletions
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index ab8f0f0b65be..ec2436e95321 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -43,60 +43,10 @@
43#include "usbaudio.h" 43#include "usbaudio.h"
44#include "usbmixer.h" 44#include "usbmixer.h"
45#include "helper.h" 45#include "helper.h"
46 46#include "mixer_quirks.h"
47/*
48 */
49
50/* ignore error from controls - for debugging */
51/* #define IGNORE_CTL_ERROR */
52
53/*
54 * Sound Blaster remote control configuration
55 *
56 * format of remote control data:
57 * Extigy: xx 00
58 * Audigy 2 NX: 06 80 xx 00 00 00
59 * Live! 24-bit: 06 80 xx yy 22 83
60 */
61static const struct rc_config {
62 u32 usb_id;
63 u8 offset;
64 u8 length;
65 u8 packet_length;
66 u8 min_packet_length; /* minimum accepted length of the URB result */
67 u8 mute_mixer_id;
68 u32 mute_code;
69} rc_configs[] = {
70 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
71 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
72 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
73 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
74};
75 47
76#define MAX_ID_ELEMS 256 48#define MAX_ID_ELEMS 256
77 49
78struct usb_mixer_interface {
79 struct snd_usb_audio *chip;
80 unsigned int ctrlif;
81 struct list_head list;
82 unsigned int ignore_ctl_error;
83 struct urb *urb;
84 /* array[MAX_ID_ELEMS], indexed by unit id */
85 struct usb_mixer_elem_info **id_elems;
86
87 /* Sound Blaster remote control stuff */
88 const struct rc_config *rc_cfg;
89 u32 rc_code;
90 wait_queue_head_t rc_waitq;
91 struct urb *rc_urb;
92 struct usb_ctrlrequest *rc_setup_packet;
93 u8 rc_buffer[6];
94
95 u8 audigy2nx_leds[3];
96 u8 xonar_u1_status;
97};
98
99
100struct usb_audio_term { 50struct usb_audio_term {
101 int id; 51 int id;
102 int type; 52 int type;
@@ -118,24 +68,6 @@ struct mixer_build {
118 const struct usbmix_selector_map *selector_map; 68 const struct usbmix_selector_map *selector_map;
119}; 69};
120 70
121#define MAX_CHANNELS 10 /* max logical channels */
122
123struct usb_mixer_elem_info {
124 struct usb_mixer_interface *mixer;
125 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
126 struct snd_ctl_elem_id *elem_id;
127 unsigned int id;
128 unsigned int control; /* CS or ICN (high byte) */
129 unsigned int cmask; /* channel mask bitmap: 0 = master */
130 int channels;
131 int val_type;
132 int min, max, res;
133 int dBmin, dBmax;
134 int cached;
135 int cache_val[MAX_CHANNELS];
136 u8 initialized;
137};
138
139enum { 71enum {
140 USB_MIXER_BOOLEAN, 72 USB_MIXER_BOOLEAN,
141 USB_MIXER_INV_BOOLEAN, 73 USB_MIXER_INV_BOOLEAN,
@@ -431,7 +363,8 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
431 * set a mixer value 363 * set a mixer value
432 */ 364 */
433 365
434static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set) 366int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
367 int request, int validx, int value_set)
435{ 368{
436 unsigned char buf[2]; 369 unsigned char buf[2];
437 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1; 370 int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
@@ -455,14 +388,14 @@ static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
455 388
456static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value) 389static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value)
457{ 390{
458 return set_ctl_value(cval, UAC_SET_CUR, validx, value); 391 return snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, validx, value);
459} 392}
460 393
461static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, 394static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
462 int index, int value) 395 int index, int value)
463{ 396{
464 int err; 397 int err;
465 err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel, 398 err = snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel,
466 value); 399 value);
467 if (err < 0) 400 if (err < 0)
468 return err; 401 return err;
@@ -751,7 +684,8 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
751 int last_valid_res = cval->res; 684 int last_valid_res = cval->res;
752 685
753 while (cval->res > 1) { 686 while (cval->res > 1) {
754 if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0) 687 if (snd_usb_mixer_set_ctl_value(cval, UAC_SET_RES,
688 (cval->control << 8) | minchn, cval->res / 2) < 0)
755 break; 689 break;
756 cval->res /= 2; 690 cval->res /= 2;
757 } 691 }
@@ -1808,8 +1742,7 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1808 return 0; 1742 return 0;
1809} 1743}
1810 1744
1811static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, 1745void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid)
1812 int unitid)
1813{ 1746{
1814 struct usb_mixer_elem_info *info; 1747 struct usb_mixer_elem_info *info;
1815 1748
@@ -1858,34 +1791,6 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
1858 } 1791 }
1859} 1792}
1860 1793
1861static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
1862 int unitid)
1863{
1864 if (!mixer->rc_cfg)
1865 return;
1866 /* unit ids specific to Extigy/Audigy 2 NX: */
1867 switch (unitid) {
1868 case 0: /* remote control */
1869 mixer->rc_urb->dev = mixer->chip->dev;
1870 usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
1871 break;
1872 case 4: /* digital in jack */
1873 case 7: /* line in jacks */
1874 case 19: /* speaker out jacks */
1875 case 20: /* headphones out jack */
1876 break;
1877 /* live24ext: 4 = line-in jack */
1878 case 3: /* hp-out jack (may actuate Mute) */
1879 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1880 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1881 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1882 break;
1883 default:
1884 snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
1885 break;
1886 }
1887}
1888
1889static void snd_usb_mixer_status_complete(struct urb *urb) 1794static void snd_usb_mixer_status_complete(struct urb *urb)
1890{ 1795{
1891 struct usb_mixer_interface *mixer = urb->context; 1796 struct usb_mixer_interface *mixer = urb->context;
@@ -1903,7 +1808,7 @@ static void snd_usb_mixer_status_complete(struct urb *urb)
1903 if (!(buf[0] & 0x40)) 1808 if (!(buf[0] & 0x40))
1904 snd_usb_mixer_notify_id(mixer, buf[1]); 1809 snd_usb_mixer_notify_id(mixer, buf[1]);
1905 else 1810 else
1906 snd_usb_mixer_memory_change(mixer, buf[1]); 1811 snd_usb_mixer_rc_memory_change(mixer, buf[1]);
1907 } 1812 }
1908 } 1813 }
1909 if (urb->status != -ENOENT && urb->status != -ECONNRESET) { 1814 if (urb->status != -ENOENT && urb->status != -ECONNRESET) {
@@ -1947,296 +1852,6 @@ static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
1947 return 0; 1852 return 0;
1948} 1853}
1949 1854
1950static void snd_usb_soundblaster_remote_complete(struct urb *urb)
1951{
1952 struct usb_mixer_interface *mixer = urb->context;
1953 const struct rc_config *rc = mixer->rc_cfg;
1954 u32 code;
1955
1956 if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
1957 return;
1958
1959 code = mixer->rc_buffer[rc->offset];
1960 if (rc->length == 2)
1961 code |= mixer->rc_buffer[rc->offset + 1] << 8;
1962
1963 /* the Mute button actually changes the mixer control */
1964 if (code == rc->mute_code)
1965 snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
1966 mixer->rc_code = code;
1967 wmb();
1968 wake_up(&mixer->rc_waitq);
1969}
1970
1971static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
1972 long count, loff_t *offset)
1973{
1974 struct usb_mixer_interface *mixer = hw->private_data;
1975 int err;
1976 u32 rc_code;
1977
1978 if (count != 1 && count != 4)
1979 return -EINVAL;
1980 err = wait_event_interruptible(mixer->rc_waitq,
1981 (rc_code = xchg(&mixer->rc_code, 0)) != 0);
1982 if (err == 0) {
1983 if (count == 1)
1984 err = put_user(rc_code, buf);
1985 else
1986 err = put_user(rc_code, (u32 __user *)buf);
1987 }
1988 return err < 0 ? err : count;
1989}
1990
1991static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
1992 poll_table *wait)
1993{
1994 struct usb_mixer_interface *mixer = hw->private_data;
1995
1996 poll_wait(file, &mixer->rc_waitq, wait);
1997 return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
1998}
1999
2000static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
2001{
2002 struct snd_hwdep *hwdep;
2003 int err, len, i;
2004
2005 for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
2006 if (rc_configs[i].usb_id == mixer->chip->usb_id)
2007 break;
2008 if (i >= ARRAY_SIZE(rc_configs))
2009 return 0;
2010 mixer->rc_cfg = &rc_configs[i];
2011
2012 len = mixer->rc_cfg->packet_length;
2013
2014 init_waitqueue_head(&mixer->rc_waitq);
2015 err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
2016 if (err < 0)
2017 return err;
2018 snprintf(hwdep->name, sizeof(hwdep->name),
2019 "%s remote control", mixer->chip->card->shortname);
2020 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
2021 hwdep->private_data = mixer;
2022 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
2023 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
2024 hwdep->exclusive = 1;
2025
2026 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
2027 if (!mixer->rc_urb)
2028 return -ENOMEM;
2029 mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
2030 if (!mixer->rc_setup_packet) {
2031 usb_free_urb(mixer->rc_urb);
2032 mixer->rc_urb = NULL;
2033 return -ENOMEM;
2034 }
2035 mixer->rc_setup_packet->bRequestType =
2036 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
2037 mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
2038 mixer->rc_setup_packet->wValue = cpu_to_le16(0);
2039 mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
2040 mixer->rc_setup_packet->wLength = cpu_to_le16(len);
2041 usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
2042 usb_rcvctrlpipe(mixer->chip->dev, 0),
2043 (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
2044 snd_usb_soundblaster_remote_complete, mixer);
2045 return 0;
2046}
2047
2048#define snd_audigy2nx_led_info snd_ctl_boolean_mono_info
2049
2050static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2051{
2052 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2053 int index = kcontrol->private_value;
2054
2055 ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
2056 return 0;
2057}
2058
2059static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2060{
2061 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2062 int index = kcontrol->private_value;
2063 int value = ucontrol->value.integer.value[0];
2064 int err, changed;
2065
2066 if (value > 1)
2067 return -EINVAL;
2068 changed = value != mixer->audigy2nx_leds[index];
2069 err = snd_usb_ctl_msg(mixer->chip->dev,
2070 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
2071 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2072 value, index + 2, NULL, 0, 100);
2073 if (err < 0)
2074 return err;
2075 mixer->audigy2nx_leds[index] = value;
2076 return changed;
2077}
2078
2079static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
2080 {
2081 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2082 .name = "CMSS LED Switch",
2083 .info = snd_audigy2nx_led_info,
2084 .get = snd_audigy2nx_led_get,
2085 .put = snd_audigy2nx_led_put,
2086 .private_value = 0,
2087 },
2088 {
2089 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2090 .name = "Power LED Switch",
2091 .info = snd_audigy2nx_led_info,
2092 .get = snd_audigy2nx_led_get,
2093 .put = snd_audigy2nx_led_put,
2094 .private_value = 1,
2095 },
2096 {
2097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2098 .name = "Dolby Digital LED Switch",
2099 .info = snd_audigy2nx_led_info,
2100 .get = snd_audigy2nx_led_get,
2101 .put = snd_audigy2nx_led_put,
2102 .private_value = 2,
2103 },
2104};
2105
2106static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
2107{
2108 int i, err;
2109
2110 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
2111 if (i > 1 && /* Live24ext has 2 LEDs only */
2112 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2113 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
2114 break;
2115 err = snd_ctl_add(mixer->chip->card,
2116 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
2117 if (err < 0)
2118 return err;
2119 }
2120 mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
2121 return 0;
2122}
2123
2124static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
2125 struct snd_info_buffer *buffer)
2126{
2127 static const struct sb_jack {
2128 int unitid;
2129 const char *name;
2130 } jacks_audigy2nx[] = {
2131 {4, "dig in "},
2132 {7, "line in"},
2133 {19, "spk out"},
2134 {20, "hph out"},
2135 {-1, NULL}
2136 }, jacks_live24ext[] = {
2137 {4, "line in"}, /* &1=Line, &2=Mic*/
2138 {3, "hph out"}, /* headphones */
2139 {0, "RC "}, /* last command, 6 bytes see rc_config above */
2140 {-1, NULL}
2141 };
2142 const struct sb_jack *jacks;
2143 struct usb_mixer_interface *mixer = entry->private_data;
2144 int i, err;
2145 u8 buf[3];
2146
2147 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
2148 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
2149 jacks = jacks_audigy2nx;
2150 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2151 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
2152 jacks = jacks_live24ext;
2153 else
2154 return;
2155
2156 for (i = 0; jacks[i].name; ++i) {
2157 snd_iprintf(buffer, "%s: ", jacks[i].name);
2158 err = snd_usb_ctl_msg(mixer->chip->dev,
2159 usb_rcvctrlpipe(mixer->chip->dev, 0),
2160 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
2161 USB_RECIP_INTERFACE, 0,
2162 jacks[i].unitid << 8, buf, 3, 100);
2163 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
2164 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
2165 else
2166 snd_iprintf(buffer, "?\n");
2167 }
2168}
2169
2170static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
2171 struct snd_ctl_elem_value *ucontrol)
2172{
2173 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2174
2175 ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
2176 return 0;
2177}
2178
2179static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
2180 struct snd_ctl_elem_value *ucontrol)
2181{
2182 struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
2183 u8 old_status, new_status;
2184 int err, changed;
2185
2186 old_status = mixer->xonar_u1_status;
2187 if (ucontrol->value.integer.value[0])
2188 new_status = old_status | 0x02;
2189 else
2190 new_status = old_status & ~0x02;
2191 changed = new_status != old_status;
2192 err = snd_usb_ctl_msg(mixer->chip->dev,
2193 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
2194 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
2195 50, 0, &new_status, 1, 100);
2196 if (err < 0)
2197 return err;
2198 mixer->xonar_u1_status = new_status;
2199 return changed;
2200}
2201
2202static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
2203 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2204 .name = "Digital Playback Switch",
2205 .info = snd_ctl_boolean_mono_info,
2206 .get = snd_xonar_u1_switch_get,
2207 .put = snd_xonar_u1_switch_put,
2208};
2209
2210static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
2211{
2212 int err;
2213
2214 err = snd_ctl_add(mixer->chip->card,
2215 snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
2216 if (err < 0)
2217 return err;
2218 mixer->xonar_u1_status = 0x05;
2219 return 0;
2220}
2221
2222void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
2223 unsigned char samplerate_id)
2224{
2225 struct usb_mixer_interface *mixer;
2226 struct usb_mixer_elem_info *cval;
2227 int unitid = 12; /* SamleRate ExtensionUnit ID */
2228
2229 list_for_each_entry(mixer, &chip->mixer_list, list) {
2230 cval = mixer->id_elems[unitid];
2231 if (cval) {
2232 set_cur_ctl_value(cval, cval->control << 8,
2233 samplerate_id);
2234 snd_usb_mixer_notify_id(mixer, unitid);
2235 }
2236 break;
2237 }
2238}
2239
2240int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif, 1855int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2241 int ignore_error) 1856 int ignore_error)
2242{ 1857{
@@ -2277,25 +1892,7 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2277 (err = snd_usb_mixer_status_create(mixer)) < 0) 1892 (err = snd_usb_mixer_status_create(mixer)) < 0)
2278 goto _error; 1893 goto _error;
2279 1894
2280 if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0) 1895 snd_usb_mixer_apply_create_quirk(mixer);
2281 goto _error;
2282
2283 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
2284 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2285 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
2286 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
2287 goto _error;
2288 if (!snd_card_proc_new(chip->card, "audigy2nx", &entry))
2289 snd_info_set_text_ops(entry, mixer,
2290 snd_audigy2nx_proc_read);
2291 }
2292
2293 if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) ||
2294 mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) {
2295 err = snd_xonar_u1_controls_create(mixer);
2296 if (err < 0)
2297 goto _error;
2298 }
2299 1896
2300 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops); 1897 err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
2301 if (err < 0) 1898 if (err < 0)
@@ -2316,7 +1913,7 @@ _error:
2316void snd_usb_mixer_disconnect(struct list_head *p) 1913void snd_usb_mixer_disconnect(struct list_head *p)
2317{ 1914{
2318 struct usb_mixer_interface *mixer; 1915 struct usb_mixer_interface *mixer;
2319 1916
2320 mixer = list_entry(p, struct usb_mixer_interface, list); 1917 mixer = list_entry(p, struct usb_mixer_interface, list);
2321 usb_kill_urb(mixer->urb); 1918 usb_kill_urb(mixer->urb);
2322 usb_kill_urb(mixer->rc_urb); 1919 usb_kill_urb(mixer->rc_urb);