| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* digi00x.c - a part of driver for Digidesign Digi 002/003 family |
| 4 |
* |
| 5 |
* Copyright (c) 2014-2015 Takashi Sakamoto |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "digi00x.h" |
| 9 |
|
| 10 |
MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver"); |
| 11 |
MODULE_AUTHOR("Takashi Sakamoto <[email protected]>"); |
| 12 |
MODULE_LICENSE("GPL"); |
| 13 |
|
| 14 |
#define VENDOR_DIGIDESIGN 0x00a07e |
| 15 |
#define MODEL_CONSOLE 0x000001 |
| 16 |
#define MODEL_RACK 0x000002 |
| 17 |
#define SPEC_VERSION 0x000001 |
| 18 |
|
| 19 |
static int name_card(struct snd_dg00x *dg00x) |
| 20 |
{ |
| 21 |
struct fw_device *fw_dev = fw_parent_device(dg00x->unit); |
| 22 |
char name[32] = {0}; |
| 23 |
char *model; |
| 24 |
int err; |
| 25 |
|
| 26 |
err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name, |
| 27 |
sizeof(name)); |
| 28 |
if (err < 0) |
| 29 |
return err; |
| 30 |
|
| 31 |
model = skip_spaces(name); |
| 32 |
|
| 33 |
strscpy(dg00x->card->driver, "Digi00x"); |
| 34 |
strscpy(dg00x->card->shortname, model); |
| 35 |
strscpy(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); |
| 40 |
|
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
static void dg00x_card_free(struct snd_card *card) |
| 45 |
{ |
| 46 |
struct snd_dg00x *dg00x = card->private_data; |
| 47 |
|
| 48 |
snd_dg00x_stream_destroy_duplex(dg00x); |
| 49 |
snd_dg00x_transaction_unregister(dg00x); |
| 50 |
|
| 51 |
mutex_destroy(&dg00x->mutex); |
| 52 |
fw_unit_put(dg00x->unit); |
| 53 |
} |
| 54 |
|
| 55 |
static int snd_dg00x_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry) |
| 56 |
{ |
| 57 |
struct snd_card *card; |
| 58 |
struct snd_dg00x *dg00x; |
| 59 |
int err; |
| 60 |
|
| 61 |
err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, sizeof(*dg00x), &card); |
| 62 |
if (err < 0) |
| 63 |
return err; |
| 64 |
card->private_free = dg00x_card_free; |
| 65 |
|
| 66 |
dg00x = card->private_data; |
| 67 |
dg00x->unit = fw_unit_get(unit); |
| 68 |
dev_set_drvdata(&unit->device, dg00x); |
| 69 |
dg00x->card = card; |
| 70 |
|
| 71 |
mutex_init(&dg00x->mutex); |
| 72 |
spin_lock_init(&dg00x->lock); |
| 73 |
init_waitqueue_head(&dg00x->hwdep_wait); |
| 74 |
|
| 75 |
dg00x->is_console = entry->model_id == MODEL_CONSOLE; |
| 76 |
|
| 77 |
err = name_card(dg00x); |
| 78 |
if (err < 0) |
| 79 |
goto error; |
| 80 |
|
| 81 |
err = snd_dg00x_stream_init_duplex(dg00x); |
| 82 |
if (err < 0) |
| 83 |
goto error; |
| 84 |
|
| 85 |
snd_dg00x_proc_init(dg00x); |
| 86 |
|
| 87 |
err = snd_dg00x_create_pcm_devices(dg00x); |
| 88 |
if (err < 0) |
| 89 |
goto error; |
| 90 |
|
| 91 |
err = snd_dg00x_create_midi_devices(dg00x); |
| 92 |
if (err < 0) |
| 93 |
goto error; |
| 94 |
|
| 95 |
err = snd_dg00x_create_hwdep_device(dg00x); |
| 96 |
if (err < 0) |
| 97 |
goto error; |
| 98 |
|
| 99 |
err = snd_dg00x_transaction_register(dg00x); |
| 100 |
if (err < 0) |
| 101 |
goto error; |
| 102 |
|
| 103 |
err = snd_card_register(card); |
| 104 |
if (err < 0) |
| 105 |
goto error; |
| 106 |
|
| 107 |
return 0; |
| 108 |
error: |
| 109 |
snd_card_free(card); |
| 110 |
return err; |
| 111 |
} |
| 112 |
|
| 113 |
static void snd_dg00x_update(struct fw_unit *unit) |
| 114 |
{ |
| 115 |
struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); |
| 116 |
|
| 117 |
snd_dg00x_transaction_reregister(dg00x); |
| 118 |
|
| 119 |
guard(mutex)(&dg00x->mutex); |
| 120 |
snd_dg00x_stream_update_duplex(dg00x); |
| 121 |
} |
| 122 |
|
| 123 |
static void snd_dg00x_remove(struct fw_unit *unit) |
| 124 |
{ |
| 125 |
struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device); |
| 126 |
|
| 127 |
// Block till all of ALSA character devices are released. |
| 128 |
snd_card_free(dg00x->card); |
| 129 |
} |
| 130 |
|
| 131 |
static const struct ieee1394_device_id snd_dg00x_id_table[] = { |
| 132 |
/* Both of 002/003 use the same ID. */ |
| 133 |
{ |
| 134 |
.match_flags = IEEE1394_MATCH_VENDOR_ID | |
| 135 |
IEEE1394_MATCH_VERSION | |
| 136 |
IEEE1394_MATCH_MODEL_ID, |
| 137 |
.vendor_id = VENDOR_DIGIDESIGN, |
| 138 |
.version = SPEC_VERSION, |
| 139 |
.model_id = MODEL_CONSOLE, |
| 140 |
}, |
| 141 |
{ |
| 142 |
.match_flags = IEEE1394_MATCH_VENDOR_ID | |
| 143 |
IEEE1394_MATCH_VERSION | |
| 144 |
IEEE1394_MATCH_MODEL_ID, |
| 145 |
.vendor_id = VENDOR_DIGIDESIGN, |
| 146 |
.version = SPEC_VERSION, |
| 147 |
.model_id = MODEL_RACK, |
| 148 |
}, |
| 149 |
{} |
| 150 |
}; |
| 151 |
MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table); |
| 152 |
|
| 153 |
static struct fw_driver dg00x_driver = { |
| 154 |
.driver = { |
| 155 |
.owner = THIS_MODULE, |
| 156 |
.name = KBUILD_MODNAME, |
| 157 |
.bus = &fw_bus_type, |
| 158 |
}, |
| 159 |
.probe = snd_dg00x_probe, |
| 160 |
.update = snd_dg00x_update, |
| 161 |
.remove = snd_dg00x_remove, |
| 162 |
.id_table = snd_dg00x_id_table, |
| 163 |
}; |
| 164 |
|
| 165 |
static int __init snd_dg00x_init(void) |
| 166 |
{ |
| 167 |
return driver_register(&dg00x_driver.driver); |
| 168 |
} |
| 169 |
|
| 170 |
static void __exit snd_dg00x_exit(void) |
| 171 |
{ |
| 172 |
driver_unregister(&dg00x_driver.driver); |
| 173 |
} |
| 174 |
|
| 175 |
module_init(snd_dg00x_init); |
| 176 |
module_exit(snd_dg00x_exit); |