^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * digi00x.c - a part of driver for Digidesign Digi 002/003 family
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2014-2015 Takashi Sakamoto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "digi00x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define VENDOR_DIGIDESIGN 0x00a07e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define MODEL_CONSOLE 0x000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define MODEL_RACK 0x000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define SPEC_VERSION 0x000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static int name_card(struct snd_dg00x *dg00x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) char name[32] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) char *model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) sizeof(name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) model = skip_spaces(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) strcpy(dg00x->card->driver, "Digi00x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) strcpy(dg00x->card->shortname, model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) strcpy(dg00x->card->mixername, model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) "Digidesign %s, GUID %08x%08x at %s, S%d", model,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) fw_dev->config_rom[3], fw_dev->config_rom[4],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void dg00x_card_free(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct snd_dg00x *dg00x = card->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) snd_dg00x_stream_destroy_duplex(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) snd_dg00x_transaction_unregister(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static void do_registration(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct snd_dg00x *dg00x =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) container_of(work, struct snd_dg00x, dwork.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (dg00x->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) err = snd_card_new(&dg00x->unit->device, -1, NULL, THIS_MODULE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) &dg00x->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dg00x->card->private_free = dg00x_card_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dg00x->card->private_data = dg00x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) err = name_card(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) err = snd_dg00x_stream_init_duplex(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) snd_dg00x_proc_init(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) err = snd_dg00x_create_pcm_devices(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) err = snd_dg00x_create_midi_devices(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) err = snd_dg00x_create_hwdep_device(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) err = snd_dg00x_transaction_register(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) err = snd_card_register(dg00x->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) dg00x->registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) snd_card_free(dg00x->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev_info(&dg00x->unit->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) "Sound card registration failed: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int snd_dg00x_probe(struct fw_unit *unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) const struct ieee1394_device_id *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct snd_dg00x *dg00x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Allocate this independent of sound card instance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) dg00x = devm_kzalloc(&unit->device, sizeof(struct snd_dg00x),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (!dg00x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) dg00x->unit = fw_unit_get(unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_set_drvdata(&unit->device, dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) mutex_init(&dg00x->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) spin_lock_init(&dg00x->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) init_waitqueue_head(&dg00x->hwdep_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dg00x->is_console = entry->model_id == MODEL_CONSOLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* Allocate and register this sound card later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) INIT_DEFERRABLE_WORK(&dg00x->dwork, do_registration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) snd_fw_schedule_registration(unit, &dg00x->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static void snd_dg00x_update(struct fw_unit *unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /* Postpone a workqueue for deferred registration. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!dg00x->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) snd_fw_schedule_registration(unit, &dg00x->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) snd_dg00x_transaction_reregister(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * After registration, userspace can start packet streaming, then this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * code block works fine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (dg00x->registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) mutex_lock(&dg00x->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) snd_dg00x_stream_update_duplex(dg00x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) mutex_unlock(&dg00x->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void snd_dg00x_remove(struct fw_unit *unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * Confirm to stop the work for registration before the sound card is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * going to be released. The work is not scheduled again because bus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * reset handler is not called anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) cancel_delayed_work_sync(&dg00x->dwork);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (dg00x->registered) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) // Block till all of ALSA character devices are released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) snd_card_free(dg00x->card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) mutex_destroy(&dg00x->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) fw_unit_put(dg00x->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static const struct ieee1394_device_id snd_dg00x_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* Both of 002/003 use the same ID. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) IEEE1394_MATCH_VERSION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .vendor_id = VENDOR_DIGIDESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .version = SPEC_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .model_id = MODEL_CONSOLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .match_flags = IEEE1394_MATCH_VENDOR_ID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) IEEE1394_MATCH_VERSION |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) IEEE1394_MATCH_MODEL_ID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .vendor_id = VENDOR_DIGIDESIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) .version = SPEC_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) .model_id = MODEL_RACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static struct fw_driver dg00x_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .bus = &fw_bus_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) .probe = snd_dg00x_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .update = snd_dg00x_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .remove = snd_dg00x_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .id_table = snd_dg00x_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static int __init snd_dg00x_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return driver_register(&dg00x_driver.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void __exit snd_dg00x_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) driver_unregister(&dg00x_driver.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) module_init(snd_dg00x_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) module_exit(snd_dg00x_exit);