bebob.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * bebob.h - a part of driver for BeBoB based devices
  4. *
  5. * Copyright (c) 2013-2014 Takashi Sakamoto
  6. */
  7. #ifndef SOUND_BEBOB_H_INCLUDED
  8. #define SOUND_BEBOB_H_INCLUDED
  9. #include <linux/compat.h>
  10. #include <linux/device.h>
  11. #include <linux/firewire.h>
  12. #include <linux/firewire-constants.h>
  13. #include <linux/module.h>
  14. #include <linux/mod_devicetable.h>
  15. #include <linux/delay.h>
  16. #include <linux/slab.h>
  17. #include <linux/sched/signal.h>
  18. #include <sound/core.h>
  19. #include <sound/initval.h>
  20. #include <sound/info.h>
  21. #include <sound/rawmidi.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/firewire.h>
  25. #include <sound/hwdep.h>
  26. #include "../lib.h"
  27. #include "../fcp.h"
  28. #include "../packets-buffer.h"
  29. #include "../iso-resources.h"
  30. #include "../amdtp-am824.h"
  31. #include "../cmp.h"
  32. /* basic register addresses on DM1000/DM1100/DM1500 */
  33. #define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL
  34. #define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL
  35. struct snd_bebob;
  36. #define SND_BEBOB_STRM_FMT_ENTRIES 7
  37. struct snd_bebob_stream_formation {
  38. unsigned int pcm;
  39. unsigned int midi;
  40. };
  41. /* this is a lookup table for index of stream formations */
  42. extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
  43. /* device specific operations */
  44. enum snd_bebob_clock_type {
  45. SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
  46. SND_BEBOB_CLOCK_TYPE_EXTERNAL,
  47. SND_BEBOB_CLOCK_TYPE_SYT,
  48. };
  49. struct snd_bebob_clock_spec {
  50. unsigned int num;
  51. const char *const *labels;
  52. const enum snd_bebob_clock_type *types;
  53. int (*get)(struct snd_bebob *bebob, unsigned int *id);
  54. };
  55. struct snd_bebob_rate_spec {
  56. int (*get)(struct snd_bebob *bebob, unsigned int *rate);
  57. int (*set)(struct snd_bebob *bebob, unsigned int rate);
  58. };
  59. struct snd_bebob_meter_spec {
  60. unsigned int num;
  61. const char *const *labels;
  62. int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
  63. };
  64. struct snd_bebob_spec {
  65. const struct snd_bebob_clock_spec *clock;
  66. const struct snd_bebob_rate_spec *rate;
  67. const struct snd_bebob_meter_spec *meter;
  68. };
  69. enum snd_bebob_quirk {
  70. SND_BEBOB_QUIRK_INITIAL_DISCONTINUOUS_DBC = (1 << 0),
  71. SND_BEBOB_QUIRK_WRONG_DBC = (1 << 1),
  72. };
  73. struct snd_bebob {
  74. struct snd_card *card;
  75. struct fw_unit *unit;
  76. int card_index;
  77. struct mutex mutex;
  78. spinlock_t lock;
  79. const struct snd_bebob_spec *spec;
  80. unsigned int quirks; // Combination of snd_bebob_quirk enumerations.
  81. unsigned int midi_input_ports;
  82. unsigned int midi_output_ports;
  83. struct amdtp_stream tx_stream;
  84. struct amdtp_stream rx_stream;
  85. struct cmp_connection out_conn;
  86. struct cmp_connection in_conn;
  87. unsigned int substreams_counter;
  88. struct snd_bebob_stream_formation
  89. tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
  90. struct snd_bebob_stream_formation
  91. rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
  92. int sync_input_plug;
  93. /* for uapi */
  94. int dev_lock_count;
  95. bool dev_lock_changed;
  96. wait_queue_head_t hwdep_wait;
  97. /* for M-Audio special devices */
  98. void *maudio_special_quirk;
  99. struct amdtp_domain domain;
  100. };
  101. static inline int
  102. snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
  103. {
  104. return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
  105. BEBOB_ADDR_REG_INFO + addr,
  106. buf, size, 0);
  107. }
  108. static inline int
  109. snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
  110. {
  111. return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
  112. BEBOB_ADDR_REG_INFO + addr,
  113. (void *)buf, sizeof(u32), 0);
  114. }
  115. /* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
  116. int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
  117. unsigned int fb_id, unsigned int num);
  118. int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
  119. unsigned int fb_id, unsigned int *num);
  120. /*
  121. * AVC command extensions, AV/C Unit and Subunit, Revision 17
  122. * (Nov 2003, BridgeCo)
  123. */
  124. #define AVC_BRIDGECO_ADDR_BYTES 6
  125. enum avc_bridgeco_plug_dir {
  126. AVC_BRIDGECO_PLUG_DIR_IN = 0x00,
  127. AVC_BRIDGECO_PLUG_DIR_OUT = 0x01
  128. };
  129. enum avc_bridgeco_plug_mode {
  130. AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00,
  131. AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01,
  132. AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02
  133. };
  134. enum avc_bridgeco_plug_unit {
  135. AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,
  136. AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01,
  137. AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02
  138. };
  139. enum avc_bridgeco_plug_type {
  140. AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,
  141. AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01,
  142. AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,
  143. AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,
  144. AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04,
  145. AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05,
  146. AVC_BRIDGECO_PLUG_TYPE_ADDITION = 0x06
  147. };
  148. static inline void
  149. avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
  150. enum avc_bridgeco_plug_dir dir,
  151. enum avc_bridgeco_plug_unit unit,
  152. unsigned int pid)
  153. {
  154. buf[0] = 0xff; /* Unit */
  155. buf[1] = dir;
  156. buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
  157. buf[3] = unit;
  158. buf[4] = 0xff & pid;
  159. buf[5] = 0xff; /* reserved */
  160. }
  161. static inline void
  162. avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
  163. enum avc_bridgeco_plug_dir dir,
  164. unsigned int pid)
  165. {
  166. buf[0] = 0x60; /* Music subunit */
  167. buf[1] = dir;
  168. buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
  169. buf[3] = 0xff & pid;
  170. buf[4] = 0xff; /* reserved */
  171. buf[5] = 0xff; /* reserved */
  172. }
  173. int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
  174. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  175. u8 *buf, unsigned int len);
  176. int avc_bridgeco_get_plug_type(struct fw_unit *unit,
  177. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  178. enum avc_bridgeco_plug_type *type);
  179. int avc_bridgeco_get_plug_ch_count(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  180. unsigned int *ch_count);
  181. int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
  182. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  183. unsigned int id, u8 *type);
  184. int avc_bridgeco_get_plug_input(struct fw_unit *unit,
  185. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  186. u8 input[7]);
  187. int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
  188. u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
  189. unsigned int *len, unsigned int eid);
  190. /* for AMDTP streaming */
  191. int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
  192. int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
  193. int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
  194. enum snd_bebob_clock_type *src);
  195. int snd_bebob_stream_discover(struct snd_bebob *bebob);
  196. int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
  197. int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate,
  198. unsigned int frames_per_period,
  199. unsigned int frames_per_buffer);
  200. int snd_bebob_stream_start_duplex(struct snd_bebob *bebob);
  201. void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
  202. void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
  203. void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
  204. int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
  205. void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
  206. void snd_bebob_proc_init(struct snd_bebob *bebob);
  207. int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
  208. int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
  209. int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
  210. /* model specific operations */
  211. extern const struct snd_bebob_spec phase88_rack_spec;
  212. extern const struct snd_bebob_spec yamaha_terratec_spec;
  213. extern const struct snd_bebob_spec saffirepro_26_spec;
  214. extern const struct snd_bebob_spec saffirepro_10_spec;
  215. extern const struct snd_bebob_spec saffire_le_spec;
  216. extern const struct snd_bebob_spec saffire_spec;
  217. extern const struct snd_bebob_spec maudio_fw410_spec;
  218. extern const struct snd_bebob_spec maudio_audiophile_spec;
  219. extern const struct snd_bebob_spec maudio_solo_spec;
  220. extern const struct snd_bebob_spec maudio_ozonic_spec;
  221. extern const struct snd_bebob_spec maudio_nrv10_spec;
  222. extern const struct snd_bebob_spec maudio_special_spec;
  223. int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
  224. int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
  225. #endif