Commit | Line | Data |
---|---|---|
31ef9134 | 1 | /* |
8832c5a7 | 2 | * oxfw.c - a part of driver for OXFW970/971 based devices |
31ef9134 CL |
3 | * |
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | |
5 | * Licensed under the terms of the GNU General Public License, version 2. | |
6 | */ | |
7 | ||
e2786ca6 | 8 | #include "oxfw.h" |
31ef9134 CL |
9 | |
10 | #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000) | |
11 | /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */ | |
12 | ||
13 | #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020) | |
14 | #define OXFORD_HARDWARE_ID_OXFW970 0x39443841 | |
15 | #define OXFORD_HARDWARE_ID_OXFW971 0x39373100 | |
16 | ||
ec4dba50 | 17 | #define VENDOR_LOUD 0x000ff2 |
31ef9134 | 18 | #define VENDOR_GRIFFIN 0x001292 |
ec4dba50 | 19 | #define VENDOR_BEHRINGER 0x001564 |
31ef9134 CL |
20 | #define VENDOR_LACIE 0x00d04b |
21 | ||
22 | #define SPECIFIER_1394TA 0x00a02d | |
23 | #define VERSION_AVC 0x010001 | |
24 | ||
8832c5a7 | 25 | MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver"); |
31ef9134 CL |
26 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
27 | MODULE_LICENSE("GPL v2"); | |
8832c5a7 | 28 | MODULE_ALIAS("snd-firewire-speakers"); |
31ef9134 | 29 | |
ec4dba50 TS |
30 | static bool detect_loud_models(struct fw_unit *unit) |
31 | { | |
32 | const char *const models[] = { | |
33 | "Onyxi", | |
34 | "Onyx-i", | |
35 | "d.Pro", | |
36 | "Mackie Onyx Satellite", | |
37 | "Tapco LINK.firewire 4x6", | |
38 | "U.420"}; | |
39 | char model[32]; | |
40 | unsigned int i; | |
41 | int err; | |
42 | ||
43 | err = fw_csr_string(unit->directory, CSR_MODEL, | |
44 | model, sizeof(model)); | |
45 | if (err < 0) | |
0d3aba30 | 46 | return false; |
ec4dba50 TS |
47 | |
48 | for (i = 0; i < ARRAY_SIZE(models); i++) { | |
49 | if (strcmp(models[i], model) == 0) | |
50 | break; | |
51 | } | |
52 | ||
53 | return (i < ARRAY_SIZE(models)); | |
54 | } | |
55 | ||
fec7b753 | 56 | static int name_card(struct snd_oxfw *oxfw) |
31ef9134 | 57 | { |
fec7b753 | 58 | struct fw_device *fw_dev = fw_parent_device(oxfw->unit); |
ec4dba50 TS |
59 | char vendor[24]; |
60 | char model[32]; | |
fec7b753 TS |
61 | const char *d, *v, *m; |
62 | u32 firmware; | |
31ef9134 CL |
63 | int err; |
64 | ||
ec4dba50 TS |
65 | /* get vendor name from root directory */ |
66 | err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR, | |
67 | vendor, sizeof(vendor)); | |
68 | if (err < 0) | |
69 | goto end; | |
70 | ||
71 | /* get model name from unit directory */ | |
72 | err = fw_csr_string(oxfw->unit->directory, CSR_MODEL, | |
73 | model, sizeof(model)); | |
74 | if (err < 0) | |
75 | goto end; | |
76 | ||
fec7b753 TS |
77 | err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST, |
78 | OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0); | |
79 | if (err < 0) | |
80 | goto end; | |
81 | be32_to_cpus(&firmware); | |
82 | ||
ec4dba50 TS |
83 | /* to apply card definitions */ |
84 | if (oxfw->device_info) { | |
85 | d = oxfw->device_info->driver_name; | |
86 | v = oxfw->device_info->vendor_name; | |
87 | m = oxfw->device_info->model_name; | |
88 | } else { | |
89 | d = "OXFW"; | |
90 | v = vendor; | |
91 | m = model; | |
92 | } | |
fec7b753 TS |
93 | |
94 | strcpy(oxfw->card->driver, d); | |
95 | strcpy(oxfw->card->mixername, m); | |
96 | strcpy(oxfw->card->shortname, m); | |
97 | ||
98 | snprintf(oxfw->card->longname, sizeof(oxfw->card->longname), | |
99 | "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d", | |
100 | v, m, firmware >> 20, firmware & 0xffff, | |
101 | fw_dev->config_rom[3], fw_dev->config_rom[4], | |
102 | dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed); | |
103 | end: | |
104 | return err; | |
31ef9134 CL |
105 | } |
106 | ||
12ed7192 TS |
107 | /* |
108 | * This module releases the FireWire unit data after all ALSA character devices | |
109 | * are released by applications. This is for releasing stream data or finishing | |
110 | * transactions safely. Thus at returning from .remove(), this module still keep | |
111 | * references for the unit. | |
112 | */ | |
8832c5a7 | 113 | static void oxfw_card_free(struct snd_card *card) |
31ef9134 | 114 | { |
8832c5a7 | 115 | struct snd_oxfw *oxfw = card->private_data; |
5cd1d3f4 TS |
116 | unsigned int i; |
117 | ||
dec84316 TS |
118 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); |
119 | if (oxfw->has_output) | |
120 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); | |
121 | ||
12ed7192 TS |
122 | fw_unit_put(oxfw->unit); |
123 | ||
b0ac0009 TS |
124 | for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { |
125 | kfree(oxfw->tx_stream_formats[i]); | |
5cd1d3f4 | 126 | kfree(oxfw->rx_stream_formats[i]); |
b0ac0009 | 127 | } |
31ef9134 | 128 | |
8832c5a7 | 129 | mutex_destroy(&oxfw->mutex); |
31ef9134 CL |
130 | } |
131 | ||
8832c5a7 | 132 | static int oxfw_probe(struct fw_unit *unit, |
94a87157 | 133 | const struct ieee1394_device_id *id) |
31ef9134 | 134 | { |
31ef9134 | 135 | struct snd_card *card; |
8832c5a7 | 136 | struct snd_oxfw *oxfw; |
31ef9134 CL |
137 | int err; |
138 | ||
ec4dba50 TS |
139 | if ((id->vendor_id == VENDOR_LOUD) && !detect_loud_models(unit)) |
140 | return -ENODEV; | |
141 | ||
06b45f00 | 142 | err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
8832c5a7 | 143 | sizeof(*oxfw), &card); |
31ef9134 CL |
144 | if (err < 0) |
145 | return err; | |
31ef9134 | 146 | |
e2786ca6 | 147 | card->private_free = oxfw_card_free; |
8832c5a7 TS |
148 | oxfw = card->private_data; |
149 | oxfw->card = card; | |
150 | mutex_init(&oxfw->mutex); | |
12ed7192 | 151 | oxfw->unit = fw_unit_get(unit); |
8832c5a7 | 152 | oxfw->device_info = (const struct device_info *)id->driver_data; |
05588d34 | 153 | spin_lock_init(&oxfw->lock); |
8985f4ac | 154 | init_waitqueue_head(&oxfw->hwdep_wait); |
31ef9134 | 155 | |
5cd1d3f4 TS |
156 | err = snd_oxfw_stream_discover(oxfw); |
157 | if (err < 0) | |
158 | goto error; | |
159 | ||
fec7b753 TS |
160 | err = name_card(oxfw); |
161 | if (err < 0) | |
162 | goto error; | |
31ef9134 | 163 | |
3713d93a | 164 | err = snd_oxfw_create_pcm(oxfw); |
31ef9134 CL |
165 | if (err < 0) |
166 | goto error; | |
167 | ||
ec4dba50 TS |
168 | if (oxfw->device_info) { |
169 | err = snd_oxfw_create_mixer(oxfw); | |
170 | if (err < 0) | |
171 | goto error; | |
172 | } | |
31ef9134 | 173 | |
3c96101f TS |
174 | snd_oxfw_proc_init(oxfw); |
175 | ||
05588d34 TS |
176 | err = snd_oxfw_create_midi(oxfw); |
177 | if (err < 0) | |
178 | goto error; | |
179 | ||
8985f4ac TS |
180 | err = snd_oxfw_create_hwdep(oxfw); |
181 | if (err < 0) | |
182 | goto error; | |
183 | ||
b0ac0009 | 184 | err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream); |
31ef9134 CL |
185 | if (err < 0) |
186 | goto error; | |
b0ac0009 TS |
187 | if (oxfw->has_output) { |
188 | err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream); | |
189 | if (err < 0) | |
190 | goto error; | |
191 | } | |
31ef9134 | 192 | |
e2786ca6 TS |
193 | err = snd_card_register(card); |
194 | if (err < 0) { | |
b0ac0009 TS |
195 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream); |
196 | if (oxfw->has_output) | |
197 | snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream); | |
e2786ca6 TS |
198 | goto error; |
199 | } | |
8832c5a7 | 200 | dev_set_drvdata(&unit->device, oxfw); |
31ef9134 CL |
201 | |
202 | return 0; | |
31ef9134 CL |
203 | error: |
204 | snd_card_free(card); | |
205 | return err; | |
206 | } | |
207 | ||
8832c5a7 | 208 | static void oxfw_bus_reset(struct fw_unit *unit) |
31ef9134 | 209 | { |
8832c5a7 | 210 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
31ef9134 | 211 | |
8832c5a7 | 212 | fcp_bus_reset(oxfw->unit); |
31ef9134 | 213 | |
e2786ca6 | 214 | mutex_lock(&oxfw->mutex); |
b0ac0009 TS |
215 | |
216 | snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream); | |
217 | if (oxfw->has_output) | |
218 | snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream); | |
219 | ||
e2786ca6 | 220 | mutex_unlock(&oxfw->mutex); |
31ef9134 CL |
221 | } |
222 | ||
8832c5a7 | 223 | static void oxfw_remove(struct fw_unit *unit) |
94a87157 | 224 | { |
8832c5a7 | 225 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
94a87157 | 226 | |
12ed7192 | 227 | /* No need to wait for releasing card object in this context. */ |
8832c5a7 | 228 | snd_card_free_when_closed(oxfw->card); |
94a87157 SR |
229 | } |
230 | ||
231 | static const struct device_info griffin_firewave = { | |
232 | .driver_name = "FireWave", | |
fec7b753 TS |
233 | .vendor_name = "Griffin", |
234 | .model_name = "FireWave", | |
94a87157 SR |
235 | .mixer_channels = 6, |
236 | .mute_fb_id = 0x01, | |
237 | .volume_fb_id = 0x02, | |
238 | }; | |
239 | ||
240 | static const struct device_info lacie_speakers = { | |
241 | .driver_name = "FWSpeakers", | |
fec7b753 TS |
242 | .vendor_name = "LaCie", |
243 | .model_name = "FireWire Speakers", | |
94a87157 SR |
244 | .mixer_channels = 1, |
245 | .mute_fb_id = 0x01, | |
246 | .volume_fb_id = 0x01, | |
247 | }; | |
248 | ||
8832c5a7 | 249 | static const struct ieee1394_device_id oxfw_id_table[] = { |
31ef9134 CL |
250 | { |
251 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
252 | IEEE1394_MATCH_MODEL_ID | | |
253 | IEEE1394_MATCH_SPECIFIER_ID | | |
254 | IEEE1394_MATCH_VERSION, | |
255 | .vendor_id = VENDOR_GRIFFIN, | |
256 | .model_id = 0x00f970, | |
257 | .specifier_id = SPECIFIER_1394TA, | |
258 | .version = VERSION_AVC, | |
94a87157 | 259 | .driver_data = (kernel_ulong_t)&griffin_firewave, |
31ef9134 CL |
260 | }, |
261 | { | |
262 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
263 | IEEE1394_MATCH_MODEL_ID | | |
264 | IEEE1394_MATCH_SPECIFIER_ID | | |
265 | IEEE1394_MATCH_VERSION, | |
266 | .vendor_id = VENDOR_LACIE, | |
267 | .model_id = 0x00f970, | |
268 | .specifier_id = SPECIFIER_1394TA, | |
269 | .version = VERSION_AVC, | |
94a87157 | 270 | .driver_data = (kernel_ulong_t)&lacie_speakers, |
31ef9134 | 271 | }, |
ec4dba50 TS |
272 | /* Behringer,F-Control Audio 202 */ |
273 | { | |
274 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
275 | IEEE1394_MATCH_MODEL_ID, | |
276 | .vendor_id = VENDOR_BEHRINGER, | |
277 | .model_id = 0x00fc22, | |
278 | }, | |
279 | /* | |
280 | * Any Mackie(Loud) models (name string/model id): | |
281 | * Onyx-i series (former models): 0x081216 | |
282 | * Mackie Onyx Satellite: 0x00200f | |
283 | * Tapco LINK.firewire 4x6: 0x000460 | |
284 | * d.2 pro: Unknown | |
285 | * d.4 pro: Unknown | |
286 | * U.420: Unknown | |
287 | * U.420d: Unknown | |
288 | */ | |
289 | { | |
290 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
291 | IEEE1394_MATCH_SPECIFIER_ID | | |
292 | IEEE1394_MATCH_VERSION, | |
293 | .vendor_id = VENDOR_LOUD, | |
294 | .specifier_id = SPECIFIER_1394TA, | |
295 | .version = VERSION_AVC, | |
296 | }, | |
31ef9134 CL |
297 | { } |
298 | }; | |
8832c5a7 | 299 | MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table); |
31ef9134 | 300 | |
8832c5a7 | 301 | static struct fw_driver oxfw_driver = { |
31ef9134 CL |
302 | .driver = { |
303 | .owner = THIS_MODULE, | |
304 | .name = KBUILD_MODNAME, | |
305 | .bus = &fw_bus_type, | |
31ef9134 | 306 | }, |
8832c5a7 TS |
307 | .probe = oxfw_probe, |
308 | .update = oxfw_bus_reset, | |
309 | .remove = oxfw_remove, | |
310 | .id_table = oxfw_id_table, | |
31ef9134 CL |
311 | }; |
312 | ||
8832c5a7 | 313 | static int __init snd_oxfw_init(void) |
31ef9134 | 314 | { |
8832c5a7 | 315 | return driver_register(&oxfw_driver.driver); |
31ef9134 CL |
316 | } |
317 | ||
8832c5a7 | 318 | static void __exit snd_oxfw_exit(void) |
31ef9134 | 319 | { |
8832c5a7 | 320 | driver_unregister(&oxfw_driver.driver); |
31ef9134 CL |
321 | } |
322 | ||
8832c5a7 TS |
323 | module_init(snd_oxfw_init); |
324 | module_exit(snd_oxfw_exit); |