2 * oxfw.c - a part of driver for OXFW970/971 based devices
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
10 #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000)
11 /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
13 #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020)
14 #define OXFORD_HARDWARE_ID_OXFW970 0x39443841
15 #define OXFORD_HARDWARE_ID_OXFW971 0x39373100
17 #define VENDOR_GRIFFIN 0x001292
18 #define VENDOR_LACIE 0x00d04b
20 #define SPECIFIER_1394TA 0x00a02d
21 #define VERSION_AVC 0x010001
23 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
24 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
25 MODULE_LICENSE("GPL v2");
26 MODULE_ALIAS("snd-firewire-speakers");
28 enum control_action { CTL_READ, CTL_WRITE };
29 enum control_attribute {
35 static int oxfw_mute_command(struct snd_oxfw *oxfw, bool *value,
36 enum control_action action)
42 buf = kmalloc(11, GFP_KERNEL);
46 if (action == CTL_READ) {
47 buf[0] = 0x01; /* AV/C, STATUS */
48 response_ok = 0x0c; /* STABLE */
50 buf[0] = 0x00; /* AV/C, CONTROL */
51 response_ok = 0x09; /* ACCEPTED */
53 buf[1] = 0x08; /* audio unit 0 */
54 buf[2] = 0xb8; /* FUNCTION BLOCK */
55 buf[3] = 0x81; /* function block type: feature */
56 buf[4] = oxfw->device_info->mute_fb_id; /* function block ID */
57 buf[5] = 0x10; /* control attribute: current */
58 buf[6] = 0x02; /* selector length */
59 buf[7] = 0x00; /* audio channel number */
60 buf[8] = 0x01; /* control selector: mute */
61 buf[9] = 0x01; /* control data length */
62 if (action == CTL_READ)
65 buf[10] = *value ? 0x70 : 0x60;
67 err = fcp_avc_transaction(oxfw->unit, buf, 11, buf, 11, 0x3fe);
71 dev_err(&oxfw->unit->device, "short FCP response\n");
75 if (buf[0] != response_ok) {
76 dev_err(&oxfw->unit->device, "mute command failed\n");
80 if (action == CTL_READ)
81 *value = buf[10] == 0x70;
91 static int oxfw_volume_command(struct snd_oxfw *oxfw, s16 *value,
93 enum control_attribute attribute,
94 enum control_action action)
100 buf = kmalloc(12, GFP_KERNEL);
104 if (action == CTL_READ) {
105 buf[0] = 0x01; /* AV/C, STATUS */
106 response_ok = 0x0c; /* STABLE */
108 buf[0] = 0x00; /* AV/C, CONTROL */
109 response_ok = 0x09; /* ACCEPTED */
111 buf[1] = 0x08; /* audio unit 0 */
112 buf[2] = 0xb8; /* FUNCTION BLOCK */
113 buf[3] = 0x81; /* function block type: feature */
114 buf[4] = oxfw->device_info->volume_fb_id; /* function block ID */
115 buf[5] = attribute; /* control attribute */
116 buf[6] = 0x02; /* selector length */
117 buf[7] = channel; /* audio channel number */
118 buf[8] = 0x02; /* control selector: volume */
119 buf[9] = 0x02; /* control data length */
120 if (action == CTL_READ) {
124 buf[10] = *value >> 8;
128 err = fcp_avc_transaction(oxfw->unit, buf, 12, buf, 12, 0x3fe);
132 dev_err(&oxfw->unit->device, "short FCP response\n");
136 if (buf[0] != response_ok) {
137 dev_err(&oxfw->unit->device, "volume command failed\n");
141 if (action == CTL_READ)
142 *value = (buf[10] << 8) | buf[11];
152 static int oxfw_mute_get(struct snd_kcontrol *control,
153 struct snd_ctl_elem_value *value)
155 struct snd_oxfw *oxfw = control->private_data;
157 value->value.integer.value[0] = !oxfw->mute;
162 static int oxfw_mute_put(struct snd_kcontrol *control,
163 struct snd_ctl_elem_value *value)
165 struct snd_oxfw *oxfw = control->private_data;
169 mute = !value->value.integer.value[0];
171 if (mute == oxfw->mute)
174 err = oxfw_mute_command(oxfw, &mute, CTL_WRITE);
182 static int oxfw_volume_info(struct snd_kcontrol *control,
183 struct snd_ctl_elem_info *info)
185 struct snd_oxfw *oxfw = control->private_data;
187 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
188 info->count = oxfw->device_info->mixer_channels;
189 info->value.integer.min = oxfw->volume_min;
190 info->value.integer.max = oxfw->volume_max;
195 static const u8 channel_map[6] = { 0, 1, 4, 5, 2, 3 };
197 static int oxfw_volume_get(struct snd_kcontrol *control,
198 struct snd_ctl_elem_value *value)
200 struct snd_oxfw *oxfw = control->private_data;
203 for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
204 value->value.integer.value[channel_map[i]] = oxfw->volume[i];
209 static int oxfw_volume_put(struct snd_kcontrol *control,
210 struct snd_ctl_elem_value *value)
212 struct snd_oxfw *oxfw = control->private_data;
213 unsigned int i, changed_channels;
214 bool equal_values = true;
218 for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
219 if (value->value.integer.value[i] < oxfw->volume_min ||
220 value->value.integer.value[i] > oxfw->volume_max)
222 if (value->value.integer.value[i] !=
223 value->value.integer.value[0])
224 equal_values = false;
227 changed_channels = 0;
228 for (i = 0; i < oxfw->device_info->mixer_channels; ++i)
229 if (value->value.integer.value[channel_map[i]] !=
231 changed_channels |= 1 << (i + 1);
233 if (equal_values && changed_channels != 0)
234 changed_channels = 1 << 0;
236 for (i = 0; i <= oxfw->device_info->mixer_channels; ++i) {
237 volume = value->value.integer.value[channel_map[i ? i - 1 : 0]];
238 if (changed_channels & (1 << i)) {
239 err = oxfw_volume_command(oxfw, &volume, i,
240 CTL_CURRENT, CTL_WRITE);
245 oxfw->volume[i - 1] = volume;
248 return changed_channels != 0;
251 static int oxfw_create_mixer(struct snd_oxfw *oxfw)
253 static const struct snd_kcontrol_new controls[] = {
255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
256 .name = "PCM Playback Switch",
257 .info = snd_ctl_boolean_mono_info,
258 .get = oxfw_mute_get,
259 .put = oxfw_mute_put,
262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
263 .name = "PCM Playback Volume",
264 .info = oxfw_volume_info,
265 .get = oxfw_volume_get,
266 .put = oxfw_volume_put,
269 unsigned int i, first_ch;
272 err = oxfw_volume_command(oxfw, &oxfw->volume_min,
273 0, CTL_MIN, CTL_READ);
276 err = oxfw_volume_command(oxfw, &oxfw->volume_max,
277 0, CTL_MAX, CTL_READ);
281 err = oxfw_mute_command(oxfw, &oxfw->mute, CTL_READ);
285 first_ch = oxfw->device_info->mixer_channels == 1 ? 0 : 1;
286 for (i = 0; i < oxfw->device_info->mixer_channels; ++i) {
287 err = oxfw_volume_command(oxfw, &oxfw->volume[i],
288 first_ch + i, CTL_CURRENT, CTL_READ);
293 for (i = 0; i < ARRAY_SIZE(controls); ++i) {
294 err = snd_ctl_add(oxfw->card,
295 snd_ctl_new1(&controls[i], oxfw));
303 static u32 oxfw_read_firmware_version(struct fw_unit *unit)
308 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
309 OXFORD_FIRMWARE_ID_ADDRESS, &data, 4, 0);
310 return err >= 0 ? be32_to_cpu(data) : 0;
313 static void oxfw_card_free(struct snd_card *card)
315 struct snd_oxfw *oxfw = card->private_data;
317 mutex_destroy(&oxfw->mutex);
320 static int oxfw_probe(struct fw_unit *unit,
321 const struct ieee1394_device_id *id)
323 struct fw_device *fw_dev = fw_parent_device(unit);
324 struct snd_card *card;
325 struct snd_oxfw *oxfw;
329 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
330 sizeof(*oxfw), &card);
334 card->private_free = oxfw_card_free;
335 oxfw = card->private_data;
337 mutex_init(&oxfw->mutex);
339 oxfw->device_info = (const struct device_info *)id->driver_data;
341 strcpy(card->driver, oxfw->device_info->driver_name);
342 strcpy(card->shortname, oxfw->device_info->short_name);
343 firmware = oxfw_read_firmware_version(unit);
344 snprintf(card->longname, sizeof(card->longname),
345 "%s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
346 oxfw->device_info->long_name,
347 firmware >> 20, firmware & 0xffff,
348 fw_dev->config_rom[3], fw_dev->config_rom[4],
349 dev_name(&unit->device), 100 << fw_dev->max_speed);
350 strcpy(card->mixername, "OXFW");
352 err = snd_oxfw_create_pcm(oxfw);
356 err = oxfw_create_mixer(oxfw);
360 err = snd_oxfw_stream_init_simplex(oxfw);
364 err = snd_card_register(card);
366 snd_oxfw_stream_destroy_simplex(oxfw);
369 dev_set_drvdata(&unit->device, oxfw);
377 static void oxfw_bus_reset(struct fw_unit *unit)
379 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
381 fcp_bus_reset(oxfw->unit);
383 mutex_lock(&oxfw->mutex);
384 snd_oxfw_stream_update_simplex(oxfw);
385 mutex_unlock(&oxfw->mutex);
388 static void oxfw_remove(struct fw_unit *unit)
390 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
392 snd_card_disconnect(oxfw->card);
394 snd_oxfw_stream_destroy_simplex(oxfw);
396 snd_card_free_when_closed(oxfw->card);
399 static const struct device_info griffin_firewave = {
400 .driver_name = "FireWave",
401 .short_name = "FireWave",
402 .long_name = "Griffin FireWave Surround",
403 .pcm_constraints = firewave_constraints,
406 .volume_fb_id = 0x02,
409 static const struct device_info lacie_speakers = {
410 .driver_name = "FWSpeakers",
411 .short_name = "FireWire Speakers",
412 .long_name = "LaCie FireWire Speakers",
413 .pcm_constraints = lacie_speakers_constraints,
416 .volume_fb_id = 0x01,
419 static const struct ieee1394_device_id oxfw_id_table[] = {
421 .match_flags = IEEE1394_MATCH_VENDOR_ID |
422 IEEE1394_MATCH_MODEL_ID |
423 IEEE1394_MATCH_SPECIFIER_ID |
424 IEEE1394_MATCH_VERSION,
425 .vendor_id = VENDOR_GRIFFIN,
426 .model_id = 0x00f970,
427 .specifier_id = SPECIFIER_1394TA,
428 .version = VERSION_AVC,
429 .driver_data = (kernel_ulong_t)&griffin_firewave,
432 .match_flags = IEEE1394_MATCH_VENDOR_ID |
433 IEEE1394_MATCH_MODEL_ID |
434 IEEE1394_MATCH_SPECIFIER_ID |
435 IEEE1394_MATCH_VERSION,
436 .vendor_id = VENDOR_LACIE,
437 .model_id = 0x00f970,
438 .specifier_id = SPECIFIER_1394TA,
439 .version = VERSION_AVC,
440 .driver_data = (kernel_ulong_t)&lacie_speakers,
444 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
446 static struct fw_driver oxfw_driver = {
448 .owner = THIS_MODULE,
449 .name = KBUILD_MODNAME,
453 .update = oxfw_bus_reset,
454 .remove = oxfw_remove,
455 .id_table = oxfw_id_table,
458 static int __init snd_oxfw_init(void)
460 return driver_register(&oxfw_driver.driver);
463 static void __exit snd_oxfw_exit(void)
465 driver_unregister(&oxfw_driver.driver);
468 module_init(snd_oxfw_init);
469 module_exit(snd_oxfw_exit);