1 // SPDX-License-Identifier: GPL-2.0-only
3 * motu.c - a part of driver for MOTU FireWire series
5 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
10 #define OUI_MOTU 0x0001f2
12 MODULE_DESCRIPTION("MOTU FireWire driver");
13 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
14 MODULE_LICENSE("GPL v2");
16 const unsigned int snd_motu_clock_rates
[SND_MOTU_CLOCK_RATE_COUNT
] = {
28 static void name_card(struct snd_motu
*motu
)
30 struct fw_device
*fw_dev
= fw_parent_device(motu
->unit
);
31 struct fw_csr_iterator it
;
35 fw_csr_iterator_init(&it
, motu
->unit
->directory
);
36 while (fw_csr_iterator_next(&it
, &key
, &val
)) {
44 strcpy(motu
->card
->driver
, "FW-MOTU");
45 strcpy(motu
->card
->shortname
, motu
->spec
->name
);
46 strcpy(motu
->card
->mixername
, motu
->spec
->name
);
47 snprintf(motu
->card
->longname
, sizeof(motu
->card
->longname
),
48 "MOTU %s (version:%06x), GUID %08x%08x at %s, S%d",
49 motu
->spec
->name
, version
,
50 fw_dev
->config_rom
[3], fw_dev
->config_rom
[4],
51 dev_name(&motu
->unit
->device
), 100 << fw_dev
->max_speed
);
54 static void motu_card_free(struct snd_card
*card
)
56 struct snd_motu
*motu
= card
->private_data
;
58 snd_motu_transaction_unregister(motu
);
59 snd_motu_stream_destroy_duplex(motu
);
62 static void do_registration(struct work_struct
*work
)
64 struct snd_motu
*motu
= container_of(work
, struct snd_motu
, dwork
.work
);
70 err
= snd_card_new(&motu
->unit
->device
, -1, NULL
, THIS_MODULE
, 0,
74 motu
->card
->private_free
= motu_card_free
;
75 motu
->card
->private_data
= motu
;
79 err
= snd_motu_transaction_register(motu
);
83 err
= snd_motu_stream_init_duplex(motu
);
87 snd_motu_proc_init(motu
);
89 err
= snd_motu_create_pcm_devices(motu
);
93 if ((motu
->spec
->flags
& SND_MOTU_SPEC_RX_MIDI_2ND_Q
) ||
94 (motu
->spec
->flags
& SND_MOTU_SPEC_RX_MIDI_3RD_Q
) ||
95 (motu
->spec
->flags
& SND_MOTU_SPEC_TX_MIDI_2ND_Q
) ||
96 (motu
->spec
->flags
& SND_MOTU_SPEC_TX_MIDI_3RD_Q
)) {
97 err
= snd_motu_create_midi_devices(motu
);
102 err
= snd_motu_create_hwdep_device(motu
);
106 err
= snd_card_register(motu
->card
);
110 motu
->registered
= true;
114 snd_card_free(motu
->card
);
115 dev_info(&motu
->unit
->device
,
116 "Sound card registration failed: %d\n", err
);
119 static int motu_probe(struct fw_unit
*unit
,
120 const struct ieee1394_device_id
*entry
)
122 struct snd_motu
*motu
;
124 /* Allocate this independently of sound card instance. */
125 motu
= devm_kzalloc(&unit
->device
, sizeof(struct snd_motu
), GFP_KERNEL
);
128 motu
->unit
= fw_unit_get(unit
);
129 dev_set_drvdata(&unit
->device
, motu
);
131 motu
->spec
= (const struct snd_motu_spec
*)entry
->driver_data
;
132 mutex_init(&motu
->mutex
);
133 spin_lock_init(&motu
->lock
);
134 init_waitqueue_head(&motu
->hwdep_wait
);
136 /* Allocate and register this sound card later. */
137 INIT_DEFERRABLE_WORK(&motu
->dwork
, do_registration
);
138 snd_fw_schedule_registration(unit
, &motu
->dwork
);
143 static void motu_remove(struct fw_unit
*unit
)
145 struct snd_motu
*motu
= dev_get_drvdata(&unit
->device
);
148 * Confirm to stop the work for registration before the sound card is
149 * going to be released. The work is not scheduled again because bus
150 * reset handler is not called anymore.
152 cancel_delayed_work_sync(&motu
->dwork
);
154 if (motu
->registered
) {
155 // Block till all of ALSA character devices are released.
156 snd_card_free(motu
->card
);
159 mutex_destroy(&motu
->mutex
);
160 fw_unit_put(motu
->unit
);
163 static void motu_bus_update(struct fw_unit
*unit
)
165 struct snd_motu
*motu
= dev_get_drvdata(&unit
->device
);
167 /* Postpone a workqueue for deferred registration. */
168 if (!motu
->registered
)
169 snd_fw_schedule_registration(unit
, &motu
->dwork
);
171 /* The handler address register becomes initialized. */
172 snd_motu_transaction_reregister(motu
);
175 #define SND_MOTU_DEV_ENTRY(model, data) \
177 .match_flags = IEEE1394_MATCH_VENDOR_ID | \
178 IEEE1394_MATCH_SPECIFIER_ID | \
179 IEEE1394_MATCH_VERSION, \
180 .vendor_id = OUI_MOTU, \
181 .specifier_id = OUI_MOTU, \
183 .driver_data = (kernel_ulong_t)data, \
186 static const struct ieee1394_device_id motu_id_table
[] = {
187 SND_MOTU_DEV_ENTRY(0x000003, &snd_motu_spec_828mk2
),
188 SND_MOTU_DEV_ENTRY(0x000009, &snd_motu_spec_traveler
),
189 SND_MOTU_DEV_ENTRY(0x00000d, &snd_motu_spec_ultralite
),
190 SND_MOTU_DEV_ENTRY(0x00000f, &snd_motu_spec_8pre
),
191 SND_MOTU_DEV_ENTRY(0x000015, &snd_motu_spec_828mk3
), // FireWire only.
192 SND_MOTU_DEV_ENTRY(0x000019, &snd_motu_spec_ultralite_mk3
), // FireWire only.
193 SND_MOTU_DEV_ENTRY(0x000035, &snd_motu_spec_828mk3
), // Hybrid.
194 SND_MOTU_DEV_ENTRY(0x000033, &snd_motu_spec_audio_express
),
195 SND_MOTU_DEV_ENTRY(0x000045, &snd_motu_spec_4pre
),
198 MODULE_DEVICE_TABLE(ieee1394
, motu_id_table
);
200 static struct fw_driver motu_driver
= {
202 .owner
= THIS_MODULE
,
203 .name
= KBUILD_MODNAME
,
207 .update
= motu_bus_update
,
208 .remove
= motu_remove
,
209 .id_table
= motu_id_table
,
212 static int __init
alsa_motu_init(void)
214 return driver_register(&motu_driver
.driver
);
217 static void __exit
alsa_motu_exit(void)
219 driver_unregister(&motu_driver
.driver
);
222 module_init(alsa_motu_init
);
223 module_exit(alsa_motu_exit
);