dice.h 5.5 KB

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