1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Line 6 Linux USB driver 4 * 5 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at) 6 */ 7 8 #ifndef DRIVER_H 9 #define DRIVER_H 10 11 #include <linux/usb.h> 12 #include <linux/mutex.h> 13 #include <linux/kfifo.h> 14 #include <sound/core.h> 15 16 #include "midi.h" 17 18 /* USB 1.1 speed configuration */ 19 #define USB_LOW_INTERVALS_PER_SECOND 1000 20 #define USB_LOW_ISO_BUFFERS 2 21 22 /* USB 2.0+ speed configuration */ 23 #define USB_HIGH_INTERVALS_PER_SECOND 8000 24 #define USB_HIGH_ISO_BUFFERS 16 25 26 /* Fallback USB interval and max packet size values */ 27 #define LINE6_FALLBACK_INTERVAL 10 28 #define LINE6_FALLBACK_MAXPACKETSIZE 16 29 30 #define LINE6_TIMEOUT 1 31 #define LINE6_BUFSIZE_LISTEN 64 32 #define LINE6_MIDI_MESSAGE_MAXLEN 256 33 34 #define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7 35 /* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */ 36 #define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER) 37 38 39 #if LINE6_BUFSIZE_LISTEN > 65535 40 #error "Use dynamic fifo instead" 41 #endif 42 43 /* 44 Line 6 MIDI control commands 45 */ 46 #define LINE6_PARAM_CHANGE 0xb0 47 #define LINE6_PROGRAM_CHANGE 0xc0 48 #define LINE6_SYSEX_BEGIN 0xf0 49 #define LINE6_SYSEX_END 0xf7 50 #define LINE6_RESET 0xff 51 52 /* 53 MIDI channel for messages initiated by the host 54 (and eventually echoed back by the device) 55 */ 56 #define LINE6_CHANNEL_HOST 0x00 57 58 /* 59 MIDI channel for messages initiated by the device 60 */ 61 #define LINE6_CHANNEL_DEVICE 0x02 62 63 #define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */ 64 65 #define LINE6_CHANNEL_MASK 0x0f 66 67 #define CHECK_STARTUP_PROGRESS(x, n) \ 68 do { \ 69 if ((x) >= (n)) \ 70 return; \ 71 x = (n); \ 72 } while (0) 73 74 extern const unsigned char line6_midi_id[3]; 75 76 static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3; 77 static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4; 78 79 /* 80 Common properties of Line 6 devices. 81 */ 82 struct line6_properties { 83 /* Card id string (maximum 16 characters). 84 * This can be used to address the device in ALSA programs as 85 * "default:CARD=<id>" 86 */ 87 const char *id; 88 89 /* Card short name (maximum 32 characters) */ 90 const char *name; 91 92 /* Bit vector defining this device's capabilities in line6usb driver */ 93 int capabilities; 94 95 int altsetting; 96 97 unsigned int ctrl_if; 98 unsigned int ep_ctrl_r; 99 unsigned int ep_ctrl_w; 100 unsigned int ep_audio_r; 101 unsigned int ep_audio_w; 102 }; 103 104 /* Capability bits */ 105 enum { 106 /* device supports settings parameter via USB */ 107 LINE6_CAP_CONTROL = 1 << 0, 108 /* device supports PCM input/output via USB */ 109 LINE6_CAP_PCM = 1 << 1, 110 /* device supports hardware monitoring */ 111 LINE6_CAP_HWMON = 1 << 2, 112 /* device requires output data when input is read */ 113 LINE6_CAP_IN_NEEDS_OUT = 1 << 3, 114 /* device uses raw MIDI via USB (data endpoints) */ 115 LINE6_CAP_CONTROL_MIDI = 1 << 4, 116 /* device provides low-level information */ 117 LINE6_CAP_CONTROL_INFO = 1 << 5, 118 }; 119 120 /* 121 Common data shared by all Line 6 devices. 122 Corresponds to a pair of USB endpoints. 123 */ 124 struct usb_line6 { 125 /* USB device */ 126 struct usb_device *usbdev; 127 128 /* Properties */ 129 const struct line6_properties *properties; 130 131 /* Interval for data USB packets */ 132 int interval; 133 /* ...for isochronous transfers framing */ 134 int intervals_per_second; 135 136 /* Number of isochronous URBs used for frame transfers */ 137 int iso_buffers; 138 139 /* Maximum size of data USB packet */ 140 int max_packet_size; 141 142 /* Device representing the USB interface */ 143 struct device *ifcdev; 144 145 /* Line 6 sound card data structure. 146 * Each device has at least MIDI or PCM. 147 */ 148 struct snd_card *card; 149 150 /* Line 6 PCM device data structure */ 151 struct snd_line6_pcm *line6pcm; 152 153 /* Line 6 MIDI device data structure */ 154 struct snd_line6_midi *line6midi; 155 156 /* URB for listening to POD data endpoint */ 157 struct urb *urb_listen; 158 159 /* Buffer for incoming data from POD data endpoint */ 160 unsigned char *buffer_listen; 161 162 /* Buffer for message to be processed, generated from MIDI layer */ 163 unsigned char *buffer_message; 164 165 /* Length of message to be processed, generated from MIDI layer */ 166 int message_length; 167 168 /* Circular buffer for non-MIDI control messages */ 169 struct { 170 struct mutex read_lock; 171 wait_queue_head_t wait_queue; 172 unsigned int active:1; 173 STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT) 174 fifo; 175 } messages; 176 177 /* Work for delayed PCM startup */ 178 struct delayed_work startup_work; 179 180 /* If MIDI is supported, buffer_message contains the pre-processed data; 181 * otherwise the data is only in urb_listen (buffer_incoming). 182 */ 183 void (*process_message)(struct usb_line6 *); 184 void (*disconnect)(struct usb_line6 *line6); 185 void (*startup)(struct usb_line6 *line6); 186 }; 187 188 extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, 189 int code2, int size); 190 extern int line6_read_data(struct usb_line6 *line6, unsigned address, 191 void *data, unsigned datalen); 192 extern int line6_read_serial_number(struct usb_line6 *line6, 193 u32 *serial_number); 194 extern int line6_send_raw_message_async(struct usb_line6 *line6, 195 const char *buffer, int size); 196 extern int line6_send_sysex_message(struct usb_line6 *line6, 197 const char *buffer, int size); 198 extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, 199 const char *buf, size_t count); 200 extern void line6_start_timer(struct timer_list *timer, unsigned long msecs, 201 void (*function)(struct timer_list *t)); 202 extern int line6_version_request_async(struct usb_line6 *line6); 203 extern int line6_write_data(struct usb_line6 *line6, unsigned address, 204 void *data, unsigned datalen); 205 206 int line6_probe(struct usb_interface *interface, 207 const struct usb_device_id *id, 208 const char *driver_name, 209 const struct line6_properties *properties, 210 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), 211 size_t data_size); 212 213 void line6_disconnect(struct usb_interface *interface); 214 215 #ifdef CONFIG_PM 216 int line6_suspend(struct usb_interface *interface, pm_message_t message); 217 int line6_resume(struct usb_interface *interface); 218 #endif 219 220 #endif 221