dice.h 7.4 KB

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