Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Bharath Ramachandramurthy | 2e3168f | 2012-05-03 16:29:09 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/sched.h> |
| 16 | #include <linux/jiffies.h> |
| 17 | #include <linux/uaccess.h> |
| 18 | #include <linux/atomic.h> |
| 19 | #include <sound/q6afe-v2.h> |
| 20 | #include <sound/q6audio-v2.h> |
| 21 | |
| 22 | int q6audio_get_port_index(u16 port_id) |
| 23 | { |
| 24 | switch (port_id) { |
| 25 | case PRIMARY_I2S_RX: return IDX_PRIMARY_I2S_RX; |
| 26 | case PRIMARY_I2S_TX: return IDX_PRIMARY_I2S_TX; |
| 27 | case PCM_RX: return IDX_PCM_RX; |
| 28 | case PCM_TX: return IDX_PCM_TX; |
| 29 | case SECONDARY_I2S_RX: return IDX_SECONDARY_I2S_RX; |
| 30 | case SECONDARY_I2S_TX: return IDX_SECONDARY_I2S_TX; |
| 31 | case MI2S_RX: return IDX_MI2S_RX; |
| 32 | case MI2S_TX: return IDX_MI2S_TX; |
| 33 | case HDMI_RX: return IDX_HDMI_RX; |
| 34 | case RSVD_2: return IDX_RSVD_2; |
| 35 | case RSVD_3: return IDX_RSVD_3; |
| 36 | case DIGI_MIC_TX: return IDX_DIGI_MIC_TX; |
| 37 | case VOICE_RECORD_RX: return IDX_VOICE_RECORD_RX; |
| 38 | case VOICE_RECORD_TX: return IDX_VOICE_RECORD_TX; |
| 39 | case VOICE_PLAYBACK_TX: return IDX_VOICE_PLAYBACK_TX; |
| 40 | case SLIMBUS_0_RX: return IDX_SLIMBUS_0_RX; |
| 41 | case SLIMBUS_0_TX: return IDX_SLIMBUS_0_TX; |
| 42 | case SLIMBUS_1_RX: return IDX_SLIMBUS_1_RX; |
| 43 | case SLIMBUS_1_TX: return IDX_SLIMBUS_1_TX; |
| 44 | case INT_BT_SCO_RX: return IDX_INT_BT_SCO_RX; |
| 45 | case INT_BT_SCO_TX: return IDX_INT_BT_SCO_TX; |
| 46 | case INT_BT_A2DP_RX: return IDX_INT_BT_A2DP_RX; |
| 47 | case INT_FM_RX: return IDX_INT_FM_RX; |
| 48 | case INT_FM_TX: return IDX_INT_FM_TX; |
| 49 | case RT_PROXY_PORT_001_RX: return IDX_RT_PROXY_PORT_001_RX; |
| 50 | case RT_PROXY_PORT_001_TX: return IDX_RT_PROXY_PORT_001_TX; |
| 51 | |
| 52 | default: return -EINVAL; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | int q6audio_get_port_id(u16 port_id) |
| 57 | { |
| 58 | switch (port_id) { |
| 59 | case PRIMARY_I2S_RX: return AFE_PORT_ID_PRIMARY_MI2S_RX; |
| 60 | case PRIMARY_I2S_TX: return AFE_PORT_ID_PRIMARY_MI2S_TX; |
| 61 | case PCM_RX: return AFE_PORT_ID_PRIMARY_PCM_RX; |
| 62 | case PCM_TX: return AFE_PORT_ID_PRIMARY_PCM_TX; |
| 63 | case SECONDARY_I2S_RX: return AFE_PORT_ID_SECONDARY_MI2S_RX; |
| 64 | case SECONDARY_I2S_TX: return AFE_PORT_ID_SECONDARY_MI2S_TX; |
| 65 | case MI2S_RX: return AFE_PORT_ID_PRIMARY_MI2S_RX; |
| 66 | case MI2S_TX: return AFE_PORT_ID_PRIMARY_MI2S_TX; |
| 67 | case HDMI_RX: return AFE_PORT_ID_MULTICHAN_HDMI_RX; |
| 68 | case RSVD_2: return IDX_RSVD_2; |
| 69 | case RSVD_3: return IDX_RSVD_3; |
| 70 | case DIGI_MIC_TX: return AFE_PORT_ID_DIGITAL_MIC_TX; |
| 71 | case VOICE_RECORD_RX: return AFE_PORT_ID_VOICE_RECORD_RX; |
| 72 | case VOICE_RECORD_TX: return AFE_PORT_ID_VOICE_RECORD_TX; |
| 73 | case VOICE_PLAYBACK_TX: return AFE_PORT_ID_VOICE_PLAYBACK_TX; |
| 74 | case SLIMBUS_0_RX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_RX; |
| 75 | case SLIMBUS_0_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_0_TX; |
| 76 | case SLIMBUS_1_RX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_RX; |
| 77 | case SLIMBUS_1_TX: return AFE_PORT_ID_SLIMBUS_MULTI_CHAN_1_TX; |
| 78 | case INT_BT_SCO_RX: return AFE_PORT_ID_INTERNAL_BT_SCO_RX; |
| 79 | case INT_BT_SCO_TX: return AFE_PORT_ID_INTERNAL_BT_SCO_TX; |
| 80 | case INT_BT_A2DP_RX: return AFE_PORT_ID_INTERNAL_BT_A2DP_RX; |
| 81 | case INT_FM_RX: return AFE_PORT_ID_INTERNAL_FM_RX; |
| 82 | case INT_FM_TX: return AFE_PORT_ID_INTERNAL_FM_TX; |
| 83 | case RT_PROXY_PORT_001_RX: return AFE_PORT_ID_RT_PROXY_PORT_001_RX; |
| 84 | case RT_PROXY_PORT_001_TX: return AFE_PORT_ID_RT_PROXY_PORT_001_TX; |
| 85 | |
| 86 | default: return -EINVAL; |
| 87 | } |
| 88 | } |
| 89 | int q6audio_convert_virtual_to_portid(u16 port_id) |
| 90 | { |
| 91 | int ret; |
| 92 | |
| 93 | /* if port_id is virtual, convert to physical.. |
| 94 | * if port_id is already physical, return physical |
| 95 | */ |
| 96 | if (q6audio_validate_port(port_id) < 0) { |
| 97 | if (port_id == RT_PROXY_DAI_001_RX || |
| 98 | port_id == RT_PROXY_DAI_001_TX || |
| 99 | port_id == RT_PROXY_DAI_002_RX || |
| 100 | port_id == RT_PROXY_DAI_002_TX) |
| 101 | ret = VIRTUAL_ID_TO_PORTID(port_id); |
| 102 | else |
| 103 | ret = -EINVAL; |
| 104 | } else |
| 105 | ret = port_id; |
| 106 | |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | int q6audio_validate_port(u16 port_id) |
| 111 | { |
| 112 | int ret; |
| 113 | |
| 114 | switch (port_id) { |
| 115 | case PRIMARY_I2S_RX: |
| 116 | case PRIMARY_I2S_TX: |
| 117 | case PCM_RX: |
| 118 | case PCM_TX: |
| 119 | case SECONDARY_I2S_RX: |
| 120 | case SECONDARY_I2S_TX: |
| 121 | case MI2S_RX: |
| 122 | case MI2S_TX: |
| 123 | case HDMI_RX: |
| 124 | case RSVD_2: |
| 125 | case RSVD_3: |
| 126 | case DIGI_MIC_TX: |
| 127 | case VOICE_RECORD_RX: |
| 128 | case VOICE_RECORD_TX: |
| 129 | case VOICE_PLAYBACK_TX: |
| 130 | case SLIMBUS_0_RX: |
| 131 | case SLIMBUS_0_TX: |
| 132 | case SLIMBUS_1_RX: |
| 133 | case SLIMBUS_1_TX: |
| 134 | case INT_BT_SCO_RX: |
| 135 | case INT_BT_SCO_TX: |
| 136 | case INT_BT_A2DP_RX: |
| 137 | case INT_FM_RX: |
| 138 | case INT_FM_TX: |
| 139 | case RT_PROXY_PORT_001_RX: |
| 140 | case RT_PROXY_PORT_001_TX: |
| 141 | { |
| 142 | ret = 0; |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | default: |
| 147 | ret = -EINVAL; |
| 148 | } |
| 149 | |
| 150 | return ret; |
| 151 | } |