sdm660-external.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. /* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/of_gpio.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/module.h>
  16. #include <sound/soc.h>
  17. #include <sound/pcm.h>
  18. #include <sound/pcm_params.h>
  19. #include <dsp/q6core.h>
  20. #include <dsp/audio_notifier.h>
  21. #include "msm-pcm-routing-v2.h"
  22. #include "msm-audio-pinctrl.h"
  23. #include "sdm660-common.h"
  24. #include "sdm660-external.h"
  25. #include "codecs/wcd9335.h"
  26. #include "codecs/wcd934x/wcd934x.h"
  27. #include "codecs/wcd934x/wcd934x-mbhc.h"
  28. #define SDM660_SPK_ON 1
  29. #define SDM660_SPK_OFF 0
  30. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  31. #define WCD9XXX_MBHC_DEF_RLOADS 5
  32. #define CODEC_EXT_CLK_RATE 9600000
  33. #define ADSP_STATE_READY_TIMEOUT_MS 3000
  34. #define TLMM_CENTER_MPM_WAKEUP_INT_EN_0 0x03596000
  35. #define LPI_GPIO_22_WAKEUP_VAL 0x00000002
  36. #define TLMM_LPI_DIR_CONN_INTR1_CFG_APPS 0x0359D004
  37. #define LPI_GPIO_22_INTR1_CFG_VAL 0x01
  38. #define LPI_GPIO_22_INTR1_CFG_MASK 0x03
  39. #define TLMM_LPI_GPIO_INTR_CFG1 0x0359B004
  40. #define LPI_GPIO_INTR_CFG1_VAL 0x00000113
  41. #define TLMM_LPI_GPIO22_CFG 0x15078040
  42. #define LPI_GPIO22_CFG_VAL 0x0000009
  43. #define TLMM_LPI_GPIO22_INOUT 0x179D1318
  44. #define LPI_GPIO22_INOUT_VAL 0x0020000
  45. #define WSA8810_NAME_1 "wsa881x.20170211"
  46. #define WSA8810_NAME_2 "wsa881x.20170212"
  47. static int msm_ext_spk_control = 1;
  48. static struct wcd_mbhc_config *wcd_mbhc_cfg_ptr;
  49. struct msm_asoc_wcd93xx_codec {
  50. void* (*get_afe_config_fn)(struct snd_soc_codec *codec,
  51. enum afe_config_type config_type);
  52. void (*mbhc_hs_detect_exit)(struct snd_soc_codec *codec);
  53. };
  54. static struct msm_asoc_wcd93xx_codec msm_codec_fn;
  55. static struct platform_device *spdev;
  56. static bool is_initial_boot;
  57. static void *def_ext_mbhc_cal(void);
  58. enum {
  59. SLIM_RX_0 = 0,
  60. SLIM_RX_1,
  61. SLIM_RX_2,
  62. SLIM_RX_3,
  63. SLIM_RX_4,
  64. SLIM_RX_5,
  65. SLIM_RX_6,
  66. SLIM_RX_7,
  67. SLIM_RX_MAX,
  68. };
  69. enum {
  70. SLIM_TX_0 = 0,
  71. SLIM_TX_1,
  72. SLIM_TX_2,
  73. SLIM_TX_3,
  74. SLIM_TX_4,
  75. SLIM_TX_5,
  76. SLIM_TX_6,
  77. SLIM_TX_7,
  78. SLIM_TX_8,
  79. SLIM_TX_MAX,
  80. };
  81. struct dev_config {
  82. u32 sample_rate;
  83. u32 bit_format;
  84. u32 channels;
  85. };
  86. /* Default configuration of slimbus channels */
  87. static struct dev_config slim_rx_cfg[] = {
  88. [SLIM_RX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  89. [SLIM_RX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  90. [SLIM_RX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  91. [SLIM_RX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  92. [SLIM_RX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  93. [SLIM_RX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  94. [SLIM_RX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  95. [SLIM_RX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  96. };
  97. static struct dev_config slim_tx_cfg[] = {
  98. [SLIM_TX_0] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  99. [SLIM_TX_1] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  100. [SLIM_TX_2] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  101. [SLIM_TX_3] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  102. [SLIM_TX_4] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  103. [SLIM_TX_5] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  104. [SLIM_TX_6] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  105. [SLIM_TX_7] = {SAMPLING_RATE_8KHZ, SNDRV_PCM_FORMAT_S16_LE, 1},
  106. [SLIM_TX_8] = {SAMPLING_RATE_48KHZ, SNDRV_PCM_FORMAT_S16_LE, 2},
  107. };
  108. static int msm_vi_feed_tx_ch = 2;
  109. static const char *const slim_rx_ch_text[] = {"One", "Two"};
  110. static const char *const slim_tx_ch_text[] = {"One", "Two", "Three", "Four",
  111. "Five", "Six", "Seven",
  112. "Eight"};
  113. static const char *const vi_feed_ch_text[] = {"One", "Two"};
  114. static char const *bit_format_text[] = {"S16_LE", "S24_LE", "S24_3LE",
  115. "S32_LE"};
  116. static char const *slim_sample_rate_text[] = {"KHZ_8", "KHZ_16",
  117. "KHZ_32", "KHZ_44P1", "KHZ_48",
  118. "KHZ_88P2", "KHZ_96", "KHZ_176P4",
  119. "KHZ_192", "KHZ_352P8", "KHZ_384"};
  120. static const char *const spk_function_text[] = {"Off", "On"};
  121. static char const *bt_sample_rate_text[] = {"KHZ_8", "KHZ_16", "KHZ_48"};
  122. static SOC_ENUM_SINGLE_EXT_DECL(spk_func_en, spk_function_text);
  123. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_chs, slim_rx_ch_text);
  124. static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_chs, slim_rx_ch_text);
  125. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_chs, slim_tx_ch_text);
  126. static SOC_ENUM_SINGLE_EXT_DECL(slim_1_tx_chs, slim_tx_ch_text);
  127. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_chs, slim_rx_ch_text);
  128. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_chs, slim_rx_ch_text);
  129. static SOC_ENUM_SINGLE_EXT_DECL(vi_feed_tx_chs, vi_feed_ch_text);
  130. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_format, bit_format_text);
  131. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_format, bit_format_text);
  132. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_format, bit_format_text);
  133. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_format, bit_format_text);
  134. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_rx_sample_rate, slim_sample_rate_text);
  135. static SOC_ENUM_SINGLE_EXT_DECL(slim_2_rx_sample_rate, slim_sample_rate_text);
  136. static SOC_ENUM_SINGLE_EXT_DECL(slim_0_tx_sample_rate, slim_sample_rate_text);
  137. static SOC_ENUM_SINGLE_EXT_DECL(slim_5_rx_sample_rate, slim_sample_rate_text);
  138. static SOC_ENUM_SINGLE_EXT_DECL(slim_6_rx_sample_rate, slim_sample_rate_text);
  139. static SOC_ENUM_SINGLE_EXT_DECL(bt_sample_rate, bt_sample_rate_text);
  140. static int slim_get_sample_rate_val(int sample_rate)
  141. {
  142. int sample_rate_val = 0;
  143. switch (sample_rate) {
  144. case SAMPLING_RATE_8KHZ:
  145. sample_rate_val = 0;
  146. break;
  147. case SAMPLING_RATE_16KHZ:
  148. sample_rate_val = 1;
  149. break;
  150. case SAMPLING_RATE_32KHZ:
  151. sample_rate_val = 2;
  152. break;
  153. case SAMPLING_RATE_44P1KHZ:
  154. sample_rate_val = 3;
  155. break;
  156. case SAMPLING_RATE_48KHZ:
  157. sample_rate_val = 4;
  158. break;
  159. case SAMPLING_RATE_88P2KHZ:
  160. sample_rate_val = 5;
  161. break;
  162. case SAMPLING_RATE_96KHZ:
  163. sample_rate_val = 6;
  164. break;
  165. case SAMPLING_RATE_176P4KHZ:
  166. sample_rate_val = 7;
  167. break;
  168. case SAMPLING_RATE_192KHZ:
  169. sample_rate_val = 8;
  170. break;
  171. case SAMPLING_RATE_352P8KHZ:
  172. sample_rate_val = 9;
  173. break;
  174. case SAMPLING_RATE_384KHZ:
  175. sample_rate_val = 10;
  176. break;
  177. default:
  178. sample_rate_val = 4;
  179. break;
  180. }
  181. return sample_rate_val;
  182. }
  183. static int slim_get_sample_rate(int value)
  184. {
  185. int sample_rate = 0;
  186. switch (value) {
  187. case 0:
  188. sample_rate = SAMPLING_RATE_8KHZ;
  189. break;
  190. case 1:
  191. sample_rate = SAMPLING_RATE_16KHZ;
  192. break;
  193. case 2:
  194. sample_rate = SAMPLING_RATE_32KHZ;
  195. break;
  196. case 3:
  197. sample_rate = SAMPLING_RATE_44P1KHZ;
  198. break;
  199. case 4:
  200. sample_rate = SAMPLING_RATE_48KHZ;
  201. break;
  202. case 5:
  203. sample_rate = SAMPLING_RATE_88P2KHZ;
  204. break;
  205. case 6:
  206. sample_rate = SAMPLING_RATE_96KHZ;
  207. break;
  208. case 7:
  209. sample_rate = SAMPLING_RATE_176P4KHZ;
  210. break;
  211. case 8:
  212. sample_rate = SAMPLING_RATE_192KHZ;
  213. break;
  214. case 9:
  215. sample_rate = SAMPLING_RATE_352P8KHZ;
  216. break;
  217. case 10:
  218. sample_rate = SAMPLING_RATE_384KHZ;
  219. break;
  220. default:
  221. sample_rate = SAMPLING_RATE_48KHZ;
  222. break;
  223. }
  224. return sample_rate;
  225. }
  226. static int slim_get_bit_format_val(int bit_format)
  227. {
  228. int val = 0;
  229. switch (bit_format) {
  230. case SNDRV_PCM_FORMAT_S32_LE:
  231. val = 3;
  232. break;
  233. case SNDRV_PCM_FORMAT_S24_3LE:
  234. val = 2;
  235. break;
  236. case SNDRV_PCM_FORMAT_S24_LE:
  237. val = 1;
  238. break;
  239. case SNDRV_PCM_FORMAT_S16_LE:
  240. default:
  241. val = 0;
  242. break;
  243. }
  244. return val;
  245. }
  246. static int slim_get_bit_format(int val)
  247. {
  248. int bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  249. switch (val) {
  250. case 0:
  251. bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  252. break;
  253. case 1:
  254. bit_fmt = SNDRV_PCM_FORMAT_S24_LE;
  255. break;
  256. case 2:
  257. bit_fmt = SNDRV_PCM_FORMAT_S24_3LE;
  258. break;
  259. case 3:
  260. bit_fmt = SNDRV_PCM_FORMAT_S32_LE;
  261. break;
  262. default:
  263. bit_fmt = SNDRV_PCM_FORMAT_S16_LE;
  264. break;
  265. }
  266. return bit_fmt;
  267. }
  268. static int slim_get_port_idx(struct snd_kcontrol *kcontrol)
  269. {
  270. int port_id = 0;
  271. if (strnstr(kcontrol->id.name, "SLIM_0_RX", sizeof("SLIM_0_RX")))
  272. port_id = SLIM_RX_0;
  273. else if (strnstr(kcontrol->id.name, "SLIM_2_RX", sizeof("SLIM_2_RX")))
  274. port_id = SLIM_RX_2;
  275. else if (strnstr(kcontrol->id.name, "SLIM_5_RX", sizeof("SLIM_5_RX")))
  276. port_id = SLIM_RX_5;
  277. else if (strnstr(kcontrol->id.name, "SLIM_6_RX", sizeof("SLIM_6_RX")))
  278. port_id = SLIM_RX_6;
  279. else if (strnstr(kcontrol->id.name, "SLIM_0_TX", sizeof("SLIM_0_TX")))
  280. port_id = SLIM_TX_0;
  281. else if (strnstr(kcontrol->id.name, "SLIM_1_TX", sizeof("SLIM_1_TX")))
  282. port_id = SLIM_TX_1;
  283. else {
  284. pr_err("%s: unsupported channel: %s",
  285. __func__, kcontrol->id.name);
  286. return -EINVAL;
  287. }
  288. return port_id;
  289. }
  290. static int msm_bt_sample_rate_get(struct snd_kcontrol *kcontrol,
  291. struct snd_ctl_elem_value *ucontrol)
  292. {
  293. /*
  294. * Slimbus_7_Rx/Tx sample rate values should always be in sync (same)
  295. * when used for BT_SCO use case. Return either Rx or Tx sample rate
  296. * value.
  297. */
  298. switch (slim_rx_cfg[SLIM_RX_7].sample_rate) {
  299. case SAMPLING_RATE_48KHZ:
  300. ucontrol->value.integer.value[0] = 2;
  301. break;
  302. case SAMPLING_RATE_16KHZ:
  303. ucontrol->value.integer.value[0] = 1;
  304. break;
  305. case SAMPLING_RATE_8KHZ:
  306. default:
  307. ucontrol->value.integer.value[0] = 0;
  308. break;
  309. }
  310. pr_debug("%s: sample rate = %d", __func__,
  311. slim_rx_cfg[SLIM_RX_7].sample_rate);
  312. return 0;
  313. }
  314. static int msm_bt_sample_rate_put(struct snd_kcontrol *kcontrol,
  315. struct snd_ctl_elem_value *ucontrol)
  316. {
  317. switch (ucontrol->value.integer.value[0]) {
  318. case 1:
  319. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_16KHZ;
  320. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_16KHZ;
  321. break;
  322. case 2:
  323. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_48KHZ;
  324. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_48KHZ;
  325. break;
  326. case 0:
  327. default:
  328. slim_rx_cfg[SLIM_RX_7].sample_rate = SAMPLING_RATE_8KHZ;
  329. slim_tx_cfg[SLIM_TX_7].sample_rate = SAMPLING_RATE_8KHZ;
  330. break;
  331. }
  332. pr_debug("%s: sample rates: slim7_rx = %d, slim7_tx = %d, value = %d\n",
  333. __func__,
  334. slim_rx_cfg[SLIM_RX_7].sample_rate,
  335. slim_tx_cfg[SLIM_TX_7].sample_rate,
  336. ucontrol->value.enumerated.item[0]);
  337. return 0;
  338. }
  339. static int slim_rx_sample_rate_get(struct snd_kcontrol *kcontrol,
  340. struct snd_ctl_elem_value *ucontrol)
  341. {
  342. int ch_num = slim_get_port_idx(kcontrol);
  343. if (ch_num < 0)
  344. return ch_num;
  345. ucontrol->value.enumerated.item[0] =
  346. slim_get_sample_rate_val(slim_rx_cfg[ch_num].sample_rate);
  347. pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  348. ch_num, slim_rx_cfg[ch_num].sample_rate,
  349. ucontrol->value.enumerated.item[0]);
  350. return 0;
  351. }
  352. static int slim_rx_sample_rate_put(struct snd_kcontrol *kcontrol,
  353. struct snd_ctl_elem_value *ucontrol)
  354. {
  355. int ch_num = slim_get_port_idx(kcontrol);
  356. if (ch_num < 0)
  357. return ch_num;
  358. slim_rx_cfg[ch_num].sample_rate =
  359. slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
  360. pr_debug("%s: slim[%d]_rx_sample_rate = %d, item = %d\n", __func__,
  361. ch_num, slim_rx_cfg[ch_num].sample_rate,
  362. ucontrol->value.enumerated.item[0]);
  363. return 0;
  364. }
  365. static int slim_tx_sample_rate_get(struct snd_kcontrol *kcontrol,
  366. struct snd_ctl_elem_value *ucontrol)
  367. {
  368. int ch_num = slim_get_port_idx(kcontrol);
  369. if (ch_num < 0)
  370. return ch_num;
  371. ucontrol->value.enumerated.item[0] =
  372. slim_get_sample_rate_val(slim_tx_cfg[ch_num].sample_rate);
  373. pr_debug("%s: slim[%d]_tx_sample_rate = %d, item = %d\n", __func__,
  374. ch_num, slim_tx_cfg[ch_num].sample_rate,
  375. ucontrol->value.enumerated.item[0]);
  376. return 0;
  377. }
  378. static int slim_tx_sample_rate_put(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_value *ucontrol)
  380. {
  381. int sample_rate = 0;
  382. int ch_num = slim_get_port_idx(kcontrol);
  383. if (ch_num < 0)
  384. return ch_num;
  385. sample_rate = slim_get_sample_rate(ucontrol->value.enumerated.item[0]);
  386. if (sample_rate == SAMPLING_RATE_44P1KHZ) {
  387. pr_err("%s: Unsupported sample rate %d: for Tx path\n",
  388. __func__, sample_rate);
  389. return -EINVAL;
  390. }
  391. slim_tx_cfg[ch_num].sample_rate = sample_rate;
  392. pr_debug("%s: slim[%d]_tx_sample_rate = %d, value = %d\n", __func__,
  393. ch_num, slim_tx_cfg[ch_num].sample_rate,
  394. ucontrol->value.enumerated.item[0]);
  395. return 0;
  396. }
  397. static int slim_rx_bit_format_get(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_value *ucontrol)
  399. {
  400. int ch_num = slim_get_port_idx(kcontrol);
  401. if (ch_num < 0)
  402. return ch_num;
  403. ucontrol->value.enumerated.item[0] =
  404. slim_get_bit_format_val(slim_rx_cfg[ch_num].bit_format);
  405. pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
  406. __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
  407. ucontrol->value.enumerated.item[0]);
  408. return 0;
  409. }
  410. static int slim_rx_bit_format_put(struct snd_kcontrol *kcontrol,
  411. struct snd_ctl_elem_value *ucontrol)
  412. {
  413. int ch_num = slim_get_port_idx(kcontrol);
  414. if (ch_num < 0)
  415. return ch_num;
  416. slim_rx_cfg[ch_num].bit_format =
  417. slim_get_bit_format(ucontrol->value.enumerated.item[0]);
  418. pr_debug("%s: slim[%d]_rx_bit_format = %d, ucontrol value = %d\n",
  419. __func__, ch_num, slim_rx_cfg[ch_num].bit_format,
  420. ucontrol->value.enumerated.item[0]);
  421. return 0;
  422. }
  423. static int slim_tx_bit_format_get(struct snd_kcontrol *kcontrol,
  424. struct snd_ctl_elem_value *ucontrol)
  425. {
  426. int ch_num = slim_get_port_idx(kcontrol);
  427. if (ch_num < 0)
  428. return ch_num;
  429. ucontrol->value.enumerated.item[0] =
  430. slim_get_bit_format_val(slim_tx_cfg[ch_num].bit_format);
  431. pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
  432. __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
  433. ucontrol->value.enumerated.item[0]);
  434. return 0;
  435. }
  436. static int slim_tx_bit_format_put(struct snd_kcontrol *kcontrol,
  437. struct snd_ctl_elem_value *ucontrol)
  438. {
  439. int ch_num = slim_get_port_idx(kcontrol);
  440. if (ch_num < 0)
  441. return ch_num;
  442. slim_tx_cfg[ch_num].bit_format =
  443. slim_get_bit_format(ucontrol->value.enumerated.item[0]);
  444. pr_debug("%s: slim[%d]_tx_bit_format = %d, ucontrol value = %d\n",
  445. __func__, ch_num, slim_tx_cfg[ch_num].bit_format,
  446. ucontrol->value.enumerated.item[0]);
  447. return 0;
  448. }
  449. static int msm_slim_rx_ch_get(struct snd_kcontrol *kcontrol,
  450. struct snd_ctl_elem_value *ucontrol)
  451. {
  452. int ch_num = slim_get_port_idx(kcontrol);
  453. if (ch_num < 0)
  454. return ch_num;
  455. pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
  456. ch_num, slim_rx_cfg[ch_num].channels);
  457. ucontrol->value.enumerated.item[0] = slim_rx_cfg[ch_num].channels - 1;
  458. return 0;
  459. }
  460. static int msm_slim_rx_ch_put(struct snd_kcontrol *kcontrol,
  461. struct snd_ctl_elem_value *ucontrol)
  462. {
  463. int ch_num = slim_get_port_idx(kcontrol);
  464. if (ch_num < 0)
  465. return ch_num;
  466. slim_rx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
  467. pr_debug("%s: msm_slim_[%d]_rx_ch = %d\n", __func__,
  468. ch_num, slim_rx_cfg[ch_num].channels);
  469. return 1;
  470. }
  471. static int msm_slim_tx_ch_get(struct snd_kcontrol *kcontrol,
  472. struct snd_ctl_elem_value *ucontrol)
  473. {
  474. int ch_num = slim_get_port_idx(kcontrol);
  475. if (ch_num < 0)
  476. return ch_num;
  477. pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
  478. ch_num, slim_tx_cfg[ch_num].channels);
  479. ucontrol->value.enumerated.item[0] = slim_tx_cfg[ch_num].channels - 1;
  480. return 0;
  481. }
  482. static int msm_slim_tx_ch_put(struct snd_kcontrol *kcontrol,
  483. struct snd_ctl_elem_value *ucontrol)
  484. {
  485. int ch_num = slim_get_port_idx(kcontrol);
  486. if (ch_num < 0)
  487. return ch_num;
  488. slim_tx_cfg[ch_num].channels = ucontrol->value.enumerated.item[0] + 1;
  489. pr_debug("%s: msm_slim_[%d]_tx_ch = %d\n", __func__,
  490. ch_num, slim_tx_cfg[ch_num].channels);
  491. return 1;
  492. }
  493. static int msm_vi_feed_tx_ch_get(struct snd_kcontrol *kcontrol,
  494. struct snd_ctl_elem_value *ucontrol)
  495. {
  496. ucontrol->value.integer.value[0] = msm_vi_feed_tx_ch - 1;
  497. pr_debug("%s: msm_vi_feed_tx_ch = %ld\n", __func__,
  498. ucontrol->value.integer.value[0]);
  499. return 0;
  500. }
  501. static int msm_vi_feed_tx_ch_put(struct snd_kcontrol *kcontrol,
  502. struct snd_ctl_elem_value *ucontrol)
  503. {
  504. msm_vi_feed_tx_ch = ucontrol->value.integer.value[0] + 1;
  505. pr_debug("%s: msm_vi_feed_tx_ch = %d\n", __func__, msm_vi_feed_tx_ch);
  506. return 1;
  507. }
  508. static void *def_ext_mbhc_cal(void)
  509. {
  510. void *wcd_mbhc_cal;
  511. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  512. u16 *btn_high;
  513. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  514. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  515. if (!wcd_mbhc_cal)
  516. return NULL;
  517. #define S(X, Y) ((WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->X) = (Y))
  518. S(v_hs_max, 1600);
  519. #undef S
  520. #define S(X, Y) ((WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->X) = (Y))
  521. S(num_btn, WCD_MBHC_DEF_BUTTONS);
  522. #undef S
  523. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  524. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  525. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  526. btn_high[0] = 75;
  527. btn_high[1] = 150;
  528. btn_high[2] = 237;
  529. btn_high[3] = 500;
  530. btn_high[4] = 500;
  531. btn_high[5] = 500;
  532. btn_high[6] = 500;
  533. btn_high[7] = 500;
  534. return wcd_mbhc_cal;
  535. }
  536. static inline int param_is_mask(int p)
  537. {
  538. return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
  539. (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
  540. }
  541. static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n)
  542. {
  543. return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
  544. }
  545. static void msm_ext_control(struct snd_soc_codec *codec)
  546. {
  547. struct snd_soc_dapm_context *dapm =
  548. snd_soc_codec_get_dapm(codec);
  549. pr_debug("%s: msm_ext_spk_control = %d", __func__, msm_ext_spk_control);
  550. if (msm_ext_spk_control == SDM660_SPK_ON) {
  551. snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
  552. snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
  553. } else {
  554. snd_soc_dapm_disable_pin(dapm, "Lineout_1 amp");
  555. snd_soc_dapm_disable_pin(dapm, "Lineout_3 amp");
  556. }
  557. snd_soc_dapm_sync(dapm);
  558. }
  559. static int msm_ext_get_spk(struct snd_kcontrol *kcontrol,
  560. struct snd_ctl_elem_value *ucontrol)
  561. {
  562. pr_debug("%s: msm_ext_spk_control = %d\n",
  563. __func__, msm_ext_spk_control);
  564. ucontrol->value.integer.value[0] = msm_ext_spk_control;
  565. return 0;
  566. }
  567. static int msm_ext_set_spk(struct snd_kcontrol *kcontrol,
  568. struct snd_ctl_elem_value *ucontrol)
  569. {
  570. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  571. pr_debug("%s()\n", __func__);
  572. if (msm_ext_spk_control == ucontrol->value.integer.value[0])
  573. return 0;
  574. msm_ext_spk_control = ucontrol->value.integer.value[0];
  575. msm_ext_control(codec);
  576. return 1;
  577. }
  578. int msm_ext_enable_codec_mclk(struct snd_soc_codec *codec, int enable,
  579. bool dapm)
  580. {
  581. int ret;
  582. pr_debug("%s: enable = %d\n", __func__, enable);
  583. if (!strcmp(dev_name(codec->dev), "tasha_codec"))
  584. ret = tasha_cdc_mclk_enable(codec, enable, dapm);
  585. else if (!strcmp(dev_name(codec->dev), "tavil_codec"))
  586. ret = tavil_cdc_mclk_enable(codec, enable);
  587. else {
  588. dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
  589. __func__);
  590. ret = -EINVAL;
  591. }
  592. return ret;
  593. }
  594. static const struct snd_kcontrol_new msm_snd_controls[] = {
  595. SOC_ENUM_EXT("Speaker Function", spk_func_en, msm_ext_get_spk,
  596. msm_ext_set_spk),
  597. SOC_ENUM_EXT("SLIM_0_RX Channels", slim_0_rx_chs,
  598. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  599. SOC_ENUM_EXT("SLIM_2_RX Channels", slim_2_rx_chs,
  600. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  601. SOC_ENUM_EXT("SLIM_0_TX Channels", slim_0_tx_chs,
  602. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  603. SOC_ENUM_EXT("SLIM_1_TX Channels", slim_1_tx_chs,
  604. msm_slim_tx_ch_get, msm_slim_tx_ch_put),
  605. SOC_ENUM_EXT("SLIM_5_RX Channels", slim_5_rx_chs,
  606. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  607. SOC_ENUM_EXT("SLIM_6_RX Channels", slim_6_rx_chs,
  608. msm_slim_rx_ch_get, msm_slim_rx_ch_put),
  609. SOC_ENUM_EXT("VI_FEED_TX Channels", vi_feed_tx_chs,
  610. msm_vi_feed_tx_ch_get, msm_vi_feed_tx_ch_put),
  611. SOC_ENUM_EXT("SLIM_0_RX Format", slim_0_rx_format,
  612. slim_rx_bit_format_get, slim_rx_bit_format_put),
  613. SOC_ENUM_EXT("SLIM_5_RX Format", slim_5_rx_format,
  614. slim_rx_bit_format_get, slim_rx_bit_format_put),
  615. SOC_ENUM_EXT("SLIM_6_RX Format", slim_6_rx_format,
  616. slim_rx_bit_format_get, slim_rx_bit_format_put),
  617. SOC_ENUM_EXT("SLIM_0_TX Format", slim_0_tx_format,
  618. slim_tx_bit_format_get, slim_tx_bit_format_put),
  619. SOC_ENUM_EXT("SLIM_0_RX SampleRate", slim_0_rx_sample_rate,
  620. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  621. SOC_ENUM_EXT("SLIM_2_RX SampleRate", slim_2_rx_sample_rate,
  622. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  623. SOC_ENUM_EXT("SLIM_0_TX SampleRate", slim_0_tx_sample_rate,
  624. slim_tx_sample_rate_get, slim_tx_sample_rate_put),
  625. SOC_ENUM_EXT("SLIM_5_RX SampleRate", slim_5_rx_sample_rate,
  626. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  627. SOC_ENUM_EXT("SLIM_6_RX SampleRate", slim_6_rx_sample_rate,
  628. slim_rx_sample_rate_get, slim_rx_sample_rate_put),
  629. SOC_ENUM_EXT("BT SampleRate", bt_sample_rate,
  630. msm_bt_sample_rate_get,
  631. msm_bt_sample_rate_put),
  632. };
  633. static int msm_slim_get_ch_from_beid(int32_t id)
  634. {
  635. int ch_id = 0;
  636. switch (id) {
  637. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  638. ch_id = SLIM_RX_0;
  639. break;
  640. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  641. ch_id = SLIM_RX_1;
  642. break;
  643. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  644. ch_id = SLIM_RX_2;
  645. break;
  646. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  647. ch_id = SLIM_RX_3;
  648. break;
  649. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  650. ch_id = SLIM_RX_4;
  651. break;
  652. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  653. ch_id = SLIM_RX_6;
  654. break;
  655. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  656. ch_id = SLIM_TX_0;
  657. break;
  658. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  659. ch_id = SLIM_TX_3;
  660. break;
  661. default:
  662. ch_id = SLIM_RX_0;
  663. break;
  664. }
  665. return ch_id;
  666. }
  667. static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned int bit)
  668. {
  669. if (bit >= SNDRV_MASK_MAX)
  670. return;
  671. if (param_is_mask(n)) {
  672. struct snd_mask *m = param_to_mask(p, n);
  673. m->bits[0] = 0;
  674. m->bits[1] = 0;
  675. m->bits[bit >> 5] |= (1 << (bit & 31));
  676. }
  677. }
  678. /**
  679. * msm_ext_be_hw_params_fixup - updates settings of ALSA BE hw params.
  680. *
  681. * @rtd: runtime dailink instance
  682. * @params: HW params of associated backend dailink.
  683. *
  684. * Returns 0 on success or rc on failure.
  685. */
  686. int msm_ext_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  687. struct snd_pcm_hw_params *params)
  688. {
  689. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  690. struct snd_interval *rate = hw_param_interval(params,
  691. SNDRV_PCM_HW_PARAM_RATE);
  692. struct snd_interval *channels = hw_param_interval(params,
  693. SNDRV_PCM_HW_PARAM_CHANNELS);
  694. int rc = 0;
  695. int idx;
  696. void *config = NULL;
  697. struct snd_soc_codec *codec = rtd->codec;
  698. pr_debug("%s: format = %d, rate = %d\n",
  699. __func__, params_format(params), params_rate(params));
  700. switch (dai_link->id) {
  701. case MSM_BACKEND_DAI_SLIMBUS_0_RX:
  702. case MSM_BACKEND_DAI_SLIMBUS_1_RX:
  703. case MSM_BACKEND_DAI_SLIMBUS_2_RX:
  704. case MSM_BACKEND_DAI_SLIMBUS_3_RX:
  705. case MSM_BACKEND_DAI_SLIMBUS_4_RX:
  706. case MSM_BACKEND_DAI_SLIMBUS_6_RX:
  707. idx = msm_slim_get_ch_from_beid(dai_link->id);
  708. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  709. slim_rx_cfg[idx].bit_format);
  710. rate->min = rate->max = slim_rx_cfg[idx].sample_rate;
  711. channels->min = channels->max = slim_rx_cfg[idx].channels;
  712. break;
  713. case MSM_BACKEND_DAI_SLIMBUS_0_TX:
  714. case MSM_BACKEND_DAI_SLIMBUS_3_TX:
  715. idx = msm_slim_get_ch_from_beid(dai_link->id);
  716. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  717. slim_tx_cfg[idx].bit_format);
  718. rate->min = rate->max = slim_tx_cfg[idx].sample_rate;
  719. channels->min = channels->max = slim_tx_cfg[idx].channels;
  720. break;
  721. case MSM_BACKEND_DAI_SLIMBUS_1_TX:
  722. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  723. slim_tx_cfg[1].bit_format);
  724. rate->min = rate->max = slim_tx_cfg[1].sample_rate;
  725. channels->min = channels->max = slim_tx_cfg[1].channels;
  726. break;
  727. case MSM_BACKEND_DAI_SLIMBUS_4_TX:
  728. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  729. SNDRV_PCM_FORMAT_S32_LE);
  730. rate->min = rate->max = SAMPLING_RATE_8KHZ;
  731. channels->min = channels->max = msm_vi_feed_tx_ch;
  732. break;
  733. case MSM_BACKEND_DAI_SLIMBUS_5_RX:
  734. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  735. slim_rx_cfg[5].bit_format);
  736. rate->min = rate->max = slim_rx_cfg[5].sample_rate;
  737. channels->min = channels->max = slim_rx_cfg[5].channels;
  738. break;
  739. case MSM_BACKEND_DAI_SLIMBUS_5_TX:
  740. rate->min = rate->max = SAMPLING_RATE_16KHZ;
  741. channels->min = channels->max = 1;
  742. config = msm_codec_fn.get_afe_config_fn(codec,
  743. AFE_SLIMBUS_SLAVE_PORT_CONFIG);
  744. if (config) {
  745. rc = afe_set_config(AFE_SLIMBUS_SLAVE_PORT_CONFIG,
  746. config, SLIMBUS_5_TX);
  747. if (rc)
  748. pr_err("%s: Failed to set slimbus slave port config %d\n",
  749. __func__, rc);
  750. }
  751. break;
  752. case MSM_BACKEND_DAI_SLIMBUS_7_RX:
  753. param_set_mask(params, SNDRV_PCM_HW_PARAM_FORMAT,
  754. slim_rx_cfg[SLIM_RX_7].bit_format);
  755. rate->min = rate->max = slim_rx_cfg[SLIM_RX_7].sample_rate;
  756. channels->min = channels->max =
  757. slim_rx_cfg[SLIM_RX_7].channels;
  758. break;
  759. case MSM_BACKEND_DAI_SLIMBUS_7_TX:
  760. rate->min = rate->max = slim_tx_cfg[SLIM_TX_7].sample_rate;
  761. channels->min = channels->max =
  762. slim_tx_cfg[SLIM_TX_7].channels;
  763. break;
  764. case MSM_BACKEND_DAI_SLIMBUS_8_TX:
  765. rate->min = rate->max = slim_tx_cfg[SLIM_TX_8].sample_rate;
  766. channels->min = channels->max =
  767. slim_tx_cfg[SLIM_TX_8].channels;
  768. break;
  769. default:
  770. rate->min = rate->max = SAMPLING_RATE_48KHZ;
  771. break;
  772. }
  773. return rc;
  774. }
  775. EXPORT_SYMBOL(msm_ext_be_hw_params_fixup);
  776. /**
  777. * msm_snd_hw_params - hw params ops of backend dailink.
  778. *
  779. * @substream: PCM stream of associated backend dailink.
  780. * @params: HW params of associated backend dailink.
  781. *
  782. * Returns 0 on success or ret on failure.
  783. */
  784. int msm_snd_hw_params(struct snd_pcm_substream *substream,
  785. struct snd_pcm_hw_params *params)
  786. {
  787. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  788. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  789. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  790. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  791. int ret = 0;
  792. u32 rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  793. u32 rx_ch_cnt = 0, tx_ch_cnt = 0;
  794. u32 user_set_tx_ch = 0;
  795. u32 rx_ch_count;
  796. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  797. ret = snd_soc_dai_get_channel_map(codec_dai,
  798. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  799. if (ret < 0) {
  800. pr_err("%s: failed to get codec chan map, err:%d\n",
  801. __func__, ret);
  802. goto err_ch_map;
  803. }
  804. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_5_RX) {
  805. pr_debug("%s: rx_5_ch=%d\n", __func__,
  806. slim_rx_cfg[5].channels);
  807. rx_ch_count = slim_rx_cfg[5].channels;
  808. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_2_RX) {
  809. pr_debug("%s: rx_2_ch=%d\n", __func__,
  810. slim_rx_cfg[2].channels);
  811. rx_ch_count = slim_rx_cfg[2].channels;
  812. } else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_6_RX) {
  813. pr_debug("%s: rx_6_ch=%d\n", __func__,
  814. slim_rx_cfg[6].channels);
  815. rx_ch_count = slim_rx_cfg[6].channels;
  816. } else {
  817. pr_debug("%s: rx_0_ch=%d\n", __func__,
  818. slim_rx_cfg[0].channels);
  819. rx_ch_count = slim_rx_cfg[0].channels;
  820. }
  821. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  822. rx_ch_count, rx_ch);
  823. if (ret < 0) {
  824. pr_err("%s: failed to set cpu chan map, err:%d\n",
  825. __func__, ret);
  826. goto err_ch_map;
  827. }
  828. } else {
  829. pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
  830. codec_dai->name, codec_dai->id, user_set_tx_ch);
  831. ret = snd_soc_dai_get_channel_map(codec_dai,
  832. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  833. if (ret < 0) {
  834. pr_err("%s: failed to get codec chan map\n, err:%d\n",
  835. __func__, ret);
  836. goto err_ch_map;
  837. }
  838. /* For <codec>_tx1 case */
  839. if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_0_TX)
  840. user_set_tx_ch = slim_tx_cfg[0].channels;
  841. /* For <codec>_tx3 case */
  842. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_1_TX)
  843. user_set_tx_ch = slim_tx_cfg[1].channels;
  844. else if (dai_link->id == MSM_BACKEND_DAI_SLIMBUS_4_TX)
  845. user_set_tx_ch = msm_vi_feed_tx_ch;
  846. else
  847. user_set_tx_ch = tx_ch_cnt;
  848. pr_debug("%s: msm_slim_0_tx_ch(%d) user_set_tx_ch(%d) tx_ch_cnt(%d), id (%d)\n",
  849. __func__, slim_tx_cfg[0].channels, user_set_tx_ch,
  850. tx_ch_cnt, dai_link->id);
  851. ret = snd_soc_dai_set_channel_map(cpu_dai,
  852. user_set_tx_ch, tx_ch, 0, 0);
  853. if (ret < 0)
  854. pr_err("%s: failed to set cpu chan map, err:%d\n",
  855. __func__, ret);
  856. }
  857. err_ch_map:
  858. return ret;
  859. }
  860. EXPORT_SYMBOL(msm_snd_hw_params);
  861. /**
  862. * msm_ext_slimbus_2_hw_params - hw params ops of slimbus_2 BE.
  863. *
  864. * @substream: PCM stream of associated backend dailink.
  865. * @params: HW params of associated backend dailink.
  866. *
  867. * Returns 0 on success or ret on failure.
  868. */
  869. int msm_ext_slimbus_2_hw_params(struct snd_pcm_substream *substream,
  870. struct snd_pcm_hw_params *params)
  871. {
  872. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  873. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  874. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  875. int ret = 0;
  876. unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  877. unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
  878. unsigned int num_tx_ch = 0;
  879. unsigned int num_rx_ch = 0;
  880. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  881. num_rx_ch = params_channels(params);
  882. pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
  883. codec_dai->name, codec_dai->id, num_rx_ch);
  884. ret = snd_soc_dai_get_channel_map(codec_dai,
  885. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  886. if (ret < 0) {
  887. pr_err("%s: failed to get codec chan map, err:%d\n",
  888. __func__, ret);
  889. goto end;
  890. }
  891. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  892. num_rx_ch, rx_ch);
  893. if (ret < 0) {
  894. pr_err("%s: failed to set cpu chan map, err:%d\n",
  895. __func__, ret);
  896. goto end;
  897. }
  898. } else {
  899. num_tx_ch = params_channels(params);
  900. pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
  901. codec_dai->name, codec_dai->id, num_tx_ch);
  902. ret = snd_soc_dai_get_channel_map(codec_dai,
  903. &tx_ch_cnt, tx_ch, &rx_ch_cnt, rx_ch);
  904. if (ret < 0) {
  905. pr_err("%s: failed to get codec chan map, err:%d\n",
  906. __func__, ret);
  907. goto end;
  908. }
  909. ret = snd_soc_dai_set_channel_map(cpu_dai,
  910. num_tx_ch, tx_ch, 0, 0);
  911. if (ret < 0) {
  912. pr_err("%s: failed to set cpu chan map, err:%d\n",
  913. __func__, ret);
  914. goto end;
  915. }
  916. }
  917. end:
  918. return ret;
  919. }
  920. EXPORT_SYMBOL(msm_ext_slimbus_2_hw_params);
  921. /**
  922. * msm_snd_cpe_hw_params - hw params ops of CPE backend.
  923. *
  924. * @substream: PCM stream of associated backend dailink.
  925. * @params: HW params of associated backend dailink.
  926. *
  927. * Returns 0 on success or ret on failure.
  928. */
  929. int msm_snd_cpe_hw_params(struct snd_pcm_substream *substream,
  930. struct snd_pcm_hw_params *params)
  931. {
  932. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  933. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  934. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  935. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  936. int ret = 0;
  937. u32 tx_ch[SLIM_MAX_TX_PORTS];
  938. u32 tx_ch_cnt = 0;
  939. if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) {
  940. pr_err("%s: Invalid stream type %d\n",
  941. __func__, substream->stream);
  942. ret = -EINVAL;
  943. goto end;
  944. }
  945. pr_debug("%s: %s_tx_dai_id_%d\n", __func__,
  946. codec_dai->name, codec_dai->id);
  947. ret = snd_soc_dai_get_channel_map(codec_dai,
  948. &tx_ch_cnt, tx_ch, NULL, NULL);
  949. if (ret < 0) {
  950. pr_err("%s: failed to get codec chan map\n, err:%d\n",
  951. __func__, ret);
  952. goto end;
  953. }
  954. pr_debug("%s: tx_ch_cnt(%d) id %d\n",
  955. __func__, tx_ch_cnt, dai_link->id);
  956. ret = snd_soc_dai_set_channel_map(cpu_dai,
  957. tx_ch_cnt, tx_ch, 0, 0);
  958. if (ret < 0) {
  959. pr_err("%s: failed to set cpu chan map, err:%d\n",
  960. __func__, ret);
  961. goto end;
  962. }
  963. end:
  964. return ret;
  965. }
  966. EXPORT_SYMBOL(msm_snd_cpe_hw_params);
  967. static int msm_afe_set_config(struct snd_soc_codec *codec)
  968. {
  969. int rc;
  970. void *config_data;
  971. pr_debug("%s: enter\n", __func__);
  972. if (!msm_codec_fn.get_afe_config_fn) {
  973. dev_err(codec->dev, "%s: codec get afe config not init'ed\n",
  974. __func__);
  975. return -EINVAL;
  976. }
  977. config_data = msm_codec_fn.get_afe_config_fn(codec,
  978. AFE_CDC_REGISTERS_CONFIG);
  979. if (config_data) {
  980. rc = afe_set_config(AFE_CDC_REGISTERS_CONFIG, config_data, 0);
  981. if (rc) {
  982. pr_err("%s: Failed to set codec registers config %d\n",
  983. __func__, rc);
  984. return rc;
  985. }
  986. }
  987. config_data = msm_codec_fn.get_afe_config_fn(codec,
  988. AFE_CDC_REGISTER_PAGE_CONFIG);
  989. if (config_data) {
  990. rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
  991. 0);
  992. if (rc)
  993. pr_err("%s: Failed to set cdc register page config\n",
  994. __func__);
  995. }
  996. config_data = msm_codec_fn.get_afe_config_fn(codec,
  997. AFE_SLIMBUS_SLAVE_CONFIG);
  998. if (config_data) {
  999. rc = afe_set_config(AFE_SLIMBUS_SLAVE_CONFIG, config_data, 0);
  1000. if (rc) {
  1001. pr_err("%s: Failed to set slimbus slave config %d\n",
  1002. __func__, rc);
  1003. return rc;
  1004. }
  1005. }
  1006. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1007. AFE_AANC_VERSION);
  1008. if (config_data) {
  1009. rc = afe_set_config(AFE_AANC_VERSION, config_data, 0);
  1010. if (rc) {
  1011. pr_err("%s: Failed to set AANC version %d\n",
  1012. __func__, rc);
  1013. return rc;
  1014. }
  1015. }
  1016. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1017. AFE_CDC_CLIP_REGISTERS_CONFIG);
  1018. if (config_data) {
  1019. rc = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG,
  1020. config_data, 0);
  1021. if (rc) {
  1022. pr_err("%s: Failed to set clip registers %d\n",
  1023. __func__, rc);
  1024. return rc;
  1025. }
  1026. }
  1027. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1028. AFE_CLIP_BANK_SEL);
  1029. if (config_data) {
  1030. rc = afe_set_config(AFE_CLIP_BANK_SEL,
  1031. config_data, 0);
  1032. if (rc) {
  1033. pr_err("%s: Failed to set AFE bank selection %d\n",
  1034. __func__, rc);
  1035. return rc;
  1036. }
  1037. }
  1038. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1039. AFE_CDC_REGISTER_PAGE_CONFIG);
  1040. if (config_data) {
  1041. rc = afe_set_config(AFE_CDC_REGISTER_PAGE_CONFIG, config_data,
  1042. 0);
  1043. if (rc)
  1044. pr_err("%s: Failed to set cdc register page config\n",
  1045. __func__);
  1046. }
  1047. return 0;
  1048. }
  1049. static void msm_afe_clear_config(void)
  1050. {
  1051. afe_clear_config(AFE_CDC_REGISTERS_CONFIG);
  1052. afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG);
  1053. }
  1054. static void msm_snd_interrupt_config(struct msm_asoc_mach_data *pdata)
  1055. {
  1056. int val;
  1057. val = ioread32(pdata->msm_snd_intr_lpi.mpm_wakeup);
  1058. val |= LPI_GPIO_22_WAKEUP_VAL;
  1059. iowrite32(val, pdata->msm_snd_intr_lpi.mpm_wakeup);
  1060. val = ioread32(pdata->msm_snd_intr_lpi.intr1_cfg_apps);
  1061. val &= ~(LPI_GPIO_22_INTR1_CFG_MASK);
  1062. val |= LPI_GPIO_22_INTR1_CFG_VAL;
  1063. iowrite32(val, pdata->msm_snd_intr_lpi.intr1_cfg_apps);
  1064. iowrite32(LPI_GPIO_INTR_CFG1_VAL,
  1065. pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg);
  1066. iowrite32(LPI_GPIO22_CFG_VAL,
  1067. pdata->msm_snd_intr_lpi.lpi_gpio_cfg);
  1068. val = ioread32(pdata->msm_snd_intr_lpi.lpi_gpio_inout);
  1069. val |= LPI_GPIO22_INOUT_VAL;
  1070. iowrite32(val, pdata->msm_snd_intr_lpi.lpi_gpio_inout);
  1071. }
  1072. static int msm_adsp_power_up_config(struct snd_soc_codec *codec)
  1073. {
  1074. int ret = 0;
  1075. unsigned long timeout;
  1076. int adsp_ready = 0;
  1077. struct snd_soc_card *card = codec->component.card;
  1078. struct msm_asoc_mach_data *pdata;
  1079. pdata = snd_soc_card_get_drvdata(card);
  1080. timeout = jiffies +
  1081. msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS);
  1082. do {
  1083. if (q6core_is_adsp_ready()) {
  1084. pr_debug("%s: ADSP Audio is ready\n", __func__);
  1085. adsp_ready = 1;
  1086. break;
  1087. }
  1088. /*
  1089. * ADSP will be coming up after subsystem restart and
  1090. * it might not be fully up when the control reaches
  1091. * here. So, wait for 50msec before checking ADSP state
  1092. */
  1093. msleep(50);
  1094. } while (time_after(timeout, jiffies));
  1095. if (!adsp_ready) {
  1096. pr_err("%s: timed out waiting for ADSP Audio\n", __func__);
  1097. ret = -ETIMEDOUT;
  1098. goto err_fail;
  1099. }
  1100. msm_snd_interrupt_config(pdata);
  1101. ret = msm_afe_set_config(codec);
  1102. if (ret)
  1103. pr_err("%s: Failed to set AFE config. err %d\n",
  1104. __func__, ret);
  1105. return 0;
  1106. err_fail:
  1107. return ret;
  1108. }
  1109. static int sdm660_notifier_service_cb(struct notifier_block *this,
  1110. unsigned long opcode, void *ptr)
  1111. {
  1112. int ret;
  1113. struct snd_soc_card *card = NULL;
  1114. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  1115. struct snd_soc_pcm_runtime *rtd;
  1116. struct snd_soc_codec *codec;
  1117. pr_debug("%s: Service opcode 0x%lx\n", __func__, opcode);
  1118. switch (opcode) {
  1119. case AUDIO_NOTIFIER_SERVICE_DOWN:
  1120. /*
  1121. * Use flag to ignore initial boot notifications
  1122. * On initial boot msm_adsp_power_up_config is
  1123. * called on init. There is no need to clear
  1124. * and set the config again on initial boot.
  1125. */
  1126. if (is_initial_boot)
  1127. break;
  1128. msm_afe_clear_config();
  1129. break;
  1130. case AUDIO_NOTIFIER_SERVICE_UP:
  1131. if (is_initial_boot) {
  1132. is_initial_boot = false;
  1133. break;
  1134. }
  1135. if (!spdev)
  1136. return -EINVAL;
  1137. card = platform_get_drvdata(spdev);
  1138. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  1139. if (!rtd) {
  1140. dev_err(card->dev,
  1141. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1142. __func__, be_dl_name);
  1143. ret = -EINVAL;
  1144. goto done;
  1145. }
  1146. codec = rtd->codec;
  1147. ret = msm_adsp_power_up_config(codec);
  1148. if (ret < 0) {
  1149. dev_err(card->dev,
  1150. "%s: msm_adsp_power_up_config failed ret = %d!\n",
  1151. __func__, ret);
  1152. goto done;
  1153. }
  1154. break;
  1155. default:
  1156. break;
  1157. }
  1158. done:
  1159. return NOTIFY_OK;
  1160. }
  1161. static struct notifier_block service_nb = {
  1162. .notifier_call = sdm660_notifier_service_cb,
  1163. .priority = -INT_MAX,
  1164. };
  1165. static int msm_config_hph_en0_gpio(struct snd_soc_codec *codec, bool high)
  1166. {
  1167. struct snd_soc_card *card = codec->component.card;
  1168. struct msm_asoc_mach_data *pdata;
  1169. int val;
  1170. if (!card)
  1171. return 0;
  1172. pdata = snd_soc_card_get_drvdata(card);
  1173. if (!pdata || !gpio_is_valid(pdata->hph_en0_gpio))
  1174. return 0;
  1175. val = gpio_get_value_cansleep(pdata->hph_en0_gpio);
  1176. if ((!!val) == high)
  1177. return 0;
  1178. gpio_direction_output(pdata->hph_en0_gpio, (int)high);
  1179. return 1;
  1180. }
  1181. static int msm_snd_enable_codec_ext_tx_clk(struct snd_soc_codec *codec,
  1182. int enable, bool dapm)
  1183. {
  1184. int ret = 0;
  1185. if (!strcmp(dev_name(codec->dev), "tasha_codec"))
  1186. ret = tasha_cdc_mclk_tx_enable(codec, enable, dapm);
  1187. else {
  1188. dev_err(codec->dev, "%s: unknown codec to enable ext clk\n",
  1189. __func__);
  1190. ret = -EINVAL;
  1191. }
  1192. return ret;
  1193. }
  1194. static int msm_ext_mclk_tx_event(struct snd_soc_dapm_widget *w,
  1195. struct snd_kcontrol *kcontrol, int event)
  1196. {
  1197. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1198. pr_debug("%s: event = %d\n", __func__, event);
  1199. switch (event) {
  1200. case SND_SOC_DAPM_PRE_PMU:
  1201. return msm_snd_enable_codec_ext_tx_clk(codec, 1, true);
  1202. case SND_SOC_DAPM_POST_PMD:
  1203. return msm_snd_enable_codec_ext_tx_clk(codec, 0, true);
  1204. }
  1205. return 0;
  1206. }
  1207. static int msm_ext_mclk_event(struct snd_soc_dapm_widget *w,
  1208. struct snd_kcontrol *kcontrol, int event)
  1209. {
  1210. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1211. pr_debug("%s: event = %d\n", __func__, event);
  1212. switch (event) {
  1213. case SND_SOC_DAPM_PRE_PMU:
  1214. return msm_ext_enable_codec_mclk(codec, 1, true);
  1215. case SND_SOC_DAPM_POST_PMD:
  1216. return msm_ext_enable_codec_mclk(codec, 0, true);
  1217. }
  1218. return 0;
  1219. }
  1220. static int msm_ext_prepare_hifi(struct msm_asoc_mach_data *pdata)
  1221. {
  1222. int ret = 0;
  1223. if (gpio_is_valid(pdata->hph_en1_gpio)) {
  1224. pr_debug("%s: hph_en1_gpio request %d\n", __func__,
  1225. pdata->hph_en1_gpio);
  1226. ret = gpio_request(pdata->hph_en1_gpio, "hph_en1_gpio");
  1227. if (ret) {
  1228. pr_err("%s: hph_en1_gpio request failed, ret:%d\n",
  1229. __func__, ret);
  1230. goto err;
  1231. }
  1232. }
  1233. if (gpio_is_valid(pdata->hph_en0_gpio)) {
  1234. pr_debug("%s: hph_en0_gpio request %d\n", __func__,
  1235. pdata->hph_en0_gpio);
  1236. ret = gpio_request(pdata->hph_en0_gpio, "hph_en0_gpio");
  1237. if (ret)
  1238. pr_err("%s: hph_en0_gpio request failed, ret:%d\n",
  1239. __func__, ret);
  1240. }
  1241. err:
  1242. return ret;
  1243. }
  1244. static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
  1245. SND_SOC_DAPM_SUPPLY_S("MCLK", -1, SND_SOC_NOPM, 0, 0,
  1246. msm_ext_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1247. SND_SOC_DAPM_SUPPLY_S("MCLK TX", -1, SND_SOC_NOPM, 0, 0,
  1248. msm_ext_mclk_tx_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1249. SND_SOC_DAPM_SPK("Lineout_1 amp", NULL),
  1250. SND_SOC_DAPM_SPK("Lineout_3 amp", NULL),
  1251. SND_SOC_DAPM_SPK("Lineout_2 amp", NULL),
  1252. SND_SOC_DAPM_SPK("Lineout_4 amp", NULL),
  1253. SND_SOC_DAPM_MIC("Handset Mic", NULL),
  1254. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  1255. SND_SOC_DAPM_MIC("Secondary Mic", NULL),
  1256. SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
  1257. SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
  1258. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  1259. SND_SOC_DAPM_MIC("Analog Mic6", NULL),
  1260. SND_SOC_DAPM_MIC("Analog Mic7", NULL),
  1261. SND_SOC_DAPM_MIC("Analog Mic8", NULL),
  1262. SND_SOC_DAPM_MIC("Digital Mic0", NULL),
  1263. SND_SOC_DAPM_MIC("Digital Mic1", NULL),
  1264. SND_SOC_DAPM_MIC("Digital Mic2", NULL),
  1265. SND_SOC_DAPM_MIC("Digital Mic3", NULL),
  1266. SND_SOC_DAPM_MIC("Digital Mic4", NULL),
  1267. SND_SOC_DAPM_MIC("Digital Mic5", NULL),
  1268. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  1269. };
  1270. static struct snd_soc_dapm_route wcd_audio_paths_tasha[] = {
  1271. {"MIC BIAS1", NULL, "MCLK TX"},
  1272. {"MIC BIAS2", NULL, "MCLK TX"},
  1273. {"MIC BIAS3", NULL, "MCLK TX"},
  1274. {"MIC BIAS4", NULL, "MCLK TX"},
  1275. };
  1276. static struct snd_soc_dapm_route wcd_audio_paths[] = {
  1277. {"MIC BIAS1", NULL, "MCLK"},
  1278. {"MIC BIAS2", NULL, "MCLK"},
  1279. {"MIC BIAS3", NULL, "MCLK"},
  1280. {"MIC BIAS4", NULL, "MCLK"},
  1281. };
  1282. int msm_snd_card_tasha_late_probe(struct snd_soc_card *card)
  1283. {
  1284. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  1285. struct snd_soc_pcm_runtime *rtd;
  1286. int ret = 0;
  1287. void *mbhc_calibration;
  1288. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  1289. if (!rtd) {
  1290. dev_err(card->dev,
  1291. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1292. __func__, be_dl_name);
  1293. ret = -EINVAL;
  1294. goto err_pcm_runtime;
  1295. }
  1296. mbhc_calibration = def_ext_mbhc_cal();
  1297. if (!mbhc_calibration) {
  1298. ret = -ENOMEM;
  1299. goto err_mbhc_cal;
  1300. }
  1301. wcd_mbhc_cfg_ptr->calibration = mbhc_calibration;
  1302. ret = tasha_mbhc_hs_detect(rtd->codec, wcd_mbhc_cfg_ptr);
  1303. if (ret) {
  1304. dev_err(card->dev, "%s: mbhc hs detect failed, err:%d\n",
  1305. __func__, ret);
  1306. goto err_hs_detect;
  1307. }
  1308. return 0;
  1309. err_hs_detect:
  1310. kfree(mbhc_calibration);
  1311. err_mbhc_cal:
  1312. err_pcm_runtime:
  1313. return ret;
  1314. }
  1315. int msm_snd_card_tavil_late_probe(struct snd_soc_card *card)
  1316. {
  1317. const char *be_dl_name = LPASS_BE_SLIMBUS_0_RX;
  1318. struct snd_soc_pcm_runtime *rtd;
  1319. int ret = 0;
  1320. void *mbhc_calibration;
  1321. rtd = snd_soc_get_pcm_runtime(card, be_dl_name);
  1322. if (!rtd) {
  1323. dev_err(card->dev,
  1324. "%s: snd_soc_get_pcm_runtime for %s failed!\n",
  1325. __func__, be_dl_name);
  1326. ret = -EINVAL;
  1327. goto err;
  1328. }
  1329. mbhc_calibration = def_ext_mbhc_cal();
  1330. if (!mbhc_calibration) {
  1331. ret = -ENOMEM;
  1332. goto err;
  1333. }
  1334. wcd_mbhc_cfg_ptr->calibration = mbhc_calibration;
  1335. ret = tavil_mbhc_hs_detect(rtd->codec, wcd_mbhc_cfg_ptr);
  1336. if (ret) {
  1337. dev_err(card->dev, "%s: mbhc hs detect failed, err:%d\n",
  1338. __func__, ret);
  1339. goto err_free_mbhc_cal;
  1340. }
  1341. return 0;
  1342. err_free_mbhc_cal:
  1343. kfree(mbhc_calibration);
  1344. err:
  1345. return ret;
  1346. }
  1347. /**
  1348. * msm_audrx_init - Audio init function of sound card instantiate.
  1349. *
  1350. * @rtd: runtime dailink instance
  1351. *
  1352. * Returns 0 on success or ret on failure.
  1353. */
  1354. int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
  1355. {
  1356. int ret;
  1357. void *config_data;
  1358. struct snd_soc_codec *codec = rtd->codec;
  1359. struct snd_soc_dapm_context *dapm =
  1360. snd_soc_codec_get_dapm(codec);
  1361. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  1362. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1363. struct snd_soc_component *aux_comp;
  1364. struct snd_card *card;
  1365. struct snd_info_entry *entry;
  1366. struct msm_asoc_mach_data *pdata =
  1367. snd_soc_card_get_drvdata(rtd->card);
  1368. /* Codec SLIMBUS configuration
  1369. * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8, RX9, RX10, RX11, RX12, RX13
  1370. * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
  1371. * TX14, TX15, TX16
  1372. */
  1373. unsigned int rx_ch[TASHA_RX_MAX] = {144, 145, 146, 147, 148, 149, 150,
  1374. 151, 152, 153, 154, 155, 156};
  1375. unsigned int tx_ch[TASHA_TX_MAX] = {128, 129, 130, 131, 132, 133,
  1376. 134, 135, 136, 137, 138, 139,
  1377. 140, 141, 142, 143};
  1378. /* Tavil Codec SLIMBUS configuration
  1379. * RX1, RX2, RX3, RX4, RX5, RX6, RX7, RX8
  1380. * TX1, TX2, TX3, TX4, TX5, TX6, TX7, TX8, TX9, TX10, TX11, TX12, TX13
  1381. * TX14, TX15, TX16
  1382. */
  1383. unsigned int rx_ch_tavil[WCD934X_RX_MAX] = {144, 145, 146, 147, 148,
  1384. 149, 150, 151};
  1385. unsigned int tx_ch_tavil[WCD934X_TX_MAX] = {128, 129, 130, 131, 132,
  1386. 133, 134, 135, 136, 137, 138,
  1387. 139, 140, 141, 142, 143};
  1388. pr_debug("%s: dev_name%s\n", __func__, dev_name(cpu_dai->dev));
  1389. rtd->pmdown_time = 0;
  1390. ret = snd_soc_add_codec_controls(codec, msm_snd_controls,
  1391. ARRAY_SIZE(msm_snd_controls));
  1392. if (ret < 0) {
  1393. pr_err("%s: add_codec_controls failed: %d\n",
  1394. __func__, ret);
  1395. return ret;
  1396. }
  1397. ret = snd_soc_add_codec_controls(codec, msm_common_snd_controls,
  1398. msm_common_snd_controls_size());
  1399. if (ret < 0) {
  1400. pr_err("%s: add_common_snd_controls failed: %d\n",
  1401. __func__, ret);
  1402. return ret;
  1403. }
  1404. snd_soc_dapm_new_controls(dapm, msm_dapm_widgets,
  1405. ARRAY_SIZE(msm_dapm_widgets));
  1406. if (!strcmp(dev_name(codec_dai->dev), "tasha_codec"))
  1407. snd_soc_dapm_add_routes(dapm, wcd_audio_paths_tasha,
  1408. ARRAY_SIZE(wcd_audio_paths_tasha));
  1409. else
  1410. snd_soc_dapm_add_routes(dapm, wcd_audio_paths,
  1411. ARRAY_SIZE(wcd_audio_paths));
  1412. snd_soc_dapm_enable_pin(dapm, "Lineout_1 amp");
  1413. snd_soc_dapm_enable_pin(dapm, "Lineout_3 amp");
  1414. snd_soc_dapm_enable_pin(dapm, "Lineout_2 amp");
  1415. snd_soc_dapm_enable_pin(dapm, "Lineout_4 amp");
  1416. snd_soc_dapm_ignore_suspend(dapm, "MADINPUT");
  1417. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_INPUT");
  1418. snd_soc_dapm_ignore_suspend(dapm, "Handset Mic");
  1419. snd_soc_dapm_ignore_suspend(dapm, "Headset Mic");
  1420. snd_soc_dapm_ignore_suspend(dapm, "Secondary Mic");
  1421. snd_soc_dapm_ignore_suspend(dapm, "Lineout_1 amp");
  1422. snd_soc_dapm_ignore_suspend(dapm, "Lineout_3 amp");
  1423. snd_soc_dapm_ignore_suspend(dapm, "Lineout_2 amp");
  1424. snd_soc_dapm_ignore_suspend(dapm, "Lineout_4 amp");
  1425. snd_soc_dapm_ignore_suspend(dapm, "ANCRight Headset Mic");
  1426. snd_soc_dapm_ignore_suspend(dapm, "ANCLeft Headset Mic");
  1427. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1428. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1429. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1430. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1431. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  1432. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  1433. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1434. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic6");
  1435. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic7");
  1436. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic8");
  1437. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1438. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT1");
  1439. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT2");
  1440. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1441. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1442. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1443. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1444. snd_soc_dapm_ignore_suspend(dapm, "AMIC5");
  1445. snd_soc_dapm_ignore_suspend(dapm, "DMIC0");
  1446. snd_soc_dapm_ignore_suspend(dapm, "DMIC1");
  1447. snd_soc_dapm_ignore_suspend(dapm, "DMIC2");
  1448. snd_soc_dapm_ignore_suspend(dapm, "DMIC3");
  1449. snd_soc_dapm_ignore_suspend(dapm, "DMIC4");
  1450. snd_soc_dapm_ignore_suspend(dapm, "DMIC5");
  1451. snd_soc_dapm_ignore_suspend(dapm, "ANC EAR");
  1452. snd_soc_dapm_ignore_suspend(dapm, "SPK1 OUT");
  1453. snd_soc_dapm_ignore_suspend(dapm, "SPK2 OUT");
  1454. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1455. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1456. snd_soc_dapm_ignore_suspend(dapm, "AIF4 VI");
  1457. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT");
  1458. if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) {
  1459. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT3");
  1460. snd_soc_dapm_ignore_suspend(dapm, "LINEOUT4");
  1461. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHL");
  1462. snd_soc_dapm_ignore_suspend(dapm, "ANC HPHR");
  1463. snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT1");
  1464. snd_soc_dapm_ignore_suspend(dapm, "ANC LINEOUT2");
  1465. } else {
  1466. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT1");
  1467. snd_soc_dapm_ignore_suspend(dapm, "MAD_CPE_OUT2");
  1468. }
  1469. snd_soc_dapm_sync(dapm);
  1470. if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
  1471. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch_tavil),
  1472. tx_ch_tavil, ARRAY_SIZE(rx_ch_tavil),
  1473. rx_ch_tavil);
  1474. } else {
  1475. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  1476. tx_ch, ARRAY_SIZE(rx_ch),
  1477. rx_ch);
  1478. }
  1479. if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
  1480. msm_codec_fn.get_afe_config_fn = tavil_get_afe_config;
  1481. } else {
  1482. msm_codec_fn.get_afe_config_fn = tasha_get_afe_config;
  1483. msm_codec_fn.mbhc_hs_detect_exit = tasha_mbhc_hs_detect_exit;
  1484. }
  1485. ret = msm_adsp_power_up_config(codec);
  1486. if (ret) {
  1487. pr_err("%s: Failed to set AFE config %d\n", __func__, ret);
  1488. goto err_afe_cfg;
  1489. }
  1490. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1491. AFE_AANC_VERSION);
  1492. if (config_data) {
  1493. ret = afe_set_config(AFE_AANC_VERSION, config_data, 0);
  1494. if (ret) {
  1495. pr_err("%s: Failed to set aanc version %d\n",
  1496. __func__, ret);
  1497. goto err_afe_cfg;
  1498. }
  1499. }
  1500. if (!strcmp(dev_name(codec_dai->dev), "tasha_codec")) {
  1501. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1502. AFE_CDC_CLIP_REGISTERS_CONFIG);
  1503. if (config_data) {
  1504. ret = afe_set_config(AFE_CDC_CLIP_REGISTERS_CONFIG,
  1505. config_data, 0);
  1506. if (ret) {
  1507. pr_err("%s: Failed to set clip registers %d\n",
  1508. __func__, ret);
  1509. goto err_afe_cfg;
  1510. }
  1511. }
  1512. config_data = msm_codec_fn.get_afe_config_fn(codec,
  1513. AFE_CLIP_BANK_SEL);
  1514. if (config_data) {
  1515. ret = afe_set_config(AFE_CLIP_BANK_SEL, config_data, 0);
  1516. if (ret) {
  1517. pr_err("%s: Failed to set AFE bank selection %d\n",
  1518. __func__, ret);
  1519. goto err_afe_cfg;
  1520. }
  1521. }
  1522. }
  1523. /*
  1524. * Send speaker configuration only for WSA8810.
  1525. * Defalut configuration is for WSA8815.
  1526. */
  1527. pr_debug("%s: Number of aux devices: %d\n",
  1528. __func__, rtd->card->num_aux_devs);
  1529. if (!strcmp(dev_name(codec_dai->dev), "tavil_codec")) {
  1530. if (rtd->card->num_aux_devs &&
  1531. !list_empty(&rtd->card->aux_comp_list)) {
  1532. aux_comp = list_first_entry(&rtd->card->aux_comp_list,
  1533. struct snd_soc_component, list_aux);
  1534. if (!strcmp(aux_comp->name, WSA8810_NAME_1) ||
  1535. !strcmp(aux_comp->name, WSA8810_NAME_2)) {
  1536. tavil_set_spkr_mode(rtd->codec, SPKR_MODE_1);
  1537. tavil_set_spkr_gain_offset(rtd->codec,
  1538. RX_GAIN_OFFSET_M1P5_DB);
  1539. }
  1540. }
  1541. card = rtd->card->snd_card;
  1542. entry = snd_info_create_subdir(card->module, "codecs",
  1543. card->proc_root);
  1544. if (!entry) {
  1545. pr_debug("%s: Cannot create codecs module entry\n",
  1546. __func__);
  1547. goto done;
  1548. }
  1549. pdata->codec_root = entry;
  1550. tavil_codec_info_create_codec_entry(pdata->codec_root, codec);
  1551. } else {
  1552. if (rtd->card->num_aux_devs &&
  1553. !list_empty(&rtd->card->aux_comp_list)) {
  1554. aux_comp = list_first_entry(&rtd->card->aux_comp_list,
  1555. struct snd_soc_component, list_aux);
  1556. if (!strcmp(aux_comp->name, WSA8810_NAME_1) ||
  1557. !strcmp(aux_comp->name, WSA8810_NAME_2)) {
  1558. tasha_set_spkr_mode(rtd->codec, SPKR_MODE_1);
  1559. tasha_set_spkr_gain_offset(rtd->codec,
  1560. RX_GAIN_OFFSET_M1P5_DB);
  1561. }
  1562. }
  1563. card = rtd->card->snd_card;
  1564. entry = snd_info_create_subdir(card->module, "codecs",
  1565. card->proc_root);
  1566. if (!entry) {
  1567. pr_debug("%s: Cannot create codecs module entry\n",
  1568. __func__);
  1569. goto done;
  1570. }
  1571. pdata->codec_root = entry;
  1572. tasha_codec_info_create_codec_entry(pdata->codec_root, codec);
  1573. tasha_mbhc_zdet_gpio_ctrl(msm_config_hph_en0_gpio, rtd->codec);
  1574. }
  1575. done:
  1576. msm_set_codec_reg_done(true);
  1577. return 0;
  1578. err_afe_cfg:
  1579. return ret;
  1580. }
  1581. EXPORT_SYMBOL(msm_audrx_init);
  1582. /**
  1583. * msm_ext_register_audio_notifier - register SSR notifier.
  1584. */
  1585. void msm_ext_register_audio_notifier(struct platform_device *pdev)
  1586. {
  1587. int ret;
  1588. is_initial_boot = true;
  1589. spdev = pdev;
  1590. ret = audio_notifier_register("sdm660", AUDIO_NOTIFIER_ADSP_DOMAIN,
  1591. &service_nb);
  1592. if (ret < 0)
  1593. pr_err("%s: Audio notifier register failed ret = %d\n",
  1594. __func__, ret);
  1595. }
  1596. EXPORT_SYMBOL(msm_ext_register_audio_notifier);
  1597. /**
  1598. * msm_ext_cdc_init - external codec machine specific init.
  1599. *
  1600. * @pdev: platform device handle
  1601. * @pdata: private data of machine driver
  1602. * @card: sound card pointer reference
  1603. * @mbhc_cfg: MBHC config reference
  1604. *
  1605. * Returns 0 on success or ret on failure.
  1606. */
  1607. int msm_ext_cdc_init(struct platform_device *pdev,
  1608. struct msm_asoc_mach_data *pdata,
  1609. struct snd_soc_card **card,
  1610. struct wcd_mbhc_config *wcd_mbhc_cfg_ptr1)
  1611. {
  1612. int ret = 0;
  1613. wcd_mbhc_cfg_ptr = wcd_mbhc_cfg_ptr1;
  1614. pdev->id = 0;
  1615. wcd_mbhc_cfg_ptr->moisture_en = true;
  1616. wcd_mbhc_cfg_ptr->mbhc_micbias = MIC_BIAS_2;
  1617. wcd_mbhc_cfg_ptr->anc_micbias = MIC_BIAS_2;
  1618. wcd_mbhc_cfg_ptr->enable_anc_mic_detect = false;
  1619. *card = populate_snd_card_dailinks(&pdev->dev, pdata->snd_card_val);
  1620. if (!(*card)) {
  1621. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1622. ret = -EPROBE_DEFER;
  1623. goto err;
  1624. }
  1625. platform_set_drvdata(pdev, *card);
  1626. snd_soc_card_set_drvdata(*card, pdata);
  1627. pdata->hph_en1_gpio = of_get_named_gpio(pdev->dev.of_node,
  1628. "qcom,hph-en1-gpio", 0);
  1629. if (!gpio_is_valid(pdata->hph_en1_gpio))
  1630. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1631. "qcom,hph-en1-gpio", 0);
  1632. if (!gpio_is_valid(pdata->hph_en1_gpio) && (!pdata->hph_en1_gpio_p)) {
  1633. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1634. "qcom,hph-en1-gpio", pdev->dev.of_node->full_name);
  1635. }
  1636. pdata->hph_en0_gpio = of_get_named_gpio(pdev->dev.of_node,
  1637. "qcom,hph-en0-gpio", 0);
  1638. if (!gpio_is_valid(pdata->hph_en0_gpio))
  1639. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1640. "qcom,hph-en0-gpio", 0);
  1641. if (!gpio_is_valid(pdata->hph_en0_gpio) && (!pdata->hph_en0_gpio_p)) {
  1642. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1643. "qcom,hph-en0-gpio", pdev->dev.of_node->full_name);
  1644. }
  1645. ret = msm_ext_prepare_hifi(pdata);
  1646. if (ret) {
  1647. dev_dbg(&pdev->dev, "msm_ext_prepare_hifi failed (%d)\n",
  1648. ret);
  1649. ret = 0;
  1650. }
  1651. pdata->msm_snd_intr_lpi.mpm_wakeup =
  1652. ioremap(TLMM_CENTER_MPM_WAKEUP_INT_EN_0, 4);
  1653. pdata->msm_snd_intr_lpi.intr1_cfg_apps =
  1654. ioremap(TLMM_LPI_DIR_CONN_INTR1_CFG_APPS, 4);
  1655. pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg =
  1656. ioremap(TLMM_LPI_GPIO_INTR_CFG1, 4);
  1657. pdata->msm_snd_intr_lpi.lpi_gpio_cfg =
  1658. ioremap(TLMM_LPI_GPIO22_CFG, 4);
  1659. pdata->msm_snd_intr_lpi.lpi_gpio_inout =
  1660. ioremap(TLMM_LPI_GPIO22_INOUT, 4);
  1661. err:
  1662. return ret;
  1663. }
  1664. EXPORT_SYMBOL(msm_ext_cdc_init);
  1665. /**
  1666. * msm_ext_cdc_deinit - external codec machine specific deinit.
  1667. */
  1668. void msm_ext_cdc_deinit(struct msm_asoc_mach_data *pdata)
  1669. {
  1670. if (pdata->msm_snd_intr_lpi.mpm_wakeup)
  1671. iounmap(pdata->msm_snd_intr_lpi.mpm_wakeup);
  1672. if (pdata->msm_snd_intr_lpi.intr1_cfg_apps)
  1673. iounmap(pdata->msm_snd_intr_lpi.intr1_cfg_apps);
  1674. if (pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg)
  1675. iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_intr_cfg);
  1676. if (pdata->msm_snd_intr_lpi.lpi_gpio_cfg)
  1677. iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_cfg);
  1678. if (pdata->msm_snd_intr_lpi.lpi_gpio_inout)
  1679. iounmap(pdata->msm_snd_intr_lpi.lpi_gpio_inout);
  1680. }
  1681. EXPORT_SYMBOL(msm_ext_cdc_deinit);