driver.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 ep_ctrl_r;
  79. unsigned ep_ctrl_w;
  80. unsigned ep_audio_r;
  81. unsigned ep_audio_w;
  82. };
  83. /* Capability bits */
  84. enum {
  85. /* device supports settings parameter via USB */
  86. LINE6_CAP_CONTROL = 1 << 0,
  87. /* device supports PCM input/output via USB */
  88. LINE6_CAP_PCM = 1 << 1,
  89. /* device supports hardware monitoring */
  90. LINE6_CAP_HWMON = 1 << 2,
  91. /* device requires output data when input is read */
  92. LINE6_CAP_IN_NEEDS_OUT = 1 << 3,
  93. /* device uses raw MIDI via USB (data endpoints) */
  94. LINE6_CAP_CONTROL_MIDI = 1 << 4,
  95. };
  96. /*
  97. Common data shared by all Line 6 devices.
  98. Corresponds to a pair of USB endpoints.
  99. */
  100. struct usb_line6 {
  101. /* USB device */
  102. struct usb_device *usbdev;
  103. /* Properties */
  104. const struct line6_properties *properties;
  105. /* Interval for data USB packets */
  106. int interval;
  107. /* ...for isochronous transfers framing */
  108. int intervals_per_second;
  109. /* Number of isochronous URBs used for frame transfers */
  110. int iso_buffers;
  111. /* Maximum size of data USB packet */
  112. int max_packet_size;
  113. /* Device representing the USB interface */
  114. struct device *ifcdev;
  115. /* Line 6 sound card data structure.
  116. * Each device has at least MIDI or PCM.
  117. */
  118. struct snd_card *card;
  119. /* Line 6 PCM device data structure */
  120. struct snd_line6_pcm *line6pcm;
  121. /* Line 6 MIDI device data structure */
  122. struct snd_line6_midi *line6midi;
  123. /* URB for listening to POD data endpoint */
  124. struct urb *urb_listen;
  125. /* Buffer for incoming data from POD data endpoint */
  126. unsigned char *buffer_listen;
  127. /* Buffer for message to be processed, generated from MIDI layer */
  128. unsigned char *buffer_message;
  129. /* Length of message to be processed, generated from MIDI layer */
  130. int message_length;
  131. /* Circular buffer for non-MIDI control messages */
  132. struct {
  133. struct mutex read_lock;
  134. wait_queue_head_t wait_queue;
  135. unsigned int active:1;
  136. STRUCT_KFIFO_REC_2(LINE6_BUFSIZE_LISTEN * LINE6_RAW_MESSAGES_MAXCOUNT)
  137. fifo;
  138. } messages;
  139. /* If MIDI is supported, buffer_message contains the pre-processed data;
  140. * otherwise the data is only in urb_listen (buffer_incoming).
  141. */
  142. void (*process_message)(struct usb_line6 *);
  143. void (*disconnect)(struct usb_line6 *line6);
  144. };
  145. extern char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1,
  146. int code2, int size);
  147. extern int line6_read_data(struct usb_line6 *line6, unsigned address,
  148. void *data, unsigned datalen);
  149. extern int line6_read_serial_number(struct usb_line6 *line6,
  150. u32 *serial_number);
  151. extern int line6_send_raw_message_async(struct usb_line6 *line6,
  152. const char *buffer, int size);
  153. extern int line6_send_sysex_message(struct usb_line6 *line6,
  154. const char *buffer, int size);
  155. extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
  156. const char *buf, size_t count);
  157. extern void line6_start_timer(struct timer_list *timer, unsigned long msecs,
  158. void (*function)(unsigned long),
  159. unsigned long data);
  160. extern int line6_version_request_async(struct usb_line6 *line6);
  161. extern int line6_write_data(struct usb_line6 *line6, unsigned address,
  162. void *data, unsigned datalen);
  163. int line6_probe(struct usb_interface *interface,
  164. const struct usb_device_id *id,
  165. const char *driver_name,
  166. const struct line6_properties *properties,
  167. int (*private_init)(struct usb_line6 *, const struct usb_device_id *id),
  168. size_t data_size);
  169. void line6_disconnect(struct usb_interface *interface);
  170. #ifdef CONFIG_PM
  171. int line6_suspend(struct usb_interface *interface, pm_message_t message);
  172. int line6_resume(struct usb_interface *interface);
  173. #endif
  174. #endif