1 // SPDX-License-Identifier: GPL-2.0-only
3 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
5 * Copyright (c) 2014-2015 Takashi Sakamoto
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
);
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_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
);
57 if (dg00x
->registered
)
60 err
= snd_card_new(&dg00x
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
64 dg00x
->card
->private_free
= dg00x_card_free
;
65 dg00x
->card
->private_data
= dg00x
;
67 err
= name_card(dg00x
);
71 err
= snd_dg00x_stream_init_duplex(dg00x
);
75 snd_dg00x_proc_init(dg00x
);
77 err
= snd_dg00x_create_pcm_devices(dg00x
);
81 err
= snd_dg00x_create_midi_devices(dg00x
);
85 err
= snd_dg00x_create_hwdep_device(dg00x
);
89 err
= snd_dg00x_transaction_register(dg00x
);
93 err
= snd_card_register(dg00x
->card
);
97 dg00x
->registered
= true;
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
),
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
);
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
= {
194 .owner
= THIS_MODULE
,
195 .name
= KBUILD_MODNAME
,
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
);