2 * Line 6 Linux USB driver
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 <linux/leds.h>
18 #include <sound/core.h>
19 #include <sound/control.h>
26 enum line6_device_type {
36 struct usb_line6_toneport;
39 struct led_classdev dev;
41 struct usb_line6_toneport *toneport;
45 struct usb_line6_toneport {
47 Generic Line 6 USB data.
49 struct usb_line6 line6;
57 Serial number of device.
62 Firmware version (x 100).
67 Timer for delayed PCM startup.
69 struct timer_list timer;
74 enum line6_device_type type;
77 struct toneport_led leds[2];
80 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
82 #define TONEPORT_PCM_DELAY 1
84 static struct snd_ratden toneport_ratden = {
91 static struct line6_pcm_properties toneport_pcm_properties = {
92 .snd_line6_playback_hw = {
93 .info = (SNDRV_PCM_INFO_MMAP |
94 SNDRV_PCM_INFO_INTERLEAVED |
95 SNDRV_PCM_INFO_BLOCK_TRANSFER |
96 SNDRV_PCM_INFO_MMAP_VALID |
97 SNDRV_PCM_INFO_PAUSE |
98 SNDRV_PCM_INFO_SYNC_START),
99 .formats = SNDRV_PCM_FMTBIT_S16_LE,
100 .rates = SNDRV_PCM_RATE_KNOT,
105 .buffer_bytes_max = 60000,
106 .period_bytes_min = 64,
107 .period_bytes_max = 8192,
109 .periods_max = 1024},
110 .snd_line6_capture_hw = {
111 .info = (SNDRV_PCM_INFO_MMAP |
112 SNDRV_PCM_INFO_INTERLEAVED |
113 SNDRV_PCM_INFO_BLOCK_TRANSFER |
114 SNDRV_PCM_INFO_MMAP_VALID |
115 SNDRV_PCM_INFO_SYNC_START),
116 .formats = SNDRV_PCM_FMTBIT_S16_LE,
117 .rates = SNDRV_PCM_RATE_KNOT,
122 .buffer_bytes_max = 60000,
123 .period_bytes_min = 64,
124 .period_bytes_max = 8192,
126 .periods_max = 1024},
129 .rats = &toneport_ratden},
133 static const struct {
136 } toneport_source_info[] = {
137 {"Microphone", 0x0a01},
139 {"Instrument", 0x0b01},
140 {"Inst & Mic", 0x0901}
143 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
147 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
148 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
149 cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ);
152 dev_err(&usbdev->dev, "send failed (error %d)\n", ret);
159 /* monitor info callback */
160 static int snd_toneport_monitor_info(struct snd_kcontrol *kcontrol,
161 struct snd_ctl_elem_info *uinfo)
163 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
165 uinfo->value.integer.min = 0;
166 uinfo->value.integer.max = 256;
170 /* monitor get callback */
171 static int snd_toneport_monitor_get(struct snd_kcontrol *kcontrol,
172 struct snd_ctl_elem_value *ucontrol)
174 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
176 ucontrol->value.integer.value[0] = line6pcm->volume_monitor;
180 /* monitor put callback */
181 static int snd_toneport_monitor_put(struct snd_kcontrol *kcontrol,
182 struct snd_ctl_elem_value *ucontrol)
184 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
187 if (ucontrol->value.integer.value[0] == line6pcm->volume_monitor)
190 line6pcm->volume_monitor = ucontrol->value.integer.value[0];
192 if (line6pcm->volume_monitor > 0) {
193 err = line6_pcm_acquire(line6pcm, LINE6_STREAM_MONITOR);
195 line6pcm->volume_monitor = 0;
196 line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
200 line6_pcm_release(line6pcm, LINE6_STREAM_MONITOR);
206 /* source info callback */
207 static int snd_toneport_source_info(struct snd_kcontrol *kcontrol,
208 struct snd_ctl_elem_info *uinfo)
210 const int size = ARRAY_SIZE(toneport_source_info);
212 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
214 uinfo->value.enumerated.items = size;
216 if (uinfo->value.enumerated.item >= size)
217 uinfo->value.enumerated.item = size - 1;
219 strcpy(uinfo->value.enumerated.name,
220 toneport_source_info[uinfo->value.enumerated.item].name);
225 /* source get callback */
226 static int snd_toneport_source_get(struct snd_kcontrol *kcontrol,
227 struct snd_ctl_elem_value *ucontrol)
229 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
230 struct usb_line6_toneport *toneport =
231 (struct usb_line6_toneport *)line6pcm->line6;
232 ucontrol->value.enumerated.item[0] = toneport->source;
236 /* source put callback */
237 static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
238 struct snd_ctl_elem_value *ucontrol)
240 struct snd_line6_pcm *line6pcm = snd_kcontrol_chip(kcontrol);
241 struct usb_line6_toneport *toneport =
242 (struct usb_line6_toneport *)line6pcm->line6;
245 source = ucontrol->value.enumerated.item[0];
246 if (source >= ARRAY_SIZE(toneport_source_info))
248 if (source == toneport->source)
251 toneport->source = source;
252 toneport_send_cmd(toneport->line6.usbdev,
253 toneport_source_info[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;
262 line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR);
265 /* control definition */
266 static struct snd_kcontrol_new toneport_control_monitor = {
267 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
268 .name = "Monitor Playback Volume",
270 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
271 .info = snd_toneport_monitor_info,
272 .get = snd_toneport_monitor_get,
273 .put = snd_toneport_monitor_put
276 /* source selector definition */
277 static struct snd_kcontrol_new toneport_control_source = {
278 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
279 .name = "PCM Capture Source",
281 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
282 .info = snd_toneport_source_info,
283 .get = snd_toneport_source_get,
284 .put = snd_toneport_source_put
288 For the led on Guitarport.
289 Brightness goes from 0x00 to 0x26. Set a value above this to have led
291 (void cmd_0x02(byte red, byte green)
294 static bool toneport_has_led(enum line6_device_type type)
297 (type == LINE6_GUITARPORT) ||
298 (type == LINE6_TONEPORT_GX);
299 /* add your device here if you are missing support for the LEDs */
302 static const char * const led_colors[2] = { "red", "green" };
303 static const int led_init_vals[2] = { 0x00, 0x26 };
305 static void toneport_update_led(struct usb_line6_toneport *toneport)
307 toneport_send_cmd(toneport->line6.usbdev,
308 (toneport->leds[0].dev.brightness << 8) | 0x0002,
309 toneport->leds[1].dev.brightness);
312 static void toneport_led_brightness_set(struct led_classdev *led_cdev,
313 enum led_brightness brightness)
315 struct toneport_led *leds =
316 container_of(led_cdev, struct toneport_led, dev);
317 toneport_update_led(leds->toneport);
320 static int toneport_init_leds(struct usb_line6_toneport *toneport)
322 struct device *dev = &toneport->line6.usbdev->dev;
325 for (i = 0; i < 2; i++) {
326 struct toneport_led *led = &toneport->leds[i];
327 struct led_classdev *leddev = &led->dev;
329 led->toneport = toneport;
330 snprintf(led->name, sizeof(led->name), "%s::%s",
331 dev_name(dev), led_colors[i]);
332 leddev->name = led->name;
333 leddev->brightness = led_init_vals[i];
334 leddev->max_brightness = 0x26;
335 leddev->brightness_set = toneport_led_brightness_set;
336 err = led_classdev_register(dev, leddev);
339 led->registered = true;
345 static void toneport_remove_leds(struct usb_line6_toneport *toneport)
347 struct toneport_led *led;
350 for (i = 0; i < 2; i++) {
351 led = &toneport->leds[i];
352 if (!led->registered)
354 led_classdev_unregister(&led->dev);
355 led->registered = false;
360 Setup Toneport device.
362 static void toneport_setup(struct usb_line6_toneport *toneport)
365 struct usb_line6 *line6 = &toneport->line6;
366 struct usb_device *usbdev = line6->usbdev;
368 /* sync time on device with host: */
369 ticks = (int)get_seconds();
370 line6_write_data(line6, 0x80c6, &ticks, 4);
373 toneport_send_cmd(usbdev, 0x0301, 0x0000);
375 /* initialize source select: */
376 switch (toneport->type) {
377 case LINE6_TONEPORT_UX1:
378 case LINE6_TONEPORT_UX2:
379 case LINE6_PODSTUDIO_UX1:
380 case LINE6_PODSTUDIO_UX2:
381 toneport_send_cmd(usbdev,
382 toneport_source_info[toneport->source].code,
388 if (toneport_has_led(toneport->type))
389 toneport_update_led(toneport);
391 mod_timer(&toneport->timer, jiffies + TONEPORT_PCM_DELAY * HZ);
395 Toneport device disconnected.
397 static void line6_toneport_disconnect(struct usb_line6 *line6)
399 struct usb_line6_toneport *toneport =
400 (struct usb_line6_toneport *)line6;
402 del_timer_sync(&toneport->timer);
404 if (toneport_has_led(toneport->type))
405 toneport_remove_leds(toneport);
410 Try to init Toneport device.
412 static int toneport_init(struct usb_line6 *line6,
413 const struct usb_device_id *id)
416 struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6;
418 toneport->type = id->driver_info;
419 setup_timer(&toneport->timer, toneport_start_pcm,
420 (unsigned long)toneport);
422 line6->disconnect = line6_toneport_disconnect;
424 /* initialize PCM subsystem: */
425 err = line6_init_pcm(line6, &toneport_pcm_properties);
429 /* register monitor control: */
430 err = snd_ctl_add(line6->card,
431 snd_ctl_new1(&toneport_control_monitor,
436 /* register source select control: */
437 switch (toneport->type) {
438 case LINE6_TONEPORT_UX1:
439 case LINE6_TONEPORT_UX2:
440 case LINE6_PODSTUDIO_UX1:
441 case LINE6_PODSTUDIO_UX2:
443 snd_ctl_add(line6->card,
444 snd_ctl_new1(&toneport_control_source,
453 line6_read_serial_number(line6, &toneport->serial_number);
454 line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
456 if (toneport_has_led(toneport->type)) {
457 err = toneport_init_leds(toneport);
462 toneport_setup(toneport);
464 /* register audio system: */
465 return snd_card_register(line6->card);
470 Resume Toneport device after reset.
472 static int toneport_reset_resume(struct usb_interface *interface)
474 toneport_setup(usb_get_intfdata(interface));
475 return line6_resume(interface);
479 #define LINE6_DEVICE(prod) USB_DEVICE(0x0e41, prod)
480 #define LINE6_IF_NUM(prod, n) USB_DEVICE_INTERFACE_NUMBER(0x0e41, prod, n)
482 /* table of devices that work with this driver */
483 static const struct usb_device_id toneport_id_table[] = {
484 { LINE6_DEVICE(0x4750), .driver_info = LINE6_GUITARPORT },
485 { LINE6_DEVICE(0x4153), .driver_info = LINE6_PODSTUDIO_GX },
486 { LINE6_DEVICE(0x4150), .driver_info = LINE6_PODSTUDIO_UX1 },
487 { LINE6_IF_NUM(0x4151, 0), .driver_info = LINE6_PODSTUDIO_UX2 },
488 { LINE6_DEVICE(0x4147), .driver_info = LINE6_TONEPORT_GX },
489 { LINE6_DEVICE(0x4141), .driver_info = LINE6_TONEPORT_UX1 },
490 { LINE6_IF_NUM(0x4142, 0), .driver_info = LINE6_TONEPORT_UX2 },
494 MODULE_DEVICE_TABLE(usb, toneport_id_table);
496 static const struct line6_properties toneport_properties_table[] = {
497 [LINE6_GUITARPORT] = {
499 .name = "GuitarPort",
500 .capabilities = LINE6_CAP_PCM,
501 .altsetting = 2, /* 1..4 seem to be ok */
502 /* no control channel */
506 [LINE6_PODSTUDIO_GX] = {
508 .name = "POD Studio GX",
509 .capabilities = LINE6_CAP_PCM,
510 .altsetting = 2, /* 1..4 seem to be ok */
511 /* no control channel */
515 [LINE6_PODSTUDIO_UX1] = {
516 .id = "PODStudioUX1",
517 .name = "POD Studio UX1",
518 .capabilities = LINE6_CAP_PCM,
519 .altsetting = 2, /* 1..4 seem to be ok */
520 /* no control channel */
524 [LINE6_PODSTUDIO_UX2] = {
525 .id = "PODStudioUX2",
526 .name = "POD Studio UX2",
527 .capabilities = LINE6_CAP_PCM,
528 .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
529 /* no control channel */
533 [LINE6_TONEPORT_GX] = {
535 .name = "TonePort GX",
536 .capabilities = LINE6_CAP_PCM,
537 .altsetting = 2, /* 1..4 seem to be ok */
538 /* no control channel */
542 [LINE6_TONEPORT_UX1] = {
544 .name = "TonePort UX1",
545 .capabilities = LINE6_CAP_PCM,
546 .altsetting = 2, /* 1..4 seem to be ok */
547 /* no control channel */
551 [LINE6_TONEPORT_UX2] = {
553 .name = "TonePort UX2",
554 .capabilities = LINE6_CAP_PCM,
555 .altsetting = 2, /* defaults to 44.1kHz, 16-bit */
556 /* no control channel */
565 static int toneport_probe(struct usb_interface *interface,
566 const struct usb_device_id *id)
568 return line6_probe(interface, id,
569 &toneport_properties_table[id->driver_info],
570 toneport_init, sizeof(struct usb_line6_toneport));
573 static struct usb_driver toneport_driver = {
574 .name = KBUILD_MODNAME,
575 .probe = toneport_probe,
576 .disconnect = line6_disconnect,
578 .suspend = line6_suspend,
579 .resume = line6_resume,
580 .reset_resume = toneport_reset_resume,
582 .id_table = toneport_id_table,
585 module_usb_driver(toneport_driver);
587 MODULE_DESCRIPTION("TonePort USB driver");
588 MODULE_LICENSE("GPL");