bebob.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * bebob.h - a part of driver for BeBoB based devices
  3. *
  4. * Copyright (c) 2013-2014 Takashi Sakamoto
  5. *
  6. * Licensed under the terms of the GNU General Public License, version 2.
  7. */
  8. #ifndef SOUND_BEBOB_H_INCLUDED
  9. #define SOUND_BEBOB_H_INCLUDED
  10. #include <linux/compat.h>
  11. #include <linux/device.h>
  12. #include <linux/firewire.h>
  13. #include <linux/firewire-constants.h>
  14. #include <linux/module.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.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.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. 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. struct snd_bebob_clock_spec *clock;
  66. struct snd_bebob_rate_spec *rate;
  67. struct snd_bebob_meter_spec *meter;
  68. };
  69. struct snd_bebob {
  70. struct snd_card *card;
  71. struct fw_unit *unit;
  72. int card_index;
  73. struct mutex mutex;
  74. spinlock_t lock;
  75. const struct snd_bebob_spec *spec;
  76. unsigned int midi_input_ports;
  77. unsigned int midi_output_ports;
  78. /* for bus reset quirk */
  79. struct completion bus_reset;
  80. bool connected;
  81. struct amdtp_stream *master;
  82. struct amdtp_stream tx_stream;
  83. struct amdtp_stream rx_stream;
  84. struct cmp_connection out_conn;
  85. struct cmp_connection in_conn;
  86. atomic_t substreams_counter;
  87. struct snd_bebob_stream_formation
  88. tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
  89. struct snd_bebob_stream_formation
  90. rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
  91. int sync_input_plug;
  92. /* for uapi */
  93. int dev_lock_count;
  94. bool dev_lock_changed;
  95. wait_queue_head_t hwdep_wait;
  96. /* for M-Audio special devices */
  97. void *maudio_special_quirk;
  98. bool deferred_registration;
  99. /* For BeBoB version quirk. */
  100. unsigned int version;
  101. };
  102. static inline int
  103. snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)
  104. {
  105. return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,
  106. BEBOB_ADDR_REG_INFO + addr,
  107. buf, size, 0);
  108. }
  109. static inline int
  110. snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)
  111. {
  112. return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
  113. BEBOB_ADDR_REG_INFO + addr,
  114. (void *)buf, sizeof(u32), 0);
  115. }
  116. /* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */
  117. int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
  118. unsigned int fb_id, unsigned int num);
  119. int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
  120. unsigned int fb_id, unsigned int *num);
  121. /*
  122. * AVC command extensions, AV/C Unit and Subunit, Revision 17
  123. * (Nov 2003, BridgeCo)
  124. */
  125. #define AVC_BRIDGECO_ADDR_BYTES 6
  126. enum avc_bridgeco_plug_dir {
  127. AVC_BRIDGECO_PLUG_DIR_IN = 0x00,
  128. AVC_BRIDGECO_PLUG_DIR_OUT = 0x01
  129. };
  130. enum avc_bridgeco_plug_mode {
  131. AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00,
  132. AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01,
  133. AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02
  134. };
  135. enum avc_bridgeco_plug_unit {
  136. AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,
  137. AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01,
  138. AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02
  139. };
  140. enum avc_bridgeco_plug_type {
  141. AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,
  142. AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01,
  143. AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,
  144. AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,
  145. AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04,
  146. AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05,
  147. AVC_BRIDGECO_PLUG_TYPE_ADDITION = 0x06
  148. };
  149. static inline void
  150. avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
  151. enum avc_bridgeco_plug_dir dir,
  152. enum avc_bridgeco_plug_unit unit,
  153. unsigned int pid)
  154. {
  155. buf[0] = 0xff; /* Unit */
  156. buf[1] = dir;
  157. buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;
  158. buf[3] = unit;
  159. buf[4] = 0xff & pid;
  160. buf[5] = 0xff; /* reserved */
  161. }
  162. static inline void
  163. avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
  164. enum avc_bridgeco_plug_dir dir,
  165. unsigned int pid)
  166. {
  167. buf[0] = 0x60; /* Music subunit */
  168. buf[1] = dir;
  169. buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
  170. buf[3] = 0xff & pid;
  171. buf[4] = 0xff; /* reserved */
  172. buf[5] = 0xff; /* reserved */
  173. }
  174. int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
  175. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  176. u8 *buf, unsigned int len);
  177. int avc_bridgeco_get_plug_type(struct fw_unit *unit,
  178. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  179. enum avc_bridgeco_plug_type *type);
  180. int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
  181. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  182. unsigned int id, u8 *type);
  183. int avc_bridgeco_get_plug_input(struct fw_unit *unit,
  184. u8 addr[AVC_BRIDGECO_ADDR_BYTES],
  185. u8 input[7]);
  186. int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
  187. u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
  188. unsigned int *len, unsigned int eid);
  189. /* for AMDTP streaming */
  190. int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
  191. int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
  192. int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
  193. enum snd_bebob_clock_type *src);
  194. int snd_bebob_stream_discover(struct snd_bebob *bebob);
  195. int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
  196. int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate);
  197. void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
  198. void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);
  199. void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
  200. void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
  201. int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
  202. void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
  203. void snd_bebob_proc_init(struct snd_bebob *bebob);
  204. int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
  205. int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
  206. int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
  207. /* model specific operations */
  208. extern struct snd_bebob_spec phase88_rack_spec;
  209. extern struct snd_bebob_spec phase24_series_spec;
  210. extern struct snd_bebob_spec yamaha_go_spec;
  211. extern struct snd_bebob_spec saffirepro_26_spec;
  212. extern struct snd_bebob_spec saffirepro_10_spec;
  213. extern struct snd_bebob_spec saffire_le_spec;
  214. extern struct snd_bebob_spec saffire_spec;
  215. extern struct snd_bebob_spec maudio_fw410_spec;
  216. extern struct snd_bebob_spec maudio_audiophile_spec;
  217. extern struct snd_bebob_spec maudio_solo_spec;
  218. extern struct snd_bebob_spec maudio_ozonic_spec;
  219. extern struct snd_bebob_spec maudio_nrv10_spec;
  220. extern struct snd_bebob_spec maudio_special_spec;
  221. int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
  222. int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
  223. #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
  224. { \
  225. .match_flags = IEEE1394_MATCH_VENDOR_ID | \
  226. IEEE1394_MATCH_MODEL_ID, \
  227. .vendor_id = vendor, \
  228. .model_id = model, \
  229. .driver_data = (kernel_ulong_t)data \
  230. }
  231. #endif