|
| 1 | +/* |
| 2 | + * tascam.c - a part of driver for TASCAM FireWire series |
| 3 | + * |
| 4 | + * Copyright (c) 2015 Takashi Sakamoto |
| 5 | + * |
| 6 | + * Licensed under the terms of the GNU General Public License, version 2. |
| 7 | + */ |
| 8 | + |
| 9 | +#include "tascam.h" |
| 10 | + |
| 11 | +MODULE_DESCRIPTION("TASCAM FireWire series Driver"); |
| 12 | +MODULE_AUTHOR( "Takashi Sakamoto <[email protected]>"); |
| 13 | +MODULE_LICENSE("GPL v2"); |
| 14 | + |
| 15 | +static int check_name(struct snd_tscm *tscm) |
| 16 | +{ |
| 17 | + struct fw_device *fw_dev = fw_parent_device(tscm->unit); |
| 18 | + char vendor[8]; |
| 19 | + char model[8]; |
| 20 | + __u32 data; |
| 21 | + |
| 22 | + /* Retrieve model name. */ |
| 23 | + data = be32_to_cpu(fw_dev->config_rom[28]); |
| 24 | + memcpy(model, &data, 4); |
| 25 | + data = be32_to_cpu(fw_dev->config_rom[29]); |
| 26 | + memcpy(model + 4, &data, 4); |
| 27 | + model[7] = '\0'; |
| 28 | + |
| 29 | + /* Retrieve vendor name. */ |
| 30 | + data = be32_to_cpu(fw_dev->config_rom[23]); |
| 31 | + memcpy(vendor, &data, 4); |
| 32 | + data = be32_to_cpu(fw_dev->config_rom[24]); |
| 33 | + memcpy(vendor + 4, &data, 4); |
| 34 | + vendor[7] = '\0'; |
| 35 | + |
| 36 | + strcpy(tscm->card->driver, "FW-TASCAM"); |
| 37 | + strcpy(tscm->card->shortname, model); |
| 38 | + strcpy(tscm->card->mixername, model); |
| 39 | + snprintf(tscm->card->longname, sizeof(tscm->card->longname), |
| 40 | + "%s %s, GUID %08x%08x at %s, S%d", vendor, model, |
| 41 | + cpu_to_be32(fw_dev->config_rom[3]), |
| 42 | + cpu_to_be32(fw_dev->config_rom[4]), |
| 43 | + dev_name(&tscm->unit->device), 100 << fw_dev->max_speed); |
| 44 | + |
| 45 | + return 0; |
| 46 | +} |
| 47 | + |
| 48 | +static void tscm_card_free(struct snd_card *card) |
| 49 | +{ |
| 50 | + struct snd_tscm *tscm = card->private_data; |
| 51 | + |
| 52 | + fw_unit_put(tscm->unit); |
| 53 | + |
| 54 | + mutex_destroy(&tscm->mutex); |
| 55 | +} |
| 56 | + |
| 57 | +static int snd_tscm_probe(struct fw_unit *unit, |
| 58 | + const struct ieee1394_device_id *entry) |
| 59 | +{ |
| 60 | + struct snd_card *card; |
| 61 | + struct snd_tscm *tscm; |
| 62 | + int err; |
| 63 | + |
| 64 | + /* create card */ |
| 65 | + err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
| 66 | + sizeof(struct snd_tscm), &card); |
| 67 | + if (err < 0) |
| 68 | + return err; |
| 69 | + card->private_free = tscm_card_free; |
| 70 | + |
| 71 | + /* initialize myself */ |
| 72 | + tscm = card->private_data; |
| 73 | + tscm->card = card; |
| 74 | + tscm->unit = fw_unit_get(unit); |
| 75 | + |
| 76 | + mutex_init(&tscm->mutex); |
| 77 | + |
| 78 | + err = check_name(tscm); |
| 79 | + if (err < 0) |
| 80 | + goto error; |
| 81 | + |
| 82 | + err = snd_card_register(card); |
| 83 | + if (err < 0) |
| 84 | + goto error; |
| 85 | + |
| 86 | + dev_set_drvdata(&unit->device, tscm); |
| 87 | + |
| 88 | + return err; |
| 89 | +error: |
| 90 | + snd_card_free(card); |
| 91 | + return err; |
| 92 | +} |
| 93 | + |
| 94 | +static void snd_tscm_update(struct fw_unit *unit) |
| 95 | +{ |
| 96 | + return; |
| 97 | +} |
| 98 | + |
| 99 | +static void snd_tscm_remove(struct fw_unit *unit) |
| 100 | +{ |
| 101 | + struct snd_tscm *tscm = dev_get_drvdata(&unit->device); |
| 102 | + |
| 103 | + /* No need to wait for releasing card object in this context. */ |
| 104 | + snd_card_free_when_closed(tscm->card); |
| 105 | +} |
| 106 | + |
| 107 | +static const struct ieee1394_device_id snd_tscm_id_table[] = { |
| 108 | + /* FW-1082 */ |
| 109 | + { |
| 110 | + .match_flags = IEEE1394_MATCH_VENDOR_ID | |
| 111 | + IEEE1394_MATCH_SPECIFIER_ID | |
| 112 | + IEEE1394_MATCH_VERSION, |
| 113 | + .vendor_id = 0x00022e, |
| 114 | + .specifier_id = 0x00022e, |
| 115 | + .version = 0x800003, |
| 116 | + }, |
| 117 | + /* FW-1884 */ |
| 118 | + { |
| 119 | + .match_flags = IEEE1394_MATCH_VENDOR_ID | |
| 120 | + IEEE1394_MATCH_SPECIFIER_ID | |
| 121 | + IEEE1394_MATCH_VERSION, |
| 122 | + .vendor_id = 0x00022e, |
| 123 | + .specifier_id = 0x00022e, |
| 124 | + .version = 0x800000, |
| 125 | + }, |
| 126 | + /* FW-1804 mey be supported if IDs are clear. */ |
| 127 | + /* FE-08 requires reverse-engineering because it just has faders. */ |
| 128 | + {} |
| 129 | +}; |
| 130 | +MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table); |
| 131 | + |
| 132 | +static struct fw_driver tscm_driver = { |
| 133 | + .driver = { |
| 134 | + .owner = THIS_MODULE, |
| 135 | + .name = "snd-firewire-tascam", |
| 136 | + .bus = &fw_bus_type, |
| 137 | + }, |
| 138 | + .probe = snd_tscm_probe, |
| 139 | + .update = snd_tscm_update, |
| 140 | + .remove = snd_tscm_remove, |
| 141 | + .id_table = snd_tscm_id_table, |
| 142 | +}; |
| 143 | + |
| 144 | +static int __init snd_tscm_init(void) |
| 145 | +{ |
| 146 | + return driver_register(&tscm_driver.driver); |
| 147 | +} |
| 148 | + |
| 149 | +static void __exit snd_tscm_exit(void) |
| 150 | +{ |
| 151 | + driver_unregister(&tscm_driver.driver); |
| 152 | +} |
| 153 | + |
| 154 | +module_init(snd_tscm_init); |
| 155 | +module_exit(snd_tscm_exit); |
0 commit comments