blob: 90d2d4475cb4eba57fbd6cb3896c614570e3bc8a [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 Grabner0ca54882012-01-20 00:09:09 +010055 line6_pcm_acquire(line6pcm, LINE6_BITS_PCM_IMPULSE);
Markus Grabner1027f4762010-08-12 01:35:30 +020056 else
Markus Grabner0ca54882012-01-20 00:09:09 +010057 line6_pcm_release(line6pcm, LINE6_BITS_PCM_IMPULSE);
Markus Grabner1027f4762010-08-12 01:35:30 +020058
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
Markus Grabner6b02a17e2011-12-10 02:12:32 +010089static bool test_flags(unsigned long flags0, unsigned long flags1,
90 unsigned long mask)
91{
92 return ((flags0 & mask) == 0) && ((flags1 & mask) != 0);
93}
94
Markus Grabner0ca54882012-01-20 00:09:09 +010095int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
Markus Grabner1027f4762010-08-12 01:35:30 +020096{
Markus Grabnere1a164d2010-08-23 01:08:25 +020097 unsigned long flags_old =
98 __sync_fetch_and_or(&line6pcm->flags, channels);
Markus Grabner1027f4762010-08-12 01:35:30 +020099 unsigned long flags_new = flags_old | channels;
Markus Grabner0ca54882012-01-20 00:09:09 +0100100 unsigned long flags_final = flags_old;
Markus Grabner1027f4762010-08-12 01:35:30 +0200101 int err = 0;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100102
Markus Grabner1027f4762010-08-12 01:35:30 +0200103 line6pcm->prev_fbuf = NULL;
Markus Grabnere1a164d2010-08-23 01:08:25 +0200104
Markus Grabner0ca54882012-01-20 00:09:09 +0100105 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_BUFFER)) {
106 /* We may be invoked multiple times in a row so allocate once only */
107 if (!line6pcm->buffer_in) {
108 line6pcm->buffer_in =
109 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
110 line6pcm->max_packet_size, GFP_KERNEL);
111
112 if (!line6pcm->buffer_in) {
113 dev_err(line6pcm->line6->ifcdev,
114 "cannot malloc capture buffer\n");
115 err = -ENOMEM;
116 goto pcm_acquire_error;
117 }
118
119 flags_final |= channels & LINE6_BITS_CAPTURE_BUFFER;
120 }
121 }
122
123 if (test_flags(flags_old, flags_new, LINE6_BITS_CAPTURE_STREAM)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200124 /*
Markus Grabnere1a164d2010-08-23 01:08:25 +0200125 Waiting for completion of active URBs in the stop handler is
126 a bug, we therefore report an error if capturing is restarted
127 too soon.
128 */
Markus Grabner0ca54882012-01-20 00:09:09 +0100129 if (line6pcm->active_urb_in | line6pcm->unlink_urb_in) {
130 dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200131 return -EBUSY;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100132 }
133
Markus Grabner1027f4762010-08-12 01:35:30 +0200134 line6pcm->count_in = 0;
135 line6pcm->prev_fsize = 0;
136 err = line6_submit_audio_in_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200137
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100138 if (err < 0)
Markus Grabner0ca54882012-01-20 00:09:09 +0100139 goto pcm_acquire_error;
140
141 flags_final |= channels & LINE6_BITS_CAPTURE_STREAM;
Markus Grabner1027f4762010-08-12 01:35:30 +0200142 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200143
Markus Grabner0ca54882012-01-20 00:09:09 +0100144 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_BUFFER)) {
145 /* We may be invoked multiple times in a row so allocate once only */
146 if (!line6pcm->buffer_out) {
147 line6pcm->buffer_out =
148 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
149 line6pcm->max_packet_size, GFP_KERNEL);
150
151 if (!line6pcm->buffer_out) {
152 dev_err(line6pcm->line6->ifcdev,
153 "cannot malloc playback buffer\n");
154 err = -ENOMEM;
155 goto pcm_acquire_error;
156 }
157
158 flags_final |= channels & LINE6_BITS_PLAYBACK_BUFFER;
159 }
160 }
161
162 if (test_flags(flags_old, flags_new, LINE6_BITS_PLAYBACK_STREAM)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200163 /*
Markus Grabner0ca54882012-01-20 00:09:09 +0100164 See comment above regarding PCM restart.
165 */
166 if (line6pcm->active_urb_out | line6pcm->unlink_urb_out) {
167 dev_err(line6pcm->line6->ifcdev, "Device not yet ready\n");
Markus Grabner1027f4762010-08-12 01:35:30 +0200168 return -EBUSY;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100169 }
170
Markus Grabner1027f4762010-08-12 01:35:30 +0200171 line6pcm->count_out = 0;
172 err = line6_submit_audio_out_all_urbs(line6pcm);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200173
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100174 if (err < 0)
Markus Grabner0ca54882012-01-20 00:09:09 +0100175 goto pcm_acquire_error;
176
177 flags_final |= channels & LINE6_BITS_PLAYBACK_STREAM;
Markus Grabner1027f4762010-08-12 01:35:30 +0200178 }
Markus Grabnere1a164d2010-08-23 01:08:25 +0200179
Markus Grabner1027f4762010-08-12 01:35:30 +0200180 return 0;
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100181
Markus Grabner0ca54882012-01-20 00:09:09 +0100182pcm_acquire_error:
183 /*
184 If not all requested resources/streams could be obtained, release
185 those which were successfully obtained (if any).
186 */
187 line6_pcm_release(line6pcm, flags_final & channels);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100188 return err;
Markus Grabner1027f4762010-08-12 01:35:30 +0200189}
190
Markus Grabner0ca54882012-01-20 00:09:09 +0100191int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels)
Markus Grabner1027f4762010-08-12 01:35:30 +0200192{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200193 unsigned long flags_old =
194 __sync_fetch_and_and(&line6pcm->flags, ~channels);
Markus Grabner1027f4762010-08-12 01:35:30 +0200195 unsigned long flags_new = flags_old & ~channels;
196
Markus Grabner0ca54882012-01-20 00:09:09 +0100197 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_STREAM))
Markus Grabner1027f4762010-08-12 01:35:30 +0200198 line6_unlink_audio_in_urbs(line6pcm);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100199
Markus Grabner0ca54882012-01-20 00:09:09 +0100200 if (test_flags(flags_new, flags_old, LINE6_BITS_CAPTURE_BUFFER)) {
201 line6_wait_clear_audio_in_urbs(line6pcm);
202 line6_free_capture_buffer(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200203 }
204
Markus Grabner0ca54882012-01-20 00:09:09 +0100205 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_STREAM))
Markus Grabner1027f4762010-08-12 01:35:30 +0200206 line6_unlink_audio_out_urbs(line6pcm);
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100207
Markus Grabner0ca54882012-01-20 00:09:09 +0100208 if (test_flags(flags_new, flags_old, LINE6_BITS_PLAYBACK_BUFFER)) {
209 line6_wait_clear_audio_out_urbs(line6pcm);
210 line6_free_playback_buffer(line6pcm);
Markus Grabner1027f4762010-08-12 01:35:30 +0200211 }
Markus Grabner1027f4762010-08-12 01:35:30 +0200212
213 return 0;
214}
215
Markus Grabner705ecec2009-02-27 19:43:04 -0800216/* trigger callback */
217int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd)
218{
219 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800220 struct snd_pcm_substream *s;
221 int err;
222 unsigned long flags;
223
224 spin_lock_irqsave(&line6pcm->lock_trigger, flags);
Markus Grabner0ca54882012-01-20 00:09:09 +0100225 clear_bit(LINE6_INDEX_PREPARED, &line6pcm->flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800226
Markus Grabner705ecec2009-02-27 19:43:04 -0800227 snd_pcm_group_for_each_entry(s, substream) {
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800228 switch (s->stream) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800229 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner1027f4762010-08-12 01:35:30 +0200230 err = snd_line6_playback_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800231
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800232 if (err < 0) {
233 spin_unlock_irqrestore(&line6pcm->lock_trigger,
234 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800235 return err;
236 }
237
238 break;
239
240 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner1027f4762010-08-12 01:35:30 +0200241 err = snd_line6_capture_trigger(line6pcm, cmd);
Markus Grabner705ecec2009-02-27 19:43:04 -0800242
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800243 if (err < 0) {
244 spin_unlock_irqrestore(&line6pcm->lock_trigger,
245 flags);
Markus Grabner705ecec2009-02-27 19:43:04 -0800246 return err;
247 }
248
249 break;
250
251 default:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200252 dev_err(line6pcm->line6->ifcdev,
253 "Unknown stream direction %d\n", s->stream);
Markus Grabner705ecec2009-02-27 19:43:04 -0800254 }
255 }
256
257 spin_unlock_irqrestore(&line6pcm->lock_trigger, flags);
258 return 0;
259}
260
261/* control info callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200262static int snd_line6_control_playback_info(struct snd_kcontrol *kcontrol,
263 struct snd_ctl_elem_info *uinfo)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800264{
Markus Grabner705ecec2009-02-27 19:43:04 -0800265 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
266 uinfo->count = 2;
267 uinfo->value.integer.min = 0;
268 uinfo->value.integer.max = 256;
269 return 0;
270}
271
272/* control get callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200273static int snd_line6_control_playback_get(struct snd_kcontrol *kcontrol,
274 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800275{
Markus Grabner705ecec2009-02-27 19:43:04 -0800276 int i;
277 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
278
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800279 for (i = 2; i--;)
Markus Grabner1027f4762010-08-12 01:35:30 +0200280 ucontrol->value.integer.value[i] = line6pcm->volume_playback[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800281
282 return 0;
283}
284
285/* control put callback */
Markus Grabner1027f4762010-08-12 01:35:30 +0200286static int snd_line6_control_playback_put(struct snd_kcontrol *kcontrol,
287 struct snd_ctl_elem_value *ucontrol)
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800288{
Markus Grabner705ecec2009-02-27 19:43:04 -0800289 int i, changed = 0;
290 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
291
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800292 for (i = 2; i--;)
Markus Grabnere1a164d2010-08-23 01:08:25 +0200293 if (line6pcm->volume_playback[i] !=
294 ucontrol->value.integer.value[i]) {
295 line6pcm->volume_playback[i] =
296 ucontrol->value.integer.value[i];
Markus Grabner705ecec2009-02-27 19:43:04 -0800297 changed = 1;
298 }
299
300 return changed;
301}
302
303/* control definition */
Markus Grabner1027f4762010-08-12 01:35:30 +0200304static struct snd_kcontrol_new line6_control_playback = {
Markus Grabner705ecec2009-02-27 19:43:04 -0800305 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
306 .name = "PCM Playback Volume",
307 .index = 0,
308 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
Markus Grabner1027f4762010-08-12 01:35:30 +0200309 .info = snd_line6_control_playback_info,
310 .get = snd_line6_control_playback_get,
311 .put = snd_line6_control_playback_put
Markus Grabner705ecec2009-02-27 19:43:04 -0800312};
313
314/*
315 Cleanup the PCM device.
316*/
317static void line6_cleanup_pcm(struct snd_pcm *pcm)
318{
319 int i;
320 struct snd_line6_pcm *line6pcm = snd_pcm_chip(pcm);
321
Markus Grabner1027f4762010-08-12 01:35:30 +0200322#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
323 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_volume);
324 device_remove_file(line6pcm->line6->ifcdev, &dev_attr_impulse_period);
325#endif
326
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800327 for (i = LINE6_ISO_BUFFERS; i--;) {
328 if (line6pcm->urb_audio_out[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800329 usb_kill_urb(line6pcm->urb_audio_out[i]);
330 usb_free_urb(line6pcm->urb_audio_out[i]);
331 }
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800332 if (line6pcm->urb_audio_in[i]) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800333 usb_kill_urb(line6pcm->urb_audio_in[i]);
334 usb_free_urb(line6pcm->urb_audio_in[i]);
335 }
336 }
337}
338
339/* create a PCM device */
340static int snd_line6_new_pcm(struct snd_line6_pcm *line6pcm)
341{
342 struct snd_pcm *pcm;
343 int err;
344
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800345 err = snd_pcm_new(line6pcm->line6->card,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200346 (char *)line6pcm->line6->properties->name,
347 0, 1, 1, &pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800348 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800349 return err;
350
351 pcm->private_data = line6pcm;
352 pcm->private_free = line6_cleanup_pcm;
353 line6pcm->pcm = pcm;
354 strcpy(pcm->name, line6pcm->line6->properties->name);
355
356 /* set operators */
Shawn Bohrerafb90912009-11-15 22:17:57 -0600357 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
358 &snd_line6_playback_ops);
Markus Grabnere1a164d2010-08-23 01:08:25 +0200359 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_line6_capture_ops);
Markus Grabner705ecec2009-02-27 19:43:04 -0800360
361 /* pre-allocation of buffers */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800362 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
Markus Grabnere1a164d2010-08-23 01:08:25 +0200363 snd_dma_continuous_data
364 (GFP_KERNEL), 64 * 1024,
365 128 * 1024);
Markus Grabner705ecec2009-02-27 19:43:04 -0800366
367 return 0;
368}
369
370/* PCM device destructor */
371static int snd_line6_pcm_free(struct snd_device *device)
372{
373 return 0;
374}
375
376/*
Markus Grabner1027f4762010-08-12 01:35:30 +0200377 Stop substream if still running.
378*/
379static void pcm_disconnect_substream(struct snd_pcm_substream *substream)
380{
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -0700381 if (substream->runtime && snd_pcm_running(substream))
Markus Grabner1027f4762010-08-12 01:35:30 +0200382 snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
Markus Grabner1027f4762010-08-12 01:35:30 +0200383}
384
385/*
386 Stop PCM stream.
387*/
388void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm)
389{
Markus Grabnere1a164d2010-08-23 01:08:25 +0200390 pcm_disconnect_substream(get_substream
391 (line6pcm, SNDRV_PCM_STREAM_CAPTURE));
392 pcm_disconnect_substream(get_substream
393 (line6pcm, SNDRV_PCM_STREAM_PLAYBACK));
Markus Grabner1027f4762010-08-12 01:35:30 +0200394 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
395 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
396}
397
398/*
Markus Grabner705ecec2009-02-27 19:43:04 -0800399 Create and register the PCM device and mixer entries.
400 Create URBs for playback and capture.
401*/
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800402int line6_init_pcm(struct usb_line6 *line6,
403 struct line6_pcm_properties *properties)
Markus Grabner705ecec2009-02-27 19:43:04 -0800404{
405 static struct snd_device_ops pcm_ops = {
406 .dev_free = snd_line6_pcm_free,
407 };
408
409 int err;
410 int ep_read = 0, ep_write = 0;
411 struct snd_line6_pcm *line6pcm;
412
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800413 if (!(line6->properties->capabilities & LINE6_BIT_PCM))
Markus Grabnere1a164d2010-08-23 01:08:25 +0200414 return 0; /* skip PCM initialization and report success */
Markus Grabner705ecec2009-02-27 19:43:04 -0800415
416 /* initialize PCM subsystem based on product id: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800417 switch (line6->product) {
Markus Grabner705ecec2009-02-27 19:43:04 -0800418 case LINE6_DEVID_BASSPODXT:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800419 case LINE6_DEVID_BASSPODXTLIVE:
420 case LINE6_DEVID_BASSPODXTPRO:
421 case LINE6_DEVID_PODXT:
422 case LINE6_DEVID_PODXTLIVE:
423 case LINE6_DEVID_PODXTPRO:
Stefan Hajnoczi16dc1042011-11-23 08:20:42 +0000424 case LINE6_DEVID_PODHD300:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200425 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800426 ep_write = 0x01;
427 break;
428
Markus Grabner4c6fb5f2011-12-05 23:51:53 +0100429 case LINE6_DEVID_PODHD500:
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800430 case LINE6_DEVID_PODX3:
431 case LINE6_DEVID_PODX3LIVE:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200432 ep_read = 0x86;
Markus Grabner705ecec2009-02-27 19:43:04 -0800433 ep_write = 0x02;
434 break;
435
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800436 case LINE6_DEVID_POCKETPOD:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200437 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800438 ep_write = 0x02;
439 break;
440
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800441 case LINE6_DEVID_GUITARPORT:
Markus Grabner1027f4762010-08-12 01:35:30 +0200442 case LINE6_DEVID_PODSTUDIO_GX:
443 case LINE6_DEVID_PODSTUDIO_UX1:
444 case LINE6_DEVID_PODSTUDIO_UX2:
Markus Grabner705ecec2009-02-27 19:43:04 -0800445 case LINE6_DEVID_TONEPORT_GX:
Markus Grabner1027f4762010-08-12 01:35:30 +0200446 case LINE6_DEVID_TONEPORT_UX1:
447 case LINE6_DEVID_TONEPORT_UX2:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200448 ep_read = 0x82;
Markus Grabner705ecec2009-02-27 19:43:04 -0800449 ep_write = 0x01;
450 break;
451
Markus Grabner1027f4762010-08-12 01:35:30 +0200452 /* this is for interface_number == 1:
Markus Grabnere1a164d2010-08-23 01:08:25 +0200453 case LINE6_DEVID_TONEPORT_UX2:
454 case LINE6_DEVID_PODSTUDIO_UX2:
455 ep_read = 0x87;
456 ep_write = 0x00;
457 break;
458 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800459
460 default:
461 MISSING_CASE;
462 }
463
464 line6pcm = kzalloc(sizeof(struct snd_line6_pcm), GFP_KERNEL);
465
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800466 if (line6pcm == NULL)
Markus Grabner705ecec2009-02-27 19:43:04 -0800467 return -ENOMEM;
468
Markus Grabner1027f4762010-08-12 01:35:30 +0200469 line6pcm->volume_playback[0] = line6pcm->volume_playback[1] = 255;
470 line6pcm->volume_monitor = 255;
Markus Grabner705ecec2009-02-27 19:43:04 -0800471 line6pcm->line6 = line6;
472 line6pcm->ep_audio_read = ep_read;
473 line6pcm->ep_audio_write = ep_write;
Stefan Hajnoczi3b08db32011-11-23 08:20:44 +0000474
475 /* Read and write buffers are sized identically, so choose minimum */
476 line6pcm->max_packet_size = min(
477 usb_maxpacket(line6->usbdev,
478 usb_rcvisocpipe(line6->usbdev, ep_read), 0),
479 usb_maxpacket(line6->usbdev,
480 usb_sndisocpipe(line6->usbdev, ep_write), 1));
481
Markus Grabner705ecec2009-02-27 19:43:04 -0800482 line6pcm->properties = properties;
483 line6->line6pcm = line6pcm;
484
485 /* PCM device: */
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800486 err = snd_device_new(line6->card, SNDRV_DEV_PCM, line6, &pcm_ops);
487 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800488 return err;
489
490 snd_card_set_dev(line6->card, line6->ifcdev);
491
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800492 err = snd_line6_new_pcm(line6pcm);
493 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800494 return err;
495
496 spin_lock_init(&line6pcm->lock_audio_out);
497 spin_lock_init(&line6pcm->lock_audio_in);
498 spin_lock_init(&line6pcm->lock_trigger);
499
Markus Grabner1027f4762010-08-12 01:35:30 +0200500 err = line6_create_audio_out_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800501 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800502 return err;
503
Markus Grabner1027f4762010-08-12 01:35:30 +0200504 err = line6_create_audio_in_urbs(line6pcm);
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800505 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800506 return err;
507
508 /* mixer: */
Markus Grabnere1a164d2010-08-23 01:08:25 +0200509 err =
510 snd_ctl_add(line6->card,
511 snd_ctl_new1(&line6_control_playback, line6pcm));
Greg Kroah-Hartman68dc3dd2009-02-27 22:43:30 -0800512 if (err < 0)
Markus Grabner705ecec2009-02-27 19:43:04 -0800513 return err;
514
Markus Grabner1027f4762010-08-12 01:35:30 +0200515#ifdef CONFIG_LINE6_USB_IMPULSE_RESPONSE
516 /* impulse response test: */
517 err = device_create_file(line6->ifcdev, &dev_attr_impulse_volume);
518 if (err < 0)
519 return err;
520
521 err = device_create_file(line6->ifcdev, &dev_attr_impulse_period);
522 if (err < 0)
523 return err;
524
525 line6pcm->impulse_period = LINE6_IMPULSE_DEFAULT_PERIOD;
526#endif
527
Markus Grabner705ecec2009-02-27 19:43:04 -0800528 return 0;
529}
530
531/* prepare pcm callback */
532int snd_line6_prepare(struct snd_pcm_substream *substream)
533{
534 struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream);
535
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100536 switch (substream->stream) {
537 case SNDRV_PCM_STREAM_PLAYBACK:
Markus Grabner0ca54882012-01-20 00:09:09 +0100538 if ((line6pcm->flags & LINE6_BITS_PLAYBACK_STREAM) == 0)
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100539 line6_unlink_wait_clear_audio_out_urbs(line6pcm);
540
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100541 break;
542
543 case SNDRV_PCM_STREAM_CAPTURE:
Markus Grabner0ca54882012-01-20 00:09:09 +0100544 if ((line6pcm->flags & LINE6_BITS_CAPTURE_STREAM) == 0)
Markus Grabner6b02a17e2011-12-10 02:12:32 +0100545 line6_unlink_wait_clear_audio_in_urbs(line6pcm);
546
Stefan Hajnoczi665f3f52011-12-10 02:12:31 +0100547 break;
548
549 default:
550 MISSING_CASE;
551 }
552
Markus Grabner0ca54882012-01-20 00:09:09 +0100553 if (!test_and_set_bit(LINE6_INDEX_PREPARED, &line6pcm->flags)) {
Markus Grabner1027f4762010-08-12 01:35:30 +0200554 line6pcm->count_out = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800555 line6pcm->pos_out = 0;
556 line6pcm->pos_out_done = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800557 line6pcm->bytes_out = 0;
Markus Grabner1027f4762010-08-12 01:35:30 +0200558 line6pcm->count_in = 0;
Markus Grabner705ecec2009-02-27 19:43:04 -0800559 line6pcm->pos_in_done = 0;
560 line6pcm->bytes_in = 0;
561 }
562
563 return 0;
564}