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_DIGI00X 0x000002
18 static int name_card(struct snd_dg00x
*dg00x
)
20 struct fw_device
*fw_dev
= fw_parent_device(dg00x
->unit
);
25 err
= fw_csr_string(dg00x
->unit
->directory
, CSR_MODEL
, name
,
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
);
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
);
64 if (dg00x
->registered
)
67 err
= snd_card_new(&dg00x
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
72 err
= name_card(dg00x
);
76 err
= snd_dg00x_stream_init_duplex(dg00x
);
80 snd_dg00x_proc_init(dg00x
);
82 err
= snd_dg00x_create_pcm_devices(dg00x
);
86 err
= snd_dg00x_create_midi_devices(dg00x
);
90 err
= snd_dg00x_create_hwdep_device(dg00x
);
94 err
= snd_dg00x_transaction_register(dg00x
);
98 err
= snd_card_register(dg00x
->card
);
102 dg00x
->card
->private_free
= dg00x_card_free
;
103 dg00x
->card
->private_data
= dg00x
;
104 dg00x
->registered
= true;
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
);
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
);
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
);
175 /* Don't forget this case. */
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
= {
194 .owner
= THIS_MODULE
,
195 .name
= "snd-firewire-digi00x",
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
);