msm-ds2-dap-config.c 64 KB

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