bebob.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 <linux/sched/signal.h>
  19. #include <sound/core.h>
  20. #include <sound/initval.h>
  21. #include <sound/info.h>
  22. #include <sound/rawmidi.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/firewire.h>
  26. #include <sound/hwdep.h>
  27. #include "../lib.h"
  28. #include "../fcp.h"
  29. #include "../packets-buffer.h"
  30. #include "../iso-resources.h"
  31. #include "../amdtp-am824.h"
  32. #include "../cmp.h"
  33. /* basic register addresses on DM1000/DM1100/DM1500 */
  34. #define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL
  35. #define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL
  36. struct snd_bebob;
  37. #define SND_BEBOB_STRM_FMT_ENTRIES 7
  38. struct snd_bebob_stream_formation {
  39. unsigned int pcm;
  40. unsigned int midi;
  41. };
  42. /* this is a lookup table for index of stream formations */
  43. extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
  44. /* device specific operations */
  45. enum snd_bebob_clock_type {
  46. SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
  47. SND_BEBOB_CLOCK_TYPE_EXTERNAL,
  48. SND_BEBOB_CLOCK_TYPE_SYT,
  49. };
  50. struct snd_bebob_clock_spec {
  51. unsigned int num;
  52. const char *const *labels;
  53. const enum snd_bebob_clock_type *types;
  54. int (*get)(struct snd_bebob *bebob, unsigned int *id);
  55. };
  56. struct snd_bebob_rate_spec {
  57. int (*get)(struct snd_bebob *bebob, unsigned int *rate);
  58. int (*set)(struct snd_bebob *bebob, unsigned int rate);
  59. };
  60. struct snd_bebob_meter_spec {
  61. unsigned int num;
  62. const char *const *labels;
  63. int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
  64. };
  65. struct snd_bebob_spec {
  66. const struct snd_bebob_clock_spec *clock;
  67. const struct snd_bebob_rate_spec *rate;
  68. const struct snd_bebob_meter_spec *meter;
  69. };
  70. struct snd_bebob {
  71. struct snd_card *card;
  72. struct fw_unit *unit;
  73. int card_index;
  74. struct mutex mutex;
  75. spinlock_t lock;
  76. bool registered;
  77. struct delayed_work dwork;
  78. const struct ieee1394_device_id *entry;
  79. const struct snd_bebob_spec *spec;
  80. unsigned int midi_input_ports;
  81. unsigned int midi_output_ports;
  82. bool connected;
  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. /* 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_destroy_duplex(struct snd_bebob *bebob);
  199. void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
  200. int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
  201. void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
  202. void snd_bebob_proc_init(struct snd_bebob *bebob);
  203. int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
  204. int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
  205. int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
  206. /* model specific operations */
  207. extern const struct snd_bebob_spec phase88_rack_spec;
  208. extern const struct snd_bebob_spec yamaha_terratec_spec;
  209. extern const struct snd_bebob_spec saffirepro_26_spec;
  210. extern const struct snd_bebob_spec saffirepro_10_spec;
  211. extern const struct snd_bebob_spec saffire_le_spec;
  212. extern const struct snd_bebob_spec saffire_spec;
  213. extern const struct snd_bebob_spec maudio_fw410_spec;
  214. extern const struct snd_bebob_spec maudio_audiophile_spec;
  215. extern const struct snd_bebob_spec maudio_solo_spec;
  216. extern const struct snd_bebob_spec maudio_ozonic_spec;
  217. extern const struct snd_bebob_spec maudio_nrv10_spec;
  218. extern const struct snd_bebob_spec maudio_special_spec;
  219. int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
  220. int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
  221. #define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
  222. { \
  223. .match_flags = IEEE1394_MATCH_VENDOR_ID | \
  224. IEEE1394_MATCH_MODEL_ID, \
  225. .vendor_id = vendor, \
  226. .model_id = model, \
  227. .driver_data = (kernel_ulong_t)data \
  228. }
  229. #endif