diff options
Diffstat (limited to 'sound/usb')
-rw-r--r-- | sound/usb/bcd2000/Makefile | 2 | ||||
-rw-r--r-- | sound/usb/format.c | 46 | ||||
-rw-r--r-- | sound/usb/helper.c | 17 | ||||
-rw-r--r-- | sound/usb/helper.h | 1 | ||||
-rw-r--r-- | sound/usb/line6/driver.c | 11 | ||||
-rw-r--r-- | sound/usb/line6/driver.h | 9 | ||||
-rw-r--r-- | sound/usb/line6/pcm.c | 5 | ||||
-rw-r--r-- | sound/usb/line6/pod.c | 108 | ||||
-rw-r--r-- | sound/usb/line6/podhd.c | 80 | ||||
-rw-r--r-- | sound/usb/line6/toneport.c | 14 | ||||
-rw-r--r-- | sound/usb/line6/variax.c | 138 | ||||
-rw-r--r-- | sound/usb/mixer.c | 16 | ||||
-rw-r--r-- | sound/usb/mixer_quirks.c | 4 | ||||
-rw-r--r-- | sound/usb/quirks-table.h | 2 | ||||
-rw-r--r-- | sound/usb/quirks.c | 18 |
15 files changed, 189 insertions, 282 deletions
diff --git a/sound/usb/bcd2000/Makefile b/sound/usb/bcd2000/Makefile index 99546074e5f4..e2d916e24787 100644 --- a/sound/usb/bcd2000/Makefile +++ b/sound/usb/bcd2000/Makefile @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only snd-bcd2000-y := bcd2000.o -obj-$(CONFIG_SND_BCD2000) += snd-bcd2000.o
\ No newline at end of file +obj-$(CONFIG_SND_BCD2000) += snd-bcd2000.o diff --git a/sound/usb/format.c b/sound/usb/format.c index c02b51a82775..d79db71305f6 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -285,6 +285,33 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip, return nr_rates; } +/* Line6 Helix series don't support the UAC2_CS_RANGE usb function + * call. Return a static table of known clock rates. + */ +static int line6_parse_audio_format_rates_quirk(struct snd_usb_audio *chip, + struct audioformat *fp) +{ + switch (chip->usb_id) { + case USB_ID(0x0E41, 0x4241): /* Line6 Helix */ + case USB_ID(0x0E41, 0x4242): /* Line6 Helix Rack */ + case USB_ID(0x0E41, 0x4244): /* Line6 Helix LT */ + case USB_ID(0x0E41, 0x4246): /* Line6 HX-Stomp */ + /* supported rates: 48Khz */ + kfree(fp->rate_table); + fp->rate_table = kmalloc(sizeof(int), GFP_KERNEL); + if (!fp->rate_table) + return -ENOMEM; + fp->nr_rates = 1; + fp->rate_min = 48000; + fp->rate_max = 48000; + fp->rates = SNDRV_PCM_RATE_48000; + fp->rate_table[0] = 48000; + return 0; + } + + return -ENODEV; +} + /* * parse the format descriptor and stores the possible sample rates * on the audioformat table (audio class v2 and v3). @@ -294,7 +321,7 @@ static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip, { struct usb_device *dev = chip->dev; unsigned char tmp[2], *data; - int nr_triplets, data_size, ret = 0; + int nr_triplets, data_size, ret = 0, ret_l6; int clock = snd_usb_clock_find_source(chip, fp->protocol, fp->clock, false); @@ -313,9 +340,22 @@ static int parse_audio_format_rates_v2v3(struct snd_usb_audio *chip, tmp, sizeof(tmp)); if (ret < 0) { - dev_err(&dev->dev, - "%s(): unable to retrieve number of sample rates (clock %d)\n", + /* line6 helix devices don't support UAC2_CS_CONTROL_SAM_FREQ call */ + ret_l6 = line6_parse_audio_format_rates_quirk(chip, fp); + if (ret_l6 == -ENODEV) { + /* no line6 device found continue showing the error */ + dev_err(&dev->dev, + "%s(): unable to retrieve number of sample rates (clock %d)\n", + __func__, clock); + goto err; + } + if (ret_l6 == 0) { + dev_info(&dev->dev, + "%s(): unable to retrieve number of sample rates: set it to a predefined value (clock %d).\n", __func__, clock); + return 0; + } + ret = ret_l6; goto err; } diff --git a/sound/usb/helper.c b/sound/usb/helper.c index 84aa265dd802..71d5f540334a 100644 --- a/sound/usb/helper.c +++ b/sound/usb/helper.c @@ -63,6 +63,20 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype return NULL; } +/* check the validity of pipe and EP types */ +int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe) +{ + static const int pipetypes[4] = { + PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT + }; + struct usb_host_endpoint *ep; + + ep = usb_pipe_endpoint(dev, pipe); + if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) + return -EINVAL; + return 0; +} + /* * Wrapper for usb_control_msg(). * Allocates a temp buffer to prevent dmaing from/to the stack. @@ -75,6 +89,9 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, void *buf = NULL; int timeout; + if (snd_usb_pipe_sanity_check(dev, pipe)) + return -EINVAL; + if (size > 0) { buf = kmemdup(data, size, GFP_KERNEL); if (!buf) diff --git a/sound/usb/helper.h b/sound/usb/helper.h index d338bd0e0ca6..6afb70156ec4 100644 --- a/sound/usb/helper.h +++ b/sound/usb/helper.h @@ -7,6 +7,7 @@ unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size); void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype); void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype); +int snd_usb_pipe_sanity_check(struct usb_device *dev, unsigned int pipe); int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size); diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index e63a2451c88f..ab2ec896f49c 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c @@ -192,17 +192,6 @@ static int line6_send_raw_message_async_part(struct message *msg, } /* - Setup and start timer. -*/ -void line6_start_timer(struct timer_list *timer, unsigned long msecs, - void (*function)(struct timer_list *t)) -{ - timer->function = function; - mod_timer(timer, jiffies + msecs_to_jiffies(msecs)); -} -EXPORT_SYMBOL_GPL(line6_start_timer); - -/* Asynchronously send raw message. */ int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer, diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h index a9f7b4aa32c4..e5e572ed5f30 100644 --- a/sound/usb/line6/driver.h +++ b/sound/usb/line6/driver.h @@ -64,13 +64,6 @@ #define LINE6_CHANNEL_MASK 0x0f -#define CHECK_STARTUP_PROGRESS(x, n) \ -do { \ - if ((x) >= (n)) \ - return; \ - x = (n); \ -} while (0) - extern const unsigned char line6_midi_id[3]; static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3; @@ -197,8 +190,6 @@ extern int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer, int size); extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, const char *buf, size_t count); -extern void line6_start_timer(struct timer_list *timer, unsigned long msecs, - void (*function)(struct timer_list *t)); extern int line6_version_request_async(struct usb_line6 *line6); extern int line6_write_data(struct usb_line6 *line6, unsigned address, void *data, unsigned datalen); diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c index 21127e4958b2..2c03e0f6bf72 100644 --- a/sound/usb/line6/pcm.c +++ b/sound/usb/line6/pcm.c @@ -556,6 +556,11 @@ int line6_init_pcm(struct usb_line6 *line6, line6pcm->max_packet_size_out = usb_maxpacket(line6->usbdev, usb_sndisocpipe(line6->usbdev, ep_write), 1); + if (!line6pcm->max_packet_size_in || !line6pcm->max_packet_size_out) { + dev_err(line6pcm->line6->ifcdev, + "cannot get proper max packet size\n"); + return -EINVAL; + } spin_lock_init(&line6pcm->out.lock); spin_lock_init(&line6pcm->in.lock); diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c index 200ae53adf22..ee4c9d220fdf 100644 --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c @@ -35,11 +35,9 @@ Stages of POD startup procedure */ enum { - POD_STARTUP_INIT = 1, POD_STARTUP_VERSIONREQ, - POD_STARTUP_WORKQUEUE, POD_STARTUP_SETUP, - POD_STARTUP_LAST = POD_STARTUP_SETUP - 1 + POD_STARTUP_DONE, }; enum { @@ -59,12 +57,6 @@ struct usb_line6_pod { /* Instrument monitor level */ int monitor_level; - /* Timer for device initialization */ - struct timer_list startup_timer; - - /* Work handler for device initialization */ - struct work_struct startup_work; - /* Current progress in startup procedure */ int startup_progress; @@ -78,6 +70,8 @@ struct usb_line6_pod { int device_id; }; +#define line6_to_pod(x) container_of(x, struct usb_line6_pod, line6) + #define POD_SYSEX_CODE 3 /* *INDENT-OFF* */ @@ -169,10 +163,6 @@ static const char pod_version_header[] = { 0xf2, 0x7e, 0x7f, 0x06, 0x02 }; -/* forward declarations: */ -static void pod_startup2(struct timer_list *t); -static void pod_startup3(struct usb_line6_pod *pod); - static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, int size) { @@ -185,14 +175,17 @@ static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, */ static void line6_pod_process_message(struct usb_line6 *line6) { - struct usb_line6_pod *pod = (struct usb_line6_pod *) line6; + struct usb_line6_pod *pod = line6_to_pod(line6); const unsigned char *buf = pod->line6.buffer_message; if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) { pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15]; pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int) buf[10]; - pod_startup3(pod); + if (pod->startup_progress == POD_STARTUP_VERSIONREQ) { + pod->startup_progress = POD_STARTUP_SETUP; + schedule_delayed_work(&line6->startup_work, 0); + } return; } @@ -277,47 +270,27 @@ static ssize_t device_id_show(struct device *dev, context). After the last one has finished, the device is ready to use. */ -static void pod_startup1(struct usb_line6_pod *pod) -{ - CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT); - - /* delay startup procedure: */ - line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2); -} - -static void pod_startup2(struct timer_list *t) -{ - struct usb_line6_pod *pod = from_timer(pod, t, startup_timer); - struct usb_line6 *line6 = &pod->line6; - - CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ); - - /* request firmware version: */ - line6_version_request_async(line6); -} - -static void pod_startup3(struct usb_line6_pod *pod) -{ - CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_WORKQUEUE); - - /* schedule work for global work queue: */ - schedule_work(&pod->startup_work); -} - -static void pod_startup4(struct work_struct *work) +static void pod_startup(struct usb_line6 *line6) { - struct usb_line6_pod *pod = - container_of(work, struct usb_line6_pod, startup_work); - struct usb_line6 *line6 = &pod->line6; - - CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_SETUP); - - /* serial number: */ - line6_read_serial_number(&pod->line6, &pod->serial_number); - - /* ALSA audio interface: */ - if (snd_card_register(line6->card)) - dev_err(line6->ifcdev, "Failed to register POD card.\n"); + struct usb_line6_pod *pod = line6_to_pod(line6); + + switch (pod->startup_progress) { + case POD_STARTUP_VERSIONREQ: + /* request firmware version: */ + line6_version_request_async(line6); + break; + case POD_STARTUP_SETUP: + /* serial number: */ + line6_read_serial_number(&pod->line6, &pod->serial_number); + + /* ALSA audio interface: */ + if (snd_card_register(line6->card)) + dev_err(line6->ifcdev, "Failed to register POD card.\n"); + pod->startup_progress = POD_STARTUP_DONE; + break; + default: + break; + } } /* POD special files: */ @@ -353,7 +326,7 @@ static int snd_pod_control_monitor_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); - struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; + struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6); ucontrol->value.integer.value[0] = pod->monitor_level; return 0; @@ -364,7 +337,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); - struct usb_line6_pod *pod = (struct usb_line6_pod *)line6pcm->line6; + struct usb_line6_pod *pod = line6_to_pod(line6pcm->line6); if (ucontrol->value.integer.value[0] == pod->monitor_level) return 0; @@ -387,30 +360,16 @@ static const struct snd_kcontrol_new pod_control_monitor = { }; /* - POD device disconnected. -*/ -static void line6_pod_disconnect(struct usb_line6 *line6) -{ - struct usb_line6_pod *pod = (struct usb_line6_pod *)line6; - - del_timer_sync(&pod->startup_timer); - cancel_work_sync(&pod->startup_work); -} - -/* Try to init POD device. */ static int pod_init(struct usb_line6 *line6, const struct usb_device_id *id) { int err; - struct usb_line6_pod *pod = (struct usb_line6_pod *) line6; + struct usb_line6_pod *pod = line6_to_pod(line6); line6->process_message = line6_pod_process_message; - line6->disconnect = line6_pod_disconnect; - - timer_setup(&pod->startup_timer, NULL, 0); - INIT_WORK(&pod->startup_work, pod_startup4); + line6->startup = pod_startup; /* create sysfs entries: */ err = snd_card_add_dev_attr(line6->card, &pod_dev_attr_group); @@ -443,7 +402,8 @@ static int pod_init(struct usb_line6 *line6, pod->monitor_level = POD_SYSTEM_INVALID; /* initiate startup procedure: */ - pod_startup1(pod); + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(POD_STARTUP_DELAY)); } return 0; diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index 77a1d55334bb..f0662bd4e50f 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c @@ -18,16 +18,6 @@ #define PODHD_STARTUP_DELAY 500 -/* - * Stages of POD startup procedure - */ -enum { - PODHD_STARTUP_INIT = 1, - PODHD_STARTUP_SCHEDULE_WORKQUEUE, - PODHD_STARTUP_SETUP, - PODHD_STARTUP_LAST = PODHD_STARTUP_SETUP - 1 -}; - enum { LINE6_PODHD300, LINE6_PODHD400, @@ -43,15 +33,6 @@ struct usb_line6_podhd { /* Generic Line 6 USB data */ struct usb_line6 line6; - /* Timer for device initialization */ - struct timer_list startup_timer; - - /* Work handler for device initialization */ - struct work_struct startup_work; - - /* Current progress in startup procedure */ - int startup_progress; - /* Serial number of device */ u32 serial_number; @@ -59,6 +40,8 @@ struct usb_line6_podhd { int firmware_version; }; +#define line6_to_podhd(x) container_of(x, struct usb_line6_podhd, line6) + static struct snd_ratden podhd_ratden = { .num_min = 48000, .num_max = 48000, @@ -154,10 +137,6 @@ static struct line6_pcm_properties podx3_pcm_properties = { }; static struct usb_driver podhd_driver; -static void podhd_startup_start_workqueue(struct timer_list *t); -static void podhd_startup_workqueue(struct work_struct *work); -static int podhd_startup_finalize(struct usb_line6_podhd *pod); - static ssize_t serial_number_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -198,26 +177,6 @@ static const struct attribute_group podhd_dev_attr_group = { * audio nor bulk interfaces to work. */ -static void podhd_startup(struct usb_line6_podhd *pod) -{ - CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_INIT); - - /* delay startup procedure: */ - line6_start_timer(&pod->startup_timer, PODHD_STARTUP_DELAY, - podhd_startup_start_workqueue); -} - -static void podhd_startup_start_workqueue(struct timer_list *t) -{ - struct usb_line6_podhd *pod = from_timer(pod, t, startup_timer); - - CHECK_STARTUP_PROGRESS(pod->startup_progress, - PODHD_STARTUP_SCHEDULE_WORKQUEUE); - - /* schedule work for global work queue: */ - schedule_work(&pod->startup_work); -} - static int podhd_dev_start(struct usb_line6_podhd *pod) { int ret; @@ -268,37 +227,23 @@ exit: return ret; } -static void podhd_startup_workqueue(struct work_struct *work) +static void podhd_startup(struct usb_line6 *line6) { - struct usb_line6_podhd *pod = - container_of(work, struct usb_line6_podhd, startup_work); - - CHECK_STARTUP_PROGRESS(pod->startup_progress, PODHD_STARTUP_SETUP); + struct usb_line6_podhd *pod = line6_to_podhd(line6); podhd_dev_start(pod); line6_read_serial_number(&pod->line6, &pod->serial_number); - - podhd_startup_finalize(pod); -} - -static int podhd_startup_finalize(struct usb_line6_podhd *pod) -{ - struct usb_line6 *line6 = &pod->line6; - - /* ALSA audio interface: */ - return snd_card_register(line6->card); + if (snd_card_register(line6->card)) + dev_err(line6->ifcdev, "Failed to register POD HD card.\n"); } static void podhd_disconnect(struct usb_line6 *line6) { - struct usb_line6_podhd *pod = (struct usb_line6_podhd *)line6; + struct usb_line6_podhd *pod = line6_to_podhd(line6); if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO) { struct usb_interface *intf; - del_timer_sync(&pod->startup_timer); - cancel_work_sync(&pod->startup_work); - intf = usb_ifnum_to_if(line6->usbdev, pod->line6.properties->ctrl_if); if (intf) @@ -313,13 +258,11 @@ static int podhd_init(struct usb_line6 *line6, const struct usb_device_id *id) { int err; - struct usb_line6_podhd *pod = (struct usb_line6_podhd *) line6; + struct usb_line6_podhd *pod = line6_to_podhd(line6); struct usb_interface *intf; line6->disconnect = podhd_disconnect; - - timer_setup(&pod->startup_timer, NULL, 0); - INIT_WORK(&pod->startup_work, podhd_startup_workqueue); + line6->startup = podhd_startup; if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { /* claim the data interface */ @@ -358,11 +301,12 @@ static int podhd_init(struct usb_line6 *line6, if (!(pod->line6.properties->capabilities & LINE6_CAP_CONTROL_INFO)) { /* register USB audio system directly */ - return podhd_startup_finalize(pod); + return snd_card_register(line6->card); } /* init device and delay registering */ - podhd_startup(pod); + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(PODHD_STARTUP_DELAY)); return 0; } diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index 974ab3e62b68..d0a555dbe324 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c @@ -57,6 +57,8 @@ struct usb_line6_toneport { struct toneport_led leds[2]; }; +#define line6_to_toneport(x) container_of(x, struct usb_line6_toneport, line6) + static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2); #define TONEPORT_PCM_DELAY 1 @@ -207,8 +209,8 @@ static int snd_toneport_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); - struct usb_line6_toneport *toneport = - (struct usb_line6_toneport *)line6pcm->line6; + struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6); + ucontrol->value.enumerated.item[0] = toneport->source; return 0; } @@ -218,8 +220,7 @@ static int snd_toneport_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol); - struct usb_line6_toneport *toneport = - (struct usb_line6_toneport *)line6pcm->line6; + struct usb_line6_toneport *toneport = line6_to_toneport(line6pcm->line6); unsigned int source; source = ucontrol->value.enumerated.item[0]; @@ -393,8 +394,7 @@ static int toneport_setup(struct usb_line6_toneport *toneport) */ static void line6_toneport_disconnect(struct usb_line6 *line6) { - struct usb_line6_toneport *toneport = - (struct usb_line6_toneport *)line6; + struct usb_line6_toneport *toneport = line6_to_toneport(line6); if (toneport_has_led(toneport)) toneport_remove_leds(toneport); @@ -408,7 +408,7 @@ static int toneport_init(struct usb_line6 *line6, const struct usb_device_id *id) { int err; - struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6; + struct usb_line6_toneport *toneport = line6_to_toneport(line6); toneport->type = id->driver_info; diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c index e59b97444399..0d24c72c155f 100644 --- a/sound/usb/line6/variax.c +++ b/sound/usb/line6/variax.c @@ -22,13 +22,9 @@ Stages of Variax startup procedure */ enum { - VARIAX_STARTUP_INIT = 1, VARIAX_STARTUP_VERSIONREQ, - VARIAX_STARTUP_WAIT, VARIAX_STARTUP_ACTIVATE, - VARIAX_STARTUP_WORKQUEUE, VARIAX_STARTUP_SETUP, - VARIAX_STARTUP_LAST = VARIAX_STARTUP_SETUP - 1 }; enum { @@ -43,17 +39,12 @@ struct usb_line6_variax { /* Buffer for activation code */ unsigned char *buffer_activate; - /* Handler for device initialization */ - struct work_struct startup_work; - - /* Timers for device initialization */ - struct timer_list startup_timer1; - struct timer_list startup_timer2; - /* Current progress in startup procedure */ int startup_progress; }; +#define line6_to_variax(x) container_of(x, struct usb_line6_variax, line6) + #define VARIAX_OFFSET_ACTIVATE 7 /* @@ -77,11 +68,6 @@ static const char variax_activate[] = { 0xf7 }; -/* forward declarations: */ -static void variax_startup2(struct timer_list *t); -static void variax_startup4(struct timer_list *t); -static void variax_startup5(struct timer_list *t); - static void variax_activate_async(struct usb_line6_variax *variax, int a) { variax->buffer_activate[VARIAX_OFFSET_ACTIVATE] = a; @@ -96,74 +82,30 @@ static void variax_activate_async(struct usb_line6_variax *variax, int a) context). After the last one has finished, the device is ready to use. */ -static void variax_startup1(struct usb_line6_variax *variax) -{ - CHECK_STARTUP_PROGRESS(variax->startup_progress, VARIAX_STARTUP_INIT); - - /* delay startup procedure: */ - line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1, - variax_startup2); -} - -static void variax_startup2(struct timer_list *t) -{ - struct usb_line6_variax *variax = from_timer(variax, t, startup_timer1); - struct usb_line6 *line6 = &variax->line6; - - /* schedule another startup procedure until startup is complete: */ - if (variax->startup_progress >= VARIAX_STARTUP_LAST) - return; - - variax->startup_progress = VARIAX_STARTUP_VERSIONREQ; - line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1, - variax_startup2); - - /* request firmware version: */ - line6_version_request_async(line6); -} - -static void variax_startup3(struct usb_line6_variax *variax) -{ - CHECK_STARTUP_PROGRESS(variax->startup_progress, VARIAX_STARTUP_WAIT); - - /* delay startup procedure: */ - line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY3, - variax_startup4); -} - -static void variax_startup4(struct timer_list *t) +static void variax_startup(struct usb_line6 *line6) { - struct usb_line6_variax *variax = from_timer(variax, t, startup_timer2); - - CHECK_STARTUP_PROGRESS(variax->startup_progress, - VARIAX_STARTUP_ACTIVATE); - - /* activate device: */ - variax_activate_async(variax, 1); - line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY4, - variax_startup5); -} - -static void variax_startup5(struct timer_list *t) -{ - struct usb_line6_variax *variax = from_timer(variax, t, startup_timer2); - - CHECK_STARTUP_PROGRESS(variax->startup_progress, - VARIAX_STARTUP_WORKQUEUE); - - /* schedule work for global work queue: */ - schedule_work(&variax->startup_work); -} - -static void variax_startup6(struct work_struct *work) -{ - struct usb_line6_variax *variax = - container_of(work, struct usb_line6_variax, startup_work); - - CHECK_STARTUP_PROGRESS(variax->startup_progress, VARIAX_STARTUP_SETUP); - - /* ALSA audio interface: */ - snd_card_register(variax->line6.card); + struct usb_line6_variax *variax = line6_to_variax(line6); + + switch (variax->startup_progress) { + case VARIAX_STARTUP_VERSIONREQ: + /* repeat request until getting the response */ + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(VARIAX_STARTUP_DELAY1)); + /* request firmware version: */ + line6_version_request_async(line6); + break; + case VARIAX_STARTUP_ACTIVATE: + /* activate device: */ + variax_activate_async(variax, 1); + variax->startup_progress = VARIAX_STARTUP_SETUP; + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(VARIAX_STARTUP_DELAY4)); + break; + case VARIAX_STARTUP_SETUP: + /* ALSA audio interface: */ + snd_card_register(variax->line6.card); + break; + } } /* @@ -171,7 +113,7 @@ static void variax_startup6(struct work_struct *work) */ static void line6_variax_process_message(struct usb_line6 *line6) { - struct usb_line6_variax *variax = (struct usb_line6_variax *) line6; + struct usb_line6_variax *variax = line6_to_variax(line6); const unsigned char *buf = variax->line6.buffer_message; switch (buf[0]) { @@ -182,11 +124,19 @@ static void line6_variax_process_message(struct usb_line6 *line6) case LINE6_SYSEX_BEGIN: if (memcmp(buf + 1, variax_init_version + 1, sizeof(variax_init_version) - 1) == 0) { - variax_startup3(variax); + if (variax->startup_progress >= VARIAX_STARTUP_ACTIVATE) + break; + variax->startup_progress = VARIAX_STARTUP_ACTIVATE; + cancel_delayed_work(&line6->startup_work); + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(VARIAX_STARTUP_DELAY3)); } else if (memcmp(buf + 1, variax_init_done + 1, sizeof(variax_init_done) - 1) == 0) { /* notify of complete initialization: */ - variax_startup4(&variax->startup_timer2); + if (variax->startup_progress >= VARIAX_STARTUP_SETUP) + break; + cancel_delayed_work(&line6->startup_work); + schedule_delayed_work(&line6->startup_work, 0); } break; } @@ -197,11 +147,7 @@ static void line6_variax_process_message(struct usb_line6 *line6) */ static void line6_variax_disconnect(struct usb_line6 *line6) { - struct usb_line6_variax *variax = (struct usb_line6_variax *)line6; - - del_timer(&variax->startup_timer1); - del_timer(&variax->startup_timer2); - cancel_work_sync(&variax->startup_work); + struct usb_line6_variax *variax = line6_to_variax(line6); kfree(variax->buffer_activate); } @@ -212,15 +158,12 @@ static void line6_variax_disconnect(struct usb_line6 *line6) static int variax_init(struct usb_line6 *line6, const struct usb_device_id *id) { - struct usb_line6_variax *variax = (struct usb_line6_variax *) line6; + struct usb_line6_variax *variax = line6_to_variax(line6); int err; line6->process_message = line6_variax_process_message; line6->disconnect = line6_variax_disconnect; - - timer_setup(&variax->startup_timer1, NULL, 0); - timer_setup(&variax->startup_timer2, NULL, 0); - INIT_WORK(&variax->startup_work, variax_startup6); + line6->startup = variax_startup; /* initialize USB buffers: */ variax->buffer_activate = kmemdup(variax_activate, @@ -235,7 +178,8 @@ static int variax_init(struct usb_line6 *line6, return err; /* initiate startup procedure: */ - variax_startup1(variax); + schedule_delayed_work(&line6->startup_work, + msecs_to_jiffies(VARIAX_STARTUP_DELAY1)); return 0; } diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c index c703f8534b07..7498b5191b68 100644 --- a/sound/usb/mixer.c +++ b/sound/usb/mixer.c @@ -2303,7 +2303,7 @@ static struct procunit_info extunits[] = { */ static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw_desc, struct procunit_info *list, - char *name) + bool extension_unit) { struct uac_processing_unit_descriptor *desc = raw_desc; int num_ins; @@ -2320,6 +2320,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, static struct procunit_info default_info = { 0, NULL, default_value_info }; + const char *name = extension_unit ? + "Extension Unit" : "Processing Unit"; if (desc->bLength < 13) { usb_audio_err(state->chip, "invalid %s descriptor (id %d)\n", name, unitid); @@ -2433,7 +2435,10 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, } else if (info->name) { strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); } else { - nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol); + if (extension_unit) + nameid = uac_extension_unit_iExtension(desc, state->mixer->protocol); + else + nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol); len = 0; if (nameid) len = snd_usb_copy_string_desc(state->chip, @@ -2466,10 +2471,10 @@ static int parse_audio_processing_unit(struct mixer_build *state, int unitid, case UAC_VERSION_2: default: return build_audio_procunit(state, unitid, raw_desc, - procunits, "Processing Unit"); + procunits, false); case UAC_VERSION_3: return build_audio_procunit(state, unitid, raw_desc, - uac3_procunits, "Processing Unit"); + uac3_procunits, false); } } @@ -2480,8 +2485,7 @@ static int parse_audio_extension_unit(struct mixer_build *state, int unitid, * Note that we parse extension units with processing unit descriptors. * That's ok as the layout is the same. */ - return build_audio_procunit(state, unitid, raw_desc, - extunits, "Extension Unit"); + return build_audio_procunit(state, unitid, raw_desc, extunits, true); } /* diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c index 1f6011f36bb0..199fa157a411 100644 --- a/sound/usb/mixer_quirks.c +++ b/sound/usb/mixer_quirks.c @@ -741,7 +741,7 @@ static int snd_ni_control_init_val(struct usb_mixer_interface *mixer, return err; } - kctl->private_value |= (value << 24); + kctl->private_value |= ((unsigned int)value << 24); return 0; } @@ -902,7 +902,7 @@ static int snd_ftu_eff_switch_init(struct usb_mixer_interface *mixer, if (err < 0) return err; - kctl->private_value |= value[0] << 24; + kctl->private_value |= (unsigned int)value[0] << 24; return 0; } diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h index 9e049f60e80e..e918ce346027 100644 --- a/sound/usb/quirks-table.h +++ b/sound/usb/quirks-table.h @@ -2408,7 +2408,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), USB_DEVICE(0x086a, 0x0001), .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { .vendor_name = "Emagic", - /* .product_name = "Unitor8", */ + .product_name = "Unitor8", .ifnum = 2, .type = QUIRK_MIDI_EMAGIC, .data = & (const struct snd_usb_midi_endpoint_info) { diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index cf5cff10c08e..78858918cbc1 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c @@ -828,11 +828,13 @@ static int snd_usb_novation_boot_quirk(struct usb_device *dev) static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) { int err, actual_length; - /* "midi send" enable */ static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 }; + void *buf; - void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); + if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x05))) + return -EINVAL; + buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL); if (!buf) return -ENOMEM; err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf, @@ -857,7 +859,11 @@ static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev) static int snd_usb_nativeinstruments_boot_quirk(struct usb_device *dev) { - int ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + int ret; + + if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0))) + return -EINVAL; + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 0xaf, USB_TYPE_VENDOR | USB_RECIP_DEVICE, 1, 0, NULL, 0, 1000); @@ -964,6 +970,8 @@ static int snd_usb_axefx3_boot_quirk(struct usb_device *dev) dev_dbg(&dev->dev, "Waiting for Axe-Fx III to boot up...\n"); + if (snd_usb_pipe_sanity_check(dev, usb_sndctrlpipe(dev, 0))) + return -EINVAL; /* If the Axe-Fx III has not fully booted, it will timeout when trying * to enable the audio streaming interface. A more generous timeout is * used here to detect when the Axe-Fx III has finished booting as the @@ -996,6 +1004,8 @@ static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf, { int err, actual_length; + if (snd_usb_pipe_sanity_check(dev, usb_sndintpipe(dev, 0x01))) + return -EINVAL; err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x01), buf, *length, &actual_length, 1000); if (err < 0) @@ -1006,6 +1016,8 @@ static int snd_usb_motu_microbookii_communicate(struct usb_device *dev, u8 *buf, memset(buf, 0, buf_size); + if (snd_usb_pipe_sanity_check(dev, usb_rcvintpipe(dev, 0x82))) + return -EINVAL; err = usb_interrupt_msg(dev, usb_rcvintpipe(dev, 0x82), buf, buf_size, &actual_length, 1000); if (err < 0) |