driver.h 4.6 KB
Newer Older
M
Markus Grabner 已提交
1
/*
2
 * Line 6 Linux USB driver
M
Markus Grabner 已提交
3
 *
4
 * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
M
Markus Grabner 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation, version 2.
 *
 */

#ifndef DRIVER_H
#define DRIVER_H

#include <linux/spinlock.h>
#include <linux/usb.h>
#include <sound/core.h>

#include "midi.h"

#define DRIVER_NAME "line6usb"

23 24 25 26 27 28
#define USB_INTERVALS_PER_SECOND 1000

/* Fallback USB interval and max packet size values */
#define LINE6_FALLBACK_INTERVAL 10
#define LINE6_FALLBACK_MAXPACKETSIZE 16

M
Markus Grabner 已提交
29 30 31 32 33
#define LINE6_TIMEOUT 1
#define LINE6_BUFSIZE_LISTEN 32
#define LINE6_MESSAGE_MAXLEN 256

/*
34
	Line 6 MIDI control commands
M
Markus Grabner 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
*/
#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

53
#define LINE6_CHANNEL_UNKNOWN 5	/* don't know yet what this is good for */
M
Markus Grabner 已提交
54 55 56

#define LINE6_CHANNEL_MASK 0x0f

57 58 59 60 61 62
#define CHECK_STARTUP_PROGRESS(x, n)	\
do {					\
	if ((x) >= (n))			\
		return;			\
	x = (n);			\
} while (0)
63

M
Markus Grabner 已提交
64 65 66 67 68
extern const unsigned char line6_midi_id[3];

static const int SYSEX_DATA_OFS = sizeof(line6_midi_id) + 3;
static const int SYSEX_EXTRA_SIZE = sizeof(line6_midi_id) + 4;

69
/*
70
	 Common properties of Line 6 devices.
M
Markus Grabner 已提交
71 72
*/
struct line6_properties {
73 74 75 76
	/* Card id string (maximum 16 characters).
	 * This can be used to address the device in ALSA programs as
	 * "default:CARD=<id>"
	 */
77 78
	const char *id;

79
	/* Card short name (maximum 32 characters) */
M
Markus Grabner 已提交
80
	const char *name;
81

82
	/* Bit vector defining this device's capabilities in line6usb driver */
M
Markus Grabner 已提交
83
	int capabilities;
84 85

	int altsetting;
86 87 88

	unsigned ep_ctrl_r;
	unsigned ep_ctrl_w;
89 90
	unsigned ep_audio_r;
	unsigned ep_audio_w;
M
Markus Grabner 已提交
91 92
};

93 94 95 96 97 98 99 100 101 102
/* 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,
	/* device support hardware monitoring */
	LINE6_CAP_HWMON =	1 << 2,
};

103
/*
104
	 Common data shared by all Line 6 devices.
M
Markus Grabner 已提交
105 106 107
	 Corresponds to a pair of USB endpoints.
*/
struct usb_line6 {
108
	/* USB device */
M
Markus Grabner 已提交
109 110
	struct usb_device *usbdev;

111
	/* Properties */
M
Markus Grabner 已提交
112 113
	const struct line6_properties *properties;

114
	/* Interval (ms) */
M
Markus Grabner 已提交
115 116
	int interval;

117
	/* Maximum size of USB packet */
M
Markus Grabner 已提交
118 119
	int max_packet_size;

120
	/* Device representing the USB interface */
M
Markus Grabner 已提交
121 122
	struct device *ifcdev;

123 124 125
	/* Line 6 sound card data structure.
	 * Each device has at least MIDI or PCM.
	 */
M
Markus Grabner 已提交
126 127
	struct snd_card *card;

128
	/* Line 6 PCM device data structure */
M
Markus Grabner 已提交
129 130
	struct snd_line6_pcm *line6pcm;

131
	/* Line 6 MIDI device data structure */
M
Markus Grabner 已提交
132 133
	struct snd_line6_midi *line6midi;

134
	/* URB for listening to PODxt Pro control endpoint */
M
Markus Grabner 已提交
135 136
	struct urb *urb_listen;

137
	/* Buffer for listening to PODxt Pro control endpoint */
M
Markus Grabner 已提交
138 139
	unsigned char *buffer_listen;

140
	/* Buffer for message to be processed */
M
Markus Grabner 已提交
141 142
	unsigned char *buffer_message;

143
	/* Length of message to be processed */
M
Markus Grabner 已提交
144
	int message_length;
145 146

	void (*process_message)(struct usb_line6 *);
147
	void (*disconnect)(struct usb_line6 *line6);
M
Markus Grabner 已提交
148 149
};

150 151 152 153 154 155 156 157 158 159 160 161
extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
				      int code2, int size);
extern int line6_read_data(struct usb_line6 *line6, int address, void *data,
			   size_t datalen);
extern int line6_read_serial_number(struct usb_line6 *line6,
				    int *serial_number);
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);
162
extern void line6_start_timer(struct timer_list *timer, unsigned int msecs,
163
			      void (*function)(unsigned long),
164
			      unsigned long data);
165
extern int line6_version_request_async(struct usb_line6 *line6);
166 167
extern int line6_write_data(struct usb_line6 *line6, int address, void *data,
			    size_t datalen);
168

T
Takashi Iwai 已提交
169
int line6_probe(struct usb_interface *interface,
170
		const struct usb_device_id *id,
T
Takashi Iwai 已提交
171
		const struct line6_properties *properties,
172 173
		int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
		size_t data_size);
174

T
Takashi Iwai 已提交
175 176 177 178 179 180 181
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

M
Markus Grabner 已提交
182
#endif