dice.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * dice.h - a part of driver for Dice based devices
  3. *
  4. * Copyright (c) Clemens Ladisch
  5. * Copyright (c) 2014 Takashi Sakamoto
  6. *
  7. * Licensed under the terms of the GNU General Public License, version 2.
  8. */
  9. #ifndef SOUND_DICE_H_INCLUDED
  10. #define SOUND_DICE_H_INCLUDED
  11. #include <linux/compat.h>
  12. #include <linux/completion.h>
  13. #include <linux/delay.h>
  14. #include <linux/device.h>
  15. #include <linux/firewire.h>
  16. #include <linux/firewire-constants.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/module.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/mutex.h>
  21. #include <linux/slab.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/wait.h>
  24. #include <linux/sched/signal.h>
  25. #include <sound/control.h>
  26. #include <sound/core.h>
  27. #include <sound/firewire.h>
  28. #include <sound/hwdep.h>
  29. #include <sound/info.h>
  30. #include <sound/initval.h>
  31. #include <sound/pcm.h>
  32. #include <sound/pcm_params.h>
  33. #include <sound/rawmidi.h>
  34. #include "../amdtp-am824.h"
  35. #include "../iso-resources.h"
  36. #include "../lib.h"
  37. #include "dice-interface.h"
  38. /*
  39. * This module support maximum 2 pairs of tx/rx isochronous streams for
  40. * our convinience.
  41. *
  42. * In documents for ASICs called with a name of 'DICE':
  43. * - ASIC for DICE II:
  44. * - Maximum 2 tx and 4 rx are supported.
  45. * - A packet supports maximum 16 data channels.
  46. * - TCD2210/2210-E (so-called 'Dice Mini'):
  47. * - Maximum 2 tx and 2 rx are supported.
  48. * - A packet supports maximum 16 data channels.
  49. * - TCD2220/2220-E (so-called 'Dice Jr.')
  50. * - 2 tx and 2 rx are supported.
  51. * - A packet supports maximum 16 data channels.
  52. * - TCD3070-CH (so-called 'Dice III')
  53. * - Maximum 2 tx and 2 rx are supported.
  54. * - A packet supports maximum 32 data channels.
  55. *
  56. * For the above, MIDI conformant data channel is just on the first isochronous
  57. * stream.
  58. */
  59. #define MAX_STREAMS 2
  60. enum snd_dice_rate_mode {
  61. SND_DICE_RATE_MODE_LOW = 0,
  62. SND_DICE_RATE_MODE_MIDDLE,
  63. SND_DICE_RATE_MODE_HIGH,
  64. SND_DICE_RATE_MODE_COUNT,
  65. };
  66. struct snd_dice;
  67. typedef int (*snd_dice_detect_formats_t)(struct snd_dice *dice);
  68. struct snd_dice {
  69. struct snd_card *card;
  70. struct fw_unit *unit;
  71. spinlock_t lock;
  72. struct mutex mutex;
  73. bool registered;
  74. struct delayed_work dwork;
  75. /* Offsets for sub-addresses */
  76. unsigned int global_offset;
  77. unsigned int rx_offset;
  78. unsigned int tx_offset;
  79. unsigned int sync_offset;
  80. unsigned int rsrv_offset;
  81. unsigned int clock_caps;
  82. unsigned int tx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
  83. unsigned int rx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
  84. unsigned int tx_midi_ports[MAX_STREAMS];
  85. unsigned int rx_midi_ports[MAX_STREAMS];
  86. snd_dice_detect_formats_t detect_formats;
  87. struct fw_address_handler notification_handler;
  88. int owner_generation;
  89. u32 notification_bits;
  90. /* For uapi */
  91. int dev_lock_count; /* > 0 driver, < 0 userspace */
  92. bool dev_lock_changed;
  93. wait_queue_head_t hwdep_wait;
  94. /* For streaming */
  95. struct fw_iso_resources tx_resources[MAX_STREAMS];
  96. struct fw_iso_resources rx_resources[MAX_STREAMS];
  97. struct amdtp_stream tx_stream[MAX_STREAMS];
  98. struct amdtp_stream rx_stream[MAX_STREAMS];
  99. bool global_enabled;
  100. struct completion clock_accepted;
  101. unsigned int substreams_counter;
  102. };
  103. enum snd_dice_addr_type {
  104. SND_DICE_ADDR_TYPE_PRIVATE,
  105. SND_DICE_ADDR_TYPE_GLOBAL,
  106. SND_DICE_ADDR_TYPE_TX,
  107. SND_DICE_ADDR_TYPE_RX,
  108. SND_DICE_ADDR_TYPE_SYNC,
  109. SND_DICE_ADDR_TYPE_RSRV,
  110. };
  111. int snd_dice_transaction_write(struct snd_dice *dice,
  112. enum snd_dice_addr_type type,
  113. unsigned int offset,
  114. void *buf, unsigned int len);
  115. int snd_dice_transaction_read(struct snd_dice *dice,
  116. enum snd_dice_addr_type type, unsigned int offset,
  117. void *buf, unsigned int len);
  118. static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
  119. unsigned int offset,
  120. void *buf, unsigned int len)
  121. {
  122. return snd_dice_transaction_write(dice,
  123. SND_DICE_ADDR_TYPE_GLOBAL, offset,
  124. buf, len);
  125. }
  126. static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
  127. unsigned int offset,
  128. void *buf, unsigned int len)
  129. {
  130. return snd_dice_transaction_read(dice,
  131. SND_DICE_ADDR_TYPE_GLOBAL, offset,
  132. buf, len);
  133. }
  134. static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
  135. unsigned int offset,
  136. void *buf, unsigned int len)
  137. {
  138. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
  139. buf, len);
  140. }
  141. static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
  142. unsigned int offset,
  143. void *buf, unsigned int len)
  144. {
  145. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
  146. buf, len);
  147. }
  148. static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
  149. unsigned int offset,
  150. void *buf, unsigned int len)
  151. {
  152. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
  153. buf, len);
  154. }
  155. static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
  156. unsigned int offset,
  157. void *buf, unsigned int len)
  158. {
  159. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
  160. buf, len);
  161. }
  162. static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
  163. unsigned int offset,
  164. void *buf, unsigned int len)
  165. {
  166. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
  167. buf, len);
  168. }
  169. static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
  170. unsigned int offset,
  171. void *buf, unsigned int len)
  172. {
  173. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
  174. buf, len);
  175. }
  176. int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
  177. unsigned int *source);
  178. int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
  179. int snd_dice_transaction_set_enable(struct snd_dice *dice);
  180. void snd_dice_transaction_clear_enable(struct snd_dice *dice);
  181. int snd_dice_transaction_init(struct snd_dice *dice);
  182. int snd_dice_transaction_reinit(struct snd_dice *dice);
  183. void snd_dice_transaction_destroy(struct snd_dice *dice);
  184. #define SND_DICE_RATES_COUNT 7
  185. extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
  186. int snd_dice_stream_get_rate_mode(struct snd_dice *dice, unsigned int rate,
  187. enum snd_dice_rate_mode *mode);
  188. int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
  189. void snd_dice_stream_stop_duplex(struct snd_dice *dice);
  190. int snd_dice_stream_init_duplex(struct snd_dice *dice);
  191. void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
  192. void snd_dice_stream_update_duplex(struct snd_dice *dice);
  193. int snd_dice_stream_detect_current_formats(struct snd_dice *dice);
  194. int snd_dice_stream_lock_try(struct snd_dice *dice);
  195. void snd_dice_stream_lock_release(struct snd_dice *dice);
  196. int snd_dice_create_pcm(struct snd_dice *dice);
  197. int snd_dice_create_hwdep(struct snd_dice *dice);
  198. void snd_dice_create_proc(struct snd_dice *dice);
  199. int snd_dice_create_midi(struct snd_dice *dice);
  200. int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice);
  201. int snd_dice_detect_alesis_formats(struct snd_dice *dice);
  202. int snd_dice_detect_extension_formats(struct snd_dice *dice);
  203. int snd_dice_detect_mytek_formats(struct snd_dice *dice);
  204. #endif