blob: ffb6dd796243b3dbe2689553c0f8a81e0ffa9825 [file] [log] [blame]
Thomas Gleixnerda607e12019-05-29 16:57:59 -07001// SPDX-License-Identifier: GPL-2.0-only
Takashi Sakamotob5b04332014-04-25 22:45:00 +09002/*
3 * fireworks.c - a part of driver for Fireworks based devices
4 *
5 * Copyright (c) 2009-2010 Clemens Ladisch
6 * Copyright (c) 2013-2014 Takashi Sakamoto
Takashi Sakamotob5b04332014-04-25 22:45:00 +09007 */
8
9/*
10 * Fireworks is a board module which Echo Audio produced. This module consists
11 * of three chipsets:
12 * - Communication chipset for IEEE1394 PHY/Link and IEC 61883-1/6
13 * - DSP or/and FPGA for signal processing
14 * - Flash Memory to store firmwares
15 */
16
17#include "fireworks.h"
18
19MODULE_DESCRIPTION("Echo Fireworks driver");
20MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
21MODULE_LICENSE("GPL v2");
22
23static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
24static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
25static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Sakamoto555e8a82014-04-25 22:45:13 +090026unsigned int snd_efw_resp_buf_size = 1024;
27bool snd_efw_resp_buf_debug = false;
Takashi Sakamotob5b04332014-04-25 22:45:00 +090028
29module_param_array(index, int, NULL, 0444);
30MODULE_PARM_DESC(index, "card index");
31module_param_array(id, charp, NULL, 0444);
32MODULE_PARM_DESC(id, "ID string");
33module_param_array(enable, bool, NULL, 0444);
34MODULE_PARM_DESC(enable, "enable Fireworks sound card");
Takashi Sakamoto555e8a82014-04-25 22:45:13 +090035module_param_named(resp_buf_size, snd_efw_resp_buf_size, uint, 0444);
36MODULE_PARM_DESC(resp_buf_size,
37 "response buffer size (max 4096, default 1024)");
38module_param_named(resp_buf_debug, snd_efw_resp_buf_debug, bool, 0444);
39MODULE_PARM_DESC(resp_buf_debug, "store all responses to buffer");
Takashi Sakamotob5b04332014-04-25 22:45:00 +090040
41static DEFINE_MUTEX(devices_mutex);
42static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
43
44#define VENDOR_LOUD 0x000ff2
45#define MODEL_MACKIE_400F 0x00400f
46#define MODEL_MACKIE_1200F 0x01200f
47
48#define VENDOR_ECHO 0x001486
49#define MODEL_ECHO_AUDIOFIRE_12 0x00af12
50#define MODEL_ECHO_AUDIOFIRE_12HD 0x0af12d
51#define MODEL_ECHO_AUDIOFIRE_12_APPLE 0x0af12a
52/* This is applied for AudioFire8 (until 2009 July) */
53#define MODEL_ECHO_AUDIOFIRE_8 0x000af8
54#define MODEL_ECHO_AUDIOFIRE_2 0x000af2
55#define MODEL_ECHO_AUDIOFIRE_4 0x000af4
56/* AudioFire9 is applied for AudioFire8(since 2009 July) and AudioFirePre8 */
57#define MODEL_ECHO_AUDIOFIRE_9 0x000af9
58/* unknown as product */
59#define MODEL_ECHO_FIREWORKS_8 0x0000f8
60#define MODEL_ECHO_FIREWORKS_HDMI 0x00afd1
61
62#define VENDOR_GIBSON 0x00075b
63/* for Robot Interface Pack of Dark Fire, Dusk Tiger, Les Paul Standard 2010 */
64#define MODEL_GIBSON_RIP 0x00afb2
65/* unknown as product */
66#define MODEL_GIBSON_GOLDTOP 0x00afb9
67
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090068/* part of hardware capability flags */
69#define FLAG_RESP_ADDR_CHANGABLE 0
70
71static int
72get_hardware_info(struct snd_efw *efw)
73{
74 struct fw_device *fw_dev = fw_parent_device(efw->unit);
75 struct snd_efw_hwinfo *hwinfo;
76 char version[12] = {0};
77 int err;
78
79 hwinfo = kzalloc(sizeof(struct snd_efw_hwinfo), GFP_KERNEL);
80 if (hwinfo == NULL)
81 return -ENOMEM;
82
83 err = snd_efw_command_get_hwinfo(efw, hwinfo);
84 if (err < 0)
85 goto end;
86
87 /* firmware version for communication chipset */
88 snprintf(version, sizeof(version), "%u.%u",
89 (hwinfo->arm_version >> 24) & 0xff,
90 (hwinfo->arm_version >> 16) & 0xff);
Takashi Sakamotod9cd0062014-04-25 22:45:06 +090091 efw->firmware_version = hwinfo->arm_version;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +090092
93 strcpy(efw->card->driver, "Fireworks");
94 strcpy(efw->card->shortname, hwinfo->model_name);
95 strcpy(efw->card->mixername, hwinfo->model_name);
96 snprintf(efw->card->longname, sizeof(efw->card->longname),
97 "%s %s v%s, GUID %08x%08x at %s, S%d",
98 hwinfo->vendor_name, hwinfo->model_name, version,
99 hwinfo->guid_hi, hwinfo->guid_lo,
100 dev_name(&efw->unit->device), 100 << fw_dev->max_speed);
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900101
102 if (hwinfo->flags & BIT(FLAG_RESP_ADDR_CHANGABLE))
103 efw->resp_addr_changable = true;
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900104
105 efw->supported_sampling_rate = 0;
106 if ((hwinfo->min_sample_rate <= 22050)
107 && (22050 <= hwinfo->max_sample_rate))
108 efw->supported_sampling_rate |= SNDRV_PCM_RATE_22050;
109 if ((hwinfo->min_sample_rate <= 32000)
110 && (32000 <= hwinfo->max_sample_rate))
111 efw->supported_sampling_rate |= SNDRV_PCM_RATE_32000;
112 if ((hwinfo->min_sample_rate <= 44100)
113 && (44100 <= hwinfo->max_sample_rate))
114 efw->supported_sampling_rate |= SNDRV_PCM_RATE_44100;
115 if ((hwinfo->min_sample_rate <= 48000)
116 && (48000 <= hwinfo->max_sample_rate))
117 efw->supported_sampling_rate |= SNDRV_PCM_RATE_48000;
118 if ((hwinfo->min_sample_rate <= 88200)
119 && (88200 <= hwinfo->max_sample_rate))
120 efw->supported_sampling_rate |= SNDRV_PCM_RATE_88200;
121 if ((hwinfo->min_sample_rate <= 96000)
122 && (96000 <= hwinfo->max_sample_rate))
123 efw->supported_sampling_rate |= SNDRV_PCM_RATE_96000;
124 if ((hwinfo->min_sample_rate <= 176400)
125 && (176400 <= hwinfo->max_sample_rate))
126 efw->supported_sampling_rate |= SNDRV_PCM_RATE_176400;
127 if ((hwinfo->min_sample_rate <= 192000)
128 && (192000 <= hwinfo->max_sample_rate))
129 efw->supported_sampling_rate |= SNDRV_PCM_RATE_192000;
130
131 /* the number of MIDI ports, not of MIDI conformant data channels */
132 if (hwinfo->midi_out_ports > SND_EFW_MAX_MIDI_OUT_PORTS ||
133 hwinfo->midi_in_ports > SND_EFW_MAX_MIDI_IN_PORTS) {
134 err = -EIO;
135 goto end;
136 }
137 efw->midi_out_ports = hwinfo->midi_out_ports;
138 efw->midi_in_ports = hwinfo->midi_in_ports;
139
Takashi Sakamoto49c7b3f2015-09-19 11:22:01 +0900140 if (hwinfo->amdtp_tx_pcm_channels > AM824_MAX_CHANNELS_FOR_PCM ||
141 hwinfo->amdtp_tx_pcm_channels_2x > AM824_MAX_CHANNELS_FOR_PCM ||
142 hwinfo->amdtp_tx_pcm_channels_4x > AM824_MAX_CHANNELS_FOR_PCM ||
143 hwinfo->amdtp_rx_pcm_channels > AM824_MAX_CHANNELS_FOR_PCM ||
144 hwinfo->amdtp_rx_pcm_channels_2x > AM824_MAX_CHANNELS_FOR_PCM ||
145 hwinfo->amdtp_rx_pcm_channels_4x > AM824_MAX_CHANNELS_FOR_PCM) {
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900146 err = -ENOSYS;
147 goto end;
148 }
149 efw->pcm_capture_channels[0] = hwinfo->amdtp_tx_pcm_channels;
150 efw->pcm_capture_channels[1] = hwinfo->amdtp_tx_pcm_channels_2x;
151 efw->pcm_capture_channels[2] = hwinfo->amdtp_tx_pcm_channels_4x;
152 efw->pcm_playback_channels[0] = hwinfo->amdtp_rx_pcm_channels;
153 efw->pcm_playback_channels[1] = hwinfo->amdtp_rx_pcm_channels_2x;
154 efw->pcm_playback_channels[2] = hwinfo->amdtp_rx_pcm_channels_4x;
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900155
156 /* Hardware metering. */
157 if (hwinfo->phys_in_grp_count > HWINFO_MAX_CAPS_GROUPS ||
158 hwinfo->phys_out_grp_count > HWINFO_MAX_CAPS_GROUPS) {
Dan Carpenter39617832014-05-28 19:42:46 +0300159 err = -EIO;
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900160 goto end;
161 }
162 efw->phys_in = hwinfo->phys_in;
163 efw->phys_out = hwinfo->phys_out;
164 efw->phys_in_grp_count = hwinfo->phys_in_grp_count;
165 efw->phys_out_grp_count = hwinfo->phys_out_grp_count;
166 memcpy(&efw->phys_in_grps, hwinfo->phys_in_grps,
167 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_in_grp_count);
168 memcpy(&efw->phys_out_grps, hwinfo->phys_out_grps,
169 sizeof(struct snd_efw_phys_grp) * hwinfo->phys_out_grp_count);
Takashi Sakamoto0655ac22016-03-27 16:09:08 +0900170
171 /* AudioFire8 (since 2009) and AudioFirePre8 */
172 if (hwinfo->type == MODEL_ECHO_AUDIOFIRE_9)
173 efw->is_af9 = true;
174 /* These models uses the same firmware. */
175 if (hwinfo->type == MODEL_ECHO_AUDIOFIRE_2 ||
176 hwinfo->type == MODEL_ECHO_AUDIOFIRE_4 ||
177 hwinfo->type == MODEL_ECHO_AUDIOFIRE_9 ||
178 hwinfo->type == MODEL_GIBSON_RIP ||
179 hwinfo->type == MODEL_GIBSON_GOLDTOP)
180 efw->is_fireworks3 = true;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900181end:
182 kfree(hwinfo);
183 return err;
184}
185
Takashi Sakamoto3babca42018-10-10 15:35:02 +0900186static void
187efw_card_free(struct snd_card *card)
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900188{
Takashi Sakamoto3babca42018-10-10 15:35:02 +0900189 struct snd_efw *efw = card->private_data;
190
Takashi Sakamoto873608d2018-10-10 15:35:01 +0900191 mutex_lock(&devices_mutex);
192 clear_bit(efw->card_index, devices_used);
193 mutex_unlock(&devices_mutex);
194
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900195 snd_efw_stream_destroy_duplex(efw);
196 snd_efw_transaction_remove_instance(efw);
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900197
198 mutex_destroy(&efw->mutex);
199 fw_unit_put(efw->unit);
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900200}
201
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900202static int efw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900203{
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900204 unsigned int card_index;
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900205 struct snd_card *card;
206 struct snd_efw *efw;
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900207 int err;
208
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900209 // check registered cards.
Takashi Sakamoto873608d2018-10-10 15:35:01 +0900210 mutex_lock(&devices_mutex);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900211 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
212 if (!test_bit(card_index, devices_used) && enable[card_index])
213 break;
214 }
215 if (card_index >= SNDRV_CARDS) {
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900216 mutex_unlock(&devices_mutex);
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900217 return -ENOENT;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900218 }
219
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900220 err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE,
221 sizeof(*efw), &card);
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900222 if (err < 0) {
223 mutex_unlock(&devices_mutex);
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900224 return err;
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900225 }
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900226 card->private_free = efw_card_free;
Takashi Sakamoto873608d2018-10-10 15:35:01 +0900227 set_bit(card_index, devices_used);
228 mutex_unlock(&devices_mutex);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900229
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900230 efw = card->private_data;
231 efw->unit = fw_unit_get(unit);
232 dev_set_drvdata(&unit->device, efw);
233 efw->card = card;
234 efw->card_index = card_index;
Takashi Sakamoto3babca42018-10-10 15:35:02 +0900235
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900236 mutex_init(&efw->mutex);
237 spin_lock_init(&efw->lock);
238 init_waitqueue_head(&efw->hwdep_wait);
239
240 // prepare response buffer.
241 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, SND_EFW_RESPONSE_MAXIMUM_BYTES, 4096U);
242 efw->resp_buf = devm_kzalloc(&card->card_dev, snd_efw_resp_buf_size, GFP_KERNEL);
Takashi Sakamoto784fffb2018-10-03 08:21:52 +0900243 if (!efw->resp_buf) {
Takashi Sakamoto555e8a82014-04-25 22:45:13 +0900244 err = -ENOMEM;
245 goto error;
246 }
247 efw->pull_ptr = efw->push_ptr = efw->resp_buf;
248 snd_efw_transaction_add_instance(efw);
249
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900250 err = get_hardware_info(efw);
251 if (err < 0)
252 goto error;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900253
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900254 err = snd_efw_stream_init_duplex(efw);
255 if (err < 0)
256 goto error;
257
Takashi Sakamoto6a226832014-04-25 22:45:08 +0900258 snd_efw_proc_init(efw);
259
Takashi Sakamotoa63d3ff2014-04-25 22:45:09 +0900260 if (efw->midi_out_ports || efw->midi_in_ports) {
261 err = snd_efw_create_midi_devices(efw);
262 if (err < 0)
263 goto error;
264 }
265
Takashi Sakamotoaa02bb62014-04-25 22:45:11 +0900266 err = snd_efw_create_pcm_devices(efw);
267 if (err < 0)
268 goto error;
269
Takashi Sakamoto594ddce2014-04-25 22:45:12 +0900270 err = snd_efw_create_hwdep_device(efw);
271 if (err < 0)
272 goto error;
273
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900274 err = snd_card_register(card);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900275 if (err < 0)
276 goto error;
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900277
Takashi Sakamoto7d3c1d52016-03-31 08:47:06 +0900278 return 0;
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900279error:
280 snd_card_free(card);
281 return err;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900282}
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 Sakamoto99d73552016-02-20 16:41:01 +0900289
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900290 mutex_lock(&efw->mutex);
291 snd_efw_stream_update_duplex(efw);
292 mutex_unlock(&efw->mutex);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900293}
294
295static void efw_remove(struct fw_unit *unit)
296{
297 struct snd_efw *efw = dev_get_drvdata(&unit->device);
Takashi Sakamoto315fd412014-04-25 22:45:02 +0900298
Takashi Sakamotod42dca62021-06-07 17:12:43 +0900299 // Block till all of ALSA character devices are released.
300 snd_card_free(efw->card);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900301}
302
Takashi Sakamoto2e6a5892021-06-11 18:37:26 +0900303#define SPECIFIER_1394TA 0x00a02d
304#define VERSION_EFW 0x010000
305
306#define SND_EFW_DEV_ENTRY(vendor, model) \
307{ \
308 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
309 IEEE1394_MATCH_MODEL_ID | \
310 IEEE1394_MATCH_SPECIFIER_ID | \
311 IEEE1394_MATCH_VERSION, \
312 .vendor_id = vendor,\
313 .model_id = model, \
314 .specifier_id = SPECIFIER_1394TA, \
315 .version = VERSION_EFW, \
316}
317
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900318static const struct ieee1394_device_id efw_id_table[] = {
319 SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_400F),
320 SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_1200F),
321 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_8),
322 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12),
323 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12HD),
324 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12_APPLE),
325 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_2),
326 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_4),
327 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_9),
328 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_8),
329 SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_HDMI),
330 SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_RIP),
331 SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_GOLDTOP),
332 {}
333};
334MODULE_DEVICE_TABLE(ieee1394, efw_id_table);
335
336static struct fw_driver efw_driver = {
337 .driver = {
338 .owner = THIS_MODULE,
Takashi Sakamoto9c0d16a2020-03-06 22:52:29 +0900339 .name = KBUILD_MODNAME,
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900340 .bus = &fw_bus_type,
341 },
342 .probe = efw_probe,
343 .update = efw_update,
344 .remove = efw_remove,
345 .id_table = efw_id_table,
346};
347
348static int __init snd_efw_init(void)
349{
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900350 int err;
351
352 err = snd_efw_transaction_register();
353 if (err < 0)
354 goto end;
355
356 err = driver_register(&efw_driver.driver);
357 if (err < 0)
358 snd_efw_transaction_unregister();
359
360end:
361 return err;
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900362}
363
364static void __exit snd_efw_exit(void)
365{
Takashi Sakamotobde8a8f2014-04-25 22:45:01 +0900366 snd_efw_transaction_unregister();
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900367 driver_unregister(&efw_driver.driver);
Takashi Sakamotob5b04332014-04-25 22:45:00 +0900368}
369
370module_init(snd_efw_init);
371module_exit(snd_efw_exit);