1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2011-2017, The Linux Foundati 2 // Copyright (c) 2011-2017, The Linux Foundation. All rights reserved. 3 // Copyright (c) 2018, Linaro Limited 3 // Copyright (c) 2018, Linaro Limited 4 4 5 #include "q6dsp-common.h" 5 #include "q6dsp-common.h" 6 #include <linux/kernel.h> 6 #include <linux/kernel.h> 7 #include <linux/module.h> 7 #include <linux/module.h> 8 #include <linux/string.h> 8 #include <linux/string.h> 9 #include <linux/errno.h> 9 #include <linux/errno.h> 10 10 11 int q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_C 11 int q6dsp_map_channels(u8 ch_map[PCM_MAX_NUM_CHANNEL], int ch) 12 { 12 { 13 memset(ch_map, 0, PCM_MAX_NUM_CHANNEL) 13 memset(ch_map, 0, PCM_MAX_NUM_CHANNEL); 14 14 15 switch (ch) { 15 switch (ch) { 16 case 1: 16 case 1: 17 ch_map[0] = PCM_CHANNEL_FC; 17 ch_map[0] = PCM_CHANNEL_FC; 18 break; 18 break; 19 case 2: 19 case 2: 20 ch_map[0] = PCM_CHANNEL_FL; 20 ch_map[0] = PCM_CHANNEL_FL; 21 ch_map[1] = PCM_CHANNEL_FR; 21 ch_map[1] = PCM_CHANNEL_FR; 22 break; 22 break; 23 case 3: 23 case 3: 24 ch_map[0] = PCM_CHANNEL_FL; 24 ch_map[0] = PCM_CHANNEL_FL; 25 ch_map[1] = PCM_CHANNEL_FR; 25 ch_map[1] = PCM_CHANNEL_FR; 26 ch_map[2] = PCM_CHANNEL_FC; 26 ch_map[2] = PCM_CHANNEL_FC; 27 break; 27 break; 28 case 4: 28 case 4: 29 ch_map[0] = PCM_CHANNEL_FL; 29 ch_map[0] = PCM_CHANNEL_FL; 30 ch_map[1] = PCM_CHANNEL_FR; 30 ch_map[1] = PCM_CHANNEL_FR; 31 ch_map[2] = PCM_CHANNEL_LS; 31 ch_map[2] = PCM_CHANNEL_LS; 32 ch_map[3] = PCM_CHANNEL_RS; 32 ch_map[3] = PCM_CHANNEL_RS; 33 break; 33 break; 34 case 5: 34 case 5: 35 ch_map[0] = PCM_CHANNEL_FL; 35 ch_map[0] = PCM_CHANNEL_FL; 36 ch_map[1] = PCM_CHANNEL_FR; 36 ch_map[1] = PCM_CHANNEL_FR; 37 ch_map[2] = PCM_CHANNEL_FC; 37 ch_map[2] = PCM_CHANNEL_FC; 38 ch_map[3] = PCM_CHANNEL_LS; 38 ch_map[3] = PCM_CHANNEL_LS; 39 ch_map[4] = PCM_CHANNEL_RS; 39 ch_map[4] = PCM_CHANNEL_RS; 40 break; 40 break; 41 case 6: 41 case 6: 42 ch_map[0] = PCM_CHANNEL_FL; 42 ch_map[0] = PCM_CHANNEL_FL; 43 ch_map[1] = PCM_CHANNEL_FR; 43 ch_map[1] = PCM_CHANNEL_FR; 44 ch_map[2] = PCM_CHANNEL_LFE; 44 ch_map[2] = PCM_CHANNEL_LFE; 45 ch_map[3] = PCM_CHANNEL_FC; 45 ch_map[3] = PCM_CHANNEL_FC; 46 ch_map[4] = PCM_CHANNEL_LS; 46 ch_map[4] = PCM_CHANNEL_LS; 47 ch_map[5] = PCM_CHANNEL_RS; 47 ch_map[5] = PCM_CHANNEL_RS; 48 break; 48 break; 49 case 8: 49 case 8: 50 ch_map[0] = PCM_CHANNEL_FL; 50 ch_map[0] = PCM_CHANNEL_FL; 51 ch_map[1] = PCM_CHANNEL_FR; 51 ch_map[1] = PCM_CHANNEL_FR; 52 ch_map[2] = PCM_CHANNEL_LFE; 52 ch_map[2] = PCM_CHANNEL_LFE; 53 ch_map[3] = PCM_CHANNEL_FC; 53 ch_map[3] = PCM_CHANNEL_FC; 54 ch_map[4] = PCM_CHANNEL_LS; 54 ch_map[4] = PCM_CHANNEL_LS; 55 ch_map[5] = PCM_CHANNEL_RS; 55 ch_map[5] = PCM_CHANNEL_RS; 56 ch_map[6] = PCM_CHANNEL_LB; 56 ch_map[6] = PCM_CHANNEL_LB; 57 ch_map[7] = PCM_CHANNEL_RB; 57 ch_map[7] = PCM_CHANNEL_RB; 58 break; 58 break; 59 default: 59 default: 60 return -EINVAL; 60 return -EINVAL; 61 } 61 } 62 62 63 return 0; 63 return 0; 64 } 64 } 65 EXPORT_SYMBOL_GPL(q6dsp_map_channels); 65 EXPORT_SYMBOL_GPL(q6dsp_map_channels); 66 66 67 int q6dsp_get_channel_allocation(int channels) 67 int q6dsp_get_channel_allocation(int channels) 68 { 68 { 69 int channel_allocation; 69 int channel_allocation; 70 70 71 /* HDMI spec CEA-861-E: Table 28 Audio 71 /* HDMI spec CEA-861-E: Table 28 Audio InfoFrame Data Byte 4 */ 72 switch (channels) { 72 switch (channels) { 73 case 2: 73 case 2: 74 channel_allocation = 0; 74 channel_allocation = 0; 75 break; 75 break; 76 case 3: 76 case 3: 77 channel_allocation = 0x02; 77 channel_allocation = 0x02; 78 break; 78 break; 79 case 4: 79 case 4: 80 channel_allocation = 0x06; 80 channel_allocation = 0x06; 81 break; 81 break; 82 case 5: 82 case 5: 83 channel_allocation = 0x0A; 83 channel_allocation = 0x0A; 84 break; 84 break; 85 case 6: 85 case 6: 86 channel_allocation = 0x0B; 86 channel_allocation = 0x0B; 87 break; 87 break; 88 case 7: 88 case 7: 89 channel_allocation = 0x12; 89 channel_allocation = 0x12; 90 break; 90 break; 91 case 8: 91 case 8: 92 channel_allocation = 0x13; 92 channel_allocation = 0x13; 93 break; 93 break; 94 default: 94 default: 95 return -EINVAL; 95 return -EINVAL; 96 } 96 } 97 97 98 return channel_allocation; 98 return channel_allocation; 99 } 99 } 100 EXPORT_SYMBOL_GPL(q6dsp_get_channel_allocation 100 EXPORT_SYMBOL_GPL(q6dsp_get_channel_allocation); 101 101 102 MODULE_DESCRIPTION("ASoC MSM QDSP6 helper func 102 MODULE_DESCRIPTION("ASoC MSM QDSP6 helper functions"); 103 MODULE_LICENSE("GPL v2"); 103 MODULE_LICENSE("GPL v2"); 104 104
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.