sdm660-external.c 51 KB

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