1 // SPDX-License-Identifier: GPL-2.0
2 // dice-presonus.c - a part of driver for DICE based devices
3 //
4 // Copyright (c) 2019 Takashi Sakamoto
5 //
6 // Licensed under the terms of the GNU General Public License, version 2.
7 
8 #include "dice.h"
9 
10 struct dice_presonus_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_presonus_spec dice_presonus_firesutio = {
17 	.tx_pcm_chs = {{16, 16, 0}, {10, 2, 0} },
18 	.rx_pcm_chs = {{16, 16, 0}, {10, 2, 0} },
19 	.has_midi = true,
20 };
21 
22 int snd_dice_detect_presonus_formats(struct snd_dice *dice)
23 {
24 	static const struct {
25 		u32 model_id;
26 		const struct dice_presonus_spec *spec;
27 	} *entry, entries[] = {
28 		{0x000008, &dice_presonus_firesutio},
29 	};
30 	struct fw_csr_iterator it;
31 	int key, val, model_id;
32 	int i;
33 
34 	model_id = 0;
35 	fw_csr_iterator_init(&it, dice->unit->directory);
36 	while (fw_csr_iterator_next(&it, &key, &val)) {
37 		if (key == CSR_MODEL) {
38 			model_id = val;
39 			break;
40 		}
41 	}
42 
43 	for (i = 0; i < ARRAY_SIZE(entries); ++i) {
44 		entry = entries + i;
45 		if (entry->model_id == model_id)
46 			break;
47 	}
48 	if (i == ARRAY_SIZE(entries))
49 		return -ENODEV;
50 
51 	memcpy(dice->tx_pcm_chs, entry->spec->tx_pcm_chs,
52 	       MAX_STREAMS * SND_DICE_RATE_MODE_COUNT * sizeof(unsigned int));
53 	memcpy(dice->rx_pcm_chs, entry->spec->rx_pcm_chs,
54 	       MAX_STREAMS * SND_DICE_RATE_MODE_COUNT * sizeof(unsigned int));
55 
56 	if (entry->spec->has_midi) {
57 		dice->tx_midi_ports[0] = 1;
58 		dice->rx_midi_ports[0] = 1;
59 	}
60 
61 	return 0;
62 }
63