Commit | Line | Data |
---|---|---|
31ef9134 | 1 | /* |
8832c5a7 | 2 | * oxfw.c - a part of driver for OXFW970/971 based devices |
31ef9134 CL |
3 | * |
4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> | |
5 | * Licensed under the terms of the GNU General Public License, version 2. | |
6 | */ | |
7 | ||
e2786ca6 | 8 | #include "oxfw.h" |
31ef9134 CL |
9 | |
10 | #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000) | |
11 | /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */ | |
12 | ||
13 | #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020) | |
14 | #define OXFORD_HARDWARE_ID_OXFW970 0x39443841 | |
15 | #define OXFORD_HARDWARE_ID_OXFW971 0x39373100 | |
16 | ||
17 | #define VENDOR_GRIFFIN 0x001292 | |
18 | #define VENDOR_LACIE 0x00d04b | |
19 | ||
20 | #define SPECIFIER_1394TA 0x00a02d | |
21 | #define VERSION_AVC 0x010001 | |
22 | ||
8832c5a7 | 23 | MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver"); |
31ef9134 CL |
24 | MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); |
25 | MODULE_LICENSE("GPL v2"); | |
8832c5a7 | 26 | MODULE_ALIAS("snd-firewire-speakers"); |
31ef9134 | 27 | |
fec7b753 | 28 | static int name_card(struct snd_oxfw *oxfw) |
31ef9134 | 29 | { |
fec7b753 TS |
30 | struct fw_device *fw_dev = fw_parent_device(oxfw->unit); |
31 | const char *d, *v, *m; | |
32 | u32 firmware; | |
31ef9134 CL |
33 | int err; |
34 | ||
fec7b753 TS |
35 | err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST, |
36 | OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0); | |
37 | if (err < 0) | |
38 | goto end; | |
39 | be32_to_cpus(&firmware); | |
40 | ||
41 | d = oxfw->device_info->driver_name; | |
42 | v = oxfw->device_info->vendor_name; | |
43 | m = oxfw->device_info->model_name; | |
44 | ||
45 | strcpy(oxfw->card->driver, d); | |
46 | strcpy(oxfw->card->mixername, m); | |
47 | strcpy(oxfw->card->shortname, m); | |
48 | ||
49 | snprintf(oxfw->card->longname, sizeof(oxfw->card->longname), | |
50 | "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d", | |
51 | v, m, firmware >> 20, firmware & 0xffff, | |
52 | fw_dev->config_rom[3], fw_dev->config_rom[4], | |
53 | dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed); | |
54 | end: | |
55 | return err; | |
31ef9134 CL |
56 | } |
57 | ||
8832c5a7 | 58 | static void oxfw_card_free(struct snd_card *card) |
31ef9134 | 59 | { |
8832c5a7 | 60 | struct snd_oxfw *oxfw = card->private_data; |
31ef9134 | 61 | |
8832c5a7 | 62 | mutex_destroy(&oxfw->mutex); |
31ef9134 CL |
63 | } |
64 | ||
8832c5a7 | 65 | static int oxfw_probe(struct fw_unit *unit, |
94a87157 | 66 | const struct ieee1394_device_id *id) |
31ef9134 | 67 | { |
31ef9134 | 68 | struct snd_card *card; |
8832c5a7 | 69 | struct snd_oxfw *oxfw; |
31ef9134 CL |
70 | int err; |
71 | ||
06b45f00 | 72 | err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE, |
8832c5a7 | 73 | sizeof(*oxfw), &card); |
31ef9134 CL |
74 | if (err < 0) |
75 | return err; | |
31ef9134 | 76 | |
e2786ca6 | 77 | card->private_free = oxfw_card_free; |
8832c5a7 TS |
78 | oxfw = card->private_data; |
79 | oxfw->card = card; | |
80 | mutex_init(&oxfw->mutex); | |
e2786ca6 | 81 | oxfw->unit = unit; |
8832c5a7 | 82 | oxfw->device_info = (const struct device_info *)id->driver_data; |
31ef9134 | 83 | |
fec7b753 TS |
84 | err = name_card(oxfw); |
85 | if (err < 0) | |
86 | goto error; | |
31ef9134 | 87 | |
3713d93a | 88 | err = snd_oxfw_create_pcm(oxfw); |
31ef9134 CL |
89 | if (err < 0) |
90 | goto error; | |
91 | ||
31514bfb | 92 | err = snd_oxfw_create_mixer(oxfw); |
31ef9134 CL |
93 | if (err < 0) |
94 | goto error; | |
95 | ||
e2786ca6 | 96 | err = snd_oxfw_stream_init_simplex(oxfw); |
31ef9134 CL |
97 | if (err < 0) |
98 | goto error; | |
99 | ||
e2786ca6 TS |
100 | err = snd_card_register(card); |
101 | if (err < 0) { | |
102 | snd_oxfw_stream_destroy_simplex(oxfw); | |
103 | goto error; | |
104 | } | |
8832c5a7 | 105 | dev_set_drvdata(&unit->device, oxfw); |
31ef9134 CL |
106 | |
107 | return 0; | |
31ef9134 CL |
108 | error: |
109 | snd_card_free(card); | |
110 | return err; | |
111 | } | |
112 | ||
8832c5a7 | 113 | static void oxfw_bus_reset(struct fw_unit *unit) |
31ef9134 | 114 | { |
8832c5a7 | 115 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
31ef9134 | 116 | |
8832c5a7 | 117 | fcp_bus_reset(oxfw->unit); |
31ef9134 | 118 | |
e2786ca6 TS |
119 | mutex_lock(&oxfw->mutex); |
120 | snd_oxfw_stream_update_simplex(oxfw); | |
121 | mutex_unlock(&oxfw->mutex); | |
31ef9134 CL |
122 | } |
123 | ||
8832c5a7 | 124 | static void oxfw_remove(struct fw_unit *unit) |
94a87157 | 125 | { |
8832c5a7 | 126 | struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device); |
94a87157 | 127 | |
8832c5a7 | 128 | snd_card_disconnect(oxfw->card); |
94a87157 | 129 | |
e2786ca6 | 130 | snd_oxfw_stream_destroy_simplex(oxfw); |
94a87157 | 131 | |
8832c5a7 | 132 | snd_card_free_when_closed(oxfw->card); |
94a87157 SR |
133 | } |
134 | ||
135 | static const struct device_info griffin_firewave = { | |
136 | .driver_name = "FireWave", | |
fec7b753 TS |
137 | .vendor_name = "Griffin", |
138 | .model_name = "FireWave", | |
94a87157 SR |
139 | .pcm_constraints = firewave_constraints, |
140 | .mixer_channels = 6, | |
141 | .mute_fb_id = 0x01, | |
142 | .volume_fb_id = 0x02, | |
143 | }; | |
144 | ||
145 | static const struct device_info lacie_speakers = { | |
146 | .driver_name = "FWSpeakers", | |
fec7b753 TS |
147 | .vendor_name = "LaCie", |
148 | .model_name = "FireWire Speakers", | |
94a87157 SR |
149 | .pcm_constraints = lacie_speakers_constraints, |
150 | .mixer_channels = 1, | |
151 | .mute_fb_id = 0x01, | |
152 | .volume_fb_id = 0x01, | |
153 | }; | |
154 | ||
8832c5a7 | 155 | static const struct ieee1394_device_id oxfw_id_table[] = { |
31ef9134 CL |
156 | { |
157 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
158 | IEEE1394_MATCH_MODEL_ID | | |
159 | IEEE1394_MATCH_SPECIFIER_ID | | |
160 | IEEE1394_MATCH_VERSION, | |
161 | .vendor_id = VENDOR_GRIFFIN, | |
162 | .model_id = 0x00f970, | |
163 | .specifier_id = SPECIFIER_1394TA, | |
164 | .version = VERSION_AVC, | |
94a87157 | 165 | .driver_data = (kernel_ulong_t)&griffin_firewave, |
31ef9134 CL |
166 | }, |
167 | { | |
168 | .match_flags = IEEE1394_MATCH_VENDOR_ID | | |
169 | IEEE1394_MATCH_MODEL_ID | | |
170 | IEEE1394_MATCH_SPECIFIER_ID | | |
171 | IEEE1394_MATCH_VERSION, | |
172 | .vendor_id = VENDOR_LACIE, | |
173 | .model_id = 0x00f970, | |
174 | .specifier_id = SPECIFIER_1394TA, | |
175 | .version = VERSION_AVC, | |
94a87157 | 176 | .driver_data = (kernel_ulong_t)&lacie_speakers, |
31ef9134 CL |
177 | }, |
178 | { } | |
179 | }; | |
8832c5a7 | 180 | MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table); |
31ef9134 | 181 | |
8832c5a7 | 182 | static struct fw_driver oxfw_driver = { |
31ef9134 CL |
183 | .driver = { |
184 | .owner = THIS_MODULE, | |
185 | .name = KBUILD_MODNAME, | |
186 | .bus = &fw_bus_type, | |
31ef9134 | 187 | }, |
8832c5a7 TS |
188 | .probe = oxfw_probe, |
189 | .update = oxfw_bus_reset, | |
190 | .remove = oxfw_remove, | |
191 | .id_table = oxfw_id_table, | |
31ef9134 CL |
192 | }; |
193 | ||
8832c5a7 | 194 | static int __init snd_oxfw_init(void) |
31ef9134 | 195 | { |
8832c5a7 | 196 | return driver_register(&oxfw_driver.driver); |
31ef9134 CL |
197 | } |
198 | ||
8832c5a7 | 199 | static void __exit snd_oxfw_exit(void) |
31ef9134 | 200 | { |
8832c5a7 | 201 | driver_unregister(&oxfw_driver.driver); |
31ef9134 CL |
202 | } |
203 | ||
8832c5a7 TS |
204 | module_init(snd_oxfw_init); |
205 | module_exit(snd_oxfw_exit); |