driver.h 5.7 KB

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