Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Line6 Linux USB driver - 0.8.0 |
| 3 | * |
| 4 | * Copyright (C) 2004-2009 Markus Grabner (grabner@icg.tugraz.at) |
| 5 | * Emil Myhrman (emil.myhrman@gmail.com) |
| 6 | * |
| 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. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include "driver.h" |
| 14 | |
| 15 | #include "audio.h" |
| 16 | #include "capture.h" |
| 17 | #include "playback.h" |
| 18 | #include "toneport.h" |
| 19 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 20 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2); |
| 21 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 22 | static struct snd_ratden toneport_ratden = { |
| 23 | .num_min = 44100, |
| 24 | .num_max = 44100, |
| 25 | .num_step = 1, |
| 26 | .den = 1 |
| 27 | }; |
| 28 | |
| 29 | static struct line6_pcm_properties toneport_pcm_properties = { |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 30 | .snd_line6_playback_hw = { |
| 31 | .info = (SNDRV_PCM_INFO_MMAP | |
| 32 | SNDRV_PCM_INFO_INTERLEAVED | |
| 33 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 34 | SNDRV_PCM_INFO_MMAP_VALID | |
| 35 | SNDRV_PCM_INFO_PAUSE | |
| 36 | SNDRV_PCM_INFO_SYNC_START), |
| 37 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 38 | .rates = SNDRV_PCM_RATE_KNOT, |
| 39 | .rate_min = 44100, |
| 40 | .rate_max = 44100, |
| 41 | .channels_min = 2, |
| 42 | .channels_max = 2, |
| 43 | .buffer_bytes_max = 60000, |
| 44 | .period_bytes_min = 180 * 4, |
| 45 | .period_bytes_max = 8192, |
| 46 | .periods_min = 1, |
| 47 | .periods_max = 1024}, |
| 48 | .snd_line6_capture_hw = { |
| 49 | .info = (SNDRV_PCM_INFO_MMAP | |
| 50 | SNDRV_PCM_INFO_INTERLEAVED | |
| 51 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 52 | SNDRV_PCM_INFO_MMAP_VALID | |
| 53 | SNDRV_PCM_INFO_SYNC_START), |
| 54 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 55 | .rates = SNDRV_PCM_RATE_KNOT, |
| 56 | .rate_min = 44100, |
| 57 | .rate_max = 44100, |
| 58 | .channels_min = 2, |
| 59 | .channels_max = 2, |
| 60 | .buffer_bytes_max = 60000, |
| 61 | .period_bytes_min = 188 * 4, |
| 62 | .period_bytes_max = 8192, |
| 63 | .periods_min = 1, |
| 64 | .periods_max = 1024}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 65 | .snd_line6_rates = { |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 66 | .nrats = 1, |
| 67 | .rats = &toneport_ratden}, |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 68 | .bytes_per_frame = 4 |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | For the led on Guitarport. |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 73 | Brightness goes from 0x00 to 0x26. Set a value above this to have led |
| 74 | blink. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 75 | (void cmd_0x02(byte red, byte green) |
| 76 | */ |
| 77 | static int led_red = 0x00; |
| 78 | static int led_green = 0x26; |
| 79 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 80 | static void toneport_update_led(struct device *dev) |
| 81 | { |
| 82 | struct usb_interface *interface = to_usb_interface(dev); |
| 83 | struct usb_line6_toneport *tp = usb_get_intfdata(interface); |
| 84 | struct usb_line6 *line6; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 85 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 86 | if (!tp) |
| 87 | return; |
| 88 | |
| 89 | line6 = &tp->line6; |
| 90 | if (line6) |
| 91 | toneport_send_cmd(line6->usbdev, (led_red << 8) | 0x0002, |
| 92 | led_green); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 93 | } |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 94 | |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 95 | static ssize_t toneport_set_led_red(struct device *dev, |
| 96 | struct device_attribute *attr, |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 97 | const char *buf, size_t count) |
| 98 | { |
Shawn Bohrer | bb950a1 | 2009-11-15 22:17:59 -0600 | [diff] [blame] | 99 | int retval; |
| 100 | long value; |
| 101 | |
| 102 | retval = strict_strtol(buf, 10, &value); |
| 103 | if (retval) |
| 104 | return retval; |
| 105 | |
| 106 | led_red = value; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 107 | toneport_update_led(dev); |
| 108 | return count; |
| 109 | } |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 110 | |
Greg Kroah-Hartman | 77491e5 | 2009-02-27 20:25:43 -0800 | [diff] [blame] | 111 | static ssize_t toneport_set_led_green(struct device *dev, |
| 112 | struct device_attribute *attr, |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 113 | const char *buf, size_t count) |
| 114 | { |
Shawn Bohrer | bb950a1 | 2009-11-15 22:17:59 -0600 | [diff] [blame] | 115 | int retval; |
| 116 | long value; |
| 117 | |
| 118 | retval = strict_strtol(buf, 10, &value); |
| 119 | if (retval) |
| 120 | return retval; |
| 121 | |
| 122 | led_green = value; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 123 | toneport_update_led(dev); |
| 124 | return count; |
| 125 | } |
| 126 | |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 127 | static DEVICE_ATTR(led_red, S_IWUGO | S_IRUGO, line6_nop_read, |
| 128 | toneport_set_led_red); |
| 129 | static DEVICE_ATTR(led_green, S_IWUGO | S_IRUGO, line6_nop_read, |
| 130 | toneport_set_led_green); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 131 | |
| 132 | static int toneport_send_cmd(struct usb_device *usbdev, int cmd1, int cmd2) |
| 133 | { |
| 134 | int ret; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 135 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 136 | ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67, |
| 137 | USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, |
| 138 | cmd1, cmd2, NULL, 0, LINE6_TIMEOUT * HZ); |
| 139 | |
| 140 | if (ret < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 141 | err("send failed (error %d)\n", ret); |
| 142 | return ret; |
| 143 | } |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | Toneport destructor. |
| 150 | */ |
| 151 | static void toneport_destruct(struct usb_interface *interface) |
| 152 | { |
| 153 | struct usb_line6_toneport *toneport = usb_get_intfdata(interface); |
| 154 | struct usb_line6 *line6; |
| 155 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 156 | if (toneport == NULL) |
| 157 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 158 | line6 = &toneport->line6; |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 159 | if (line6 == NULL) |
| 160 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 161 | line6_cleanup_audio(line6); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | Init Toneport device. |
| 166 | */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 167 | int toneport_init(struct usb_interface *interface, |
| 168 | struct usb_line6_toneport *toneport) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 169 | { |
| 170 | int err, ticks; |
| 171 | struct usb_line6 *line6 = &toneport->line6; |
| 172 | struct usb_device *usbdev; |
| 173 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 174 | if ((interface == NULL) || (toneport == NULL)) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 175 | return -ENODEV; |
| 176 | |
| 177 | /* initialize audio system: */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 178 | err = line6_init_audio(line6); |
| 179 | if (err < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 180 | toneport_destruct(interface); |
| 181 | return err; |
| 182 | } |
| 183 | |
| 184 | /* initialize PCM subsystem: */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 185 | err = line6_init_pcm(line6, &toneport_pcm_properties); |
| 186 | if (err < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 187 | toneport_destruct(interface); |
| 188 | return err; |
| 189 | } |
| 190 | |
| 191 | /* register audio system: */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 192 | err = line6_register_audio(line6); |
| 193 | if (err < 0) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 194 | toneport_destruct(interface); |
| 195 | return err; |
| 196 | } |
| 197 | |
| 198 | usbdev = line6->usbdev; |
| 199 | line6_read_serial_number(line6, &toneport->serial_number); |
| 200 | line6_read_data(line6, 0x80c2, &toneport->firmware_version, 1); |
| 201 | |
| 202 | /* sync time on device with host: */ |
| 203 | ticks = (int)get_seconds(); |
| 204 | line6_write_data(line6, 0x80c6, &ticks, 4); |
| 205 | |
| 206 | /* |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 207 | seems to work without the first two... |
| 208 | */ |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 209 | /* toneport_send_cmd(usbdev, 0x0201, 0x0002); */ |
| 210 | /* toneport_send_cmd(usbdev, 0x0801, 0x0000); */ |
| 211 | /* only one that works for me; on GP, TP might be different? */ |
| 212 | toneport_send_cmd(usbdev, 0x0301, 0x0000); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 213 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 214 | if (usbdev->descriptor.idProduct != LINE6_DEVID_GUITARPORT) { |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 215 | CHECK_RETURN(device_create_file |
| 216 | (&interface->dev, &dev_attr_led_red)); |
| 217 | CHECK_RETURN(device_create_file |
| 218 | (&interface->dev, &dev_attr_led_green)); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 219 | toneport_update_led(&usbdev->dev); |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* |
| 226 | Toneport device disconnected. |
| 227 | */ |
| 228 | void toneport_disconnect(struct usb_interface *interface) |
| 229 | { |
| 230 | struct usb_line6_toneport *toneport; |
| 231 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 232 | if (interface == NULL) |
| 233 | return; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 234 | toneport = usb_get_intfdata(interface); |
| 235 | |
Shawn Bohrer | 63a4a8b | 2009-11-15 22:17:58 -0600 | [diff] [blame] | 236 | if (toneport->line6.usbdev->descriptor.idProduct != |
| 237 | LINE6_DEVID_GUITARPORT) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 238 | device_remove_file(&interface->dev, &dev_attr_led_red); |
| 239 | device_remove_file(&interface->dev, &dev_attr_led_green); |
| 240 | } |
| 241 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 242 | if (toneport != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 243 | struct snd_line6_pcm *line6pcm = toneport->line6.line6pcm; |
| 244 | |
Greg Kroah-Hartman | 6353773 | 2009-02-27 22:43:45 -0800 | [diff] [blame] | 245 | if (line6pcm != NULL) { |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 246 | unlink_wait_clear_audio_out_urbs(line6pcm); |
| 247 | unlink_wait_clear_audio_in_urbs(line6pcm); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | toneport_destruct(interface); |
| 252 | } |