dice.h 6.1 KB

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