apq8064.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  1. /* Copyright (c) 2011-2013, 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/clk.h>
  13. #include <linux/delay.h>
  14. #include <linux/gpio.h>
  15. #include <linux/mfd/pm8xxx/pm8921.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/gpio.h>
  18. #include <linux/mfd/pm8xxx/pm8921.h>
  19. #include <linux/slab.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/slimbus/slimbus.h>
  22. #include <sound/core.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <sound/pcm.h>
  26. #include <sound/jack.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/socinfo.h>
  29. #include "msm-pcm-routing.h"
  30. #include "../codecs/wcd9310.h"
  31. /* 8064 machine driver */
  32. #define PM8921_GPIO_BASE NR_GPIO_IRQS
  33. #define PM8921_GPIO_PM_TO_SYS(pm_gpio) (pm_gpio - 1 + PM8921_GPIO_BASE)
  34. #define MSM8064_SPK_ON 1
  35. #define MSM8064_SPK_OFF 0
  36. #define MSM_SLIM_0_RX_MAX_CHANNELS 2
  37. #define MSM_SLIM_0_TX_MAX_CHANNELS 4
  38. #define SAMPLE_RATE_8KHZ 8000
  39. #define SAMPLE_RATE_16KHZ 16000
  40. #define SAMPLE_RATE_48KHZ 48000
  41. #define BOTTOM_SPK_AMP_POS 0x1
  42. #define BOTTOM_SPK_AMP_NEG 0x2
  43. #define TOP_SPK_AMP_POS 0x4
  44. #define TOP_SPK_AMP_NEG 0x8
  45. #define TOP_SPK_AMP 0x10
  46. #define GPIO_AUX_PCM_DOUT 43
  47. #define GPIO_AUX_PCM_DIN 44
  48. #define GPIO_AUX_PCM_SYNC 45
  49. #define GPIO_AUX_PCM_CLK 46
  50. #define TABLA_EXT_CLK_RATE 12288000
  51. #define TABLA_MBHC_DEF_BUTTONS 8
  52. #define TABLA_MBHC_DEF_RLOADS 5
  53. #define JACK_DETECT_GPIO 38
  54. /* Shared channel numbers for Slimbus ports that connect APQ to MDM. */
  55. enum {
  56. SLIM_1_RX_1 = 145, /* BT-SCO and USB TX */
  57. SLIM_1_TX_1 = 146, /* BT-SCO and USB RX */
  58. SLIM_1_TX_2 = 147, /* USB RX */
  59. SLIM_3_RX_1 = 151, /* External echo-cancellation ref */
  60. SLIM_3_RX_2 = 152, /* External echo-cancellation ref */
  61. SLIM_3_TX_1 = 153, /* HDMI RX */
  62. SLIM_3_TX_2 = 154, /* HDMI RX */
  63. SLIM_4_TX_1 = 148, /* In-call recording RX */
  64. SLIM_4_TX_2 = 149, /* In-call recording RX */
  65. SLIM_4_RX_1 = 150, /* In-call music delivery TX */
  66. };
  67. enum {
  68. INCALL_REC_MONO,
  69. INCALL_REC_STEREO,
  70. };
  71. static u32 top_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(18);
  72. static u32 bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(19);
  73. static int msm_spk_control;
  74. static int msm_ext_bottom_spk_pamp;
  75. static int msm_ext_top_spk_pamp;
  76. static int msm_slim_0_rx_ch = 1;
  77. static int msm_slim_0_tx_ch = 1;
  78. static int msm_slim_3_rx_ch = 1;
  79. static int msm_slim_1_rate = SAMPLE_RATE_8KHZ;
  80. static int msm_btsco_ch = 1;
  81. static int msm_slim_1_rx_ch = 1;
  82. static int msm_slim_1_tx_ch = 1;
  83. static int hdmi_rate_variable;
  84. static int rec_mode = INCALL_REC_MONO;
  85. static struct clk *codec_clk;
  86. static int clk_users;
  87. static struct snd_soc_jack hs_jack;
  88. static struct snd_soc_jack button_jack;
  89. static atomic_t auxpcm_rsc_ref;
  90. static int apq8064_hs_detect_use_gpio = -1;
  91. module_param(apq8064_hs_detect_use_gpio, int, 0444);
  92. MODULE_PARM_DESC(apq8064_hs_detect_use_gpio, "Use GPIO for headset detection");
  93. static bool apq8064_hs_detect_extn_cable;
  94. module_param(apq8064_hs_detect_extn_cable, bool, 0444);
  95. MODULE_PARM_DESC(apq8064_hs_detect_extn_cable, "Enable extension cable feature");
  96. static bool apq8064_hs_detect_use_firmware;
  97. module_param(apq8064_hs_detect_use_firmware, bool, 0444);
  98. MODULE_PARM_DESC(apq8064_hs_detect_use_firmware, "Use firmware for headset "
  99. "detection");
  100. static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
  101. bool dapm);
  102. static struct tabla_mbhc_config mbhc_cfg = {
  103. .headset_jack = &hs_jack,
  104. .button_jack = &button_jack,
  105. .read_fw_bin = false,
  106. .calibration = NULL,
  107. .micbias = TABLA_MICBIAS2,
  108. .mclk_cb_fn = msm_enable_codec_ext_clk,
  109. .mclk_rate = TABLA_EXT_CLK_RATE,
  110. .gpio = 0,
  111. .gpio_irq = 0,
  112. .gpio_level_insert = 1,
  113. .detect_extn_cable = false,
  114. };
  115. static struct mutex cdc_mclk_mutex;
  116. static void msm_enable_ext_spk_amp_gpio(u32 spk_amp_gpio)
  117. {
  118. int ret = 0;
  119. struct pm_gpio param = {
  120. .direction = PM_GPIO_DIR_OUT,
  121. .output_buffer = PM_GPIO_OUT_BUF_CMOS,
  122. .output_value = 1,
  123. .pull = PM_GPIO_PULL_NO,
  124. .vin_sel = PM_GPIO_VIN_S4,
  125. .out_strength = PM_GPIO_STRENGTH_MED,
  126. .
  127. function = PM_GPIO_FUNC_NORMAL,
  128. };
  129. if (spk_amp_gpio == bottom_spk_pamp_gpio) {
  130. ret = gpio_request(bottom_spk_pamp_gpio, "BOTTOM_SPK_AMP");
  131. if (ret) {
  132. pr_err("%s: Error requesting BOTTOM SPK AMP GPIO %u\n",
  133. __func__, bottom_spk_pamp_gpio);
  134. return;
  135. }
  136. ret = pm8xxx_gpio_config(bottom_spk_pamp_gpio, &param);
  137. if (ret)
  138. pr_err("%s: Failed to configure Bottom Spk Ampl"
  139. " gpio %u\n", __func__, bottom_spk_pamp_gpio);
  140. else {
  141. pr_debug("%s: enable Bottom spkr amp gpio\n", __func__);
  142. gpio_direction_output(bottom_spk_pamp_gpio, 1);
  143. }
  144. } else if (spk_amp_gpio == top_spk_pamp_gpio) {
  145. ret = gpio_request(top_spk_pamp_gpio, "TOP_SPK_AMP");
  146. if (ret) {
  147. pr_err("%s: Error requesting GPIO %d\n", __func__,
  148. top_spk_pamp_gpio);
  149. return;
  150. }
  151. ret = pm8xxx_gpio_config(top_spk_pamp_gpio, &param);
  152. if (ret)
  153. pr_err("%s: Failed to configure Top Spk Ampl"
  154. " gpio %u\n", __func__, top_spk_pamp_gpio);
  155. else {
  156. pr_debug("%s: enable Top spkr amp gpio\n", __func__);
  157. gpio_direction_output(top_spk_pamp_gpio, 1);
  158. }
  159. } else {
  160. pr_err("%s: ERROR : Invalid External Speaker Ampl GPIO."
  161. " gpio = %u\n", __func__, spk_amp_gpio);
  162. return;
  163. }
  164. }
  165. static void msm_ext_spk_power_amp_on(u32 spk)
  166. {
  167. if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
  168. if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
  169. (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
  170. pr_debug("%s() External Bottom Speaker Ampl already "
  171. "turned on. spk = 0x%08x\n", __func__, spk);
  172. return;
  173. }
  174. msm_ext_bottom_spk_pamp |= spk;
  175. if ((msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_POS) &&
  176. (msm_ext_bottom_spk_pamp & BOTTOM_SPK_AMP_NEG)) {
  177. msm_enable_ext_spk_amp_gpio(bottom_spk_pamp_gpio);
  178. pr_debug("%s: slepping 4 ms after turning on external "
  179. " Bottom Speaker Ampl\n", __func__);
  180. usleep_range(4000, 4000);
  181. }
  182. } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG | TOP_SPK_AMP)) {
  183. pr_debug("%s():top_spk_amp_state = 0x%x spk_event = 0x%x\n",
  184. __func__, msm_ext_top_spk_pamp, spk);
  185. if (((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
  186. (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) ||
  187. (msm_ext_top_spk_pamp & TOP_SPK_AMP)) {
  188. pr_debug("%s() External Top Speaker Ampl already"
  189. "turned on. spk = 0x%08x\n", __func__, spk);
  190. return;
  191. }
  192. msm_ext_top_spk_pamp |= spk;
  193. if (((msm_ext_top_spk_pamp & TOP_SPK_AMP_POS) &&
  194. (msm_ext_top_spk_pamp & TOP_SPK_AMP_NEG)) ||
  195. (msm_ext_top_spk_pamp & TOP_SPK_AMP)) {
  196. msm_enable_ext_spk_amp_gpio(top_spk_pamp_gpio);
  197. pr_debug("%s: sleeping 4 ms after turning on "
  198. " external Top Speaker Ampl\n", __func__);
  199. usleep_range(4000, 4000);
  200. }
  201. } else {
  202. pr_err("%s: ERROR : Invalid External Speaker Ampl. spk = 0x%08x\n",
  203. __func__, spk);
  204. return;
  205. }
  206. }
  207. static void msm_ext_spk_power_amp_off(u32 spk)
  208. {
  209. if (spk & (BOTTOM_SPK_AMP_POS | BOTTOM_SPK_AMP_NEG)) {
  210. if (!msm_ext_bottom_spk_pamp)
  211. return;
  212. gpio_direction_output(bottom_spk_pamp_gpio, 0);
  213. gpio_free(bottom_spk_pamp_gpio);
  214. msm_ext_bottom_spk_pamp = 0;
  215. pr_debug("%s: sleeping 4 ms after turning off external Bottom"
  216. " Speaker Ampl\n", __func__);
  217. usleep_range(4000, 4000);
  218. } else if (spk & (TOP_SPK_AMP_POS | TOP_SPK_AMP_NEG | TOP_SPK_AMP)) {
  219. pr_debug("%s: top_spk_amp_state = 0x%x spk_event = 0x%x\n",
  220. __func__, msm_ext_top_spk_pamp, spk);
  221. if (!msm_ext_top_spk_pamp)
  222. return;
  223. if ((spk & TOP_SPK_AMP_POS) || (spk & TOP_SPK_AMP_NEG)) {
  224. msm_ext_top_spk_pamp &= (~(TOP_SPK_AMP_POS |
  225. TOP_SPK_AMP_NEG));
  226. } else if (spk & TOP_SPK_AMP) {
  227. msm_ext_top_spk_pamp &= ~TOP_SPK_AMP;
  228. }
  229. if (msm_ext_top_spk_pamp)
  230. return;
  231. gpio_direction_output(top_spk_pamp_gpio, 0);
  232. gpio_free(top_spk_pamp_gpio);
  233. msm_ext_top_spk_pamp = 0;
  234. pr_debug("%s: sleeping 4 ms after ext Top Spek Ampl is off\n",
  235. __func__);
  236. usleep_range(4000, 4000);
  237. } else {
  238. pr_err("%s: ERROR : Invalid Ext Spk Ampl. spk = 0x%08x\n",
  239. __func__, spk);
  240. return;
  241. }
  242. }
  243. static void msm_ext_control(struct snd_soc_codec *codec)
  244. {
  245. struct snd_soc_dapm_context *dapm = &codec->dapm;
  246. pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
  247. if (msm_spk_control == MSM8064_SPK_ON) {
  248. snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
  249. snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
  250. snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
  251. snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
  252. } else {
  253. snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Pos");
  254. snd_soc_dapm_disable_pin(dapm, "Ext Spk Bottom Neg");
  255. snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Pos");
  256. snd_soc_dapm_disable_pin(dapm, "Ext Spk Top Neg");
  257. }
  258. snd_soc_dapm_sync(dapm);
  259. }
  260. static int msm_get_spk(struct snd_kcontrol *kcontrol,
  261. struct snd_ctl_elem_value *ucontrol)
  262. {
  263. pr_debug("%s: msm_spk_control = %d", __func__, msm_spk_control);
  264. ucontrol->value.integer.value[0] = msm_spk_control;
  265. return 0;
  266. }
  267. static int msm_set_spk(struct snd_kcontrol *kcontrol,
  268. struct snd_ctl_elem_value *ucontrol)
  269. {
  270. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  271. pr_debug("%s()\n", __func__);
  272. if (msm_spk_control == ucontrol->value.integer.value[0])
  273. return 0;
  274. msm_spk_control = ucontrol->value.integer.value[0];
  275. msm_ext_control(codec);
  276. return 1;
  277. }
  278. static int msm_spkramp_event(struct snd_soc_dapm_widget *w,
  279. struct snd_kcontrol *k, int event)
  280. {
  281. pr_debug("%s() %x\n", __func__, SND_SOC_DAPM_EVENT_ON(event));
  282. if (SND_SOC_DAPM_EVENT_ON(event)) {
  283. if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
  284. msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_POS);
  285. else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
  286. msm_ext_spk_power_amp_on(BOTTOM_SPK_AMP_NEG);
  287. else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
  288. msm_ext_spk_power_amp_on(TOP_SPK_AMP_POS);
  289. else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
  290. msm_ext_spk_power_amp_on(TOP_SPK_AMP_NEG);
  291. else if (!strncmp(w->name, "Ext Spk Top", 12))
  292. msm_ext_spk_power_amp_on(TOP_SPK_AMP);
  293. else {
  294. pr_err("%s() Invalid Speaker Widget = %s\n",
  295. __func__, w->name);
  296. return -EINVAL;
  297. }
  298. } else {
  299. if (!strncmp(w->name, "Ext Spk Bottom Pos", 18))
  300. msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_POS);
  301. else if (!strncmp(w->name, "Ext Spk Bottom Neg", 18))
  302. msm_ext_spk_power_amp_off(BOTTOM_SPK_AMP_NEG);
  303. else if (!strncmp(w->name, "Ext Spk Top Pos", 15))
  304. msm_ext_spk_power_amp_off(TOP_SPK_AMP_POS);
  305. else if (!strncmp(w->name, "Ext Spk Top Neg", 15))
  306. msm_ext_spk_power_amp_off(TOP_SPK_AMP_NEG);
  307. else if (!strncmp(w->name, "Ext Spk Top", 12))
  308. msm_ext_spk_power_amp_off(TOP_SPK_AMP);
  309. else {
  310. pr_err("%s() Invalid Speaker Widget = %s\n",
  311. __func__, w->name);
  312. return -EINVAL;
  313. }
  314. }
  315. return 0;
  316. }
  317. static int msm_enable_codec_ext_clk(struct snd_soc_codec *codec, int enable,
  318. bool dapm)
  319. {
  320. int r = 0;
  321. pr_debug("%s: enable = %d\n", __func__, enable);
  322. mutex_lock(&cdc_mclk_mutex);
  323. if (enable) {
  324. clk_users++;
  325. pr_debug("%s: clk_users = %d\n", __func__, clk_users);
  326. if (clk_users == 1) {
  327. if (codec_clk) {
  328. clk_set_rate(codec_clk, TABLA_EXT_CLK_RATE);
  329. clk_prepare_enable(codec_clk);
  330. tabla_mclk_enable(codec, 1, dapm);
  331. } else {
  332. pr_err("%s: Error setting Tabla MCLK\n",
  333. __func__);
  334. clk_users--;
  335. r = -EINVAL;
  336. }
  337. }
  338. } else {
  339. if (clk_users > 0) {
  340. clk_users--;
  341. pr_debug("%s: clk_users = %d\n", __func__, clk_users);
  342. if (clk_users == 0) {
  343. pr_debug("%s: disabling MCLK. clk_users = %d\n",
  344. __func__, clk_users);
  345. tabla_mclk_enable(codec, 0, dapm);
  346. clk_disable_unprepare(codec_clk);
  347. }
  348. } else {
  349. pr_err("%s: Error releasing Tabla MCLK\n", __func__);
  350. r = -EINVAL;
  351. }
  352. }
  353. mutex_unlock(&cdc_mclk_mutex);
  354. return r;
  355. }
  356. static int msm_mclk_event(struct snd_soc_dapm_widget *w,
  357. struct snd_kcontrol *kcontrol, int event)
  358. {
  359. pr_debug("%s: event = %d\n", __func__, event);
  360. switch (event) {
  361. case SND_SOC_DAPM_PRE_PMU:
  362. clk_users++;
  363. pr_debug("%s: clk_users = %d\n", __func__, clk_users);
  364. if (clk_users != 1)
  365. return 0;
  366. if (codec_clk) {
  367. clk_set_rate(codec_clk, 12288000);
  368. clk_prepare_enable(codec_clk);
  369. tabla_mclk_enable(w->codec, 1, true);
  370. } else {
  371. pr_err("%s: Error setting Tabla MCLK\n", __func__);
  372. clk_users--;
  373. return -EINVAL;
  374. }
  375. break;
  376. case SND_SOC_DAPM_POST_PMD:
  377. pr_debug("%s: clk_users = %d\n", __func__, clk_users);
  378. if (clk_users == 0)
  379. return 0;
  380. clk_users--;
  381. if (!clk_users) {
  382. pr_debug("%s: disabling MCLK. clk_users = %d\n",
  383. __func__, clk_users);
  384. tabla_mclk_enable(w->codec, 0, true);
  385. clk_disable_unprepare(codec_clk);
  386. }
  387. break;
  388. }
  389. return 0;
  390. }
  391. static const struct snd_soc_dapm_widget apq8064_dapm_widgets[] = {
  392. SND_SOC_DAPM_SUPPLY("MCLK", SND_SOC_NOPM, 0, 0,
  393. msm_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  394. SND_SOC_DAPM_SPK("Ext Spk Bottom Pos", msm_spkramp_event),
  395. SND_SOC_DAPM_SPK("Ext Spk Bottom Neg", msm_spkramp_event),
  396. SND_SOC_DAPM_SPK("Ext Spk Top Pos", msm_spkramp_event),
  397. SND_SOC_DAPM_SPK("Ext Spk Top Neg", msm_spkramp_event),
  398. SND_SOC_DAPM_SPK("Ext Spk Top", msm_spkramp_event),
  399. /************ Analog MICs ************/
  400. /**
  401. * Analog mic7 (Front Top) on Liquid.
  402. * Used as Handset mic on CDP.
  403. */
  404. SND_SOC_DAPM_MIC("Analog mic7", NULL),
  405. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  406. SND_SOC_DAPM_MIC("ANCRight Headset Mic", NULL),
  407. SND_SOC_DAPM_MIC("ANCLeft Headset Mic", NULL),
  408. /*********** Digital Mics ***************/
  409. SND_SOC_DAPM_MIC("Digital Mic1", NULL),
  410. SND_SOC_DAPM_MIC("Digital Mic2", NULL),
  411. SND_SOC_DAPM_MIC("Digital Mic3", NULL),
  412. SND_SOC_DAPM_MIC("Digital Mic4", NULL),
  413. SND_SOC_DAPM_MIC("Digital Mic5", NULL),
  414. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  415. };
  416. static const struct snd_soc_dapm_route apq8064_common_audio_map[] = {
  417. {"RX_BIAS", NULL, "MCLK"},
  418. {"LDO_H", NULL, "MCLK"},
  419. {"HEADPHONE", NULL, "LDO_H"},
  420. /* Speaker path */
  421. {"Ext Spk Bottom Pos", NULL, "LINEOUT1"},
  422. {"Ext Spk Bottom Neg", NULL, "LINEOUT3"},
  423. {"Ext Spk Top Pos", NULL, "LINEOUT2"},
  424. {"Ext Spk Top Neg", NULL, "LINEOUT4"},
  425. {"Ext Spk Top", NULL, "LINEOUT5"},
  426. /************ Analog MIC Paths ************/
  427. /* Headset Mic */
  428. {"AMIC2", NULL, "MIC BIAS2 External"},
  429. {"MIC BIAS2 External", NULL, "Headset Mic"},
  430. /* Headset ANC microphones */
  431. {"AMIC3", NULL, "MIC BIAS3 Internal1"},
  432. {"MIC BIAS3 Internal1", NULL, "ANCRight Headset Mic"},
  433. {"AMIC4", NULL, "MIC BIAS1 Internal2"},
  434. {"MIC BIAS1 Internal2", NULL, "ANCLeft Headset Mic"},
  435. };
  436. static const struct snd_soc_dapm_route apq8064_mtp_audio_map[] = {
  437. /************ Digital MIC Paths ************/
  438. /*
  439. * Digital Mic1 (Front bottom Left) on MTP.
  440. * Conncted to DMIC1 Input on Tabla codec.
  441. */
  442. {"DMIC1", NULL, "MIC BIAS1 External"},
  443. {"MIC BIAS1 External", NULL, "Digital Mic1"},
  444. /**
  445. * Digital Mic2 (Front bottom right) on MTP.
  446. * Conncted to DMIC2 Input on Tabla codec.
  447. */
  448. {"DMIC2", NULL, "MIC BIAS1 External"},
  449. {"MIC BIAS1 External", NULL, "Digital Mic2"},
  450. /**
  451. * Digital Mic3 (Back bottom) on MTP.
  452. * Conncted to DMIC3 Input on Tabla codec.
  453. */
  454. {"DMIC3", NULL, "MIC BIAS3 External"},
  455. {"MIC BIAS3 External", NULL, "Digital Mic3"},
  456. /**
  457. * Digital Mic4 (Back top) on MTP.
  458. * Conncted to DMIC4 Input on Tabla codec.
  459. */
  460. {"DMIC4", NULL, "MIC BIAS3 External"},
  461. {"MIC BIAS3 External", NULL, "Digital Mic4"},
  462. /**
  463. * Digital Mic5 (Top front Mic) on MTP.
  464. * Conncted to DMIC6 Input on Tabla codec.
  465. */
  466. {"DMIC6", NULL, "MIC BIAS4 External"},
  467. {"MIC BIAS4 External", NULL, "Digital Mic5"},
  468. };
  469. static const struct snd_soc_dapm_route apq8064_liquid_cdp_audio_map[] = {
  470. /************ Analog MIC Paths ************/
  471. /**
  472. * Analog mic7 (Front Top Mic) on Liquid.
  473. * Used as Handset mic on CDP.
  474. * Not there on MTP.
  475. */
  476. {"AMIC1", NULL, "MIC BIAS1 External"},
  477. {"MIC BIAS1 External", NULL, "Analog mic7"},
  478. /************ Digital MIC Paths ************/
  479. /**
  480. * The digital Mic routes are setup considering
  481. * Liquid as default device.
  482. */
  483. /**
  484. * Digital Mic1 (Front bottom left corner) on Liquid.
  485. * Digital Mic2 (Front bottom right) on MTP.
  486. * Digital Mic GM1 on CDP mainboard.
  487. * Conncted to DMIC2 Input on Tabla codec.
  488. */
  489. {"DMIC2", NULL, "MIC BIAS1 External"},
  490. {"MIC BIAS1 External", NULL, "Digital Mic1"},
  491. /**
  492. * Digital Mic2 (Front left side) on Liquid.
  493. * Digital Mic GM2 on CDP mainboard.
  494. * Not there on MTP.
  495. * Conncted to DMIC3 Input on Tabla codec.
  496. */
  497. {"DMIC3", NULL, "MIC BIAS3 External"},
  498. {"MIC BIAS3 External", NULL, "Digital Mic2"},
  499. /**
  500. * Digital Mic3. Front bottom left of middle on Liquid.
  501. * Digital Mic5 (Top front Mic) on MTP.
  502. * Digital Mic GM5 on CDP mainboard.
  503. * Conncted to DMIC6 Input on Tabla codec.
  504. */
  505. {"DMIC6", NULL, "MIC BIAS4 External"},
  506. {"MIC BIAS4 External", NULL, "Digital Mic3"},
  507. /**
  508. * Digital Mic4. Back bottom on Liquid.
  509. * Digital Mic GM3 on CDP mainboard.
  510. * Top Front Mic on MTP.
  511. * Conncted to DMIC5 Input on Tabla codec.
  512. */
  513. {"DMIC5", NULL, "MIC BIAS4 External"},
  514. {"MIC BIAS4 External", NULL, "Digital Mic4"},
  515. /**
  516. * Digital Mic5. Front bottom right of middle on Liquid.
  517. * Digital Mic GM6 on CDP mainboard.
  518. * Not there on MTP.
  519. * Conncted to DMIC4 Input on Tabla codec.
  520. */
  521. {"DMIC4", NULL, "MIC BIAS3 External"},
  522. {"MIC BIAS3 External", NULL, "Digital Mic5"},
  523. /* Digital Mic6 (Front bottom right corner) on Liquid.
  524. * Digital Mic1 (Front bottom Left) on MTP.
  525. * Digital Mic GM4 on CDP.
  526. * Conncted to DMIC1 Input on Tabla codec.
  527. */
  528. {"DMIC1", NULL, "MIC BIAS1 External"},
  529. {"MIC BIAS1 External", NULL, "Digital Mic6"},
  530. };
  531. static const char *spk_function[] = {"Off", "On"};
  532. static const char *slim0_rx_ch_text[] = {"One", "Two"};
  533. static const char *slim0_tx_ch_text[] = {"One", "Two", "Three", "Four"};
  534. static const char * const hdmi_rate[] = {"Default", "Variable"};
  535. static const struct soc_enum msm_enum[] = {
  536. SOC_ENUM_SINGLE_EXT(2, spk_function),
  537. SOC_ENUM_SINGLE_EXT(2, slim0_rx_ch_text),
  538. SOC_ENUM_SINGLE_EXT(4, slim0_tx_ch_text),
  539. SOC_ENUM_SINGLE_EXT(2, hdmi_rate),
  540. };
  541. static const char * const slim1_rate_text[] = {"8000", "16000", "48000"};
  542. static const struct soc_enum msm_slim_1_rate_enum[] = {
  543. SOC_ENUM_SINGLE_EXT(3, slim1_rate_text),
  544. };
  545. static const char * const slim1_tx_ch_text[] = {"One", "Two"};
  546. static const struct soc_enum msm_slim_1_tx_ch_enum[] = {
  547. SOC_ENUM_SINGLE_EXT(2, slim1_tx_ch_text),
  548. };
  549. static int msm_slim_0_rx_ch_get(struct snd_kcontrol *kcontrol,
  550. struct snd_ctl_elem_value *ucontrol)
  551. {
  552. pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
  553. msm_slim_0_rx_ch);
  554. ucontrol->value.integer.value[0] = msm_slim_0_rx_ch - 1;
  555. return 0;
  556. }
  557. static int msm_slim_0_rx_ch_put(struct snd_kcontrol *kcontrol,
  558. struct snd_ctl_elem_value *ucontrol)
  559. {
  560. msm_slim_0_rx_ch = ucontrol->value.integer.value[0] + 1;
  561. pr_debug("%s: msm_slim_0_rx_ch = %d\n", __func__,
  562. msm_slim_0_rx_ch);
  563. return 1;
  564. }
  565. static int msm_slim_0_tx_ch_get(struct snd_kcontrol *kcontrol,
  566. struct snd_ctl_elem_value *ucontrol)
  567. {
  568. pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
  569. msm_slim_0_tx_ch);
  570. ucontrol->value.integer.value[0] = msm_slim_0_tx_ch - 1;
  571. return 0;
  572. }
  573. static int msm_slim_0_tx_ch_put(struct snd_kcontrol *kcontrol,
  574. struct snd_ctl_elem_value *ucontrol)
  575. {
  576. msm_slim_0_tx_ch = ucontrol->value.integer.value[0] + 1;
  577. pr_debug("%s: msm_slim_0_tx_ch = %d\n", __func__,
  578. msm_slim_0_tx_ch);
  579. return 1;
  580. }
  581. static int msm_slim_1_tx_ch_get(struct snd_kcontrol *kcontrol,
  582. struct snd_ctl_elem_value *ucontrol)
  583. {
  584. pr_debug("%s: msm_slim_1_tx_ch = %d\n", __func__,
  585. msm_slim_1_tx_ch);
  586. ucontrol->value.integer.value[0] = msm_slim_1_tx_ch - 1;
  587. return 0;
  588. }
  589. static int msm_slim_1_tx_ch_put(struct snd_kcontrol *kcontrol,
  590. struct snd_ctl_elem_value *ucontrol)
  591. {
  592. msm_slim_1_tx_ch = ucontrol->value.integer.value[0] + 1;
  593. pr_debug("%s: msm_slim_1_tx_ch = %d\n", __func__,
  594. msm_slim_1_tx_ch);
  595. return 1;
  596. }
  597. static int msm_slim_3_rx_ch_get(struct snd_kcontrol *kcontrol,
  598. struct snd_ctl_elem_value *ucontrol)
  599. {
  600. pr_debug("%s: msm_slim_3_rx_ch = %d\n", __func__,
  601. msm_slim_3_rx_ch);
  602. ucontrol->value.integer.value[0] = msm_slim_3_rx_ch - 1;
  603. return 0;
  604. }
  605. static int msm_slim_3_rx_ch_put(struct snd_kcontrol *kcontrol,
  606. struct snd_ctl_elem_value *ucontrol)
  607. {
  608. msm_slim_3_rx_ch = ucontrol->value.integer.value[0] + 1;
  609. pr_debug("%s: msm_slim_3_rx_ch = %d\n", __func__,
  610. msm_slim_3_rx_ch);
  611. return 1;
  612. }
  613. static int msm_slim_1_rate_get(struct snd_kcontrol *kcontrol,
  614. struct snd_ctl_elem_value *ucontrol)
  615. {
  616. pr_debug("%s: msm_slim_1_rate = %d", __func__,
  617. msm_slim_1_rate);
  618. ucontrol->value.integer.value[0] = msm_slim_1_rate;
  619. return 0;
  620. }
  621. static int msm_slim_1_rate_put(struct snd_kcontrol *kcontrol,
  622. struct snd_ctl_elem_value *ucontrol)
  623. {
  624. switch (ucontrol->value.integer.value[0]) {
  625. case 8000:
  626. msm_slim_1_rate = SAMPLE_RATE_8KHZ;
  627. break;
  628. case 16000:
  629. msm_slim_1_rate = SAMPLE_RATE_16KHZ;
  630. break;
  631. case 48000:
  632. msm_slim_1_rate = SAMPLE_RATE_48KHZ;
  633. break;
  634. default:
  635. msm_slim_1_rate = SAMPLE_RATE_8KHZ;
  636. break;
  637. }
  638. pr_debug("%s: msm_slim_1_rate = %d\n", __func__,
  639. msm_slim_1_rate);
  640. return 0;
  641. }
  642. static int msm_incall_rec_mode_get(struct snd_kcontrol *kcontrol,
  643. struct snd_ctl_elem_value *ucontrol)
  644. {
  645. ucontrol->value.integer.value[0] = rec_mode;
  646. return 0;
  647. }
  648. static int msm_incall_rec_mode_put(struct snd_kcontrol *kcontrol,
  649. struct snd_ctl_elem_value *ucontrol)
  650. {
  651. rec_mode = ucontrol->value.integer.value[0];
  652. pr_debug("%s: rec_mode:%d\n", __func__, rec_mode);
  653. return 0;
  654. }
  655. static int msm_hdmi_rate_put(struct snd_kcontrol *kcontrol,
  656. struct snd_ctl_elem_value *ucontrol)
  657. {
  658. hdmi_rate_variable = ucontrol->value.integer.value[0];
  659. pr_debug("%s: hdmi_rate_variable = %d\n", __func__, hdmi_rate_variable);
  660. return 0;
  661. }
  662. static int msm_hdmi_rate_get(struct snd_kcontrol *kcontrol,
  663. struct snd_ctl_elem_value *ucontrol)
  664. {
  665. ucontrol->value.integer.value[0] = hdmi_rate_variable;
  666. return 0;
  667. }
  668. static const struct snd_kcontrol_new tabla_msm_controls[] = {
  669. SOC_ENUM_EXT("Speaker Function", msm_enum[0], msm_get_spk,
  670. msm_set_spk),
  671. SOC_ENUM_EXT("SLIM_0_RX Channels", msm_enum[1],
  672. msm_slim_0_rx_ch_get, msm_slim_0_rx_ch_put),
  673. SOC_ENUM_EXT("SLIM_0_TX Channels", msm_enum[2],
  674. msm_slim_0_tx_ch_get, msm_slim_0_tx_ch_put),
  675. SOC_ENUM_EXT("SLIM_1_TX Channels", msm_slim_1_tx_ch_enum[0],
  676. msm_slim_1_tx_ch_get, msm_slim_1_tx_ch_put),
  677. SOC_ENUM_EXT("SLIM_1 SampleRate", msm_slim_1_rate_enum[0],
  678. msm_slim_1_rate_get, msm_slim_1_rate_put),
  679. SOC_SINGLE_EXT("Incall Rec Mode", SND_SOC_NOPM, 0, 1, 0,
  680. msm_incall_rec_mode_get, msm_incall_rec_mode_put),
  681. SOC_ENUM_EXT("SLIM_3_RX Channels", msm_enum[1],
  682. msm_slim_3_rx_ch_get, msm_slim_3_rx_ch_put),
  683. SOC_ENUM_EXT("HDMI RX Rate", msm_enum[3],
  684. msm_hdmi_rate_get,
  685. msm_hdmi_rate_put),
  686. };
  687. static void *def_tabla_mbhc_cal(void)
  688. {
  689. void *tabla_cal;
  690. struct tabla_mbhc_btn_detect_cfg *btn_cfg;
  691. u16 *btn_low, *btn_high;
  692. u8 *n_ready, *n_cic, *gain;
  693. tabla_cal = kzalloc(TABLA_MBHC_CAL_SIZE(TABLA_MBHC_DEF_BUTTONS,
  694. TABLA_MBHC_DEF_RLOADS),
  695. GFP_KERNEL);
  696. if (!tabla_cal) {
  697. pr_err("%s: out of memory\n", __func__);
  698. return NULL;
  699. }
  700. #define S(X, Y) ((TABLA_MBHC_CAL_GENERAL_PTR(tabla_cal)->X) = (Y))
  701. S(t_ldoh, 100);
  702. S(t_bg_fast_settle, 100);
  703. S(t_shutdown_plug_rem, 255);
  704. S(mbhc_nsa, 4);
  705. S(mbhc_navg, 4);
  706. #undef S
  707. #define S(X, Y) ((TABLA_MBHC_CAL_PLUG_DET_PTR(tabla_cal)->X) = (Y))
  708. S(mic_current, TABLA_PID_MIC_5_UA);
  709. S(hph_current, TABLA_PID_MIC_5_UA);
  710. S(t_mic_pid, 100);
  711. S(t_ins_complete, 250);
  712. S(t_ins_retry, 200);
  713. #undef S
  714. #define S(X, Y) ((TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla_cal)->X) = (Y))
  715. S(v_no_mic, 30);
  716. S(v_hs_max, 2400);
  717. #undef S
  718. #define S(X, Y) ((TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal)->X) = (Y))
  719. S(c[0], 62);
  720. S(c[1], 124);
  721. S(nc, 1);
  722. S(n_meas, 3);
  723. S(mbhc_nsc, 11);
  724. S(n_btn_meas, 1);
  725. S(n_btn_con, 2);
  726. S(num_btn, TABLA_MBHC_DEF_BUTTONS);
  727. S(v_btn_press_delta_sta, 100);
  728. S(v_btn_press_delta_cic, 50);
  729. #undef S
  730. btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(tabla_cal);
  731. btn_low = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_LOW);
  732. btn_high = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_V_BTN_HIGH);
  733. btn_low[0] = -50;
  734. btn_high[0] = 20;
  735. btn_low[1] = 21;
  736. btn_high[1] = 62;
  737. btn_low[2] = 62;
  738. btn_high[2] = 104;
  739. btn_low[3] = 105;
  740. btn_high[3] = 143;
  741. btn_low[4] = 144;
  742. btn_high[4] = 181;
  743. btn_low[5] = 182;
  744. btn_high[5] = 218;
  745. btn_low[6] = 219;
  746. btn_high[6] = 254;
  747. btn_low[7] = 255;
  748. btn_high[7] = 330;
  749. n_ready = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_READY);
  750. n_ready[0] = 80;
  751. n_ready[1] = 68;
  752. n_cic = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_N_CIC);
  753. n_cic[0] = 60;
  754. n_cic[1] = 47;
  755. gain = tabla_mbhc_cal_btn_det_mp(btn_cfg, TABLA_BTN_DET_GAIN);
  756. gain[0] = 11;
  757. gain[1] = 9;
  758. return tabla_cal;
  759. }
  760. static int msm_hw_params(struct snd_pcm_substream *substream,
  761. struct snd_pcm_hw_params *params)
  762. {
  763. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  764. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  765. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  766. int ret = 0;
  767. unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  768. unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
  769. unsigned int num_tx_ch = 0;
  770. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  771. pr_debug("%s: rx_0_ch=%d\n", __func__, msm_slim_0_rx_ch);
  772. ret = snd_soc_dai_get_channel_map(codec_dai,
  773. &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
  774. if (ret < 0) {
  775. pr_err("%s: failed to get codec chan map\n", __func__);
  776. goto end;
  777. }
  778. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  779. msm_slim_0_rx_ch, rx_ch);
  780. if (ret < 0) {
  781. pr_err("%s: failed to set cpu chan map\n", __func__);
  782. goto end;
  783. }
  784. } else {
  785. pr_debug("%s: %s_tx_dai_id_%d_ch=%d\n", __func__,
  786. codec_dai->name, codec_dai->id, num_tx_ch);
  787. ret = snd_soc_dai_get_channel_map(codec_dai,
  788. &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
  789. if (ret < 0) {
  790. pr_err("%s: failed to get codec chan map\n", __func__);
  791. goto end;
  792. }
  793. /* For tabla_tx1 case */
  794. if (codec_dai->id == 1)
  795. num_tx_ch = msm_slim_0_tx_ch;
  796. /* For tabla_tx3 case */
  797. else if (codec_dai->id == 4) {
  798. /* DAI 5 is used for external EC reference from codec.
  799. * Since Rx is fed as reference for EC, the config of
  800. * this DAI is based on that of the Rx path.
  801. */
  802. num_tx_ch = msm_slim_0_rx_ch;
  803. } else {
  804. num_tx_ch = tx_ch_cnt;
  805. }
  806. ret = snd_soc_dai_set_channel_map(cpu_dai,
  807. num_tx_ch, tx_ch, 0 , 0);
  808. if (ret < 0) {
  809. pr_err("%s: failed to set cpu chan map\n", __func__);
  810. goto end;
  811. }
  812. }
  813. end:
  814. return ret;
  815. }
  816. static int msm_stubrx_init(struct snd_soc_pcm_runtime *rtd)
  817. {
  818. rtd->pmdown_time = 0;
  819. return 0;
  820. }
  821. static int msm_slimbus_2_hw_params(struct snd_pcm_substream *substream,
  822. struct snd_pcm_hw_params *params)
  823. {
  824. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  825. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  826. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  827. int ret = 0;
  828. unsigned int rx_ch[SLIM_MAX_RX_PORTS], tx_ch[SLIM_MAX_TX_PORTS];
  829. unsigned int rx_ch_cnt = 0, tx_ch_cnt = 0;
  830. unsigned int num_tx_ch = 0;
  831. unsigned int num_rx_ch = 0;
  832. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  833. num_rx_ch = params_channels(params);
  834. pr_debug("%s: %s rx_dai_id = %d num_ch = %d\n", __func__,
  835. codec_dai->name, codec_dai->id, num_rx_ch);
  836. ret = snd_soc_dai_get_channel_map(codec_dai,
  837. &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
  838. if (ret < 0) {
  839. pr_err("%s: failed to get codec chan map\n", __func__);
  840. goto end;
  841. }
  842. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  843. num_rx_ch, rx_ch);
  844. if (ret < 0) {
  845. pr_err("%s: failed to set cpu chan map\n", __func__);
  846. goto end;
  847. }
  848. } else {
  849. num_tx_ch = params_channels(params);
  850. pr_debug("%s: %s tx_dai_id = %d num_ch = %d\n", __func__,
  851. codec_dai->name, codec_dai->id, num_tx_ch);
  852. ret = snd_soc_dai_get_channel_map(codec_dai,
  853. &tx_ch_cnt, tx_ch, &rx_ch_cnt , rx_ch);
  854. if (ret < 0) {
  855. pr_err("%s: failed to get codec chan map\n", __func__);
  856. goto end;
  857. }
  858. ret = snd_soc_dai_set_channel_map(cpu_dai,
  859. num_tx_ch, tx_ch, 0 , 0);
  860. if (ret < 0) {
  861. pr_err("%s: failed to set cpu chan map\n", __func__);
  862. goto end;
  863. }
  864. }
  865. end:
  866. return ret;
  867. }
  868. static int msm_slimbus_1_hw_params(struct snd_pcm_substream *substream,
  869. struct snd_pcm_hw_params *params)
  870. {
  871. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  872. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  873. int ret = 0;
  874. unsigned int rx_ch = SLIM_1_RX_1, tx_ch[2] = {SLIM_1_TX_1, SLIM_1_TX_2};
  875. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  876. pr_debug("%s: APQ BT/USB TX -> SLIMBUS_1_RX -> MDM TX shared ch %d\n",
  877. __func__, rx_ch);
  878. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
  879. if (ret < 0) {
  880. pr_err("%s: Erorr %d setting SLIM_1 RX channel map\n",
  881. __func__, ret);
  882. goto end;
  883. }
  884. } else {
  885. pr_debug("%s: MDM RX ->SLIMBUS_1_TX ->APQ BT/USB Rx shared ch %d %d\n",
  886. __func__, tx_ch[0], tx_ch[1]);
  887. ret = snd_soc_dai_set_channel_map(cpu_dai, msm_slim_1_tx_ch,
  888. tx_ch, 0, 0);
  889. if (ret < 0) {
  890. pr_err("%s: Erorr %d setting SLIM_1 TX channel map\n",
  891. __func__, ret);
  892. goto end;
  893. }
  894. }
  895. end:
  896. return ret;
  897. }
  898. static int msm_slimbus_3_hw_params(struct snd_pcm_substream *substream,
  899. struct snd_pcm_hw_params *params)
  900. {
  901. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  902. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  903. int ret = 0;
  904. unsigned int rx_ch[2] = {SLIM_3_RX_1, SLIM_3_RX_2};
  905. unsigned int tx_ch[2] = {SLIM_3_TX_1, SLIM_3_TX_2};
  906. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  907. pr_debug("%s: slim_3_rx_ch %d, sch %d %d\n",
  908. __func__, msm_slim_3_rx_ch,
  909. rx_ch[0], rx_ch[1]);
  910. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0,
  911. msm_slim_3_rx_ch, rx_ch);
  912. if (ret < 0) {
  913. pr_err("%s: Erorr %d setting SLIM_3 RX channel map\n",
  914. __func__, ret);
  915. goto end;
  916. }
  917. } else {
  918. pr_debug("%s: MDM RX -> SLIMBUS_3_TX -> APQ HDMI ch: %d, %d\n",
  919. __func__, tx_ch[0], tx_ch[1]);
  920. ret = snd_soc_dai_set_channel_map(cpu_dai, 2, tx_ch, 0, 0);
  921. if (ret < 0) {
  922. pr_err("%s: Erorr %d setting SLIM_3 TX channel map\n",
  923. __func__, ret);
  924. goto end;
  925. }
  926. }
  927. end:
  928. return ret;
  929. }
  930. static int msm_slimbus_4_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 *cpu_dai = rtd->cpu_dai;
  935. int ret = 0;
  936. unsigned int rx_ch = SLIM_4_RX_1, tx_ch[2];
  937. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  938. pr_debug("%s: APQ Incall Playback SLIMBUS_4_RX -> MDM TX shared ch %d\n",
  939. __func__, rx_ch);
  940. ret = snd_soc_dai_set_channel_map(cpu_dai, 0, 0, 1, &rx_ch);
  941. if (ret < 0) {
  942. pr_err("%s: Erorr %d setting SLIM_4 RX channel map\n",
  943. __func__, ret);
  944. }
  945. } else {
  946. if (rec_mode == INCALL_REC_STEREO) {
  947. tx_ch[0] = SLIM_4_TX_1;
  948. tx_ch[1] = SLIM_4_TX_2;
  949. ret = snd_soc_dai_set_channel_map(cpu_dai, 2,
  950. tx_ch, 0, 0);
  951. } else {
  952. tx_ch[0] = SLIM_4_TX_1;
  953. ret = snd_soc_dai_set_channel_map(cpu_dai, 1,
  954. tx_ch, 0, 0);
  955. }
  956. pr_debug("%s: Incall Record shared tx_ch[0]:%d, tx_ch[1]:%d\n",
  957. __func__, tx_ch[0], tx_ch[1]);
  958. if (ret < 0) {
  959. pr_err("%s: Erorr %d setting SLIM_4 TX channel map\n",
  960. __func__, ret);
  961. }
  962. }
  963. return ret;
  964. }
  965. static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd)
  966. {
  967. int err;
  968. uint32_t revision;
  969. struct snd_soc_codec *codec = rtd->codec;
  970. struct snd_soc_dapm_context *dapm = &codec->dapm;
  971. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  972. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  973. unsigned int rx_ch[TABLA_RX_MAX] = {138, 139, 140, 141, 142, 143, 144};
  974. unsigned int tx_ch[TABLA_TX_MAX] = {128, 129, 130, 131, 132, 133, 134,
  975. 135, 136, 137};
  976. pr_debug("%s(), dev_name%s\n", __func__, dev_name(cpu_dai->dev));
  977. snd_soc_dapm_new_controls(dapm, apq8064_dapm_widgets,
  978. ARRAY_SIZE(apq8064_dapm_widgets));
  979. snd_soc_dapm_add_routes(dapm, apq8064_common_audio_map,
  980. ARRAY_SIZE(apq8064_common_audio_map));
  981. if (machine_is_apq8064_mtp()) {
  982. snd_soc_dapm_add_routes(dapm, apq8064_mtp_audio_map,
  983. ARRAY_SIZE(apq8064_mtp_audio_map));
  984. } else {
  985. snd_soc_dapm_add_routes(dapm, apq8064_liquid_cdp_audio_map,
  986. ARRAY_SIZE(apq8064_liquid_cdp_audio_map));
  987. }
  988. snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Pos");
  989. snd_soc_dapm_enable_pin(dapm, "Ext Spk Bottom Neg");
  990. snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Pos");
  991. snd_soc_dapm_enable_pin(dapm, "Ext Spk Top Neg");
  992. snd_soc_dapm_sync(dapm);
  993. err = snd_soc_jack_new(codec, "Headset Jack",
  994. (SND_JACK_HEADSET | SND_JACK_LINEOUT |
  995. SND_JACK_OC_HPHL | SND_JACK_OC_HPHR |
  996. SND_JACK_UNSUPPORTED),
  997. &hs_jack);
  998. if (err) {
  999. pr_err("failed to create new jack\n");
  1000. return err;
  1001. }
  1002. err = snd_soc_jack_new(codec, "Button Jack",
  1003. TABLA_JACK_BUTTON_MASK, &button_jack);
  1004. if (err) {
  1005. pr_err("failed to create new jack\n");
  1006. return err;
  1007. }
  1008. codec_clk = clk_get(cpu_dai->dev, "osr_clk");
  1009. /* APQ8064 Rev 1.1 CDP and Liquid have mechanical switch */
  1010. revision = socinfo_get_version();
  1011. if (apq8064_hs_detect_use_gpio != -1) {
  1012. if (apq8064_hs_detect_use_gpio == 1)
  1013. pr_debug("%s: MBHC mechanical is enabled by request\n",
  1014. __func__);
  1015. else if (apq8064_hs_detect_use_gpio == 0)
  1016. pr_debug("%s: MBHC mechanical is disabled by request\n",
  1017. __func__);
  1018. else
  1019. pr_warn("%s: Invalid hs_detect_use_gpio %d\n", __func__,
  1020. apq8064_hs_detect_use_gpio);
  1021. } else if (SOCINFO_VERSION_MAJOR(revision) == 0) {
  1022. pr_warn("%s: Unknown HW revision detected %d.%d\n", __func__,
  1023. SOCINFO_VERSION_MAJOR(revision),
  1024. SOCINFO_VERSION_MINOR(revision));
  1025. } else if ((SOCINFO_VERSION_MAJOR(revision) == 1 &&
  1026. SOCINFO_VERSION_MINOR(revision) >= 1 &&
  1027. (machine_is_apq8064_cdp() ||
  1028. machine_is_apq8064_liquid())) ||
  1029. SOCINFO_VERSION_MAJOR(revision) > 1) {
  1030. pr_debug("%s: MBHC mechanical switch available APQ8064 "
  1031. "detected\n", __func__);
  1032. apq8064_hs_detect_use_gpio = 1;
  1033. }
  1034. if (apq8064_hs_detect_use_gpio == 1) {
  1035. pr_debug("%s: Using MBHC mechanical switch\n", __func__);
  1036. mbhc_cfg.gpio = JACK_DETECT_GPIO;
  1037. mbhc_cfg.gpio_irq = gpio_to_irq(JACK_DETECT_GPIO);
  1038. err = gpio_request(mbhc_cfg.gpio, "MBHC_HS_DETECT");
  1039. if (err < 0) {
  1040. pr_err("%s: gpio_request %d failed %d\n", __func__,
  1041. mbhc_cfg.gpio, err);
  1042. return err;
  1043. }
  1044. gpio_direction_input(JACK_DETECT_GPIO);
  1045. if (apq8064_hs_detect_extn_cable)
  1046. mbhc_cfg.detect_extn_cable = true;
  1047. } else
  1048. pr_debug("%s: Not using MBHC mechanical switch\n", __func__);
  1049. mbhc_cfg.read_fw_bin = apq8064_hs_detect_use_firmware;
  1050. err = tabla_hs_detect(codec, &mbhc_cfg);
  1051. snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  1052. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  1053. return err;
  1054. }
  1055. static int msm_slim_0_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1056. struct snd_pcm_hw_params *params)
  1057. {
  1058. struct snd_interval *rate = hw_param_interval(params,
  1059. SNDRV_PCM_HW_PARAM_RATE);
  1060. struct snd_interval *channels = hw_param_interval(params,
  1061. SNDRV_PCM_HW_PARAM_CHANNELS);
  1062. pr_debug("%s()\n", __func__);
  1063. rate->min = rate->max = 48000;
  1064. channels->min = channels->max = msm_slim_0_rx_ch;
  1065. return 0;
  1066. }
  1067. static int msm_slim_0_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1068. struct snd_pcm_hw_params *params)
  1069. {
  1070. struct snd_interval *rate = hw_param_interval(params,
  1071. SNDRV_PCM_HW_PARAM_RATE);
  1072. struct snd_interval *channels = hw_param_interval(params,
  1073. SNDRV_PCM_HW_PARAM_CHANNELS);
  1074. pr_debug("%s()\n", __func__);
  1075. rate->min = rate->max = 48000;
  1076. channels->min = channels->max = msm_slim_0_tx_ch;
  1077. return 0;
  1078. }
  1079. static int msm_slim_3_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1080. struct snd_pcm_hw_params *params)
  1081. {
  1082. struct snd_interval *rate = hw_param_interval(params,
  1083. SNDRV_PCM_HW_PARAM_RATE);
  1084. struct snd_interval *channels = hw_param_interval(params,
  1085. SNDRV_PCM_HW_PARAM_CHANNELS);
  1086. pr_debug("%s()\n", __func__);
  1087. rate->min = rate->max = 48000;
  1088. channels->min = channels->max = msm_slim_3_rx_ch;
  1089. return 0;
  1090. }
  1091. static int msm_slim_3_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1092. struct snd_pcm_hw_params *params)
  1093. {
  1094. struct snd_interval *rate = hw_param_interval(params,
  1095. SNDRV_PCM_HW_PARAM_RATE);
  1096. struct snd_interval *channels = hw_param_interval(params,
  1097. SNDRV_PCM_HW_PARAM_CHANNELS);
  1098. pr_debug("%s()\n", __func__);
  1099. rate->min = rate->max = 48000;
  1100. channels->min = channels->max = 2;
  1101. return 0;
  1102. }
  1103. static int msm_slim_4_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1104. struct snd_pcm_hw_params *params)
  1105. {
  1106. struct snd_interval *rate = hw_param_interval(params,
  1107. SNDRV_PCM_HW_PARAM_RATE);
  1108. struct snd_interval *channels = hw_param_interval(params,
  1109. SNDRV_PCM_HW_PARAM_CHANNELS);
  1110. pr_debug("%s()\n", __func__);
  1111. rate->min = rate->max = 48000;
  1112. if (rec_mode == INCALL_REC_STEREO)
  1113. channels->min = channels->max = 2;
  1114. else
  1115. channels->min = channels->max = 1;
  1116. pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
  1117. channels->min, channels->max);
  1118. return 0;
  1119. }
  1120. static int msm_slim_4_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1121. struct snd_pcm_hw_params *params)
  1122. {
  1123. struct snd_interval *rate = hw_param_interval(params,
  1124. SNDRV_PCM_HW_PARAM_RATE);
  1125. struct snd_interval *channels = hw_param_interval(params,
  1126. SNDRV_PCM_HW_PARAM_CHANNELS);
  1127. rate->min = rate->max = 48000;
  1128. channels->min = channels->max = 1;
  1129. pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
  1130. channels->min, channels->max);
  1131. return 0;
  1132. }
  1133. static int msm_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1134. struct snd_pcm_hw_params *params)
  1135. {
  1136. struct snd_interval *rate = hw_param_interval(params,
  1137. SNDRV_PCM_HW_PARAM_RATE);
  1138. pr_debug("%s()\n", __func__);
  1139. rate->min = rate->max = 48000;
  1140. return 0;
  1141. }
  1142. static int msm_hdmi_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1143. struct snd_pcm_hw_params *params)
  1144. {
  1145. struct snd_interval *rate = hw_param_interval(params,
  1146. SNDRV_PCM_HW_PARAM_RATE);
  1147. struct snd_interval *channels = hw_param_interval(params,
  1148. SNDRV_PCM_HW_PARAM_CHANNELS);
  1149. pr_debug("%s channels->min %u channels->max %u ()\n", __func__,
  1150. channels->min, channels->max);
  1151. if (channels->max < 2)
  1152. channels->min = channels->max = 2;
  1153. if (!hdmi_rate_variable)
  1154. rate->min = rate->max = 48000;
  1155. return 0;
  1156. }
  1157. static int msm_btsco_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1158. struct snd_pcm_hw_params *params)
  1159. {
  1160. struct snd_interval *rate = hw_param_interval(params,
  1161. SNDRV_PCM_HW_PARAM_RATE);
  1162. struct snd_interval *channels = hw_param_interval(params,
  1163. SNDRV_PCM_HW_PARAM_CHANNELS);
  1164. rate->min = rate->max = msm_slim_1_rate;
  1165. channels->min = channels->max = msm_btsco_ch;
  1166. return 0;
  1167. }
  1168. static int msm_slim_1_rx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1169. struct snd_pcm_hw_params *params)
  1170. {
  1171. struct snd_interval *rate = hw_param_interval(params,
  1172. SNDRV_PCM_HW_PARAM_RATE);
  1173. struct snd_interval *channels = hw_param_interval(params,
  1174. SNDRV_PCM_HW_PARAM_CHANNELS);
  1175. rate->min = rate->max = msm_slim_1_rate;
  1176. channels->min = channels->max = msm_slim_1_rx_ch;
  1177. return 0;
  1178. }
  1179. static int msm_slim_1_tx_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1180. struct snd_pcm_hw_params *params)
  1181. {
  1182. struct snd_interval *rate = hw_param_interval(params,
  1183. SNDRV_PCM_HW_PARAM_RATE);
  1184. struct snd_interval *channels = hw_param_interval(params,
  1185. SNDRV_PCM_HW_PARAM_CHANNELS);
  1186. rate->min = rate->max = msm_slim_1_rate;
  1187. channels->min = channels->max = msm_slim_1_tx_ch;
  1188. return 0;
  1189. }
  1190. static int msm_auxpcm_be_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1191. struct snd_pcm_hw_params *params)
  1192. {
  1193. struct snd_interval *rate = hw_param_interval(params,
  1194. SNDRV_PCM_HW_PARAM_RATE);
  1195. struct snd_interval *channels = hw_param_interval(params,
  1196. SNDRV_PCM_HW_PARAM_CHANNELS);
  1197. /* PCM only supports mono output with 8khz sample rate */
  1198. rate->min = rate->max = 8000;
  1199. channels->min = channels->max = 1;
  1200. return 0;
  1201. }
  1202. static int msm_proxy_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
  1203. struct snd_pcm_hw_params *params)
  1204. {
  1205. struct snd_interval *rate = hw_param_interval(params,
  1206. SNDRV_PCM_HW_PARAM_RATE);
  1207. pr_debug("%s()\n", __func__);
  1208. rate->min = rate->max = 48000;
  1209. return 0;
  1210. }
  1211. static int msm_aux_pcm_get_gpios(void)
  1212. {
  1213. int ret = 0;
  1214. pr_debug("%s\n", __func__);
  1215. ret = gpio_request(GPIO_AUX_PCM_DOUT, "AUX PCM DOUT");
  1216. if (ret < 0) {
  1217. pr_err("%s: Failed to request gpio(%d): AUX PCM DOUT",
  1218. __func__, GPIO_AUX_PCM_DOUT);
  1219. goto fail_dout;
  1220. }
  1221. ret = gpio_request(GPIO_AUX_PCM_DIN, "AUX PCM DIN");
  1222. if (ret < 0) {
  1223. pr_err("%s: Failed to request gpio(%d): AUX PCM DIN",
  1224. __func__, GPIO_AUX_PCM_DIN);
  1225. goto fail_din;
  1226. }
  1227. ret = gpio_request(GPIO_AUX_PCM_SYNC, "AUX PCM SYNC");
  1228. if (ret < 0) {
  1229. pr_err("%s: Failed to request gpio(%d): AUX PCM SYNC",
  1230. __func__, GPIO_AUX_PCM_SYNC);
  1231. goto fail_sync;
  1232. }
  1233. ret = gpio_request(GPIO_AUX_PCM_CLK, "AUX PCM CLK");
  1234. if (ret < 0) {
  1235. pr_err("%s: Failed to request gpio(%d): AUX PCM CLK",
  1236. __func__, GPIO_AUX_PCM_CLK);
  1237. goto fail_clk;
  1238. }
  1239. return 0;
  1240. fail_clk:
  1241. gpio_free(GPIO_AUX_PCM_SYNC);
  1242. fail_sync:
  1243. gpio_free(GPIO_AUX_PCM_DIN);
  1244. fail_din:
  1245. gpio_free(GPIO_AUX_PCM_DOUT);
  1246. fail_dout:
  1247. return ret;
  1248. }
  1249. static int msm_aux_pcm_free_gpios(void)
  1250. {
  1251. gpio_free(GPIO_AUX_PCM_DIN);
  1252. gpio_free(GPIO_AUX_PCM_DOUT);
  1253. gpio_free(GPIO_AUX_PCM_SYNC);
  1254. gpio_free(GPIO_AUX_PCM_CLK);
  1255. return 0;
  1256. }
  1257. static int msm_startup(struct snd_pcm_substream *substream)
  1258. {
  1259. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1260. pr_debug("%s(): dai_link_str_name = %s cpu_dai = %s codec_dai = %s\n",
  1261. __func__, rtd->dai_link->stream_name,
  1262. rtd->dai_link->cpu_dai_name,
  1263. rtd->dai_link->codec_dai_name);
  1264. return 0;
  1265. }
  1266. static int msm_auxpcm_startup(struct snd_pcm_substream *substream)
  1267. {
  1268. int ret = 0;
  1269. pr_debug("%s(): substream = %s, auxpcm_rsc_ref counter = %d\n",
  1270. __func__, substream->name, atomic_read(&auxpcm_rsc_ref));
  1271. if (atomic_inc_return(&auxpcm_rsc_ref) == 1)
  1272. ret = msm_aux_pcm_get_gpios();
  1273. if (ret < 0) {
  1274. pr_err("%s: Aux PCM GPIO request failed\n", __func__);
  1275. return -EINVAL;
  1276. }
  1277. return 0;
  1278. }
  1279. static int msm_slimbus_1_startup(struct snd_pcm_substream *substream)
  1280. {
  1281. struct slim_controller *slim = slim_busnum_to_ctrl(1);
  1282. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  1283. substream->name, substream->stream);
  1284. if (slim != NULL)
  1285. pm_runtime_get_sync(slim->dev.parent);
  1286. return 0;
  1287. }
  1288. static void msm_auxpcm_shutdown(struct snd_pcm_substream *substream)
  1289. {
  1290. pr_debug("%s(): substream = %s, auxpcm_rsc_ref counter = %d\n",
  1291. __func__, substream->name, atomic_read(&auxpcm_rsc_ref));
  1292. if (atomic_dec_return(&auxpcm_rsc_ref) == 0)
  1293. msm_aux_pcm_free_gpios();
  1294. }
  1295. static void msm_shutdown(struct snd_pcm_substream *substream)
  1296. {
  1297. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1298. pr_debug("%s(): dai_link_str_name = %s cpu_dai = %s codec_dai = %s\n",
  1299. __func__, rtd->dai_link->stream_name,
  1300. rtd->dai_link->cpu_dai_name, rtd->dai_link->codec_dai_name);
  1301. }
  1302. static void msm_slimbus_1_shutdown(struct snd_pcm_substream *substream)
  1303. {
  1304. struct slim_controller *slim = slim_busnum_to_ctrl(1);
  1305. pr_debug("%s(): substream = %s stream = %d\n", __func__,
  1306. substream->name, substream->stream);
  1307. if (slim != NULL) {
  1308. pm_runtime_mark_last_busy(slim->dev.parent);
  1309. pm_runtime_put(slim->dev.parent);
  1310. }
  1311. }
  1312. static struct snd_soc_ops msm_be_ops = {
  1313. .startup = msm_startup,
  1314. .hw_params = msm_hw_params,
  1315. .shutdown = msm_shutdown,
  1316. };
  1317. static struct snd_soc_ops msm_auxpcm_be_ops = {
  1318. .startup = msm_auxpcm_startup,
  1319. .shutdown = msm_auxpcm_shutdown,
  1320. };
  1321. static struct snd_soc_ops msm_slimbus_1_be_ops = {
  1322. .startup = msm_slimbus_1_startup,
  1323. .hw_params = msm_slimbus_1_hw_params,
  1324. .shutdown = msm_slimbus_1_shutdown,
  1325. };
  1326. static struct snd_soc_ops msm_slimbus_3_be_ops = {
  1327. .startup = msm_startup,
  1328. .hw_params = msm_slimbus_3_hw_params,
  1329. .shutdown = msm_shutdown,
  1330. };
  1331. static struct snd_soc_ops msm_slimbus_4_be_ops = {
  1332. .startup = msm_startup,
  1333. .hw_params = msm_slimbus_4_hw_params,
  1334. .shutdown = msm_shutdown,
  1335. };
  1336. static struct snd_soc_ops msm_slimbus_2_be_ops = {
  1337. .startup = msm_startup,
  1338. .hw_params = msm_slimbus_2_hw_params,
  1339. .shutdown = msm_shutdown,
  1340. };
  1341. /* Digital audio interface glue - connects codec <---> CPU */
  1342. static struct snd_soc_dai_link msm_dai[] = {
  1343. /* FrontEnd DAI Links */
  1344. {
  1345. .name = "MSM8960 Media1",
  1346. .stream_name = "MultiMedia1",
  1347. .cpu_dai_name = "MultiMedia1",
  1348. .platform_name = "msm-pcm-dsp",
  1349. .dynamic = 1,
  1350. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1351. .codec_dai_name = "snd-soc-dummy-dai",
  1352. .codec_name = "snd-soc-dummy",
  1353. .ignore_suspend = 1,
  1354. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1355. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA1
  1356. },
  1357. {
  1358. .name = "MSM8960 Media2",
  1359. .stream_name = "MultiMedia2",
  1360. .cpu_dai_name = "MultiMedia2",
  1361. .platform_name = "msm-multi-ch-pcm-dsp",
  1362. .dynamic = 1,
  1363. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1364. .codec_dai_name = "snd-soc-dummy-dai",
  1365. .codec_name = "snd-soc-dummy",
  1366. .ignore_suspend = 1,
  1367. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1368. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA2,
  1369. },
  1370. {
  1371. .name = "Circuit-Switch Voice",
  1372. .stream_name = "CS-Voice",
  1373. .cpu_dai_name = "CS-VOICE",
  1374. .platform_name = "msm-pcm-voice",
  1375. .dynamic = 1,
  1376. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1377. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1378. .ignore_suspend = 1,
  1379. .codec_dai_name = "snd-soc-dummy-dai",
  1380. .codec_name = "snd-soc-dummy",
  1381. .ignore_suspend = 1,
  1382. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1383. .be_id = MSM_FRONTEND_DAI_CS_VOICE,
  1384. },
  1385. {
  1386. .name = "MSM VoIP",
  1387. .stream_name = "VoIP",
  1388. .cpu_dai_name = "VoIP",
  1389. .platform_name = "msm-voip-dsp",
  1390. .dynamic = 1,
  1391. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1392. .codec_dai_name = "snd-soc-dummy-dai",
  1393. .codec_name = "snd-soc-dummy",
  1394. .ignore_suspend = 1,
  1395. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1396. .be_id = MSM_FRONTEND_DAI_VOIP,
  1397. },
  1398. {
  1399. .name = "MSM8960 LPA",
  1400. .stream_name = "LPA",
  1401. .cpu_dai_name = "MultiMedia3",
  1402. .platform_name = "msm-pcm-lpa",
  1403. .dynamic = 1,
  1404. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1405. .codec_dai_name = "snd-soc-dummy-dai",
  1406. .codec_name = "snd-soc-dummy",
  1407. .ignore_suspend = 1,
  1408. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1409. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA3,
  1410. },
  1411. /* Hostless PMC purpose */
  1412. {
  1413. .name = "SLIMBUS_0 Hostless",
  1414. .stream_name = "SLIMBUS_0 Hostless",
  1415. .cpu_dai_name = "SLIMBUS0_HOSTLESS",
  1416. .platform_name = "msm-pcm-hostless",
  1417. .dynamic = 1,
  1418. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1419. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1420. .ignore_suspend = 1,
  1421. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1422. .codec_dai_name = "snd-soc-dummy-dai",
  1423. .codec_name = "snd-soc-dummy",
  1424. /* .be_id = do not care */
  1425. },
  1426. {
  1427. .name = "INT_FM Hostless",
  1428. .stream_name = "INT_FM Hostless",
  1429. .cpu_dai_name = "INT_FM_HOSTLESS",
  1430. .platform_name = "msm-pcm-hostless",
  1431. .dynamic = 1,
  1432. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1433. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1434. .ignore_suspend = 1,
  1435. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1436. .codec_dai_name = "snd-soc-dummy-dai",
  1437. .codec_name = "snd-soc-dummy",
  1438. /* .be_id = do not care */
  1439. },
  1440. {
  1441. .name = "MSM AFE-PCM RX",
  1442. .stream_name = "AFE-PROXY RX",
  1443. .cpu_dai_name = "msm-dai-q6.241",
  1444. .codec_name = "msm-stub-codec.1",
  1445. .codec_dai_name = "msm-stub-rx",
  1446. .platform_name = "msm-pcm-afe",
  1447. .ignore_suspend = 1,
  1448. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1449. },
  1450. {
  1451. .name = "MSM AFE-PCM TX",
  1452. .stream_name = "AFE-PROXY TX",
  1453. .cpu_dai_name = "msm-dai-q6.240",
  1454. .codec_name = "msm-stub-codec.1",
  1455. .codec_dai_name = "msm-stub-tx",
  1456. .platform_name = "msm-pcm-afe",
  1457. .ignore_suspend = 1,
  1458. },
  1459. {
  1460. .name = "MSM8960 Compr",
  1461. .stream_name = "COMPR",
  1462. .cpu_dai_name = "MultiMedia4",
  1463. .platform_name = "msm-compr-dsp",
  1464. .dynamic = 1,
  1465. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1466. .codec_dai_name = "snd-soc-dummy-dai",
  1467. .codec_name = "snd-soc-dummy",
  1468. .ignore_suspend = 1,
  1469. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1470. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA4,
  1471. },
  1472. {
  1473. .name = "AUXPCM Hostless",
  1474. .stream_name = "AUXPCM Hostless",
  1475. .cpu_dai_name = "AUXPCM_HOSTLESS",
  1476. .platform_name = "msm-pcm-hostless",
  1477. .dynamic = 1,
  1478. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1479. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1480. .ignore_suspend = 1,
  1481. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1482. .codec_dai_name = "snd-soc-dummy-dai",
  1483. .codec_name = "snd-soc-dummy",
  1484. },
  1485. /* HDMI Hostless */
  1486. {
  1487. .name = "HDMI_RX_HOSTLESS",
  1488. .stream_name = "HDMI_RX_HOSTLESS",
  1489. .cpu_dai_name = "HDMI_HOSTLESS",
  1490. .platform_name = "msm-pcm-hostless",
  1491. .dynamic = 1,
  1492. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1493. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1494. .codec_dai_name = "snd-soc-dummy-dai",
  1495. .codec_name = "snd-soc-dummy",
  1496. .ignore_suspend = 1,
  1497. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1498. },
  1499. {
  1500. .name = "Voice Stub",
  1501. .stream_name = "Voice Stub",
  1502. .cpu_dai_name = "VOICE_STUB",
  1503. .platform_name = "msm-pcm-hostless",
  1504. .dynamic = 1,
  1505. .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
  1506. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1507. .ignore_suspend = 1,
  1508. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1509. .codec_dai_name = "snd-soc-dummy-dai",
  1510. .codec_name = "snd-soc-dummy",
  1511. },
  1512. {
  1513. .name = "VoLTE Stub",
  1514. .stream_name = "VoLTE Stub",
  1515. .cpu_dai_name = "VOLTE_STUB",
  1516. .platform_name = "msm-pcm-hostless",
  1517. .dynamic = 1,
  1518. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1519. SND_SOC_DPCM_TRIGGER_POST},
  1520. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1521. .ignore_suspend = 1,
  1522. .ignore_pmdown_time = 1,
  1523. .codec_dai_name = "snd-soc-dummy-dai",
  1524. .codec_name = "snd-soc-dummy",
  1525. },
  1526. {
  1527. .name = "MSM8960 LowLatency",
  1528. .stream_name = "MultiMedia5",
  1529. .cpu_dai_name = "MultiMedia5",
  1530. .platform_name = "msm-lowlatency-pcm-dsp",
  1531. .dynamic = 1,
  1532. .codec_dai_name = "snd-soc-dummy-dai",
  1533. .codec_name = "snd-soc-dummy",
  1534. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1535. SND_SOC_DPCM_TRIGGER_POST},
  1536. .ignore_suspend = 1,
  1537. /* this dainlink has playback support */
  1538. .ignore_pmdown_time = 1,
  1539. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA5,
  1540. },
  1541. {
  1542. .name = "MSM8960 Media6",
  1543. .stream_name = "MultiMedia6",
  1544. .cpu_dai_name = "MultiMedia6",
  1545. .platform_name = "msm-multi-ch-pcm-dsp",
  1546. .dynamic = 1,
  1547. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1548. SND_SOC_DPCM_TRIGGER_POST},
  1549. .codec_dai_name = "snd-soc-dummy-dai",
  1550. .codec_name = "snd-soc-dummy",
  1551. .ignore_suspend = 1,
  1552. .ignore_pmdown_time = 1, /* this dailink has playback support */
  1553. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA6
  1554. },
  1555. {
  1556. .name = "MSM8960 Compr2",
  1557. .stream_name = "COMPR2",
  1558. .cpu_dai_name = "MultiMedia7",
  1559. .platform_name = "msm-compr-dsp",
  1560. .dynamic = 1,
  1561. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1562. SND_SOC_DPCM_TRIGGER_POST},
  1563. .codec_dai_name = "snd-soc-dummy-dai",
  1564. .codec_name = "snd-soc-dummy",
  1565. .ignore_suspend = 1,
  1566. .ignore_pmdown_time = 1, /* this dailink has playback support */
  1567. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA7,
  1568. },
  1569. {
  1570. .name = "MSM8960 Compr3",
  1571. .stream_name = "COMPR3",
  1572. .cpu_dai_name = "MultiMedia8",
  1573. .platform_name = "msm-compr-dsp",
  1574. .dynamic = 1,
  1575. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1576. SND_SOC_DPCM_TRIGGER_POST},
  1577. .codec_dai_name = "snd-soc-dummy-dai",
  1578. .codec_name = "snd-soc-dummy",
  1579. .ignore_suspend = 1,
  1580. .ignore_pmdown_time = 1, /* this dailink has playback support */
  1581. .be_id = MSM_FRONTEND_DAI_MULTIMEDIA8,
  1582. },
  1583. {
  1584. .name = "Voice2 Stub",
  1585. .stream_name = "Voice2 Stub",
  1586. .cpu_dai_name = "VOICE2_STUB",
  1587. .platform_name = "msm-pcm-hostless",
  1588. .dynamic = 1,
  1589. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  1590. SND_SOC_DPCM_TRIGGER_POST},
  1591. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1592. .ignore_suspend = 1,
  1593. .ignore_pmdown_time = 1,
  1594. /* this dainlink has playback support */
  1595. .codec_dai_name = "snd-soc-dummy-dai",
  1596. .codec_name = "snd-soc-dummy",
  1597. },
  1598. /* Backend DAI Links */
  1599. {
  1600. .name = LPASS_BE_SLIMBUS_0_RX,
  1601. .stream_name = "Slimbus Playback",
  1602. .cpu_dai_name = "msm-dai-q6.16384",
  1603. .platform_name = "msm-pcm-routing",
  1604. .codec_name = "tabla_codec",
  1605. .codec_dai_name = "tabla_rx1",
  1606. .no_pcm = 1,
  1607. .be_id = MSM_BACKEND_DAI_SLIMBUS_0_RX,
  1608. .init = &msm_audrx_init,
  1609. .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
  1610. .ops = &msm_be_ops,
  1611. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1612. },
  1613. {
  1614. .name = LPASS_BE_SLIMBUS_0_TX,
  1615. .stream_name = "Slimbus Capture",
  1616. .cpu_dai_name = "msm-dai-q6.16385",
  1617. .platform_name = "msm-pcm-routing",
  1618. .codec_name = "tabla_codec",
  1619. .codec_dai_name = "tabla_tx1",
  1620. .no_pcm = 1,
  1621. .be_id = MSM_BACKEND_DAI_SLIMBUS_0_TX,
  1622. .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
  1623. .ops = &msm_be_ops,
  1624. },
  1625. /* Backend BT/FM DAI Links */
  1626. {
  1627. .name = LPASS_BE_INT_BT_SCO_RX,
  1628. .stream_name = "Internal BT-SCO Playback",
  1629. .cpu_dai_name = "msm-dai-q6.12288",
  1630. .platform_name = "msm-pcm-routing",
  1631. .codec_name = "msm-stub-codec.1",
  1632. .codec_dai_name = "msm-stub-rx",
  1633. .no_pcm = 1,
  1634. .be_id = MSM_BACKEND_DAI_INT_BT_SCO_RX,
  1635. .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
  1636. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1637. },
  1638. {
  1639. .name = LPASS_BE_INT_BT_SCO_TX,
  1640. .stream_name = "Internal BT-SCO Capture",
  1641. .cpu_dai_name = "msm-dai-q6.12289",
  1642. .platform_name = "msm-pcm-routing",
  1643. .codec_name = "msm-stub-codec.1",
  1644. .codec_dai_name = "msm-stub-tx",
  1645. .no_pcm = 1,
  1646. .be_id = MSM_BACKEND_DAI_INT_BT_SCO_TX,
  1647. .be_hw_params_fixup = msm_btsco_be_hw_params_fixup,
  1648. },
  1649. {
  1650. .name = LPASS_BE_INT_FM_RX,
  1651. .stream_name = "Internal FM Playback",
  1652. .cpu_dai_name = "msm-dai-q6.12292",
  1653. .platform_name = "msm-pcm-routing",
  1654. .codec_name = "msm-stub-codec.1",
  1655. .codec_dai_name = "msm-stub-rx",
  1656. .no_pcm = 1,
  1657. .be_id = MSM_BACKEND_DAI_INT_FM_RX,
  1658. .be_hw_params_fixup = msm_be_hw_params_fixup,
  1659. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1660. },
  1661. {
  1662. .name = LPASS_BE_INT_FM_TX,
  1663. .stream_name = "Internal FM Capture",
  1664. .cpu_dai_name = "msm-dai-q6.12293",
  1665. .platform_name = "msm-pcm-routing",
  1666. .codec_name = "msm-stub-codec.1",
  1667. .codec_dai_name = "msm-stub-tx",
  1668. .no_pcm = 1,
  1669. .be_id = MSM_BACKEND_DAI_INT_FM_TX,
  1670. .be_hw_params_fixup = msm_be_hw_params_fixup,
  1671. },
  1672. /* HDMI BACK END DAI Link */
  1673. {
  1674. .name = LPASS_BE_HDMI,
  1675. .stream_name = "HDMI Playback",
  1676. .cpu_dai_name = "msm-dai-q6-hdmi.8",
  1677. .platform_name = "msm-pcm-routing",
  1678. .codec_name = "msm-stub-codec.1",
  1679. .codec_dai_name = "msm-stub-rx",
  1680. .no_pcm = 1,
  1681. .be_id = MSM_BACKEND_DAI_HDMI_RX,
  1682. .be_hw_params_fixup = msm_hdmi_be_hw_params_fixup,
  1683. },
  1684. /* Backend AFE DAI Links */
  1685. {
  1686. .name = LPASS_BE_AFE_PCM_RX,
  1687. .stream_name = "AFE Playback",
  1688. .cpu_dai_name = "msm-dai-q6.224",
  1689. .platform_name = "msm-pcm-routing",
  1690. .codec_name = "msm-stub-codec.1",
  1691. .codec_dai_name = "msm-stub-rx",
  1692. .no_pcm = 1,
  1693. .be_id = MSM_BACKEND_DAI_AFE_PCM_RX,
  1694. .be_hw_params_fixup = msm_proxy_be_hw_params_fixup,
  1695. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1696. },
  1697. {
  1698. .name = LPASS_BE_AFE_PCM_TX,
  1699. .stream_name = "AFE Capture",
  1700. .cpu_dai_name = "msm-dai-q6.225",
  1701. .platform_name = "msm-pcm-routing",
  1702. .codec_name = "msm-stub-codec.1",
  1703. .codec_dai_name = "msm-stub-tx",
  1704. .no_pcm = 1,
  1705. .be_id = MSM_BACKEND_DAI_AFE_PCM_TX,
  1706. .be_hw_params_fixup = msm_proxy_be_hw_params_fixup,
  1707. },
  1708. /* AUX PCM Backend DAI Links */
  1709. {
  1710. .name = LPASS_BE_AUXPCM_RX,
  1711. .stream_name = "AUX PCM Playback",
  1712. .cpu_dai_name = "msm-dai-q6.2",
  1713. .platform_name = "msm-pcm-routing",
  1714. .codec_name = "msm-stub-codec.1",
  1715. .codec_dai_name = "msm-stub-rx",
  1716. .no_pcm = 1,
  1717. .be_id = MSM_BACKEND_DAI_AUXPCM_RX,
  1718. .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
  1719. .ops = &msm_auxpcm_be_ops,
  1720. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1721. },
  1722. {
  1723. .name = LPASS_BE_AUXPCM_TX,
  1724. .stream_name = "AUX PCM Capture",
  1725. .cpu_dai_name = "msm-dai-q6.3",
  1726. .platform_name = "msm-pcm-routing",
  1727. .codec_name = "msm-stub-codec.1",
  1728. .codec_dai_name = "msm-stub-tx",
  1729. .no_pcm = 1,
  1730. .be_id = MSM_BACKEND_DAI_AUXPCM_TX,
  1731. .be_hw_params_fixup = msm_auxpcm_be_params_fixup,
  1732. .ops = &msm_auxpcm_be_ops,
  1733. },
  1734. {
  1735. .name = LPASS_BE_STUB_RX,
  1736. .stream_name = "Stub Playback",
  1737. .cpu_dai_name = "msm-dai-stub",
  1738. .platform_name = "msm-pcm-routing",
  1739. .codec_name = "tabla_codec",
  1740. .codec_dai_name = "tabla_rx2",
  1741. .no_pcm = 1,
  1742. .be_id = MSM_BACKEND_DAI_EXTPROC_RX,
  1743. .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
  1744. .init = &msm_stubrx_init,
  1745. .ops = &msm_be_ops,
  1746. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1747. },
  1748. {
  1749. .name = LPASS_BE_STUB_TX,
  1750. .stream_name = "Stub Capture",
  1751. .cpu_dai_name = "msm-dai-stub",
  1752. .platform_name = "msm-pcm-routing",
  1753. .codec_name = "tabla_codec",
  1754. .codec_dai_name = "tabla_tx1",
  1755. .no_pcm = 1,
  1756. .be_id = MSM_BACKEND_DAI_EXTPROC_TX,
  1757. .be_hw_params_fixup = msm_slim_0_tx_be_hw_params_fixup,
  1758. .ops = &msm_be_ops,
  1759. },
  1760. {
  1761. .name = LPASS_BE_SLIMBUS_1_RX,
  1762. .stream_name = "Slimbus1 Playback",
  1763. .cpu_dai_name = "msm-dai-q6.16386",
  1764. .platform_name = "msm-pcm-routing",
  1765. .codec_name = "msm-stub-codec.1",
  1766. .codec_dai_name = "msm-stub-rx",
  1767. .no_pcm = 1,
  1768. .be_id = MSM_BACKEND_DAI_SLIMBUS_1_RX,
  1769. .be_hw_params_fixup = msm_slim_1_rx_be_hw_params_fixup,
  1770. .ops = &msm_slimbus_1_be_ops,
  1771. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1772. },
  1773. {
  1774. .name = LPASS_BE_SLIMBUS_1_TX,
  1775. .stream_name = "Slimbus1 Capture",
  1776. .cpu_dai_name = "msm-dai-q6.16387",
  1777. .platform_name = "msm-pcm-routing",
  1778. .codec_name = "msm-stub-codec.1",
  1779. .codec_dai_name = "msm-stub-tx",
  1780. .no_pcm = 1,
  1781. .be_id = MSM_BACKEND_DAI_SLIMBUS_1_TX,
  1782. .be_hw_params_fixup = msm_slim_1_tx_be_hw_params_fixup,
  1783. .ops = &msm_slimbus_1_be_ops,
  1784. },
  1785. /* Ultrasound TX Back End DAI Link */
  1786. {
  1787. .name = "SLIMBUS_2 Hostless Capture",
  1788. .stream_name = "SLIMBUS_2 Hostless Capture",
  1789. .cpu_dai_name = "msm-dai-q6.16389",
  1790. .platform_name = "msm-pcm-hostless",
  1791. .codec_name = "tabla_codec",
  1792. .codec_dai_name = "tabla_tx2",
  1793. .ignore_suspend = 1,
  1794. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1795. .ops = &msm_slimbus_2_be_ops,
  1796. },
  1797. /* Ultrasound RX Back End DAI Link */
  1798. {
  1799. .name = "SLIMBUS_2 Hostless Playback",
  1800. .stream_name = "SLIMBUS_2 Hostless Playback",
  1801. .cpu_dai_name = "msm-dai-q6.16388",
  1802. .platform_name = "msm-pcm-hostless",
  1803. .codec_name = "tabla_codec",
  1804. .codec_dai_name = "tabla_rx3",
  1805. .ignore_suspend = 1,
  1806. .no_host_mode = SND_SOC_DAI_LINK_NO_HOST,
  1807. .ops = &msm_slimbus_2_be_ops,
  1808. },
  1809. /* Incall Music Back End DAI Link */
  1810. {
  1811. .name = LPASS_BE_SLIMBUS_4_RX,
  1812. .stream_name = "Slimbus4 Playback",
  1813. .cpu_dai_name = "msm-dai-q6.16392",
  1814. .platform_name = "msm-pcm-routing",
  1815. .codec_name = "msm-stub-codec.1",
  1816. .codec_dai_name = "msm-stub-rx",
  1817. .no_pcm = 1,
  1818. .be_id = MSM_BACKEND_DAI_SLIMBUS_4_RX,
  1819. .be_hw_params_fixup = msm_slim_4_rx_be_hw_params_fixup,
  1820. .ops = &msm_slimbus_4_be_ops,
  1821. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1822. },
  1823. /* Incall Record Back End DAI Link */
  1824. {
  1825. .name = LPASS_BE_SLIMBUS_4_TX,
  1826. .stream_name = "Slimbus4 Capture",
  1827. .cpu_dai_name = "msm-dai-q6.16393",
  1828. .platform_name = "msm-pcm-routing",
  1829. .codec_name = "msm-stub-codec.1",
  1830. .codec_dai_name = "msm-stub-tx",
  1831. .no_pcm = 1,
  1832. .be_id = MSM_BACKEND_DAI_SLIMBUS_4_TX,
  1833. .be_hw_params_fixup = msm_slim_4_tx_be_hw_params_fixup,
  1834. .ops = &msm_slimbus_4_be_ops,
  1835. },
  1836. {
  1837. .name = LPASS_BE_STUB_1_TX,
  1838. .stream_name = "Stub1 Capture",
  1839. .cpu_dai_name = "msm-dai-stub",
  1840. .platform_name = "msm-pcm-routing",
  1841. .codec_name = "tabla_codec",
  1842. .codec_dai_name = "tabla_tx3",
  1843. .no_pcm = 1,
  1844. .be_id = MSM_BACKEND_DAI_EXTPROC_EC_TX,
  1845. /* This BE is used for external EC reference from codec. Since
  1846. * Rx is fed as reference for EC, the config of this DAI is
  1847. * based on that of the Rx path.
  1848. */
  1849. .be_hw_params_fixup = msm_slim_0_rx_be_hw_params_fixup,
  1850. .ops = &msm_be_ops,
  1851. },
  1852. {
  1853. .name = LPASS_BE_SLIMBUS_3_RX,
  1854. .stream_name = "Slimbus3 Playback",
  1855. .cpu_dai_name = "msm-dai-q6.16390",
  1856. .platform_name = "msm-pcm-routing",
  1857. .codec_name = "msm-stub-codec.1",
  1858. .codec_dai_name = "msm-stub-rx",
  1859. .no_pcm = 1,
  1860. .be_id = MSM_BACKEND_DAI_SLIMBUS_3_RX,
  1861. .be_hw_params_fixup = msm_slim_3_rx_be_hw_params_fixup,
  1862. .ops = &msm_slimbus_3_be_ops,
  1863. .ignore_pmdown_time = 1, /* this dainlink has playback support */
  1864. },
  1865. {
  1866. .name = LPASS_BE_SLIMBUS_3_TX,
  1867. .stream_name = "Slimbus3 Capture",
  1868. .cpu_dai_name = "msm-dai-q6.16391",
  1869. .platform_name = "msm-pcm-routing",
  1870. .codec_name = "msm-stub-codec.1",
  1871. .codec_dai_name = "msm-stub-tx",
  1872. .no_pcm = 1,
  1873. .be_id = MSM_BACKEND_DAI_SLIMBUS_3_TX,
  1874. .be_hw_params_fixup = msm_slim_3_tx_be_hw_params_fixup,
  1875. .ops = &msm_slimbus_3_be_ops,
  1876. },
  1877. };
  1878. static struct snd_soc_card snd_soc_card_msm = {
  1879. .name = "apq8064-tabla-snd-card",
  1880. .dai_link = msm_dai,
  1881. .num_links = ARRAY_SIZE(msm_dai),
  1882. .controls = tabla_msm_controls,
  1883. .num_controls = ARRAY_SIZE(tabla_msm_controls),
  1884. };
  1885. static struct platform_device *msm_snd_device;
  1886. static int __init msm_audio_init(void)
  1887. {
  1888. int ret;
  1889. u32 version = socinfo_get_platform_version();
  1890. if (!soc_class_is_apq8064() ||
  1891. (socinfo_get_id() == 130) ||
  1892. (machine_is_apq8064_mtp() &&
  1893. (SOCINFO_VERSION_MINOR(version) == 1))) {
  1894. pr_info("%s: Not APQ8064 in SLIMBUS mode\n", __func__);
  1895. return -ENODEV;
  1896. }
  1897. if (socinfo_get_pmic_model() == PMIC_MODEL_PM8917)
  1898. bottom_spk_pamp_gpio = PM8921_GPIO_PM_TO_SYS(16);
  1899. mutex_init(&cdc_mclk_mutex);
  1900. mbhc_cfg.calibration = def_tabla_mbhc_cal();
  1901. if (!mbhc_cfg.calibration) {
  1902. pr_err("Calibration data allocation failed\n");
  1903. return -ENOMEM;
  1904. }
  1905. msm_snd_device = platform_device_alloc("soc-audio", 0);
  1906. if (!msm_snd_device) {
  1907. pr_err("Platform device allocation failed\n");
  1908. kfree(mbhc_cfg.calibration);
  1909. return -ENOMEM;
  1910. }
  1911. platform_set_drvdata(msm_snd_device, &snd_soc_card_msm);
  1912. ret = platform_device_add(msm_snd_device);
  1913. if (ret) {
  1914. platform_device_put(msm_snd_device);
  1915. kfree(mbhc_cfg.calibration);
  1916. return ret;
  1917. }
  1918. atomic_set(&auxpcm_rsc_ref, 0);
  1919. return ret;
  1920. }
  1921. module_init(msm_audio_init);
  1922. static void __exit msm_audio_exit(void)
  1923. {
  1924. if (!soc_class_is_apq8064() || socinfo_get_id() == 130) {
  1925. pr_err("%s: Not the right machine type\n", __func__);
  1926. return ;
  1927. }
  1928. platform_device_unregister(msm_snd_device);
  1929. if (mbhc_cfg.gpio)
  1930. gpio_free(mbhc_cfg.gpio);
  1931. kfree(mbhc_cfg.calibration);
  1932. mutex_destroy(&cdc_mclk_mutex);
  1933. }
  1934. module_exit(msm_audio_exit);
  1935. MODULE_DESCRIPTION("ALSA SoC msm");
  1936. MODULE_LICENSE("GPL v2");