2019-05-31 11:09:32 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-02-28 06:43:04 +03:00
|
|
|
/*
|
2015-01-20 11:20:50 +03:00
|
|
|
* Line 6 Linux USB driver
|
2009-02-28 06:43:04 +03:00
|
|
|
*
|
2010-08-12 03:35:30 +04:00
|
|
|
* Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
|
2009-02-28 06:43:04 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DRIVER_H
|
|
|
|
#define DRIVER_H
|
|
|
|
|
|
|
|
#include <linux/usb.h>
|
2016-09-18 21:59:32 +03:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/kfifo.h>
|
2009-02-28 06:43:04 +03:00
|
|
|
#include <sound/core.h>
|
|
|
|
|
|
|
|
#include "midi.h"
|
|
|
|
|
2016-09-18 21:59:22 +03:00
|
|
|
/* USB 1.1 speed configuration */
|
|
|
|
#define USB_LOW_INTERVALS_PER_SECOND 1000
|
|
|
|
#define USB_LOW_ISO_BUFFERS 2
|
|
|
|
|
|
|
|
/* USB 2.0+ speed configuration */
|
|
|
|
#define USB_HIGH_INTERVALS_PER_SECOND 8000
|
|
|
|
#define USB_HIGH_ISO_BUFFERS 16
|
2015-01-28 16:50:08 +03:00
|
|
|
|
|
|
|
/* Fallback USB interval and max packet size values */
|
|
|
|
#define LINE6_FALLBACK_INTERVAL 10
|
|
|
|
#define LINE6_FALLBACK_MAXPACKETSIZE 16
|
|
|
|
|
2021-10-25 15:11:42 +03:00
|
|
|
#define LINE6_TIMEOUT 1000
|
2016-09-18 21:59:24 +03:00
|
|
|
#define LINE6_BUFSIZE_LISTEN 64
|
2016-09-18 21:59:32 +03:00
|
|
|
#define LINE6_MIDI_MESSAGE_MAXLEN 256
|
|
|
|
|
|
|
|
#define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7
|
|
|
|
/* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */
|
|
|
|
#define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER)
|
|
|
|
|
|
|
|
|
|
|
|
#if LINE6_BUFSIZE_LISTEN > 65535
|
|
|
|
#error "Use dynamic fifo instead"
|
|
|
|
#endif
|
2009-02-28 06:43:04 +03:00
|
|
|
|
|
|
|
/*
|
2015-01-20 11:20:49 +03:00
|
|
|
Line 6 MIDI control commands
|
2009-02-28 06:43:04 +03:00
|
|
|
*/
|
|
|
|
#define LINE6_PARAM_CHANGE 0xb0
|
|
|
|
#define LINE6_PROGRAM_CHANGE 0xc0
|
|
|
|
#define LINE6_SYSEX_BEGIN 0xf0
|
|
|
|
#define LINE6_SYSEX_END 0xf7
|
|
|
|
#define LINE6_RESET 0xff
|
|
|
|
|
|
|
|
/*
|
|
|
|
MIDI channel for messages initiated by the host
|
|
|
|
(and eventually echoed back by the device)
|
|
|
|
*/
|
|
|
|
#define LINE6_CHANNEL_HOST 0x00
|
|
|
|
|
|
|
|
/*
|
|
|
|
MIDI channel for messages initiated by the device
|
|
|
|
*/
|
|
|
|
#define LINE6_CHANNEL_DEVICE 0x02
|
|
|
|
|
2010-08-23 03:08:25 +04:00
|
|
|
#define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
|
2009-02-28 06:43:04 +03:00
|
|
|
|
|
|
|
#define LINE6_CHANNEL_MASK 0x0f
|
|
|
|
|
|
|
|
extern const unsigned char line6_midi_id[3];
|
|
|
|
|
2020-07-07 21:49:24 +03:00
|
|
|
#define SYSEX_DATA_OFS (sizeof(line6_midi_id) + 3)
|
|
|
|
#define SYSEX_EXTRA_SIZE (sizeof(line6_midi_id) + 4)
|
2009-02-28 06:43:04 +03:00
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/*
|
2015-01-20 11:20:49 +03:00
|
|
|
Common properties of Line 6 devices.
|
2009-02-28 06:43:04 +03:00
|
|
|
*/
|
|
|
|
struct line6_properties {
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Card id string (maximum 16 characters).
|
|
|
|
* This can be used to address the device in ALSA programs as
|
|
|
|
* "default:CARD=<id>"
|
|
|
|
*/
|
2010-08-12 03:35:30 +04:00
|
|
|
const char *id;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Card short name (maximum 32 characters) */
|
2009-02-28 06:43:04 +03:00
|
|
|
const char *name;
|
2010-08-12 03:35:30 +04:00
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Bit vector defining this device's capabilities in line6usb driver */
|
2009-02-28 06:43:04 +03:00
|
|
|
int capabilities;
|
2015-01-12 23:42:52 +03:00
|
|
|
|
|
|
|
int altsetting;
|
2015-01-12 23:42:53 +03:00
|
|
|
|
2016-11-30 00:12:51 +03:00
|
|
|
unsigned int ctrl_if;
|
|
|
|
unsigned int ep_ctrl_r;
|
|
|
|
unsigned int ep_ctrl_w;
|
|
|
|
unsigned int ep_audio_r;
|
|
|
|
unsigned int ep_audio_w;
|
2009-02-28 06:43:04 +03:00
|
|
|
};
|
|
|
|
|
2015-01-28 16:50:08 +03:00
|
|
|
/* Capability bits */
|
|
|
|
enum {
|
|
|
|
/* device supports settings parameter via USB */
|
|
|
|
LINE6_CAP_CONTROL = 1 << 0,
|
|
|
|
/* device supports PCM input/output via USB */
|
|
|
|
LINE6_CAP_PCM = 1 << 1,
|
2016-09-18 21:59:25 +03:00
|
|
|
/* device supports hardware monitoring */
|
2015-01-28 16:50:08 +03:00
|
|
|
LINE6_CAP_HWMON = 1 << 2,
|
2016-09-18 21:59:25 +03:00
|
|
|
/* device requires output data when input is read */
|
|
|
|
LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
|
2016-09-18 21:59:26 +03:00
|
|
|
/* device uses raw MIDI via USB (data endpoints) */
|
|
|
|
LINE6_CAP_CONTROL_MIDI = 1 << 4,
|
2017-06-16 21:14:17 +03:00
|
|
|
/* device provides low-level information */
|
|
|
|
LINE6_CAP_CONTROL_INFO = 1 << 5,
|
2020-07-13 18:28:52 +03:00
|
|
|
/* device provides hardware monitoring volume control */
|
|
|
|
LINE6_CAP_HWMON_CTL = 1 << 6,
|
2015-01-28 16:50:08 +03:00
|
|
|
};
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/*
|
2015-01-20 11:20:49 +03:00
|
|
|
Common data shared by all Line 6 devices.
|
2009-02-28 06:43:04 +03:00
|
|
|
Corresponds to a pair of USB endpoints.
|
|
|
|
*/
|
|
|
|
struct usb_line6 {
|
2015-01-28 16:43:11 +03:00
|
|
|
/* USB device */
|
2009-02-28 06:43:04 +03:00
|
|
|
struct usb_device *usbdev;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Properties */
|
2009-02-28 06:43:04 +03:00
|
|
|
const struct line6_properties *properties;
|
|
|
|
|
2016-09-18 21:59:22 +03:00
|
|
|
/* Interval for data USB packets */
|
2009-02-28 06:43:04 +03:00
|
|
|
int interval;
|
2016-09-18 21:59:22 +03:00
|
|
|
/* ...for isochronous transfers framing */
|
|
|
|
int intervals_per_second;
|
|
|
|
|
2016-09-18 21:59:21 +03:00
|
|
|
/* Number of isochronous URBs used for frame transfers */
|
|
|
|
int iso_buffers;
|
2009-02-28 06:43:04 +03:00
|
|
|
|
2016-09-18 21:59:22 +03:00
|
|
|
/* Maximum size of data USB packet */
|
2009-02-28 06:43:04 +03:00
|
|
|
int max_packet_size;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Device representing the USB interface */
|
2009-02-28 06:43:04 +03:00
|
|
|
struct device *ifcdev;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Line 6 sound card data structure.
|
|
|
|
* Each device has at least MIDI or PCM.
|
|
|
|
*/
|
2009-02-28 06:43:04 +03:00
|
|
|
struct snd_card *card;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Line 6 PCM device data structure */
|
2009-02-28 06:43:04 +03:00
|
|
|
struct snd_line6_pcm *line6pcm;
|
|
|
|
|
2015-01-28 16:43:11 +03:00
|
|
|
/* Line 6 MIDI device data structure */
|
2009-02-28 06:43:04 +03:00
|
|
|
struct snd_line6_midi *line6midi;
|
|
|
|
|
2016-09-18 21:59:26 +03:00
|
|
|
/* URB for listening to POD data endpoint */
|
2009-02-28 06:43:04 +03:00
|
|
|
struct urb *urb_listen;
|
|
|
|
|
2016-09-18 21:59:27 +03:00
|
|
|
/* Buffer for incoming data from POD data endpoint */
|
2009-02-28 06:43:04 +03:00
|
|
|
unsigned char *buffer_listen;
|
|
|
|
|
2016-09-18 21:59:27 +03:00
|
|
|
/* Buffer for message to be processed, generated from MIDI layer */
|
2009-02-28 06:43:04 +03:00
|
|
|
unsigned char *buffer_message;
|
|
|
|
|
2016-09-18 21:59:27 +03:00
|
|
|
/* Length of message to be processed, generated from MIDI layer */
|
2009-02-28 06:43:04 +03:00
|
|
|
int message_length;
|
2015-01-12 23:42:58 +03:00
|
|
|
|
2016-09-18 21:59:32 +03:00
|
|
|
/* Circular buffer for non-MIDI control messages */
|
|
|
|
struct {
|
|
|
|
struct mutex read_lock;
|
|
|
|
wait_queue_head_t wait_queue;
|
|
|
|
unsigned int active:1;
|
2020-05-02 22:31:19 +03:00
|
|
|
unsigned int nonblock:1;
|
2016-09-18 21:59:32 +03:00
|
|
|
STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
|
|
|
|
fifo;
|
|
|
|
} messages;
|
|
|
|
|
2019-05-28 09:39:44 +03:00
|
|
|
/* Work for delayed PCM startup */
|
|
|
|
struct delayed_work startup_work;
|
|
|
|
|
2016-09-18 21:59:27 +03:00
|
|
|
/* If MIDI is supported, buffer_message contains the pre-processed data;
|
|
|
|
* otherwise the data is only in urb_listen (buffer_incoming).
|
|
|
|
*/
|
2015-01-12 23:42:58 +03:00
|
|
|
void (*process_message)(struct usb_line6 *);
|
2015-01-25 20:22:58 +03:00
|
|
|
void (*disconnect)(struct usb_line6 *line6);
|
2019-05-28 09:39:44 +03:00
|
|
|
void (*startup)(struct usb_line6 *line6);
|
2009-02-28 06:43:04 +03:00
|
|
|
};
|
|
|
|
|
2009-02-28 08:09:55 +03:00
|
|
|
extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
|
|
|
|
int code2, int size);
|
2015-02-11 15:03:31 +03:00
|
|
|
extern int line6_read_data(struct usb_line6 *line6, unsigned address,
|
|
|
|
void *data, unsigned datalen);
|
2009-02-28 08:09:55 +03:00
|
|
|
extern int line6_read_serial_number(struct usb_line6 *line6,
|
2015-02-11 08:03:16 +03:00
|
|
|
u32 *serial_number);
|
2020-07-13 18:28:52 +03:00
|
|
|
extern int line6_send_raw_message(struct usb_line6 *line6,
|
|
|
|
const char *buffer, int size);
|
2009-02-28 08:09:55 +03:00
|
|
|
extern int line6_send_raw_message_async(struct usb_line6 *line6,
|
|
|
|
const char *buffer, int size);
|
|
|
|
extern int line6_send_sysex_message(struct usb_line6 *line6,
|
|
|
|
const char *buffer, int size);
|
|
|
|
extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count);
|
2010-08-12 03:35:30 +04:00
|
|
|
extern int line6_version_request_async(struct usb_line6 *line6);
|
2015-02-11 15:03:31 +03:00
|
|
|
extern int line6_write_data(struct usb_line6 *line6, unsigned address,
|
|
|
|
void *data, unsigned datalen);
|
2010-08-12 03:35:30 +04:00
|
|
|
|
2015-01-15 10:22:31 +03:00
|
|
|
int line6_probe(struct usb_interface *interface,
|
2015-01-25 20:22:58 +03:00
|
|
|
const struct usb_device_id *id,
|
2015-02-07 19:43:19 +03:00
|
|
|
const char *driver_name,
|
2015-01-15 10:22:31 +03:00
|
|
|
const struct line6_properties *properties,
|
2015-01-25 20:36:29 +03:00
|
|
|
int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
|
|
|
|
size_t data_size);
|
2015-01-25 20:22:58 +03:00
|
|
|
|
2015-01-15 10:22:31 +03:00
|
|
|
void line6_disconnect(struct usb_interface *interface);
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
int line6_suspend(struct usb_interface *interface, pm_message_t message);
|
|
|
|
int line6_resume(struct usb_interface *interface);
|
|
|
|
#endif
|
|
|
|
|
2009-02-28 06:43:04 +03:00
|
|
|
#endif
|