dice.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. struct snd_dice {
  61. struct snd_card *card;
  62. struct fw_unit *unit;
  63. spinlock_t lock;
  64. struct mutex mutex;
  65. bool registered;
  66. struct delayed_work dwork;
  67. /* Offsets for sub-addresses */
  68. unsigned int global_offset;
  69. unsigned int rx_offset;
  70. unsigned int tx_offset;
  71. unsigned int sync_offset;
  72. unsigned int rsrv_offset;
  73. unsigned int clock_caps;
  74. struct fw_address_handler notification_handler;
  75. int owner_generation;
  76. u32 notification_bits;
  77. /* For uapi */
  78. int dev_lock_count; /* > 0 driver, < 0 userspace */
  79. bool dev_lock_changed;
  80. wait_queue_head_t hwdep_wait;
  81. /* For streaming */
  82. struct fw_iso_resources tx_resources[MAX_STREAMS];
  83. struct fw_iso_resources rx_resources[MAX_STREAMS];
  84. struct amdtp_stream tx_stream[MAX_STREAMS];
  85. struct amdtp_stream rx_stream[MAX_STREAMS];
  86. bool global_enabled;
  87. struct completion clock_accepted;
  88. unsigned int substreams_counter;
  89. bool force_two_pcms;
  90. };
  91. enum snd_dice_addr_type {
  92. SND_DICE_ADDR_TYPE_PRIVATE,
  93. SND_DICE_ADDR_TYPE_GLOBAL,
  94. SND_DICE_ADDR_TYPE_TX,
  95. SND_DICE_ADDR_TYPE_RX,
  96. SND_DICE_ADDR_TYPE_SYNC,
  97. SND_DICE_ADDR_TYPE_RSRV,
  98. };
  99. int snd_dice_transaction_write(struct snd_dice *dice,
  100. enum snd_dice_addr_type type,
  101. unsigned int offset,
  102. void *buf, unsigned int len);
  103. int snd_dice_transaction_read(struct snd_dice *dice,
  104. enum snd_dice_addr_type type, unsigned int offset,
  105. void *buf, unsigned int len);
  106. static inline int snd_dice_transaction_write_global(struct snd_dice *dice,
  107. unsigned int offset,
  108. void *buf, unsigned int len)
  109. {
  110. return snd_dice_transaction_write(dice,
  111. SND_DICE_ADDR_TYPE_GLOBAL, offset,
  112. buf, len);
  113. }
  114. static inline int snd_dice_transaction_read_global(struct snd_dice *dice,
  115. unsigned int offset,
  116. void *buf, unsigned int len)
  117. {
  118. return snd_dice_transaction_read(dice,
  119. SND_DICE_ADDR_TYPE_GLOBAL, offset,
  120. buf, len);
  121. }
  122. static inline int snd_dice_transaction_write_tx(struct snd_dice *dice,
  123. unsigned int offset,
  124. void *buf, unsigned int len)
  125. {
  126. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_TX, offset,
  127. buf, len);
  128. }
  129. static inline int snd_dice_transaction_read_tx(struct snd_dice *dice,
  130. unsigned int offset,
  131. void *buf, unsigned int len)
  132. {
  133. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_TX, offset,
  134. buf, len);
  135. }
  136. static inline int snd_dice_transaction_write_rx(struct snd_dice *dice,
  137. unsigned int offset,
  138. void *buf, unsigned int len)
  139. {
  140. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_RX, offset,
  141. buf, len);
  142. }
  143. static inline int snd_dice_transaction_read_rx(struct snd_dice *dice,
  144. unsigned int offset,
  145. void *buf, unsigned int len)
  146. {
  147. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_RX, offset,
  148. buf, len);
  149. }
  150. static inline int snd_dice_transaction_write_sync(struct snd_dice *dice,
  151. unsigned int offset,
  152. void *buf, unsigned int len)
  153. {
  154. return snd_dice_transaction_write(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
  155. buf, len);
  156. }
  157. static inline int snd_dice_transaction_read_sync(struct snd_dice *dice,
  158. unsigned int offset,
  159. void *buf, unsigned int len)
  160. {
  161. return snd_dice_transaction_read(dice, SND_DICE_ADDR_TYPE_SYNC, offset,
  162. buf, len);
  163. }
  164. int snd_dice_transaction_get_clock_source(struct snd_dice *dice,
  165. unsigned int *source);
  166. int snd_dice_transaction_get_rate(struct snd_dice *dice, unsigned int *rate);
  167. int snd_dice_transaction_set_enable(struct snd_dice *dice);
  168. void snd_dice_transaction_clear_enable(struct snd_dice *dice);
  169. int snd_dice_transaction_init(struct snd_dice *dice);
  170. int snd_dice_transaction_reinit(struct snd_dice *dice);
  171. void snd_dice_transaction_destroy(struct snd_dice *dice);
  172. #define SND_DICE_RATES_COUNT 7
  173. extern const unsigned int snd_dice_rates[SND_DICE_RATES_COUNT];
  174. int snd_dice_stream_start_duplex(struct snd_dice *dice, unsigned int rate);
  175. void snd_dice_stream_stop_duplex(struct snd_dice *dice);
  176. int snd_dice_stream_init_duplex(struct snd_dice *dice);
  177. void snd_dice_stream_destroy_duplex(struct snd_dice *dice);
  178. void snd_dice_stream_update_duplex(struct snd_dice *dice);
  179. int snd_dice_stream_lock_try(struct snd_dice *dice);
  180. void snd_dice_stream_lock_release(struct snd_dice *dice);
  181. int snd_dice_create_pcm(struct snd_dice *dice);
  182. int snd_dice_create_hwdep(struct snd_dice *dice);
  183. void snd_dice_create_proc(struct snd_dice *dice);
  184. int snd_dice_create_midi(struct snd_dice *dice);
  185. #endif