2 * Line6 Linux USB driver - 0.9.1beta
4 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
5 * Emil Myhrman (emil.myhrman@gmail.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
13 #include <linux/wait.h>
14 #include <sound/control.h>
22 static int toneport_send_cmd(struct usb_device
*usbdev
, int cmd1
, int cmd2
);
24 #define TONEPORT_PCM_DELAY 1
26 static struct snd_ratden toneport_ratden
= {
33 static struct line6_pcm_properties toneport_pcm_properties
= {
34 .snd_line6_playback_hw
= {
35 .info
= (SNDRV_PCM_INFO_MMAP
|
36 SNDRV_PCM_INFO_INTERLEAVED
|
37 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
38 SNDRV_PCM_INFO_MMAP_VALID
|
39 SNDRV_PCM_INFO_PAUSE
|
41 SNDRV_PCM_INFO_RESUME
|
43 SNDRV_PCM_INFO_SYNC_START
),
44 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
45 .rates
= SNDRV_PCM_RATE_KNOT
,
50 .buffer_bytes_max
= 60000,
51 .period_bytes_min
= 64,
52 .period_bytes_max
= 8192,
55 .snd_line6_capture_hw
= {
56 .info
= (SNDRV_PCM_INFO_MMAP
|
57 SNDRV_PCM_INFO_INTERLEAVED
|
58 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
59 SNDRV_PCM_INFO_MMAP_VALID
|
61 SNDRV_PCM_INFO_RESUME
|
63 SNDRV_PCM_INFO_SYNC_START
),
64 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
65 .rates
= SNDRV_PCM_RATE_KNOT
,
70 .buffer_bytes_max
= 60000,
71 .period_bytes_min
= 64,
72 .period_bytes_max
= 8192,
77 .rats
= &toneport_ratden
},
82 For the led on Guitarport.
83 Brightness goes from 0x00 to 0x26. Set a value above this to have led
85 (void cmd_0x02(byte red, byte green)
87 static int led_red
= 0x00;
88 static int led_green
= 0x26;
93 } toneport_source_info
[] = {
94 {"Microphone", 0x0a01},
96 {"Instrument", 0x0b01},
97 {"Inst & Mic", 0x0901}
100 static bool toneport_has_led(short product
)
103 (product
== LINE6_DEVID_GUITARPORT
) ||
104 (product
== LINE6_DEVID_TONEPORT_GX
);
105 /* add your device here if you are missing support for the LEDs */
108 static void toneport_update_led(struct device
*dev
)
110 struct usb_interface
*interface
= to_usb_interface(dev
);
111 struct usb_line6_toneport
*tp
= usb_get_intfdata(interface
);
112 struct usb_line6
*line6
;
119 toneport_send_cmd(line6
->usbdev
, (led_red
<< 8) | 0x0002,
123 static ssize_t
toneport_set_led_red(struct device
*dev
,
124 struct device_attribute
*attr
,
125 const char *buf
, size_t count
)
129 retval
= kstrtoint(buf
, 10, &led_red
);
133 toneport_update_led(dev
);
137 static ssize_t
toneport_set_led_green(struct device
*dev
,
138 struct device_attribute
*attr
,
139 const char *buf
, size_t count
)
143 retval
= kstrtoint(buf
, 10, &led_green
);
147 toneport_update_led(dev
);
151 static DEVICE_ATTR(led_red
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
152 toneport_set_led_red
);
153 static DEVICE_ATTR(led_green
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
154 toneport_set_led_green
);
156 static int toneport_send_cmd(struct usb_device
*usbdev
, int cmd1
, int cmd2
)
160 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
161 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
162 cmd1
, cmd2
, NULL
, 0, LINE6_TIMEOUT
* HZ
);
165 dev_err(&usbdev
->dev
, "send failed (error %d)\n", ret
);
172 /* monitor info callback */
173 static int snd_toneport_monitor_info(struct snd_kcontrol
*kcontrol
,
174 struct snd_ctl_elem_info
*uinfo
)
176 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
178 uinfo
->value
.integer
.min
= 0;
179 uinfo
->value
.integer
.max
= 256;
183 /* monitor get callback */
184 static int snd_toneport_monitor_get(struct snd_kcontrol
*kcontrol
,
185 struct snd_ctl_elem_value
*ucontrol
)
187 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
188 ucontrol
->value
.integer
.value
[0] = line6pcm
->volume_monitor
;
192 /* monitor put callback */
193 static int snd_toneport_monitor_put(struct snd_kcontrol
*kcontrol
,
194 struct snd_ctl_elem_value
*ucontrol
)
196 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
198 if (ucontrol
->value
.integer
.value
[0] == line6pcm
->volume_monitor
)
201 line6pcm
->volume_monitor
= ucontrol
->value
.integer
.value
[0];
203 if (line6pcm
->volume_monitor
> 0)
204 line6_pcm_acquire(line6pcm
, LINE6_BITS_PCM_MONITOR
);
206 line6_pcm_release(line6pcm
, LINE6_BITS_PCM_MONITOR
);
211 /* source info callback */
212 static int snd_toneport_source_info(struct snd_kcontrol
*kcontrol
,
213 struct snd_ctl_elem_info
*uinfo
)
215 const int size
= ARRAY_SIZE(toneport_source_info
);
216 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
218 uinfo
->value
.enumerated
.items
= size
;
220 if (uinfo
->value
.enumerated
.item
>= size
)
221 uinfo
->value
.enumerated
.item
= size
- 1;
223 strcpy(uinfo
->value
.enumerated
.name
,
224 toneport_source_info
[uinfo
->value
.enumerated
.item
].name
);
229 /* source get callback */
230 static int snd_toneport_source_get(struct snd_kcontrol
*kcontrol
,
231 struct snd_ctl_elem_value
*ucontrol
)
233 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
234 struct usb_line6_toneport
*toneport
=
235 (struct usb_line6_toneport
*)line6pcm
->line6
;
236 ucontrol
->value
.enumerated
.item
[0] = toneport
->source
;
240 /* source put callback */
241 static int snd_toneport_source_put(struct snd_kcontrol
*kcontrol
,
242 struct snd_ctl_elem_value
*ucontrol
)
244 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
245 struct usb_line6_toneport
*toneport
=
246 (struct usb_line6_toneport
*)line6pcm
->line6
;
248 if (ucontrol
->value
.enumerated
.item
[0] == toneport
->source
)
251 toneport
->source
= ucontrol
->value
.enumerated
.item
[0];
252 toneport_send_cmd(toneport
->line6
.usbdev
,
253 toneport_source_info
[toneport
->source
].code
, 0x0000);
257 static void toneport_start_pcm(unsigned long arg
)
259 struct usb_line6_toneport
*toneport
= (struct usb_line6_toneport
*)arg
;
260 struct usb_line6
*line6
= &toneport
->line6
;
261 line6_pcm_acquire(line6
->line6pcm
, LINE6_BITS_PCM_MONITOR
);
264 /* control definition */
265 static struct snd_kcontrol_new toneport_control_monitor
= {
266 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
267 .name
= "Monitor Playback Volume",
269 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
270 .info
= snd_toneport_monitor_info
,
271 .get
= snd_toneport_monitor_get
,
272 .put
= snd_toneport_monitor_put
275 /* source selector definition */
276 static struct snd_kcontrol_new toneport_control_source
= {
277 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
278 .name
= "PCM Capture Source",
280 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
281 .info
= snd_toneport_source_info
,
282 .get
= snd_toneport_source_get
,
283 .put
= snd_toneport_source_put
289 static void toneport_destruct(struct usb_interface
*interface
)
291 struct usb_line6_toneport
*toneport
= usb_get_intfdata(interface
);
293 if (toneport
== NULL
)
295 line6_cleanup_audio(&toneport
->line6
);
299 Setup Toneport device.
301 static void toneport_setup(struct usb_line6_toneport
*toneport
)
304 struct usb_line6
*line6
= &toneport
->line6
;
305 struct usb_device
*usbdev
= line6
->usbdev
;
307 /* sync time on device with host: */
308 ticks
= (int)get_seconds();
309 line6_write_data(line6
, 0x80c6, &ticks
, 4);
312 toneport_send_cmd(usbdev
, 0x0301, 0x0000);
314 /* initialize source select: */
315 switch (usbdev
->descriptor
.idProduct
) {
316 case LINE6_DEVID_TONEPORT_UX1
:
317 case LINE6_DEVID_TONEPORT_UX2
:
318 case LINE6_DEVID_PODSTUDIO_UX1
:
319 case LINE6_DEVID_PODSTUDIO_UX2
:
320 toneport_send_cmd(usbdev
,
321 toneport_source_info
[toneport
->source
].code
,
325 if (toneport_has_led(usbdev
->descriptor
.idProduct
))
326 toneport_update_led(&usbdev
->dev
);
330 Try to init Toneport device.
332 static int toneport_try_init(struct usb_interface
*interface
,
333 struct usb_line6_toneport
*toneport
)
336 struct usb_line6
*line6
= &toneport
->line6
;
337 struct usb_device
*usbdev
= line6
->usbdev
;
339 if ((interface
== NULL
) || (toneport
== NULL
))
342 /* initialize audio system: */
343 err
= line6_init_audio(line6
);
347 /* initialize PCM subsystem: */
348 err
= line6_init_pcm(line6
, &toneport_pcm_properties
);
352 /* register monitor control: */
353 err
= snd_ctl_add(line6
->card
,
354 snd_ctl_new1(&toneport_control_monitor
,
359 /* register source select control: */
360 switch (usbdev
->descriptor
.idProduct
) {
361 case LINE6_DEVID_TONEPORT_UX1
:
362 case LINE6_DEVID_TONEPORT_UX2
:
363 case LINE6_DEVID_PODSTUDIO_UX1
:
364 case LINE6_DEVID_PODSTUDIO_UX2
:
366 snd_ctl_add(line6
->card
,
367 snd_ctl_new1(&toneport_control_source
,
373 /* register audio system: */
374 err
= line6_register_audio(line6
);
378 line6_read_serial_number(line6
, &toneport
->serial_number
);
379 line6_read_data(line6
, 0x80c2, &toneport
->firmware_version
, 1);
381 if (toneport_has_led(usbdev
->descriptor
.idProduct
)) {
382 CHECK_RETURN(device_create_file
383 (&interface
->dev
, &dev_attr_led_red
));
384 CHECK_RETURN(device_create_file
385 (&interface
->dev
, &dev_attr_led_green
));
388 toneport_setup(toneport
);
390 init_timer(&toneport
->timer
);
391 toneport
->timer
.expires
= jiffies
+ TONEPORT_PCM_DELAY
* HZ
;
392 toneport
->timer
.function
= toneport_start_pcm
;
393 toneport
->timer
.data
= (unsigned long)toneport
;
394 add_timer(&toneport
->timer
);
400 Init Toneport device (and clean up in case of failure).
402 int line6_toneport_init(struct usb_interface
*interface
,
403 struct usb_line6_toneport
*toneport
)
405 int err
= toneport_try_init(interface
, toneport
);
408 toneport_destruct(interface
);
414 Resume Toneport device after reset.
416 void line6_toneport_reset_resume(struct usb_line6_toneport
*toneport
)
418 toneport_setup(toneport
);
422 Toneport device disconnected.
424 void line6_toneport_disconnect(struct usb_interface
*interface
)
426 struct usb_line6_toneport
*toneport
;
428 if (interface
== NULL
)
431 toneport
= usb_get_intfdata(interface
);
432 del_timer_sync(&toneport
->timer
);
434 if (toneport_has_led(toneport
->line6
.usbdev
->descriptor
.idProduct
)) {
435 device_remove_file(&interface
->dev
, &dev_attr_led_red
);
436 device_remove_file(&interface
->dev
, &dev_attr_led_green
);
439 if (toneport
!= NULL
) {
440 struct snd_line6_pcm
*line6pcm
= toneport
->line6
.line6pcm
;
442 if (line6pcm
!= NULL
) {
443 line6_pcm_release(line6pcm
, LINE6_BITS_PCM_MONITOR
);
444 line6_pcm_disconnect(line6pcm
);
448 toneport_destruct(interface
);