1
2
3
4
5
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>
19#include <linux/sched/signal.h>
20
21#include <sound/core.h>
22#include <sound/initval.h>
23#include <sound/info.h>
24#include <sound/rawmidi.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/firewire.h>
28#include <sound/hwdep.h>
29
30#include "../lib.h"
31#include "../fcp.h"
32#include "../packets-buffer.h"
33#include "../iso-resources.h"
34#include "../amdtp-am824.h"
35#include "../cmp.h"
36
37
38#define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL
39#define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL
40
41struct snd_bebob;
42
43#define SND_BEBOB_STRM_FMT_ENTRIES 7
44struct snd_bebob_stream_formation {
45 unsigned int pcm;
46 unsigned int midi;
47};
48
49extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];
50
51
52enum snd_bebob_clock_type {
53 SND_BEBOB_CLOCK_TYPE_INTERNAL = 0,
54 SND_BEBOB_CLOCK_TYPE_EXTERNAL,
55 SND_BEBOB_CLOCK_TYPE_SYT,
56};
57struct snd_bebob_clock_spec {
58 unsigned int num;
59 const char *const *labels;
60 const enum snd_bebob_clock_type *types;
61 int (*get)(struct snd_bebob *bebob, unsigned int *id);
62};
63struct 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};
67struct snd_bebob_meter_spec {
68 unsigned int num;
69 const char *const *labels;
70 int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);
71};
72struct snd_bebob_spec {
73 const struct snd_bebob_clock_spec *clock;
74 const struct snd_bebob_rate_spec *rate;
75 const struct snd_bebob_meter_spec *meter;
76};
77
78struct 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;
85
86 bool registered;
87 struct delayed_work dwork;
88
89 const struct ieee1394_device_id *entry;
90 const struct snd_bebob_spec *spec;
91
92 unsigned int midi_input_ports;
93 unsigned int midi_output_ports;
94
95 struct amdtp_stream tx_stream;
96 struct amdtp_stream rx_stream;
97 struct cmp_connection out_conn;
98 struct cmp_connection in_conn;
99 unsigned int substreams_counter;
100
101 struct snd_bebob_stream_formation
102 tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
103 struct snd_bebob_stream_formation
104 rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];
105
106 int sync_input_plug;
107
108
109 int dev_lock_count;
110 bool dev_lock_changed;
111 wait_queue_head_t hwdep_wait;
112
113
114 void *maudio_special_quirk;
115
116
117 unsigned int version;
118};
119
120static inline int
121snd_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
128static inline int
129snd_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
137int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,
138 unsigned int fb_id, unsigned int num);
139int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,
140 unsigned int fb_id, unsigned int *num);
141
142
143
144
145
146#define AVC_BRIDGECO_ADDR_BYTES 6
147enum avc_bridgeco_plug_dir {
148 AVC_BRIDGECO_PLUG_DIR_IN = 0x00,
149 AVC_BRIDGECO_PLUG_DIR_OUT = 0x01
150};
151enum 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};
156enum 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};
161enum 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};
170static inline void
171avc_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;
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;
182}
183static inline void
184avc_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;
189 buf[1] = dir;
190 buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;
191 buf[3] = 0xff & pid;
192 buf[4] = 0xff;
193 buf[5] = 0xff;
194}
195int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
196 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
197 u8 *buf, unsigned int len);
198int avc_bridgeco_get_plug_type(struct fw_unit *unit,
199 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
200 enum avc_bridgeco_plug_type *type);
201int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,
202 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
203 unsigned int id, u8 *type);
204int avc_bridgeco_get_plug_input(struct fw_unit *unit,
205 u8 addr[AVC_BRIDGECO_ADDR_BYTES],
206 u8 input[7]);
207int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,
208 u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,
209 unsigned int *len, unsigned int eid);
210
211
212int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);
213int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);
214int snd_bebob_stream_get_clock_src(struct snd_bebob *bebob,
215 enum snd_bebob_clock_type *src);
216int snd_bebob_stream_discover(struct snd_bebob *bebob);
217int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);
218int snd_bebob_stream_reserve_duplex(struct snd_bebob *bebob, unsigned int rate);
219int snd_bebob_stream_start_duplex(struct snd_bebob *bebob);
220void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);
221void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);
222
223void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);
224int snd_bebob_stream_lock_try(struct snd_bebob *bebob);
225void snd_bebob_stream_lock_release(struct snd_bebob *bebob);
226
227void snd_bebob_proc_init(struct snd_bebob *bebob);
228
229int snd_bebob_create_midi_devices(struct snd_bebob *bebob);
230
231int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);
232
233int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);
234
235
236extern const struct snd_bebob_spec phase88_rack_spec;
237extern const struct snd_bebob_spec yamaha_terratec_spec;
238extern const struct snd_bebob_spec saffirepro_26_spec;
239extern const struct snd_bebob_spec saffirepro_10_spec;
240extern const struct snd_bebob_spec saffire_le_spec;
241extern const struct snd_bebob_spec saffire_spec;
242extern const struct snd_bebob_spec maudio_fw410_spec;
243extern const struct snd_bebob_spec maudio_audiophile_spec;
244extern const struct snd_bebob_spec maudio_solo_spec;
245extern const struct snd_bebob_spec maudio_ozonic_spec;
246extern const struct snd_bebob_spec maudio_nrv10_spec;
247extern const struct snd_bebob_spec maudio_special_spec;
248int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);
249int snd_bebob_maudio_load_firmware(struct fw_unit *unit);
250
251#define SND_BEBOB_DEV_ENTRY(vendor, model, data) \
252{ \
253 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
254 IEEE1394_MATCH_MODEL_ID, \
255 .vendor_id = vendor, \
256 .model_id = model, \
257 .driver_data = (kernel_ulong_t)data \
258}
259
260#endif
261