Linux Audio

Check our new training course

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