blob: d48c7d2f1575f8b71fddbf7378c1c6d8e204349a [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/spinlock.h>
16#include <linux/usb.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080017#include <sound/core.h>
18
19#include "midi.h"
20
Andrej Krutak79faa2b2016-09-18 20:59:22 +020021/* 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 Iwai129b3be2015-01-28 14:50:08 +010028
29/* Fallback USB interval and max packet size values */
30#define LINE6_FALLBACK_INTERVAL 10
31#define LINE6_FALLBACK_MAXPACKETSIZE 16
32
Markus Grabner705ecec2009-02-27 19:43:04 -080033#define LINE6_TIMEOUT 1
Andrej Krutak97d78ac2016-09-18 20:59:24 +020034#define LINE6_BUFSIZE_LISTEN 64
Markus Grabner705ecec2009-02-27 19:43:04 -080035#define LINE6_MESSAGE_MAXLEN 256
36
Markus Grabner705ecec2009-02-27 19:43:04 -080037/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060038 Line 6 MIDI control commands
Markus Grabner705ecec2009-02-27 19:43:04 -080039*/
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 Grabnere1a164d2010-08-23 01:08:25 +020057#define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
Markus Grabner705ecec2009-02-27 19:43:04 -080058
59#define LINE6_CHANNEL_MASK 0x0f
60
Greg Kroah-Hartman027360c2010-09-21 16:58:00 -070061#define CHECK_STARTUP_PROGRESS(x, n) \
62do { \
63 if ((x) >= (n)) \
64 return; \
65 x = (n); \
66} while (0)
Markus Grabner1027f472010-08-12 01:35:30 +020067
Markus Grabner705ecec2009-02-27 19:43:04 -080068extern const unsigned char line6_midi_id[3];
Markus Grabner705ecec2009-02-27 19:43:04 -080069
70static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
71static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;
72
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010073/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060074 Common properties of Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -080075*/
76struct line6_properties {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010077 /* 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 Grabner1027f472010-08-12 01:35:30 +020081 const char *id;
82
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010083 /* Card short name (maximum 32 characters) */
Markus Grabner705ecec2009-02-27 19:43:04 -080084 const char *name;
Markus Grabner1027f472010-08-12 01:35:30 +020085
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010086 /* Bit vector defining this device's capabilities in line6usb driver */
Markus Grabner705ecec2009-02-27 19:43:04 -080087 int capabilities;
Chris Rorvick7b9584f2015-01-12 12:42:52 -080088
89 int altsetting;
Chris Rorvick9e165be2015-01-12 12:42:53 -080090
91 unsigned ep_ctrl_r;
92 unsigned ep_ctrl_w;
Chris Rorvick16d603d2015-01-12 12:42:55 -080093 unsigned ep_audio_r;
94 unsigned ep_audio_w;
Markus Grabner705ecec2009-02-27 19:43:04 -080095};
96
Takashi Iwai129b3be2015-01-28 14:50:08 +010097/* Capability bits */
98enum {
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,
Andrej Krutakf56742c2016-09-18 20:59:25 +0200103 /* device supports hardware monitoring */
Takashi Iwai129b3be2015-01-28 14:50:08 +0100104 LINE6_CAP_HWMON = 1 << 2,
Andrej Krutakf56742c2016-09-18 20:59:25 +0200105 /* device requires output data when input is read */
106 LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200107 /* device uses raw MIDI via USB (data endpoints) */
108 LINE6_CAP_CONTROL_MIDI = 1 << 4,
Takashi Iwai129b3be2015-01-28 14:50:08 +0100109};
110
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100111/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600112 Common data shared by all Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -0800113 Corresponds to a pair of USB endpoints.
114*/
115struct usb_line6 {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100116 /* USB device */
Markus Grabner705ecec2009-02-27 19:43:04 -0800117 struct usb_device *usbdev;
118
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100119 /* Properties */
Markus Grabner705ecec2009-02-27 19:43:04 -0800120 const struct line6_properties *properties;
121
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200122 /* Interval for data USB packets */
Markus Grabner705ecec2009-02-27 19:43:04 -0800123 int interval;
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200124 /* ...for isochronous transfers framing */
125 int intervals_per_second;
126
Andrej Krutakb2233d92016-09-18 20:59:21 +0200127 /* Number of isochronous URBs used for frame transfers */
128 int iso_buffers;
Markus Grabner705ecec2009-02-27 19:43:04 -0800129
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200130 /* Maximum size of data USB packet */
Markus Grabner705ecec2009-02-27 19:43:04 -0800131 int max_packet_size;
132
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100133 /* Device representing the USB interface */
Markus Grabner705ecec2009-02-27 19:43:04 -0800134 struct device *ifcdev;
135
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100136 /* Line 6 sound card data structure.
137 * Each device has at least MIDI or PCM.
138 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800139 struct snd_card *card;
140
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100141 /* Line 6 PCM device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800142 struct snd_line6_pcm *line6pcm;
143
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100144 /* Line 6 MIDI device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800145 struct snd_line6_midi *line6midi;
146
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200147 /* URB for listening to POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800148 struct urb *urb_listen;
149
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200150 /* Buffer for listening to POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800151 unsigned char *buffer_listen;
152
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100153 /* Buffer for message to be processed */
Markus Grabner705ecec2009-02-27 19:43:04 -0800154 unsigned char *buffer_message;
155
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100156 /* Length of message to be processed */
Markus Grabner705ecec2009-02-27 19:43:04 -0800157 int message_length;
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800158
159 void (*process_message)(struct usb_line6 *);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100160 void (*disconnect)(struct usb_line6 *line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800161};
162
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800163extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
164 int code2, int size);
Chris Rorvick25a07072015-02-11 06:03:31 -0600165extern int line6_read_data(struct usb_line6 *line6, unsigned address,
166 void *data, unsigned datalen);
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800167extern int line6_read_serial_number(struct usb_line6 *line6,
Chris Rorvick12b00152015-02-10 23:03:16 -0600168 u32 *serial_number);
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800169extern int line6_send_raw_message_async(struct usb_line6 *line6,
170 const char *buffer, int size);
171extern int line6_send_sysex_message(struct usb_line6 *line6,
172 const char *buffer, int size);
173extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
174 const char *buf, size_t count);
Nicholas Mc Guire6ccd93b2015-02-03 02:38:56 -0500175extern void line6_start_timer(struct timer_list *timer, unsigned long msecs,
Monam Agarwal56733e92014-02-27 21:06:58 +0530176 void (*function)(unsigned long),
Markus Grabnere1a164d2010-08-23 01:08:25 +0200177 unsigned long data);
Markus Grabner1027f472010-08-12 01:35:30 +0200178extern int line6_version_request_async(struct usb_line6 *line6);
Chris Rorvick25a07072015-02-11 06:03:31 -0600179extern int line6_write_data(struct usb_line6 *line6, unsigned address,
180 void *data, unsigned datalen);
Markus Grabner1027f472010-08-12 01:35:30 +0200181
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100182int line6_probe(struct usb_interface *interface,
Takashi Iwaif66fd992015-01-25 18:22:58 +0100183 const struct usb_device_id *id,
Chris Rorvick12865ca2015-02-07 10:43:19 -0600184 const char *driver_name,
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100185 const struct line6_properties *properties,
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100186 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
187 size_t data_size);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100188
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100189void line6_disconnect(struct usb_interface *interface);
190
191#ifdef CONFIG_PM
192int line6_suspend(struct usb_interface *interface, pm_message_t message);
193int line6_resume(struct usb_interface *interface);
194#endif
195
Markus Grabner705ecec2009-02-27 19:43:04 -0800196#endif