xref: /openbmc/linux/sound/soc/qcom/qdsp6/q6dsp-common.c (revision 2612e3bbc0386368a850140a6c9b990cd496a5ec)
14dddbddbSSrinivas Kandagatla // SPDX-License-Identifier: GPL-2.0
24dddbddbSSrinivas Kandagatla // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
34dddbddbSSrinivas Kandagatla // Copyright (c) 2018, Linaro Limited
44dddbddbSSrinivas Kandagatla 
54dddbddbSSrinivas Kandagatla #include "q6dsp-common.h"
64dddbddbSSrinivas Kandagatla #include <linux/kernel.h>
74dddbddbSSrinivas Kandagatla #include <linux/module.h>
84dddbddbSSrinivas Kandagatla #include <linux/string.h>
94dddbddbSSrinivas Kandagatla #include <linux/errno.h>
104dddbddbSSrinivas Kandagatla 
q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_CHANNEL],int ch)114dddbddbSSrinivas Kandagatla int q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_CHANNEL], int ch)
124dddbddbSSrinivas Kandagatla {
134dddbddbSSrinivas Kandagatla 	memset(ch_map, 0, PCM_MAX_NUM_CHANNEL);
144dddbddbSSrinivas Kandagatla 
154dddbddbSSrinivas Kandagatla 	switch (ch) {
164dddbddbSSrinivas Kandagatla 	case 1:
174dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FC;
184dddbddbSSrinivas Kandagatla 		break;
194dddbddbSSrinivas Kandagatla 	case 2:
204dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
214dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
224dddbddbSSrinivas Kandagatla 		break;
234dddbddbSSrinivas Kandagatla 	case 3:
244dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
254dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
264dddbddbSSrinivas Kandagatla 		ch_map[2] = PCM_CHANNEL_FC;
274dddbddbSSrinivas Kandagatla 		break;
284dddbddbSSrinivas Kandagatla 	case 4:
294dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
304dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
314dddbddbSSrinivas Kandagatla 		ch_map[2] = PCM_CHANNEL_LS;
324dddbddbSSrinivas Kandagatla 		ch_map[3] = PCM_CHANNEL_RS;
334dddbddbSSrinivas Kandagatla 		break;
344dddbddbSSrinivas Kandagatla 	case 5:
354dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
364dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
374dddbddbSSrinivas Kandagatla 		ch_map[2] = PCM_CHANNEL_FC;
384dddbddbSSrinivas Kandagatla 		ch_map[3] = PCM_CHANNEL_LS;
394dddbddbSSrinivas Kandagatla 		ch_map[4] = PCM_CHANNEL_RS;
404dddbddbSSrinivas Kandagatla 		break;
414dddbddbSSrinivas Kandagatla 	case 6:
424dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
434dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
444dddbddbSSrinivas Kandagatla 		ch_map[2] = PCM_CHANNEL_LFE;
454dddbddbSSrinivas Kandagatla 		ch_map[3] = PCM_CHANNEL_FC;
464dddbddbSSrinivas Kandagatla 		ch_map[4] = PCM_CHANNEL_LS;
474dddbddbSSrinivas Kandagatla 		ch_map[5] = PCM_CHANNEL_RS;
484dddbddbSSrinivas Kandagatla 		break;
494dddbddbSSrinivas Kandagatla 	case 8:
504dddbddbSSrinivas Kandagatla 		ch_map[0] = PCM_CHANNEL_FL;
514dddbddbSSrinivas Kandagatla 		ch_map[1] = PCM_CHANNEL_FR;
524dddbddbSSrinivas Kandagatla 		ch_map[2] = PCM_CHANNEL_LFE;
534dddbddbSSrinivas Kandagatla 		ch_map[3] = PCM_CHANNEL_FC;
544dddbddbSSrinivas Kandagatla 		ch_map[4] = PCM_CHANNEL_LS;
554dddbddbSSrinivas Kandagatla 		ch_map[5] = PCM_CHANNEL_RS;
564dddbddbSSrinivas Kandagatla 		ch_map[6] = PCM_CHANNEL_LB;
574dddbddbSSrinivas Kandagatla 		ch_map[7] = PCM_CHANNEL_RB;
584dddbddbSSrinivas Kandagatla 		break;
594dddbddbSSrinivas Kandagatla 	default:
604dddbddbSSrinivas Kandagatla 		return -EINVAL;
614dddbddbSSrinivas Kandagatla 	}
624dddbddbSSrinivas Kandagatla 
634dddbddbSSrinivas Kandagatla 	return 0;
644dddbddbSSrinivas Kandagatla }
654dddbddbSSrinivas Kandagatla EXPORT_SYMBOL_GPL(q6dsp_map_channels);
66*4c2be53fSSrinivas Kandagatla 
q6dsp_get_channel_allocation(int channels)67*4c2be53fSSrinivas Kandagatla int q6dsp_get_channel_allocation(int channels)
68*4c2be53fSSrinivas Kandagatla {
69*4c2be53fSSrinivas Kandagatla 	int channel_allocation;
70*4c2be53fSSrinivas Kandagatla 
71*4c2be53fSSrinivas Kandagatla 	/* HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4 */
72*4c2be53fSSrinivas Kandagatla 	switch (channels) {
73*4c2be53fSSrinivas Kandagatla 	case 2:
74*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0;
75*4c2be53fSSrinivas Kandagatla 		break;
76*4c2be53fSSrinivas Kandagatla 	case 3:
77*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x02;
78*4c2be53fSSrinivas Kandagatla 		break;
79*4c2be53fSSrinivas Kandagatla 	case 4:
80*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x06;
81*4c2be53fSSrinivas Kandagatla 		break;
82*4c2be53fSSrinivas Kandagatla 	case 5:
83*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x0A;
84*4c2be53fSSrinivas Kandagatla 		break;
85*4c2be53fSSrinivas Kandagatla 	case 6:
86*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x0B;
87*4c2be53fSSrinivas Kandagatla 		break;
88*4c2be53fSSrinivas Kandagatla 	case 7:
89*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x12;
90*4c2be53fSSrinivas Kandagatla 		break;
91*4c2be53fSSrinivas Kandagatla 	case 8:
92*4c2be53fSSrinivas Kandagatla 		channel_allocation = 0x13;
93*4c2be53fSSrinivas Kandagatla 		break;
94*4c2be53fSSrinivas Kandagatla 	default:
95*4c2be53fSSrinivas Kandagatla 		return -EINVAL;
96*4c2be53fSSrinivas Kandagatla 	}
97*4c2be53fSSrinivas Kandagatla 
98*4c2be53fSSrinivas Kandagatla 	return channel_allocation;
99*4c2be53fSSrinivas Kandagatla }
100*4c2be53fSSrinivas Kandagatla EXPORT_SYMBOL_GPL(q6dsp_get_channel_allocation);
1014dddbddbSSrinivas Kandagatla MODULE_LICENSE("GPL v2");
102