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