Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1 | /* |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/bitops.h> |
| 17 | #include <sound/control.h> |
Laxminath Kasam | 605b42f | 2017-08-01 22:02:15 +0530 | [diff] [blame] | 18 | #include <dsp/q6adm-v2.h> |
| 19 | #include <dsp/q6core.h> |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 20 | #include <dsp/q6common.h> |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 21 | |
| 22 | #include "msm-ds2-dap-config.h" |
| 23 | #include "msm-pcm-routing-v2.h" |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 24 | |
| 25 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 26 | /* ramp up/down for 30ms */ |
| 27 | #define DOLBY_SOFT_VOLUME_PERIOD 40 |
| 28 | /* Step value 0ms or 0us */ |
| 29 | #define DOLBY_SOFT_VOLUME_STEP 1000 |
| 30 | #define DOLBY_ADDITIONAL_RAMP_WAIT 10 |
| 31 | #define SOFT_VOLUME_PARAM_SIZE 3 |
| 32 | #define PARAM_PAYLOAD_SIZE 3 |
| 33 | |
| 34 | enum { |
| 35 | DOLBY_SOFT_VOLUME_CURVE_LINEAR = 0, |
| 36 | DOLBY_SOFT_VOLUME_CURVE_EXP, |
| 37 | DOLBY_SOFT_VOLUME_CURVE_LOG, |
| 38 | }; |
| 39 | |
| 40 | #define VOLUME_ZERO_GAIN 0x0 |
| 41 | #define VOLUME_UNITY_GAIN 0x2000 |
| 42 | /* Wait time for module enable/disble */ |
| 43 | #define DOLBY_MODULE_ENABLE_PERIOD 50 |
| 44 | |
| 45 | /* DOLBY device definitions end */ |
| 46 | enum { |
| 47 | DOLBY_OFF_CACHE = 0, |
| 48 | DOLBY_SPEAKER_CACHE, |
| 49 | DOLBY_HEADPHONE_CACHE, |
| 50 | DOLBY_HDMI_CACHE, |
| 51 | DOLBY_WFD_CACHE, |
| 52 | DOLBY_FM_CACHE, |
| 53 | DOLBY_MAX_CACHE, |
| 54 | }; |
| 55 | |
| 56 | enum { |
| 57 | DAP_SOFT_BYPASS = 0, |
| 58 | DAP_HARD_BYPASS, |
| 59 | }; |
| 60 | |
| 61 | enum { |
| 62 | MODULE_DISABLE = 0, |
| 63 | MODULE_ENABLE, |
| 64 | }; |
| 65 | /* dolby param ids to/from dsp */ |
| 66 | static uint32_t ds2_dap_params_id[MAX_DS2_PARAMS] = { |
| 67 | DOLBY_PARAM_ID_VDHE, DOLBY_PARAM_ID_VSPE, DOLBY_PARAM_ID_DSSF, |
| 68 | DOLBY_PARAM_ID_DVLI, DOLBY_PARAM_ID_DVLO, DOLBY_PARAM_ID_DVLE, |
| 69 | DOLBY_PARAM_ID_DVMC, DOLBY_PARAM_ID_DVME, DOLBY_PARAM_ID_IENB, |
| 70 | DOLBY_PARAM_ID_IEBF, DOLBY_PARAM_ID_IEON, DOLBY_PARAM_ID_DEON, |
| 71 | DOLBY_PARAM_ID_NGON, DOLBY_PARAM_ID_GEON, DOLBY_PARAM_ID_GENB, |
| 72 | DOLBY_PARAM_ID_GEBF, DOLBY_PARAM_ID_AONB, DOLBY_PARAM_ID_AOBF, |
| 73 | DOLBY_PARAM_ID_AOBG, DOLBY_PARAM_ID_AOON, DOLBY_PARAM_ID_ARNB, |
| 74 | DOLBY_PARAM_ID_ARBF, DOLBY_PARAM_ID_PLB, DOLBY_PARAM_ID_PLMD, |
| 75 | DOLBY_PARAM_ID_DHSB, DOLBY_PARAM_ID_DHRG, DOLBY_PARAM_ID_DSSB, |
| 76 | DOLBY_PARAM_ID_DSSA, DOLBY_PARAM_ID_DVLA, DOLBY_PARAM_ID_IEBT, |
| 77 | DOLBY_PARAM_ID_IEA, DOLBY_PARAM_ID_DEA, DOLBY_PARAM_ID_DED, |
| 78 | DOLBY_PARAM_ID_GEBG, DOLBY_PARAM_ID_AOCC, DOLBY_PARAM_ID_ARBI, |
| 79 | DOLBY_PARAM_ID_ARBL, DOLBY_PARAM_ID_ARBH, DOLBY_PARAM_ID_AROD, |
| 80 | DOLBY_PARAM_ID_ARTP, DOLBY_PARAM_ID_VMON, DOLBY_PARAM_ID_VMB, |
| 81 | DOLBY_PARAM_ID_VCNB, DOLBY_PARAM_ID_VCBF, DOLBY_PARAM_ID_PREG, |
| 82 | DOLBY_PARAM_ID_VEN, DOLBY_PARAM_ID_PSTG, DOLBY_PARAM_ID_INIT_ENDP, |
| 83 | }; |
| 84 | |
| 85 | /* modifed state: 0x00000000 - Not updated |
| 86 | * > 0x00000000 && < 0x00010000 |
| 87 | * Updated and not committed to DSP |
| 88 | * 0x00010001 - Updated and committed to DSP |
| 89 | * > 0x00010001 - Modified the committed value |
| 90 | */ |
| 91 | /* param offset */ |
| 92 | static uint32_t ds2_dap_params_offset[MAX_DS2_PARAMS] = { |
| 93 | DOLBY_PARAM_VDHE_OFFSET, DOLBY_PARAM_VSPE_OFFSET, |
| 94 | DOLBY_PARAM_DSSF_OFFSET, DOLBY_PARAM_DVLI_OFFSET, |
| 95 | DOLBY_PARAM_DVLO_OFFSET, DOLBY_PARAM_DVLE_OFFSET, |
| 96 | DOLBY_PARAM_DVMC_OFFSET, DOLBY_PARAM_DVME_OFFSET, |
| 97 | DOLBY_PARAM_IENB_OFFSET, DOLBY_PARAM_IEBF_OFFSET, |
| 98 | DOLBY_PARAM_IEON_OFFSET, DOLBY_PARAM_DEON_OFFSET, |
| 99 | DOLBY_PARAM_NGON_OFFSET, DOLBY_PARAM_GEON_OFFSET, |
| 100 | DOLBY_PARAM_GENB_OFFSET, DOLBY_PARAM_GEBF_OFFSET, |
| 101 | DOLBY_PARAM_AONB_OFFSET, DOLBY_PARAM_AOBF_OFFSET, |
| 102 | DOLBY_PARAM_AOBG_OFFSET, DOLBY_PARAM_AOON_OFFSET, |
| 103 | DOLBY_PARAM_ARNB_OFFSET, DOLBY_PARAM_ARBF_OFFSET, |
| 104 | DOLBY_PARAM_PLB_OFFSET, DOLBY_PARAM_PLMD_OFFSET, |
| 105 | DOLBY_PARAM_DHSB_OFFSET, DOLBY_PARAM_DHRG_OFFSET, |
| 106 | DOLBY_PARAM_DSSB_OFFSET, DOLBY_PARAM_DSSA_OFFSET, |
| 107 | DOLBY_PARAM_DVLA_OFFSET, DOLBY_PARAM_IEBT_OFFSET, |
| 108 | DOLBY_PARAM_IEA_OFFSET, DOLBY_PARAM_DEA_OFFSET, |
| 109 | DOLBY_PARAM_DED_OFFSET, DOLBY_PARAM_GEBG_OFFSET, |
| 110 | DOLBY_PARAM_AOCC_OFFSET, DOLBY_PARAM_ARBI_OFFSET, |
| 111 | DOLBY_PARAM_ARBL_OFFSET, DOLBY_PARAM_ARBH_OFFSET, |
| 112 | DOLBY_PARAM_AROD_OFFSET, DOLBY_PARAM_ARTP_OFFSET, |
| 113 | DOLBY_PARAM_VMON_OFFSET, DOLBY_PARAM_VMB_OFFSET, |
| 114 | DOLBY_PARAM_VCNB_OFFSET, DOLBY_PARAM_VCBF_OFFSET, |
| 115 | DOLBY_PARAM_PREG_OFFSET, DOLBY_PARAM_VEN_OFFSET, |
| 116 | DOLBY_PARAM_PSTG_OFFSET, DOLBY_PARAM_INT_ENDP_OFFSET, |
| 117 | }; |
| 118 | /* param_length */ |
| 119 | static uint32_t ds2_dap_params_length[MAX_DS2_PARAMS] = { |
| 120 | DOLBY_PARAM_VDHE_LENGTH, DOLBY_PARAM_VSPE_LENGTH, |
| 121 | DOLBY_PARAM_DSSF_LENGTH, DOLBY_PARAM_DVLI_LENGTH, |
| 122 | DOLBY_PARAM_DVLO_LENGTH, DOLBY_PARAM_DVLE_LENGTH, |
| 123 | DOLBY_PARAM_DVMC_LENGTH, DOLBY_PARAM_DVME_LENGTH, |
| 124 | DOLBY_PARAM_IENB_LENGTH, DOLBY_PARAM_IEBF_LENGTH, |
| 125 | DOLBY_PARAM_IEON_LENGTH, DOLBY_PARAM_DEON_LENGTH, |
| 126 | DOLBY_PARAM_NGON_LENGTH, DOLBY_PARAM_GEON_LENGTH, |
| 127 | DOLBY_PARAM_GENB_LENGTH, DOLBY_PARAM_GEBF_LENGTH, |
| 128 | DOLBY_PARAM_AONB_LENGTH, DOLBY_PARAM_AOBF_LENGTH, |
| 129 | DOLBY_PARAM_AOBG_LENGTH, DOLBY_PARAM_AOON_LENGTH, |
| 130 | DOLBY_PARAM_ARNB_LENGTH, DOLBY_PARAM_ARBF_LENGTH, |
| 131 | DOLBY_PARAM_PLB_LENGTH, DOLBY_PARAM_PLMD_LENGTH, |
| 132 | DOLBY_PARAM_DHSB_LENGTH, DOLBY_PARAM_DHRG_LENGTH, |
| 133 | DOLBY_PARAM_DSSB_LENGTH, DOLBY_PARAM_DSSA_LENGTH, |
| 134 | DOLBY_PARAM_DVLA_LENGTH, DOLBY_PARAM_IEBT_LENGTH, |
| 135 | DOLBY_PARAM_IEA_LENGTH, DOLBY_PARAM_DEA_LENGTH, |
| 136 | DOLBY_PARAM_DED_LENGTH, DOLBY_PARAM_GEBG_LENGTH, |
| 137 | DOLBY_PARAM_AOCC_LENGTH, DOLBY_PARAM_ARBI_LENGTH, |
| 138 | DOLBY_PARAM_ARBL_LENGTH, DOLBY_PARAM_ARBH_LENGTH, |
| 139 | DOLBY_PARAM_AROD_LENGTH, DOLBY_PARAM_ARTP_LENGTH, |
| 140 | DOLBY_PARAM_VMON_LENGTH, DOLBY_PARAM_VMB_LENGTH, |
| 141 | DOLBY_PARAM_VCNB_LENGTH, DOLBY_PARAM_VCBF_LENGTH, |
| 142 | DOLBY_PARAM_PREG_LENGTH, DOLBY_PARAM_VEN_LENGTH, |
| 143 | DOLBY_PARAM_PSTG_LENGTH, DOLBY_PARAM_INT_ENDP_LENGTH, |
| 144 | }; |
| 145 | |
| 146 | struct ds2_dap_params_s { |
| 147 | int32_t params_val[TOTAL_LENGTH_DS2_PARAM]; |
| 148 | int32_t dap_params_modified[MAX_DS2_PARAMS]; |
| 149 | }; |
| 150 | |
| 151 | struct audio_rx_cal_data { |
| 152 | char aud_proc_data[AUD_PROC_BLOCK_SIZE]; |
| 153 | int32_t aud_proc_size; |
| 154 | char aud_vol_data[AUD_VOL_BLOCK_SIZE]; |
| 155 | int32_t aud_vol_size; |
| 156 | }; |
| 157 | |
| 158 | static struct ds2_dap_params_s ds2_dap_params[DOLBY_MAX_CACHE]; |
| 159 | |
| 160 | struct ds2_device_mapping { |
| 161 | int32_t device_id; /* audio_out_... */ |
| 162 | int port_id; /* afe port. constant for a target variant. routing-v2*/ |
| 163 | /*Only one Dolby COPP for a specific port*/ |
| 164 | int copp_idx; /* idx for the copp port on which ds2 is active */ |
| 165 | int cache_dev; /* idx to a shared parameter array dependent on device*/ |
| 166 | uint32_t stream_ref_count; |
| 167 | bool active; |
| 168 | void *cal_data; |
| 169 | }; |
| 170 | |
| 171 | static struct ds2_device_mapping dev_map[DS2_DEVICES_ALL]; |
| 172 | |
| 173 | struct ds2_dap_params_states_s { |
| 174 | bool use_cache; |
| 175 | bool dap_bypass; |
| 176 | bool dap_bypass_type; |
| 177 | bool node_opened; |
| 178 | int32_t device; |
| 179 | bool custom_stereo_onoff; |
| 180 | }; |
| 181 | |
| 182 | static struct ds2_dap_params_states_s ds2_dap_params_states = {true, false, |
| 183 | false, DEVICE_NONE}; |
| 184 | |
| 185 | static int all_supported_devices = EARPIECE|SPEAKER|WIRED_HEADSET| |
| 186 | WIRED_HEADPHONE|BLUETOOTH_SCO|AUX_DIGITAL| |
| 187 | ANLG_DOCK_HEADSET|DGTL_DOCK_HEADSET| |
| 188 | REMOTE_SUBMIX|ANC_HEADSET|ANC_HEADPHONE| |
| 189 | PROXY|FM|FM_TX|DEVICE_NONE| |
| 190 | BLUETOOTH_SCO_HEADSET|BLUETOOTH_SCO_CARKIT; |
| 191 | |
| 192 | |
| 193 | static void msm_ds2_dap_check_and_update_ramp_wait(int port_id, int copp_idx, |
| 194 | int *ramp_wait) |
| 195 | { |
| 196 | |
| 197 | int32_t *update_params_value = NULL; |
| 198 | uint32_t params_length = SOFT_VOLUME_PARAM_SIZE * sizeof(uint32_t); |
| 199 | uint32_t param_payload_len = PARAM_PAYLOAD_SIZE * sizeof(uint32_t); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 200 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 201 | int rc = 0; |
| 202 | |
| 203 | update_params_value = kzalloc(params_length + param_payload_len, |
| 204 | GFP_KERNEL); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 205 | if (!update_params_value) { |
| 206 | pr_err("%s: params memory alloc failed\n", __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 207 | goto end; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 208 | } |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 209 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 210 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 211 | param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL; |
| 212 | param_hdr.instance_id = INSTANCE_ID_0; |
| 213 | param_hdr.param_id = AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS; |
| 214 | param_hdr.param_size = params_length + param_payload_len; |
| 215 | rc = adm_get_pp_params(port_id, copp_idx, ADM_CLIENT_ID_DEFAULT, NULL, |
| 216 | ¶m_hdr, (char *) update_params_value); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 217 | if (rc == 0) { |
| 218 | pr_debug("%s: params_value [0x%x, 0x%x, 0x%x]\n", |
| 219 | __func__, update_params_value[0], |
| 220 | update_params_value[1], |
| 221 | update_params_value[2]); |
| 222 | *ramp_wait = update_params_value[0]; |
| 223 | } |
| 224 | end: |
| 225 | kfree(update_params_value); |
| 226 | /* |
| 227 | * No error returned as we do not need to error out from dap on/dap |
| 228 | * bypass. The default ramp parameter will be used to wait during |
| 229 | * ramp down. |
| 230 | */ |
| 231 | } |
| 232 | |
| 233 | static int msm_ds2_dap_set_vspe_vdhe(int dev_map_idx, |
| 234 | bool is_custom_stereo_enabled) |
| 235 | { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 236 | u8 *packed_param_data = NULL; |
| 237 | u8 *param_data = NULL; |
| 238 | struct param_hdr_v3 param_hdr; |
| 239 | u32 packed_param_size = 0; |
| 240 | u32 param_size = 0; |
| 241 | int cdev; |
| 242 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 243 | |
| 244 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 245 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 246 | rc = -EINVAL; |
| 247 | goto end; |
| 248 | } |
| 249 | |
| 250 | if (dev_map[dev_map_idx].port_id == DOLBY_INVALID_PORT_ID) { |
| 251 | pr_err("%s: Invalid port id\n", __func__); |
| 252 | rc = -EINVAL; |
| 253 | goto end; |
| 254 | } |
| 255 | |
| 256 | if ((dev_map[dev_map_idx].copp_idx < 0) || |
| 257 | (dev_map[dev_map_idx].copp_idx >= MAX_COPPS_PER_PORT)) { |
| 258 | pr_err("%s: Invalid copp_idx\n", __func__); |
| 259 | rc = -EINVAL; |
| 260 | goto end; |
| 261 | } |
| 262 | |
| 263 | if ((dev_map[dev_map_idx].port_id != SLIMBUS_0_RX) && |
| 264 | (dev_map[dev_map_idx].port_id != RT_PROXY_PORT_001_RX)) { |
| 265 | pr_debug("%s:No Custom stereo for port:0x%x\n", |
| 266 | __func__, dev_map[dev_map_idx].port_id); |
| 267 | goto end; |
| 268 | } |
| 269 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 270 | /* Allocate the max space needed */ |
| 271 | packed_param_size = (TOTAL_LENGTH_DOLBY_PARAM * sizeof(uint32_t)) + |
| 272 | (2 * sizeof(union param_hdrs)); |
| 273 | packed_param_data = kzalloc(packed_param_size, GFP_KERNEL); |
| 274 | if (!packed_param_data) |
| 275 | return -ENOMEM; |
| 276 | |
| 277 | packed_param_size = 0; |
| 278 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 279 | |
| 280 | /* Set common values */ |
| 281 | cdev = dev_map[dev_map_idx].cache_dev; |
| 282 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 283 | param_hdr.instance_id = INSTANCE_ID_0; |
| 284 | |
| 285 | /* Pack VDHE header + data */ |
| 286 | param_hdr.param_id = DOLBY_PARAM_ID_VDHE; |
| 287 | param_size = DOLBY_PARAM_VDHE_LENGTH * sizeof(uint32_t); |
| 288 | param_hdr.param_size = param_size; |
| 289 | |
| 290 | if (is_custom_stereo_enabled) |
| 291 | param_data = NULL; |
| 292 | else |
| 293 | param_data = (u8 *) &ds2_dap_params[cdev] |
| 294 | .params_val[DOLBY_PARAM_VDHE_OFFSET]; |
| 295 | |
| 296 | rc = q6common_pack_pp_params(packed_param_data, ¶m_hdr, param_data, |
| 297 | ¶m_size); |
| 298 | if (rc) { |
| 299 | pr_err("%s: Failed to pack params for dolby vdhe, error %d\n", |
| 300 | __func__, rc); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 301 | goto end; |
| 302 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 303 | packed_param_size += param_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 304 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 305 | /* Pack VSPE header + data */ |
| 306 | param_hdr.param_id = DOLBY_PARAM_ID_VSPE; |
| 307 | param_size = DOLBY_PARAM_VSPE_LENGTH * sizeof(uint32_t); |
| 308 | param_hdr.param_size = param_size; |
| 309 | |
| 310 | if (is_custom_stereo_enabled) |
| 311 | param_data = NULL; |
| 312 | else |
| 313 | param_data = (u8 *) &ds2_dap_params[cdev] |
| 314 | .params_val[DOLBY_PARAM_VSPE_OFFSET]; |
| 315 | |
| 316 | rc = q6common_pack_pp_params(packed_param_data + packed_param_size, |
| 317 | ¶m_hdr, param_data, ¶m_size); |
| 318 | if (rc) { |
| 319 | pr_err("%s: Failed to pack params for dolby vspe, error %d\n", |
| 320 | __func__, rc); |
| 321 | goto end; |
| 322 | } |
| 323 | packed_param_size += param_size; |
| 324 | |
| 325 | rc = adm_set_pp_params(dev_map[dev_map_idx].port_id, |
| 326 | dev_map[dev_map_idx].copp_idx, NULL, |
| 327 | packed_param_data, packed_param_size); |
| 328 | if (rc) { |
| 329 | pr_err("%s: send vdhe/vspe params failed with rc=%d\n", |
| 330 | __func__, rc); |
| 331 | rc = -EINVAL; |
| 332 | goto end; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 333 | } |
| 334 | end: |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 335 | kfree(packed_param_data); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 336 | return rc; |
| 337 | } |
| 338 | |
| 339 | int qti_set_custom_stereo_on(int port_id, int copp_idx, |
| 340 | bool is_custom_stereo_on) |
| 341 | { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 342 | struct custom_stereo_param custom_stereo; |
| 343 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 344 | uint16_t op_FL_ip_FL_weight; |
| 345 | uint16_t op_FL_ip_FR_weight; |
| 346 | uint16_t op_FR_ip_FL_weight; |
| 347 | uint16_t op_FR_ip_FR_weight; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 348 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 349 | |
| 350 | if ((port_id != SLIMBUS_0_RX) && |
| 351 | (port_id != RT_PROXY_PORT_001_RX)) { |
| 352 | pr_debug("%s:No Custom stereo for port:0x%x\n", |
| 353 | __func__, port_id); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 354 | return 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 355 | } |
| 356 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 357 | memset(&custom_stereo, 0, sizeof(custom_stereo)); |
| 358 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 359 | pr_debug("%s: port 0x%x, copp_idx %d, is_custom_stereo_on %d\n", |
| 360 | __func__, port_id, copp_idx, is_custom_stereo_on); |
| 361 | if (is_custom_stereo_on) { |
| 362 | op_FL_ip_FL_weight = |
| 363 | Q14_GAIN_ZERO_POINT_FIVE; |
| 364 | op_FL_ip_FR_weight = |
| 365 | Q14_GAIN_ZERO_POINT_FIVE; |
| 366 | op_FR_ip_FL_weight = |
| 367 | Q14_GAIN_ZERO_POINT_FIVE; |
| 368 | op_FR_ip_FR_weight = |
| 369 | Q14_GAIN_ZERO_POINT_FIVE; |
| 370 | } else { |
| 371 | op_FL_ip_FL_weight = Q14_GAIN_UNITY; |
| 372 | op_FL_ip_FR_weight = 0; |
| 373 | op_FR_ip_FL_weight = 0; |
| 374 | op_FR_ip_FR_weight = Q14_GAIN_UNITY; |
| 375 | } |
| 376 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 377 | param_hdr.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER; |
| 378 | param_hdr.instance_id = INSTANCE_ID_0; |
| 379 | param_hdr.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF; |
| 380 | param_hdr.param_size = sizeof(struct custom_stereo_param); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 381 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 382 | /* index is 32-bit param in little endian*/ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 383 | custom_stereo.index = CUSTOM_STEREO_INDEX_PARAM; |
| 384 | custom_stereo.reserved = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 385 | /* for stereo mixing num out ch*/ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 386 | custom_stereo.num_out_ch = CUSTOM_STEREO_NUM_OUT_CH; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 387 | /* for stereo mixing num in ch*/ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 388 | custom_stereo.num_in_ch = CUSTOM_STEREO_NUM_IN_CH; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 389 | |
| 390 | /* Out ch map FL/FR*/ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 391 | custom_stereo.out_fl = PCM_CHANNEL_FL; |
| 392 | custom_stereo.out_fr = PCM_CHANNEL_FR; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 393 | |
| 394 | /* In ch map FL/FR*/ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 395 | custom_stereo.in_fl = PCM_CHANNEL_FL; |
| 396 | custom_stereo.in_fr = PCM_CHANNEL_FR; |
| 397 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 398 | /* weighting coefficients as name suggests, |
| 399 | * mixing will be done according to these coefficients |
| 400 | */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 401 | custom_stereo.op_FL_ip_FL_weight = op_FL_ip_FL_weight; |
| 402 | custom_stereo.op_FL_ip_FR_weight = op_FL_ip_FR_weight; |
| 403 | custom_stereo.op_FR_ip_FL_weight = op_FR_ip_FL_weight; |
| 404 | custom_stereo.op_FR_ip_FR_weight = op_FR_ip_FR_weight; |
| 405 | rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, |
| 406 | (u8 *) &custom_stereo); |
| 407 | if (rc) { |
| 408 | pr_err("%s: send params failed rc=%d\n", __func__, rc); |
| 409 | return -EINVAL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 410 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 411 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 412 | return 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 413 | } |
| 414 | static int dap_set_custom_stereo_onoff(int dev_map_idx, |
| 415 | bool is_custom_stereo_enabled) |
| 416 | { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 417 | uint32_t enable = is_custom_stereo_enabled ? 1 : 0; |
| 418 | struct param_hdr_v3 param_hdr; |
| 419 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 420 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 421 | if ((dev_map[dev_map_idx].port_id != SLIMBUS_0_RX) && |
| 422 | (dev_map[dev_map_idx].port_id != RT_PROXY_PORT_001_RX)) { |
| 423 | pr_debug("%s:No Custom stereo for port:0x%x\n", |
| 424 | __func__, dev_map[dev_map_idx].port_id); |
| 425 | goto end; |
| 426 | } |
| 427 | |
| 428 | if ((dev_map[dev_map_idx].copp_idx < 0) || |
| 429 | (dev_map[dev_map_idx].copp_idx >= MAX_COPPS_PER_PORT)) { |
| 430 | rc = -EINVAL; |
| 431 | goto end; |
| 432 | } |
| 433 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 434 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
| 435 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 436 | /* DAP custom stereo */ |
| 437 | msm_ds2_dap_set_vspe_vdhe(dev_map_idx, |
| 438 | is_custom_stereo_enabled); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 439 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 440 | param_hdr.instance_id = INSTANCE_ID_0; |
| 441 | param_hdr.param_id = DOLBY_ENABLE_CUSTOM_STEREO; |
| 442 | param_hdr.param_size = sizeof(enable); |
| 443 | |
| 444 | rc = adm_pack_and_set_one_pp_param(dev_map[dev_map_idx].port_id, |
| 445 | dev_map[dev_map_idx].copp_idx, |
| 446 | param_hdr, (u8 *) &enable); |
| 447 | if (rc) { |
| 448 | pr_err("%s: set custom stereo enable failed with rc=%d\n", |
| 449 | __func__, rc); |
| 450 | rc = -EINVAL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 451 | } |
| 452 | end: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 453 | return rc; |
| 454 | |
| 455 | } |
| 456 | |
| 457 | |
| 458 | static int set_custom_stereo_onoff(int dev_map_idx, |
| 459 | bool is_custom_stereo_enabled) |
| 460 | { |
| 461 | int rc = 0; |
| 462 | |
| 463 | pr_debug("%s: map index %d, custom stereo %d\n", __func__, dev_map_idx, |
| 464 | is_custom_stereo_enabled); |
| 465 | |
| 466 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 467 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 468 | rc = -EINVAL; |
| 469 | goto end; |
| 470 | } |
| 471 | |
| 472 | if (dev_map[dev_map_idx].port_id == DOLBY_INVALID_PORT_ID) { |
| 473 | pr_err("%s: invalid port id\n", __func__); |
| 474 | rc = -EINVAL; |
| 475 | goto end; |
| 476 | } |
| 477 | |
| 478 | if ((dev_map[dev_map_idx].copp_idx < 0) || |
| 479 | (dev_map[dev_map_idx].copp_idx >= MAX_COPPS_PER_PORT)) { |
| 480 | pr_err("%s: invalid copp idx\n", __func__); |
| 481 | rc = -EINVAL; |
| 482 | goto end; |
| 483 | } |
| 484 | |
| 485 | if (ds2_dap_params_states.dap_bypass == true && |
| 486 | ds2_dap_params_states.dap_bypass_type == DAP_HARD_BYPASS) { |
| 487 | |
| 488 | rc = qti_set_custom_stereo_on(dev_map[dev_map_idx].port_id, |
| 489 | dev_map[dev_map_idx].copp_idx, |
| 490 | is_custom_stereo_enabled); |
| 491 | if (rc < 0) { |
| 492 | pr_err("%s:qti_set_custom_stereo_on_copp failed C.S %d", |
| 493 | __func__, is_custom_stereo_enabled); |
| 494 | } |
| 495 | goto end; |
| 496 | |
| 497 | } |
| 498 | |
| 499 | if (ds2_dap_params_states.dap_bypass == false) { |
| 500 | rc = dap_set_custom_stereo_onoff(dev_map_idx, |
| 501 | is_custom_stereo_enabled); |
| 502 | if (rc < 0) { |
| 503 | pr_err("%s:qti_set_custom_stereo_on_copp failed C.S %d", |
| 504 | __func__, is_custom_stereo_enabled); |
| 505 | } |
| 506 | goto end; |
| 507 | } |
| 508 | end: |
| 509 | return rc; |
| 510 | } |
| 511 | |
| 512 | static int msm_ds2_dap_alloc_and_store_cal_data(int dev_map_idx, int path, |
| 513 | int perf_mode) |
| 514 | { |
| 515 | int rc = 0; |
| 516 | struct audio_rx_cal_data *aud_cal_data; |
| 517 | |
| 518 | pr_debug("%s: path %d, perf_mode %d, dev_map_idx %d\n", |
| 519 | __func__, path, perf_mode, dev_map_idx); |
| 520 | |
| 521 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 522 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 523 | rc = -EINVAL; |
| 524 | goto end; |
| 525 | } |
| 526 | |
| 527 | aud_cal_data = kzalloc(sizeof(struct audio_rx_cal_data), GFP_KERNEL); |
| 528 | if (!aud_cal_data) { |
| 529 | rc = -ENOMEM; |
| 530 | goto end; |
| 531 | } |
| 532 | |
| 533 | rc = adm_store_cal_data(dev_map[dev_map_idx].port_id, |
| 534 | dev_map[dev_map_idx].copp_idx, path, perf_mode, |
| 535 | ADM_AUDPROC_CAL, aud_cal_data->aud_proc_data, |
| 536 | &aud_cal_data->aud_proc_size); |
| 537 | if (rc < 0) { |
| 538 | pr_err("%s: store cal data err %d\n", __func__, rc); |
| 539 | kfree(aud_cal_data); |
| 540 | goto end; |
| 541 | } |
| 542 | |
| 543 | rc = adm_store_cal_data(dev_map[dev_map_idx].port_id, |
| 544 | dev_map[dev_map_idx].copp_idx, path, perf_mode, |
| 545 | ADM_AUDVOL_CAL, aud_cal_data->aud_vol_data, |
| 546 | &aud_cal_data->aud_vol_size); |
| 547 | if (rc < 0) { |
| 548 | pr_err("%s: store cal data err %d\n", __func__, rc); |
| 549 | kfree(aud_cal_data); |
| 550 | goto end; |
| 551 | } |
| 552 | |
| 553 | dev_map[dev_map_idx].cal_data = (void *)aud_cal_data; |
| 554 | |
| 555 | end: |
| 556 | pr_debug("%s: ret %d\n", __func__, rc); |
| 557 | return rc; |
| 558 | } |
| 559 | |
| 560 | static int msm_ds2_dap_free_cal_data(int dev_map_idx) |
| 561 | { |
| 562 | int rc = 0; |
| 563 | struct audio_rx_cal_data *aud_cal_data; |
| 564 | |
| 565 | pr_debug("%s: dev_map_idx %d\n", __func__, dev_map_idx); |
| 566 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 567 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 568 | rc = -EINVAL; |
| 569 | goto end; |
| 570 | } |
| 571 | aud_cal_data = (struct audio_rx_cal_data *) |
| 572 | dev_map[dev_map_idx].cal_data; |
| 573 | kfree(aud_cal_data); |
| 574 | dev_map[dev_map_idx].cal_data = NULL; |
| 575 | |
| 576 | end: |
| 577 | return rc; |
| 578 | } |
| 579 | |
| 580 | static int msm_ds2_dap_send_cal_data(int dev_map_idx) |
| 581 | { |
| 582 | int rc = 0; |
| 583 | struct audio_rx_cal_data *aud_cal_data = NULL; |
| 584 | |
| 585 | pr_debug("%s: devmap index %d\n", __func__, dev_map_idx); |
| 586 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 587 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 588 | rc = -EINVAL; |
| 589 | goto end; |
| 590 | } |
| 591 | |
| 592 | if (dev_map[dev_map_idx].cal_data == NULL) { |
| 593 | pr_err("%s: No valid calibration data stored for idx %d\n", |
| 594 | __func__, dev_map_idx); |
| 595 | rc = -EINVAL; |
| 596 | goto end; |
| 597 | } |
| 598 | |
| 599 | /* send aud proc cal */ |
| 600 | aud_cal_data = (struct audio_rx_cal_data *) |
| 601 | dev_map[dev_map_idx].cal_data; |
| 602 | rc = adm_send_calibration(dev_map[dev_map_idx].port_id, |
| 603 | dev_map[dev_map_idx].copp_idx, |
| 604 | ADM_PATH_PLAYBACK, 0, |
| 605 | ADM_AUDPROC_CAL, |
| 606 | aud_cal_data->aud_proc_data, |
| 607 | aud_cal_data->aud_proc_size); |
| 608 | if (rc < 0) { |
| 609 | pr_err("%s: adm_send_calibration failed %d\n", __func__, rc); |
| 610 | goto end; |
| 611 | } |
| 612 | |
| 613 | /* send aud volume cal*/ |
| 614 | rc = adm_send_calibration(dev_map[dev_map_idx].port_id, |
| 615 | dev_map[dev_map_idx].copp_idx, |
| 616 | ADM_PATH_PLAYBACK, 0, |
| 617 | ADM_AUDVOL_CAL, |
| 618 | aud_cal_data->aud_vol_data, |
| 619 | aud_cal_data->aud_vol_size); |
| 620 | if (rc < 0) |
| 621 | pr_err("%s: adm_send_calibration failed %d\n", __func__, rc); |
| 622 | end: |
| 623 | pr_debug("%s: return %d\n", __func__, rc); |
| 624 | return rc; |
| 625 | } |
| 626 | |
| 627 | static inline int msm_ds2_dap_can_enable_module(int32_t module_id) |
| 628 | { |
| 629 | if (module_id == MTMX_MODULE_ID_DEFAULT_CHMIXER || |
| 630 | module_id == AUDPROC_MODULE_ID_RESAMPLER || |
| 631 | module_id == AUDPROC_MODULE_ID_VOL_CTRL) { |
| 632 | return false; |
| 633 | } |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | static int msm_ds2_dap_init_modules_in_topology(int dev_map_idx) |
| 638 | { |
| 639 | int rc = 0, i = 0, port_id, copp_idx; |
| 640 | /* Account for 32 bit integer allocation */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 641 | int32_t param_sz = |
| 642 | (ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH / sizeof(uint32_t)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 643 | int32_t *update_param_val = NULL; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 644 | struct module_instance_info mod_inst_info; |
| 645 | int mod_inst_info_sz = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 646 | |
| 647 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 648 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 649 | rc = -EINVAL; |
| 650 | goto end; |
| 651 | } |
| 652 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 653 | memset(&mod_inst_info, 0, sizeof(mod_inst_info)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 654 | port_id = dev_map[dev_map_idx].port_id; |
| 655 | copp_idx = dev_map[dev_map_idx].copp_idx; |
| 656 | pr_debug("%s: port_id 0x%x copp_idx %d\n", __func__, port_id, copp_idx); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 657 | update_param_val = |
| 658 | kzalloc(ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH, GFP_KERNEL); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 659 | if (!update_param_val) { |
| 660 | pr_err("%s, param memory alloc failed\n", __func__); |
| 661 | rc = -ENOMEM; |
| 662 | goto end; |
| 663 | } |
| 664 | |
| 665 | if (!ds2_dap_params_states.dap_bypass) { |
| 666 | /* get modules from dsp */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 667 | rc = adm_get_pp_topo_module_list_v2( |
| 668 | port_id, copp_idx, |
| 669 | ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH, |
| 670 | update_param_val); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 671 | if (rc < 0) { |
| 672 | pr_err("%s:topo list port %d, err %d,copp_idx %d\n", |
| 673 | __func__, port_id, copp_idx, rc); |
| 674 | goto end; |
| 675 | } |
| 676 | |
| 677 | if (update_param_val[0] > (param_sz - 1)) { |
| 678 | pr_err("%s:max modules exp/ret [%d: %d]\n", |
| 679 | __func__, (param_sz - 1), |
| 680 | update_param_val[0]); |
| 681 | rc = -EINVAL; |
| 682 | goto end; |
| 683 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 684 | |
| 685 | mod_inst_info_sz = sizeof(struct module_instance_info) / |
| 686 | sizeof(uint32_t); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 687 | /* Turn off modules */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 688 | for (i = 1; i < update_param_val[0] * mod_inst_info_sz; |
| 689 | i += mod_inst_info_sz) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 690 | if (!msm_ds2_dap_can_enable_module( |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 691 | update_param_val[i]) || |
| 692 | (update_param_val[i] == DS2_MODULE_ID)) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 693 | pr_debug("%s: Do not enable/disable %d\n", |
| 694 | __func__, update_param_val[i]); |
| 695 | continue; |
| 696 | } |
| 697 | |
| 698 | pr_debug("%s: param disable %d\n", |
| 699 | __func__, update_param_val[i]); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 700 | memcpy(&mod_inst_info, &update_param_val[i], |
| 701 | sizeof(mod_inst_info)); |
| 702 | adm_param_enable_v2(port_id, copp_idx, |
| 703 | mod_inst_info, |
| 704 | MODULE_DISABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 705 | } |
| 706 | } else { |
| 707 | msm_ds2_dap_send_cal_data(dev_map_idx); |
| 708 | |
| 709 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 710 | |
| 711 | mod_inst_info.module_id = DS2_MODULE_ID; |
| 712 | mod_inst_info.instance_id = INSTANCE_ID_0; |
| 713 | adm_param_enable_v2(port_id, copp_idx, mod_inst_info, |
| 714 | !ds2_dap_params_states.dap_bypass); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 715 | end: |
| 716 | kfree(update_param_val); |
| 717 | return rc; |
| 718 | } |
| 719 | |
| 720 | static bool msm_ds2_dap_check_is_param_modified(int32_t *dap_params_modified, |
| 721 | int32_t idx, int32_t commit) |
| 722 | { |
| 723 | if ((dap_params_modified[idx] == 0) || |
| 724 | (commit && |
| 725 | ((dap_params_modified[idx] & 0x00010000) && |
| 726 | ((dap_params_modified[idx] & 0x0000FFFF) <= 1)))) { |
| 727 | pr_debug("%s: not modified at idx %d\n", __func__, idx); |
| 728 | return false; |
| 729 | } |
| 730 | pr_debug("%s: modified at idx %d\n", __func__, idx); |
| 731 | return true; |
| 732 | } |
| 733 | |
| 734 | static int msm_ds2_dap_map_device_to_dolby_cache_devices(int32_t device_id) |
| 735 | { |
| 736 | int32_t cache_dev = -1; |
| 737 | |
| 738 | switch (device_id) { |
| 739 | case DEVICE_NONE: |
| 740 | cache_dev = DOLBY_OFF_CACHE; |
| 741 | break; |
| 742 | case EARPIECE: |
| 743 | case SPEAKER: |
| 744 | cache_dev = DOLBY_SPEAKER_CACHE; |
| 745 | break; |
| 746 | case WIRED_HEADSET: |
| 747 | case WIRED_HEADPHONE: |
| 748 | case ANLG_DOCK_HEADSET: |
| 749 | case DGTL_DOCK_HEADSET: |
| 750 | case ANC_HEADSET: |
| 751 | case ANC_HEADPHONE: |
| 752 | case BLUETOOTH_SCO: |
| 753 | case BLUETOOTH_SCO_HEADSET: |
| 754 | case BLUETOOTH_SCO_CARKIT: |
| 755 | cache_dev = DOLBY_HEADPHONE_CACHE; |
| 756 | break; |
| 757 | case FM: |
| 758 | case FM_TX: |
| 759 | cache_dev = DOLBY_FM_CACHE; |
| 760 | break; |
| 761 | case AUX_DIGITAL: |
| 762 | cache_dev = DOLBY_HDMI_CACHE; |
| 763 | break; |
| 764 | case PROXY: |
| 765 | case REMOTE_SUBMIX: |
| 766 | cache_dev = DOLBY_WFD_CACHE; |
| 767 | break; |
| 768 | default: |
| 769 | pr_err("%s: invalid cache device\n", __func__); |
| 770 | } |
| 771 | pr_debug("%s: cache device %d\n", __func__, cache_dev); |
| 772 | return cache_dev; |
| 773 | } |
| 774 | |
| 775 | static int msm_ds2_dap_update_num_devices(struct dolby_param_data *dolby_data, |
| 776 | int32_t *num_device, int32_t *dev_arr, |
| 777 | int32_t array_size) |
| 778 | { |
| 779 | int32_t idx = 0; |
| 780 | int supported_devices = 0; |
| 781 | |
| 782 | if (!array_size) { |
| 783 | pr_err("%s: array size zero\n", __func__); |
| 784 | return -EINVAL; |
| 785 | } |
| 786 | |
| 787 | if (dolby_data->device_id == DEVICE_OUT_ALL || |
| 788 | dolby_data->device_id == DEVICE_OUT_DEFAULT) |
| 789 | supported_devices = all_supported_devices; |
| 790 | else |
| 791 | supported_devices = dolby_data->device_id; |
| 792 | |
| 793 | if ((idx < array_size) && (supported_devices & EARPIECE)) |
| 794 | dev_arr[idx++] = EARPIECE; |
| 795 | if ((idx < array_size) && (supported_devices & SPEAKER)) |
| 796 | dev_arr[idx++] = SPEAKER; |
| 797 | if ((idx < array_size) && (supported_devices & WIRED_HEADSET)) |
| 798 | dev_arr[idx++] = WIRED_HEADSET; |
| 799 | if ((idx < array_size) && (supported_devices & WIRED_HEADPHONE)) |
| 800 | dev_arr[idx++] = WIRED_HEADPHONE; |
| 801 | if ((idx < array_size) && (supported_devices & BLUETOOTH_SCO)) |
| 802 | dev_arr[idx++] = BLUETOOTH_SCO; |
| 803 | if ((idx < array_size) && (supported_devices & BLUETOOTH_SCO_CARKIT)) |
| 804 | dev_arr[idx++] = BLUETOOTH_SCO_CARKIT; |
| 805 | if ((idx < array_size) && (supported_devices & BLUETOOTH_SCO_HEADSET)) |
| 806 | dev_arr[idx++] = BLUETOOTH_SCO_HEADSET; |
| 807 | if ((idx < array_size) && (supported_devices & AUX_DIGITAL)) |
| 808 | dev_arr[idx++] = AUX_DIGITAL; |
| 809 | if ((idx < array_size) && (supported_devices & ANLG_DOCK_HEADSET)) |
| 810 | dev_arr[idx++] = ANLG_DOCK_HEADSET; |
| 811 | if ((idx < array_size) && (supported_devices & DGTL_DOCK_HEADSET)) |
| 812 | dev_arr[idx++] = DGTL_DOCK_HEADSET; |
| 813 | if ((idx < array_size) && (supported_devices & REMOTE_SUBMIX)) |
| 814 | dev_arr[idx++] = REMOTE_SUBMIX; |
| 815 | if ((idx < array_size) && (supported_devices & ANC_HEADSET)) |
| 816 | dev_arr[idx++] = ANC_HEADSET; |
| 817 | if ((idx < array_size) && (supported_devices & ANC_HEADPHONE)) |
| 818 | dev_arr[idx++] = ANC_HEADPHONE; |
| 819 | if ((idx < array_size) && (supported_devices & PROXY)) |
| 820 | dev_arr[idx++] = PROXY; |
| 821 | if ((idx < array_size) && (supported_devices & FM)) |
| 822 | dev_arr[idx++] = FM; |
| 823 | if ((idx < array_size) && (supported_devices & FM_TX)) |
| 824 | dev_arr[idx++] = FM_TX; |
| 825 | /* CHECK device none separately */ |
| 826 | if ((idx < array_size) && (supported_devices == DEVICE_NONE)) |
| 827 | dev_arr[idx++] = DEVICE_NONE; |
| 828 | pr_debug("%s: dev id 0x%x, idx %d\n", __func__, |
| 829 | supported_devices, idx); |
| 830 | *num_device = idx; |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static int msm_ds2_dap_get_port_id( |
| 835 | int32_t device_id, int32_t be_id) |
| 836 | { |
| 837 | struct msm_pcm_routing_bdai_data bedais; |
| 838 | int port_id = DOLBY_INVALID_PORT_ID; |
| 839 | int port_type = 0; |
| 840 | |
| 841 | if (be_id < 0) { |
| 842 | port_id = -1; |
| 843 | goto end; |
| 844 | } |
| 845 | |
| 846 | msm_pcm_routing_get_bedai_info(be_id, &bedais); |
| 847 | pr_debug("%s: be port_id %d\n", __func__, bedais.port_id); |
| 848 | port_id = bedais.port_id; |
| 849 | port_type = afe_get_port_type(bedais.port_id); |
| 850 | if (port_type != MSM_AFE_PORT_TYPE_RX) |
| 851 | port_id = DOLBY_INVALID_PORT_ID; |
| 852 | end: |
| 853 | pr_debug("%s: device_id 0x%x, be_id %d, port_id %d\n", |
| 854 | __func__, device_id, be_id, port_id); |
| 855 | return port_id; |
| 856 | } |
| 857 | |
| 858 | static int msm_ds2_dap_update_dev_map_port_id(int32_t device_id, int port_id) |
| 859 | { |
| 860 | int i; |
| 861 | |
| 862 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 863 | if (dev_map[i].device_id == device_id) |
| 864 | dev_map[i].port_id = port_id; |
| 865 | } |
| 866 | pr_debug("%s: port_id %d, device_id 0x%x\n", |
| 867 | __func__, port_id, device_id); |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | static int msm_ds2_dap_handle_bypass_wait(int port_id, int copp_idx, |
| 872 | int wait_time) |
| 873 | { |
| 874 | int ret = 0; |
| 875 | |
| 876 | adm_set_wait_parameters(port_id, copp_idx); |
| 877 | msm_pcm_routing_release_lock(); |
| 878 | ret = adm_wait_timeout(port_id, copp_idx, wait_time); |
| 879 | msm_pcm_routing_acquire_lock(); |
| 880 | /* Reset the parameters if wait has timed out */ |
| 881 | if (ret == 0) |
| 882 | adm_reset_wait_parameters(port_id, copp_idx); |
| 883 | return ret; |
| 884 | } |
| 885 | |
| 886 | static int msm_ds2_dap_handle_bypass(struct dolby_param_data *dolby_data) |
| 887 | { |
| 888 | int rc = 0, i = 0, j = 0; |
| 889 | /*Account for 32 bit integer allocation */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 890 | int32_t param_sz = |
| 891 | (ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH / sizeof(uint32_t)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 892 | int32_t *mod_list = NULL; |
| 893 | int port_id = 0, copp_idx = -1; |
| 894 | bool cs_onoff = ds2_dap_params_states.custom_stereo_onoff; |
| 895 | int ramp_wait = DOLBY_SOFT_VOLUME_PERIOD; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 896 | struct module_instance_info mod_inst_info; |
| 897 | int mod_inst_info_sz = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 898 | |
| 899 | pr_debug("%s: bypass type %d bypass %d custom stereo %d\n", __func__, |
| 900 | ds2_dap_params_states.dap_bypass_type, |
| 901 | ds2_dap_params_states.dap_bypass, |
| 902 | ds2_dap_params_states.custom_stereo_onoff); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 903 | memset(&mod_inst_info, 0, sizeof(mod_inst_info)); |
| 904 | mod_list = |
| 905 | kzalloc(ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH, GFP_KERNEL); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 906 | if (!mod_list) { |
| 907 | pr_err("%s: param memory alloc failed\n", __func__); |
| 908 | rc = -ENOMEM; |
| 909 | goto end; |
| 910 | } |
| 911 | |
| 912 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 913 | pr_debug("%s: active dev %d\n", __func__, dev_map[i].active); |
| 914 | if (dev_map[i].active) { |
| 915 | port_id = dev_map[i].port_id; |
| 916 | copp_idx = dev_map[i].copp_idx; |
| 917 | |
| 918 | if (port_id == DOLBY_INVALID_PORT_ID) { |
| 919 | pr_err("%s: invalid port\n", __func__); |
| 920 | rc = 0; |
| 921 | goto end; |
| 922 | } |
| 923 | |
| 924 | if ((copp_idx < 0) || |
| 925 | (copp_idx >= MAX_COPPS_PER_PORT)) { |
| 926 | pr_err("%s: Invalid copp_idx\n", __func__); |
| 927 | rc = 0; |
| 928 | goto end; |
| 929 | } |
| 930 | |
| 931 | /* getmodules from dsp */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 932 | rc = adm_get_pp_topo_module_list_v2( |
| 933 | port_id, copp_idx, |
| 934 | ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH, |
| 935 | mod_list); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 936 | if (rc < 0) { |
| 937 | pr_err("%s:adm get topo list port %d", |
| 938 | __func__, port_id); |
| 939 | pr_err("copp_idx %d, err %d\n", |
| 940 | copp_idx, rc); |
| 941 | goto end; |
| 942 | } |
| 943 | if (mod_list[0] > (param_sz - 1)) { |
| 944 | pr_err("%s:max modules exp/ret [%d: %d]\n", |
| 945 | __func__, (param_sz - 1), |
| 946 | mod_list[0]); |
| 947 | rc = -EINVAL; |
| 948 | goto end; |
| 949 | } |
| 950 | /* |
| 951 | * get ramp parameters |
| 952 | * check for change in ramp parameters |
| 953 | * update ramp wait |
| 954 | */ |
| 955 | msm_ds2_dap_check_and_update_ramp_wait(port_id, |
| 956 | copp_idx, |
| 957 | &ramp_wait); |
| 958 | |
| 959 | /* Mute before switching modules */ |
| 960 | rc = adm_set_volume(port_id, copp_idx, |
| 961 | VOLUME_ZERO_GAIN); |
| 962 | if (rc < 0) { |
| 963 | /* |
| 964 | * Not Fatal can continue bypass operations. |
| 965 | * Do not need to block playback |
| 966 | */ |
| 967 | pr_info("%s :Set volume port_id %d", |
| 968 | __func__, port_id); |
| 969 | pr_info("copp_idx %d, error %d\n", |
| 970 | copp_idx, rc); |
| 971 | } |
| 972 | |
| 973 | rc = msm_ds2_dap_handle_bypass_wait(port_id, copp_idx, |
| 974 | (ramp_wait + |
| 975 | DOLBY_ADDITIONAL_RAMP_WAIT)); |
| 976 | if (rc == -EINTR) { |
| 977 | pr_info("%s:bypass interrupted-ignore,port %d", |
| 978 | __func__, port_id); |
| 979 | pr_info("copp_idx %d\n", copp_idx); |
| 980 | rc = 0; |
| 981 | continue; |
| 982 | } |
| 983 | |
| 984 | /* if dap bypass is set */ |
| 985 | if (ds2_dap_params_states.dap_bypass) { |
| 986 | /* Turn off dap module */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 987 | mod_inst_info.module_id = DS2_MODULE_ID; |
| 988 | mod_inst_info.instance_id = INSTANCE_ID_0; |
| 989 | adm_param_enable_v2(port_id, copp_idx, |
| 990 | mod_inst_info, |
| 991 | MODULE_DISABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 992 | /* |
| 993 | * If custom stereo is on at the time of bypass, |
| 994 | * switch off custom stereo on dap and turn on |
| 995 | * custom stereo on qti channel mixer. |
| 996 | */ |
| 997 | if (cs_onoff) { |
| 998 | rc = dap_set_custom_stereo_onoff(i, |
| 999 | !cs_onoff); |
| 1000 | if (rc < 0) { |
| 1001 | pr_info("%s:D_CS i %d,rc %d\n", |
| 1002 | __func__, i, rc); |
| 1003 | } |
| 1004 | rc = qti_set_custom_stereo_on(port_id, |
| 1005 | copp_idx, |
| 1006 | cs_onoff); |
| 1007 | if (rc < 0) { |
| 1008 | pr_info("%s:Q_CS port id 0x%x", |
| 1009 | __func__, port_id); |
| 1010 | pr_info("copp idx %d, rc %d\n", |
| 1011 | copp_idx, rc); |
| 1012 | } |
| 1013 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1014 | |
| 1015 | mod_inst_info_sz = |
| 1016 | sizeof(struct module_instance_info) / |
| 1017 | sizeof(uint32_t); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1018 | /* Turn on qti modules */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1019 | for (j = 1; j < mod_list[0] * mod_inst_info_sz; |
| 1020 | j += mod_inst_info_sz) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1021 | if (!msm_ds2_dap_can_enable_module( |
| 1022 | mod_list[j]) || |
| 1023 | mod_list[j] == |
| 1024 | DS2_MODULE_ID) |
| 1025 | continue; |
| 1026 | pr_debug("%s: param enable %d\n", |
| 1027 | __func__, mod_list[j]); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1028 | memcpy(&mod_inst_info, &mod_list[j], |
| 1029 | sizeof(mod_inst_info)); |
| 1030 | adm_param_enable_v2(port_id, copp_idx, |
| 1031 | mod_inst_info, |
| 1032 | MODULE_ENABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | /* Add adm api to resend calibration on port */ |
| 1036 | rc = msm_ds2_dap_send_cal_data(i); |
| 1037 | if (rc < 0) { |
| 1038 | /* |
| 1039 | * Not fatal,continue bypass operations. |
| 1040 | * Do not need to block playback |
| 1041 | */ |
| 1042 | pr_info("%s:send cal err %d index %d\n", |
| 1043 | __func__, rc, i); |
| 1044 | } |
| 1045 | } else { |
| 1046 | /* Turn off qti modules */ |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1047 | for (j = 1; j < mod_list[0] * mod_inst_info_sz; |
| 1048 | j += mod_inst_info_sz) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1049 | if (!msm_ds2_dap_can_enable_module( |
| 1050 | mod_list[j]) || |
| 1051 | mod_list[j] == |
| 1052 | DS2_MODULE_ID) |
| 1053 | continue; |
| 1054 | pr_debug("%s: param disable %d\n", |
| 1055 | __func__, mod_list[j]); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1056 | memcpy(&mod_inst_info, &mod_list[j], |
| 1057 | sizeof(mod_inst_info)); |
| 1058 | adm_param_enable_v2(port_id, copp_idx, |
| 1059 | mod_inst_info, |
| 1060 | MODULE_DISABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | /* Enable DAP modules */ |
| 1064 | pr_debug("%s:DS2 param enable\n", __func__); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1065 | mod_inst_info.module_id = DS2_MODULE_ID; |
| 1066 | mod_inst_info.instance_id = INSTANCE_ID_0; |
| 1067 | adm_param_enable_v2(port_id, copp_idx, |
| 1068 | mod_inst_info, |
| 1069 | MODULE_ENABLE); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1070 | /* |
| 1071 | * If custom stereo is on at the time of dap on, |
| 1072 | * switch off custom stereo on qti channel mixer |
| 1073 | * and turn on custom stereo on DAP. |
| 1074 | * mixer(qti). |
| 1075 | */ |
| 1076 | if (cs_onoff) { |
| 1077 | rc = qti_set_custom_stereo_on(port_id, |
| 1078 | copp_idx, |
| 1079 | !cs_onoff); |
| 1080 | if (rc < 0) { |
| 1081 | pr_info("%s:Q_CS port_id 0x%x", |
| 1082 | __func__, port_id); |
| 1083 | pr_info("copp_idx %d rc %d\n", |
| 1084 | copp_idx, rc); |
| 1085 | } |
| 1086 | rc = dap_set_custom_stereo_onoff(i, |
| 1087 | cs_onoff); |
| 1088 | if (rc < 0) { |
| 1089 | pr_info("%s:D_CS i %d,rc %d\n", |
| 1090 | __func__, i, rc); |
| 1091 | } |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | rc = msm_ds2_dap_handle_bypass_wait(port_id, copp_idx, |
| 1096 | DOLBY_MODULE_ENABLE_PERIOD); |
| 1097 | if (rc == -EINTR) { |
| 1098 | pr_info("%s:bypass interrupted port_id %d copp_idx %d\n", |
| 1099 | __func__, port_id, copp_idx); |
| 1100 | /* Interrupted ignore bypass */ |
| 1101 | rc = 0; |
| 1102 | continue; |
| 1103 | } |
| 1104 | |
| 1105 | /* set volume to unity gain after module on/off */ |
| 1106 | rc = adm_set_volume(port_id, copp_idx, |
| 1107 | VOLUME_UNITY_GAIN); |
| 1108 | if (rc < 0) { |
| 1109 | /* |
| 1110 | * Not Fatal can continue bypass operations. |
| 1111 | * Do not need to block playback |
| 1112 | */ |
| 1113 | pr_info("%s: Set vol port %d copp %d, rc %d\n", |
| 1114 | __func__, port_id, copp_idx, rc); |
| 1115 | rc = 0; |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | end: |
| 1121 | kfree(mod_list); |
| 1122 | pr_debug("%s:return rc=%d\n", __func__, rc); |
| 1123 | return rc; |
| 1124 | } |
| 1125 | |
| 1126 | static int msm_ds2_dap_send_end_point(int dev_map_idx, int endp_idx) |
| 1127 | { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1128 | uint32_t offset = 0; |
| 1129 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1130 | int cache_device = 0; |
| 1131 | struct ds2_dap_params_s *ds2_ap_params_obj = NULL; |
| 1132 | int32_t *modified_param = NULL; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1133 | int rc = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1134 | |
| 1135 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 1136 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 1137 | rc = -EINVAL; |
| 1138 | goto end; |
| 1139 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1140 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1141 | cache_device = dev_map[dev_map_idx].cache_dev; |
| 1142 | |
| 1143 | ds2_ap_params_obj = &ds2_dap_params[cache_device]; |
| 1144 | pr_debug("%s: cache dev %d, dev_map_idx %d\n", __func__, |
| 1145 | cache_device, dev_map_idx); |
| 1146 | pr_debug("%s: endp - %pK %pK\n", __func__, |
| 1147 | &ds2_dap_params[cache_device], ds2_ap_params_obj); |
| 1148 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1149 | if (dev_map[dev_map_idx].port_id == DOLBY_INVALID_PORT_ID) { |
| 1150 | pr_err("%s: invalid port\n", __func__); |
| 1151 | rc = -EINVAL; |
| 1152 | goto end; |
| 1153 | } |
| 1154 | |
| 1155 | if ((dev_map[dev_map_idx].copp_idx < 0) || |
| 1156 | (dev_map[dev_map_idx].copp_idx >= MAX_COPPS_PER_PORT)) { |
| 1157 | pr_err("%s: Invalid copp_idx\n", __func__); |
| 1158 | rc = -EINVAL; |
| 1159 | goto end; |
| 1160 | } |
| 1161 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1162 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1163 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1164 | param_hdr.param_id = DOLBY_PARAM_ID_INIT_ENDP; |
| 1165 | param_hdr.param_size = sizeof(offset); |
| 1166 | offset = ds2_ap_params_obj->params_val[ds2_dap_params_offset[endp_idx]]; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1167 | pr_debug("%s: off %d, length %d\n", __func__, |
| 1168 | ds2_dap_params_offset[endp_idx], |
| 1169 | ds2_dap_params_length[endp_idx]); |
| 1170 | pr_debug("%s: param 0x%x, param val %d\n", __func__, |
| 1171 | ds2_dap_params_id[endp_idx], ds2_ap_params_obj-> |
| 1172 | params_val[ds2_dap_params_offset[endp_idx]]); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1173 | rc = adm_pack_and_set_one_pp_param(dev_map[dev_map_idx].port_id, |
| 1174 | dev_map[dev_map_idx].copp_idx, |
| 1175 | param_hdr, (u8 *) &offset); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1176 | if (rc) { |
| 1177 | pr_err("%s: send dolby params failed rc %d\n", __func__, rc); |
| 1178 | rc = -EINVAL; |
| 1179 | } |
| 1180 | modified_param = ds2_ap_params_obj->dap_params_modified; |
| 1181 | if (modified_param == NULL) { |
| 1182 | pr_err("%s: modified param structure invalid\n", |
| 1183 | __func__); |
| 1184 | rc = -EINVAL; |
| 1185 | goto end; |
| 1186 | } |
| 1187 | |
| 1188 | if (msm_ds2_dap_check_is_param_modified(modified_param, endp_idx, 0)) |
| 1189 | ds2_ap_params_obj->dap_params_modified[endp_idx] = 0x00010001; |
| 1190 | |
| 1191 | end: |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1192 | return rc; |
| 1193 | } |
| 1194 | |
| 1195 | static int msm_ds2_dap_send_cached_params(int dev_map_idx, |
| 1196 | int commit) |
| 1197 | { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1198 | uint8_t *packed_params = NULL; |
| 1199 | uint32_t packed_params_size = 0; |
| 1200 | uint32_t param_size = 0; |
| 1201 | struct param_hdr_v3 param_hdr; |
| 1202 | uint32_t idx, i, ret = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1203 | int cache_device = 0; |
| 1204 | struct ds2_dap_params_s *ds2_ap_params_obj = NULL; |
| 1205 | int32_t *modified_param = NULL; |
| 1206 | |
| 1207 | if (dev_map_idx < 0 || dev_map_idx >= DS2_DEVICES_ALL) { |
| 1208 | pr_err("%s: invalid dev map index %d\n", __func__, dev_map_idx); |
| 1209 | ret = -EINVAL; |
| 1210 | goto end; |
| 1211 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1212 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1213 | cache_device = dev_map[dev_map_idx].cache_dev; |
| 1214 | |
| 1215 | /* Use off profile cache in only for soft bypass */ |
| 1216 | if (ds2_dap_params_states.dap_bypass_type == DAP_SOFT_BYPASS && |
| 1217 | ds2_dap_params_states.dap_bypass == true) { |
| 1218 | pr_debug("%s: use bypass cache 0\n", __func__); |
| 1219 | cache_device = dev_map[0].cache_dev; |
| 1220 | } |
| 1221 | |
| 1222 | ds2_ap_params_obj = &ds2_dap_params[cache_device]; |
| 1223 | pr_debug("%s: cached param - %pK %pK, cache_device %d\n", __func__, |
| 1224 | &ds2_dap_params[cache_device], ds2_ap_params_obj, |
| 1225 | cache_device); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1226 | |
| 1227 | /* |
| 1228 | * Allocate the max space needed. This is enough space to hold the |
| 1229 | * header for each param plus the total size of all the params. |
| 1230 | */ |
| 1231 | packed_params_size = (sizeof(param_hdr) * (MAX_DS2_PARAMS - 1)) + |
| 1232 | (TOTAL_LENGTH_DOLBY_PARAM * sizeof(uint32_t)); |
| 1233 | packed_params = kzalloc(packed_params_size, GFP_KERNEL); |
| 1234 | if (!packed_params) |
| 1235 | return -ENOMEM; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1236 | |
| 1237 | if (dev_map[dev_map_idx].port_id == DOLBY_INVALID_PORT_ID) { |
| 1238 | pr_err("%s: invalid port id\n", __func__); |
| 1239 | ret = -EINVAL; |
| 1240 | goto end; |
| 1241 | } |
| 1242 | |
| 1243 | if ((dev_map[dev_map_idx].copp_idx < 0) || |
| 1244 | (dev_map[dev_map_idx].copp_idx >= MAX_COPPS_PER_PORT)) { |
| 1245 | pr_err("%s: Invalid copp_idx\n", __func__); |
| 1246 | ret = -EINVAL; |
| 1247 | goto end; |
| 1248 | } |
| 1249 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1250 | packed_params_size = 0; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1251 | for (i = 0; i < (MAX_DS2_PARAMS-1); i++) { |
| 1252 | /*get the pointer to the param modified array in the cache*/ |
| 1253 | modified_param = ds2_ap_params_obj->dap_params_modified; |
| 1254 | if (modified_param == NULL) { |
| 1255 | pr_err("%s: modified param structure invalid\n", |
| 1256 | __func__); |
| 1257 | ret = -EINVAL; |
| 1258 | goto end; |
| 1259 | } |
| 1260 | if (!msm_ds2_dap_check_is_param_modified(modified_param, i, |
| 1261 | commit)) |
| 1262 | continue; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1263 | |
| 1264 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1265 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1266 | param_hdr.param_id = ds2_dap_params_id[i]; |
| 1267 | param_hdr.param_size = |
| 1268 | ds2_dap_params_length[i] * sizeof(uint32_t); |
| 1269 | |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1270 | idx = ds2_dap_params_offset[i]; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1271 | ret = q6common_pack_pp_params( |
| 1272 | packed_params + packed_params_size, ¶m_hdr, |
| 1273 | (u8 *) &ds2_ap_params_obj->params_val[idx], |
| 1274 | ¶m_size); |
| 1275 | if (ret) { |
| 1276 | pr_err("%s: Failed to pack params, error %d\n", |
| 1277 | __func__, ret); |
| 1278 | goto end; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1279 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1280 | |
| 1281 | packed_params_size += param_size; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1282 | } |
| 1283 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1284 | pr_debug("%s: total packed param length: %d\n", __func__, |
| 1285 | packed_params_size); |
| 1286 | if (packed_params_size) { |
| 1287 | ret = adm_set_pp_params(dev_map[dev_map_idx].port_id, |
| 1288 | dev_map[dev_map_idx].copp_idx, NULL, |
| 1289 | packed_params, packed_params_size); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1290 | if (ret) { |
| 1291 | pr_err("%s: send dolby params failed ret %d\n", |
| 1292 | __func__, ret); |
| 1293 | ret = -EINVAL; |
| 1294 | goto end; |
| 1295 | } |
| 1296 | for (i = 0; i < MAX_DS2_PARAMS-1; i++) { |
| 1297 | /*get pointer to the param modified array in the cache*/ |
| 1298 | modified_param = ds2_ap_params_obj->dap_params_modified; |
| 1299 | if (modified_param == NULL) { |
| 1300 | pr_err("%s: modified param struct invalid\n", |
| 1301 | __func__); |
| 1302 | ret = -EINVAL; |
| 1303 | goto end; |
| 1304 | } |
| 1305 | if (!msm_ds2_dap_check_is_param_modified( |
| 1306 | modified_param, i, commit)) |
| 1307 | continue; |
| 1308 | ds2_ap_params_obj->dap_params_modified[i] = 0x00010001; |
| 1309 | } |
| 1310 | } |
| 1311 | end: |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1312 | kfree(packed_params); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1313 | return ret; |
| 1314 | } |
| 1315 | |
| 1316 | static int msm_ds2_dap_commit_params(struct dolby_param_data *dolby_data, |
| 1317 | int commit) |
| 1318 | { |
| 1319 | int ret = 0, i, idx; |
| 1320 | struct ds2_dap_params_s *ds2_ap_params_obj = NULL; |
| 1321 | int32_t *modified_param = NULL; |
| 1322 | |
| 1323 | /* Do not commit params if in hard bypass */ |
| 1324 | if (ds2_dap_params_states.dap_bypass_type == DAP_HARD_BYPASS && |
| 1325 | ds2_dap_params_states.dap_bypass == true) { |
| 1326 | pr_debug("%s: called in bypass", __func__); |
| 1327 | ret = -EINVAL; |
| 1328 | goto end; |
| 1329 | } |
| 1330 | for (idx = 0; idx < MAX_DS2_PARAMS; idx++) { |
| 1331 | if (ds2_dap_params_id[idx] == DOLBY_PARAM_ID_INIT_ENDP) |
| 1332 | break; |
| 1333 | } |
| 1334 | if (idx >= MAX_DS2_PARAMS || idx < 0) { |
| 1335 | pr_err("%s: index of DS2 Param not found idx %d\n", |
| 1336 | __func__, idx); |
| 1337 | ret = -EINVAL; |
| 1338 | goto end; |
| 1339 | } |
| 1340 | pr_debug("%s: found endp - idx %d 0x%x\n", __func__, idx, |
| 1341 | ds2_dap_params_id[idx]); |
| 1342 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 1343 | pr_debug("%s:dev[0x%x,0x%x],i:%d,active:%d,bypass:%d,type:%d\n", |
| 1344 | __func__, dolby_data->device_id, dev_map[i].device_id, |
| 1345 | i, dev_map[i].active, ds2_dap_params_states.dap_bypass, |
| 1346 | ds2_dap_params_states.dap_bypass_type); |
| 1347 | |
| 1348 | if (((dev_map[i].device_id & ds2_dap_params_states.device) || |
| 1349 | ((ds2_dap_params_states.dap_bypass_type == |
| 1350 | DAP_SOFT_BYPASS) && |
| 1351 | (ds2_dap_params_states.dap_bypass == true))) && |
| 1352 | (dev_map[i].active == true)) { |
| 1353 | |
| 1354 | /*get ptr to the cache storing the params for device*/ |
| 1355 | if ((ds2_dap_params_states.dap_bypass_type == |
| 1356 | DAP_SOFT_BYPASS) && |
| 1357 | (ds2_dap_params_states.dap_bypass == true)) |
| 1358 | ds2_ap_params_obj = |
| 1359 | &ds2_dap_params[dev_map[0].cache_dev]; |
| 1360 | else |
| 1361 | ds2_ap_params_obj = |
| 1362 | &ds2_dap_params[dev_map[i].cache_dev]; |
| 1363 | |
| 1364 | /*get the pointer to the param modified array in cache*/ |
| 1365 | modified_param = ds2_ap_params_obj->dap_params_modified; |
| 1366 | if (modified_param == NULL) { |
| 1367 | pr_err("%s: modified_param NULL\n", __func__); |
| 1368 | ret = -EINVAL; |
| 1369 | goto end; |
| 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * Send the endp param if use cache is set |
| 1374 | * or if param is modified |
| 1375 | */ |
| 1376 | if (!commit || msm_ds2_dap_check_is_param_modified( |
| 1377 | modified_param, idx, commit)) { |
| 1378 | msm_ds2_dap_send_end_point(i, idx); |
| 1379 | commit = 0; |
| 1380 | } |
| 1381 | ret = msm_ds2_dap_send_cached_params(i, commit); |
| 1382 | if (ret < 0) { |
| 1383 | pr_err("%s: send cached param %d\n", |
| 1384 | __func__, ret); |
| 1385 | goto end; |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | end: |
| 1390 | return ret; |
| 1391 | } |
| 1392 | |
| 1393 | static int msm_ds2_dap_handle_commands(u32 cmd, void *arg) |
| 1394 | { |
| 1395 | int ret = 0, port_id = 0; |
| 1396 | int32_t data; |
| 1397 | struct dolby_param_data *dolby_data = (struct dolby_param_data *)arg; |
| 1398 | |
| 1399 | if (get_user(data, &dolby_data->data[0])) { |
| 1400 | pr_debug("%s error getting data\n", __func__); |
| 1401 | ret = -EFAULT; |
| 1402 | goto end; |
| 1403 | } |
| 1404 | |
| 1405 | pr_debug("%s: param_id %d,be_id %d,device_id 0x%x,length %d,data %d\n", |
| 1406 | __func__, dolby_data->param_id, dolby_data->be_id, |
| 1407 | dolby_data->device_id, dolby_data->length, data); |
| 1408 | |
| 1409 | switch (dolby_data->param_id) { |
| 1410 | case DAP_CMD_COMMIT_ALL: |
| 1411 | msm_ds2_dap_commit_params(dolby_data, 0); |
| 1412 | break; |
| 1413 | |
| 1414 | case DAP_CMD_COMMIT_CHANGED: |
| 1415 | msm_ds2_dap_commit_params(dolby_data, 1); |
| 1416 | break; |
| 1417 | |
| 1418 | case DAP_CMD_USE_CACHE_FOR_INIT: |
| 1419 | ds2_dap_params_states.use_cache = data; |
| 1420 | break; |
| 1421 | |
| 1422 | case DAP_CMD_SET_BYPASS: |
| 1423 | pr_debug("%s: bypass %d bypass type %d, data %d\n", __func__, |
| 1424 | ds2_dap_params_states.dap_bypass, |
| 1425 | ds2_dap_params_states.dap_bypass_type, |
| 1426 | data); |
| 1427 | /* Do not perform bypass operation if bypass state is same*/ |
| 1428 | if (ds2_dap_params_states.dap_bypass == data) |
| 1429 | break; |
| 1430 | ds2_dap_params_states.dap_bypass = data; |
| 1431 | /* hard bypass */ |
| 1432 | if (ds2_dap_params_states.dap_bypass_type == DAP_HARD_BYPASS) |
| 1433 | msm_ds2_dap_handle_bypass(dolby_data); |
| 1434 | /* soft bypass */ |
| 1435 | msm_ds2_dap_commit_params(dolby_data, 0); |
| 1436 | break; |
| 1437 | |
| 1438 | case DAP_CMD_SET_BYPASS_TYPE: |
| 1439 | if (data == true) |
| 1440 | ds2_dap_params_states.dap_bypass_type = |
| 1441 | DAP_HARD_BYPASS; |
| 1442 | else |
| 1443 | ds2_dap_params_states.dap_bypass_type = |
| 1444 | DAP_SOFT_BYPASS; |
| 1445 | pr_debug("%s: bypass type %d", __func__, |
| 1446 | ds2_dap_params_states.dap_bypass_type); |
| 1447 | break; |
| 1448 | |
| 1449 | case DAP_CMD_SET_ACTIVE_DEVICE: |
| 1450 | pr_debug("%s: DAP_CMD_SET_ACTIVE_DEVICE length %d\n", |
| 1451 | __func__, dolby_data->length); |
| 1452 | /* TODO: need to handle multiple instance*/ |
| 1453 | ds2_dap_params_states.device |= dolby_data->device_id; |
| 1454 | port_id = msm_ds2_dap_get_port_id( |
| 1455 | dolby_data->device_id, |
| 1456 | dolby_data->be_id); |
| 1457 | pr_debug("%s: device id 0x%x all_dev 0x%x port_id %d\n", |
| 1458 | __func__, dolby_data->device_id, |
| 1459 | ds2_dap_params_states.device, port_id); |
| 1460 | msm_ds2_dap_update_dev_map_port_id(dolby_data->device_id, |
| 1461 | port_id); |
| 1462 | if (port_id == DOLBY_INVALID_PORT_ID) { |
| 1463 | pr_err("%s: invalid port id %d\n", __func__, port_id); |
| 1464 | ret = -EINVAL; |
| 1465 | goto end; |
| 1466 | } |
| 1467 | break; |
| 1468 | } |
| 1469 | end: |
| 1470 | return ret; |
| 1471 | |
| 1472 | } |
| 1473 | |
| 1474 | static int msm_ds2_dap_set_param(u32 cmd, void *arg) |
| 1475 | { |
| 1476 | int rc = 0, idx, i, j, off, port_id = 0, cdev = 0; |
| 1477 | int32_t num_device = 0; |
| 1478 | int32_t data = 0; |
| 1479 | int32_t dev_arr[DS2_DSP_SUPPORTED_ENDP_DEVICE] = {0}; |
| 1480 | struct dolby_param_data *dolby_data = (struct dolby_param_data *)arg; |
| 1481 | |
| 1482 | rc = msm_ds2_dap_update_num_devices(dolby_data, &num_device, dev_arr, |
| 1483 | DS2_DSP_SUPPORTED_ENDP_DEVICE); |
| 1484 | if (num_device == 0 || rc < 0) { |
| 1485 | pr_err("%s: num devices 0\n", __func__); |
| 1486 | rc = -EINVAL; |
| 1487 | goto end; |
| 1488 | } |
| 1489 | for (i = 0; i < num_device; i++) { |
| 1490 | port_id = msm_ds2_dap_get_port_id(dev_arr[i], |
| 1491 | dolby_data->be_id); |
| 1492 | if (port_id != DOLBY_INVALID_PORT_ID) |
| 1493 | msm_ds2_dap_update_dev_map_port_id(dev_arr[i], port_id); |
| 1494 | |
| 1495 | cdev = msm_ds2_dap_map_device_to_dolby_cache_devices( |
| 1496 | dev_arr[i]); |
| 1497 | if (cdev < 0 || cdev >= DOLBY_MAX_CACHE) { |
| 1498 | pr_err("%s: Invalid cache device %d for device 0x%x\n", |
| 1499 | __func__, cdev, dev_arr[i]); |
| 1500 | rc = -EINVAL; |
| 1501 | goto end; |
| 1502 | } |
| 1503 | pr_debug("%s:port:%d,be:%d,dev:0x%x,cdev:%d,param:0x%x,len:%d\n" |
| 1504 | , __func__, port_id, dolby_data->be_id, dev_arr[i], |
| 1505 | cdev, dolby_data->param_id, dolby_data->length); |
| 1506 | for (idx = 0; idx < MAX_DS2_PARAMS; idx++) { |
| 1507 | /*paramid from user space*/ |
| 1508 | if (dolby_data->param_id == ds2_dap_params_id[idx]) |
| 1509 | break; |
| 1510 | } |
| 1511 | if (idx > MAX_DS2_PARAMS-1) { |
| 1512 | pr_err("%s: invalid param id 0x%x at idx %d\n", |
| 1513 | __func__, dolby_data->param_id, idx); |
| 1514 | rc = -EINVAL; |
| 1515 | goto end; |
| 1516 | } |
| 1517 | |
| 1518 | off = ds2_dap_params_offset[idx]; |
| 1519 | if ((dolby_data->length <= 0) || |
| 1520 | (dolby_data->length > TOTAL_LENGTH_DS2_PARAM - off)) { |
| 1521 | pr_err("%s: invalid length %d at idx %d\n", |
| 1522 | __func__, dolby_data->length, idx); |
| 1523 | rc = -EINVAL; |
| 1524 | goto end; |
| 1525 | } |
| 1526 | |
| 1527 | /* cache the parameters */ |
| 1528 | ds2_dap_params[cdev].dap_params_modified[idx] += 1; |
| 1529 | for (j = 0; j < dolby_data->length; j++) { |
| 1530 | if (get_user(data, &dolby_data->data[j])) { |
| 1531 | pr_debug("%s:error getting data\n", __func__); |
| 1532 | rc = -EFAULT; |
| 1533 | goto end; |
| 1534 | } |
| 1535 | ds2_dap_params[cdev].params_val[off + j] = data; |
| 1536 | pr_debug("%s:off %d,val[i/p:o/p]-[%d / %d]\n", |
| 1537 | __func__, off, data, |
| 1538 | ds2_dap_params[cdev]. |
| 1539 | params_val[off + j]); |
| 1540 | } |
| 1541 | } |
| 1542 | end: |
| 1543 | return rc; |
| 1544 | } |
| 1545 | |
| 1546 | static int msm_ds2_dap_get_param(u32 cmd, void *arg) |
| 1547 | { |
| 1548 | int rc = 0, i, port_id = 0, copp_idx = -1; |
| 1549 | struct dolby_param_data *dolby_data = (struct dolby_param_data *)arg; |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1550 | int32_t *params_value = NULL; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1551 | uint32_t params_length = DOLBY_MAX_LENGTH_INDIVIDUAL_PARAM * |
| 1552 | sizeof(uint32_t); |
| 1553 | uint32_t param_payload_len = |
| 1554 | DOLBY_PARAM_PAYLOAD_SIZE * sizeof(uint32_t); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1555 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1556 | |
| 1557 | /* Return error on get param in soft or hard bypass */ |
| 1558 | if (ds2_dap_params_states.dap_bypass == true) { |
| 1559 | pr_err("%s: called in bypass_type %d bypass %d\n", __func__, |
| 1560 | ds2_dap_params_states.dap_bypass_type, |
| 1561 | ds2_dap_params_states.dap_bypass); |
| 1562 | rc = -EINVAL; |
| 1563 | goto end; |
| 1564 | } |
| 1565 | |
| 1566 | /* Return if invalid length */ |
| 1567 | if ((dolby_data->length > |
| 1568 | (DOLBY_MAX_LENGTH_INDIVIDUAL_PARAM - DOLBY_PARAM_PAYLOAD_SIZE)) || |
| 1569 | (dolby_data->length <= 0)) { |
| 1570 | pr_err("Invalid length %d", dolby_data->length); |
| 1571 | rc = -EINVAL; |
| 1572 | goto end; |
| 1573 | } |
| 1574 | |
| 1575 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 1576 | if ((dev_map[i].active) && |
| 1577 | (dev_map[i].device_id & dolby_data->device_id)) { |
| 1578 | port_id = dev_map[i].port_id; |
| 1579 | copp_idx = dev_map[i].copp_idx; |
| 1580 | break; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | if (port_id == DOLBY_INVALID_PORT_ID) { |
| 1585 | pr_err("%s: Invalid port\n", __func__); |
| 1586 | rc = -EINVAL; |
| 1587 | goto end; |
| 1588 | } |
| 1589 | |
| 1590 | if ((copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) { |
| 1591 | pr_err("%s: Invalid copp_idx\n", __func__); |
| 1592 | rc = -EINVAL; |
| 1593 | goto end; |
| 1594 | } |
| 1595 | |
| 1596 | pr_debug("%s: port_id 0x%x, copp_idx %d, dev_map[i].device_id %x\n", |
| 1597 | __func__, port_id, copp_idx, dev_map[i].device_id); |
| 1598 | |
| 1599 | params_value = kzalloc(params_length + param_payload_len, |
| 1600 | GFP_KERNEL); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1601 | if (!params_value) |
| 1602 | return -ENOMEM; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1603 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1604 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1605 | if (dolby_data->param_id == DOLBY_PARAM_ID_VER) { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1606 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1607 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1608 | param_hdr.param_id = DOLBY_PARAM_ID_VER; |
| 1609 | param_hdr.param_size = params_length + param_payload_len; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1610 | } else { |
| 1611 | for (i = 0; i < MAX_DS2_PARAMS; i++) |
| 1612 | if (ds2_dap_params_id[i] == |
| 1613 | dolby_data->param_id) |
| 1614 | break; |
| 1615 | if (i > MAX_DS2_PARAMS-1) { |
| 1616 | pr_err("%s: invalid param id 0x%x at id %d\n", __func__, |
| 1617 | dolby_data->param_id, i); |
| 1618 | rc = -EINVAL; |
| 1619 | goto end; |
| 1620 | } else { |
| 1621 | params_length = |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1622 | ds2_dap_params_length[i] * sizeof(uint32_t); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1623 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1624 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1625 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1626 | param_hdr.param_id = ds2_dap_params_id[i]; |
| 1627 | param_hdr.param_size = |
| 1628 | params_length + param_payload_len; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1629 | } |
| 1630 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1631 | rc = adm_get_pp_params(port_id, copp_idx, ADM_CLIENT_ID_DEFAULT, NULL, |
| 1632 | ¶m_hdr, (u8 *) params_value); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1633 | if (rc) { |
| 1634 | pr_err("%s: get parameters failed rc %d\n", __func__, rc); |
| 1635 | rc = -EINVAL; |
| 1636 | goto end; |
| 1637 | } |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1638 | if (copy_to_user((void __user *) dolby_data->data, |
| 1639 | ¶ms_value[DOLBY_PARAM_PAYLOAD_SIZE], |
| 1640 | (dolby_data->length * sizeof(uint32_t)))) { |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1641 | pr_err("%s: error getting param\n", __func__); |
| 1642 | rc = -EFAULT; |
| 1643 | goto end; |
| 1644 | } |
| 1645 | end: |
| 1646 | kfree(params_value); |
| 1647 | return rc; |
| 1648 | } |
| 1649 | |
| 1650 | static int msm_ds2_dap_param_visualizer_control_get(u32 cmd, void *arg) |
| 1651 | { |
| 1652 | int32_t *visualizer_data = NULL; |
| 1653 | int i = 0, ret = 0, port_id = -1, cache_dev = -1, copp_idx = -1; |
| 1654 | int32_t *update_visualizer_data = NULL; |
| 1655 | struct dolby_param_data *dolby_data = (struct dolby_param_data *)arg; |
| 1656 | uint32_t offset, length, params_length; |
| 1657 | uint32_t param_payload_len = |
| 1658 | DOLBY_PARAM_PAYLOAD_SIZE * sizeof(uint32_t); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1659 | struct param_hdr_v3 param_hdr; |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1660 | |
| 1661 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 1662 | if ((dev_map[i].active)) { |
| 1663 | port_id = dev_map[i].port_id; |
| 1664 | cache_dev = dev_map[i].cache_dev; |
| 1665 | copp_idx = dev_map[i].copp_idx; |
| 1666 | break; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | if (port_id == DOLBY_INVALID_PORT_ID || |
| 1671 | (copp_idx < 0) || (copp_idx >= MAX_COPPS_PER_PORT)) { |
| 1672 | ret = 0; |
| 1673 | dolby_data->length = 0; |
| 1674 | pr_err("%s: no device active\n", __func__); |
| 1675 | goto end; |
| 1676 | } |
| 1677 | |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1678 | memset(¶m_hdr, 0, sizeof(param_hdr)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1679 | length = ds2_dap_params[cache_dev].params_val[DOLBY_PARAM_VCNB_OFFSET]; |
| 1680 | |
| 1681 | if (length > DOLBY_PARAM_VCNB_MAX_LENGTH || length <= 0) { |
| 1682 | ret = 0; |
| 1683 | dolby_data->length = 0; |
| 1684 | pr_err("%s Incorrect VCNB length", __func__); |
| 1685 | return -EINVAL; |
| 1686 | } |
| 1687 | |
| 1688 | params_length = (2*length + DOLBY_VIS_PARAM_HEADER_SIZE) * |
| 1689 | sizeof(uint32_t); |
| 1690 | |
| 1691 | visualizer_data = kzalloc(params_length, GFP_KERNEL); |
| 1692 | if (!visualizer_data) { |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1693 | pr_err("%s: params memory alloc failed\n", __func__); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1694 | ret = -ENOMEM; |
| 1695 | dolby_data->length = 0; |
| 1696 | goto end; |
| 1697 | } |
| 1698 | memset(visualizer_data, 0x0, params_length); |
| 1699 | |
| 1700 | /* Return error on get param in soft or hard bypass */ |
| 1701 | if (ds2_dap_params_states.dap_bypass == true) { |
| 1702 | pr_debug("%s: visualizer called in bypass, return 0\n", |
| 1703 | __func__); |
| 1704 | ret = 0; |
| 1705 | dolby_data->length = 0; |
| 1706 | goto end; |
| 1707 | } |
| 1708 | |
| 1709 | offset = 0; |
| 1710 | params_length = length * sizeof(uint32_t); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1711 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1712 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1713 | param_hdr.param_id = DOLBY_PARAM_ID_VCBG; |
| 1714 | param_hdr.param_size = length * sizeof(uint32_t) + param_payload_len; |
| 1715 | ret = adm_get_pp_params(port_id, copp_idx, ADM_CLIENT_ID_DEFAULT, NULL, |
| 1716 | ¶m_hdr, |
| 1717 | (((char *) (visualizer_data)) + offset)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1718 | if (ret) { |
| 1719 | pr_err("%s: get parameters failed ret %d\n", __func__, ret); |
| 1720 | ret = -EINVAL; |
| 1721 | dolby_data->length = 0; |
| 1722 | goto end; |
| 1723 | } |
| 1724 | offset = length * sizeof(uint32_t); |
Vignesh Kulothungan | 916967b | 2018-01-29 16:52:52 -0800 | [diff] [blame^] | 1725 | param_hdr.module_id = DOLBY_BUNDLE_MODULE_ID; |
| 1726 | param_hdr.instance_id = INSTANCE_ID_0; |
| 1727 | param_hdr.param_id = DOLBY_PARAM_ID_VCBE; |
| 1728 | param_hdr.param_size = length * sizeof(uint32_t) + param_payload_len; |
| 1729 | ret = adm_get_pp_params(port_id, copp_idx, ADM_CLIENT_ID_DEFAULT, NULL, |
| 1730 | ¶m_hdr, |
| 1731 | (((char *) (visualizer_data)) + offset)); |
Asish Bhattacharya | 8e2277f | 2017-07-20 18:31:55 +0530 | [diff] [blame] | 1732 | if (ret) { |
| 1733 | pr_err("%s: get parameters failed ret %d\n", __func__, ret); |
| 1734 | ret = -EINVAL; |
| 1735 | dolby_data->length = 0; |
| 1736 | goto end; |
| 1737 | } |
| 1738 | update_visualizer_data = visualizer_data; |
| 1739 | dolby_data->length = 2 * length; |
| 1740 | |
| 1741 | if (copy_to_user((void *)dolby_data->data, |
| 1742 | (void *)update_visualizer_data, |
| 1743 | (dolby_data->length * sizeof(uint32_t)))) { |
| 1744 | pr_err("%s: copy to user failed for data\n", __func__); |
| 1745 | dolby_data->length = 0; |
| 1746 | ret = -EFAULT; |
| 1747 | goto end; |
| 1748 | } |
| 1749 | |
| 1750 | end: |
| 1751 | kfree(visualizer_data); |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
| 1755 | int msm_ds2_dap_set_security_control(u32 cmd, void *arg) |
| 1756 | { |
| 1757 | struct dolby_param_license *dolby_license = |
| 1758 | ((struct dolby_param_license *)arg); |
| 1759 | pr_debug("%s: dmid %d license key %d\n", __func__, |
| 1760 | dolby_license->dmid, dolby_license->license_key); |
| 1761 | core_set_dolby_manufacturer_id(dolby_license->dmid); |
| 1762 | core_set_license(dolby_license->license_key, DOLBY_DS1_LICENSE_ID); |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | int msm_ds2_dap_update_port_parameters(struct snd_hwdep *hw, struct file *file, |
| 1767 | bool open) |
| 1768 | { |
| 1769 | int i = 0, dev_id = 0; |
| 1770 | |
| 1771 | pr_debug("%s: open %d\n", __func__, open); |
| 1772 | ds2_dap_params_states.node_opened = open; |
| 1773 | ds2_dap_params_states.dap_bypass = true; |
| 1774 | ds2_dap_params_states.dap_bypass_type = 0; |
| 1775 | ds2_dap_params_states.use_cache = 0; |
| 1776 | ds2_dap_params_states.device = 0; |
| 1777 | ds2_dap_params_states.custom_stereo_onoff = 0; |
| 1778 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 1779 | if (i == 0) |
| 1780 | dev_map[i].device_id = 0; |
| 1781 | else { |
| 1782 | dev_id = (1 << (i-1)); |
| 1783 | if (all_supported_devices & dev_id) |
| 1784 | dev_map[i].device_id = dev_id; |
| 1785 | else |
| 1786 | continue; |
| 1787 | } |
| 1788 | dev_map[i].cache_dev = |
| 1789 | msm_ds2_dap_map_device_to_dolby_cache_devices( |
| 1790 | dev_map[i].device_id); |
| 1791 | if (dev_map[i].cache_dev < 0 || |
| 1792 | dev_map[i].cache_dev >= DOLBY_MAX_CACHE) |
| 1793 | pr_err("%s: Invalid cache device %d for device 0x%x\n", |
| 1794 | __func__, |
| 1795 | dev_map[i].cache_dev, |
| 1796 | dev_map[i].device_id); |
| 1797 | dev_map[i].port_id = -1; |
| 1798 | dev_map[i].active = false; |
| 1799 | dev_map[i].stream_ref_count = 0; |
| 1800 | dev_map[i].cal_data = NULL; |
| 1801 | dev_map[i].copp_idx = -1; |
| 1802 | pr_debug("%s: device_id 0x%x, cache_dev %d act %d\n", __func__, |
| 1803 | dev_map[i].device_id, dev_map[i].cache_dev, |
| 1804 | dev_map[i].active); |
| 1805 | } |
| 1806 | return 0; |
| 1807 | |
| 1808 | } |
| 1809 | |
| 1810 | int msm_ds2_dap_ioctl_shared(struct snd_hwdep *hw, struct file *file, |
| 1811 | u32 cmd, void *arg) |
| 1812 | { |
| 1813 | int ret = 0; |
| 1814 | |
| 1815 | pr_debug("%s: cmd: 0x%x\n", __func__, cmd); |
| 1816 | switch (cmd) { |
| 1817 | case SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM: |
| 1818 | ret = msm_ds2_dap_set_param(cmd, arg); |
| 1819 | break; |
| 1820 | case SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM: |
| 1821 | ret = msm_ds2_dap_get_param(cmd, arg); |
| 1822 | break; |
| 1823 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND: |
| 1824 | ret = msm_ds2_dap_handle_commands(cmd, arg); |
| 1825 | break; |
| 1826 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE: |
| 1827 | ret = msm_ds2_dap_set_security_control(cmd, arg); |
| 1828 | break; |
| 1829 | case SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER: |
| 1830 | ret = msm_ds2_dap_param_visualizer_control_get(cmd, arg); |
| 1831 | break; |
| 1832 | default: |
| 1833 | pr_err("%s: called with invalid control 0x%x\n", __func__, cmd); |
| 1834 | ret = -EINVAL; |
| 1835 | } |
| 1836 | return ret; |
| 1837 | } |
| 1838 | |
| 1839 | int msm_ds2_dap_ioctl(struct snd_hwdep *hw, struct file *file, |
| 1840 | u32 cmd, void *arg) |
| 1841 | { |
| 1842 | |
| 1843 | int ret = 0; |
| 1844 | |
| 1845 | pr_debug("%s: cmd: 0x%x\n", __func__, cmd); |
| 1846 | if (!arg) { |
| 1847 | pr_err("%s: Invalid params event status\n", __func__); |
| 1848 | ret = -EINVAL; |
| 1849 | goto end; |
| 1850 | } |
| 1851 | switch (cmd) { |
| 1852 | case SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM: |
| 1853 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND: { |
| 1854 | struct dolby_param_data dolby_data; |
| 1855 | |
| 1856 | if (copy_from_user((void *)&dolby_data, (void *)arg, |
| 1857 | sizeof(struct dolby_param_data))) { |
| 1858 | pr_err("%s: Copy from user failed\n", __func__); |
| 1859 | ret = -EFAULT; |
| 1860 | goto end; |
| 1861 | } |
| 1862 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_data); |
| 1863 | break; |
| 1864 | } |
| 1865 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE: { |
| 1866 | struct dolby_param_license dolby_license; |
| 1867 | |
| 1868 | if (copy_from_user((void *)&dolby_license, (void *)arg, |
| 1869 | sizeof(struct dolby_param_license))) { |
| 1870 | pr_err("%s: Copy from user failed\n", __func__); |
| 1871 | ret = -EFAULT; |
| 1872 | goto end; |
| 1873 | } |
| 1874 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_license); |
| 1875 | break; |
| 1876 | } |
| 1877 | case SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM: |
| 1878 | case SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER: { |
| 1879 | struct dolby_param_data dolby_data; |
| 1880 | |
| 1881 | if (copy_from_user((void *)&dolby_data, (void *)arg, |
| 1882 | sizeof(struct dolby_param_data))) { |
| 1883 | pr_err("%s: Copy from user failed\n", __func__); |
| 1884 | ret = -EFAULT; |
| 1885 | goto end; |
| 1886 | } |
| 1887 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_data); |
| 1888 | if (ret < 0) |
| 1889 | pr_err("%s: ioctl cmd %d returned err %d\n", |
| 1890 | __func__, cmd, ret); |
| 1891 | if (copy_to_user((void *)arg, &dolby_data, |
| 1892 | sizeof(struct dolby_param_data))) { |
| 1893 | pr_err("%s: Copy to user failed\n", __func__); |
| 1894 | ret = -EFAULT; |
| 1895 | goto end; |
| 1896 | } |
| 1897 | break; |
| 1898 | } |
| 1899 | default: |
| 1900 | pr_err("%s: called with invalid control 0x%x\n", __func__, cmd); |
| 1901 | ret = -EINVAL; |
| 1902 | } |
| 1903 | end: |
| 1904 | return ret; |
| 1905 | |
| 1906 | } |
| 1907 | #ifdef CONFIG_COMPAT |
| 1908 | int msm_ds2_dap_compat_ioctl(struct snd_hwdep *hw, struct file *file, |
| 1909 | u32 cmd, void *arg) |
| 1910 | { |
| 1911 | int ret = 0; |
| 1912 | |
| 1913 | pr_debug("%s: cmd: 0x%x\n", __func__, cmd); |
| 1914 | switch (cmd) { |
| 1915 | case SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM32: |
| 1916 | cmd = SNDRV_DEVDEP_DAP_IOCTL_SET_PARAM; |
| 1917 | goto handle_set_ioctl; |
| 1918 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND32: |
| 1919 | cmd = SNDRV_DEVDEP_DAP_IOCTL_DAP_COMMAND; |
| 1920 | handle_set_ioctl: |
| 1921 | { |
| 1922 | struct dolby_param_data32 dolby_data32; |
| 1923 | struct dolby_param_data dolby_data; |
| 1924 | |
| 1925 | memset(&dolby_data32, 0, sizeof(dolby_data32)); |
| 1926 | memset(&dolby_data, 0, sizeof(dolby_data)); |
| 1927 | if (copy_from_user(&dolby_data32, (void *)arg, |
| 1928 | sizeof(struct dolby_param_data32))) { |
| 1929 | pr_err("%s: Copy from user failed\n", __func__); |
| 1930 | ret = -EFAULT; |
| 1931 | goto end; |
| 1932 | } |
| 1933 | dolby_data.version = dolby_data32.version; |
| 1934 | dolby_data.device_id = dolby_data32.device_id; |
| 1935 | dolby_data.be_id = dolby_data32.be_id; |
| 1936 | dolby_data.param_id = dolby_data32.param_id; |
| 1937 | dolby_data.length = dolby_data32.length; |
| 1938 | dolby_data.data = compat_ptr(dolby_data32.data); |
| 1939 | |
| 1940 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_data); |
| 1941 | break; |
| 1942 | } |
| 1943 | case SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM32: |
| 1944 | cmd = SNDRV_DEVDEP_DAP_IOCTL_GET_PARAM; |
| 1945 | goto handle_get_ioctl; |
| 1946 | case SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER32: |
| 1947 | cmd = SNDRV_DEVDEP_DAP_IOCTL_GET_VISUALIZER; |
| 1948 | handle_get_ioctl: |
| 1949 | { |
| 1950 | struct dolby_param_data32 dolby_data32; |
| 1951 | struct dolby_param_data dolby_data; |
| 1952 | |
| 1953 | memset(&dolby_data32, 0, sizeof(dolby_data32)); |
| 1954 | memset(&dolby_data, 0, sizeof(dolby_data)); |
| 1955 | if (copy_from_user(&dolby_data32, (void *)arg, |
| 1956 | sizeof(struct dolby_param_data32))) { |
| 1957 | pr_err("%s: Copy from user failed\n", __func__); |
| 1958 | ret = -EFAULT; |
| 1959 | goto end; |
| 1960 | } |
| 1961 | dolby_data.version = dolby_data32.version; |
| 1962 | dolby_data.device_id = dolby_data32.device_id; |
| 1963 | dolby_data.be_id = dolby_data32.be_id; |
| 1964 | dolby_data.param_id = dolby_data32.param_id; |
| 1965 | dolby_data.length = dolby_data32.length; |
| 1966 | dolby_data.data = compat_ptr(dolby_data32.data); |
| 1967 | |
| 1968 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_data); |
| 1969 | if (ret < 0) |
| 1970 | pr_err("%s: ioctl cmd %d, returned err %d\n", |
| 1971 | __func__, cmd, ret); |
| 1972 | dolby_data32.length = dolby_data.length; |
| 1973 | if (copy_to_user((void *)arg, &dolby_data32, |
| 1974 | sizeof(struct dolby_param_data32))) { |
| 1975 | pr_err("%s: Copy to user failed\n", __func__); |
| 1976 | ret = -EFAULT; |
| 1977 | goto end; |
| 1978 | } |
| 1979 | break; |
| 1980 | } |
| 1981 | case SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE32: { |
| 1982 | struct dolby_param_license32 dolby_license32; |
| 1983 | struct dolby_param_license dolby_license; |
| 1984 | |
| 1985 | cmd = SNDRV_DEVDEP_DAP_IOCTL_DAP_LICENSE; |
| 1986 | if (copy_from_user((void *)&dolby_license32, (void *)arg, |
| 1987 | sizeof(struct dolby_param_license32))) { |
| 1988 | pr_err("%s: Copy from user failed\n", __func__); |
| 1989 | ret = -EFAULT; |
| 1990 | goto end; |
| 1991 | } |
| 1992 | dolby_license.dmid = dolby_license32.dmid; |
| 1993 | dolby_license.license_key = dolby_license32.license_key; |
| 1994 | ret = msm_ds2_dap_ioctl_shared(hw, file, cmd, &dolby_license); |
| 1995 | break; |
| 1996 | } |
| 1997 | default: |
| 1998 | pr_err("%s: called with invalid control 0x%x\n", |
| 1999 | __func__, cmd); |
| 2000 | ret = -EINVAL; |
| 2001 | } |
| 2002 | end: |
| 2003 | return ret; |
| 2004 | |
| 2005 | } |
| 2006 | #endif |
| 2007 | |
| 2008 | int msm_ds2_dap_init(int port_id, int copp_idx, int channels, |
| 2009 | bool is_custom_stereo_on) |
| 2010 | { |
| 2011 | int ret = 0, idx = -1, i; |
| 2012 | struct dolby_param_data dolby_data; |
| 2013 | |
| 2014 | struct audproc_softvolume_params softvol = { |
| 2015 | .period = DOLBY_SOFT_VOLUME_PERIOD, |
| 2016 | .step = DOLBY_SOFT_VOLUME_STEP, |
| 2017 | .rampingcurve = DOLBY_SOFT_VOLUME_CURVE_EXP, |
| 2018 | }; |
| 2019 | |
| 2020 | pr_debug("%s: port id %d, copp_idx %d\n", __func__, port_id, copp_idx); |
| 2021 | |
| 2022 | if (port_id != DOLBY_INVALID_PORT_ID) { |
| 2023 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 2024 | if ((dev_map[i].port_id == port_id) && |
| 2025 | /* device part of active device */ |
| 2026 | (dev_map[i].device_id & |
| 2027 | ds2_dap_params_states.device)) { |
| 2028 | idx = i; |
| 2029 | /* Give priority to headset in case of |
| 2030 | * combo device |
| 2031 | */ |
| 2032 | if (dev_map[i].device_id == SPEAKER) |
| 2033 | continue; |
| 2034 | else |
| 2035 | break; |
| 2036 | } |
| 2037 | } |
| 2038 | if (idx < 0) { |
| 2039 | pr_err("%s: invalid index for port %d\n", |
| 2040 | __func__, port_id); |
| 2041 | ret = -EINVAL; |
| 2042 | goto end; |
| 2043 | } |
| 2044 | pr_debug("%s:index %d, dev[0x%x,0x%x]\n", __func__, idx, |
| 2045 | dev_map[idx].device_id, ds2_dap_params_states.device); |
| 2046 | dev_map[idx].active = true; |
| 2047 | dev_map[idx].copp_idx = copp_idx; |
| 2048 | dolby_data.param_id = DOLBY_COMMIT_ALL_TO_DSP; |
| 2049 | dolby_data.length = 0; |
| 2050 | dolby_data.data = NULL; |
| 2051 | dolby_data.device_id = dev_map[idx].device_id; |
| 2052 | pr_debug("%s: idx %d, active %d, dev id 0x%x, ref count %d\n", |
| 2053 | __func__, idx, dev_map[idx].active, |
| 2054 | dev_map[idx].device_id, |
| 2055 | dev_map[idx].stream_ref_count); |
| 2056 | if (dev_map[idx].stream_ref_count == 0) { |
| 2057 | /*perform next 3 func only if hard bypass enabled*/ |
| 2058 | if (ds2_dap_params_states.dap_bypass_type == |
| 2059 | DAP_HARD_BYPASS) { |
| 2060 | ret = msm_ds2_dap_alloc_and_store_cal_data(idx, |
| 2061 | ADM_PATH_PLAYBACK, 0); |
| 2062 | if (ret < 0) { |
| 2063 | pr_err("%s: Failed to alloc and store cal data for idx %d, device %d, copp_idx %d", |
| 2064 | __func__, |
| 2065 | idx, dev_map[idx].device_id, |
| 2066 | dev_map[idx].copp_idx); |
| 2067 | dev_map[idx].active = false; |
| 2068 | dev_map[idx].copp_idx = -1; |
| 2069 | goto end; |
| 2070 | } |
| 2071 | |
| 2072 | ret = adm_set_softvolume(port_id, copp_idx, |
| 2073 | &softvol); |
| 2074 | if (ret < 0) { |
| 2075 | pr_err("%s: Soft volume ret error %d\n", |
| 2076 | __func__, ret); |
| 2077 | dev_map[idx].active = false; |
| 2078 | dev_map[idx].copp_idx = -1; |
| 2079 | goto end; |
| 2080 | } |
| 2081 | |
| 2082 | ret = msm_ds2_dap_init_modules_in_topology( |
| 2083 | idx); |
| 2084 | if (ret < 0) { |
| 2085 | pr_err("%s: Failed to init modules in topolofy for idx %d, device %d, copp_idx %d\n", |
| 2086 | __func__, idx, |
| 2087 | dev_map[idx].device_id, |
| 2088 | dev_map[idx].copp_idx); |
| 2089 | dev_map[idx].active = false; |
| 2090 | dev_map[idx].copp_idx = -1; |
| 2091 | goto end; |
| 2092 | } |
| 2093 | } |
| 2094 | |
| 2095 | ret = msm_ds2_dap_commit_params(&dolby_data, 0); |
| 2096 | if (ret < 0) { |
| 2097 | pr_debug("%s: commit params ret %d\n", |
| 2098 | __func__, ret); |
| 2099 | ret = 0; |
| 2100 | } |
| 2101 | } |
| 2102 | dev_map[idx].stream_ref_count++; |
| 2103 | if (is_custom_stereo_on) { |
| 2104 | ds2_dap_params_states.custom_stereo_onoff = |
| 2105 | is_custom_stereo_on; |
| 2106 | set_custom_stereo_onoff(idx, |
| 2107 | is_custom_stereo_on); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | end: |
| 2112 | return ret; |
| 2113 | } |
| 2114 | |
| 2115 | void msm_ds2_dap_deinit(int port_id) |
| 2116 | { |
| 2117 | /* |
| 2118 | * Get the active port corrresponding to the active device |
| 2119 | * Check if this is same as incoming port |
| 2120 | * Set it to invalid |
| 2121 | */ |
| 2122 | int idx = -1, i; |
| 2123 | |
| 2124 | pr_debug("%s: port_id %d\n", __func__, port_id); |
| 2125 | if (port_id != DOLBY_INVALID_PORT_ID) { |
| 2126 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 2127 | /* Active port */ |
| 2128 | if ((dev_map[i].port_id == port_id) && |
| 2129 | /* device part of active device */ |
| 2130 | (dev_map[i].device_id & |
| 2131 | ds2_dap_params_states.device) && |
| 2132 | /* |
| 2133 | * Need this check to avoid race condition of |
| 2134 | * active device being set and playback |
| 2135 | * instance opened |
| 2136 | */ |
| 2137 | /* active device*/ |
| 2138 | dev_map[i].active) { |
| 2139 | idx = i; |
| 2140 | if (dev_map[i].device_id == SPEAKER) |
| 2141 | continue; |
| 2142 | else |
| 2143 | break; |
| 2144 | } |
| 2145 | } |
| 2146 | if (idx < 0) { |
| 2147 | pr_err("%s: invalid index for port %d\n", |
| 2148 | __func__, port_id); |
| 2149 | return; |
| 2150 | } |
| 2151 | pr_debug("%s:index %d, dev [0x%x, 0x%x]\n", __func__, idx, |
| 2152 | dev_map[idx].device_id, ds2_dap_params_states.device); |
| 2153 | dev_map[idx].stream_ref_count--; |
| 2154 | if (dev_map[idx].stream_ref_count == 0) { |
| 2155 | /*perform next func only if hard bypass enabled*/ |
| 2156 | if (ds2_dap_params_states.dap_bypass_type == |
| 2157 | DAP_HARD_BYPASS) { |
| 2158 | msm_ds2_dap_free_cal_data(idx); |
| 2159 | } |
| 2160 | ds2_dap_params_states.device &= ~dev_map[idx].device_id; |
| 2161 | dev_map[idx].active = false; |
| 2162 | dev_map[idx].copp_idx = -1; |
| 2163 | } |
| 2164 | pr_debug("%s:idx %d, active %d, dev id 0x%x ref count %d\n", |
| 2165 | __func__, idx, dev_map[idx].active, |
| 2166 | dev_map[idx].device_id, dev_map[idx].stream_ref_count); |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | int msm_ds2_dap_set_custom_stereo_onoff(int port_id, int copp_idx, |
| 2171 | bool is_custom_stereo_enabled) |
| 2172 | { |
| 2173 | int idx = -1, rc = 0, i; |
| 2174 | |
| 2175 | pr_debug("%s: port_id %d\n", __func__, port_id); |
| 2176 | if (port_id != DOLBY_INVALID_PORT_ID) { |
| 2177 | for (i = 0; i < DS2_DEVICES_ALL; i++) { |
| 2178 | if ((dev_map[i].port_id == port_id) && |
| 2179 | /* device part of active device */ |
| 2180 | (dev_map[i].device_id & |
| 2181 | ds2_dap_params_states.device)) { |
| 2182 | idx = i; |
| 2183 | if (dev_map[i].device_id == SPEAKER) |
| 2184 | continue; |
| 2185 | else |
| 2186 | break; |
| 2187 | } |
| 2188 | } |
| 2189 | if (idx < 0) { |
| 2190 | pr_err("%s: invalid index for port %d\n", |
| 2191 | __func__, port_id); |
| 2192 | return rc; |
| 2193 | } |
| 2194 | ds2_dap_params_states.custom_stereo_onoff = |
| 2195 | is_custom_stereo_enabled; |
| 2196 | rc = set_custom_stereo_onoff(idx, |
| 2197 | is_custom_stereo_enabled); |
| 2198 | if (rc < 0) { |
| 2199 | pr_err("%s: Custom stereo err %d on port %d\n", |
| 2200 | __func__, rc, port_id); |
| 2201 | } |
| 2202 | } |
| 2203 | return rc; |
| 2204 | } |