blob: bbe3be7fea9ba27b7a675f5c73dbe1c4ed745638 [file] [log] [blame]
Takashi Sakamoto9edf7232015-09-30 09:39:16 +09001/*
2 * digi00x.c - a part of driver for Digidesign Digi 002/003 family
3 *
4 * Copyright (c) 2014-2015 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "digi00x.h"
10
11MODULE_DESCRIPTION("Digidesign Digi 002/003 family Driver");
12MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
13MODULE_LICENSE("GPL v2");
14
15#define VENDOR_DIGIDESIGN 0x00a07e
16#define MODEL_DIGI00X 0x000002
17
18static int name_card(struct snd_dg00x *dg00x)
19{
20 struct fw_device *fw_dev = fw_parent_device(dg00x->unit);
21 char name[32] = {0};
22 char *model;
23 int err;
24
25 err = fw_csr_string(dg00x->unit->directory, CSR_MODEL, name,
26 sizeof(name));
27 if (err < 0)
28 return err;
29
30 model = skip_spaces(name);
31
32 strcpy(dg00x->card->driver, "Digi00x");
33 strcpy(dg00x->card->shortname, model);
34 strcpy(dg00x->card->mixername, model);
35 snprintf(dg00x->card->longname, sizeof(dg00x->card->longname),
36 "Digidesign %s, GUID %08x%08x at %s, S%d", model,
37 cpu_to_be32(fw_dev->config_rom[3]),
38 cpu_to_be32(fw_dev->config_rom[4]),
39 dev_name(&dg00x->unit->device), 100 << fw_dev->max_speed);
40
41 return 0;
42}
43
44static void dg00x_card_free(struct snd_card *card)
45{
46 struct snd_dg00x *dg00x = card->private_data;
47
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090048 snd_dg00x_stream_destroy_duplex(dg00x);
Takashi Sakamoto44b73082015-09-30 09:39:22 +090049 snd_dg00x_transaction_unregister(dg00x);
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090050
Takashi Sakamoto9edf7232015-09-30 09:39:16 +090051 fw_unit_put(dg00x->unit);
52
53 mutex_destroy(&dg00x->mutex);
54}
55
56static int snd_dg00x_probe(struct fw_unit *unit,
57 const struct ieee1394_device_id *entry)
58{
59 struct snd_card *card;
60 struct snd_dg00x *dg00x;
61 int err;
62
63 /* create card */
64 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
65 sizeof(struct snd_dg00x), &card);
66 if (err < 0)
67 return err;
68 card->private_free = dg00x_card_free;
69
70 /* initialize myself */
71 dg00x = card->private_data;
72 dg00x->card = card;
73 dg00x->unit = fw_unit_get(unit);
74
75 mutex_init(&dg00x->mutex);
Takashi Sakamoto660dd3d2015-09-30 09:39:21 +090076 spin_lock_init(&dg00x->lock);
77 init_waitqueue_head(&dg00x->hwdep_wait);
Takashi Sakamoto9edf7232015-09-30 09:39:16 +090078
79 err = name_card(dg00x);
80 if (err < 0)
81 goto error;
82
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +090083 err = snd_dg00x_stream_init_duplex(dg00x);
84 if (err < 0)
85 goto error;
86
Takashi Sakamoto927f17d2015-09-30 09:39:19 +090087 snd_dg00x_proc_init(dg00x);
88
Takashi Sakamoto0120d0f2015-09-30 09:39:20 +090089 err = snd_dg00x_create_pcm_devices(dg00x);
90 if (err < 0)
91 goto error;
92
Takashi Sakamoto9fbfd382015-10-11 12:30:16 +090093 err = snd_dg00x_create_midi_devices(dg00x);
94 if (err < 0)
95 goto error;
96
Takashi Sakamoto660dd3d2015-09-30 09:39:21 +090097 err = snd_dg00x_create_hwdep_device(dg00x);
98 if (err < 0)
99 goto error;
100
Takashi Sakamoto44b73082015-09-30 09:39:22 +0900101 err = snd_dg00x_transaction_register(dg00x);
102 if (err < 0)
103 goto error;
104
Takashi Sakamoto9edf7232015-09-30 09:39:16 +0900105 err = snd_card_register(card);
106 if (err < 0)
107 goto error;
108
109 dev_set_drvdata(&unit->device, dg00x);
110
111 return err;
112error:
113 snd_card_free(card);
114 return err;
115}
116
117static void snd_dg00x_update(struct fw_unit *unit)
118{
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +0900119 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
120
Takashi Sakamoto44b73082015-09-30 09:39:22 +0900121 snd_dg00x_transaction_reregister(dg00x);
122
Takashi Sakamoto3a2a1792015-09-30 09:39:18 +0900123 mutex_lock(&dg00x->mutex);
124 snd_dg00x_stream_update_duplex(dg00x);
125 mutex_unlock(&dg00x->mutex);
Takashi Sakamoto9edf7232015-09-30 09:39:16 +0900126}
127
128static void snd_dg00x_remove(struct fw_unit *unit)
129{
130 struct snd_dg00x *dg00x = dev_get_drvdata(&unit->device);
131
132 /* No need to wait for releasing card object in this context. */
133 snd_card_free_when_closed(dg00x->card);
134}
135
136static const struct ieee1394_device_id snd_dg00x_id_table[] = {
137 /* Both of 002/003 use the same ID. */
138 {
139 .match_flags = IEEE1394_MATCH_VENDOR_ID |
140 IEEE1394_MATCH_MODEL_ID,
141 .vendor_id = VENDOR_DIGIDESIGN,
142 .model_id = MODEL_DIGI00X,
143 },
144 {}
145};
146MODULE_DEVICE_TABLE(ieee1394, snd_dg00x_id_table);
147
148static struct fw_driver dg00x_driver = {
149 .driver = {
150 .owner = THIS_MODULE,
151 .name = "snd-firewire-digi00x",
152 .bus = &fw_bus_type,
153 },
154 .probe = snd_dg00x_probe,
155 .update = snd_dg00x_update,
156 .remove = snd_dg00x_remove,
157 .id_table = snd_dg00x_id_table,
158};
159
160static int __init snd_dg00x_init(void)
161{
162 return driver_register(&dg00x_driver.driver);
163}
164
165static void __exit snd_dg00x_exit(void)
166{
167 driver_unregister(&dg00x_driver.driver);
168}
169
170module_init(snd_dg00x_init);
171module_exit(snd_dg00x_exit);