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 | ||
fd6f4b0d TS |
51 | struct snd_bebob { |
52 | struct snd_card *card; | |
53 | struct fw_unit *unit; | |
54 | int card_index; | |
55 | ||
56 | struct mutex mutex; | |
57 | spinlock_t lock; | |
eb7b3a05 TS |
58 | |
59 | unsigned int midi_input_ports; | |
60 | unsigned int midi_output_ports; | |
61 | ||
b6bc8123 TS |
62 | /* for bus reset quirk */ |
63 | struct completion bus_reset; | |
64 | bool connected; | |
65 | ||
eb7b3a05 TS |
66 | struct amdtp_stream *master; |
67 | struct amdtp_stream tx_stream; | |
68 | struct amdtp_stream rx_stream; | |
69 | struct cmp_connection out_conn; | |
70 | struct cmp_connection in_conn; | |
71 | atomic_t capture_substreams; | |
72 | atomic_t playback_substreams; | |
73 | ||
74 | struct snd_bebob_stream_formation | |
75 | tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES]; | |
76 | struct snd_bebob_stream_formation | |
77 | rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES]; | |
78 | ||
79 | int sync_input_plug; | |
618eabea TS |
80 | |
81 | /* for uapi */ | |
82 | int dev_lock_count; | |
83 | bool dev_lock_changed; | |
84 | wait_queue_head_t hwdep_wait; | |
fd6f4b0d TS |
85 | }; |
86 | ||
87 | static inline int | |
88 | snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size) | |
89 | { | |
90 | return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST, | |
91 | BEBOB_ADDR_REG_INFO + addr, | |
92 | buf, size, 0); | |
93 | } | |
94 | ||
95 | static inline int | |
96 | snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf) | |
97 | { | |
98 | return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST, | |
99 | BEBOB_ADDR_REG_INFO + addr, | |
100 | (void *)buf, sizeof(u32), 0); | |
101 | } | |
102 | ||
eb7b3a05 TS |
103 | /* |
104 | * AVC command extensions, AV/C Unit and Subunit, Revision 17 | |
105 | * (Nov 2003, BridgeCo) | |
106 | */ | |
107 | #define AVC_BRIDGECO_ADDR_BYTES 6 | |
108 | enum avc_bridgeco_plug_dir { | |
109 | AVC_BRIDGECO_PLUG_DIR_IN = 0x00, | |
110 | AVC_BRIDGECO_PLUG_DIR_OUT = 0x01 | |
111 | }; | |
112 | enum avc_bridgeco_plug_mode { | |
113 | AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00, | |
114 | AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01, | |
115 | AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02 | |
116 | }; | |
117 | enum avc_bridgeco_plug_unit { | |
118 | AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00, | |
119 | AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01, | |
120 | AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02 | |
121 | }; | |
122 | enum avc_bridgeco_plug_type { | |
123 | AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00, | |
124 | AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01, | |
125 | AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02, | |
126 | AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03, | |
127 | AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04, | |
128 | AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05 | |
129 | }; | |
130 | static inline void | |
131 | avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
132 | enum avc_bridgeco_plug_dir dir, | |
133 | enum avc_bridgeco_plug_unit unit, | |
134 | unsigned int pid) | |
135 | { | |
136 | buf[0] = 0xff; /* Unit */ | |
137 | buf[1] = dir; | |
138 | buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT; | |
139 | buf[3] = unit; | |
140 | buf[4] = 0xff & pid; | |
141 | buf[5] = 0xff; /* reserved */ | |
142 | } | |
143 | static inline void | |
144 | avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], | |
145 | enum avc_bridgeco_plug_dir dir, | |
146 | unsigned int pid) | |
147 | { | |
148 | buf[0] = 0x60; /* Music subunit */ | |
149 | buf[1] = dir; | |
150 | buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT; | |
151 | buf[3] = 0xff & pid; | |
152 | buf[4] = 0xff; /* reserved */ | |
153 | buf[5] = 0xff; /* reserved */ | |
154 | } | |
155 | int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, | |
156 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
157 | u8 *buf, unsigned int len); | |
158 | int avc_bridgeco_get_plug_type(struct fw_unit *unit, | |
159 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
160 | enum avc_bridgeco_plug_type *type); | |
161 | int avc_bridgeco_get_plug_section_type(struct fw_unit *unit, | |
162 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
163 | unsigned int id, u8 *type); | |
164 | int avc_bridgeco_get_plug_input(struct fw_unit *unit, | |
165 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], | |
166 | u8 input[7]); | |
167 | int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit, | |
168 | u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf, | |
169 | unsigned int *len, unsigned int eid); | |
170 | ||
171 | /* for AMDTP streaming */ | |
172 | int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate); | |
173 | int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate); | |
174 | int snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, | |
175 | bool *internal); | |
176 | int snd_bebob_stream_discover(struct snd_bebob *bebob); | |
177 | int snd_bebob_stream_map(struct snd_bebob *bebob, | |
178 | struct amdtp_stream *stream); | |
179 | int snd_bebob_stream_init_duplex(struct snd_bebob *bebob); | |
180 | int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, int rate); | |
181 | void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob); | |
182 | void snd_bebob_stream_update_duplex(struct snd_bebob *bebob); | |
183 | void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob); | |
184 | ||
618eabea TS |
185 | void snd_bebob_stream_lock_changed(struct snd_bebob *bebob); |
186 | int snd_bebob_stream_lock_try(struct snd_bebob *bebob); | |
187 | void snd_bebob_stream_lock_release(struct snd_bebob *bebob); | |
188 | ||
ad9697ba TS |
189 | void snd_bebob_proc_init(struct snd_bebob *bebob); |
190 | ||
248b7802 TS |
191 | int snd_bebob_create_midi_devices(struct snd_bebob *bebob); |
192 | ||
fbbebd2c TS |
193 | int snd_bebob_create_pcm_devices(struct snd_bebob *bebob); |
194 | ||
618eabea TS |
195 | int snd_bebob_create_hwdep_device(struct snd_bebob *bebob); |
196 | ||
fd6f4b0d TS |
197 | #define SND_BEBOB_DEV_ENTRY(vendor, model) \ |
198 | { \ | |
199 | .match_flags = IEEE1394_MATCH_VENDOR_ID | \ | |
200 | IEEE1394_MATCH_MODEL_ID, \ | |
201 | .vendor_id = vendor, \ | |
202 | .model_id = model, \ | |
203 | } | |
204 | ||
205 | #endif |