bebob.h 7.6 KB

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