driver.h 6.0 KB

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