blob: 8fb5596efe9e86457d1d6cec18d804bdd184c1ad [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
Markus Grabnere1a164d2010-08-23 01:08:25 +020082static DEVICE_ATTR(impulse_volume, S_IWUGO | S_IRUGO, pcm_get_impulse_volume,
83 pcm_set_impulse_volume);
84static DEVICE_ATTR(impulse_period, S_IWUGO | S_IRUGO, pcm_get_impulse_period,
85 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 Grabnere1a164d2010-08-23 01:08:25 +0200122 line6pcm->buffer_in =
123 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
124 line6pcm->max_packet_size, GFP_KERNEL);
Markus Grabner1027f4762010-08-12 01:35:30 +0200125
126 if (!line6pcm->buffer_in) {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200127 dev_err(line6pcm->line6->ifcdev,
128 "cannot malloc capture buffer\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200129 return -ENOMEM;
130 }
131
132 line6pcm->count_in = 0;
133 line6pcm->prev_fsize = 0;
134 err = line6_submit_audio_in_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200135
Markus Grabner1027f4762010-08-12 01:35:30 +0200136 if (err < 0) {
137 __sync_fetch_and_and(&line6pcm->flags, ~channels);
138 return err;
139 }
140 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200141
Markus Grabner1027f4762010-08-12 01:35:30 +0200142 if (((flags_old & MASK_PLAYBACK) == 0) &&
143 ((flags_new & MASK_PLAYBACK) != 0)) {
144 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200145 See comment above regarding PCM restart.
146 */
147 if (line6pcm->active_urb_out | line6pcm->unlink_urb_out)
Markus Grabner1027f4762010-08-12 01:35:30 +0200148 return -EBUSY;
149
Markus Grabnere1a164d2010-08-23 01:08:25 +0200150 line6pcm->buffer_out =
151 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
152 line6pcm->max_packet_size, GFP_KERNEL);
Markus Grabner1027f4762010-08-12 01:35:30 +0200153
154 if (!line6pcm->buffer_out) {
Markus Grabnere1a164d2010-08-23 01:08:25 +0200155 dev_err(line6pcm->line6->ifcdev,
156 "cannot malloc playback buffer\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200157 return -ENOMEM;
158 }
159
160 line6pcm->count_out = 0;
161 err = line6_submit_audio_out_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200162
Markus Grabner1027f4762010-08-12 01:35:30 +0200163 if (err < 0) {
164 __sync_fetch_and_and(&line6pcm->flags, ~channels);
165 return err;
166 }
167 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200168
Markus Grabner1027f4762010-08-12 01:35:30 +0200169 return 0;
170}
171
172int line6_pcm_stop(struct snd_line6_pcm *line6pcm, int channels)
173{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200174 unsigned long flags_old =
175 __sync_fetch_and_and(&line6pcm->flags, ~channels);
Markus Grabner1027f4762010-08-12 01:35:30 +0200176 unsigned long flags_new = flags_old & ~channels;
177
178 if (((flags_old & MASK_CAPTURE) != 0) &&
179 ((flags_new & MASK_CAPTURE) == 0)) {
180 line6_unlink_audio_in_urbs(line6pcm);
181 kfree(line6pcm->buffer_in);
182 line6pcm->buffer_in = NULL;
183 }
184
185 if (((flags_old & MASK_PLAYBACK) != 0) &&
186 ((flags_new & MASK_PLAYBACK) == 0)) {
187 line6_unlink_audio_out_urbs(line6pcm);
188 kfree(line6pcm->buffer_out);
189 line6pcm->buffer_out = NULL;
190 }
Markus Grabner1027f4762010-08-12 01:35:30 +0200191#if LINE6_BACKUP_MONITOR_SIGNAL
192 if (line6pcm->prev_fbuf != NULL)
193 kfree(line6pcm->prev_fbuf);
194#endif
195
196 return 0;
197}
198
Markus Grabner705ecec2009-02-27 19:43:04 -0800199/* trigger callback */
200int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
201{
202 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800203 struct snd_pcm_substream *s;
204 int err;
205 unsigned long flags;
206
207 spin_lock_irqsave(&line6pcm->lock_trigger, flags);
208 clear_bit(BIT_PREPARED, &line6pcm->flags);
209
Markus Grabner705ecec2009-02-27 19:43:04 -0800210 snd_pcm_group_for_each_entry(s, substream) {
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800211 switch (s->stream) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800212 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner1027f4762010-08-12 01:35:30 +0200213 err = snd_line6_playback_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800214
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800215 if (err < 0) {
216 spin_unlock_irqrestore(&line6pcm->lock_trigger,
217 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800218 return err;
219 }
220
221 break;
222
223 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner1027f4762010-08-12 01:35:30 +0200224 err = snd_line6_capture_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800225
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800226 if (err < 0) {
227 spin_unlock_irqrestore(&line6pcm->lock_trigger,
228 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800229 return err;
230 }
231
232 break;
233
234 default:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200235 dev_err(line6pcm->line6->ifcdev,
236 "Unknown stream direction %d\n", s->stream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800237 }
238 }
239
240 spin_unlock_irqrestore(&line6pcm->lock_trigger, flags);
241 return 0;
242}
243
244/* control info callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200245static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800247{
Markus Grabner705ecec2009-02-27 19:43:04 -0800248 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
249 uinfo->count = 2;
250 uinfo->value.integer.min = 0;
251 uinfo->value.integer.max = 256;
252 return 0;
253}
254
255/* control get callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200256static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800258{
Markus Grabner705ecec2009-02-27 19:43:04 -0800259 int i;
260 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
261
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800262 for (i = 2; i--;)
Markus Grabner1027f4762010-08-12 01:35:30 +0200263 ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800264
265 return 0;
266}
267
268/* control put callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200269static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800271{
Markus Grabner705ecec2009-02-27 19:43:04 -0800272 int i, changed = 0;
273 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
274
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800275 for (i = 2; i--;)
Markus Grabnere1a164d2010-08-23 01:08:25 +0200276 if (line6pcm->volume_playback[i] !=
277 ucontrol->value.integer.value[i]) {
278 line6pcm->volume_playback[i] =
279 ucontrol->value.integer.value[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800280 changed = 1;
281 }
282
283 return changed;
284}
285
286/* control definition */
Markus Grabner1027f4762010-08-12 01:35:30 +0200287static struct snd_kcontrol_new line6_control_playback = {
Markus Grabner705ecec2009-02-27 19:43:04 -0800288 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
289 .name = "PCM Playback Volume",
290 .index = 0,
291 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
Markus Grabner1027f4762010-08-12 01:35:30 +0200292 .info = snd_line6_control_playback_info,
293 .get = snd_line6_control_playback_get,
294 .put = snd_line6_control_playback_put
Markus Grabner705ecec2009-02-27 19:43:04 -0800295};
296
297/*
298 Cleanup the PCM device.
299*/
300static void line6_cleanup_pcm(struct snd_pcm *pcm)
301{
302 int i;
303 struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
304
Markus Grabner1027f4762010-08-12 01:35:30 +0200305#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
306 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_volume);
307 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_period);
308#endif
309
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800310 for (i = LINE6_ISO_BUFFERS; i--;) {
311 if (line6pcm->urb_audio_out[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800312 usb_kill_urb(line6pcm->urb_audio_out[i]);
313 usb_free_urb(line6pcm->urb_audio_out[i]);
314 }
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800315 if (line6pcm->urb_audio_in[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800316 usb_kill_urb(line6pcm->urb_audio_in[i]);
317 usb_free_urb(line6pcm->urb_audio_in[i]);
318 }
319 }
320}
321
322/* create a PCM device */
323static int snd_line6_new_pcm(struct snd_line6_pcm *line6pcm)
324{
325 struct snd_pcm *pcm;
326 int err;
327
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800328 err = snd_pcm_new(line6pcm->line6->card,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200329 (char *)line6pcm->line6->properties->name,
330 0, 1, 1, &pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800331 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800332 return err;
333
334 pcm->private_data = line6pcm;
335 pcm->private_free = line6_cleanup_pcm;
336 line6pcm->pcm = pcm;
337 strcpy(pcm->name, line6pcm->line6->properties->name);
338
339 /* set operators */
Shawn Bohrerafb90912009-11-15 22:17:57 -0600340 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
341 &snd_line6_playback_ops);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200342 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
Markus Grabner705ecec2009-02-27 19:43:04 -0800343
344 /* pre-allocation of buffers */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800345 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200346 snd_dma_continuous_data
347 (GFP_KERNEL), 64 * 1024,
348 128 * 1024);
Markus Grabner705ecec2009-02-27 19:43:04 -0800349
350 return 0;
351}
352
353/* PCM device destructor */
354static int snd_line6_pcm_free(struct snd_device *device)
355{
356 return 0;
357}
358
359/*
Markus Grabner1027f4762010-08-12 01:35:30 +0200360 Stop substream if still running.
361*/
362static void pcm_disconnect_substream(struct snd_pcm_substream *substream)
363{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200364 if (substream->runtime && snd_pcm_running(substream)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200365 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
366 }
367}
368
369/*
370 Stop PCM stream.
371*/
372void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
373{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200374 pcm_disconnect_substream(get_substream
375 (line6pcm, SNDRV_PCM_STREAM_CAPTURE));
376 pcm_disconnect_substream(get_substream
377 (line6pcm, SNDRV_PCM_STREAM_PLAYBACK));
Markus Grabner1027f4762010-08-12 01:35:30 +0200378 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
379 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
380}
381
382/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800383 Create and register the PCM device and mixer entries.
384 Create URBs for playback and capture.
385*/
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800386int line6_init_pcm(struct usb_line6 *line6,
387 struct line6_pcm_properties *properties)
Markus Grabner705ecec2009-02-27 19:43:04 -0800388{
389 static struct snd_device_ops pcm_ops = {
390 .dev_free = snd_line6_pcm_free,
391 };
392
393 int err;
394 int ep_read = 0, ep_write = 0;
395 struct snd_line6_pcm *line6pcm;
396
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800397 if (!(line6->properties->capabilities & LINE6_BIT_PCM))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200398 return 0; /* skip PCM initialization and report success */
Markus Grabner705ecec2009-02-27 19:43:04 -0800399
400 /* initialize PCM subsystem based on product id: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800401 switch (line6->product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800402 case LINE6_DEVID_BASSPODXT:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800403 case LINE6_DEVID_BASSPODXTLIVE:
404 case LINE6_DEVID_BASSPODXTPRO:
405 case LINE6_DEVID_PODXT:
406 case LINE6_DEVID_PODXTLIVE:
407 case LINE6_DEVID_PODXTPRO:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200408 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800409 ep_write = 0x01;
410 break;
411
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800412 case LINE6_DEVID_PODX3:
413 case LINE6_DEVID_PODX3LIVE:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200414 ep_read = 0x86;
Markus Grabner705ecec2009-02-27 19:43:04 -0800415 ep_write = 0x02;
416 break;
417
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800418 case LINE6_DEVID_POCKETPOD:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200419 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800420 ep_write = 0x02;
421 break;
422
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800423 case LINE6_DEVID_GUITARPORT:
Markus Grabner1027f4762010-08-12 01:35:30 +0200424 case LINE6_DEVID_PODSTUDIO_GX:
425 case LINE6_DEVID_PODSTUDIO_UX1:
426 case LINE6_DEVID_PODSTUDIO_UX2:
Markus Grabner705ecec2009-02-27 19:43:04 -0800427 case LINE6_DEVID_TONEPORT_GX:
Markus Grabner1027f4762010-08-12 01:35:30 +0200428 case LINE6_DEVID_TONEPORT_UX1:
429 case LINE6_DEVID_TONEPORT_UX2:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200430 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800431 ep_write = 0x01;
432 break;
433
Markus Grabner1027f4762010-08-12 01:35:30 +0200434 /* this is for interface_number == 1:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200435 case LINE6_DEVID_TONEPORT_UX2:
436 case LINE6_DEVID_PODSTUDIO_UX2:
437 ep_read = 0x87;
438 ep_write = 0x00;
439 break;
440 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800441
442 default:
443 MISSING_CASE;
444 }
445
446 line6pcm = kzalloc(sizeof(struct snd_line6_pcm), GFP_KERNEL);
447
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800448 if (line6pcm == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800449 return -ENOMEM;
450
Markus Grabner1027f4762010-08-12 01:35:30 +0200451 line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
452 line6pcm->volume_monitor = 255;
Markus Grabner705ecec2009-02-27 19:43:04 -0800453 line6pcm->line6 = line6;
454 line6pcm->ep_audio_read = ep_read;
455 line6pcm->ep_audio_write = ep_write;
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800456 line6pcm->max_packet_size = usb_maxpacket(line6->usbdev,
Markus Grabner1027f4762010-08-12 01:35:30 +0200457 usb_rcvintpipe(line6->usbdev,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200458 ep_read), 0);
Markus Grabner705ecec2009-02-27 19:43:04 -0800459 line6pcm->properties = properties;
460 line6->line6pcm = line6pcm;
461
462 /* PCM device: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800463 err = snd_device_new(line6->card, SNDRV_DEV_PCM, line6, &pcm_ops);
464 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800465 return err;
466
467 snd_card_set_dev(line6->card, line6->ifcdev);
468
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800469 err = snd_line6_new_pcm(line6pcm);
470 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800471 return err;
472
473 spin_lock_init(&line6pcm->lock_audio_out);
474 spin_lock_init(&line6pcm->lock_audio_in);
475 spin_lock_init(&line6pcm->lock_trigger);
476
Markus Grabner1027f4762010-08-12 01:35:30 +0200477 err = line6_create_audio_out_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800478 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800479 return err;
480
Markus Grabner1027f4762010-08-12 01:35:30 +0200481 err = line6_create_audio_in_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800482 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800483 return err;
484
485 /* mixer: */
Markus Grabnere1a164d2010-08-23 01:08:25 +0200486 err =
487 snd_ctl_add(line6->card,
488 snd_ctl_new1(&line6_control_playback, line6pcm));
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800489 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800490 return err;
491
Markus Grabner1027f4762010-08-12 01:35:30 +0200492#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
493 /* impulse response test: */
494 err = device_create_file(line6->ifcdev, &dev_attr_impulse_volume);
495 if (err < 0)
496 return err;
497
498 err = device_create_file(line6->ifcdev, &dev_attr_impulse_period);
499 if (err < 0)
500 return err;
501
502 line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
503#endif
504
Markus Grabner705ecec2009-02-27 19:43:04 -0800505 return 0;
506}
507
508/* prepare pcm callback */
509int snd_line6_prepare(struct snd_pcm_substream *substream)
510{
511 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
512
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800513 if (!test_and_set_bit(BIT_PREPARED, &line6pcm->flags)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200514 line6pcm->count_out = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800515 line6pcm->pos_out = 0;
516 line6pcm->pos_out_done = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800517 line6pcm->bytes_out = 0;
Markus Grabner1027f4762010-08-12 01:35:30 +0200518 line6pcm->count_in = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800519 line6pcm->pos_in_done = 0;
520 line6pcm->bytes_in = 0;
521 }
522
523 return 0;
524}