treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 345
[linux-2.6-block.git] / sound / firewire / fireface / ff.c
CommitLineData
da607e19 1// SPDX-License-Identifier: GPL-2.0-only
17c4e5ea
TS
2/*
3 * ff.c - a part of driver for RME Fireface series
4 *
5 * Copyright (c) 2015-2017 Takashi Sakamoto
17c4e5ea
TS
6 */
7
8#include "ff.h"
9
10#define OUI_RME 0x000a35
11
12MODULE_DESCRIPTION("RME Fireface series Driver");
13MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
14MODULE_LICENSE("GPL v2");
15
16static void name_card(struct snd_ff *ff)
17{
18 struct fw_device *fw_dev = fw_parent_device(ff->unit);
17c4e5ea
TS
19
20 strcpy(ff->card->driver, "Fireface");
ed90f91a
TS
21 strcpy(ff->card->shortname, ff->spec->name);
22 strcpy(ff->card->mixername, ff->spec->name);
17c4e5ea 23 snprintf(ff->card->longname, sizeof(ff->card->longname),
ed90f91a 24 "RME %s, GUID %08x%08x at %s, S%d", ff->spec->name,
17c4e5ea
TS
25 fw_dev->config_rom[3], fw_dev->config_rom[4],
26 dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
27}
28
3babca45 29static void ff_card_free(struct snd_card *card)
17c4e5ea 30{
3babca45
TS
31 struct snd_ff *ff = card->private_data;
32
fc716397 33 snd_ff_stream_destroy_duplex(ff);
73f5537f 34 snd_ff_transaction_unregister(ff);
324540c4
TS
35}
36
324540c4
TS
37static void do_registration(struct work_struct *work)
38{
39 struct snd_ff *ff = container_of(work, struct snd_ff, dwork.work);
40 int err;
41
42 if (ff->registered)
43 return;
44
45 err = snd_card_new(&ff->unit->device, -1, NULL, THIS_MODULE, 0,
46 &ff->card);
47 if (err < 0)
48 return;
3babca45
TS
49 ff->card->private_free = ff_card_free;
50 ff->card->private_data = ff;
324540c4 51
73f5537f
TS
52 err = snd_ff_transaction_register(ff);
53 if (err < 0)
54 goto error;
19174295 55
324540c4
TS
56 name_card(ff);
57
fc716397
TS
58 err = snd_ff_stream_init_duplex(ff);
59 if (err < 0)
60 goto error;
75d6d898 61
d3fc7aac
TS
62 snd_ff_proc_init(ff);
63
73f5537f
TS
64 err = snd_ff_create_midi_devices(ff);
65 if (err < 0)
66 goto error;
ff2c293e 67
fc716397
TS
68 err = snd_ff_create_pcm_devices(ff);
69 if (err < 0)
70 goto error;
4b316436 71
fc716397
TS
72 err = snd_ff_create_hwdep_devices(ff);
73 if (err < 0)
74 goto error;
f656edd5 75
324540c4
TS
76 err = snd_card_register(ff->card);
77 if (err < 0)
78 goto error;
79
324540c4
TS
80 ff->registered = true;
81
82 return;
83error:
84 snd_card_free(ff->card);
85 dev_info(&ff->unit->device,
86 "Sound card registration failed: %d\n", err);
17c4e5ea
TS
87}
88
89static int snd_ff_probe(struct fw_unit *unit,
90 const struct ieee1394_device_id *entry)
91{
17c4e5ea 92 struct snd_ff *ff;
17c4e5ea 93
366a20d7
TS
94 ff = devm_kzalloc(&unit->device, sizeof(struct snd_ff), GFP_KERNEL);
95 if (!ff)
324540c4 96 return -ENOMEM;
17c4e5ea
TS
97 ff->unit = fw_unit_get(unit);
98 dev_set_drvdata(&unit->device, ff);
99
100 mutex_init(&ff->mutex);
ff2c293e 101 spin_lock_init(&ff->lock);
f656edd5 102 init_waitqueue_head(&ff->hwdep_wait);
17c4e5ea 103
ed90f91a
TS
104 ff->spec = (const struct snd_ff_spec *)entry->driver_data;
105
324540c4
TS
106 /* Register this sound card later. */
107 INIT_DEFERRABLE_WORK(&ff->dwork, do_registration);
108 snd_fw_schedule_registration(unit, &ff->dwork);
17c4e5ea
TS
109
110 return 0;
111}
112
113static void snd_ff_update(struct fw_unit *unit)
114{
324540c4
TS
115 struct snd_ff *ff = dev_get_drvdata(&unit->device);
116
117 /* Postpone a workqueue for deferred registration. */
118 if (!ff->registered)
119 snd_fw_schedule_registration(unit, &ff->dwork);
19174295 120
73f5537f 121 snd_ff_transaction_reregister(ff);
75d6d898 122
fc716397 123 if (ff->registered)
75d6d898 124 snd_ff_stream_update_duplex(ff);
17c4e5ea
TS
125}
126
127static void snd_ff_remove(struct fw_unit *unit)
128{
129 struct snd_ff *ff = dev_get_drvdata(&unit->device);
130
324540c4
TS
131 /*
132 * Confirm to stop the work for registration before the sound card is
133 * going to be released. The work is not scheduled again because bus
134 * reset handler is not called anymore.
135 */
136 cancel_work_sync(&ff->dwork.work);
137
138 if (ff->registered) {
61ccc6f6
TS
139 // Block till all of ALSA character devices are released.
140 snd_card_free(ff->card);
324540c4 141 }
5b14ec25
TS
142
143 mutex_destroy(&ff->mutex);
144 fw_unit_put(ff->unit);
17c4e5ea
TS
145}
146
a91f6760
TS
147static const struct snd_ff_spec spec_ff800 = {
148 .name = "Fireface800",
fc716397
TS
149 .pcm_capture_channels = {28, 20, 12},
150 .pcm_playback_channels = {28, 20, 12},
a91f6760
TS
151 .midi_in_ports = 1,
152 .midi_out_ports = 1,
153 .protocol = &snd_ff_protocol_ff800,
6d1ef1bb 154 .midi_high_addr = 0x000200000320ull,
90089677 155 .midi_addr_range = 12,
481e09ac 156 .midi_rx_addrs = {0x000080180000ull, 0},
a91f6760
TS
157};
158
782fbec7 159static const struct snd_ff_spec spec_ff400 = {
76fdb3a9
TS
160 .name = "Fireface400",
161 .pcm_capture_channels = {18, 14, 10},
162 .pcm_playback_channels = {18, 14, 10},
163 .midi_in_ports = 2,
164 .midi_out_ports = 2,
165 .protocol = &snd_ff_protocol_ff400,
6d1ef1bb 166 .midi_high_addr = 0x0000801003f4ull,
90089677 167 .midi_addr_range = SND_FF_MAXIMIM_MIDI_QUADS * 4,
481e09ac 168 .midi_rx_addrs = {0x000080180000ull, 0x000080190000ull},
76fdb3a9
TS
169};
170
fd1cc9de
TS
171static const struct snd_ff_spec spec_ucx = {
172 .name = "FirefaceUCX",
173 .pcm_capture_channels = {18, 14, 12},
174 .pcm_playback_channels = {18, 14, 12},
73f5537f 175 .midi_in_ports = 2,
f0f9f497 176 .midi_out_ports = 2,
fd1cc9de 177 .protocol = &snd_ff_protocol_latter,
73f5537f
TS
178 .midi_high_addr = 0xffff00000034ull,
179 .midi_addr_range = 0x80,
481e09ac 180 .midi_rx_addrs = {0xffff00000030ull, 0xffff00000030ull},
fd1cc9de
TS
181};
182
17c4e5ea 183static const struct ieee1394_device_id snd_ff_id_table[] = {
a91f6760
TS
184 /* Fireface 800 */
185 {
186 .match_flags = IEEE1394_MATCH_VENDOR_ID |
187 IEEE1394_MATCH_SPECIFIER_ID |
188 IEEE1394_MATCH_VERSION |
189 IEEE1394_MATCH_MODEL_ID,
190 .vendor_id = OUI_RME,
191 .specifier_id = OUI_RME,
192 .version = 0x000001,
193 .model_id = 0x101800,
194 .driver_data = (kernel_ulong_t)&spec_ff800,
195 },
76fdb3a9
TS
196 /* Fireface 400 */
197 {
198 .match_flags = IEEE1394_MATCH_VENDOR_ID |
199 IEEE1394_MATCH_SPECIFIER_ID |
200 IEEE1394_MATCH_VERSION |
201 IEEE1394_MATCH_MODEL_ID,
202 .vendor_id = OUI_RME,
a91f6760 203 .specifier_id = OUI_RME,
76fdb3a9
TS
204 .version = 0x000002,
205 .model_id = 0x101800,
206 .driver_data = (kernel_ulong_t)&spec_ff400,
207 },
fd1cc9de
TS
208 // Fireface UCX.
209 {
210 .match_flags = IEEE1394_MATCH_VENDOR_ID |
211 IEEE1394_MATCH_SPECIFIER_ID |
212 IEEE1394_MATCH_VERSION |
213 IEEE1394_MATCH_MODEL_ID,
214 .vendor_id = OUI_RME,
215 .specifier_id = OUI_RME,
216 .version = 0x000004,
217 .model_id = 0x101800,
218 .driver_data = (kernel_ulong_t)&spec_ucx,
219 },
17c4e5ea
TS
220 {}
221};
222MODULE_DEVICE_TABLE(ieee1394, snd_ff_id_table);
223
224static struct fw_driver ff_driver = {
225 .driver = {
226 .owner = THIS_MODULE,
227 .name = "snd-fireface",
228 .bus = &fw_bus_type,
229 },
230 .probe = snd_ff_probe,
231 .update = snd_ff_update,
232 .remove = snd_ff_remove,
233 .id_table = snd_ff_id_table,
234};
235
236static int __init snd_ff_init(void)
237{
238 return driver_register(&ff_driver.driver);
239}
240
241static void __exit snd_ff_exit(void)
242{
243 driver_unregister(&ff_driver.driver);
244}
245
246module_init(snd_ff_init);
247module_exit(snd_ff_exit);