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;
90 struct ToneportSourceInfo
{
95 static const struct ToneportSourceInfo toneport_source_info
[] = {
96 {"Microphone", 0x0a01},
98 {"Instrument", 0x0b01},
99 {"Inst & Mic", 0x0901}
102 static bool toneport_has_led(short product
)
105 (product
== LINE6_DEVID_GUITARPORT
) ||
106 (product
== LINE6_DEVID_TONEPORT_GX
);
107 /* add your device here if you are missing support for the LEDs */
110 static void toneport_update_led(struct device
*dev
)
112 struct usb_interface
*interface
= to_usb_interface(dev
);
113 struct usb_line6_toneport
*tp
= usb_get_intfdata(interface
);
114 struct usb_line6
*line6
;
121 toneport_send_cmd(line6
->usbdev
, (led_red
<< 8) | 0x0002,
125 static ssize_t
toneport_set_led_red(struct device
*dev
,
126 struct device_attribute
*attr
,
127 const char *buf
, size_t count
)
131 retval
= kstrtoint(buf
, 10, &led_red
);
135 toneport_update_led(dev
);
139 static ssize_t
toneport_set_led_green(struct device
*dev
,
140 struct device_attribute
*attr
,
141 const char *buf
, size_t count
)
145 retval
= kstrtoint(buf
, 10, &led_green
);
149 toneport_update_led(dev
);
153 static DEVICE_ATTR(led_red
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
154 toneport_set_led_red
);
155 static DEVICE_ATTR(led_green
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
156 toneport_set_led_green
);
158 static int toneport_send_cmd(struct usb_device
*usbdev
, int cmd1
, int cmd2
)
162 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
163 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
164 cmd1
, cmd2
, NULL
, 0, LINE6_TIMEOUT
* HZ
);
167 dev_err(&usbdev
->dev
, "send failed (error %d)\n", ret
);
174 /* monitor info callback */
175 static int snd_toneport_monitor_info(struct snd_kcontrol
*kcontrol
,
176 struct snd_ctl_elem_info
*uinfo
)
178 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
180 uinfo
->value
.integer
.min
= 0;
181 uinfo
->value
.integer
.max
= 256;
185 /* monitor get callback */
186 static int snd_toneport_monitor_get(struct snd_kcontrol
*kcontrol
,
187 struct snd_ctl_elem_value
*ucontrol
)
189 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
190 ucontrol
->value
.integer
.value
[0] = line6pcm
->volume_monitor
;
194 /* monitor put callback */
195 static int snd_toneport_monitor_put(struct snd_kcontrol
*kcontrol
,
196 struct snd_ctl_elem_value
*ucontrol
)
198 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
200 if (ucontrol
->value
.integer
.value
[0] == line6pcm
->volume_monitor
)
203 line6pcm
->volume_monitor
= ucontrol
->value
.integer
.value
[0];
205 if (line6pcm
->volume_monitor
> 0)
206 line6_pcm_acquire(line6pcm
, LINE6_BITS_PCM_MONITOR
);
208 line6_pcm_release(line6pcm
, LINE6_BITS_PCM_MONITOR
);
213 /* source info callback */
214 static int snd_toneport_source_info(struct snd_kcontrol
*kcontrol
,
215 struct snd_ctl_elem_info
*uinfo
)
217 const int size
= ARRAY_SIZE(toneport_source_info
);
218 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
220 uinfo
->value
.enumerated
.items
= size
;
222 if (uinfo
->value
.enumerated
.item
>= size
)
223 uinfo
->value
.enumerated
.item
= size
- 1;
225 strcpy(uinfo
->value
.enumerated
.name
,
226 toneport_source_info
[uinfo
->value
.enumerated
.item
].name
);
231 /* source get callback */
232 static int snd_toneport_source_get(struct snd_kcontrol
*kcontrol
,
233 struct snd_ctl_elem_value
*ucontrol
)
235 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
236 struct usb_line6_toneport
*toneport
=
237 (struct usb_line6_toneport
*)line6pcm
->line6
;
238 ucontrol
->value
.enumerated
.item
[0] = toneport
->source
;
242 /* source put callback */
243 static int snd_toneport_source_put(struct snd_kcontrol
*kcontrol
,
244 struct snd_ctl_elem_value
*ucontrol
)
246 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
247 struct usb_line6_toneport
*toneport
=
248 (struct usb_line6_toneport
*)line6pcm
->line6
;
250 if (ucontrol
->value
.enumerated
.item
[0] == toneport
->source
)
253 toneport
->source
= ucontrol
->value
.enumerated
.item
[0];
254 toneport_send_cmd(toneport
->line6
.usbdev
,
255 toneport_source_info
[toneport
->source
].code
, 0x0000);
259 static void toneport_start_pcm(unsigned long arg
)
261 struct usb_line6_toneport
*toneport
= (struct usb_line6_toneport
*)arg
;
262 struct usb_line6
*line6
= &toneport
->line6
;
263 line6_pcm_acquire(line6
->line6pcm
, LINE6_BITS_PCM_MONITOR
);
266 /* control definition */
267 static struct snd_kcontrol_new toneport_control_monitor
= {
268 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
269 .name
= "Monitor Playback Volume",
271 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
272 .info
= snd_toneport_monitor_info
,
273 .get
= snd_toneport_monitor_get
,
274 .put
= snd_toneport_monitor_put
277 /* source selector definition */
278 static struct snd_kcontrol_new toneport_control_source
= {
279 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
280 .name
= "PCM Capture Source",
282 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
283 .info
= snd_toneport_source_info
,
284 .get
= snd_toneport_source_get
,
285 .put
= snd_toneport_source_put
291 static void toneport_destruct(struct usb_interface
*interface
)
293 struct usb_line6_toneport
*toneport
= usb_get_intfdata(interface
);
295 if (toneport
== NULL
)
297 line6_cleanup_audio(&toneport
->line6
);
301 Setup Toneport device.
303 static void toneport_setup(struct usb_line6_toneport
*toneport
)
306 struct usb_line6
*line6
= &toneport
->line6
;
307 struct usb_device
*usbdev
= line6
->usbdev
;
309 /* sync time on device with host: */
310 ticks
= (int)get_seconds();
311 line6_write_data(line6
, 0x80c6, &ticks
, 4);
314 toneport_send_cmd(usbdev
, 0x0301, 0x0000);
316 /* initialize source select: */
317 switch (usbdev
->descriptor
.idProduct
) {
318 case LINE6_DEVID_TONEPORT_UX1
:
319 case LINE6_DEVID_TONEPORT_UX2
:
320 case LINE6_DEVID_PODSTUDIO_UX1
:
321 case LINE6_DEVID_PODSTUDIO_UX2
:
322 toneport_send_cmd(usbdev
,
323 toneport_source_info
[toneport
->source
].code
,
327 if (toneport_has_led(usbdev
->descriptor
.idProduct
))
328 toneport_update_led(&usbdev
->dev
);
332 Try to init Toneport device.
334 static int toneport_try_init(struct usb_interface
*interface
,
335 struct usb_line6_toneport
*toneport
)
338 struct usb_line6
*line6
= &toneport
->line6
;
339 struct usb_device
*usbdev
= line6
->usbdev
;
341 if ((interface
== NULL
) || (toneport
== NULL
))
344 /* initialize audio system: */
345 err
= line6_init_audio(line6
);
349 /* initialize PCM subsystem: */
350 err
= line6_init_pcm(line6
, &toneport_pcm_properties
);
354 /* register monitor control: */
355 err
= snd_ctl_add(line6
->card
,
356 snd_ctl_new1(&toneport_control_monitor
,
361 /* register source select control: */
362 switch (usbdev
->descriptor
.idProduct
) {
363 case LINE6_DEVID_TONEPORT_UX1
:
364 case LINE6_DEVID_TONEPORT_UX2
:
365 case LINE6_DEVID_PODSTUDIO_UX1
:
366 case LINE6_DEVID_PODSTUDIO_UX2
:
368 snd_ctl_add(line6
->card
,
369 snd_ctl_new1(&toneport_control_source
,
375 /* register audio system: */
376 err
= line6_register_audio(line6
);
380 line6_read_serial_number(line6
, &toneport
->serial_number
);
381 line6_read_data(line6
, 0x80c2, &toneport
->firmware_version
, 1);
383 if (toneport_has_led(usbdev
->descriptor
.idProduct
)) {
384 CHECK_RETURN(device_create_file
385 (&interface
->dev
, &dev_attr_led_red
));
386 CHECK_RETURN(device_create_file
387 (&interface
->dev
, &dev_attr_led_green
));
390 toneport_setup(toneport
);
392 init_timer(&toneport
->timer
);
393 toneport
->timer
.expires
= jiffies
+ TONEPORT_PCM_DELAY
* HZ
;
394 toneport
->timer
.function
= toneport_start_pcm
;
395 toneport
->timer
.data
= (unsigned long)toneport
;
396 add_timer(&toneport
->timer
);
402 Init Toneport device (and clean up in case of failure).
404 int line6_toneport_init(struct usb_interface
*interface
,
405 struct usb_line6_toneport
*toneport
)
407 int err
= toneport_try_init(interface
, toneport
);
410 toneport_destruct(interface
);
416 Resume Toneport device after reset.
418 void line6_toneport_reset_resume(struct usb_line6_toneport
*toneport
)
420 toneport_setup(toneport
);
424 Toneport device disconnected.
426 void line6_toneport_disconnect(struct usb_interface
*interface
)
428 struct usb_line6_toneport
*toneport
;
430 if (interface
== NULL
)
433 toneport
= usb_get_intfdata(interface
);
434 del_timer_sync(&toneport
->timer
);
436 if (toneport_has_led(toneport
->line6
.usbdev
->descriptor
.idProduct
)) {
437 device_remove_file(&interface
->dev
, &dev_attr_led_red
);
438 device_remove_file(&interface
->dev
, &dev_attr_led_green
);
441 if (toneport
!= NULL
) {
442 struct snd_line6_pcm
*line6pcm
= toneport
->line6
.line6pcm
;
444 if (line6pcm
!= NULL
) {
445 line6_pcm_release(line6pcm
, LINE6_BITS_PCM_MONITOR
);
446 line6_pcm_disconnect(line6pcm
);
450 toneport_destruct(interface
);