blob: 7fe44a6fd0eda32630e230fe82dde2dcf098f328 [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
Markus Grabnere1a164d2010-08-23 01:08:25 +02002 * Line6 Linux USB driver - 0.9.1beta
Markus Grabner705ecec2009-02-27 19:43:04 -08003 *
Markus Grabner1027f4762010-08-12 01:35:30 +02004 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 *
10 */
11
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080013#include <sound/core.h>
14#include <sound/control.h>
15#include <sound/pcm.h>
16#include <sound/pcm_params.h>
17
18#include "audio.h"
19#include "capture.h"
Markus Grabner1027f4762010-08-12 01:35:30 +020020#include "driver.h"
Markus Grabner705ecec2009-02-27 19:43:04 -080021#include "playback.h"
22#include "pod.h"
23
Markus Grabner1027f4762010-08-12 01:35:30 +020024#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
25
Markus Grabnere1a164d2010-08-23 01:08:25 +020026static struct snd_line6_pcm *dev2pcm(struct device *dev)
Markus Grabner1027f4762010-08-12 01:35:30 +020027{
28 struct usb_interface *interface = to_usb_interface(dev);
29 struct usb_line6 *line6 = usb_get_intfdata(interface);
30 struct snd_line6_pcm *line6pcm = line6->line6pcm;
31 return line6pcm;
32}
33
34/*
35 "read" request on "impulse_volume" special file.
36*/
37static ssize_t pcm_get_impulse_volume(struct device *dev,
Markus Grabnere1a164d2010-08-23 01:08:25 +020038 struct device_attribute *attr, char *buf)
Markus Grabner1027f4762010-08-12 01:35:30 +020039{
40 return sprintf(buf, "%d\n", dev2pcm(dev)->impulse_volume);
41}
42
43/*
44 "write" request on "impulse_volume" special file.
45*/
46static ssize_t pcm_set_impulse_volume(struct device *dev,
47 struct device_attribute *attr,
48 const char *buf, size_t count)
49{
50 struct snd_line6_pcm *line6pcm = dev2pcm(dev);
Johannes Thumshirncdf5e552012-08-06 14:08:50 +020051 int value;
52 int rv;
53
54 rv = kstrtoint(buf, 10, &value);
55 if (rv < 0)
56 return rv;
57
Markus Grabner1027f4762010-08-12 01:35:30 +020058 line6pcm->impulse_volume = value;
59
Markus Grabnere1a164d2010-08-23 01:08:25 +020060 if (value > 0)
Markus Grabner0ca54882012-01-20 00:09:09 +010061 line6_pcm_acquire(line6pcm, LINE6_BITS_PCM_IMPULSE);
Markus Grabner1027f4762010-08-12 01:35:30 +020062 else
Markus Grabner0ca54882012-01-20 00:09:09 +010063 line6_pcm_release(line6pcm, LINE6_BITS_PCM_IMPULSE);
Markus Grabner1027f4762010-08-12 01:35:30 +020064
65 return count;
66}
67
68/*
69 "read" request on "impulse_period" special file.
70*/
71static ssize_t pcm_get_impulse_period(struct device *dev,
Markus Grabnere1a164d2010-08-23 01:08:25 +020072 struct device_attribute *attr, char *buf)
Markus Grabner1027f4762010-08-12 01:35:30 +020073{
74 return sprintf(buf, "%d\n", dev2pcm(dev)->impulse_period);
75}
76
77/*
78 "write" request on "impulse_period" special file.
79*/
80static ssize_t pcm_set_impulse_period(struct device *dev,
81 struct device_attribute *attr,
82 const char *buf, size_t count)
83{
84 dev2pcm(dev)->impulse_period = simple_strtoul(buf, NULL, 10);
85 return count;
86}
87
Greg Kroah-Hartmana3a972a2010-11-18 11:21:04 -080088static DEVICE_ATTR(impulse_volume, S_IWUSR | S_IRUGO, pcm_get_impulse_volume,
Markus Grabnere1a164d2010-08-23 01:08:25 +020089 pcm_set_impulse_volume);
Greg Kroah-Hartmana3a972a2010-11-18 11:21:04 -080090static DEVICE_ATTR(impulse_period, S_IWUSR | S_IRUGO, pcm_get_impulse_period,
Markus Grabnere1a164d2010-08-23 01:08:25 +020091 pcm_set_impulse_period);
Markus Grabner1027f4762010-08-12 01:35:30 +020092
93#endif
94
Markus Grabner6b02a17e2011-12-10 02:12:32 +010095static bool test_flags(unsigned long flags0, unsigned long flags1,
96 unsigned long mask)
97{
98 return ((flags0 & mask) == 0) && ((flags1 & mask) != 0);
99}
100
Markus Grabner0ca54882012-01-20 00:09:09 +0100101int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
Markus Grabner1027f4762010-08-12 01:35:30 +0200102{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200103 unsigned long flags_old =
104 __sync_fetch_and_or(&line6pcm->flags, channels);
Markus Grabner1027f4762010-08-12 01:35:30 +0200105 unsigned long flags_new = flags_old | channels;
Markus Grabner0ca54882012-01-20 00:09:09 +0100106 unsigned long flags_final = flags_old;
Markus Grabner1027f4762010-08-12 01:35:30 +0200107 int err = 0;
Johannes Thumshirn82a74d42012-05-05 16:31:52 +0200108
Markus Grabner1027f4762010-08-12 01:35:30 +0200109 line6pcm->prev_fbuf = NULL;
Markus Grabnere1a164d2010-08-23 01:08:25 +0200110
Markus Grabner0ca54882012-01-20 00:09:09 +0100111 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
112 /* We may be invoked multiple times in a row so allocate once only */
113 if (!line6pcm->buffer_in) {
114 line6pcm->buffer_in =
115 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
116 line6pcm->max_packet_size, GFP_KERNEL);
117
118 if (!line6pcm->buffer_in) {
119 dev_err(line6pcm->line6->ifcdev,
120 "cannot malloc capture buffer\n");
121 err = -ENOMEM;
122 goto pcm_acquire_error;
123 }
124
125 flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER;
126 }
127 }
128
129 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_STREAM)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200130 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200131 Waiting for completion of active URBs in the stop handler is
132 a bug, we therefore report an error if capturing is restarted
133 too soon.
134 */
Markus Grabner0ca54882012-01-20 00:09:09 +0100135 if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) {
136 dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200137 return -EBUSY;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100138 }
139
Markus Grabner1027f4762010-08-12 01:35:30 +0200140 line6pcm->count_in = 0;
141 line6pcm->prev_fsize = 0;
142 err = line6_submit_audio_in_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200143
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100144 if (err < 0)
Markus Grabner0ca54882012-01-20 00:09:09 +0100145 goto pcm_acquire_error;
146
147 flags_final |= channels & LINE6_BITS_CAPTURE_STREAM;
Markus Grabner1027f4762010-08-12 01:35:30 +0200148 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200149
Markus Grabner0ca54882012-01-20 00:09:09 +0100150 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) {
151 /* We may be invoked multiple times in a row so allocate once only */
152 if (!line6pcm->buffer_out) {
153 line6pcm->buffer_out =
154 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
155 line6pcm->max_packet_size, GFP_KERNEL);
156
157 if (!line6pcm->buffer_out) {
158 dev_err(line6pcm->line6->ifcdev,
159 "cannot malloc playback buffer\n");
160 err = -ENOMEM;
161 goto pcm_acquire_error;
162 }
163
164 flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER;
165 }
166 }
167
168 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_STREAM)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200169 /*
Markus Grabner0ca54882012-01-20 00:09:09 +0100170 See comment above regarding PCM restart.
171 */
172 if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) {
173 dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200174 return -EBUSY;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100175 }
176
Markus Grabner1027f4762010-08-12 01:35:30 +0200177 line6pcm->count_out = 0;
178 err = line6_submit_audio_out_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200179
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100180 if (err < 0)
Markus Grabner0ca54882012-01-20 00:09:09 +0100181 goto pcm_acquire_error;
182
183 flags_final |= channels & LINE6_BITS_PLAYBACK_STREAM;
Markus Grabner1027f4762010-08-12 01:35:30 +0200184 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200185
Markus Grabner1027f4762010-08-12 01:35:30 +0200186 return 0;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100187
Markus Grabner0ca54882012-01-20 00:09:09 +0100188pcm_acquire_error:
189 /*
190 If not all requested resources/streams could be obtained, release
191 those which were successfully obtained (if any).
192 */
193 line6_pcm_release(line6pcm, flags_final & channels);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100194 return err;
Markus Grabner1027f4762010-08-12 01:35:30 +0200195}
196
Markus Grabner0ca54882012-01-20 00:09:09 +0100197int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels)
Markus Grabner1027f4762010-08-12 01:35:30 +0200198{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200199 unsigned long flags_old =
200 __sync_fetch_and_and(&line6pcm->flags, ~channels);
Markus Grabner1027f4762010-08-12 01:35:30 +0200201 unsigned long flags_new = flags_old & ~channels;
202
Markus Grabner0ca54882012-01-20 00:09:09 +0100203 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM))
Markus Grabner1027f4762010-08-12 01:35:30 +0200204 line6_unlink_audio_in_urbs(line6pcm);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100205
Markus Grabner0ca54882012-01-20 00:09:09 +0100206 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) {
207 line6_wait_clear_audio_in_urbs(line6pcm);
208 line6_free_capture_buffer(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200209 }
210
Markus Grabner0ca54882012-01-20 00:09:09 +0100211 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM))
Markus Grabner1027f4762010-08-12 01:35:30 +0200212 line6_unlink_audio_out_urbs(line6pcm);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100213
Markus Grabner0ca54882012-01-20 00:09:09 +0100214 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) {
215 line6_wait_clear_audio_out_urbs(line6pcm);
216 line6_free_playback_buffer(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200217 }
Markus Grabner1027f4762010-08-12 01:35:30 +0200218
219 return 0;
220}
221
Markus Grabner705ecec2009-02-27 19:43:04 -0800222/* trigger callback */
223int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
224{
225 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800226 struct snd_pcm_substream *s;
227 int err;
228 unsigned long flags;
229
230 spin_lock_irqsave(&line6pcm->lock_trigger, flags);
Markus Grabner0ca54882012-01-20 00:09:09 +0100231 clear_bit(LINE6_INDEX_PREPARED, &line6pcm->flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800232
Markus Grabner705ecec2009-02-27 19:43:04 -0800233 snd_pcm_group_for_each_entry(s, substream) {
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800234 switch (s->stream) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800235 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner1027f4762010-08-12 01:35:30 +0200236 err = snd_line6_playback_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800237
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800238 if (err < 0) {
239 spin_unlock_irqrestore(&line6pcm->lock_trigger,
240 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800241 return err;
242 }
243
244 break;
245
246 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner1027f4762010-08-12 01:35:30 +0200247 err = snd_line6_capture_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800248
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800249 if (err < 0) {
250 spin_unlock_irqrestore(&line6pcm->lock_trigger,
251 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800252 return err;
253 }
254
255 break;
256
257 default:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200258 dev_err(line6pcm->line6->ifcdev,
259 "Unknown stream direction %d\n", s->stream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800260 }
261 }
262
263 spin_unlock_irqrestore(&line6pcm->lock_trigger, flags);
264 return 0;
265}
266
267/* control info callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200268static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
269 struct snd_ctl_elem_info *uinfo)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800270{
Markus Grabner705ecec2009-02-27 19:43:04 -0800271 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
272 uinfo->count = 2;
273 uinfo->value.integer.min = 0;
274 uinfo->value.integer.max = 256;
275 return 0;
276}
277
278/* control get callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200279static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800281{
Markus Grabner705ecec2009-02-27 19:43:04 -0800282 int i;
283 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
284
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800285 for (i = 2; i--;)
Markus Grabner1027f4762010-08-12 01:35:30 +0200286 ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800287
288 return 0;
289}
290
291/* control put callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200292static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800294{
Markus Grabner705ecec2009-02-27 19:43:04 -0800295 int i, changed = 0;
296 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
297
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800298 for (i = 2; i--;)
Markus Grabnere1a164d2010-08-23 01:08:25 +0200299 if (line6pcm->volume_playback[i] !=
300 ucontrol->value.integer.value[i]) {
301 line6pcm->volume_playback[i] =
302 ucontrol->value.integer.value[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800303 changed = 1;
304 }
305
306 return changed;
307}
308
309/* control definition */
Markus Grabner1027f4762010-08-12 01:35:30 +0200310static struct snd_kcontrol_new line6_control_playback = {
Markus Grabner705ecec2009-02-27 19:43:04 -0800311 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
312 .name = "PCM Playback Volume",
313 .index = 0,
314 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
Markus Grabner1027f4762010-08-12 01:35:30 +0200315 .info = snd_line6_control_playback_info,
316 .get = snd_line6_control_playback_get,
317 .put = snd_line6_control_playback_put
Markus Grabner705ecec2009-02-27 19:43:04 -0800318};
319
320/*
321 Cleanup the PCM device.
322*/
323static void line6_cleanup_pcm(struct snd_pcm *pcm)
324{
325 int i;
326 struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
327
Markus Grabner1027f4762010-08-12 01:35:30 +0200328#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
329 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_volume);
330 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_period);
331#endif
332
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800333 for (i = LINE6_ISO_BUFFERS; i--;) {
334 if (line6pcm->urb_audio_out[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800335 usb_kill_urb(line6pcm->urb_audio_out[i]);
336 usb_free_urb(line6pcm->urb_audio_out[i]);
337 }
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800338 if (line6pcm->urb_audio_in[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800339 usb_kill_urb(line6pcm->urb_audio_in[i]);
340 usb_free_urb(line6pcm->urb_audio_in[i]);
341 }
342 }
343}
344
345/* create a PCM device */
346static int snd_line6_new_pcm(struct snd_line6_pcm *line6pcm)
347{
348 struct snd_pcm *pcm;
349 int err;
350
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800351 err = snd_pcm_new(line6pcm->line6->card,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200352 (char *)line6pcm->line6->properties->name,
353 0, 1, 1, &pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800354 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800355 return err;
356
357 pcm->private_data = line6pcm;
358 pcm->private_free = line6_cleanup_pcm;
359 line6pcm->pcm = pcm;
360 strcpy(pcm->name, line6pcm->line6->properties->name);
361
362 /* set operators */
Shawn Bohrerafb90912009-11-15 22:17:57 -0600363 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
364 &snd_line6_playback_ops);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200365 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
Markus Grabner705ecec2009-02-27 19:43:04 -0800366
367 /* pre-allocation of buffers */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800368 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200369 snd_dma_continuous_data
370 (GFP_KERNEL), 64 * 1024,
371 128 * 1024);
Markus Grabner705ecec2009-02-27 19:43:04 -0800372
373 return 0;
374}
375
376/* PCM device destructor */
377static int snd_line6_pcm_free(struct snd_device *device)
378{
379 return 0;
380}
381
382/*
Markus Grabner1027f4762010-08-12 01:35:30 +0200383 Stop substream if still running.
384*/
385static void pcm_disconnect_substream(struct snd_pcm_substream *substream)
386{
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700387 if (substream->runtime && snd_pcm_running(substream))
Markus Grabner1027f4762010-08-12 01:35:30 +0200388 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
Markus Grabner1027f4762010-08-12 01:35:30 +0200389}
390
391/*
392 Stop PCM stream.
393*/
394void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
395{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200396 pcm_disconnect_substream(get_substream
397 (line6pcm, SNDRV_PCM_STREAM_CAPTURE));
398 pcm_disconnect_substream(get_substream
399 (line6pcm, SNDRV_PCM_STREAM_PLAYBACK));
Markus Grabner1027f4762010-08-12 01:35:30 +0200400 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
401 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
402}
403
404/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800405 Create and register the PCM device and mixer entries.
406 Create URBs for playback and capture.
407*/
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800408int line6_init_pcm(struct usb_line6 *line6,
409 struct line6_pcm_properties *properties)
Markus Grabner705ecec2009-02-27 19:43:04 -0800410{
411 static struct snd_device_ops pcm_ops = {
412 .dev_free = snd_line6_pcm_free,
413 };
414
415 int err;
416 int ep_read = 0, ep_write = 0;
417 struct snd_line6_pcm *line6pcm;
418
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800419 if (!(line6->properties->capabilities & LINE6_BIT_PCM))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200420 return 0; /* skip PCM initialization and report success */
Markus Grabner705ecec2009-02-27 19:43:04 -0800421
422 /* initialize PCM subsystem based on product id: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800423 switch (line6->product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800424 case LINE6_DEVID_BASSPODXT:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800425 case LINE6_DEVID_BASSPODXTLIVE:
426 case LINE6_DEVID_BASSPODXTPRO:
427 case LINE6_DEVID_PODXT:
428 case LINE6_DEVID_PODXTLIVE:
429 case LINE6_DEVID_PODXTPRO:
Stefan Hajnoczi16dc1042011-11-23 08:20:42 +0000430 case LINE6_DEVID_PODHD300:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200431 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800432 ep_write = 0x01;
433 break;
434
Markus Grabner4c6fb5f2011-12-05 23:51:53 +0100435 case LINE6_DEVID_PODHD500:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800436 case LINE6_DEVID_PODX3:
437 case LINE6_DEVID_PODX3LIVE:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200438 ep_read = 0x86;
Markus Grabner705ecec2009-02-27 19:43:04 -0800439 ep_write = 0x02;
440 break;
441
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800442 case LINE6_DEVID_POCKETPOD:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200443 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800444 ep_write = 0x02;
445 break;
446
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800447 case LINE6_DEVID_GUITARPORT:
Markus Grabner1027f4762010-08-12 01:35:30 +0200448 case LINE6_DEVID_PODSTUDIO_GX:
449 case LINE6_DEVID_PODSTUDIO_UX1:
450 case LINE6_DEVID_PODSTUDIO_UX2:
Markus Grabner705ecec2009-02-27 19:43:04 -0800451 case LINE6_DEVID_TONEPORT_GX:
Markus Grabner1027f4762010-08-12 01:35:30 +0200452 case LINE6_DEVID_TONEPORT_UX1:
453 case LINE6_DEVID_TONEPORT_UX2:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200454 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800455 ep_write = 0x01;
456 break;
457
Markus Grabner1027f4762010-08-12 01:35:30 +0200458 /* this is for interface_number == 1:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200459 case LINE6_DEVID_TONEPORT_UX2:
460 case LINE6_DEVID_PODSTUDIO_UX2:
461 ep_read = 0x87;
462 ep_write = 0x00;
463 break;
464 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800465
466 default:
467 MISSING_CASE;
468 }
469
470 line6pcm = kzalloc(sizeof(struct snd_line6_pcm), GFP_KERNEL);
471
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800472 if (line6pcm == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800473 return -ENOMEM;
474
Markus Grabner1027f4762010-08-12 01:35:30 +0200475 line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
476 line6pcm->volume_monitor = 255;
Markus Grabner705ecec2009-02-27 19:43:04 -0800477 line6pcm->line6 = line6;
478 line6pcm->ep_audio_read = ep_read;
479 line6pcm->ep_audio_write = ep_write;
Stefan Hajnoczi3b08db32011-11-23 08:20:44 +0000480
481 /* Read and write buffers are sized identically, so choose minimum */
482 line6pcm->max_packet_size = min(
483 usb_maxpacket(line6->usbdev,
484 usb_rcvisocpipe(line6->usbdev, ep_read), 0),
485 usb_maxpacket(line6->usbdev,
486 usb_sndisocpipe(line6->usbdev, ep_write), 1));
487
Markus Grabner705ecec2009-02-27 19:43:04 -0800488 line6pcm->properties = properties;
489 line6->line6pcm = line6pcm;
490
491 /* PCM device: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800492 err = snd_device_new(line6->card, SNDRV_DEV_PCM, line6, &pcm_ops);
493 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800494 return err;
495
496 snd_card_set_dev(line6->card, line6->ifcdev);
497
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800498 err = snd_line6_new_pcm(line6pcm);
499 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800500 return err;
501
502 spin_lock_init(&line6pcm->lock_audio_out);
503 spin_lock_init(&line6pcm->lock_audio_in);
504 spin_lock_init(&line6pcm->lock_trigger);
505
Markus Grabner1027f4762010-08-12 01:35:30 +0200506 err = line6_create_audio_out_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800507 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800508 return err;
509
Markus Grabner1027f4762010-08-12 01:35:30 +0200510 err = line6_create_audio_in_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800511 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800512 return err;
513
514 /* mixer: */
Markus Grabnere1a164d2010-08-23 01:08:25 +0200515 err =
516 snd_ctl_add(line6->card,
517 snd_ctl_new1(&line6_control_playback, line6pcm));
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800518 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800519 return err;
520
Markus Grabner1027f4762010-08-12 01:35:30 +0200521#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
522 /* impulse response test: */
523 err = device_create_file(line6->ifcdev, &dev_attr_impulse_volume);
524 if (err < 0)
525 return err;
526
527 err = device_create_file(line6->ifcdev, &dev_attr_impulse_period);
528 if (err < 0)
529 return err;
530
531 line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
532#endif
533
Markus Grabner705ecec2009-02-27 19:43:04 -0800534 return 0;
535}
536
537/* prepare pcm callback */
538int snd_line6_prepare(struct snd_pcm_substream *substream)
539{
540 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
541
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100542 switch (substream->stream) {
543 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner0ca54882012-01-20 00:09:09 +0100544 if ((line6pcm->flags & LINE6_BITS_PLAYBACK_STREAM) == 0)
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100545 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
546
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100547 break;
548
549 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner0ca54882012-01-20 00:09:09 +0100550 if ((line6pcm->flags & LINE6_BITS_CAPTURE_STREAM) == 0)
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100551 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
552
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100553 break;
554
555 default:
556 MISSING_CASE;
557 }
558
Markus Grabner0ca54882012-01-20 00:09:09 +0100559 if (!test_and_set_bit(LINE6_INDEX_PREPARED, &line6pcm->flags)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200560 line6pcm->count_out = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800561 line6pcm->pos_out = 0;
562 line6pcm->pos_out_done = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800563 line6pcm->bytes_out = 0;
Markus Grabner1027f4762010-08-12 01:35:30 +0200564 line6pcm->count_in = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800565 line6pcm->pos_in_done = 0;
566 line6pcm->bytes_in = 0;
567 }
568
569 return 0;
570}