blob: 2e4e164e81d8f93626fe70b4a683c5cfeee05e8a [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);
51 int value = simple_strtoul(buf, NULL, 10);
52 line6pcm->impulse_volume = value;
53
Markus Grabnere1a164d2010-08-23 01:08:25 +020054 if (value > 0)
Markus Grabner1027f4762010-08-12 01:35:30 +020055 line6_pcm_start(line6pcm, MASK_PCM_IMPULSE);
56 else
57 line6_pcm_stop(line6pcm, MASK_PCM_IMPULSE);
58
59 return count;
60}
61
62/*
63 "read" request on "impulse_period" special file.
64*/
65static ssize_t pcm_get_impulse_period(struct device *dev,
Markus Grabnere1a164d2010-08-23 01:08:25 +020066 struct device_attribute *attr, char *buf)
Markus Grabner1027f4762010-08-12 01:35:30 +020067{
68 return sprintf(buf, "%d\n", dev2pcm(dev)->impulse_period);
69}
70
71/*
72 "write" request on "impulse_period" special file.
73*/
74static ssize_t pcm_set_impulse_period(struct device *dev,
75 struct device_attribute *attr,
76 const char *buf, size_t count)
77{
78 dev2pcm(dev)->impulse_period = simple_strtoul(buf, NULL, 10);
79 return count;
80}
81
Greg Kroah-Hartmana3a972a2010-11-18 11:21:04 -080082static DEVICE_ATTR(impulse_volume, S_IWUSR | S_IRUGO, pcm_get_impulse_volume,
Markus Grabnere1a164d2010-08-23 01:08:25 +020083 pcm_set_impulse_volume);
Greg Kroah-Hartmana3a972a2010-11-18 11:21:04 -080084static DEVICE_ATTR(impulse_period, S_IWUSR | S_IRUGO, pcm_get_impulse_period,
Markus Grabnere1a164d2010-08-23 01:08:25 +020085 pcm_set_impulse_period);
Markus Grabner1027f4762010-08-12 01:35:30 +020086
87#endif
88
89int line6_pcm_start(struct snd_line6_pcm *line6pcm, int channels)
90{
Markus Grabnere1a164d2010-08-23 01:08:25 +020091 unsigned long flags_old =
92 __sync_fetch_and_or(&line6pcm->flags, channels);
Markus Grabner1027f4762010-08-12 01:35:30 +020093 unsigned long flags_new = flags_old | channels;
94 int err = 0;
95
96#if LINE6_BACKUP_MONITOR_SIGNAL
97 if (!(line6pcm->line6->properties->capabilities & LINE6_BIT_HWMON)) {
Markus Grabnere1a164d2010-08-23 01:08:25 +020098 line6pcm->prev_fbuf =
99 kmalloc(LINE6_ISO_PACKETS * line6pcm->max_packet_size,
100 GFP_KERNEL);
Markus Grabner1027f4762010-08-12 01:35:30 +0200101
102 if (!line6pcm->prev_fbuf) {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200103 dev_err(line6pcm->line6->ifcdev,
104 "cannot malloc monitor buffer\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200105 return -ENOMEM;
106 }
107 }
108#else
109 line6pcm->prev_fbuf = NULL;
110#endif
Markus Grabnere1a164d2010-08-23 01:08:25 +0200111
Markus Grabner1027f4762010-08-12 01:35:30 +0200112 if (((flags_old & MASK_CAPTURE) == 0) &&
113 ((flags_new & MASK_CAPTURE) != 0)) {
114 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200115 Waiting for completion of active URBs in the stop handler is
116 a bug, we therefore report an error if capturing is restarted
117 too soon.
118 */
119 if (line6pcm->active_urb_in | line6pcm->unlink_urb_in)
Markus Grabner1027f4762010-08-12 01:35:30 +0200120 return -EBUSY;
121
Markus Grabner1027f4762010-08-12 01:35:30 +0200122 line6pcm->count_in = 0;
123 line6pcm->prev_fsize = 0;
124 err = line6_submit_audio_in_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200125
Markus Grabner1027f4762010-08-12 01:35:30 +0200126 if (err < 0) {
127 __sync_fetch_and_and(&line6pcm->flags, ~channels);
128 return err;
129 }
130 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200131
Markus Grabner1027f4762010-08-12 01:35:30 +0200132 if (((flags_old & MASK_PLAYBACK) == 0) &&
133 ((flags_new & MASK_PLAYBACK) != 0)) {
134 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200135 See comment above regarding PCM restart.
136 */
137 if (line6pcm->active_urb_out | line6pcm->unlink_urb_out)
Markus Grabner1027f4762010-08-12 01:35:30 +0200138 return -EBUSY;
139
Markus Grabner1027f4762010-08-12 01:35:30 +0200140 line6pcm->count_out = 0;
141 err = line6_submit_audio_out_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200142
Markus Grabner1027f4762010-08-12 01:35:30 +0200143 if (err < 0) {
144 __sync_fetch_and_and(&line6pcm->flags, ~channels);
145 return err;
146 }
147 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200148
Markus Grabner1027f4762010-08-12 01:35:30 +0200149 return 0;
150}
151
152int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels)
153{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200154 unsigned long flags_old =
155 __sync_fetch_and_and(&line6pcm->flags, ~channels);
Markus Grabner1027f4762010-08-12 01:35:30 +0200156 unsigned long flags_new = flags_old & ~channels;
157
158 if (((flags_old & MASK_CAPTURE) != 0) &&
159 ((flags_new & MASK_CAPTURE) == 0)) {
160 line6_unlink_audio_in_urbs(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200161 }
162
163 if (((flags_old & MASK_PLAYBACK) != 0) &&
164 ((flags_new & MASK_PLAYBACK) == 0)) {
165 line6_unlink_audio_out_urbs(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200166 }
Markus Grabner1027f4762010-08-12 01:35:30 +0200167#if LINE6_BACKUP_MONITOR_SIGNAL
Ilia Mirkin43c04d42011-03-13 00:29:02 -0500168 kfree(line6pcm->prev_fbuf);
Markus Grabner1027f4762010-08-12 01:35:30 +0200169#endif
170
171 return 0;
172}
173
Markus Grabner705ecec2009-02-27 19:43:04 -0800174/* trigger callback */
175int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
176{
177 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800178 struct snd_pcm_substream *s;
179 int err;
180 unsigned long flags;
181
182 spin_lock_irqsave(&line6pcm->lock_trigger, flags);
183 clear_bit(BIT_PREPARED, &line6pcm->flags);
184
Markus Grabner705ecec2009-02-27 19:43:04 -0800185 snd_pcm_group_for_each_entry(s, substream) {
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800186 switch (s->stream) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800187 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner1027f4762010-08-12 01:35:30 +0200188 err = snd_line6_playback_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800189
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800190 if (err < 0) {
191 spin_unlock_irqrestore(&line6pcm->lock_trigger,
192 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800193 return err;
194 }
195
196 break;
197
198 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner1027f4762010-08-12 01:35:30 +0200199 err = snd_line6_capture_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800200
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800201 if (err < 0) {
202 spin_unlock_irqrestore(&line6pcm->lock_trigger,
203 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800204 return err;
205 }
206
207 break;
208
209 default:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200210 dev_err(line6pcm->line6->ifcdev,
211 "Unknown stream direction %d\n", s->stream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800212 }
213 }
214
215 spin_unlock_irqrestore(&line6pcm->lock_trigger, flags);
216 return 0;
217}
218
219/* control info callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200220static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
221 struct snd_ctl_elem_info *uinfo)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800222{
Markus Grabner705ecec2009-02-27 19:43:04 -0800223 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
224 uinfo->count = 2;
225 uinfo->value.integer.min = 0;
226 uinfo->value.integer.max = 256;
227 return 0;
228}
229
230/* control get callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200231static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
232 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800233{
Markus Grabner705ecec2009-02-27 19:43:04 -0800234 int i;
235 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
236
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800237 for (i = 2; i--;)
Markus Grabner1027f4762010-08-12 01:35:30 +0200238 ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800239
240 return 0;
241}
242
243/* control put callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200244static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800246{
Markus Grabner705ecec2009-02-27 19:43:04 -0800247 int i, changed = 0;
248 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
249
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800250 for (i = 2; i--;)
Markus Grabnere1a164d2010-08-23 01:08:25 +0200251 if (line6pcm->volume_playback[i] !=
252 ucontrol->value.integer.value[i]) {
253 line6pcm->volume_playback[i] =
254 ucontrol->value.integer.value[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800255 changed = 1;
256 }
257
258 return changed;
259}
260
261/* control definition */
Markus Grabner1027f4762010-08-12 01:35:30 +0200262static struct snd_kcontrol_new line6_control_playback = {
Markus Grabner705ecec2009-02-27 19:43:04 -0800263 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
264 .name = "PCM Playback Volume",
265 .index = 0,
266 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
Markus Grabner1027f4762010-08-12 01:35:30 +0200267 .info = snd_line6_control_playback_info,
268 .get = snd_line6_control_playback_get,
269 .put = snd_line6_control_playback_put
Markus Grabner705ecec2009-02-27 19:43:04 -0800270};
271
272/*
273 Cleanup the PCM device.
274*/
275static void line6_cleanup_pcm(struct snd_pcm *pcm)
276{
277 int i;
278 struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
279
Markus Grabner1027f4762010-08-12 01:35:30 +0200280#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
281 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_volume);
282 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_period);
283#endif
284
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800285 for (i = LINE6_ISO_BUFFERS; i--;) {
286 if (line6pcm->urb_audio_out[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800287 usb_kill_urb(line6pcm->urb_audio_out[i]);
288 usb_free_urb(line6pcm->urb_audio_out[i]);
289 }
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800290 if (line6pcm->urb_audio_in[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800291 usb_kill_urb(line6pcm->urb_audio_in[i]);
292 usb_free_urb(line6pcm->urb_audio_in[i]);
293 }
294 }
295}
296
297/* create a PCM device */
298static int snd_line6_new_pcm(struct snd_line6_pcm *line6pcm)
299{
300 struct snd_pcm *pcm;
301 int err;
302
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800303 err = snd_pcm_new(line6pcm->line6->card,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200304 (char *)line6pcm->line6->properties->name,
305 0, 1, 1, &pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800306 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800307 return err;
308
309 pcm->private_data = line6pcm;
310 pcm->private_free = line6_cleanup_pcm;
311 line6pcm->pcm = pcm;
312 strcpy(pcm->name, line6pcm->line6->properties->name);
313
314 /* set operators */
Shawn Bohrerafb90912009-11-15 22:17:57 -0600315 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
316 &snd_line6_playback_ops);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200317 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
Markus Grabner705ecec2009-02-27 19:43:04 -0800318
319 /* pre-allocation of buffers */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800320 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200321 snd_dma_continuous_data
322 (GFP_KERNEL), 64 * 1024,
323 128 * 1024);
Markus Grabner705ecec2009-02-27 19:43:04 -0800324
325 return 0;
326}
327
328/* PCM device destructor */
329static int snd_line6_pcm_free(struct snd_device *device)
330{
331 return 0;
332}
333
334/*
Markus Grabner1027f4762010-08-12 01:35:30 +0200335 Stop substream if still running.
336*/
337static void pcm_disconnect_substream(struct snd_pcm_substream *substream)
338{
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700339 if (substream->runtime && snd_pcm_running(substream))
Markus Grabner1027f4762010-08-12 01:35:30 +0200340 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
Markus Grabner1027f4762010-08-12 01:35:30 +0200341}
342
343/*
344 Stop PCM stream.
345*/
346void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
347{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200348 pcm_disconnect_substream(get_substream
349 (line6pcm, SNDRV_PCM_STREAM_CAPTURE));
350 pcm_disconnect_substream(get_substream
351 (line6pcm, SNDRV_PCM_STREAM_PLAYBACK));
Markus Grabner1027f4762010-08-12 01:35:30 +0200352 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
353 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
354}
355
356/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800357 Create and register the PCM device and mixer entries.
358 Create URBs for playback and capture.
359*/
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800360int line6_init_pcm(struct usb_line6 *line6,
361 struct line6_pcm_properties *properties)
Markus Grabner705ecec2009-02-27 19:43:04 -0800362{
363 static struct snd_device_ops pcm_ops = {
364 .dev_free = snd_line6_pcm_free,
365 };
366
367 int err;
368 int ep_read = 0, ep_write = 0;
369 struct snd_line6_pcm *line6pcm;
370
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800371 if (!(line6->properties->capabilities & LINE6_BIT_PCM))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200372 return 0; /* skip PCM initialization and report success */
Markus Grabner705ecec2009-02-27 19:43:04 -0800373
374 /* initialize PCM subsystem based on product id: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800375 switch (line6->product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800376 case LINE6_DEVID_BASSPODXT:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800377 case LINE6_DEVID_BASSPODXTLIVE:
378 case LINE6_DEVID_BASSPODXTPRO:
379 case LINE6_DEVID_PODXT:
380 case LINE6_DEVID_PODXTLIVE:
381 case LINE6_DEVID_PODXTPRO:
Stefan Hajnoczi16dc1042011-11-23 08:20:42 +0000382 case LINE6_DEVID_PODHD300:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200383 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800384 ep_write = 0x01;
385 break;
386
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800387 case LINE6_DEVID_PODX3:
388 case LINE6_DEVID_PODX3LIVE:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200389 ep_read = 0x86;
Markus Grabner705ecec2009-02-27 19:43:04 -0800390 ep_write = 0x02;
391 break;
392
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800393 case LINE6_DEVID_POCKETPOD:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200394 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800395 ep_write = 0x02;
396 break;
397
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800398 case LINE6_DEVID_GUITARPORT:
Markus Grabner1027f4762010-08-12 01:35:30 +0200399 case LINE6_DEVID_PODSTUDIO_GX:
400 case LINE6_DEVID_PODSTUDIO_UX1:
401 case LINE6_DEVID_PODSTUDIO_UX2:
Markus Grabner705ecec2009-02-27 19:43:04 -0800402 case LINE6_DEVID_TONEPORT_GX:
Markus Grabner1027f4762010-08-12 01:35:30 +0200403 case LINE6_DEVID_TONEPORT_UX1:
404 case LINE6_DEVID_TONEPORT_UX2:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200405 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800406 ep_write = 0x01;
407 break;
408
Markus Grabner1027f4762010-08-12 01:35:30 +0200409 /* this is for interface_number == 1:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200410 case LINE6_DEVID_TONEPORT_UX2:
411 case LINE6_DEVID_PODSTUDIO_UX2:
412 ep_read = 0x87;
413 ep_write = 0x00;
414 break;
415 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800416
417 default:
418 MISSING_CASE;
419 }
420
421 line6pcm = kzalloc(sizeof(struct snd_line6_pcm), GFP_KERNEL);
422
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800423 if (line6pcm == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800424 return -ENOMEM;
425
Markus Grabner1027f4762010-08-12 01:35:30 +0200426 line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
427 line6pcm->volume_monitor = 255;
Markus Grabner705ecec2009-02-27 19:43:04 -0800428 line6pcm->line6 = line6;
429 line6pcm->ep_audio_read = ep_read;
430 line6pcm->ep_audio_write = ep_write;
Stefan Hajnoczi3b08db32011-11-23 08:20:44 +0000431
432 /* Read and write buffers are sized identically, so choose minimum */
433 line6pcm->max_packet_size = min(
434 usb_maxpacket(line6->usbdev,
435 usb_rcvisocpipe(line6->usbdev, ep_read), 0),
436 usb_maxpacket(line6->usbdev,
437 usb_sndisocpipe(line6->usbdev, ep_write), 1));
438
Markus Grabner705ecec2009-02-27 19:43:04 -0800439 line6pcm->properties = properties;
440 line6->line6pcm = line6pcm;
441
442 /* PCM device: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800443 err = snd_device_new(line6->card, SNDRV_DEV_PCM, line6, &pcm_ops);
444 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800445 return err;
446
447 snd_card_set_dev(line6->card, line6->ifcdev);
448
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800449 err = snd_line6_new_pcm(line6pcm);
450 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800451 return err;
452
453 spin_lock_init(&line6pcm->lock_audio_out);
454 spin_lock_init(&line6pcm->lock_audio_in);
455 spin_lock_init(&line6pcm->lock_trigger);
456
Markus Grabner1027f4762010-08-12 01:35:30 +0200457 err = line6_create_audio_out_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800458 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800459 return err;
460
Markus Grabner1027f4762010-08-12 01:35:30 +0200461 err = line6_create_audio_in_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800462 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800463 return err;
464
465 /* mixer: */
Markus Grabnere1a164d2010-08-23 01:08:25 +0200466 err =
467 snd_ctl_add(line6->card,
468 snd_ctl_new1(&line6_control_playback, line6pcm));
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800469 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800470 return err;
471
Markus Grabner1027f4762010-08-12 01:35:30 +0200472#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
473 /* impulse response test: */
474 err = device_create_file(line6->ifcdev, &dev_attr_impulse_volume);
475 if (err < 0)
476 return err;
477
478 err = device_create_file(line6->ifcdev, &dev_attr_impulse_period);
479 if (err < 0)
480 return err;
481
482 line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
483#endif
484
Markus Grabner705ecec2009-02-27 19:43:04 -0800485 return 0;
486}
487
488/* prepare pcm callback */
489int snd_line6_prepare(struct snd_pcm_substream *substream)
490{
491 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
492
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800493 if (!test_and_set_bit(BIT_PREPARED, &line6pcm->flags)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200494 line6pcm->count_out = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800495 line6pcm->pos_out = 0;
496 line6pcm->pos_out_done = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800497 line6pcm->bytes_out = 0;
Markus Grabner1027f4762010-08-12 01:35:30 +0200498 line6pcm->count_in = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800499 line6pcm->pos_in_done = 0;
500 line6pcm->bytes_in = 0;
501 }
502
503 return 0;
504}