spi: spi-fsl-qspi: Fix return value check of devm_ioremap() in probe
[linux/fpc-iii.git] / sound / firewire / digi00x / digi00x.c
blobc84b913a9fe010d391740c14013ed743fcf584df
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
5 * Copyright (c) 2014-2015 Takashi Sakamoto
6 */
8 #include "digi00x.h"
10 MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
11 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
12 MODULE_LICENSE("GPL v2");
14 #define VENDOR_DIGIDESIGN 0x00a07e
15 #define MODEL_CONSOLE 0x000001
16 #define MODEL_RACK 0x000002
18 static int name_card(struct snd_dg00x *dg00x)
20 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
21 char name[32] = {0};
22 char *model;
23 int err;
25 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
26 sizeof(name));
27 if (err < 0)
28 return err;
30 model = skip_spaces(name);
32 strcpy(dg00x->card->driver, "Digi00x");
33 strcpy(dg00x->card->shortname, model);
34 strcpy(dg00x->card->mixername, model);
35 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
36 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
37 fw_dev->config_rom[3], fw_dev->config_rom[4],
38 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
40 return 0;
43 static void dg00x_card_free(struct snd_card *card)
45 struct snd_dg00x *dg00x = card->private_data;
47 snd_dg00x_stream_destroy_duplex(dg00x);
48 snd_dg00x_transaction_unregister(dg00x);
51 static void do_registration(struct work_struct *work)
53 struct snd_dg00x *dg00x =
54 container_of(work, struct snd_dg00x, dwork.work);
55 int err;
57 if (dg00x->registered)
58 return;
60 err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0,
61 &dg00x->card);
62 if (err < 0)
63 return;
64 dg00x->card->private_free = dg00x_card_free;
65 dg00x->card->private_data = dg00x;
67 err = name_card(dg00x);
68 if (err < 0)
69 goto error;
71 err = snd_dg00x_stream_init_duplex(dg00x);
72 if (err < 0)
73 goto error;
75 snd_dg00x_proc_init(dg00x);
77 err = snd_dg00x_create_pcm_devices(dg00x);
78 if (err < 0)
79 goto error;
81 err = snd_dg00x_create_midi_devices(dg00x);
82 if (err < 0)
83 goto error;
85 err = snd_dg00x_create_hwdep_device(dg00x);
86 if (err < 0)
87 goto error;
89 err = snd_dg00x_transaction_register(dg00x);
90 if (err < 0)
91 goto error;
93 err = snd_card_register(dg00x->card);
94 if (err < 0)
95 goto error;
97 dg00x->registered = true;
99 return;
100 error:
101 snd_card_free(dg00x->card);
102 dev_info(&dg00x->unit->device,
103 "Sound card registration failed: %d\n", err);
106 static int snd_dg00x_probe(struct fw_unit *unit,
107 const struct ieee1394_device_id *entry)
109 struct snd_dg00x *dg00x;
111 /* Allocate this independent of sound card instance. */
112 dg00x = devm_kzalloc(&unit->device, sizeof(struct snd_dg00x),
113 GFP_KERNEL);
114 if (!dg00x)
115 return -ENOMEM;
117 dg00x->unit = fw_unit_get(unit);
118 dev_set_drvdata(&unit->device, dg00x);
120 mutex_init(&dg00x->mutex);
121 spin_lock_init(&dg00x->lock);
122 init_waitqueue_head(&dg00x->hwdep_wait);
124 dg00x->is_console = entry->model_id == MODEL_CONSOLE;
126 /* Allocate and register this sound card later. */
127 INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration);
128 snd_fw_schedule_registration(unit, &dg00x->dwork);
130 return 0;
133 static void snd_dg00x_update(struct fw_unit *unit)
135 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
137 /* Postpone a workqueue for deferred registration. */
138 if (!dg00x->registered)
139 snd_fw_schedule_registration(unit, &dg00x->dwork);
141 snd_dg00x_transaction_reregister(dg00x);
144 * After registration, userspace can start packet streaming, then this
145 * code block works fine.
147 if (dg00x->registered) {
148 mutex_lock(&dg00x->mutex);
149 snd_dg00x_stream_update_duplex(dg00x);
150 mutex_unlock(&dg00x->mutex);
154 static void snd_dg00x_remove(struct fw_unit *unit)
156 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
159 * Confirm to stop the work for registration before the sound card is
160 * going to be released. The work is not scheduled again because bus
161 * reset handler is not called anymore.
163 cancel_delayed_work_sync(&dg00x->dwork);
165 if (dg00x->registered) {
166 // Block till all of ALSA character devices are released.
167 snd_card_free(dg00x->card);
170 mutex_destroy(&dg00x->mutex);
171 fw_unit_put(dg00x->unit);
174 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
175 /* Both of 002/003 use the same ID. */
177 .match_flags = IEEE1394_MATCH_VENDOR_ID |
178 IEEE1394_MATCH_MODEL_ID,
179 .vendor_id = VENDOR_DIGIDESIGN,
180 .model_id = MODEL_CONSOLE,
183 .match_flags = IEEE1394_MATCH_VENDOR_ID |
184 IEEE1394_MATCH_MODEL_ID,
185 .vendor_id = VENDOR_DIGIDESIGN,
186 .model_id = MODEL_RACK,
190 MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
192 static struct fw_driver dg00x_driver = {
193 .driver = {
194 .owner = THIS_MODULE,
195 .name = KBUILD_MODNAME,
196 .bus = &fw_bus_type,
198 .probe = snd_dg00x_probe,
199 .update = snd_dg00x_update,
200 .remove = snd_dg00x_remove,
201 .id_table = snd_dg00x_id_table,
204 static int __init snd_dg00x_init(void)
206 return driver_register(&dg00x_driver.driver);
209 static void __exit snd_dg00x_exit(void)
211 driver_unregister(&dg00x_driver.driver);
214 module_init(snd_dg00x_init);
215 module_exit(snd_dg00x_exit);