]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - rpmsg/rpmsg.git/blob - sound/firewire/tascam/tascam.c
Merge tag 'alloc-args-v4.19-rc8' of https://git.kernel.org/pub/scm/linux/kernel/git...
[rpmsg/rpmsg.git] / sound / firewire / tascam / tascam.c
1 /*
2  * tascam.c - a part of driver for TASCAM FireWire series
3  *
4  * Copyright (c) 2015 Takashi Sakamoto
5  *
6  * Licensed under the terms of the GNU General Public License, version 2.
7  */
9 #include "tascam.h"
11 MODULE_DESCRIPTION("TASCAM FireWire series Driver");
12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13 MODULE_LICENSE("GPL v2");
15 static const struct snd_tscm_spec model_specs[] = {
16         {
17                 .name = "FW-1884",
18                 .has_adat = true,
19                 .has_spdif = true,
20                 .pcm_capture_analog_channels = 8,
21                 .pcm_playback_analog_channels = 8,
22                 .midi_capture_ports = 4,
23                 .midi_playback_ports = 4,
24         },
25         {
26                 .name = "FW-1082",
27                 .has_adat = false,
28                 .has_spdif = true,
29                 .pcm_capture_analog_channels = 8,
30                 .pcm_playback_analog_channels = 2,
31                 .midi_capture_ports = 2,
32                 .midi_playback_ports = 2,
33         },
34         {
35                 .name = "FW-1804",
36                 .has_adat = true,
37                 .has_spdif = true,
38                 .pcm_capture_analog_channels = 8,
39                 .pcm_playback_analog_channels = 2,
40                 .midi_capture_ports = 2,
41                 .midi_playback_ports = 4,
42         },
43 };
45 static int identify_model(struct snd_tscm *tscm)
46 {
47         struct fw_device *fw_dev = fw_parent_device(tscm->unit);
48         const u32 *config_rom = fw_dev->config_rom;
49         char model[9];
50         unsigned int i;
51         u8 c;
53         if (fw_dev->config_rom_length < 30) {
54                 dev_err(&tscm->unit->device,
55                         "Configuration ROM is too short.\n");
56                 return -ENODEV;
57         }
59         /* Pick up model name from certain addresses. */
60         for (i = 0; i < 8; i++) {
61                 c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4));
62                 if (c == '\0')
63                         break;
64                 model[i] = c;
65         }
66         model[i] = '\0';
68         for (i = 0; i < ARRAY_SIZE(model_specs); i++) {
69                 if (strcmp(model, model_specs[i].name) == 0) {
70                         tscm->spec = &model_specs[i];
71                         break;
72                 }
73         }
74         if (tscm->spec == NULL)
75                 return -ENODEV;
77         strcpy(tscm->card->driver, "FW-TASCAM");
78         strcpy(tscm->card->shortname, model);
79         strcpy(tscm->card->mixername, model);
80         snprintf(tscm->card->longname, sizeof(tscm->card->longname),
81                  "TASCAM %s, GUID %08x%08x at %s, S%d", model,
82                  fw_dev->config_rom[3], fw_dev->config_rom[4],
83                  dev_name(&tscm->unit->device), 100 << fw_dev->max_speed);
85         return 0;
86 }
88 static void tscm_free(struct snd_tscm *tscm)
89 {
90         snd_tscm_transaction_unregister(tscm);
91         snd_tscm_stream_destroy_duplex(tscm);
93         fw_unit_put(tscm->unit);
95         mutex_destroy(&tscm->mutex);
96         kfree(tscm);
97 }
99 static void tscm_card_free(struct snd_card *card)
101         tscm_free(card->private_data);
104 static void do_registration(struct work_struct *work)
106         struct snd_tscm *tscm = container_of(work, struct snd_tscm, dwork.work);
107         int err;
109         err = snd_card_new(&tscm->unit->device, -1, NULL, THIS_MODULE, 0,
110                            &tscm->card);
111         if (err < 0)
112                 return;
114         err = identify_model(tscm);
115         if (err < 0)
116                 goto error;
118         err = snd_tscm_transaction_register(tscm);
119         if (err < 0)
120                 goto error;
122         err = snd_tscm_stream_init_duplex(tscm);
123         if (err < 0)
124                 goto error;
126         snd_tscm_proc_init(tscm);
128         err = snd_tscm_create_pcm_devices(tscm);
129         if (err < 0)
130                 goto error;
132         err = snd_tscm_create_midi_devices(tscm);
133         if (err < 0)
134                 goto error;
136         err = snd_tscm_create_hwdep_device(tscm);
137         if (err < 0)
138                 goto error;
140         err = snd_card_register(tscm->card);
141         if (err < 0)
142                 goto error;
144         /*
145          * After registered, tscm instance can be released corresponding to
146          * releasing the sound card instance.
147          */
148         tscm->card->private_free = tscm_card_free;
149         tscm->card->private_data = tscm;
150         tscm->registered = true;
152         return;
153 error:
154         snd_tscm_transaction_unregister(tscm);
155         snd_tscm_stream_destroy_duplex(tscm);
156         snd_card_free(tscm->card);
157         dev_info(&tscm->unit->device,
158                  "Sound card registration failed: %d\n", err);
161 static int snd_tscm_probe(struct fw_unit *unit,
162                            const struct ieee1394_device_id *entry)
164         struct snd_tscm *tscm;
166         /* Allocate this independent of sound card instance. */
167         tscm = kzalloc(sizeof(struct snd_tscm), GFP_KERNEL);
168         if (tscm == NULL)
169                 return -ENOMEM;
171         /* initialize myself */
172         tscm->unit = fw_unit_get(unit);
173         dev_set_drvdata(&unit->device, tscm);
175         mutex_init(&tscm->mutex);
176         spin_lock_init(&tscm->lock);
177         init_waitqueue_head(&tscm->hwdep_wait);
179         /* Allocate and register this sound card later. */
180         INIT_DEFERRABLE_WORK(&tscm->dwork, do_registration);
181         snd_fw_schedule_registration(unit, &tscm->dwork);
183         return 0;
186 static void snd_tscm_update(struct fw_unit *unit)
188         struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
190         /* Postpone a workqueue for deferred registration. */
191         if (!tscm->registered)
192                 snd_fw_schedule_registration(unit, &tscm->dwork);
194         snd_tscm_transaction_reregister(tscm);
196         /*
197          * After registration, userspace can start packet streaming, then this
198          * code block works fine.
199          */
200         if (tscm->registered) {
201                 mutex_lock(&tscm->mutex);
202                 snd_tscm_stream_update_duplex(tscm);
203                 mutex_unlock(&tscm->mutex);
204         }
207 static void snd_tscm_remove(struct fw_unit *unit)
209         struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
211         /*
212          * Confirm to stop the work for registration before the sound card is
213          * going to be released. The work is not scheduled again because bus
214          * reset handler is not called anymore.
215          */
216         cancel_delayed_work_sync(&tscm->dwork);
218         if (tscm->registered) {
219                 /* No need to wait for releasing card object in this context. */
220                 snd_card_free_when_closed(tscm->card);
221         } else {
222                 /* Don't forget this case. */
223                 tscm_free(tscm);
224         }
227 static const struct ieee1394_device_id snd_tscm_id_table[] = {
228         {
229                 .match_flags = IEEE1394_MATCH_VENDOR_ID |
230                                IEEE1394_MATCH_SPECIFIER_ID,
231                 .vendor_id = 0x00022e,
232                 .specifier_id = 0x00022e,
233         },
234         /* FE-08 requires reverse-engineering because it just has faders. */
235         {}
236 };
237 MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table);
239 static struct fw_driver tscm_driver = {
240         .driver = {
241                 .owner = THIS_MODULE,
242                 .name = "snd-firewire-tascam",
243                 .bus = &fw_bus_type,
244         },
245         .probe    = snd_tscm_probe,
246         .update   = snd_tscm_update,
247         .remove   = snd_tscm_remove,
248         .id_table = snd_tscm_id_table,
249 };
251 static int __init snd_tscm_init(void)
253         return driver_register(&tscm_driver.driver);
256 static void __exit snd_tscm_exit(void)
258         driver_unregister(&tscm_driver.driver);
261 module_init(snd_tscm_init);
262 module_exit(snd_tscm_exit);