Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 2 | * Line6 Linux USB driver - 0.9.1beta |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 4 | * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation, version 2. |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | #ifndef DRIVER_H |
| 13 | #define DRIVER_H |
| 14 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/usb.h> |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 17 | #include <sound/core.h> |
| 18 | |
| 19 | #include "midi.h" |
| 20 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 21 | #define DRIVER_NAME "line6usb" |
| 22 | |
Chris Rorvick | 410dca8 | 2015-01-12 12:42:40 -0800 | [diff] [blame] | 23 | enum line6_device_type { |
| 24 | LINE6_BASSPODXT, |
| 25 | LINE6_BASSPODXTLIVE, |
| 26 | LINE6_BASSPODXTPRO, |
| 27 | LINE6_GUITARPORT, |
| 28 | LINE6_POCKETPOD, |
| 29 | LINE6_PODHD300, |
| 30 | LINE6_PODHD400, |
Chris Rorvick | 951dd31 | 2015-01-12 12:42:49 -0800 | [diff] [blame] | 31 | LINE6_PODHD500_0, |
| 32 | LINE6_PODHD500_1, |
Chris Rorvick | 410dca8 | 2015-01-12 12:42:40 -0800 | [diff] [blame] | 33 | LINE6_PODSTUDIO_GX, |
| 34 | LINE6_PODSTUDIO_UX1, |
| 35 | LINE6_PODSTUDIO_UX2, |
| 36 | LINE6_PODXT, |
Chris Rorvick | 7ad0731 | 2015-01-12 12:42:48 -0800 | [diff] [blame] | 37 | LINE6_PODXTLIVE_POD, |
| 38 | LINE6_PODXTLIVE_VARIAX, |
Chris Rorvick | 410dca8 | 2015-01-12 12:42:40 -0800 | [diff] [blame] | 39 | LINE6_PODXTPRO, |
| 40 | LINE6_TONEPORT_GX, |
| 41 | LINE6_TONEPORT_UX1, |
| 42 | LINE6_TONEPORT_UX2, |
| 43 | LINE6_VARIAX |
| 44 | }; |
| 45 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 46 | #define LINE6_TIMEOUT 1 |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 47 | #define LINE6_BUFSIZE_LISTEN 32 |
| 48 | #define LINE6_MESSAGE_MAXLEN 256 |
| 49 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 50 | /* |
| 51 | Line6 MIDI control commands |
| 52 | */ |
| 53 | #define LINE6_PARAM_CHANGE 0xb0 |
| 54 | #define LINE6_PROGRAM_CHANGE 0xc0 |
| 55 | #define LINE6_SYSEX_BEGIN 0xf0 |
| 56 | #define LINE6_SYSEX_END 0xf7 |
| 57 | #define LINE6_RESET 0xff |
| 58 | |
| 59 | /* |
| 60 | MIDI channel for messages initiated by the host |
| 61 | (and eventually echoed back by the device) |
| 62 | */ |
| 63 | #define LINE6_CHANNEL_HOST 0x00 |
| 64 | |
| 65 | /* |
| 66 | MIDI channel for messages initiated by the device |
| 67 | */ |
| 68 | #define LINE6_CHANNEL_DEVICE 0x02 |
| 69 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 70 | #define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 71 | |
| 72 | #define LINE6_CHANNEL_MASK 0x0f |
| 73 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 74 | #define MISSING_CASE \ |
Stefan Hajnoczi | 4d3f50e | 2013-01-11 23:08:11 +0100 | [diff] [blame] | 75 | pr_err("line6usb driver bug: missing case in %s:%d\n", \ |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 76 | __FILE__, __LINE__) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 77 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 78 | #define CHECK_RETURN(x) \ |
| 79 | do { \ |
| 80 | err = x; \ |
| 81 | if (err < 0) \ |
| 82 | return err; \ |
| 83 | } while (0) |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 84 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 85 | #define CHECK_STARTUP_PROGRESS(x, n) \ |
| 86 | do { \ |
| 87 | if ((x) >= (n)) \ |
| 88 | return; \ |
| 89 | x = (n); \ |
| 90 | } while (0) |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 91 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 92 | extern const unsigned char line6_midi_id[3]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 93 | |
| 94 | static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3; |
| 95 | static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4; |
| 96 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 97 | /** |
| 98 | Common properties of Line6 devices. |
| 99 | */ |
| 100 | struct line6_properties { |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 101 | /** |
| 102 | Card id string (maximum 16 characters). |
| 103 | This can be used to address the device in ALSA programs as |
| 104 | "default:CARD=<id>" |
| 105 | */ |
| 106 | const char *id; |
| 107 | |
| 108 | /** |
| 109 | Card short name (maximum 32 characters). |
| 110 | */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 111 | const char *name; |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 112 | |
| 113 | /** |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 114 | Bit vector defining this device's capabilities in the |
| 115 | line6usb driver. |
| 116 | */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 117 | int capabilities; |
Chris Rorvick | 7b9584f | 2015-01-12 12:42:52 -0800 | [diff] [blame] | 118 | |
| 119 | int altsetting; |
Chris Rorvick | 9e165be | 2015-01-12 12:42:53 -0800 | [diff] [blame] | 120 | |
| 121 | unsigned ep_ctrl_r; |
| 122 | unsigned ep_ctrl_w; |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 123 | unsigned ep_audio_r; |
| 124 | unsigned ep_audio_w; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /** |
| 128 | Common data shared by all Line6 devices. |
| 129 | Corresponds to a pair of USB endpoints. |
| 130 | */ |
| 131 | struct usb_line6 { |
| 132 | /** |
| 133 | USB device. |
| 134 | */ |
| 135 | struct usb_device *usbdev; |
| 136 | |
| 137 | /** |
Chris Rorvick | a23a8bf | 2015-01-12 12:42:42 -0800 | [diff] [blame] | 138 | Device type. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 139 | */ |
Chris Rorvick | a23a8bf | 2015-01-12 12:42:42 -0800 | [diff] [blame] | 140 | enum line6_device_type type; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | Properties. |
| 144 | */ |
| 145 | const struct line6_properties *properties; |
| 146 | |
| 147 | /** |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 148 | Interval (ms). |
| 149 | */ |
| 150 | int interval; |
| 151 | |
| 152 | /** |
| 153 | Maximum size of USB packet. |
| 154 | */ |
| 155 | int max_packet_size; |
| 156 | |
| 157 | /** |
| 158 | Device representing the USB interface. |
| 159 | */ |
| 160 | struct device *ifcdev; |
| 161 | |
| 162 | /** |
| 163 | Line6 sound card data structure. |
| 164 | Each device has at least MIDI or PCM. |
| 165 | */ |
| 166 | struct snd_card *card; |
| 167 | |
| 168 | /** |
| 169 | Line6 PCM device data structure. |
| 170 | */ |
| 171 | struct snd_line6_pcm *line6pcm; |
| 172 | |
| 173 | /** |
| 174 | Line6 MIDI device data structure. |
| 175 | */ |
| 176 | struct snd_line6_midi *line6midi; |
| 177 | |
| 178 | /** |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 179 | URB for listening to PODxt Pro control endpoint. |
| 180 | */ |
| 181 | struct urb *urb_listen; |
| 182 | |
| 183 | /** |
| 184 | Buffer for listening to PODxt Pro control endpoint. |
| 185 | */ |
| 186 | unsigned char *buffer_listen; |
| 187 | |
| 188 | /** |
| 189 | Buffer for message to be processed. |
| 190 | */ |
| 191 | unsigned char *buffer_message; |
| 192 | |
| 193 | /** |
| 194 | Length of message to be processed. |
| 195 | */ |
| 196 | int message_length; |
Chris Rorvick | 01f6b2b | 2015-01-12 12:42:58 -0800 | [diff] [blame] | 197 | |
| 198 | void (*process_message)(struct usb_line6 *); |
Chris Rorvick | a46c467 | 2015-01-12 12:42:59 -0800 | [diff] [blame] | 199 | void (*disconnect)(struct usb_interface *); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 200 | }; |
| 201 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 202 | extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, |
| 203 | int code2, int size); |
| 204 | extern ssize_t line6_nop_read(struct device *dev, |
| 205 | struct device_attribute *attr, char *buf); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 206 | extern int line6_read_data(struct usb_line6 *line6, int address, void *data, |
| 207 | size_t datalen); |
| 208 | extern int line6_read_serial_number(struct usb_line6 *line6, |
| 209 | int *serial_number); |
Johannes Thumshirn | 317e188 | 2012-06-27 21:25:58 +0200 | [diff] [blame] | 210 | extern int line6_send_program(struct usb_line6 *line6, u8 value); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 211 | extern int line6_send_raw_message(struct usb_line6 *line6, const char *buffer, |
| 212 | int size); |
| 213 | extern int line6_send_raw_message_async(struct usb_line6 *line6, |
| 214 | const char *buffer, int size); |
| 215 | extern int line6_send_sysex_message(struct usb_line6 *line6, |
| 216 | const char *buffer, int size); |
| 217 | extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, |
| 218 | const char *buf, size_t count); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 219 | extern void line6_start_timer(struct timer_list *timer, unsigned int msecs, |
Monam Agarwal | 56733e9 | 2014-02-27 21:06:58 +0530 | [diff] [blame] | 220 | void (*function)(unsigned long), |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 221 | unsigned long data); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 222 | extern int line6_transmit_parameter(struct usb_line6 *line6, int param, |
Johannes Thumshirn | 2471c09 | 2012-06-27 21:25:55 +0200 | [diff] [blame] | 223 | u8 value); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 224 | extern int line6_version_request_async(struct usb_line6 *line6); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 225 | extern int line6_write_data(struct usb_line6 *line6, int address, void *data, |
| 226 | size_t datalen); |
Markus Grabner | 1027f476 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 227 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 228 | #endif |