2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at)
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.
14 #include <linux/slab.h>
16 #include <sound/core.h>
17 #include <sound/control.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
27 /* trigger callback */
28 int snd_line6_trigger(struct snd_pcm_substream
*substream
, int cmd
)
30 struct snd_line6_pcm
*line6pcm
= snd_pcm_substream_chip(substream
);
31 struct snd_pcm_substream
*s
;
35 spin_lock_irqsave(&line6pcm
->lock_trigger
, flags
);
36 clear_bit(BIT_PREPARED
, &line6pcm
->flags
);
38 snd_pcm_group_for_each_entry(s
, substream
) {
40 case SNDRV_PCM_STREAM_PLAYBACK
:
41 err
= snd_line6_playback_trigger(s
, cmd
);
44 spin_unlock_irqrestore(&line6pcm
->lock_trigger
,
51 case SNDRV_PCM_STREAM_CAPTURE
:
52 err
= snd_line6_capture_trigger(s
, cmd
);
55 spin_unlock_irqrestore(&line6pcm
->lock_trigger
,
63 dev_err(s2m(substream
), "Unknown stream direction %d\n",
68 spin_unlock_irqrestore(&line6pcm
->lock_trigger
, flags
);
72 /* control info callback */
73 static int snd_line6_control_info(struct snd_kcontrol
*kcontrol
,
74 struct snd_ctl_elem_info
*uinfo
)
76 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
78 uinfo
->value
.integer
.min
= 0;
79 uinfo
->value
.integer
.max
= 256;
83 /* control get callback */
84 static int snd_line6_control_get(struct snd_kcontrol
*kcontrol
,
85 struct snd_ctl_elem_value
*ucontrol
)
88 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
91 ucontrol
->value
.integer
.value
[i
] = line6pcm
->volume
[i
];
96 /* control put callback */
97 static int snd_line6_control_put(struct snd_kcontrol
*kcontrol
,
98 struct snd_ctl_elem_value
*ucontrol
)
101 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
104 if (line6pcm
->volume
[i
] != ucontrol
->value
.integer
.value
[i
]) {
105 line6pcm
->volume
[i
] = ucontrol
->value
.integer
.value
[i
];
112 /* control definition */
113 static struct snd_kcontrol_new line6_control
= {
114 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
115 .name
= "PCM Playback Volume",
117 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
118 .info
= snd_line6_control_info
,
119 .get
= snd_line6_control_get
,
120 .put
= snd_line6_control_put
124 Cleanup the PCM device.
126 static void line6_cleanup_pcm(struct snd_pcm
*pcm
)
129 struct snd_line6_pcm
*line6pcm
= snd_pcm_chip(pcm
);
131 for (i
= LINE6_ISO_BUFFERS
; i
--;) {
132 if (line6pcm
->urb_audio_out
[i
]) {
133 usb_kill_urb(line6pcm
->urb_audio_out
[i
]);
134 usb_free_urb(line6pcm
->urb_audio_out
[i
]);
136 if (line6pcm
->urb_audio_in
[i
]) {
137 usb_kill_urb(line6pcm
->urb_audio_in
[i
]);
138 usb_free_urb(line6pcm
->urb_audio_in
[i
]);
143 /* create a PCM device */
144 static int snd_line6_new_pcm(struct snd_line6_pcm
*line6pcm
)
149 err
= snd_pcm_new(line6pcm
->line6
->card
,
150 (char *)line6pcm
->line6
->properties
->name
,
155 pcm
->private_data
= line6pcm
;
156 pcm
->private_free
= line6_cleanup_pcm
;
158 strcpy(pcm
->name
, line6pcm
->line6
->properties
->name
);
161 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
162 &snd_line6_playback_ops
);
163 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_line6_capture_ops
);
165 /* pre-allocation of buffers */
166 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_CONTINUOUS
,
167 snd_dma_continuous_data(GFP_KERNEL
),
168 64 * 1024, 128 * 1024);
173 /* PCM device destructor */
174 static int snd_line6_pcm_free(struct snd_device
*device
)
180 Create and register the PCM device and mixer entries.
181 Create URBs for playback and capture.
183 int line6_init_pcm(struct usb_line6
*line6
,
184 struct line6_pcm_properties
*properties
)
186 static struct snd_device_ops pcm_ops
= {
187 .dev_free
= snd_line6_pcm_free
,
191 int ep_read
= 0, ep_write
= 0;
192 struct snd_line6_pcm
*line6pcm
;
194 if (!(line6
->properties
->capabilities
& LINE6_BIT_PCM
))
195 return 0; /* skip PCM initialization and report success */
197 /* initialize PCM subsystem based on product id: */
198 switch (line6
->product
) {
199 case LINE6_DEVID_BASSPODXT
:
200 case LINE6_DEVID_BASSPODXTLIVE
:
201 case LINE6_DEVID_BASSPODXTPRO
:
202 case LINE6_DEVID_PODXT
:
203 case LINE6_DEVID_PODXTLIVE
:
204 case LINE6_DEVID_PODXTPRO
:
209 case LINE6_DEVID_PODX3
:
210 case LINE6_DEVID_PODX3LIVE
:
215 case LINE6_DEVID_POCKETPOD
:
220 case LINE6_DEVID_GUITARPORT
:
221 case LINE6_DEVID_TONEPORT_GX
:
226 case LINE6_DEVID_TONEPORT_UX1
:
231 case LINE6_DEVID_TONEPORT_UX2
:
240 line6pcm
= kzalloc(sizeof(struct snd_line6_pcm
), GFP_KERNEL
);
242 if (line6pcm
== NULL
)
245 line6pcm
->volume
[0] = line6pcm
->volume
[1] = 128;
246 line6pcm
->line6
= line6
;
247 line6pcm
->ep_audio_read
= ep_read
;
248 line6pcm
->ep_audio_write
= ep_write
;
249 line6pcm
->max_packet_size
= usb_maxpacket(line6
->usbdev
,
250 usb_rcvintpipe(line6
->usbdev
,
253 line6pcm
->properties
= properties
;
254 line6
->line6pcm
= line6pcm
;
257 err
= snd_device_new(line6
->card
, SNDRV_DEV_PCM
, line6
, &pcm_ops
);
261 snd_card_set_dev(line6
->card
, line6
->ifcdev
);
263 err
= snd_line6_new_pcm(line6pcm
);
267 spin_lock_init(&line6pcm
->lock_audio_out
);
268 spin_lock_init(&line6pcm
->lock_audio_in
);
269 spin_lock_init(&line6pcm
->lock_trigger
);
271 err
= create_audio_out_urbs(line6pcm
);
275 err
= create_audio_in_urbs(line6pcm
);
280 err
= snd_ctl_add(line6
->card
, snd_ctl_new1(&line6_control
, line6pcm
));
287 /* prepare pcm callback */
288 int snd_line6_prepare(struct snd_pcm_substream
*substream
)
290 struct snd_line6_pcm
*line6pcm
= snd_pcm_substream_chip(substream
);
292 if (!test_and_set_bit(BIT_PREPARED
, &line6pcm
->flags
)) {
293 unlink_wait_clear_audio_out_urbs(line6pcm
);
294 line6pcm
->pos_out
= 0;
295 line6pcm
->pos_out_done
= 0;
297 unlink_wait_clear_audio_in_urbs(line6pcm
);
298 line6pcm
->bytes_out
= 0;
299 line6pcm
->pos_in_done
= 0;
300 line6pcm
->bytes_in
= 0;