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 <linux/usb.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <sound/core.h>
18 #include <sound/control.h>
25 enum line6_device_type
{
35 struct usb_line6_toneport
{
37 Generic Line6 USB data.
39 struct usb_line6 line6
;
47 Serial number of device.
52 Firmware version (x 100).
57 Timer for delayed PCM startup.
59 struct timer_list timer
;
64 enum line6_device_type type
;
67 static int toneport_send_cmd(struct usb_device
*usbdev
, int cmd1
, int cmd2
);
69 #define TONEPORT_PCM_DELAY 1
71 static struct snd_ratden toneport_ratden
= {
78 static struct line6_pcm_properties toneport_pcm_properties
= {
79 .snd_line6_playback_hw
= {
80 .info
= (SNDRV_PCM_INFO_MMAP
|
81 SNDRV_PCM_INFO_INTERLEAVED
|
82 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
83 SNDRV_PCM_INFO_MMAP_VALID
|
84 SNDRV_PCM_INFO_PAUSE
|
85 SNDRV_PCM_INFO_SYNC_START
),
86 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
87 .rates
= SNDRV_PCM_RATE_KNOT
,
92 .buffer_bytes_max
= 60000,
93 .period_bytes_min
= 64,
94 .period_bytes_max
= 8192,
97 .snd_line6_capture_hw
= {
98 .info
= (SNDRV_PCM_INFO_MMAP
|
99 SNDRV_PCM_INFO_INTERLEAVED
|
100 SNDRV_PCM_INFO_BLOCK_TRANSFER
|
101 SNDRV_PCM_INFO_MMAP_VALID
|
102 SNDRV_PCM_INFO_SYNC_START
),
103 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,
104 .rates
= SNDRV_PCM_RATE_KNOT
,
109 .buffer_bytes_max
= 60000,
110 .period_bytes_min
= 64,
111 .period_bytes_max
= 8192,
113 .periods_max
= 1024},
116 .rats
= &toneport_ratden
},
121 For the led on Guitarport.
122 Brightness goes from 0x00 to 0x26. Set a value above this to have led
124 (void cmd_0x02(byte red, byte green)
126 static int led_red
= 0x00;
127 static int led_green
= 0x26;
129 static const struct {
132 } toneport_source_info
[] = {
133 {"Microphone", 0x0a01},
135 {"Instrument", 0x0b01},
136 {"Inst & Mic", 0x0901}
139 static bool toneport_has_led(enum line6_device_type type
)
142 (type
== LINE6_GUITARPORT
) ||
143 (type
== LINE6_TONEPORT_GX
);
144 /* add your device here if you are missing support for the LEDs */
147 static void toneport_update_led(struct device
*dev
)
149 struct usb_interface
*interface
= to_usb_interface(dev
);
150 struct usb_line6_toneport
*tp
= usb_get_intfdata(interface
);
151 struct usb_line6
*line6
;
158 toneport_send_cmd(line6
->usbdev
, (led_red
<< 8) | 0x0002,
162 static ssize_t
toneport_set_led_red(struct device
*dev
,
163 struct device_attribute
*attr
,
164 const char *buf
, size_t count
)
168 retval
= kstrtoint(buf
, 10, &led_red
);
172 toneport_update_led(dev
);
176 static ssize_t
toneport_set_led_green(struct device
*dev
,
177 struct device_attribute
*attr
,
178 const char *buf
, size_t count
)
182 retval
= kstrtoint(buf
, 10, &led_green
);
186 toneport_update_led(dev
);
190 static DEVICE_ATTR(led_red
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
191 toneport_set_led_red
);
192 static DEVICE_ATTR(led_green
, S_IWUSR
| S_IRUGO
, line6_nop_read
,
193 toneport_set_led_green
);
195 static int toneport_send_cmd(struct usb_device
*usbdev
, int cmd1
, int cmd2
)
199 ret
= usb_control_msg(usbdev
, usb_sndctrlpipe(usbdev
, 0), 0x67,
200 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_OUT
,
201 cmd1
, cmd2
, NULL
, 0, LINE6_TIMEOUT
* HZ
);
204 dev_err(&usbdev
->dev
, "send failed (error %d)\n", ret
);
211 /* monitor info callback */
212 static int snd_toneport_monitor_info(struct snd_kcontrol
*kcontrol
,
213 struct snd_ctl_elem_info
*uinfo
)
215 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
217 uinfo
->value
.integer
.min
= 0;
218 uinfo
->value
.integer
.max
= 256;
222 /* monitor get callback */
223 static int snd_toneport_monitor_get(struct snd_kcontrol
*kcontrol
,
224 struct snd_ctl_elem_value
*ucontrol
)
226 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
228 ucontrol
->value
.integer
.value
[0] = line6pcm
->volume_monitor
;
232 /* monitor put callback */
233 static int snd_toneport_monitor_put(struct snd_kcontrol
*kcontrol
,
234 struct snd_ctl_elem_value
*ucontrol
)
236 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
238 if (ucontrol
->value
.integer
.value
[0] == line6pcm
->volume_monitor
)
241 line6pcm
->volume_monitor
= ucontrol
->value
.integer
.value
[0];
243 if (line6pcm
->volume_monitor
> 0)
244 line6_pcm_acquire(line6pcm
, LINE6_BITS_PCM_MONITOR
);
246 line6_pcm_release(line6pcm
, LINE6_BITS_PCM_MONITOR
);
251 /* source info callback */
252 static int snd_toneport_source_info(struct snd_kcontrol
*kcontrol
,
253 struct snd_ctl_elem_info
*uinfo
)
255 const int size
= ARRAY_SIZE(toneport_source_info
);
257 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
259 uinfo
->value
.enumerated
.items
= size
;
261 if (uinfo
->value
.enumerated
.item
>= size
)
262 uinfo
->value
.enumerated
.item
= size
- 1;
264 strcpy(uinfo
->value
.enumerated
.name
,
265 toneport_source_info
[uinfo
->value
.enumerated
.item
].name
);
270 /* source get callback */
271 static int snd_toneport_source_get(struct snd_kcontrol
*kcontrol
,
272 struct snd_ctl_elem_value
*ucontrol
)
274 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
275 struct usb_line6_toneport
*toneport
=
276 (struct usb_line6_toneport
*)line6pcm
->line6
;
277 ucontrol
->value
.enumerated
.item
[0] = toneport
->source
;
281 /* source put callback */
282 static int snd_toneport_source_put(struct snd_kcontrol
*kcontrol
,
283 struct snd_ctl_elem_value
*ucontrol
)
285 struct snd_line6_pcm
*line6pcm
= snd_kcontrol_chip(kcontrol
);
286 struct usb_line6_toneport
*toneport
=
287 (struct usb_line6_toneport
*)line6pcm
->line6
;
290 source
= ucontrol
->value
.enumerated
.item
[0];
291 if (source
>= ARRAY_SIZE(toneport_source_info
))
293 if (source
== toneport
->source
)
296 toneport
->source
= source
;
297 toneport_send_cmd(toneport
->line6
.usbdev
,
298 toneport_source_info
[source
].code
, 0x0000);
302 static void toneport_start_pcm(unsigned long arg
)
304 struct usb_line6_toneport
*toneport
= (struct usb_line6_toneport
*)arg
;
305 struct usb_line6
*line6
= &toneport
->line6
;
307 line6_pcm_acquire(line6
->line6pcm
, LINE6_BITS_PCM_MONITOR
);
310 /* control definition */
311 static struct snd_kcontrol_new toneport_control_monitor
= {
312 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
313 .name
= "Monitor Playback Volume",
315 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
316 .info
= snd_toneport_monitor_info
,
317 .get
= snd_toneport_monitor_get
,
318 .put
= snd_toneport_monitor_put
321 /* source selector definition */
322 static struct snd_kcontrol_new toneport_control_source
= {
323 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
324 .name
= "PCM Capture Source",
326 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
,
327 .info
= snd_toneport_source_info
,
328 .get
= snd_toneport_source_get
,
329 .put
= snd_toneport_source_put
333 Setup Toneport device.
335 static void toneport_setup(struct usb_line6_toneport
*toneport
)
338 struct usb_line6
*line6
= &toneport
->line6
;
339 struct usb_device
*usbdev
= line6
->usbdev
;
341 /* sync time on device with host: */
342 ticks
= (int)get_seconds();
343 line6_write_data(line6
, 0x80c6, &ticks
, 4);
346 toneport_send_cmd(usbdev
, 0x0301, 0x0000);
348 /* initialize source select: */
349 switch (toneport
->type
) {
350 case LINE6_TONEPORT_UX1
:
351 case LINE6_TONEPORT_UX2
:
352 case LINE6_PODSTUDIO_UX1
:
353 case LINE6_PODSTUDIO_UX2
:
354 toneport_send_cmd(usbdev
,
355 toneport_source_info
[toneport
->source
].code
,
361 if (toneport_has_led(toneport
->type
))
362 toneport_update_led(&usbdev
->dev
);
366 Toneport device disconnected.
368 static void line6_toneport_disconnect(struct usb_interface
*interface
)
370 struct usb_line6_toneport
*toneport
;
373 if (interface
== NULL
)
376 toneport
= usb_get_intfdata(interface
);
377 del_timer_sync(&toneport
->timer
);
378 idProduct
= le16_to_cpu(toneport
->line6
.usbdev
->descriptor
.idProduct
);
380 if (toneport_has_led(idProduct
)) {
381 device_remove_file(&interface
->dev
, &dev_attr_led_red
);
382 device_remove_file(&interface
->dev
, &dev_attr_led_green
);
388 Try to init Toneport device.
390 static int toneport_init(struct usb_interface
*interface
,
391 struct usb_line6
*line6
)
394 struct usb_line6_toneport
*toneport
= (struct usb_line6_toneport
*) line6
;
396 if ((interface
== NULL
) || (toneport
== NULL
))
399 line6
->disconnect
= line6_toneport_disconnect
;
401 /* initialize PCM subsystem: */
402 err
= line6_init_pcm(line6
, &toneport_pcm_properties
);
406 /* register monitor control: */
407 err
= snd_ctl_add(line6
->card
,
408 snd_ctl_new1(&toneport_control_monitor
,
413 /* register source select control: */
414 switch (toneport
->type
) {
415 case LINE6_TONEPORT_UX1
:
416 case LINE6_TONEPORT_UX2
:
417 case LINE6_PODSTUDIO_UX1
:
418 case LINE6_PODSTUDIO_UX2
:
420 snd_ctl_add(line6
->card
,
421 snd_ctl_new1(&toneport_control_source
,
430 line6_read_serial_number(line6
, &toneport
->serial_number
);
431 line6_read_data(line6
, 0x80c2, &toneport
->firmware_version
, 1);
433 if (toneport_has_led(toneport
->type
)) {
434 CHECK_RETURN(device_create_file
435 (&interface
->dev
, &dev_attr_led_red
));
436 CHECK_RETURN(device_create_file
437 (&interface
->dev
, &dev_attr_led_green
));
440 toneport_setup(toneport
);
442 setup_timer(&toneport
->timer
, toneport_start_pcm
,
443 (unsigned long)toneport
);
444 mod_timer(&toneport
->timer
, jiffies
+ TONEPORT_PCM_DELAY
* HZ
);
446 /* register audio system: */
447 return snd_card_register(line6
->card
);
452 Resume Toneport device after reset.
454 static int toneport_reset_resume(struct usb_interface
*interface
)
456 toneport_setup(usb_get_intfdata(interface
));
457 return line6_resume(interface
);
461 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
462 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
464 /* table of devices that work with this driver */
465 static const struct usb_device_id toneport_id_table
[] = {
466 { LINE6_DEVICE(0x4750), .driver_info
= LINE6_GUITARPORT
},
467 { LINE6_DEVICE(0x4153), .driver_info
= LINE6_PODSTUDIO_GX
},
468 { LINE6_DEVICE(0x4150), .driver_info
= LINE6_PODSTUDIO_UX1
},
469 { LINE6_IF_NUM(0x4151, 0), .driver_info
= LINE6_PODSTUDIO_UX2
},
470 { LINE6_DEVICE(0x4147), .driver_info
= LINE6_TONEPORT_GX
},
471 { LINE6_DEVICE(0x4141), .driver_info
= LINE6_TONEPORT_UX1
},
472 { LINE6_IF_NUM(0x4142, 0), .driver_info
= LINE6_TONEPORT_UX2
},
476 MODULE_DEVICE_TABLE(usb
, toneport_id_table
);
478 static const struct line6_properties toneport_properties_table
[] = {
479 [LINE6_GUITARPORT
] = {
481 .name
= "GuitarPort",
482 .capabilities
= LINE6_CAP_PCM
,
483 .altsetting
= 2, /* 1..4 seem to be ok */
484 /* no control channel */
488 [LINE6_PODSTUDIO_GX
] = {
490 .name
= "POD Studio GX",
491 .capabilities
= LINE6_CAP_PCM
,
492 .altsetting
= 2, /* 1..4 seem to be ok */
493 /* no control channel */
497 [LINE6_PODSTUDIO_UX1
] = {
498 .id
= "PODStudioUX1",
499 .name
= "POD Studio UX1",
500 .capabilities
= LINE6_CAP_PCM
,
501 .altsetting
= 2, /* 1..4 seem to be ok */
502 /* no control channel */
506 [LINE6_PODSTUDIO_UX2
] = {
507 .id
= "PODStudioUX2",
508 .name
= "POD Studio UX2",
509 .capabilities
= LINE6_CAP_PCM
,
510 .altsetting
= 2, /* defaults to 44.1kHz, 16-bit */
511 /* no control channel */
515 [LINE6_TONEPORT_GX
] = {
517 .name
= "TonePort GX",
518 .capabilities
= LINE6_CAP_PCM
,
519 .altsetting
= 2, /* 1..4 seem to be ok */
520 /* no control channel */
524 [LINE6_TONEPORT_UX1
] = {
526 .name
= "TonePort UX1",
527 .capabilities
= LINE6_CAP_PCM
,
528 .altsetting
= 2, /* 1..4 seem to be ok */
529 /* no control channel */
533 [LINE6_TONEPORT_UX2
] = {
535 .name
= "TonePort UX2",
536 .capabilities
= LINE6_CAP_PCM
,
537 .altsetting
= 2, /* defaults to 44.1kHz, 16-bit */
538 /* no control channel */
547 static int toneport_probe(struct usb_interface
*interface
,
548 const struct usb_device_id
*id
)
550 struct usb_line6_toneport
*toneport
;
552 toneport
= kzalloc(sizeof(*toneport
), GFP_KERNEL
);
555 toneport
->type
= id
->driver_info
;
556 return line6_probe(interface
, &toneport
->line6
,
557 &toneport_properties_table
[id
->driver_info
],
561 static struct usb_driver toneport_driver
= {
562 .name
= KBUILD_MODNAME
,
563 .probe
= toneport_probe
,
564 .disconnect
= line6_disconnect
,
566 .suspend
= line6_suspend
,
567 .resume
= line6_resume
,
568 .reset_resume
= toneport_reset_resume
,
570 .id_table
= toneport_id_table
,
573 module_usb_driver(toneport_driver
);
575 MODULE_DESCRIPTION("TonePort USB driver");
576 MODULE_LICENSE("GPL");