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