1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2018, Linaro Limited
4 
5 #include "q6dsp-common.h"
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/string.h>
9 #include <linux/errno.h>
10 
11 int q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_CHANNEL], int ch)
12 {
13 	memset(ch_map, 0, PCM_MAX_NUM_CHANNEL);
14 
15 	switch (ch) {
16 	case 1:
17 		ch_map[0] = PCM_CHANNEL_FC;
18 		break;
19 	case 2:
20 		ch_map[0] = PCM_CHANNEL_FL;
21 		ch_map[1] = PCM_CHANNEL_FR;
22 		break;
23 	case 3:
24 		ch_map[0] = PCM_CHANNEL_FL;
25 		ch_map[1] = PCM_CHANNEL_FR;
26 		ch_map[2] = PCM_CHANNEL_FC;
27 		break;
28 	case 4:
29 		ch_map[0] = PCM_CHANNEL_FL;
30 		ch_map[1] = PCM_CHANNEL_FR;
31 		ch_map[2] = PCM_CHANNEL_LS;
32 		ch_map[3] = PCM_CHANNEL_RS;
33 		break;
34 	case 5:
35 		ch_map[0] = PCM_CHANNEL_FL;
36 		ch_map[1] = PCM_CHANNEL_FR;
37 		ch_map[2] = PCM_CHANNEL_FC;
38 		ch_map[3] = PCM_CHANNEL_LS;
39 		ch_map[4] = PCM_CHANNEL_RS;
40 		break;
41 	case 6:
42 		ch_map[0] = PCM_CHANNEL_FL;
43 		ch_map[1] = PCM_CHANNEL_FR;
44 		ch_map[2] = PCM_CHANNEL_LFE;
45 		ch_map[3] = PCM_CHANNEL_FC;
46 		ch_map[4] = PCM_CHANNEL_LS;
47 		ch_map[5] = PCM_CHANNEL_RS;
48 		break;
49 	case 8:
50 		ch_map[0] = PCM_CHANNEL_FL;
51 		ch_map[1] = PCM_CHANNEL_FR;
52 		ch_map[2] = PCM_CHANNEL_LFE;
53 		ch_map[3] = PCM_CHANNEL_FC;
54 		ch_map[4] = PCM_CHANNEL_LS;
55 		ch_map[5] = PCM_CHANNEL_RS;
56 		ch_map[6] = PCM_CHANNEL_LB;
57 		ch_map[7] = PCM_CHANNEL_RB;
58 		break;
59 	default:
60 		return -EINVAL;
61 	}
62 
63 	return 0;
64 }
65 EXPORT_SYMBOL_GPL(q6dsp_map_channels);
66 MODULE_LICENSE("GPL v2");
67