Commit | Line | Data |
---|---|---|
b5b04336 TS |
1 | /* |
2 | * fireworks.h - a part of driver for Fireworks based devices | |
3 | * | |
4 | * Copyright (c) 2009-2010 Clemens Ladisch | |
5 | * Copyright (c) 2013-2014 Takashi Sakamoto | |
6 | * | |
7 | * Licensed under the terms of the GNU General Public License, version 2. | |
8 | */ | |
9 | #ifndef SOUND_FIREWORKS_H_INCLUDED | |
10 | #define SOUND_FIREWORKS_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> | |
174cd4b1 | 20 | #include <linux/sched/signal.h> |
b5b04336 TS |
21 | |
22 | #include <sound/core.h> | |
23 | #include <sound/initval.h> | |
bde8a8f2 | 24 | #include <sound/pcm.h> |
6a22683e | 25 | #include <sound/info.h> |
a63d3ff1 | 26 | #include <sound/rawmidi.h> |
aa02bb6e | 27 | #include <sound/pcm_params.h> |
594ddced TS |
28 | #include <sound/firewire.h> |
29 | #include <sound/hwdep.h> | |
bde8a8f2 | 30 | |
315fd41f TS |
31 | #include "../packets-buffer.h" |
32 | #include "../iso-resources.h" | |
5955815e | 33 | #include "../amdtp-am824.h" |
bde8a8f2 TS |
34 | #include "../cmp.h" |
35 | #include "../lib.h" | |
36 | ||
315fd41f TS |
37 | #define SND_EFW_MAX_MIDI_OUT_PORTS 2 |
38 | #define SND_EFW_MAX_MIDI_IN_PORTS 2 | |
39 | ||
bde8a8f2 TS |
40 | #define SND_EFW_MULTIPLIER_MODES 3 |
41 | #define HWINFO_NAME_SIZE_BYTES 32 | |
42 | #define HWINFO_MAX_CAPS_GROUPS 8 | |
43 | ||
44 | /* | |
45 | * This should be greater than maximum bytes for EFW response content. | |
46 | * Currently response against command for isochronous channel mapping is | |
47 | * confirmed to be the maximum one. But for flexibility, use maximum data | |
48 | * payload for asynchronous primary packets at S100 (Cable base rate) in | |
49 | * IEEE Std 1394-1995. | |
50 | */ | |
51 | #define SND_EFW_RESPONSE_MAXIMUM_BYTES 0x200U | |
52 | ||
555e8a8f TS |
53 | extern unsigned int snd_efw_resp_buf_size; |
54 | extern bool snd_efw_resp_buf_debug; | |
55 | ||
bde8a8f2 TS |
56 | struct snd_efw_phys_grp { |
57 | u8 type; /* see enum snd_efw_grp_type */ | |
58 | u8 count; | |
59 | } __packed; | |
b5b04336 TS |
60 | |
61 | struct snd_efw { | |
62 | struct snd_card *card; | |
63 | struct fw_unit *unit; | |
64 | int card_index; | |
65 | ||
66 | struct mutex mutex; | |
67 | spinlock_t lock; | |
bde8a8f2 | 68 | |
7d3c1d59 TS |
69 | bool registered; |
70 | struct delayed_work dwork; | |
71 | ||
bde8a8f2 TS |
72 | /* for transaction */ |
73 | u32 seqnum; | |
74 | bool resp_addr_changable; | |
315fd41f | 75 | |
69702239 TS |
76 | /* for quirks */ |
77 | bool is_af9; | |
18f5ed36 | 78 | bool is_fireworks3; |
d9cd0065 | 79 | u32 firmware_version; |
69702239 | 80 | |
315fd41f TS |
81 | unsigned int midi_in_ports; |
82 | unsigned int midi_out_ports; | |
83 | ||
84 | unsigned int supported_sampling_rate; | |
85 | unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES]; | |
86 | unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES]; | |
87 | ||
315fd41f TS |
88 | struct amdtp_stream tx_stream; |
89 | struct amdtp_stream rx_stream; | |
90 | struct cmp_connection out_conn; | |
91 | struct cmp_connection in_conn; | |
4d2c50a0 TS |
92 | unsigned int capture_substreams; |
93 | unsigned int playback_substreams; | |
6a22683e TS |
94 | |
95 | /* hardware metering parameters */ | |
96 | unsigned int phys_out; | |
97 | unsigned int phys_in; | |
98 | unsigned int phys_out_grp_count; | |
99 | unsigned int phys_in_grp_count; | |
100 | struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS]; | |
101 | struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS]; | |
594ddced TS |
102 | |
103 | /* for uapi */ | |
104 | int dev_lock_count; | |
105 | bool dev_lock_changed; | |
106 | wait_queue_head_t hwdep_wait; | |
bde8a8f2 | 107 | |
555e8a8f TS |
108 | /* response queue */ |
109 | u8 *resp_buf; | |
110 | u8 *pull_ptr; | |
111 | u8 *push_ptr; | |
bde8a8f2 | 112 | }; |
555e8a8f TS |
113 | |
114 | int snd_efw_transaction_cmd(struct fw_unit *unit, | |
115 | const void *cmd, unsigned int size); | |
bde8a8f2 TS |
116 | int snd_efw_transaction_run(struct fw_unit *unit, |
117 | const void *cmd, unsigned int cmd_size, | |
118 | void *resp, unsigned int resp_size); | |
119 | int snd_efw_transaction_register(void); | |
120 | void snd_efw_transaction_unregister(void); | |
121 | void snd_efw_transaction_bus_reset(struct fw_unit *unit); | |
555e8a8f TS |
122 | void snd_efw_transaction_add_instance(struct snd_efw *efw); |
123 | void snd_efw_transaction_remove_instance(struct snd_efw *efw); | |
bde8a8f2 TS |
124 | |
125 | struct snd_efw_hwinfo { | |
126 | u32 flags; | |
127 | u32 guid_hi; | |
128 | u32 guid_lo; | |
129 | u32 type; | |
130 | u32 version; | |
131 | char vendor_name[HWINFO_NAME_SIZE_BYTES]; | |
132 | char model_name[HWINFO_NAME_SIZE_BYTES]; | |
133 | u32 supported_clocks; | |
134 | u32 amdtp_rx_pcm_channels; | |
135 | u32 amdtp_tx_pcm_channels; | |
136 | u32 phys_out; | |
137 | u32 phys_in; | |
138 | u32 phys_out_grp_count; | |
139 | struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS]; | |
140 | u32 phys_in_grp_count; | |
141 | struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS]; | |
142 | u32 midi_out_ports; | |
143 | u32 midi_in_ports; | |
144 | u32 max_sample_rate; | |
145 | u32 min_sample_rate; | |
146 | u32 dsp_version; | |
147 | u32 arm_version; | |
148 | u32 mixer_playback_channels; | |
149 | u32 mixer_capture_channels; | |
150 | u32 fpga_version; | |
151 | u32 amdtp_rx_pcm_channels_2x; | |
152 | u32 amdtp_tx_pcm_channels_2x; | |
153 | u32 amdtp_rx_pcm_channels_4x; | |
154 | u32 amdtp_tx_pcm_channels_4x; | |
155 | u32 reserved[16]; | |
156 | } __packed; | |
157 | enum snd_efw_grp_type { | |
158 | SND_EFW_CH_TYPE_ANALOG = 0, | |
159 | SND_EFW_CH_TYPE_SPDIF = 1, | |
160 | SND_EFW_CH_TYPE_ADAT = 2, | |
161 | SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3, | |
162 | SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4, | |
163 | SND_EFW_CH_TYPE_HEADPHONES = 5, | |
164 | SND_EFW_CH_TYPE_I2S = 6, | |
165 | SND_EFW_CH_TYPE_GUITAR = 7, | |
166 | SND_EFW_CH_TYPE_PIEZO_GUITAR = 8, | |
167 | SND_EFW_CH_TYPE_GUITAR_STRING = 9, | |
bde8a8f2 TS |
168 | SND_EFW_CH_TYPE_DUMMY |
169 | }; | |
170 | struct snd_efw_phys_meters { | |
171 | u32 status; /* guitar state/midi signal/clock input detect */ | |
172 | u32 reserved0; | |
173 | u32 reserved1; | |
174 | u32 reserved2; | |
175 | u32 reserved3; | |
176 | u32 out_meters; | |
177 | u32 in_meters; | |
178 | u32 reserved4; | |
179 | u32 reserved5; | |
180 | u32 values[0]; | |
181 | } __packed; | |
182 | enum snd_efw_clock_source { | |
183 | SND_EFW_CLOCK_SOURCE_INTERNAL = 0, | |
184 | SND_EFW_CLOCK_SOURCE_SYTMATCH = 1, | |
185 | SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2, | |
186 | SND_EFW_CLOCK_SOURCE_SPDIF = 3, | |
187 | SND_EFW_CLOCK_SOURCE_ADAT_1 = 4, | |
188 | SND_EFW_CLOCK_SOURCE_ADAT_2 = 5, | |
189 | SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */ | |
190 | }; | |
191 | enum snd_efw_transport_mode { | |
192 | SND_EFW_TRANSPORT_MODE_WINDOWS = 0, | |
193 | SND_EFW_TRANSPORT_MODE_IEC61883 = 1, | |
b5b04336 | 194 | }; |
bde8a8f2 TS |
195 | int snd_efw_command_set_resp_addr(struct snd_efw *efw, |
196 | u16 addr_high, u32 addr_low); | |
93219d06 TS |
197 | int snd_efw_command_set_tx_mode(struct snd_efw *efw, |
198 | enum snd_efw_transport_mode mode); | |
bde8a8f2 TS |
199 | int snd_efw_command_get_hwinfo(struct snd_efw *efw, |
200 | struct snd_efw_hwinfo *hwinfo); | |
201 | int snd_efw_command_get_phys_meters(struct snd_efw *efw, | |
202 | struct snd_efw_phys_meters *meters, | |
203 | unsigned int len); | |
204 | int snd_efw_command_get_clock_source(struct snd_efw *efw, | |
205 | enum snd_efw_clock_source *source); | |
206 | int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate); | |
207 | int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate); | |
b5b04336 | 208 | |
315fd41f | 209 | int snd_efw_stream_init_duplex(struct snd_efw *efw); |
4a286d55 | 210 | int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate); |
315fd41f TS |
211 | void snd_efw_stream_stop_duplex(struct snd_efw *efw); |
212 | void snd_efw_stream_update_duplex(struct snd_efw *efw); | |
213 | void snd_efw_stream_destroy_duplex(struct snd_efw *efw); | |
594ddced TS |
214 | void snd_efw_stream_lock_changed(struct snd_efw *efw); |
215 | int snd_efw_stream_lock_try(struct snd_efw *efw); | |
216 | void snd_efw_stream_lock_release(struct snd_efw *efw); | |
315fd41f | 217 | |
6a22683e TS |
218 | void snd_efw_proc_init(struct snd_efw *efw); |
219 | ||
a63d3ff1 TS |
220 | int snd_efw_create_midi_devices(struct snd_efw *efw); |
221 | ||
aa02bb6e TS |
222 | int snd_efw_create_pcm_devices(struct snd_efw *efw); |
223 | int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode); | |
224 | ||
594ddced TS |
225 | int snd_efw_create_hwdep_device(struct snd_efw *efw); |
226 | ||
b5b04336 TS |
227 | #define SND_EFW_DEV_ENTRY(vendor, model) \ |
228 | { \ | |
229 | .match_flags = IEEE1394_MATCH_VENDOR_ID | \ | |
230 | IEEE1394_MATCH_MODEL_ID, \ | |
231 | .vendor_id = vendor,\ | |
232 | .model_id = model \ | |
233 | } | |
234 | ||
235 | #endif |