msm-ds2-dap-config.c 61 KB

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