ALSA: firewire-lib/dice/speakers: Add common PCM constraints for AMDTP streams
[firefly-linux-kernel-4.4.55.git] / sound / firewire / speakers.c
1 /*
2  * OXFW970-based speakers driver
3  *
4  * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5  * Licensed under the terms of the GNU General Public License, version 2.
6  */
7
8 #include <linux/device.h>
9 #include <linux/firewire.h>
10 #include <linux/firewire-constants.h>
11 #include <linux/module.h>
12 #include <linux/mod_devicetable.h>
13 #include <linux/mutex.h>
14 #include <linux/slab.h>
15 #include <sound/control.h>
16 #include <sound/core.h>
17 #include <sound/initval.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include "cmp.h"
21 #include "fcp.h"
22 #include "amdtp.h"
23 #include "lib.h"
24
25 #define OXFORD_FIRMWARE_ID_ADDRESS      (CSR_REGISTER_BASE + 0x50000)
26 /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
27
28 #define OXFORD_HARDWARE_ID_ADDRESS      (CSR_REGISTER_BASE + 0x90020)
29 #define OXFORD_HARDWARE_ID_OXFW970      0x39443841
30 #define OXFORD_HARDWARE_ID_OXFW971      0x39373100
31
32 #define VENDOR_GRIFFIN          0x001292
33 #define VENDOR_LACIE            0x00d04b
34
35 #define SPECIFIER_1394TA        0x00a02d
36 #define VERSION_AVC             0x010001
37
38 struct device_info {
39         const char *driver_name;
40         const char *short_name;
41         const char *long_name;
42         int (*pcm_constraints)(struct snd_pcm_runtime *runtime);
43         unsigned int mixer_channels;
44         u8 mute_fb_id;
45         u8 volume_fb_id;
46 };
47
48 struct fwspk {
49         struct snd_card *card;
50         struct fw_unit *unit;
51         const struct device_info *device_info;
52         struct mutex mutex;
53         struct cmp_connection connection;
54         struct amdtp_stream stream;
55         bool mute;
56         s16 volume[6];
57         s16 volume_min;
58         s16 volume_max;
59 };
60
61 MODULE_DESCRIPTION("FireWire speakers driver");
62 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
63 MODULE_LICENSE("GPL v2");
64
65 static int firewave_rate_constraint(struct snd_pcm_hw_params *params,
66                                     struct snd_pcm_hw_rule *rule)
67 {
68         static unsigned int stereo_rates[] = { 48000, 96000 };
69         struct snd_interval *channels =
70                         hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
71         struct snd_interval *rate =
72                         hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
73
74         /* two channels work only at 48/96 kHz */
75         if (snd_interval_max(channels) < 6)
76                 return snd_interval_list(rate, 2, stereo_rates, 0);
77         return 0;
78 }
79
80 static int firewave_channels_constraint(struct snd_pcm_hw_params *params,
81                                         struct snd_pcm_hw_rule *rule)
82 {
83         static const struct snd_interval all_channels = { .min = 6, .max = 6 };
84         struct snd_interval *rate =
85                         hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
86         struct snd_interval *channels =
87                         hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
88
89         /* 32/44.1 kHz work only with all six channels */
90         if (snd_interval_max(rate) < 48000)
91                 return snd_interval_refine(channels, &all_channels);
92         return 0;
93 }
94
95 static int firewave_constraints(struct snd_pcm_runtime *runtime)
96 {
97         static unsigned int channels_list[] = { 2, 6 };
98         static struct snd_pcm_hw_constraint_list channels_list_constraint = {
99                 .count = 2,
100                 .list = channels_list,
101         };
102         int err;
103
104         runtime->hw.rates = SNDRV_PCM_RATE_32000 |
105                             SNDRV_PCM_RATE_44100 |
106                             SNDRV_PCM_RATE_48000 |
107                             SNDRV_PCM_RATE_96000;
108         runtime->hw.channels_max = 6;
109
110         err = snd_pcm_hw_constraint_list(runtime, 0,
111                                          SNDRV_PCM_HW_PARAM_CHANNELS,
112                                          &channels_list_constraint);
113         if (err < 0)
114                 return err;
115         err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
116                                   firewave_rate_constraint, NULL,
117                                   SNDRV_PCM_HW_PARAM_CHANNELS, -1);
118         if (err < 0)
119                 return err;
120         err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
121                                   firewave_channels_constraint, NULL,
122                                   SNDRV_PCM_HW_PARAM_RATE, -1);
123         if (err < 0)
124                 return err;
125
126         return 0;
127 }
128
129 static int lacie_speakers_constraints(struct snd_pcm_runtime *runtime)
130 {
131         runtime->hw.rates = SNDRV_PCM_RATE_32000 |
132                             SNDRV_PCM_RATE_44100 |
133                             SNDRV_PCM_RATE_48000 |
134                             SNDRV_PCM_RATE_88200 |
135                             SNDRV_PCM_RATE_96000;
136
137         return 0;
138 }
139
140 static int fwspk_open(struct snd_pcm_substream *substream)
141 {
142         static const struct snd_pcm_hardware hardware = {
143                 .info = SNDRV_PCM_INFO_MMAP |
144                         SNDRV_PCM_INFO_MMAP_VALID |
145                         SNDRV_PCM_INFO_BATCH |
146                         SNDRV_PCM_INFO_INTERLEAVED |
147                         SNDRV_PCM_INFO_BLOCK_TRANSFER,
148                 .formats = AMDTP_OUT_PCM_FORMAT_BITS,
149                 .channels_min = 2,
150                 .channels_max = 2,
151                 .buffer_bytes_max = 4 * 1024 * 1024,
152                 .period_bytes_min = 1,
153                 .period_bytes_max = UINT_MAX,
154                 .periods_min = 1,
155                 .periods_max = UINT_MAX,
156         };
157         struct fwspk *fwspk = substream->private_data;
158         struct snd_pcm_runtime *runtime = substream->runtime;
159         int err;
160
161         runtime->hw = hardware;
162
163         err = fwspk->device_info->pcm_constraints(runtime);
164         if (err < 0)
165                 return err;
166         err = snd_pcm_limit_hw_rates(runtime);
167         if (err < 0)
168                 return err;
169
170         err = amdtp_stream_add_pcm_hw_constraints(&fwspk->stream, runtime);
171         if (err < 0)
172                 return err;
173
174         return 0;
175 }
176
177 static int fwspk_close(struct snd_pcm_substream *substream)
178 {
179         return 0;
180 }
181
182 static void fwspk_stop_stream(struct fwspk *fwspk)
183 {
184         if (amdtp_stream_running(&fwspk->stream)) {
185                 amdtp_stream_stop(&fwspk->stream);
186                 cmp_connection_break(&fwspk->connection);
187         }
188 }
189
190 static int fwspk_set_rate(struct fwspk *fwspk, unsigned int sfc)
191 {
192         u8 *buf;
193         int err;
194
195         buf = kmalloc(8, GFP_KERNEL);
196         if (!buf)
197                 return -ENOMEM;
198
199         buf[0] = 0x00;          /* AV/C, CONTROL */
200         buf[1] = 0xff;          /* unit */
201         buf[2] = 0x19;          /* INPUT PLUG SIGNAL FORMAT */
202         buf[3] = 0x00;          /* plug 0 */
203         buf[4] = 0x90;          /* format: audio */
204         buf[5] = 0x00 | sfc;    /* AM824, frequency */
205         buf[6] = 0xff;          /* SYT (not used) */
206         buf[7] = 0xff;
207
208         err = fcp_avc_transaction(fwspk->unit, buf, 8, buf, 8,
209                                   BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));
210         if (err < 0)
211                 goto error;
212         if (err < 6 || buf[0] != 0x09 /* ACCEPTED */) {
213                 dev_err(&fwspk->unit->device, "failed to set sample rate\n");
214                 err = -EIO;
215                 goto error;
216         }
217
218         err = 0;
219
220 error:
221         kfree(buf);
222
223         return err;
224 }
225
226 static int fwspk_hw_params(struct snd_pcm_substream *substream,
227                            struct snd_pcm_hw_params *hw_params)
228 {
229         struct fwspk *fwspk = substream->private_data;
230         int err;
231
232         mutex_lock(&fwspk->mutex);
233         fwspk_stop_stream(fwspk);
234         mutex_unlock(&fwspk->mutex);
235
236         err = snd_pcm_lib_alloc_vmalloc_buffer(substream,
237                                                params_buffer_bytes(hw_params));
238         if (err < 0)
239                 goto error;
240
241         amdtp_stream_set_parameters(&fwspk->stream,
242                                     params_rate(hw_params),
243                                     params_channels(hw_params),
244                                     0);
245
246         amdtp_stream_set_pcm_format(&fwspk->stream,
247                                     params_format(hw_params));
248
249         err = fwspk_set_rate(fwspk, fwspk->stream.sfc);
250         if (err < 0)
251                 goto err_buffer;
252
253         return 0;
254
255 err_buffer:
256         snd_pcm_lib_free_vmalloc_buffer(substream);
257 error:
258         return err;
259 }
260
261 static int fwspk_hw_free(struct snd_pcm_substream *substream)
262 {
263         struct fwspk *fwspk = substream->private_data;
264
265         mutex_lock(&fwspk->mutex);
266         fwspk_stop_stream(fwspk);
267         mutex_unlock(&fwspk->mutex);
268
269         return snd_pcm_lib_free_vmalloc_buffer(substream);
270 }
271
272 static int fwspk_prepare(struct snd_pcm_substream *substream)
273 {
274         struct fwspk *fwspk = substream->private_data;
275         int err;
276
277         mutex_lock(&fwspk->mutex);
278
279         if (amdtp_streaming_error(&fwspk->stream))
280                 fwspk_stop_stream(fwspk);
281
282         if (!amdtp_stream_running(&fwspk->stream)) {
283                 err = cmp_connection_establish(&fwspk->connection,
284                         amdtp_stream_get_max_payload(&fwspk->stream));
285                 if (err < 0)
286                         goto err_mutex;
287
288                 err = amdtp_stream_start(&fwspk->stream,
289                                          fwspk->connection.resources.channel,
290                                          fwspk->connection.speed);
291                 if (err < 0)
292                         goto err_connection;
293         }
294
295         mutex_unlock(&fwspk->mutex);
296
297         amdtp_stream_pcm_prepare(&fwspk->stream);
298
299         return 0;
300
301 err_connection:
302         cmp_connection_break(&fwspk->connection);
303 err_mutex:
304         mutex_unlock(&fwspk->mutex);
305
306         return err;
307 }
308
309 static int fwspk_trigger(struct snd_pcm_substream *substream, int cmd)
310 {
311         struct fwspk *fwspk = substream->private_data;
312         struct snd_pcm_substream *pcm;
313
314         switch (cmd) {
315         case SNDRV_PCM_TRIGGER_START:
316                 pcm = substream;
317                 break;
318         case SNDRV_PCM_TRIGGER_STOP:
319                 pcm = NULL;
320                 break;
321         default:
322                 return -EINVAL;
323         }
324         amdtp_stream_pcm_trigger(&fwspk->stream, pcm);
325         return 0;
326 }
327
328 static snd_pcm_uframes_t fwspk_pointer(struct snd_pcm_substream *substream)
329 {
330         struct fwspk *fwspk = substream->private_data;
331
332         return amdtp_stream_pcm_pointer(&fwspk->stream);
333 }
334
335 static int fwspk_create_pcm(struct fwspk *fwspk)
336 {
337         static struct snd_pcm_ops ops = {
338                 .open      = fwspk_open,
339                 .close     = fwspk_close,
340                 .ioctl     = snd_pcm_lib_ioctl,
341                 .hw_params = fwspk_hw_params,
342                 .hw_free   = fwspk_hw_free,
343                 .prepare   = fwspk_prepare,
344                 .trigger   = fwspk_trigger,
345                 .pointer   = fwspk_pointer,
346                 .page      = snd_pcm_lib_get_vmalloc_page,
347                 .mmap      = snd_pcm_lib_mmap_vmalloc,
348         };
349         struct snd_pcm *pcm;
350         int err;
351
352         err = snd_pcm_new(fwspk->card, "OXFW970", 0, 1, 0, &pcm);
353         if (err < 0)
354                 return err;
355         pcm->private_data = fwspk;
356         strcpy(pcm->name, fwspk->device_info->short_name);
357         snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &ops);
358         return 0;
359 }
360
361 enum control_action { CTL_READ, CTL_WRITE };
362 enum control_attribute {
363         CTL_MIN         = 0x02,
364         CTL_MAX         = 0x03,
365         CTL_CURRENT     = 0x10,
366 };
367
368 static int fwspk_mute_command(struct fwspk *fwspk, bool *value,
369                               enum control_action action)
370 {
371         u8 *buf;
372         u8 response_ok;
373         int err;
374
375         buf = kmalloc(11, GFP_KERNEL);
376         if (!buf)
377                 return -ENOMEM;
378
379         if (action == CTL_READ) {
380                 buf[0] = 0x01;          /* AV/C, STATUS */
381                 response_ok = 0x0c;     /*       STABLE */
382         } else {
383                 buf[0] = 0x00;          /* AV/C, CONTROL */
384                 response_ok = 0x09;     /*       ACCEPTED */
385         }
386         buf[1] = 0x08;                  /* audio unit 0 */
387         buf[2] = 0xb8;                  /* FUNCTION BLOCK */
388         buf[3] = 0x81;                  /* function block type: feature */
389         buf[4] = fwspk->device_info->mute_fb_id; /* function block ID */
390         buf[5] = 0x10;                  /* control attribute: current */
391         buf[6] = 0x02;                  /* selector length */
392         buf[7] = 0x00;                  /* audio channel number */
393         buf[8] = 0x01;                  /* control selector: mute */
394         buf[9] = 0x01;                  /* control data length */
395         if (action == CTL_READ)
396                 buf[10] = 0xff;
397         else
398                 buf[10] = *value ? 0x70 : 0x60;
399
400         err = fcp_avc_transaction(fwspk->unit, buf, 11, buf, 11, 0x3fe);
401         if (err < 0)
402                 goto error;
403         if (err < 11) {
404                 dev_err(&fwspk->unit->device, "short FCP response\n");
405                 err = -EIO;
406                 goto error;
407         }
408         if (buf[0] != response_ok) {
409                 dev_err(&fwspk->unit->device, "mute command failed\n");
410                 err = -EIO;
411                 goto error;
412         }
413         if (action == CTL_READ)
414                 *value = buf[10] == 0x70;
415
416         err = 0;
417
418 error:
419         kfree(buf);
420
421         return err;
422 }
423
424 static int fwspk_volume_command(struct fwspk *fwspk, s16 *value,
425                                 unsigned int channel,
426                                 enum control_attribute attribute,
427                                 enum control_action action)
428 {
429         u8 *buf;
430         u8 response_ok;
431         int err;
432
433         buf = kmalloc(12, GFP_KERNEL);
434         if (!buf)
435                 return -ENOMEM;
436
437         if (action == CTL_READ) {
438                 buf[0] = 0x01;          /* AV/C, STATUS */
439                 response_ok = 0x0c;     /*       STABLE */
440         } else {
441                 buf[0] = 0x00;          /* AV/C, CONTROL */
442                 response_ok = 0x09;     /*       ACCEPTED */
443         }
444         buf[1] = 0x08;                  /* audio unit 0 */
445         buf[2] = 0xb8;                  /* FUNCTION BLOCK */
446         buf[3] = 0x81;                  /* function block type: feature */
447         buf[4] = fwspk->device_info->volume_fb_id; /* function block ID */
448         buf[5] = attribute;             /* control attribute */
449         buf[6] = 0x02;                  /* selector length */
450         buf[7] = channel;               /* audio channel number */
451         buf[8] = 0x02;                  /* control selector: volume */
452         buf[9] = 0x02;                  /* control data length */
453         if (action == CTL_READ) {
454                 buf[10] = 0xff;
455                 buf[11] = 0xff;
456         } else {
457                 buf[10] = *value >> 8;
458                 buf[11] = *value;
459         }
460
461         err = fcp_avc_transaction(fwspk->unit, buf, 12, buf, 12, 0x3fe);
462         if (err < 0)
463                 goto error;
464         if (err < 12) {
465                 dev_err(&fwspk->unit->device, "short FCP response\n");
466                 err = -EIO;
467                 goto error;
468         }
469         if (buf[0] != response_ok) {
470                 dev_err(&fwspk->unit->device, "volume command failed\n");
471                 err = -EIO;
472                 goto error;
473         }
474         if (action == CTL_READ)
475                 *value = (buf[10] << 8) | buf[11];
476
477         err = 0;
478
479 error:
480         kfree(buf);
481
482         return err;
483 }
484
485 static int fwspk_mute_get(struct snd_kcontrol *control,
486                           struct snd_ctl_elem_value *value)
487 {
488         struct fwspk *fwspk = control->private_data;
489
490         value->value.integer.value[0] = !fwspk->mute;
491
492         return 0;
493 }
494
495 static int fwspk_mute_put(struct snd_kcontrol *control,
496                           struct snd_ctl_elem_value *value)
497 {
498         struct fwspk *fwspk = control->private_data;
499         bool mute;
500         int err;
501
502         mute = !value->value.integer.value[0];
503
504         if (mute == fwspk->mute)
505                 return 0;
506
507         err = fwspk_mute_command(fwspk, &mute, CTL_WRITE);
508         if (err < 0)
509                 return err;
510         fwspk->mute = mute;
511
512         return 1;
513 }
514
515 static int fwspk_volume_info(struct snd_kcontrol *control,
516                              struct snd_ctl_elem_info *info)
517 {
518         struct fwspk *fwspk = control->private_data;
519
520         info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
521         info->count = fwspk->device_info->mixer_channels;
522         info->value.integer.min = fwspk->volume_min;
523         info->value.integer.max = fwspk->volume_max;
524
525         return 0;
526 }
527
528 static const u8 channel_map[6] = { 0, 1, 4, 5, 2, 3 };
529
530 static int fwspk_volume_get(struct snd_kcontrol *control,
531                             struct snd_ctl_elem_value *value)
532 {
533         struct fwspk *fwspk = control->private_data;
534         unsigned int i;
535
536         for (i = 0; i < fwspk->device_info->mixer_channels; ++i)
537                 value->value.integer.value[channel_map[i]] = fwspk->volume[i];
538
539         return 0;
540 }
541
542 static int fwspk_volume_put(struct snd_kcontrol *control,
543                           struct snd_ctl_elem_value *value)
544 {
545         struct fwspk *fwspk = control->private_data;
546         unsigned int i, changed_channels;
547         bool equal_values = true;
548         s16 volume;
549         int err;
550
551         for (i = 0; i < fwspk->device_info->mixer_channels; ++i) {
552                 if (value->value.integer.value[i] < fwspk->volume_min ||
553                     value->value.integer.value[i] > fwspk->volume_max)
554                         return -EINVAL;
555                 if (value->value.integer.value[i] !=
556                     value->value.integer.value[0])
557                         equal_values = false;
558         }
559
560         changed_channels = 0;
561         for (i = 0; i < fwspk->device_info->mixer_channels; ++i)
562                 if (value->value.integer.value[channel_map[i]] !=
563                                                         fwspk->volume[i])
564                         changed_channels |= 1 << (i + 1);
565
566         if (equal_values && changed_channels != 0)
567                 changed_channels = 1 << 0;
568
569         for (i = 0; i <= fwspk->device_info->mixer_channels; ++i) {
570                 volume = value->value.integer.value[channel_map[i ? i - 1 : 0]];
571                 if (changed_channels & (1 << i)) {
572                         err = fwspk_volume_command(fwspk, &volume, i,
573                                                    CTL_CURRENT, CTL_WRITE);
574                         if (err < 0)
575                                 return err;
576                 }
577                 if (i > 0)
578                         fwspk->volume[i - 1] = volume;
579         }
580
581         return changed_channels != 0;
582 }
583
584 static int fwspk_create_mixer(struct fwspk *fwspk)
585 {
586         static const struct snd_kcontrol_new controls[] = {
587                 {
588                         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
589                         .name = "PCM Playback Switch",
590                         .info = snd_ctl_boolean_mono_info,
591                         .get = fwspk_mute_get,
592                         .put = fwspk_mute_put,
593                 },
594                 {
595                         .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
596                         .name = "PCM Playback Volume",
597                         .info = fwspk_volume_info,
598                         .get = fwspk_volume_get,
599                         .put = fwspk_volume_put,
600                 },
601         };
602         unsigned int i, first_ch;
603         int err;
604
605         err = fwspk_volume_command(fwspk, &fwspk->volume_min,
606                                    0, CTL_MIN, CTL_READ);
607         if (err < 0)
608                 return err;
609         err = fwspk_volume_command(fwspk, &fwspk->volume_max,
610                                    0, CTL_MAX, CTL_READ);
611         if (err < 0)
612                 return err;
613
614         err = fwspk_mute_command(fwspk, &fwspk->mute, CTL_READ);
615         if (err < 0)
616                 return err;
617
618         first_ch = fwspk->device_info->mixer_channels == 1 ? 0 : 1;
619         for (i = 0; i < fwspk->device_info->mixer_channels; ++i) {
620                 err = fwspk_volume_command(fwspk, &fwspk->volume[i],
621                                            first_ch + i, CTL_CURRENT, CTL_READ);
622                 if (err < 0)
623                         return err;
624         }
625
626         for (i = 0; i < ARRAY_SIZE(controls); ++i) {
627                 err = snd_ctl_add(fwspk->card,
628                                   snd_ctl_new1(&controls[i], fwspk));
629                 if (err < 0)
630                         return err;
631         }
632
633         return 0;
634 }
635
636 static u32 fwspk_read_firmware_version(struct fw_unit *unit)
637 {
638         __be32 data;
639         int err;
640
641         err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,
642                                  OXFORD_FIRMWARE_ID_ADDRESS, &data, 4, 0);
643         return err >= 0 ? be32_to_cpu(data) : 0;
644 }
645
646 static void fwspk_card_free(struct snd_card *card)
647 {
648         struct fwspk *fwspk = card->private_data;
649
650         amdtp_stream_destroy(&fwspk->stream);
651         cmp_connection_destroy(&fwspk->connection);
652         fw_unit_put(fwspk->unit);
653         mutex_destroy(&fwspk->mutex);
654 }
655
656 static int fwspk_probe(struct fw_unit *unit,
657                        const struct ieee1394_device_id *id)
658 {
659         struct fw_device *fw_dev = fw_parent_device(unit);
660         struct snd_card *card;
661         struct fwspk *fwspk;
662         u32 firmware;
663         int err;
664
665         err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
666                            sizeof(*fwspk), &card);
667         if (err < 0)
668                 return err;
669
670         fwspk = card->private_data;
671         fwspk->card = card;
672         mutex_init(&fwspk->mutex);
673         fwspk->unit = fw_unit_get(unit);
674         fwspk->device_info = (const struct device_info *)id->driver_data;
675
676         err = cmp_connection_init(&fwspk->connection, unit, 0);
677         if (err < 0)
678                 goto err_unit;
679
680         err = amdtp_stream_init(&fwspk->stream, unit, AMDTP_OUT_STREAM,
681                                 CIP_NONBLOCKING);
682         if (err < 0)
683                 goto err_connection;
684
685         card->private_free = fwspk_card_free;
686
687         strcpy(card->driver, fwspk->device_info->driver_name);
688         strcpy(card->shortname, fwspk->device_info->short_name);
689         firmware = fwspk_read_firmware_version(unit);
690         snprintf(card->longname, sizeof(card->longname),
691                  "%s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
692                  fwspk->device_info->long_name,
693                  firmware >> 20, firmware & 0xffff,
694                  fw_dev->config_rom[3], fw_dev->config_rom[4],
695                  dev_name(&unit->device), 100 << fw_dev->max_speed);
696         strcpy(card->mixername, "OXFW970");
697
698         err = fwspk_create_pcm(fwspk);
699         if (err < 0)
700                 goto error;
701
702         err = fwspk_create_mixer(fwspk);
703         if (err < 0)
704                 goto error;
705
706         err = snd_card_register(card);
707         if (err < 0)
708                 goto error;
709
710         dev_set_drvdata(&unit->device, fwspk);
711
712         return 0;
713
714 err_connection:
715         cmp_connection_destroy(&fwspk->connection);
716 err_unit:
717         fw_unit_put(fwspk->unit);
718         mutex_destroy(&fwspk->mutex);
719 error:
720         snd_card_free(card);
721         return err;
722 }
723
724 static void fwspk_bus_reset(struct fw_unit *unit)
725 {
726         struct fwspk *fwspk = dev_get_drvdata(&unit->device);
727
728         fcp_bus_reset(fwspk->unit);
729
730         if (cmp_connection_update(&fwspk->connection) < 0) {
731                 amdtp_stream_pcm_abort(&fwspk->stream);
732                 mutex_lock(&fwspk->mutex);
733                 fwspk_stop_stream(fwspk);
734                 mutex_unlock(&fwspk->mutex);
735                 return;
736         }
737
738         amdtp_stream_update(&fwspk->stream);
739 }
740
741 static void fwspk_remove(struct fw_unit *unit)
742 {
743         struct fwspk *fwspk = dev_get_drvdata(&unit->device);
744
745         amdtp_stream_pcm_abort(&fwspk->stream);
746         snd_card_disconnect(fwspk->card);
747
748         mutex_lock(&fwspk->mutex);
749         fwspk_stop_stream(fwspk);
750         mutex_unlock(&fwspk->mutex);
751
752         snd_card_free_when_closed(fwspk->card);
753 }
754
755 static const struct device_info griffin_firewave = {
756         .driver_name = "FireWave",
757         .short_name  = "FireWave",
758         .long_name   = "Griffin FireWave Surround",
759         .pcm_constraints = firewave_constraints,
760         .mixer_channels = 6,
761         .mute_fb_id   = 0x01,
762         .volume_fb_id = 0x02,
763 };
764
765 static const struct device_info lacie_speakers = {
766         .driver_name = "FWSpeakers",
767         .short_name  = "FireWire Speakers",
768         .long_name   = "LaCie FireWire Speakers",
769         .pcm_constraints = lacie_speakers_constraints,
770         .mixer_channels = 1,
771         .mute_fb_id   = 0x01,
772         .volume_fb_id = 0x01,
773 };
774
775 static const struct ieee1394_device_id fwspk_id_table[] = {
776         {
777                 .match_flags  = IEEE1394_MATCH_VENDOR_ID |
778                                 IEEE1394_MATCH_MODEL_ID |
779                                 IEEE1394_MATCH_SPECIFIER_ID |
780                                 IEEE1394_MATCH_VERSION,
781                 .vendor_id    = VENDOR_GRIFFIN,
782                 .model_id     = 0x00f970,
783                 .specifier_id = SPECIFIER_1394TA,
784                 .version      = VERSION_AVC,
785                 .driver_data  = (kernel_ulong_t)&griffin_firewave,
786         },
787         {
788                 .match_flags  = IEEE1394_MATCH_VENDOR_ID |
789                                 IEEE1394_MATCH_MODEL_ID |
790                                 IEEE1394_MATCH_SPECIFIER_ID |
791                                 IEEE1394_MATCH_VERSION,
792                 .vendor_id    = VENDOR_LACIE,
793                 .model_id     = 0x00f970,
794                 .specifier_id = SPECIFIER_1394TA,
795                 .version      = VERSION_AVC,
796                 .driver_data  = (kernel_ulong_t)&lacie_speakers,
797         },
798         { }
799 };
800 MODULE_DEVICE_TABLE(ieee1394, fwspk_id_table);
801
802 static struct fw_driver fwspk_driver = {
803         .driver   = {
804                 .owner  = THIS_MODULE,
805                 .name   = KBUILD_MODNAME,
806                 .bus    = &fw_bus_type,
807         },
808         .probe    = fwspk_probe,
809         .update   = fwspk_bus_reset,
810         .remove   = fwspk_remove,
811         .id_table = fwspk_id_table,
812 };
813
814 static int __init alsa_fwspk_init(void)
815 {
816         return driver_register(&fwspk_driver.driver);
817 }
818
819 static void __exit alsa_fwspk_exit(void)
820 {
821         driver_unregister(&fwspk_driver.driver);
822 }
823
824 module_init(alsa_fwspk_init);
825 module_exit(alsa_fwspk_exit);