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.
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
);
26 err
= fw_csr_string(dg00x
->unit
->directory
, CSR_MODEL
, name
,
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
);
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
);
55 static void dg00x_card_free(struct snd_card
*card
)
57 dg00x_free(card
->private_data
);
60 static void do_registration(struct work_struct
*work
)
62 struct snd_dg00x
*dg00x
=
63 container_of(work
, struct snd_dg00x
, dwork
.work
);
66 if (dg00x
->registered
)
69 err
= snd_card_new(&dg00x
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
74 err
= name_card(dg00x
);
78 err
= snd_dg00x_stream_init_duplex(dg00x
);
82 snd_dg00x_proc_init(dg00x
);
84 err
= snd_dg00x_create_pcm_devices(dg00x
);
88 err
= snd_dg00x_create_midi_devices(dg00x
);
92 err
= snd_dg00x_create_hwdep_device(dg00x
);
96 err
= snd_dg00x_transaction_register(dg00x
);
100 err
= snd_card_register(dg00x
->card
);
104 dg00x
->card
->private_free
= dg00x_card_free
;
105 dg00x
->card
->private_data
= dg00x
;
106 dg00x
->registered
= true;
110 snd_dg00x_transaction_unregister(dg00x
);
111 snd_dg00x_stream_destroy_duplex(dg00x
);
112 snd_card_free(dg00x
->card
);
113 dev_info(&dg00x
->unit
->device
,
114 "Sound card registration failed: %d\n", err
);
117 static int snd_dg00x_probe(struct fw_unit
*unit
,
118 const struct ieee1394_device_id
*entry
)
120 struct snd_dg00x
*dg00x
;
122 /* Allocate this independent of sound card instance. */
123 dg00x
= kzalloc(sizeof(struct snd_dg00x
), GFP_KERNEL
);
127 dg00x
->unit
= fw_unit_get(unit
);
128 dev_set_drvdata(&unit
->device
, dg00x
);
130 mutex_init(&dg00x
->mutex
);
131 spin_lock_init(&dg00x
->lock
);
132 init_waitqueue_head(&dg00x
->hwdep_wait
);
134 dg00x
->is_console
= entry
->model_id
== MODEL_CONSOLE
;
136 /* Allocate and register this sound card later. */
137 INIT_DEFERRABLE_WORK(&dg00x
->dwork
, do_registration
);
138 snd_fw_schedule_registration(unit
, &dg00x
->dwork
);
143 static void snd_dg00x_update(struct fw_unit
*unit
)
145 struct snd_dg00x
*dg00x
= dev_get_drvdata(&unit
->device
);
147 /* Postpone a workqueue for deferred registration. */
148 if (!dg00x
->registered
)
149 snd_fw_schedule_registration(unit
, &dg00x
->dwork
);
151 snd_dg00x_transaction_reregister(dg00x
);
154 * After registration, userspace can start packet streaming, then this
155 * code block works fine.
157 if (dg00x
->registered
) {
158 mutex_lock(&dg00x
->mutex
);
159 snd_dg00x_stream_update_duplex(dg00x
);
160 mutex_unlock(&dg00x
->mutex
);
164 static void snd_dg00x_remove(struct fw_unit
*unit
)
166 struct snd_dg00x
*dg00x
= dev_get_drvdata(&unit
->device
);
169 * Confirm to stop the work for registration before the sound card is
170 * going to be released. The work is not scheduled again because bus
171 * reset handler is not called anymore.
173 cancel_delayed_work_sync(&dg00x
->dwork
);
175 if (dg00x
->registered
) {
176 /* No need to wait for releasing card object in this context. */
177 snd_card_free_when_closed(dg00x
->card
);
179 /* Don't forget this case. */
184 static const struct ieee1394_device_id snd_dg00x_id_table
[] = {
185 /* Both of 002/003 use the same ID. */
187 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
188 IEEE1394_MATCH_MODEL_ID
,
189 .vendor_id
= VENDOR_DIGIDESIGN
,
190 .model_id
= MODEL_CONSOLE
,
193 .match_flags
= IEEE1394_MATCH_VENDOR_ID
|
194 IEEE1394_MATCH_MODEL_ID
,
195 .vendor_id
= VENDOR_DIGIDESIGN
,
196 .model_id
= MODEL_RACK
,
200 MODULE_DEVICE_TABLE(ieee1394
, snd_dg00x_id_table
);
202 static struct fw_driver dg00x_driver
= {
204 .owner
= THIS_MODULE
,
205 .name
= "snd-firewire-digi00x",
208 .probe
= snd_dg00x_probe
,
209 .update
= snd_dg00x_update
,
210 .remove
= snd_dg00x_remove
,
211 .id_table
= snd_dg00x_id_table
,
214 static int __init
snd_dg00x_init(void)
216 return driver_register(&dg00x_driver
.driver
);
219 static void __exit
snd_dg00x_exit(void)
221 driver_unregister(&dg00x_driver
.driver
);
224 module_init(snd_dg00x_init
);
225 module_exit(snd_dg00x_exit
);