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