Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 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 <o-takashi@sakamocchi.jp>"); |
| 13 | MODULE_LICENSE("GPL v2"); |
| 14 | |
Takashi Sakamoto | 6f81ba1 | 2015-10-01 22:02:12 +0900 | [diff] [blame] | 15 | static struct snd_tscm_spec model_specs[] = { |
| 16 | { |
| 17 | .name = "FW-1884", |
| 18 | .has_adat = true, |
| 19 | .has_spdif = true, |
| 20 | .pcm_capture_analog_channels = 8, |
| 21 | .pcm_playback_analog_channels = 8, |
| 22 | .midi_capture_ports = 4, |
| 23 | .midi_playback_ports = 4, |
| 24 | .is_controller = true, |
| 25 | }, |
| 26 | { |
Takashi Sakamoto | 6f81ba1 | 2015-10-01 22:02:12 +0900 | [diff] [blame] | 27 | .name = "FW-1082", |
| 28 | .has_adat = false, |
| 29 | .has_spdif = true, |
| 30 | .pcm_capture_analog_channels = 8, |
| 31 | .pcm_playback_analog_channels = 2, |
| 32 | .midi_capture_ports = 2, |
| 33 | .midi_playback_ports = 2, |
| 34 | .is_controller = true, |
| 35 | }, |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 36 | /* FW-1804 may be supported. */ |
Takashi Sakamoto | 6f81ba1 | 2015-10-01 22:02:12 +0900 | [diff] [blame] | 37 | }; |
| 38 | |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 39 | static int identify_model(struct snd_tscm *tscm) |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 40 | { |
| 41 | struct fw_device *fw_dev = fw_parent_device(tscm->unit); |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 42 | const u32 *config_rom = fw_dev->config_rom; |
Dan Carpenter | 9a30ae2 | 2015-10-19 14:29:27 +0300 | [diff] [blame] | 43 | char model[9]; |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 44 | unsigned int i; |
| 45 | u8 c; |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 46 | |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 47 | if (fw_dev->config_rom_length < 30) { |
| 48 | dev_err(&tscm->unit->device, |
| 49 | "Configuration ROM is too short.\n"); |
| 50 | return -ENODEV; |
| 51 | } |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 52 | |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 53 | /* Pick up model name from certain addresses. */ |
| 54 | for (i = 0; i < 8; i++) { |
| 55 | c = config_rom[28 + i / 4] >> (24 - 8 * (i % 4)); |
| 56 | if (c == '\0') |
| 57 | break; |
| 58 | model[i] = c; |
| 59 | } |
| 60 | model[i] = '\0'; |
| 61 | |
| 62 | for (i = 0; i < ARRAY_SIZE(model_specs); i++) { |
| 63 | if (strcmp(model, model_specs[i].name) == 0) { |
| 64 | tscm->spec = &model_specs[i]; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | if (tscm->spec == NULL) |
| 69 | return -ENODEV; |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 70 | |
| 71 | strcpy(tscm->card->driver, "FW-TASCAM"); |
| 72 | strcpy(tscm->card->shortname, model); |
| 73 | strcpy(tscm->card->mixername, model); |
| 74 | snprintf(tscm->card->longname, sizeof(tscm->card->longname), |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 75 | "TASCAM %s, GUID %08x%08x at %s, S%d", model, |
Takashi Sakamoto | bd04809 | 2015-10-18 22:39:53 +0900 | [diff] [blame] | 76 | fw_dev->config_rom[3], fw_dev->config_rom[4], |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 77 | dev_name(&tscm->unit->device), 100 << fw_dev->max_speed); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static void tscm_card_free(struct snd_card *card) |
| 83 | { |
| 84 | struct snd_tscm *tscm = card->private_data; |
| 85 | |
Takashi Sakamoto | 107cc01 | 2015-10-12 19:10:21 +0900 | [diff] [blame] | 86 | snd_tscm_transaction_unregister(tscm); |
Takashi Sakamoto | 35efa5c | 2015-10-01 22:02:15 +0900 | [diff] [blame] | 87 | snd_tscm_stream_destroy_duplex(tscm); |
| 88 | |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 89 | fw_unit_put(tscm->unit); |
| 90 | |
| 91 | mutex_destroy(&tscm->mutex); |
| 92 | } |
| 93 | |
| 94 | static int snd_tscm_probe(struct fw_unit *unit, |
| 95 | const struct ieee1394_device_id *entry) |
| 96 | { |
| 97 | struct snd_card *card; |
| 98 | struct snd_tscm *tscm; |
| 99 | int err; |
| 100 | |
| 101 | /* create card */ |
| 102 | err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
| 103 | sizeof(struct snd_tscm), &card); |
| 104 | if (err < 0) |
| 105 | return err; |
| 106 | card->private_free = tscm_card_free; |
| 107 | |
| 108 | /* initialize myself */ |
| 109 | tscm = card->private_data; |
| 110 | tscm->card = card; |
| 111 | tscm->unit = fw_unit_get(unit); |
| 112 | |
| 113 | mutex_init(&tscm->mutex); |
Takashi Sakamoto | e5e0c3d | 2015-10-01 22:02:17 +0900 | [diff] [blame] | 114 | spin_lock_init(&tscm->lock); |
| 115 | init_waitqueue_head(&tscm->hwdep_wait); |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 116 | |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 117 | err = identify_model(tscm); |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 118 | if (err < 0) |
| 119 | goto error; |
| 120 | |
Takashi Sakamoto | 96e5fbb | 2015-10-01 22:02:13 +0900 | [diff] [blame] | 121 | snd_tscm_proc_init(tscm); |
| 122 | |
Takashi Sakamoto | 35efa5c | 2015-10-01 22:02:15 +0900 | [diff] [blame] | 123 | err = snd_tscm_stream_init_duplex(tscm); |
| 124 | if (err < 0) |
| 125 | goto error; |
| 126 | |
Takashi Sakamoto | e453df4 | 2015-10-01 22:02:16 +0900 | [diff] [blame] | 127 | err = snd_tscm_create_pcm_devices(tscm); |
| 128 | if (err < 0) |
| 129 | goto error; |
| 130 | |
Takashi Sakamoto | 107cc01 | 2015-10-12 19:10:21 +0900 | [diff] [blame] | 131 | err = snd_tscm_transaction_register(tscm); |
| 132 | if (err < 0) |
| 133 | goto error; |
| 134 | |
Takashi Sakamoto | 0db18e7 | 2015-10-12 19:10:23 +0900 | [diff] [blame] | 135 | err = snd_tscm_create_midi_devices(tscm); |
| 136 | if (err < 0) |
| 137 | goto error; |
| 138 | |
Takashi Sakamoto | e5e0c3d | 2015-10-01 22:02:17 +0900 | [diff] [blame] | 139 | err = snd_tscm_create_hwdep_device(tscm); |
| 140 | if (err < 0) |
| 141 | goto error; |
| 142 | |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 143 | err = snd_card_register(card); |
| 144 | if (err < 0) |
| 145 | goto error; |
| 146 | |
| 147 | dev_set_drvdata(&unit->device, tscm); |
| 148 | |
| 149 | return err; |
| 150 | error: |
| 151 | snd_card_free(card); |
| 152 | return err; |
| 153 | } |
| 154 | |
| 155 | static void snd_tscm_update(struct fw_unit *unit) |
| 156 | { |
Takashi Sakamoto | 35efa5c | 2015-10-01 22:02:15 +0900 | [diff] [blame] | 157 | struct snd_tscm *tscm = dev_get_drvdata(&unit->device); |
| 158 | |
Takashi Sakamoto | 107cc01 | 2015-10-12 19:10:21 +0900 | [diff] [blame] | 159 | snd_tscm_transaction_reregister(tscm); |
| 160 | |
Takashi Sakamoto | 35efa5c | 2015-10-01 22:02:15 +0900 | [diff] [blame] | 161 | mutex_lock(&tscm->mutex); |
| 162 | snd_tscm_stream_update_duplex(tscm); |
| 163 | mutex_unlock(&tscm->mutex); |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void snd_tscm_remove(struct fw_unit *unit) |
| 167 | { |
| 168 | struct snd_tscm *tscm = dev_get_drvdata(&unit->device); |
| 169 | |
| 170 | /* No need to wait for releasing card object in this context. */ |
| 171 | snd_card_free_when_closed(tscm->card); |
| 172 | } |
| 173 | |
| 174 | static const struct ieee1394_device_id snd_tscm_id_table[] = { |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 175 | { |
| 176 | .match_flags = IEEE1394_MATCH_VENDOR_ID | |
Takashi Sakamoto | 53b3ffe | 2015-10-12 19:10:25 +0900 | [diff] [blame] | 177 | IEEE1394_MATCH_SPECIFIER_ID, |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 178 | .vendor_id = 0x00022e, |
| 179 | .specifier_id = 0x00022e, |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 180 | }, |
Takashi Sakamoto | c0949b2 | 2015-10-01 22:02:11 +0900 | [diff] [blame] | 181 | /* FE-08 requires reverse-engineering because it just has faders. */ |
| 182 | {} |
| 183 | }; |
| 184 | MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table); |
| 185 | |
| 186 | static struct fw_driver tscm_driver = { |
| 187 | .driver = { |
| 188 | .owner = THIS_MODULE, |
| 189 | .name = "snd-firewire-tascam", |
| 190 | .bus = &fw_bus_type, |
| 191 | }, |
| 192 | .probe = snd_tscm_probe, |
| 193 | .update = snd_tscm_update, |
| 194 | .remove = snd_tscm_remove, |
| 195 | .id_table = snd_tscm_id_table, |
| 196 | }; |
| 197 | |
| 198 | static int __init snd_tscm_init(void) |
| 199 | { |
| 200 | return driver_register(&tscm_driver.driver); |
| 201 | } |
| 202 | |
| 203 | static void __exit snd_tscm_exit(void) |
| 204 | { |
| 205 | driver_unregister(&tscm_driver.driver); |
| 206 | } |
| 207 | |
| 208 | module_init(snd_tscm_init); |
| 209 | module_exit(snd_tscm_exit); |