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