Commit | Line | Data |
---|---|---|
da607e19 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
fd6f4b0d TS |
2 | /* |
3 | * bebob.h - a part of driver for BeBoB based devices | |
4 | * | |
5 | * Copyright (c) 2013-2014 Takashi Sakamoto | |
fd6f4b0d TS |
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/mod_devicetable.h> | |
17 | #include <linux/delay.h> | |
18 | #include <linux/slab.h> | |
174cd4b1 | 19 | #include <linux/sched/signal.h> |
fd6f4b0d TS |
20 | |
21 | #include <sound/core.h> | |
22 | #include <sound/initval.h> | |
ad9697ba | 23 | #include <sound/info.h> |
248b7802 | 24 | #include <sound/rawmidi.h> |
fbbebd2c TS |
25 | #include <sound/pcm.h> |
26 | #include <sound/pcm_params.h> | |
618eabea TS |
27 | #include <sound/firewire.h> |
28 | #include <sound/hwdep.h> | |
fd6f4b0d TS |
29 | |
30 | #include "../lib.h" | |
31 | #include "../fcp.h" | |
eb7b3a05 TS |
32 | #include "../packets-buffer.h" |
33 | #include "../iso-resources.h" | |
5955815e | 34 | #include "../amdtp-am824.h" |
eb7b3a05 | 35 | #include "../cmp.h" |
fd6f4b0d TS |
36 | |
37 | /* basic register addresses on DM1000/DM1100/DM1500 */ | |
9b5f0edf TS |
38 | #define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL |
39 | #define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL | |
fd6f4b0d | 40 | |
eb7b3a05 TS |
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 | ||
1fc9522a | 51 | /* device specific operations */ |
13a4f420 TS |
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 | }; | |
1fc9522a TS |
57 | struct snd_bebob_clock_spec { |
58 | unsigned int num; | |
e7ced413 | 59 | const char *const *labels; |
782fbec7 | 60 | const enum snd_bebob_clock_type *types; |
1fc9522a TS |
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; | |
e7ced413 | 69 | const char *const *labels; |
1fc9522a TS |
70 | int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size); |
71 | }; | |
72 | struct snd_bebob_spec { | |
6b9866c8 JL |
73 | const struct snd_bebob_clock_spec *clock; |
74 | const struct snd_bebob_rate_spec *rate; | |
75 | const struct snd_bebob_meter_spec *meter; | |
1fc9522a TS |
76 | }; |
77 | ||
93cd12d6 | 78 | enum snd_bebob_quirk { |
36d1a672 CIK |
79 | SND_BEBOB_QUIRK_INITIAL_DISCONTINUOUS_DBC = (1 << 0), |
80 | SND_BEBOB_QUIRK_WRONG_DBC = (1 << 1), | |
93cd12d6 TS |
81 | }; |
82 | ||
fd6f4b0d TS |
83 | struct snd_bebob { |
84 | struct snd_card *card; | |
85 | struct fw_unit *unit; | |
86 | int card_index; | |
87 | ||
88 | struct mutex mutex; | |
89 | spinlock_t lock; | |
eb7b3a05 | 90 | |
1fc9522a | 91 | const struct snd_bebob_spec *spec; |
93cd12d6 | 92 | unsigned int quirks; // Combination of snd_bebob_quirk enumerations. |
1fc9522a | 93 | |
eb7b3a05 TS |
94 | unsigned int midi_input_ports; |
95 | unsigned int midi_output_ports; | |
96 | ||
eb7b3a05 TS |
97 | struct amdtp_stream tx_stream; |
98 | struct amdtp_stream rx_stream; | |
99 | struct cmp_connection out_conn; | |
100 | struct cmp_connection in_conn; | |
4fd6c6c7 | 101 | unsigned int substreams_counter; |
eb7b3a05 TS |
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; | |
618eabea TS |
109 | |
110 | /* for uapi */ | |
111 | int dev_lock_count; | |
112 | bool dev_lock_changed; | |
113 | wait_queue_head_t hwdep_wait; | |
3149ac48 TS |
114 | |
115 | /* for M-Audio special devices */ | |
116 | void *maudio_special_quirk; | |
7b4d7dcf | 117 | |
b0db4d51 | 118 | struct amdtp_domain domain; |
fd6f4b0d TS |
119 | }; |
120 | ||
121 | static inline int | |
122 | snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size) | |
123 | { | |
124 | return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, | |
125 | BEBOB_ADDR_REG_INFO + addr, | |
126 | buf, size, 0); | |
127 | } | |
128 | ||
129 | static inline int | |
130 | snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf) | |
131 | { | |
132 | return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, | |
133 | BEBOB_ADDR_REG_INFO + addr, | |
134 | (void *)buf, sizeof(u32), 0); | |
135 | } | |
136 | ||
1fc9522a TS |
137 | /* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */ |
138 | int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id, | |
139 | unsigned int fb_id, unsigned int num); | |
140 | int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id, | |
141 | unsigned int fb_id, unsigned int *num); | |
142 | ||
eb7b3a05 TS |
143 | /* |
144 | * AVC command extensions, AV/C Unit and Subunit, Revision 17 | |
145 | * (Nov 2003, BridgeCo) | |
146 | */ | |
147 | #define AVC_BRIDGECO_ADDR_BYTES 6 | |
148 | enum avc_bridgeco_plug_dir { | |
149 | AVC_BRIDGECO_PLUG_DIR_IN = 0x00, | |
150 | AVC_BRIDGECO_PLUG_DIR_OUT = 0x01 | |
151 | }; | |
152 | enum avc_bridgeco_plug_mode { | |
153 | AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00, | |
154 | AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01, | |
155 | AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02 | |
156 | }; | |
157 | enum avc_bridgeco_plug_unit { | |
158 | AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00, | |
159 | AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01, | |
160 | AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02 | |
161 | }; | |
162 | enum avc_bridgeco_plug_type { | |
163 | AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00, | |
164 | AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01, | |
165 | AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02, | |
166 | AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03, | |
167 | AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04, | |
5a668812 TS |
168 | AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05, |
169 | AVC_BRIDGECO_PLUG_TYPE_ADDITION = 0x06 | |
eb7b3a05 TS |
170 | }; |
171 | static inline void | |
172 | avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
173 | enum avc_bridgeco_plug_dir dir, | |
174 | enum avc_bridgeco_plug_unit unit, | |
175 | unsigned int pid) | |
176 | { | |
177 | buf[0] = 0xff; /* Unit */ | |
178 | buf[1] = dir; | |
179 | buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT; | |
180 | buf[3] = unit; | |
181 | buf[4] = 0xff & pid; | |
182 | buf[5] = 0xff; /* reserved */ | |
183 | } | |
184 | static inline void | |
185 | avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
186 | enum avc_bridgeco_plug_dir dir, | |
187 | unsigned int pid) | |
188 | { | |
189 | buf[0] = 0x60; /* Music subunit */ | |
190 | buf[1] = dir; | |
191 | buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT; | |
192 | buf[3] = 0xff & pid; | |
193 | buf[4] = 0xff; /* reserved */ | |
194 | buf[5] = 0xff; /* reserved */ | |
195 | } | |
196 | int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, | |
197 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
198 | u8 *buf, unsigned int len); | |
199 | int avc_bridgeco_get_plug_type(struct fw_unit *unit, | |
200 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
201 | enum avc_bridgeco_plug_type *type); | |
5c6ea94f TS |
202 | int avc_bridgeco_get_plug_ch_count(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES], |
203 | unsigned int *ch_count); | |
eb7b3a05 TS |
204 | int avc_bridgeco_get_plug_section_type(struct fw_unit *unit, |
205 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
206 | unsigned int id, u8 *type); | |
207 | int avc_bridgeco_get_plug_input(struct fw_unit *unit, | |
208 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
209 | u8 input[7]); | |
210 | int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit, | |
211 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf, | |
212 | unsigned int *len, unsigned int eid); | |
213 | ||
214 | /* for AMDTP streaming */ | |
215 | int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate); | |
216 | int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate); | |
3e254b16 TS |
217 | int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob, |
218 | enum snd_bebob_clock_type *src); | |
eb7b3a05 | 219 | int snd_bebob_stream_discover(struct snd_bebob *bebob); |
eb7b3a05 | 220 | int snd_bebob_stream_init_duplex(struct snd_bebob *bebob); |
8737209f | 221 | int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate, |
1fde7a44 TS |
222 | unsigned int frames_per_period, |
223 | unsigned int frames_per_buffer); | |
ac2888b9 | 224 | int snd_bebob_stream_start_duplex(struct snd_bebob *bebob); |
eb7b3a05 | 225 | void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob); |
eb7b3a05 TS |
226 | void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob); |
227 | ||
618eabea TS |
228 | void snd_bebob_stream_lock_changed(struct snd_bebob *bebob); |
229 | int snd_bebob_stream_lock_try(struct snd_bebob *bebob); | |
230 | void snd_bebob_stream_lock_release(struct snd_bebob *bebob); | |
231 | ||
ad9697ba TS |
232 | void snd_bebob_proc_init(struct snd_bebob *bebob); |
233 | ||
248b7802 TS |
234 | int snd_bebob_create_midi_devices(struct snd_bebob *bebob); |
235 | ||
fbbebd2c TS |
236 | int snd_bebob_create_pcm_devices(struct snd_bebob *bebob); |
237 | ||
618eabea TS |
238 | int snd_bebob_create_hwdep_device(struct snd_bebob *bebob); |
239 | ||
326b9cac | 240 | /* model specific operations */ |
6b9866c8 | 241 | extern const struct snd_bebob_spec phase88_rack_spec; |
e15c282e | 242 | extern const struct snd_bebob_spec yamaha_terratec_spec; |
6b9866c8 JL |
243 | extern const struct snd_bebob_spec saffirepro_26_spec; |
244 | extern const struct snd_bebob_spec saffirepro_10_spec; | |
245 | extern const struct snd_bebob_spec saffire_le_spec; | |
246 | extern const struct snd_bebob_spec saffire_spec; | |
247 | extern const struct snd_bebob_spec maudio_fw410_spec; | |
248 | extern const struct snd_bebob_spec maudio_audiophile_spec; | |
249 | extern const struct snd_bebob_spec maudio_solo_spec; | |
250 | extern const struct snd_bebob_spec maudio_ozonic_spec; | |
251 | extern const struct snd_bebob_spec maudio_nrv10_spec; | |
252 | extern const struct snd_bebob_spec maudio_special_spec; | |
3149ac48 | 253 | int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814); |
a2b2a779 | 254 | int snd_bebob_maudio_load_firmware(struct fw_unit *unit); |
326b9cac | 255 | |
fd6f4b0d | 256 | #endif |