sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / sound / firewire / digi00x / digi00x.c
blobcc4776c6ded313673ef1c767101f2ed7e0c4369f
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_DIGI00X 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_free(struct snd_dg00x *dg00x)
45 snd_dg00x_stream_destroy_duplex(dg00x);
46 snd_dg00x_transaction_unregister(dg00x);
48 fw_unit_put(dg00x->unit);
50 mutex_destroy(&dg00x->mutex);
53 static void dg00x_card_free(struct snd_card *card)
55 dg00x_free(card->private_data);
58 static void do_registration(struct work_struct *work)
60 struct snd_dg00x *dg00x =
61 container_of(work, struct snd_dg00x, dwork.work);
62 int err;
64 if (dg00x->registered)
65 return;
67 err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0,
68 &dg00x->card);
69 if (err < 0)
70 return;
72 err = name_card(dg00x);
73 if (err < 0)
74 goto error;
76 err = snd_dg00x_stream_init_duplex(dg00x);
77 if (err < 0)
78 goto error;
80 snd_dg00x_proc_init(dg00x);
82 err = snd_dg00x_create_pcm_devices(dg00x);
83 if (err < 0)
84 goto error;
86 err = snd_dg00x_create_midi_devices(dg00x);
87 if (err < 0)
88 goto error;
90 err = snd_dg00x_create_hwdep_device(dg00x);
91 if (err < 0)
92 goto error;
94 err = snd_dg00x_transaction_register(dg00x);
95 if (err < 0)
96 goto error;
98 err = snd_card_register(dg00x->card);
99 if (err < 0)
100 goto error;
102 dg00x->card->private_free = dg00x_card_free;
103 dg00x->card->private_data = dg00x;
104 dg00x->registered = true;
106 return;
107 error:
108 snd_dg00x_transaction_unregister(dg00x);
109 snd_dg00x_stream_destroy_duplex(dg00x);
110 snd_card_free(dg00x->card);
111 dev_info(&dg00x->unit->device,
112 "Sound card registration failed: %d\n", err);
115 static int snd_dg00x_probe(struct fw_unit *unit,
116 const struct ieee1394_device_id *entry)
118 struct snd_dg00x *dg00x;
120 /* Allocate this independent of sound card instance. */
121 dg00x = kzalloc(sizeof(struct snd_dg00x), GFP_KERNEL);
122 if (dg00x == NULL)
123 return -ENOMEM;
125 dg00x->unit = fw_unit_get(unit);
126 dev_set_drvdata(&unit->device, dg00x);
128 mutex_init(&dg00x->mutex);
129 spin_lock_init(&dg00x->lock);
130 init_waitqueue_head(&dg00x->hwdep_wait);
132 /* Allocate and register this sound card later. */
133 INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration);
134 snd_fw_schedule_registration(unit, &dg00x->dwork);
136 return 0;
139 static void snd_dg00x_update(struct fw_unit *unit)
141 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
143 /* Postpone a workqueue for deferred registration. */
144 if (!dg00x->registered)
145 snd_fw_schedule_registration(unit, &dg00x->dwork);
147 snd_dg00x_transaction_reregister(dg00x);
150 * After registration, userspace can start packet streaming, then this
151 * code block works fine.
153 if (dg00x->registered) {
154 mutex_lock(&dg00x->mutex);
155 snd_dg00x_stream_update_duplex(dg00x);
156 mutex_unlock(&dg00x->mutex);
160 static void snd_dg00x_remove(struct fw_unit *unit)
162 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
165 * Confirm to stop the work for registration before the sound card is
166 * going to be released. The work is not scheduled again because bus
167 * reset handler is not called anymore.
169 cancel_delayed_work_sync(&dg00x->dwork);
171 if (dg00x->registered) {
172 /* No need to wait for releasing card object in this context. */
173 snd_card_free_when_closed(dg00x->card);
174 } else {
175 /* Don't forget this case. */
176 dg00x_free(dg00x);
180 static const struct ieee1394_device_id snd_dg00x_id_table[] = {
181 /* Both of 002/003 use the same ID. */
183 .match_flags = IEEE1394_MATCH_VENDOR_ID |
184 IEEE1394_MATCH_MODEL_ID,
185 .vendor_id = VENDOR_DIGIDESIGN,
186 .model_id = MODEL_DIGI00X,
190 MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
192 static struct fw_driver dg00x_driver = {
193 .driver = {
194 .owner = THIS_MODULE,
195 .name = "snd-firewire-digi00x",
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);