2 * Line6 Linux USB driver - 0.8.0
4 * Copyright (C) 2004-2009 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.
21 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2);
24 static struct snd_ratden toneport_ratden = {
31 static struct line6_pcm_properties toneport_pcm_properties = {
32 .snd_line6_playback_hw = {
33 .info = (SNDRV_PCM_INFO_MMAP |
34 SNDRV_PCM_INFO_INTERLEAVED |
35 SNDRV_PCM_INFO_BLOCK_TRANSFER |
36 SNDRV_PCM_INFO_MMAP_VALID |
37 SNDRV_PCM_INFO_PAUSE |
38 SNDRV_PCM_INFO_SYNC_START),
39 .formats = SNDRV_PCM_FMTBIT_S16_LE,
40 .rates = SNDRV_PCM_RATE_KNOT,
45 .buffer_bytes_max = 60000,
46 .period_bytes_min = 180 * 4,
47 .period_bytes_max = 8192,
51 .snd_line6_capture_hw = {
52 .info = (SNDRV_PCM_INFO_MMAP |
53 SNDRV_PCM_INFO_INTERLEAVED |
54 SNDRV_PCM_INFO_BLOCK_TRANSFER |
55 SNDRV_PCM_INFO_MMAP_VALID |
56 SNDRV_PCM_INFO_SYNC_START),
57 .formats = SNDRV_PCM_FMTBIT_S16_LE,
58 .rates = SNDRV_PCM_RATE_KNOT,
63 .buffer_bytes_max = 60000,
64 .period_bytes_min = 188 * 4,
65 .period_bytes_max = 8192,
71 .rats = &toneport_ratden
77 For the led on Guitarport.
78 Brightness goes from 0x00 to 0x26. Set a value above this to have led blink.
79 (void cmd_0x02(byte red, byte green)
81 static int led_red = 0x00;
82 static int led_green = 0x26;
84 static void toneport_update_led(struct device *dev) {
85 struct usb_interface *interface;
86 struct usb_line6_toneport *tp;
87 struct usb_line6* line6;
89 if ((interface = to_usb_interface(dev)) &&
90 (tp = usb_get_intfdata(interface)) &&
92 toneport_send_cmd(line6->usbdev, (led_red<<8)|0x0002, led_green); // for setting the LED on Guitarport
94 static ssize_t toneport_set_led_red(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count) {
98 led_red = simple_strtol(buf, &c, 10);
99 toneport_update_led(dev);
102 static ssize_t toneport_set_led_green(struct device *dev,
103 struct device_attribute *attr,
104 const char *buf, size_t count) {
106 led_green = simple_strtol(buf, &c, 10);
107 toneport_update_led(dev);
111 static DEVICE_ATTR(led_red, S_IWUGO | S_IRUGO, line6_nop_read, toneport_set_led_red);
112 static DEVICE_ATTR(led_green, S_IWUGO | S_IRUGO, line6_nop_read, toneport_set_led_green);
115 static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2)
118 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev,0), 0x67,
119 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
120 cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ);
123 err("send failed (error %d)\n", ret);
133 static void toneport_destruct(struct usb_interface *interface)
135 struct usb_line6_toneport *toneport = usb_get_intfdata(interface);
136 struct usb_line6 *line6;
138 if(toneport == NULL) return;
139 line6 = &toneport->line6;
140 if(line6 == NULL) return;
141 line6_cleanup_audio(line6);
145 Init Toneport device.
147 int toneport_init(struct usb_interface *interface, struct usb_line6_toneport *toneport)
150 struct usb_line6 *line6 = &toneport->line6;
151 struct usb_device *usbdev;
153 if((interface == NULL) || (toneport == NULL))
156 /* initialize audio system: */
157 if((err = line6_init_audio(line6)) < 0) {
158 toneport_destruct(interface);
162 /* initialize PCM subsystem: */
163 if((err = line6_init_pcm(line6, &toneport_pcm_properties)) < 0) {
164 toneport_destruct(interface);
168 /* register audio system: */
169 if((err = line6_register_audio(line6)) < 0) {
170 toneport_destruct(interface);
174 usbdev = line6->usbdev;
175 line6_read_serial_number(line6, &toneport->serial_number);
176 line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1);
178 /* sync time on device with host: */
179 ticks = (int)get_seconds();
180 line6_write_data(line6, 0x80c6, &ticks, 4);
183 seems to work without the first two...
185 //toneport_send_cmd(usbdev, 0x0201, 0x0002); // ..
186 //toneport_send_cmd(usbdev, 0x0801, 0x0000); // ..
187 toneport_send_cmd(usbdev, 0x0301, 0x0000); // only one that works for me; on GP, TP might be different?
189 if (usbdev->descriptor.idProduct!=LINE6_DEVID_GUITARPORT) {
190 CHECK_RETURN(device_create_file(&interface->dev, &dev_attr_led_red));
191 CHECK_RETURN(device_create_file(&interface->dev, &dev_attr_led_green));
192 toneport_update_led(&usbdev->dev);
199 Toneport device disconnected.
201 void toneport_disconnect(struct usb_interface *interface)
203 struct usb_line6_toneport *toneport;
205 if(interface == NULL) return;
206 toneport = usb_get_intfdata(interface);
208 if (toneport->line6.usbdev->descriptor.idProduct != LINE6_DEVID_GUITARPORT) {
209 device_remove_file(&interface->dev, &dev_attr_led_red);
210 device_remove_file(&interface->dev, &dev_attr_led_green);
213 if(toneport != NULL) {
214 struct snd_line6_pcm *line6pcm = toneport->line6.line6pcm;
216 if(line6pcm != NULL) {
217 unlink_wait_clear_audio_out_urbs(line6pcm);
218 unlink_wait_clear_audio_in_urbs(line6pcm);
222 toneport_destruct(interface);