sdm660-external.c 51 KB

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