blob: 60e5cad0531aeb181d4cc6558f44b4cd6896f070 [file] [log] [blame]
Clemens Ladisch31ef9132011-03-15 07:53:21 +01001/*
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +09002 * oxfw.c - a part of driver for OXFW970/971 based devices
Clemens Ladisch31ef9132011-03-15 07:53:21 +01003 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +09008#include "oxfw.h"
Clemens Ladisch31ef9132011-03-15 07:53:21 +01009
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
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090017#define VENDOR_LOUD 0x000ff2
Clemens Ladisch31ef9132011-03-15 07:53:21 +010018#define VENDOR_GRIFFIN 0x001292
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090019#define VENDOR_BEHRINGER 0x001564
Clemens Ladisch31ef9132011-03-15 07:53:21 +010020#define VENDOR_LACIE 0x00d04b
21
22#define SPECIFIER_1394TA 0x00a02d
23#define VERSION_AVC 0x010001
24
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +090025MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
Clemens Ladisch31ef9132011-03-15 07:53:21 +010026MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
27MODULE_LICENSE("GPL v2");
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +090028MODULE_ALIAS("snd-firewire-speakers");
Clemens Ladisch31ef9132011-03-15 07:53:21 +010029
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090030static 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)
Dan Carpenter0d3aba32014-12-12 22:28:10 +030046 return false;
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090047
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
Takashi Sakamotofec7b752014-12-09 00:10:40 +090056static int name_card(struct snd_oxfw *oxfw)
Clemens Ladisch31ef9132011-03-15 07:53:21 +010057{
Takashi Sakamotofec7b752014-12-09 00:10:40 +090058 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090059 char vendor[24];
60 char model[32];
Takashi Sakamotofec7b752014-12-09 00:10:40 +090061 const char *d, *v, *m;
62 u32 firmware;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010063 int err;
64
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090065 /* 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
Takashi Sakamotofec7b752014-12-09 00:10:40 +090077 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
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090083 /* 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 }
Takashi Sakamotofec7b752014-12-09 00:10:40 +090093
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);
103end:
104 return err;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100105}
106
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900107static void oxfw_card_free(struct snd_card *card)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100108{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900109 struct snd_oxfw *oxfw = card->private_data;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900110 unsigned int i;
111
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900112 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
113 kfree(oxfw->tx_stream_formats[i]);
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900114 kfree(oxfw->rx_stream_formats[i]);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900115 }
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100116
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900117 mutex_destroy(&oxfw->mutex);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100118}
119
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900120static int oxfw_probe(struct fw_unit *unit,
Stefan Richter94a87152013-06-09 18:15:00 +0200121 const struct ieee1394_device_id *id)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100122{
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100123 struct snd_card *card;
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900124 struct snd_oxfw *oxfw;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100125 int err;
126
Takashi Sakamotoec4dba52014-12-09 00:10:45 +0900127 if ((id->vendor_id == VENDOR_LOUD) && !detect_loud_models(unit))
128 return -ENODEV;
129
Takashi Iwai06b45f02014-01-29 14:23:55 +0100130 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900131 sizeof(*oxfw), &card);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100132 if (err < 0)
133 return err;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100134
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900135 card->private_free = oxfw_card_free;
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900136 oxfw = card->private_data;
137 oxfw->card = card;
138 mutex_init(&oxfw->mutex);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900139 oxfw->unit = unit;
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900140 oxfw->device_info = (const struct device_info *)id->driver_data;
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900141 spin_lock_init(&oxfw->lock);
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900142 init_waitqueue_head(&oxfw->hwdep_wait);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100143
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900144 err = snd_oxfw_stream_discover(oxfw);
145 if (err < 0)
146 goto error;
147
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900148 err = name_card(oxfw);
149 if (err < 0)
150 goto error;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100151
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900152 err = snd_oxfw_create_pcm(oxfw);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100153 if (err < 0)
154 goto error;
155
Takashi Sakamotoec4dba52014-12-09 00:10:45 +0900156 if (oxfw->device_info) {
157 err = snd_oxfw_create_mixer(oxfw);
158 if (err < 0)
159 goto error;
160 }
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100161
Takashi Sakamoto3c961012014-12-09 00:10:43 +0900162 snd_oxfw_proc_init(oxfw);
163
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900164 err = snd_oxfw_create_midi(oxfw);
165 if (err < 0)
166 goto error;
167
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900168 err = snd_oxfw_create_hwdep(oxfw);
169 if (err < 0)
170 goto error;
171
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900172 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100173 if (err < 0)
174 goto error;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900175 if (oxfw->has_output) {
176 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
177 if (err < 0)
178 goto error;
179 }
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100180
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900181 err = snd_card_register(card);
182 if (err < 0) {
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900183 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
184 if (oxfw->has_output)
185 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900186 goto error;
187 }
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900188 dev_set_drvdata(&unit->device, oxfw);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100189
190 return 0;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100191error:
192 snd_card_free(card);
193 return err;
194}
195
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900196static void oxfw_bus_reset(struct fw_unit *unit)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100197{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900198 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100199
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900200 fcp_bus_reset(oxfw->unit);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100201
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900202 mutex_lock(&oxfw->mutex);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900203
204 snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
205 if (oxfw->has_output)
206 snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
207
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900208 mutex_unlock(&oxfw->mutex);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100209}
210
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900211static void oxfw_remove(struct fw_unit *unit)
Stefan Richter94a87152013-06-09 18:15:00 +0200212{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900213 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
Stefan Richter94a87152013-06-09 18:15:00 +0200214
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900215 snd_card_disconnect(oxfw->card);
Stefan Richter94a87152013-06-09 18:15:00 +0200216
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900217 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
218 if (oxfw->has_output)
219 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
Stefan Richter94a87152013-06-09 18:15:00 +0200220
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900221 snd_card_free_when_closed(oxfw->card);
Stefan Richter94a87152013-06-09 18:15:00 +0200222}
223
224static const struct device_info griffin_firewave = {
225 .driver_name = "FireWave",
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900226 .vendor_name = "Griffin",
227 .model_name = "FireWave",
Stefan Richter94a87152013-06-09 18:15:00 +0200228 .mixer_channels = 6,
229 .mute_fb_id = 0x01,
230 .volume_fb_id = 0x02,
231};
232
233static const struct device_info lacie_speakers = {
234 .driver_name = "FWSpeakers",
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900235 .vendor_name = "LaCie",
236 .model_name = "FireWire Speakers",
Stefan Richter94a87152013-06-09 18:15:00 +0200237 .mixer_channels = 1,
238 .mute_fb_id = 0x01,
239 .volume_fb_id = 0x01,
240};
241
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900242static const struct ieee1394_device_id oxfw_id_table[] = {
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100243 {
244 .match_flags = IEEE1394_MATCH_VENDOR_ID |
245 IEEE1394_MATCH_MODEL_ID |
246 IEEE1394_MATCH_SPECIFIER_ID |
247 IEEE1394_MATCH_VERSION,
248 .vendor_id = VENDOR_GRIFFIN,
249 .model_id = 0x00f970,
250 .specifier_id = SPECIFIER_1394TA,
251 .version = VERSION_AVC,
Stefan Richter94a87152013-06-09 18:15:00 +0200252 .driver_data = (kernel_ulong_t)&griffin_firewave,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100253 },
254 {
255 .match_flags = IEEE1394_MATCH_VENDOR_ID |
256 IEEE1394_MATCH_MODEL_ID |
257 IEEE1394_MATCH_SPECIFIER_ID |
258 IEEE1394_MATCH_VERSION,
259 .vendor_id = VENDOR_LACIE,
260 .model_id = 0x00f970,
261 .specifier_id = SPECIFIER_1394TA,
262 .version = VERSION_AVC,
Stefan Richter94a87152013-06-09 18:15:00 +0200263 .driver_data = (kernel_ulong_t)&lacie_speakers,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100264 },
Takashi Sakamotoec4dba52014-12-09 00:10:45 +0900265 /* Behringer,F-Control Audio 202 */
266 {
267 .match_flags = IEEE1394_MATCH_VENDOR_ID |
268 IEEE1394_MATCH_MODEL_ID,
269 .vendor_id = VENDOR_BEHRINGER,
270 .model_id = 0x00fc22,
271 },
272 /*
273 * Any Mackie(Loud) models (name string/model id):
274 * Onyx-i series (former models): 0x081216
275 * Mackie Onyx Satellite: 0x00200f
276 * Tapco LINK.firewire 4x6: 0x000460
277 * d.2 pro: Unknown
278 * d.4 pro: Unknown
279 * U.420: Unknown
280 * U.420d: Unknown
281 */
282 {
283 .match_flags = IEEE1394_MATCH_VENDOR_ID |
284 IEEE1394_MATCH_SPECIFIER_ID |
285 IEEE1394_MATCH_VERSION,
286 .vendor_id = VENDOR_LOUD,
287 .specifier_id = SPECIFIER_1394TA,
288 .version = VERSION_AVC,
289 },
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100290 { }
291};
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900292MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100293
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900294static struct fw_driver oxfw_driver = {
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100295 .driver = {
296 .owner = THIS_MODULE,
297 .name = KBUILD_MODNAME,
298 .bus = &fw_bus_type,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100299 },
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900300 .probe = oxfw_probe,
301 .update = oxfw_bus_reset,
302 .remove = oxfw_remove,
303 .id_table = oxfw_id_table,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100304};
305
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900306static int __init snd_oxfw_init(void)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100307{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900308 return driver_register(&oxfw_driver.driver);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100309}
310
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900311static void __exit snd_oxfw_exit(void)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100312{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900313 driver_unregister(&oxfw_driver.driver);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100314}
315
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900316module_init(snd_oxfw_init);
317module_exit(snd_oxfw_exit);