sdm660-external.c 52 KB

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