blob: dbb1d90d36475e27fcdf10379becf33c19bc7058 [file] [log] [blame]
Thomas Gleixnera10e7632019-05-31 01:09:32 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Markus Grabner705ecec2009-02-27 19:43:04 -08002/*
Chris Rorvickc078a4a2015-01-20 02:20:50 -06003 * Line 6 Linux USB driver
Markus Grabner705ecec2009-02-27 19:43:04 -08004 *
Markus Grabner1027f472010-08-12 01:35:30 +02005 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
Markus Grabner705ecec2009-02-27 19:43:04 -08006 */
7
8#ifndef DRIVER_H
9#define DRIVER_H
10
Markus Grabner705ecec2009-02-27 19:43:04 -080011#include <linux/usb.h>
Andrej Krutaka16039cb2016-09-18 20:59:32 +020012#include <linux/mutex.h>
13#include <linux/kfifo.h>
Markus Grabner705ecec2009-02-27 19:43:04 -080014#include <sound/core.h>
15
16#include "midi.h"
17
Andrej Krutak79faa2b2016-09-18 20:59:22 +020018/* 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
Takashi Iwai129b3be2015-01-28 14:50:08 +010025
26/* Fallback USB interval and max packet size values */
27#define LINE6_FALLBACK_INTERVAL 10
28#define LINE6_FALLBACK_MAXPACKETSIZE 16
29
Johan Hovoldf4000b582021-10-25 14:11:42 +020030#define LINE6_TIMEOUT 1000
Andrej Krutak97d78ac2016-09-18 20:59:24 +020031#define LINE6_BUFSIZE_LISTEN 64
Andrej Krutaka16039cb2016-09-18 20:59:32 +020032#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
Markus Grabner705ecec2009-02-27 19:43:04 -080042
Markus Grabner705ecec2009-02-27 19:43:04 -080043/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060044 Line 6 MIDI control commands
Markus Grabner705ecec2009-02-27 19:43:04 -080045*/
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
Markus Grabnere1a164d2010-08-23 01:08:25 +020063#define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
Markus Grabner705ecec2009-02-27 19:43:04 -080064
65#define LINE6_CHANNEL_MASK 0x0f
66
Markus Grabner705ecec2009-02-27 19:43:04 -080067extern const unsigned char line6_midi_id[3];
Markus Grabner705ecec2009-02-27 19:43:04 -080068
Pierre-Louis Bossartec033702020-07-07 13:49:24 -050069#define SYSEX_DATA_OFS (sizeof(line6_midi_id) + 3)
70#define SYSEX_EXTRA_SIZE (sizeof(line6_midi_id) + 4)
Markus Grabner705ecec2009-02-27 19:43:04 -080071
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010072/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -060073 Common properties of Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -080074*/
75struct line6_properties {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010076 /* Card id string (maximum 16 characters).
77 * This can be used to address the device in ALSA programs as
78 * "default:CARD=<id>"
79 */
Markus Grabner1027f472010-08-12 01:35:30 +020080 const char *id;
81
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010082 /* Card short name (maximum 32 characters) */
Markus Grabner705ecec2009-02-27 19:43:04 -080083 const char *name;
Markus Grabner1027f472010-08-12 01:35:30 +020084
Takashi Iwaicddbd4f2015-01-28 14:43:11 +010085 /* Bit vector defining this device's capabilities in line6usb driver */
Markus Grabner705ecec2009-02-27 19:43:04 -080086 int capabilities;
Chris Rorvick7b9584f2015-01-12 12:42:52 -080087
88 int altsetting;
Chris Rorvick9e165be2015-01-12 12:42:53 -080089
Andrej Krutakfc901722016-11-29 22:12:51 +010090 unsigned int ctrl_if;
91 unsigned int ep_ctrl_r;
92 unsigned int ep_ctrl_w;
93 unsigned int ep_audio_r;
94 unsigned int 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,
Hans P. Möller Ebner8cad7a32017-06-16 14:14:17 -0400109 /* device provides low-level information */
110 LINE6_CAP_CONTROL_INFO = 1 << 5,
Vasily Khoruzhick0afff872020-07-13 08:28:52 -0700111 /* device provides hardware monitoring volume control */
112 LINE6_CAP_HWMON_CTL = 1 << 6,
Takashi Iwai129b3be2015-01-28 14:50:08 +0100113};
114
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100115/*
Chris Rorvickc6fffce2015-01-20 02:20:49 -0600116 Common data shared by all Line 6 devices.
Markus Grabner705ecec2009-02-27 19:43:04 -0800117 Corresponds to a pair of USB endpoints.
118*/
119struct usb_line6 {
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100120 /* USB device */
Markus Grabner705ecec2009-02-27 19:43:04 -0800121 struct usb_device *usbdev;
122
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100123 /* Properties */
Markus Grabner705ecec2009-02-27 19:43:04 -0800124 const struct line6_properties *properties;
125
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200126 /* Interval for data USB packets */
Markus Grabner705ecec2009-02-27 19:43:04 -0800127 int interval;
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200128 /* ...for isochronous transfers framing */
129 int intervals_per_second;
130
Andrej Krutakb2233d92016-09-18 20:59:21 +0200131 /* Number of isochronous URBs used for frame transfers */
132 int iso_buffers;
Markus Grabner705ecec2009-02-27 19:43:04 -0800133
Andrej Krutak79faa2b2016-09-18 20:59:22 +0200134 /* Maximum size of data USB packet */
Markus Grabner705ecec2009-02-27 19:43:04 -0800135 int max_packet_size;
136
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100137 /* Device representing the USB interface */
Markus Grabner705ecec2009-02-27 19:43:04 -0800138 struct device *ifcdev;
139
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100140 /* Line 6 sound card data structure.
141 * Each device has at least MIDI or PCM.
142 */
Markus Grabner705ecec2009-02-27 19:43:04 -0800143 struct snd_card *card;
144
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100145 /* Line 6 PCM device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800146 struct snd_line6_pcm *line6pcm;
147
Takashi Iwaicddbd4f2015-01-28 14:43:11 +0100148 /* Line 6 MIDI device data structure */
Markus Grabner705ecec2009-02-27 19:43:04 -0800149 struct snd_line6_midi *line6midi;
150
Andrej Krutak174e1fc2016-09-18 20:59:26 +0200151 /* URB for listening to POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800152 struct urb *urb_listen;
153
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200154 /* Buffer for incoming data from POD data endpoint */
Markus Grabner705ecec2009-02-27 19:43:04 -0800155 unsigned char *buffer_listen;
156
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200157 /* Buffer for message to be processed, generated from MIDI layer */
Markus Grabner705ecec2009-02-27 19:43:04 -0800158 unsigned char *buffer_message;
159
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200160 /* Length of message to be processed, generated from MIDI layer */
Markus Grabner705ecec2009-02-27 19:43:04 -0800161 int message_length;
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800162
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200163 /* Circular buffer for non-MIDI control messages */
164 struct {
165 struct mutex read_lock;
166 wait_queue_head_t wait_queue;
167 unsigned int active:1;
Vasily Khoruzhick5c2d0de2020-05-02 12:31:19 -0700168 unsigned int nonblock:1;
Andrej Krutaka16039cb2016-09-18 20:59:32 +0200169 STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
170 fifo;
171 } messages;
172
Takashi Iwai0b074ab2019-05-28 08:39:44 +0200173 /* Work for delayed PCM startup */
174 struct delayed_work startup_work;
175
Andrej Krutak7811a3a2016-09-18 20:59:27 +0200176 /* If MIDI is supported, buffer_message contains the pre-processed data;
177 * otherwise the data is only in urb_listen (buffer_incoming).
178 */
Chris Rorvick01f6b2b2015-01-12 12:42:58 -0800179 void (*process_message)(struct usb_line6 *);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100180 void (*disconnect)(struct usb_line6 *line6);
Takashi Iwai0b074ab2019-05-28 08:39:44 +0200181 void (*startup)(struct usb_line6 *line6);
Markus Grabner705ecec2009-02-27 19:43:04 -0800182};
183
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800184extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
185 int code2, int size);
Chris Rorvick25a07072015-02-11 06:03:31 -0600186extern int line6_read_data(struct usb_line6 *line6, unsigned address,
187 void *data, unsigned datalen);
Greg Kroah-Hartmana49e4832009-02-27 21:09:55 -0800188extern int line6_read_serial_number(struct usb_line6 *line6,
Chris Rorvick12b00152015-02-10 23:03:16 -0600189 u32 *serial_number);
Vasily Khoruzhick0afff872020-07-13 08:28:52 -0700190extern int line6_send_raw_message(struct usb_line6 *line6,
191 const char *buffer, int size);
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);
Markus Grabner1027f472010-08-12 01:35:30 +0200196extern int line6_version_request_async(struct usb_line6 *line6);
Chris Rorvick25a07072015-02-11 06:03:31 -0600197extern int line6_write_data(struct usb_line6 *line6, unsigned address,
198 void *data, unsigned datalen);
Markus Grabner1027f472010-08-12 01:35:30 +0200199
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100200int line6_probe(struct usb_interface *interface,
Takashi Iwaif66fd992015-01-25 18:22:58 +0100201 const struct usb_device_id *id,
Chris Rorvick12865ca2015-02-07 10:43:19 -0600202 const char *driver_name,
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100203 const struct line6_properties *properties,
Takashi Iwaiaca514b2015-01-25 18:36:29 +0100204 int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
205 size_t data_size);
Takashi Iwaif66fd992015-01-25 18:22:58 +0100206
Takashi Iwaiccddbe42015-01-15 08:22:31 +0100207void line6_disconnect(struct usb_interface *interface);
208
209#ifdef CONFIG_PM
210int line6_suspend(struct usb_interface *interface, pm_message_t message);
211int line6_resume(struct usb_interface *interface);
212#endif
213
Markus Grabner705ecec2009-02-27 19:43:04 -0800214#endif