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