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 
q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_CHANNEL],int ch)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 
q6dsp_get_channel_allocation(int channels)67 int q6dsp_get_channel_allocation(int channels)
68 {
69 	int channel_allocation;
70 
71 	/* HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4 */
72 	switch (channels) {
73 	case 2:
74 		channel_allocation = 0;
75 		break;
76 	case 3:
77 		channel_allocation = 0x02;
78 		break;
79 	case 4:
80 		channel_allocation = 0x06;
81 		break;
82 	case 5:
83 		channel_allocation = 0x0A;
84 		break;
85 	case 6:
86 		channel_allocation = 0x0B;
87 		break;
88 	case 7:
89 		channel_allocation = 0x12;
90 		break;
91 	case 8:
92 		channel_allocation = 0x13;
93 		break;
94 	default:
95 		return -EINVAL;
96 	}
97 
98 	return channel_allocation;
99 }
100 EXPORT_SYMBOL_GPL(q6dsp_get_channel_allocation);
101 MODULE_LICENSE("GPL v2");
102