Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Line 6 Linux USB driver
0004  *
0005  * Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
0006  */
0007 
0008 #ifndef DRIVER_H
0009 #define DRIVER_H
0010 
0011 #include <linux/usb.h>
0012 #include <linux/mutex.h>
0013 #include <linux/kfifo.h>
0014 #include <sound/core.h>
0015 
0016 #include "midi.h"
0017 
0018 /* USB 1.1 speed configuration */
0019 #define USB_LOW_INTERVALS_PER_SECOND 1000
0020 #define USB_LOW_ISO_BUFFERS 2
0021 
0022 /* USB 2.0+ speed configuration */
0023 #define USB_HIGH_INTERVALS_PER_SECOND 8000
0024 #define USB_HIGH_ISO_BUFFERS 16
0025 
0026 /* Fallback USB interval and max packet size values */
0027 #define LINE6_FALLBACK_INTERVAL 10
0028 #define LINE6_FALLBACK_MAXPACKETSIZE 16
0029 
0030 #define LINE6_TIMEOUT 1000
0031 #define LINE6_BUFSIZE_LISTEN 64
0032 #define LINE6_MIDI_MESSAGE_MAXLEN 256
0033 
0034 #define LINE6_RAW_MESSAGES_MAXCOUNT_ORDER 7
0035 /* 4k packets are common, BUFSIZE * MAXCOUNT should be bigger... */
0036 #define LINE6_RAW_MESSAGES_MAXCOUNT (1 << LINE6_RAW_MESSAGES_MAXCOUNT_ORDER)
0037 
0038 
0039 #if LINE6_BUFSIZE_LISTEN > 65535
0040 #error "Use dynamic fifo instead"
0041 #endif
0042 
0043 /*
0044     Line 6 MIDI control commands
0045 */
0046 #define LINE6_PARAM_CHANGE   0xb0
0047 #define LINE6_PROGRAM_CHANGE 0xc0
0048 #define LINE6_SYSEX_BEGIN    0xf0
0049 #define LINE6_SYSEX_END      0xf7
0050 #define LINE6_RESET          0xff
0051 
0052 /*
0053     MIDI channel for messages initiated by the host
0054     (and eventually echoed back by the device)
0055 */
0056 #define LINE6_CHANNEL_HOST   0x00
0057 
0058 /*
0059     MIDI channel for messages initiated by the device
0060 */
0061 #define LINE6_CHANNEL_DEVICE 0x02
0062 
0063 #define LINE6_CHANNEL_UNKNOWN 5 /* don't know yet what this is good for */
0064 
0065 #define LINE6_CHANNEL_MASK 0x0f
0066 
0067 extern const unsigned char line6_midi_id[3];
0068 
0069 #define SYSEX_DATA_OFS (sizeof(line6_midi_id) + 3)
0070 #define SYSEX_EXTRA_SIZE (sizeof(line6_midi_id) + 4)
0071 
0072 /*
0073      Common properties of Line 6 devices.
0074 */
0075 struct line6_properties {
0076     /* Card id string (maximum 16 characters).
0077      * This can be used to address the device in ALSA programs as
0078      * "default:CARD=<id>"
0079      */
0080     const char *id;
0081 
0082     /* Card short name (maximum 32 characters) */
0083     const char *name;
0084 
0085     /* Bit vector defining this device's capabilities in line6usb driver */
0086     int capabilities;
0087 
0088     int altsetting;
0089 
0090     unsigned int ctrl_if;
0091     unsigned int ep_ctrl_r;
0092     unsigned int ep_ctrl_w;
0093     unsigned int ep_audio_r;
0094     unsigned int ep_audio_w;
0095 };
0096 
0097 /* Capability bits */
0098 enum {
0099     /* device supports settings parameter via USB */
0100     LINE6_CAP_CONTROL = 1 << 0,
0101     /* device supports PCM input/output via USB */
0102     LINE6_CAP_PCM =     1 << 1,
0103     /* device supports hardware monitoring */
0104     LINE6_CAP_HWMON =   1 << 2,
0105     /* device requires output data when input is read */
0106     LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
0107     /* device uses raw MIDI via USB (data endpoints) */
0108     LINE6_CAP_CONTROL_MIDI = 1 << 4,
0109     /* device provides low-level information */
0110     LINE6_CAP_CONTROL_INFO = 1 << 5,
0111     /* device provides hardware monitoring volume control */
0112     LINE6_CAP_HWMON_CTL =   1 << 6,
0113 };
0114 
0115 /*
0116      Common data shared by all Line 6 devices.
0117      Corresponds to a pair of USB endpoints.
0118 */
0119 struct usb_line6 {
0120     /* USB device */
0121     struct usb_device *usbdev;
0122 
0123     /* Properties */
0124     const struct line6_properties *properties;
0125 
0126     /* Interval for data USB packets */
0127     int interval;
0128     /* ...for isochronous transfers framing */
0129     int intervals_per_second;
0130 
0131     /* Number of isochronous URBs used for frame transfers */
0132     int iso_buffers;
0133 
0134     /* Maximum size of data USB packet */
0135     int max_packet_size;
0136 
0137     /* Device representing the USB interface */
0138     struct device *ifcdev;
0139 
0140     /* Line 6 sound card data structure.
0141      * Each device has at least MIDI or PCM.
0142      */
0143     struct snd_card *card;
0144 
0145     /* Line 6 PCM device data structure */
0146     struct snd_line6_pcm *line6pcm;
0147 
0148     /* Line 6 MIDI device data structure */
0149     struct snd_line6_midi *line6midi;
0150 
0151     /* URB for listening to POD data endpoint */
0152     struct urb *urb_listen;
0153 
0154     /* Buffer for incoming data from POD data endpoint */
0155     unsigned char *buffer_listen;
0156 
0157     /* Buffer for message to be processed, generated from MIDI layer */
0158     unsigned char *buffer_message;
0159 
0160     /* Length of message to be processed, generated from MIDI layer  */
0161     int message_length;
0162 
0163     /* Circular buffer for non-MIDI control messages */
0164     struct {
0165         struct mutex read_lock;
0166         wait_queue_head_t wait_queue;
0167         unsigned int active:1;
0168         unsigned int nonblock:1;
0169         STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
0170             fifo;
0171     } messages;
0172 
0173     /* Work for delayed PCM startup */
0174     struct delayed_work startup_work;
0175 
0176     /* If MIDI is supported, buffer_message contains the pre-processed data;
0177      * otherwise the data is only in urb_listen (buffer_incoming).
0178      */
0179     void (*process_message)(struct usb_line6 *);
0180     void (*disconnect)(struct usb_line6 *line6);
0181     void (*startup)(struct usb_line6 *line6);
0182 };
0183 
0184 extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
0185                       int code2, int size);
0186 extern int line6_read_data(struct usb_line6 *line6, unsigned address,
0187                void *data, unsigned datalen);
0188 extern int line6_read_serial_number(struct usb_line6 *line6,
0189                     u32 *serial_number);
0190 extern int line6_send_raw_message(struct usb_line6 *line6,
0191                     const char *buffer, int size);
0192 extern int line6_send_raw_message_async(struct usb_line6 *line6,
0193                     const char *buffer, int size);
0194 extern int line6_send_sysex_message(struct usb_line6 *line6,
0195                     const char *buffer, int size);
0196 extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
0197                  const char *buf, size_t count);
0198 extern int line6_version_request_async(struct usb_line6 *line6);
0199 extern int line6_write_data(struct usb_line6 *line6, unsigned address,
0200                 void *data, unsigned datalen);
0201 
0202 int line6_probe(struct usb_interface *interface,
0203         const struct usb_device_id *id,
0204         const char *driver_name,
0205         const struct line6_properties *properties,
0206         int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
0207         size_t data_size);
0208 
0209 void line6_disconnect(struct usb_interface *interface);
0210 
0211 #ifdef CONFIG_PM
0212 int line6_suspend(struct usb_interface *interface, pm_message_t message);
0213 int line6_resume(struct usb_interface *interface);
0214 #endif
0215 
0216 #endif