blob: a354d26afe9e4cb2eb2280a8f20ba2acef64ec87 [file] [log] [blame]
Takashi Sakamotob5b04332014-04-25 22:45:00 +09001/*
2 * fireworks.c - 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
10/*
11 * Fireworks is a board module which Echo Audio produced. This module consists
12 * of three chipsets:
13 * - Communication chipset for IEEE1394 PHY/Link and IEC 61883-1/6
14 * - DSP or/and FPGA for signal processing
15 * - Flash Memory to store firmwares
16 */
17
18#include "fireworks.h"
19
20MODULE_DESCRIPTION("Echo Fireworks driver");
21MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
22MODULE_LICENSE("GPL v2");
23
24static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
25static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
26static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Sakamoto555e8a82014-04-25 22:45:13 +090027unsigned int snd_efw_resp_buf_size = 1024;
28bool snd_efw_resp_buf_debug = false;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090029
30module_param_array(index, int, NULL, 0444);
31MODULE_PARM_DESC(index, "card index");
32module_param_array(id, charp, NULL, 0444);
33MODULE_PARM_DESC(id, "ID string");
34module_param_array(enable, bool, NULL, 0444);
35MODULE_PARM_DESC(enable, "enable Fireworks sound card");
Takashi Sakamoto555e8a82014-04-25 22:45:13 +090036module_param_named(resp_buf_size, snd_efw_resp_buf_size, uint, 0444);
37MODULE_PARM_DESC(resp_buf_size,
38 "response buffer size (max 4096, default 1024)");
39module_param_named(resp_buf_debug, snd_efw_resp_buf_debug, bool, 0444);
40MODULE_PARM_DESC(resp_buf_debug, "store all responses to buffer");
Takashi Sakamotob5b04332014-04-25 22:45:00 +090041
42static DEFINE_MUTEX(devices_mutex);
43static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
44
45#define VENDOR_LOUD 0x000ff2
46#define MODEL_MACKIE_400F 0x00400f
47#define MODEL_MACKIE_1200F 0x01200f
48
49#define VENDOR_ECHO 0x001486
50#define MODEL_ECHO_AUDIOFIRE_12 0x00af12
51#define MODEL_ECHO_AUDIOFIRE_12HD 0x0af12d
52#define MODEL_ECHO_AUDIOFIRE_12_APPLE 0x0af12a
53/* This is applied for AudioFire8 (until 2009 July) */
54#define MODEL_ECHO_AUDIOFIRE_8 0x000af8
55#define MODEL_ECHO_AUDIOFIRE_2 0x000af2
56#define MODEL_ECHO_AUDIOFIRE_4 0x000af4
57/* AudioFire9 is applied for AudioFire8(since 2009 July) and AudioFirePre8 */
58#define MODEL_ECHO_AUDIOFIRE_9 0x000af9
59/* unknown as product */
60#define MODEL_ECHO_FIREWORKS_8 0x0000f8
61#define MODEL_ECHO_FIREWORKS_HDMI 0x00afd1
62
63#define VENDOR_GIBSON 0x00075b
64/* for Robot Interface Pack of Dark Fire, Dusk Tiger, Les Paul Standard 2010 */
65#define MODEL_GIBSON_RIP 0x00afb2
66/* unknown as product */
67#define MODEL_GIBSON_GOLDTOP 0x00afb9
68
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090069/* part of hardware capability flags */
70#define FLAG_RESP_ADDR_CHANGABLE 0
71
72static int
73get_hardware_info(struct snd_efw *efw)
74{
75 struct fw_device *fw_dev = fw_parent_device(efw->unit);
76 struct snd_efw_hwinfo *hwinfo;
77 char version[12] = {0};
78 int err;
79
80 hwinfo = kzalloc(sizeof(struct snd_efw_hwinfo), GFP_KERNEL);
81 if (hwinfo == NULL)
82 return -ENOMEM;
83
84 err = snd_efw_command_get_hwinfo(efw, hwinfo);
85 if (err < 0)
86 goto end;
87
88 /* firmware version for communication chipset */
89 snprintf(version, sizeof(version), "%u.%u",
90 (hwinfo->arm_version >> 24) & 0xff,
91 (hwinfo->arm_version >> 16) & 0xff);
92 if (err < 0)
93 goto end;
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090094 efw->firmware_version = hwinfo->arm_version;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090095
96 strcpy(efw->card->driver, "Fireworks");
97 strcpy(efw->card->shortname, hwinfo->model_name);
98 strcpy(efw->card->mixername, hwinfo->model_name);
99 snprintf(efw->card->longname, sizeof(efw->card->longname),
100 "%s %s v%s, GUID %08x%08x at %s, S%d",
101 hwinfo->vendor_name, hwinfo->model_name, version,
102 hwinfo->guid_hi, hwinfo->guid_lo,
103 dev_name(&efw->unit->device), 100 << fw_dev->max_speed);
104 if (err < 0)
105 goto end;
106
107 if (hwinfo->flags & BIT(FLAG_RESP_ADDR_CHANGABLE))
108 efw->resp_addr_changable = true;
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900109
110 efw->supported_sampling_rate = 0;
111 if ((hwinfo->min_sample_rate <= 22050)
112 && (22050 <= hwinfo->max_sample_rate))
113 efw->supported_sampling_rate |= SNDRV_PCM_RATE_22050;
114 if ((hwinfo->min_sample_rate <= 32000)
115 && (32000 <= hwinfo->max_sample_rate))
116 efw->supported_sampling_rate |= SNDRV_PCM_RATE_32000;
117 if ((hwinfo->min_sample_rate <= 44100)
118 && (44100 <= hwinfo->max_sample_rate))
119 efw->supported_sampling_rate |= SNDRV_PCM_RATE_44100;
120 if ((hwinfo->min_sample_rate <= 48000)
121 && (48000 <= hwinfo->max_sample_rate))
122 efw->supported_sampling_rate |= SNDRV_PCM_RATE_48000;
123 if ((hwinfo->min_sample_rate <= 88200)
124 && (88200 <= hwinfo->max_sample_rate))
125 efw->supported_sampling_rate |= SNDRV_PCM_RATE_88200;
126 if ((hwinfo->min_sample_rate <= 96000)
127 && (96000 <= hwinfo->max_sample_rate))
128 efw->supported_sampling_rate |= SNDRV_PCM_RATE_96000;
129 if ((hwinfo->min_sample_rate <= 176400)
130 && (176400 <= hwinfo->max_sample_rate))
131 efw->supported_sampling_rate |= SNDRV_PCM_RATE_176400;
132 if ((hwinfo->min_sample_rate <= 192000)
133 && (192000 <= hwinfo->max_sample_rate))
134 efw->supported_sampling_rate |= SNDRV_PCM_RATE_192000;
135
136 /* the number of MIDI ports, not of MIDI conformant data channels */
137 if (hwinfo->midi_out_ports > SND_EFW_MAX_MIDI_OUT_PORTS ||
138 hwinfo->midi_in_ports > SND_EFW_MAX_MIDI_IN_PORTS) {
139 err = -EIO;
140 goto end;
141 }
142 efw->midi_out_ports = hwinfo->midi_out_ports;
143 efw->midi_in_ports = hwinfo->midi_in_ports;
144
145 if (hwinfo->amdtp_tx_pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM ||
146 hwinfo->amdtp_tx_pcm_channels_2x > AMDTP_MAX_CHANNELS_FOR_PCM ||
147 hwinfo->amdtp_tx_pcm_channels_4x > AMDTP_MAX_CHANNELS_FOR_PCM ||
148 hwinfo->amdtp_rx_pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM ||
149 hwinfo->amdtp_rx_pcm_channels_2x > AMDTP_MAX_CHANNELS_FOR_PCM ||
150 hwinfo->amdtp_rx_pcm_channels_4x > AMDTP_MAX_CHANNELS_FOR_PCM) {
151 err = -ENOSYS;
152 goto end;
153 }
154 efw->pcm_capture_channels[0] = hwinfo->amdtp_tx_pcm_channels;
155 efw->pcm_capture_channels[1] = hwinfo->amdtp_tx_pcm_channels_2x;
156 efw->pcm_capture_channels[2] = hwinfo->amdtp_tx_pcm_channels_4x;
157 efw->pcm_playback_channels[0] = hwinfo->amdtp_rx_pcm_channels;
158 efw->pcm_playback_channels[1] = hwinfo->amdtp_rx_pcm_channels_2x;
159 efw->pcm_playback_channels[2] = hwinfo->amdtp_rx_pcm_channels_4x;
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900160
161 /* Hardware metering. */
162 if (hwinfo->phys_in_grp_count > HWINFO_MAX_CAPS_GROUPS ||
163 hwinfo->phys_out_grp_count > HWINFO_MAX_CAPS_GROUPS) {
164 return -EIO;
165 goto end;
166 }
167 efw->phys_in = hwinfo->phys_in;
168 efw->phys_out = hwinfo->phys_out;
169 efw->phys_in_grp_count = hwinfo->phys_in_grp_count;
170 efw->phys_out_grp_count = hwinfo->phys_out_grp_count;
171 memcpy(&efw->phys_in_grps, hwinfo->phys_in_grps,
172 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_in_grp_count);
173 memcpy(&efw->phys_out_grps, hwinfo->phys_out_grps,
174 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_out_grp_count);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900175end:
176 kfree(hwinfo);
177 return err;
178}
179
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900180static void
181efw_card_free(struct snd_card *card)
182{
183 struct snd_efw *efw = card->private_data;
184
185 if (efw->card_index >= 0) {
186 mutex_lock(&devices_mutex);
187 clear_bit(efw->card_index, devices_used);
188 mutex_unlock(&devices_mutex);
189 }
190
191 mutex_destroy(&efw->mutex);
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900192 kfree(efw->resp_buf);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900193}
194
195static int
196efw_probe(struct fw_unit *unit,
197 const struct ieee1394_device_id *entry)
198{
199 struct snd_card *card;
200 struct snd_efw *efw;
201 int card_index, err;
202
203 mutex_lock(&devices_mutex);
204
205 /* check registered cards */
206 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
207 if (!test_bit(card_index, devices_used) && enable[card_index])
208 break;
209 }
210 if (card_index >= SNDRV_CARDS) {
211 err = -ENOENT;
212 goto end;
213 }
214
215 err = snd_card_new(&unit->device, index[card_index], id[card_index],
216 THIS_MODULE, sizeof(struct snd_efw), &card);
217 if (err < 0)
218 goto end;
219 efw = card->private_data;
220 efw->card_index = card_index;
221 set_bit(card_index, devices_used);
222 card->private_free = efw_card_free;
223
224 efw->card = card;
225 efw->unit = unit;
226 mutex_init(&efw->mutex);
227 spin_lock_init(&efw->lock);
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900228 init_waitqueue_head(&efw->hwdep_wait);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900229
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900230 /* prepare response buffer */
231 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size,
232 SND_EFW_RESPONSE_MAXIMUM_BYTES, 4096U);
233 efw->resp_buf = kzalloc(snd_efw_resp_buf_size, GFP_KERNEL);
234 if (efw->resp_buf == NULL) {
235 err = -ENOMEM;
236 goto error;
237 }
238 efw->pull_ptr = efw->push_ptr = efw->resp_buf;
239 snd_efw_transaction_add_instance(efw);
240
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900241 err = get_hardware_info(efw);
242 if (err < 0)
243 goto error;
Takashi Sakamoto69702232014-04-25 22:45:05 +0900244 if (entry->model_id == MODEL_ECHO_AUDIOFIRE_9)
245 efw->is_af9 = true;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900246
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900247 snd_efw_proc_init(efw);
248
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900249 if (efw->midi_out_ports || efw->midi_in_ports) {
250 err = snd_efw_create_midi_devices(efw);
251 if (err < 0)
252 goto error;
253 }
254
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900255 err = snd_efw_create_pcm_devices(efw);
256 if (err < 0)
257 goto error;
258
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900259 err = snd_efw_create_hwdep_device(efw);
260 if (err < 0)
261 goto error;
262
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900263 err = snd_efw_stream_init_duplex(efw);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900264 if (err < 0)
265 goto error;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900266
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900267 err = snd_card_register(card);
268 if (err < 0) {
269 snd_efw_stream_destroy_duplex(efw);
270 goto error;
271 }
272
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900273 dev_set_drvdata(&unit->device, efw);
274end:
275 mutex_unlock(&devices_mutex);
276 return err;
277error:
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900278 snd_efw_transaction_remove_instance(efw);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900279 mutex_unlock(&devices_mutex);
280 snd_card_free(card);
281 return err;
282}
283
284static void efw_update(struct fw_unit *unit)
285{
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900286 struct snd_efw *efw = dev_get_drvdata(&unit->device);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900287
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900288 snd_efw_transaction_bus_reset(efw->unit);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900289 snd_efw_stream_update_duplex(efw);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900290}
291
292static void efw_remove(struct fw_unit *unit)
293{
294 struct snd_efw *efw = dev_get_drvdata(&unit->device);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900295
296 snd_efw_stream_destroy_duplex(efw);
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900297 snd_efw_transaction_remove_instance(efw);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900298
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900299 snd_card_disconnect(efw->card);
300 snd_card_free_when_closed(efw->card);
301}
302
303static const struct ieee1394_device_id efw_id_table[] = {
304 SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_400F),
305 SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_1200F),
306 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_8),
307 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12),
308 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12HD),
309 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12_APPLE),
310 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_2),
311 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_4),
312 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_9),
313 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_8),
314 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_HDMI),
315 SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_RIP),
316 SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_GOLDTOP),
317 {}
318};
319MODULE_DEVICE_TABLE(ieee1394, efw_id_table);
320
321static struct fw_driver efw_driver = {
322 .driver = {
323 .owner = THIS_MODULE,
324 .name = "snd-fireworks",
325 .bus = &fw_bus_type,
326 },
327 .probe = efw_probe,
328 .update = efw_update,
329 .remove = efw_remove,
330 .id_table = efw_id_table,
331};
332
333static int __init snd_efw_init(void)
334{
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900335 int err;
336
337 err = snd_efw_transaction_register();
338 if (err < 0)
339 goto end;
340
341 err = driver_register(&efw_driver.driver);
342 if (err < 0)
343 snd_efw_transaction_unregister();
344
345end:
346 return err;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900347}
348
349static void __exit snd_efw_exit(void)
350{
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900351 snd_efw_transaction_unregister();
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900352 driver_unregister(&efw_driver.driver);
353 mutex_destroy(&devices_mutex);
354}
355
356module_init(snd_efw_init);
357module_exit(snd_efw_exit);