8 #include <linux/device.h>
11 #include <linux/module.h>
14 #include <linux/slab.h>
25 #define OXFORD_FIRMWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x50000)
28 #define OXFORD_HARDWARE_ID_ADDRESS (CSR_REGISTER_BASE + 0x90020)
29 #define OXFORD_HARDWARE_ID_OXFW970 0x39443841
30 #define OXFORD_HARDWARE_ID_OXFW971 0x39373100
32 #define VENDOR_GRIFFIN 0x001292
33 #define VENDOR_LACIE 0x00d04b
35 #define SPECIFIER_1394TA 0x00a02d
36 #define VERSION_AVC 0x010001
70 static unsigned int stereo_rates[] = { 48000, 96000 };
77 if (snd_interval_max(channels) < 6)
92 if (snd_interval_max(rate) < 48000)
99 static unsigned int channels_list[] = { 2, 6 };
102 .list = channels_list,
110 runtime->
hw.channels_max = 6;
114 &channels_list_constraint);
118 firewave_rate_constraint,
NULL,
123 firewave_channels_constraint,
NULL,
153 .buffer_bytes_max = 4 * 1024 * 1024,
154 .period_bytes_min = 1,
165 err = fwspk->
device_info->pcm_constraints(runtime);
190 static void fwspk_stop_stream(
struct fwspk *fwspk)
199 static int fwspk_set_rate(
struct fwspk *fwspk,
unsigned int sfc)
221 if (err < 6 || buf[0] != 0x09 ) {
222 dev_err(&fwspk->
unit->device,
"failed to set sample rate\n");
242 fwspk_stop_stream(fwspk);
256 err = fwspk_set_rate(fwspk, fwspk->
stream.sfc);
273 fwspk_stop_stream(fwspk);
286 if (amdtp_out_streaming_error(&fwspk->
stream))
287 fwspk_stop_stream(fwspk);
333 amdtp_out_stream_pcm_trigger(&fwspk->
stream, pcm);
344 static int fwspk_create_pcm(
struct fwspk *fwspk)
348 .close = fwspk_close,
350 .hw_params = fwspk_hw_params,
351 .hw_free = fwspk_hw_free,
352 .prepare = fwspk_prepare,
353 .trigger = fwspk_trigger,
354 .pointer = fwspk_pointer,
367 fwspk->
pcm->ops = &ops;
378 static int fwspk_mute_command(
struct fwspk *fwspk,
bool *
value,
408 buf[10] = *value ? 0x70 : 0x60;
414 dev_err(&fwspk->
unit->device,
"short FCP response\n");
418 if (buf[0] != response_ok) {
419 dev_err(&fwspk->
unit->device,
"mute command failed\n");
424 *value = buf[10] == 0x70;
434 static int fwspk_volume_command(
struct fwspk *fwspk,
s16 *value,
467 buf[10] = *value >> 8;
475 dev_err(&fwspk->
unit->device,
"short FCP response\n");
479 if (buf[0] != response_ok) {
480 dev_err(&fwspk->
unit->device,
"volume command failed\n");
485 *value = (buf[10] << 8) | buf[11];
500 value->
value.integer.value[0] = !fwspk->
mute;
512 mute = !value->
value.integer.value[0];
514 if (mute == fwspk->
mute)
517 err = fwspk_mute_command(fwspk, &mute,
CTL_WRITE);
525 static int fwspk_volume_info(
struct snd_kcontrol *control,
538 static const u8 channel_map[6] = { 0, 1, 4, 5, 2, 3 };
540 static int fwspk_volume_get(
struct snd_kcontrol *control,
546 for (i = 0; i < fwspk->
device_info->mixer_channels; ++
i)
547 value->
value.integer.value[channel_map[i]] = fwspk->
volume[i];
552 static int fwspk_volume_put(
struct snd_kcontrol *control,
556 unsigned int i, changed_channels;
557 bool equal_values =
true;
561 for (i = 0; i < fwspk->
device_info->mixer_channels; ++
i) {
565 if (value->
value.integer.value[i] !=
566 value->
value.integer.value[0])
567 equal_values =
false;
570 changed_channels = 0;
571 for (i = 0; i < fwspk->
device_info->mixer_channels; ++
i)
572 if (value->
value.integer.value[channel_map[i]] !=
574 changed_channels |= 1 << (i + 1);
576 if (equal_values && changed_channels != 0)
577 changed_channels = 1 << 0;
579 for (i = 0; i <= fwspk->
device_info->mixer_channels; ++
i) {
580 volume = value->
value.integer.value[channel_map[i ? i - 1 : 0]];
581 if (changed_channels & (1 << i)) {
582 err = fwspk_volume_command(fwspk, &volume, i,
591 return changed_channels != 0;
594 static int fwspk_create_mixer(
struct fwspk *fwspk)
599 .name =
"PCM Playback Switch",
601 .get = fwspk_mute_get,
602 .put = fwspk_mute_put,
606 .name =
"PCM Playback Volume",
607 .info = fwspk_volume_info,
608 .get = fwspk_volume_get,
609 .put = fwspk_volume_put,
612 unsigned int i, first_ch;
615 err = fwspk_volume_command(fwspk, &fwspk->
volume_min,
619 err = fwspk_volume_command(fwspk, &fwspk->
volume_max,
624 err = fwspk_mute_command(fwspk, &fwspk->
mute,
CTL_READ);
628 first_ch = fwspk->
device_info->mixer_channels == 1 ? 0 : 1;
629 for (i = 0; i < fwspk->
device_info->mixer_channels; ++
i) {
630 err = fwspk_volume_command(fwspk, &fwspk->
volume[i],
662 fw_unit_put(fwspk->
unit);
668 static const struct device_info griffin_firewave = {
670 .short_name =
"FireWave",
671 .long_name =
"Griffin FireWave Surround",
672 .pcm_constraints = firewave_constraints,
675 .volume_fb_id = 0x02,
679 .short_name =
"FireWire Speakers",
680 .long_name =
"LaCie FireWire Speakers",
681 .pcm_constraints = lacie_speakers_constraints,
684 .volume_fb_id = 0x01,
694 return &griffin_firewave;
696 return &lacie_speakers;
705 struct fw_device *fw_dev = fw_parent_device(unit);
719 fwspk->
unit = fw_unit_get(unit);
738 firmware = fwspk_read_firmware_version(unit);
740 "%s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
742 firmware >> 20, firmware & 0xffff,
747 err = fwspk_create_pcm(fwspk);
751 err = fwspk_create_mixer(fwspk);
766 fw_unit_put(fwspk->
unit);
781 fwspk_stop_stream(fwspk);
789 static void fwspk_bus_reset(
struct fw_unit *unit)
798 fwspk_stop_stream(fwspk);
813 .model_id = 0x00f970,
823 .model_id = 0x00f970,
834 .name = KBUILD_MODNAME,
836 .probe = fwspk_probe,
839 .update = fwspk_bus_reset,
840 .id_table = fwspk_id_table,
843 static int __init alsa_fwspk_init(
void)
848 static void __exit alsa_fwspk_exit(
void)