blob: ee0bc183950888ba6ade12bb8441fa81be41ec11 [file] [log] [blame]
Takashi Sakamotoc0949b22015-10-01 22:02:11 +09001/*
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
11MODULE_DESCRIPTION("TASCAM FireWire series Driver");
12MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13MODULE_LICENSE("GPL v2");
14
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090015static 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 Sakamoto6f81ba12015-10-01 22:02:12 +090027 .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 Sakamoto53b3ffe2015-10-12 19:10:25 +090036 /* FW-1804 may be supported. */
Takashi Sakamoto6f81ba12015-10-01 22:02:12 +090037};
38
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +090039static int identify_model(struct snd_tscm *tscm)
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090040{
41 struct fw_device *fw_dev = fw_parent_device(tscm->unit);
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +090042 const u32 *config_rom = fw_dev->config_rom;
Dan Carpenter9a30ae22015-10-19 14:29:27 +030043 char model[9];
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +090044 unsigned int i;
45 u8 c;
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090046
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +090047 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 Sakamotoc0949b22015-10-01 22:02:11 +090052
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +090053 /* 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 Sakamotoc0949b22015-10-01 22:02:11 +090070
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 Sakamoto53b3ffe2015-10-12 19:10:25 +090075 "TASCAM %s, GUID %08x%08x at %s, S%d", model,
Takashi Sakamotobd048092015-10-18 22:39:53 +090076 fw_dev->config_rom[3], fw_dev->config_rom[4],
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090077 dev_name(&tscm->unit->device), 100 << fw_dev->max_speed);
78
79 return 0;
80}
81
82static void tscm_card_free(struct snd_card *card)
83{
84 struct snd_tscm *tscm = card->private_data;
85
Takashi Sakamoto107cc012015-10-12 19:10:21 +090086 snd_tscm_transaction_unregister(tscm);
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +090087 snd_tscm_stream_destroy_duplex(tscm);
88
Takashi Sakamotoc0949b22015-10-01 22:02:11 +090089 fw_unit_put(tscm->unit);
90
91 mutex_destroy(&tscm->mutex);
92}
93
94static 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 Sakamotoe5e0c3d2015-10-01 22:02:17 +0900114 spin_lock_init(&tscm->lock);
115 init_waitqueue_head(&tscm->hwdep_wait);
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900116
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +0900117 err = identify_model(tscm);
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900118 if (err < 0)
119 goto error;
120
Takashi Sakamoto96e5fbb2015-10-01 22:02:13 +0900121 snd_tscm_proc_init(tscm);
122
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900123 err = snd_tscm_stream_init_duplex(tscm);
124 if (err < 0)
125 goto error;
126
Takashi Sakamotoe453df42015-10-01 22:02:16 +0900127 err = snd_tscm_create_pcm_devices(tscm);
128 if (err < 0)
129 goto error;
130
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900131 err = snd_tscm_transaction_register(tscm);
132 if (err < 0)
133 goto error;
134
Takashi Sakamoto0db18e72015-10-12 19:10:23 +0900135 err = snd_tscm_create_midi_devices(tscm);
136 if (err < 0)
137 goto error;
138
Takashi Sakamotoe5e0c3d2015-10-01 22:02:17 +0900139 err = snd_tscm_create_hwdep_device(tscm);
140 if (err < 0)
141 goto error;
142
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900143 err = snd_card_register(card);
144 if (err < 0)
145 goto error;
146
147 dev_set_drvdata(&unit->device, tscm);
148
149 return err;
150error:
151 snd_card_free(card);
152 return err;
153}
154
155static void snd_tscm_update(struct fw_unit *unit)
156{
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900157 struct snd_tscm *tscm = dev_get_drvdata(&unit->device);
158
Takashi Sakamoto107cc012015-10-12 19:10:21 +0900159 snd_tscm_transaction_reregister(tscm);
160
Takashi Sakamoto35efa5c2015-10-01 22:02:15 +0900161 mutex_lock(&tscm->mutex);
162 snd_tscm_stream_update_duplex(tscm);
163 mutex_unlock(&tscm->mutex);
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900164}
165
166static 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
174static const struct ieee1394_device_id snd_tscm_id_table[] = {
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900175 {
176 .match_flags = IEEE1394_MATCH_VENDOR_ID |
Takashi Sakamoto53b3ffe2015-10-12 19:10:25 +0900177 IEEE1394_MATCH_SPECIFIER_ID,
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900178 .vendor_id = 0x00022e,
179 .specifier_id = 0x00022e,
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900180 },
Takashi Sakamotoc0949b22015-10-01 22:02:11 +0900181 /* FE-08 requires reverse-engineering because it just has faders. */
182 {}
183};
184MODULE_DEVICE_TABLE(ieee1394, snd_tscm_id_table);
185
186static 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
198static int __init snd_tscm_init(void)
199{
200 return driver_register(&tscm_driver.driver);
201}
202
203static void __exit snd_tscm_exit(void)
204{
205 driver_unregister(&tscm_driver.driver);
206}
207
208module_init(snd_tscm_init);
209module_exit(snd_tscm_exit);