blob: a5c2e9ae5f172732240db27b0140e71385d00a5e [file] [log] [blame]
Markus Grabner705ecec2009-02-27 19:43:04 -08001/*
Chris Rorvickc078a4a2015-01-20 02:20:50 -06002 * Line 6 Linux USB driver
Markus Grabner705ecec2009-02-27 19:43:04 -08003 *
Markus Grabner1027f472010-08-12 01:35:30 +02004 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08005 *
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 Grabner705ecec2009-02-27 19:43:04 -080015#include <linux/usb.h>
Andrej Krutaka16039c2016-09-18 20:59:32 +020016#include <linux/mutex.h>
17#include <linux/kfifo.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080018#include <sound/core.h>
19
20#include "midi.h"
21
Andrej Krutak79faa2b2016-09-18 20:59:22 +020022/* USB 1.1 speed configuration */
23#define USB_LOW_INTERVALS_PER_SECOND 1000
24#define USB_LOW_ISO_BUFFERS 2
25
26/* USB 2.0+ speed configuration */
27#define USB_HIGH_INTERVALS_PER_SECOND 8000
28#define USB_HIGH_ISO_BUFFERS 16
Takashi Iwai129b3be2015-01-28 14:50:08 +010029
30/* Fallback USB interval and max packet size values */
31#define LINE6_FALLBACK_INTERVAL 10
32#define LINE6_FALLBACK_MAXPACKETSIZE 16
33
Markus Grabner705ecec2009-02-27 19:43:04 -080034#define LINE6_TIMEOUT 1
Andrej Krutak97d78ac2016-09-18 20:59:24 +020035#define LINE6_BUFSIZE_LISTEN 64
Andrej Krutaka16039c2016-09-18 20:59:32 +020036#define LINE6_MIDI_MESSAGE_MAXLEN 256
37
38#define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7
39/* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */
40#define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER)
41
42
43#if LINE6_BUFSIZE_LISTEN > 65535
44#error "Use dynamic fifo instead"
45#endif
Markus Grabner705ecec2009-02-27 19:43:04 -080046
Markus Grabner705ecec2009-02-27 19:43:04 -080047/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060048 Line 6 MIDI control commands
Markus Grabner705ecec2009-02-27 19:43:04 -080049*/
50#define LINE6_PARAM_CHANGE 0xb0
51#define LINE6_PROGRAM_CHANGE 0xc0
52#define LINE6_SYSEX_BEGIN 0xf0
53#define LINE6_SYSEX_END 0xf7
54#define LINE6_RESET 0xff
55
56/*
57 MIDI channel for messages initiated by the host
58 (and eventually echoed back by the device)
59*/
60#define LINE6_CHANNEL_HOST 0x00
61
62/*
63 MIDI channel for messages initiated by the device
64*/
65#define LINE6_CHANNEL_DEVICE 0x02
66
Markus Grabnere1a164d2010-08-23 01:08:25 +020067#define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
Markus Grabner705ecec2009-02-27 19:43:04 -080068
69#define LINE6_CHANNEL_MASK 0x0f
70
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -070071#define CHECK_STARTUP_PROGRESS(x, n) \
72do { \
73 if ((x) >= (n)) \
74 return; \
75 x = (n); \
76} while (0)
Markus Grabner1027f472010-08-12 01:35:30 +020077
Markus Grabner705ecec2009-02-27 19:43:04 -080078extern const unsigned char line6_midi_id[3];
Markus Grabner705ecec2009-02-27 19:43:04 -080079
80static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
81static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;
82
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010083/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060084 Common properties of Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -080085*/
86struct line6_properties {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010087 /* Card id string (maximum 16 characters).
88 * This can be used to address the device in ALSA programs as
89 * "default:CARD=<id>"
90 */
Markus Grabner1027f472010-08-12 01:35:30 +020091 const char *id;
92
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010093 /* Card short name (maximum 32 characters) */
Markus Grabner705ecec2009-02-27 19:43:04 -080094 const char *name;
Markus Grabner1027f472010-08-12 01:35:30 +020095
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010096 /* Bit vector defining this device's capabilities in line6usb driver */
Markus Grabner705ecec2009-02-27 19:43:04 -080097 int capabilities;
Chris Rorvick7b9584f2015-01-12 12:42:52 -080098
99 int altsetting;
Chris Rorvick9e165be2015-01-12 12:42:53 -0800100
Andrej Krutakfc901722016-11-29 22:12:51 +0100101 unsigned int ctrl_if;
102 unsigned int ep_ctrl_r;
103 unsigned int ep_ctrl_w;
104 unsigned int ep_audio_r;
105 unsigned int ep_audio_w;
Markus Grabner705ecec2009-02-27 19:43:04 -0800106};
107
Takashi Iwai129b3be2015-01-28 14:50:08 +0100108/* Capability bits */
109enum {
110 /* device supports settings parameter via USB */
111 LINE6_CAP_CONTROL = 1 << 0,
112 /* device supports PCM input/output via USB */
113 LINE6_CAP_PCM = 1 << 1,
Andrej Krutakf56742c2016-09-18 20:59:25 +0200114 /* device supports hardware monitoring */
Takashi Iwai129b3be2015-01-28 14:50:08 +0100115 LINE6_CAP_HWMON = 1 << 2,
Andrej Krutakf56742c2016-09-18 20:59:25 +0200116 /* device requires output data when input is read */
117 LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200118 /* device uses raw MIDI via USB (data endpoints) */
119 LINE6_CAP_CONTROL_MIDI = 1 << 4,
Takashi Iwai129b3be2015-01-28 14:50:08 +0100120};
121
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100122/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600123 Common data shared by all Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -0800124 Corresponds to a pair of USB endpoints.
125*/
126struct usb_line6 {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100127 /* USB device */
Markus Grabner705ecec2009-02-27 19:43:04 -0800128 struct usb_device *usbdev;
129
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100130 /* Properties */
Markus Grabner705ecec2009-02-27 19:43:04 -0800131 const struct line6_properties *properties;
132
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200133 /* Interval for data USB packets */
Markus Grabner705ecec2009-02-27 19:43:04 -0800134 int interval;
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200135 /* ...for isochronous transfers framing */
136 int intervals_per_second;
137
Andrej Krutakb2233d92016-09-18 20:59:21 +0200138 /* Number of isochronous URBs used for frame transfers */
139 int iso_buffers;
Markus Grabner705ecec2009-02-27 19:43:04 -0800140
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200141 /* Maximum size of data USB packet */
Markus Grabner705ecec2009-02-27 19:43:04 -0800142 int max_packet_size;
143
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100144 /* Device representing the USB interface */
Markus Grabner705ecec2009-02-27 19:43:04 -0800145 struct device *ifcdev;
146
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100147 /* Line 6 sound card data structure.
148 * Each device has at least MIDI or PCM.
149 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800150 struct snd_card *card;
151
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100152 /* Line 6 PCM device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800153 struct snd_line6_pcm *line6pcm;
154
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100155 /* Line 6 MIDI device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800156 struct snd_line6_midi *line6midi;
157
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200158 /* URB for listening to POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800159 struct urb *urb_listen;
160
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200161 /* Buffer for incoming data from POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800162 unsigned char *buffer_listen;
163
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200164 /* Buffer for message to be processed, generated from MIDI layer */
Markus Grabner705ecec2009-02-27 19:43:04 -0800165 unsigned char *buffer_message;
166
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200167 /* Length of message to be processed, generated from MIDI layer */
Markus Grabner705ecec2009-02-27 19:43:04 -0800168 int message_length;
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800169
Andrej Krutaka16039c2016-09-18 20:59:32 +0200170 /* Circular buffer for non-MIDI control messages */
171 struct {
172 struct mutex read_lock;
173 wait_queue_head_t wait_queue;
174 unsigned int active:1;
175 STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
176 fifo;
177 } messages;
178
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200179 /* If MIDI is supported, buffer_message contains the pre-processed data;
180 * otherwise the data is only in urb_listen (buffer_incoming).
181 */
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800182 void (*process_message)(struct usb_line6 *);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100183 void (*disconnect)(struct usb_line6 *line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800184};
185
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800186extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
187 int code2, int size);
Chris Rorvick25a07072015-02-11 06:03:31 -0600188extern int line6_read_data(struct usb_line6 *line6, unsigned address,
189 void *data, unsigned datalen);
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800190extern int line6_read_serial_number(struct usb_line6 *line6,
Chris Rorvick12b00152015-02-10 23:03:16 -0600191 u32 *serial_number);
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800192extern int line6_send_raw_message_async(struct usb_line6 *line6,
193 const char *buffer, int size);
194extern int line6_send_sysex_message(struct usb_line6 *line6,
195 const char *buffer, int size);
196extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
197 const char *buf, size_t count);
Nicholas Mc Guire6ccd93b2015-02-03 02:38:56 -0500198extern void line6_start_timer(struct timer_list *timer, unsigned long msecs,
Monam Agarwal56733e92014-02-27 21:06:58 +0530199 void (*function)(unsigned long),
Markus Grabnere1a164d2010-08-23 01:08:25 +0200200 unsigned long data);
Markus Grabner1027f472010-08-12 01:35:30 +0200201extern int line6_version_request_async(struct usb_line6 *line6);
Chris Rorvick25a07072015-02-11 06:03:31 -0600202extern int line6_write_data(struct usb_line6 *line6, unsigned address,
203 void *data, unsigned datalen);
Markus Grabner1027f472010-08-12 01:35:30 +0200204
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100205int line6_probe(struct usb_interface *interface,
Takashi Iwaif66fd992015-01-25 18:22:58 +0100206 const struct usb_device_id *id,
Chris Rorvick12865ca2015-02-07 10:43:19 -0600207 const char *driver_name,
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100208 const struct line6_properties *properties,
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100209 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
210 size_t data_size);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100211
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100212void line6_disconnect(struct usb_interface *interface);
213
214#ifdef CONFIG_PM
215int line6_suspend(struct usb_interface *interface, pm_message_t message);
216int line6_resume(struct usb_interface *interface);
217#endif
218
Markus Grabner705ecec2009-02-27 19:43:04 -0800219#endif