af8203b9d1a634c5928590418fac9b74ac5ae263
[linux-2.6-microblaze.git] / sound / firewire / dice / dice-tcelectronic.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * dice-tc_electronic.c - a part of driver for DICE based devices
4  *
5  * Copyright (c) 2018 Takashi Sakamoto
6  */
7
8 #include "dice.h"
9
10 struct dice_tc_spec {
11         unsigned int tx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
12         unsigned int rx_pcm_chs[MAX_STREAMS][SND_DICE_RATE_MODE_COUNT];
13         bool has_midi;
14 };
15
16 static const struct dice_tc_spec desktop_konnekt6 = {
17         .tx_pcm_chs = {{6, 6, 2}, {0, 0, 0} },
18         .rx_pcm_chs = {{6, 6, 4}, {0, 0, 0} },
19         .has_midi = false,
20 };
21
22 static const struct dice_tc_spec impact_twin = {
23         .tx_pcm_chs = {{14, 10, 6}, {0, 0, 0} },
24         .rx_pcm_chs = {{14, 10, 6}, {0, 0, 0} },
25         .has_midi = true,
26 };
27
28 static const struct dice_tc_spec konnekt_8 = {
29         .tx_pcm_chs = {{4, 4, 3}, {0, 0, 0} },
30         .rx_pcm_chs = {{4, 4, 3}, {0, 0, 0} },
31         .has_midi = true,
32 };
33
34 static const struct dice_tc_spec konnekt_24d = {
35         .tx_pcm_chs = {{16, 16, 6}, {0, 0, 0} },
36         .rx_pcm_chs = {{16, 16, 6}, {0, 0, 0} },
37         .has_midi = true,
38 };
39
40 static const struct dice_tc_spec konnekt_live = {
41         .tx_pcm_chs = {{16, 16, 16}, {0, 0, 0} },
42         .rx_pcm_chs = {{16, 16, 16}, {0, 0, 0} },
43         .has_midi = true,
44 };
45
46 static const struct dice_tc_spec studio_konnekt_48 = {
47         .tx_pcm_chs = {{16, 16, 16}, {16, 16, 0} },
48         .rx_pcm_chs = {{16, 16, 16}, {16, 16, 0} },
49         .has_midi = true,
50 };
51
52 int snd_dice_detect_tcelectronic_formats(struct snd_dice *dice)
53 {
54         static const struct {
55                 u32 model_id;
56                 const struct dice_tc_spec *spec;
57         } *entry, entries[] = {
58                 {0x00000020, &konnekt_24d},
59                 {0x00000021, &konnekt_8},
60                 {0x00000022, &studio_konnekt_48},
61                 {0x00000023, &konnekt_live},
62                 {0x00000024, &desktop_konnekt6},
63                 {0x00000027, &impact_twin},
64         };
65         struct fw_csr_iterator it;
66         int key, val, model_id;
67         int i;
68
69         model_id = 0;
70         fw_csr_iterator_init(&it, dice->unit->directory);
71         while (fw_csr_iterator_next(&it, &key, &val)) {
72                 if (key == CSR_MODEL) {
73                         model_id = val;
74                         break;
75                 }
76         }
77
78         entry = NULL;
79         for (i = 0; i < ARRAY_SIZE(entries); ++i) {
80                 entry = entries + i;
81                 if (entry->model_id == model_id)
82                         break;
83         }
84         if (!entry)
85                 return -ENODEV;
86
87         memcpy(dice->tx_pcm_chs, entry->spec->tx_pcm_chs,
88                MAX_STREAMS * SND_DICE_RATE_MODE_COUNT * sizeof(unsigned int));
89         memcpy(dice->rx_pcm_chs, entry->spec->rx_pcm_chs,
90                MAX_STREAMS * SND_DICE_RATE_MODE_COUNT * sizeof(unsigned int));
91
92         for (i = 0; i < MAX_STREAMS; ++i) {
93                 if (entry->spec->has_midi) {
94                         dice->tx_midi_ports[i] = 1;
95                         dice->rx_midi_ports[i] = 1;
96                 }
97         }
98
99         return 0;
100 }