Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 1 | /* |
Chris Rorvick | c078a4a | 2015-01-20 02:20:50 -0600 | [diff] [blame] | 2 | * Line 6 Linux USB driver |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 3 | * |
Markus Grabner | 1027f47 | 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 | |
Andrej Krutak | 79faa2b | 2016-09-18 20:59:22 +0200 | [diff] [blame] | 21 | /* USB 1.1 speed configuration */ |
| 22 | #define USB_LOW_INTERVALS_PER_SECOND 1000 |
| 23 | #define USB_LOW_ISO_BUFFERS 2 |
| 24 | |
| 25 | /* USB 2.0+ speed configuration */ |
| 26 | #define USB_HIGH_INTERVALS_PER_SECOND 8000 |
| 27 | #define USB_HIGH_ISO_BUFFERS 16 |
Takashi Iwai | 129b3be | 2015-01-28 14:50:08 +0100 | [diff] [blame] | 28 | |
| 29 | /* Fallback USB interval and max packet size values */ |
| 30 | #define LINE6_FALLBACK_INTERVAL 10 |
| 31 | #define LINE6_FALLBACK_MAXPACKETSIZE 16 |
| 32 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 33 | #define LINE6_TIMEOUT 1 |
Andrej Krutak | 97d78ac | 2016-09-18 20:59:24 +0200 | [diff] [blame^] | 34 | #define LINE6_BUFSIZE_LISTEN 64 |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 35 | #define LINE6_MESSAGE_MAXLEN 256 |
| 36 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 37 | /* |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 38 | Line 6 MIDI control commands |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 39 | */ |
| 40 | #define LINE6_PARAM_CHANGE 0xb0 |
| 41 | #define LINE6_PROGRAM_CHANGE 0xc0 |
| 42 | #define LINE6_SYSEX_BEGIN 0xf0 |
| 43 | #define LINE6_SYSEX_END 0xf7 |
| 44 | #define LINE6_RESET 0xff |
| 45 | |
| 46 | /* |
| 47 | MIDI channel for messages initiated by the host |
| 48 | (and eventually echoed back by the device) |
| 49 | */ |
| 50 | #define LINE6_CHANNEL_HOST 0x00 |
| 51 | |
| 52 | /* |
| 53 | MIDI channel for messages initiated by the device |
| 54 | */ |
| 55 | #define LINE6_CHANNEL_DEVICE 0x02 |
| 56 | |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 57 | #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] | 58 | |
| 59 | #define LINE6_CHANNEL_MASK 0x0f |
| 60 | |
Greg Kroah-Hartman | 027360c | 2010-09-21 16:58:00 -0700 | [diff] [blame] | 61 | #define CHECK_STARTUP_PROGRESS(x, n) \ |
| 62 | do { \ |
| 63 | if ((x) >= (n)) \ |
| 64 | return; \ |
| 65 | x = (n); \ |
| 66 | } while (0) |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 67 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 68 | extern const unsigned char line6_midi_id[3]; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 69 | |
| 70 | static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3; |
| 71 | static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4; |
| 72 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 73 | /* |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 74 | Common properties of Line 6 devices. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 75 | */ |
| 76 | struct line6_properties { |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 77 | /* Card id string (maximum 16 characters). |
| 78 | * This can be used to address the device in ALSA programs as |
| 79 | * "default:CARD=<id>" |
| 80 | */ |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 81 | const char *id; |
| 82 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 83 | /* Card short name (maximum 32 characters) */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 84 | const char *name; |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 85 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 86 | /* Bit vector defining this device's capabilities in line6usb driver */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 87 | int capabilities; |
Chris Rorvick | 7b9584f | 2015-01-12 12:42:52 -0800 | [diff] [blame] | 88 | |
| 89 | int altsetting; |
Chris Rorvick | 9e165be | 2015-01-12 12:42:53 -0800 | [diff] [blame] | 90 | |
| 91 | unsigned ep_ctrl_r; |
| 92 | unsigned ep_ctrl_w; |
Chris Rorvick | 16d603d | 2015-01-12 12:42:55 -0800 | [diff] [blame] | 93 | unsigned ep_audio_r; |
| 94 | unsigned ep_audio_w; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
Takashi Iwai | 129b3be | 2015-01-28 14:50:08 +0100 | [diff] [blame] | 97 | /* Capability bits */ |
| 98 | enum { |
| 99 | /* device supports settings parameter via USB */ |
| 100 | LINE6_CAP_CONTROL = 1 << 0, |
| 101 | /* device supports PCM input/output via USB */ |
| 102 | LINE6_CAP_PCM = 1 << 1, |
| 103 | /* device support hardware monitoring */ |
| 104 | LINE6_CAP_HWMON = 1 << 2, |
| 105 | }; |
| 106 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 107 | /* |
Chris Rorvick | c6fffce | 2015-01-20 02:20:49 -0600 | [diff] [blame] | 108 | Common data shared by all Line 6 devices. |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 109 | Corresponds to a pair of USB endpoints. |
| 110 | */ |
| 111 | struct usb_line6 { |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 112 | /* USB device */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 113 | struct usb_device *usbdev; |
| 114 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 115 | /* Properties */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 116 | const struct line6_properties *properties; |
| 117 | |
Andrej Krutak | 79faa2b | 2016-09-18 20:59:22 +0200 | [diff] [blame] | 118 | /* Interval for data USB packets */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 119 | int interval; |
Andrej Krutak | 79faa2b | 2016-09-18 20:59:22 +0200 | [diff] [blame] | 120 | /* ...for isochronous transfers framing */ |
| 121 | int intervals_per_second; |
| 122 | |
Andrej Krutak | b2233d9 | 2016-09-18 20:59:21 +0200 | [diff] [blame] | 123 | /* Number of isochronous URBs used for frame transfers */ |
| 124 | int iso_buffers; |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 125 | |
Andrej Krutak | 79faa2b | 2016-09-18 20:59:22 +0200 | [diff] [blame] | 126 | /* Maximum size of data USB packet */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 127 | int max_packet_size; |
| 128 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 129 | /* Device representing the USB interface */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 130 | struct device *ifcdev; |
| 131 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 132 | /* Line 6 sound card data structure. |
| 133 | * Each device has at least MIDI or PCM. |
| 134 | */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 135 | struct snd_card *card; |
| 136 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 137 | /* Line 6 PCM device data structure */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 138 | struct snd_line6_pcm *line6pcm; |
| 139 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 140 | /* Line 6 MIDI device data structure */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 141 | struct snd_line6_midi *line6midi; |
| 142 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 143 | /* URB for listening to PODxt Pro control endpoint */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 144 | struct urb *urb_listen; |
| 145 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 146 | /* Buffer for listening to PODxt Pro control endpoint */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 147 | unsigned char *buffer_listen; |
| 148 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 149 | /* Buffer for message to be processed */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 150 | unsigned char *buffer_message; |
| 151 | |
Takashi Iwai | cddbd4f | 2015-01-28 14:43:11 +0100 | [diff] [blame] | 152 | /* Length of message to be processed */ |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 153 | int message_length; |
Chris Rorvick | 01f6b2b | 2015-01-12 12:42:58 -0800 | [diff] [blame] | 154 | |
| 155 | void (*process_message)(struct usb_line6 *); |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 156 | void (*disconnect)(struct usb_line6 *line6); |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 157 | }; |
| 158 | |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 159 | extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, |
| 160 | int code2, int size); |
Chris Rorvick | 25a0707 | 2015-02-11 06:03:31 -0600 | [diff] [blame] | 161 | extern int line6_read_data(struct usb_line6 *line6, unsigned address, |
| 162 | void *data, unsigned datalen); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 163 | extern int line6_read_serial_number(struct usb_line6 *line6, |
Chris Rorvick | 12b0015 | 2015-02-10 23:03:16 -0600 | [diff] [blame] | 164 | u32 *serial_number); |
Greg Kroah-Hartman | a49e483 | 2009-02-27 21:09:55 -0800 | [diff] [blame] | 165 | extern int line6_send_raw_message_async(struct usb_line6 *line6, |
| 166 | const char *buffer, int size); |
| 167 | extern int line6_send_sysex_message(struct usb_line6 *line6, |
| 168 | const char *buffer, int size); |
| 169 | extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, |
| 170 | const char *buf, size_t count); |
Nicholas Mc Guire | 6ccd93b | 2015-02-03 02:38:56 -0500 | [diff] [blame] | 171 | extern void line6_start_timer(struct timer_list *timer, unsigned long msecs, |
Monam Agarwal | 56733e9 | 2014-02-27 21:06:58 +0530 | [diff] [blame] | 172 | void (*function)(unsigned long), |
Markus Grabner | e1a164d | 2010-08-23 01:08:25 +0200 | [diff] [blame] | 173 | unsigned long data); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 174 | extern int line6_version_request_async(struct usb_line6 *line6); |
Chris Rorvick | 25a0707 | 2015-02-11 06:03:31 -0600 | [diff] [blame] | 175 | extern int line6_write_data(struct usb_line6 *line6, unsigned address, |
| 176 | void *data, unsigned datalen); |
Markus Grabner | 1027f47 | 2010-08-12 01:35:30 +0200 | [diff] [blame] | 177 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 178 | int line6_probe(struct usb_interface *interface, |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 179 | const struct usb_device_id *id, |
Chris Rorvick | 12865ca | 2015-02-07 10:43:19 -0600 | [diff] [blame] | 180 | const char *driver_name, |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 181 | const struct line6_properties *properties, |
Takashi Iwai | aca514b | 2015-01-25 18:36:29 +0100 | [diff] [blame] | 182 | int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), |
| 183 | size_t data_size); |
Takashi Iwai | f66fd99 | 2015-01-25 18:22:58 +0100 | [diff] [blame] | 184 | |
Takashi Iwai | ccddbe4 | 2015-01-15 08:22:31 +0100 | [diff] [blame] | 185 | void line6_disconnect(struct usb_interface *interface); |
| 186 | |
| 187 | #ifdef CONFIG_PM |
| 188 | int line6_suspend(struct usb_interface *interface, pm_message_t message); |
| 189 | int line6_resume(struct usb_interface *interface); |
| 190 | #endif |
| 191 | |
Markus Grabner | 705ecec | 2009-02-27 19:43:04 -0800 | [diff] [blame] | 192 | #endif |