mfd: wm831x: Remove redundant !pdata checks
[linux/fpc-iii.git] / sound / firewire / digi00x / digi00x.c
blob1f5e1d23f31a7132a5dfb5f3f34468b1517a89d0
1 /*
2 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
4 * Copyright (c) 2014-2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
9 #include "digi00x.h"
11 MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
12 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13 MODULE_LICENSE("GPL v2");
15 #define VENDOR_DIGIDESIGN 0x00a07e
16 #define MODEL_CONSOLE 0x000001
17 #define MODEL_RACK 0x000002
19 static int name_card(struct snd_dg00x *dg00x)
21 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
22 char name[32] = {0};
23 char *model;
24 int err;
26 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
27 sizeof(name));
28 if (err < 0)
29 return err;
31 model = skip_spaces(name);
33 strcpy(dg00x->card->driver, "Digi00x");
34 strcpy(dg00x->card->shortname, model);
35 strcpy(dg00x->card->mixername, model);
36 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
37 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
38 fw_dev->config_rom[3], fw_dev->config_rom[4],
39 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
41 return 0;
44 static void dg00x_free(struct snd_dg00x *dg00x)
46 snd_dg00x_stream_destroy_duplex(dg00x);
47 snd_dg00x_transaction_unregister(dg00x);
49 fw_unit_put(dg00x->unit);
51 mutex_destroy(&dg00x->mutex);
54 static void dg00x_card_free(struct snd_card *card)
56 dg00x_free(card->private_data);
59 static void do_registration(struct work_struct *work)
61 struct snd_dg00x *dg00x =
62 container_of(work, struct snd_dg00x, dwork.work);
63 int err;
65 if (dg00x->registered)
66 return;
68 err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0,
69 &dg00x->card);
70 if (err < 0)
71 return;
73 err = name_card(dg00x);
74 if (err < 0)
75 goto error;
77 err = snd_dg00x_stream_init_duplex(dg00x);
78 if (err < 0)
79 goto error;
81 snd_dg00x_proc_init(dg00x);
83 err = snd_dg00x_create_pcm_devices(dg00x);
84 if (err < 0)
85 goto error;
87 err = snd_dg00x_create_midi_devices(dg00x);
88 if (err < 0)
89 goto error;
91 err = snd_dg00x_create_hwdep_device(dg00x);
92 if (err < 0)
93 goto error;
95 err = snd_dg00x_transaction_register(dg00x);
96 if (err < 0)
97 goto error;
99 err = snd_card_register(dg00x->card);
100 if (err < 0)
101 goto error;
103 dg00x->card->private_free = dg00x_card_free;
104 dg00x->card->private_data = dg00x;
105 dg00x->registered = true;
107 return;
108 error:
109 snd_dg00x_transaction_unregister(dg00x);
110 snd_dg00x_stream_destroy_duplex(dg00x);
111 snd_card_free(dg00x->card);
112 dev_info(&dg00x->unit->device,
113 "Sound card registration failed: %d\n", err);
116 static int snd_dg00x_probe(struct fw_unit *unit,
117 const struct ieee1394_device_id *entry)
119 struct snd_dg00x *dg00x;
121 /* Allocate this independent of sound card instance. */
122 dg00x = kzalloc(sizeof(struct snd_dg00x), GFP_KERNEL);
123 if (dg00x == NULL)
124 return -ENOMEM;
126 dg00x->unit = fw_unit_get(unit);
127 dev_set_drvdata(&unit->device, dg00x);
129 mutex_init(&dg00x->mutex);
130 spin_lock_init(&dg00x->lock);
131 init_waitqueue_head(&dg00x->hwdep_wait);
133 dg00x->is_console = entry->model_id == MODEL_CONSOLE;
135 /* Allocate and register this sound card later. */
136 INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration);
137 snd_fw_schedule_registration(unit, &dg00x->dwork);
139 return 0;
142 static void snd_dg00x_update(struct fw_unit *unit)
144 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
146 /* Postpone a workqueue for deferred registration. */
147 if (!dg00x->registered)
148 snd_fw_schedule_registration(unit, &dg00x->dwork);
150 snd_dg00x_transaction_reregister(dg00x);
153 * After registration, userspace can start packet streaming, then this
154 * code block works fine.
156 if (dg00x->registered) {
157 mutex_lock(&dg00x->mutex);
158 snd_dg00x_stream_update_duplex(dg00x);
159 mutex_unlock(&dg00x->mutex);
163 static void snd_dg00x_remove(struct fw_unit *unit)
165 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
168 * Confirm to stop the work for registration before the sound card is
169 * going to be released. The work is not scheduled again because bus
170 * reset handler is not called anymore.
172 cancel_delayed_work_sync(&dg00x->dwork);
174 if (dg00x->registered) {
175 /* No need to wait for releasing card object in this context. */
176 snd_card_free_when_closed(dg00x->card);
177 } else {
178 /* Don't forget this case. */
179 dg00x_free(dg00x);
183 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
184 /* Both of 002/003 use the same ID. */
186 .match_flags = IEEE1394_MATCH_VENDOR_ID |
187 IEEE1394_MATCH_MODEL_ID,
188 .vendor_id = VENDOR_DIGIDESIGN,
189 .model_id = MODEL_CONSOLE,
192 .match_flags = IEEE1394_MATCH_VENDOR_ID |
193 IEEE1394_MATCH_MODEL_ID,
194 .vendor_id = VENDOR_DIGIDESIGN,
195 .model_id = MODEL_RACK,
199 MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
201 static struct fw_driver dg00x_driver = {
202 .driver = {
203 .owner = THIS_MODULE,
204 .name = "snd-firewire-digi00x",
205 .bus = &fw_bus_type,
207 .probe = snd_dg00x_probe,
208 .update = snd_dg00x_update,
209 .remove = snd_dg00x_remove,
210 .id_table = snd_dg00x_id_table,
213 static int __init snd_dg00x_init(void)
215 return driver_register(&dg00x_driver.driver);
218 static void __exit snd_dg00x_exit(void)
220 driver_unregister(&dg00x_driver.driver);
223 module_init(snd_dg00x_init);
224 module_exit(snd_dg00x_exit);