kona.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <linux/io.h>
  12. #include <linux/module.h>
  13. #include <linux/input.h>
  14. #include <linux/of_device.h>
  15. #include <linux/soc/qcom/fsa4480-i2c.h>
  16. #include <sound/control.h>
  17. #include <sound/core.h>
  18. #include <sound/soc.h>
  19. #include <sound/soc-dapm.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/info.h>
  23. #include <soc/snd_event.h>
  24. #include <dsp/audio_prm.h>
  25. #include <soc/swr-common.h>
  26. #include "device_event.h"
  27. #include "asoc/msm-cdc-pinctrl.h"
  28. #include "asoc/wcd-mbhc-v2.h"
  29. #include "codecs/wcd938x/wcd938x-mbhc.h"
  30. #include "codecs/wsa881x.h"
  31. #include "codecs/wcd938x/wcd938x.h"
  32. #include "codecs/bolero/bolero-cdc.h"
  33. #include <dt-bindings/sound/audio-codec-port-types.h>
  34. #include "codecs/bolero/wsa-macro.h"
  35. #include "kona-port-config.h"
  36. #include "msm-audio-defs.h"
  37. #include "msm_common.h"
  38. #define DRV_NAME "kona-asoc-snd"
  39. #define __CHIPSET__ "KONA "
  40. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  41. #define WCD9XXX_MBHC_DEF_RLOADS 5
  42. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  43. #define CODEC_EXT_CLK_RATE 9600000
  44. #define DEV_NAME_STR_LEN 32
  45. #define WCD_MBHC_HS_V_MAX 1600
  46. #define WSA8810_NAME_1 "wsa881x.1020170211"
  47. #define WSA8810_NAME_2 "wsa881x.1020170212"
  48. #define WSA8815_NAME_1 "wsa881x.1021170213"
  49. #define WSA8815_NAME_2 "wsa881x.1021170214"
  50. #define WCN_CDC_SLIM_RX_CH_MAX 2
  51. #define WCN_CDC_SLIM_TX_CH_MAX 2
  52. struct msm_asoc_mach_data {
  53. struct snd_info_entry *codec_root;
  54. struct msm_common_pdata *common_pdata;
  55. int lito_v2_enabled;
  56. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  57. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  58. struct device_node *dmic45_gpio_p; /* used by pinctrl API */
  59. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  60. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  61. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  62. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  63. struct device_node *fsa_handle;
  64. };
  65. struct msm_wsa881x_dev_info {
  66. struct device_node *of_node;
  67. u32 index;
  68. };
  69. struct aux_codec_dev_info {
  70. struct device_node *of_node;
  71. u32 index;
  72. };
  73. static bool is_initial_boot;
  74. static bool codec_reg_done;
  75. static struct snd_soc_aux_dev *msm_aux_dev;
  76. static struct snd_soc_codec_conf *msm_codec_conf;
  77. static struct snd_soc_card snd_soc_card_kona_msm;
  78. static int dmic_0_1_gpio_cnt;
  79. static int dmic_2_3_gpio_cnt;
  80. static int dmic_4_5_gpio_cnt;
  81. static void *def_wcd_mbhc_cal(void);
  82. /*
  83. * Need to report LINEIN
  84. * if R/L channel impedance is larger than 5K ohm
  85. */
  86. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  87. .read_fw_bin = false,
  88. .calibration = NULL,
  89. .detect_extn_cable = true,
  90. .mono_stero_detection = false,
  91. .swap_gnd_mic = NULL,
  92. .hs_ext_micbias = true,
  93. .key_code[0] = KEY_MEDIA,
  94. .key_code[1] = KEY_VOICECOMMAND,
  95. .key_code[2] = KEY_VOLUMEUP,
  96. .key_code[3] = KEY_VOLUMEDOWN,
  97. .key_code[4] = 0,
  98. .key_code[5] = 0,
  99. .key_code[6] = 0,
  100. .key_code[7] = 0,
  101. .linein_th = 5000,
  102. .moisture_en = false,
  103. .mbhc_micbias = MIC_BIAS_2,
  104. .anc_micbias = MIC_BIAS_2,
  105. .enable_anc_mic_detect = false,
  106. .moisture_duty_cycle_en = true,
  107. };
  108. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component, bool active)
  109. {
  110. struct snd_soc_card *card = component->card;
  111. struct msm_asoc_mach_data *pdata =
  112. snd_soc_card_get_drvdata(card);
  113. if (!pdata->fsa_handle)
  114. return false;
  115. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  116. }
  117. static bool msm_swap_gnd_mic(struct snd_soc_component *component, bool active)
  118. {
  119. int value = 0;
  120. bool ret = false;
  121. struct snd_soc_card *card;
  122. struct msm_asoc_mach_data *pdata;
  123. if (!component) {
  124. pr_err("%s component is NULL\n", __func__);
  125. return false;
  126. }
  127. card = component->card;
  128. pdata = snd_soc_card_get_drvdata(card);
  129. if (!pdata)
  130. return false;
  131. if (wcd_mbhc_cfg.enable_usbc_analog)
  132. return msm_usbc_swap_gnd_mic(component, active);
  133. /* if usbc is not defined, swap using us_euro_gpio_p */
  134. if (pdata->us_euro_gpio_p) {
  135. value = msm_cdc_pinctrl_get_state(
  136. pdata->us_euro_gpio_p);
  137. if (value)
  138. msm_cdc_pinctrl_select_sleep_state(
  139. pdata->us_euro_gpio_p);
  140. else
  141. msm_cdc_pinctrl_select_active_state(
  142. pdata->us_euro_gpio_p);
  143. dev_dbg(component->dev, "%s: swap select switch %d to %d\n",
  144. __func__, value, !value);
  145. ret = true;
  146. }
  147. return ret;
  148. }
  149. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  150. struct snd_kcontrol *kcontrol, int event)
  151. {
  152. struct msm_asoc_mach_data *pdata = NULL;
  153. struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  154. int ret = 0;
  155. u32 dmic_idx;
  156. int *dmic_gpio_cnt;
  157. struct device_node *dmic_gpio;
  158. char *wname;
  159. wname = strpbrk(w->name, "012345");
  160. if (!wname) {
  161. dev_err(component->dev, "%s: widget not found\n", __func__);
  162. return -EINVAL;
  163. }
  164. ret = kstrtouint(wname, 10, &dmic_idx);
  165. if (ret < 0) {
  166. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  167. __func__);
  168. return -EINVAL;
  169. }
  170. pdata = snd_soc_card_get_drvdata(component->card);
  171. switch (dmic_idx) {
  172. case 0:
  173. case 1:
  174. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  175. dmic_gpio = pdata->dmic01_gpio_p;
  176. break;
  177. case 2:
  178. case 3:
  179. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  180. dmic_gpio = pdata->dmic23_gpio_p;
  181. break;
  182. case 4:
  183. case 5:
  184. dmic_gpio_cnt = &dmic_4_5_gpio_cnt;
  185. dmic_gpio = pdata->dmic45_gpio_p;
  186. break;
  187. default:
  188. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  189. __func__);
  190. return -EINVAL;
  191. }
  192. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  193. __func__, event, dmic_idx, *dmic_gpio_cnt);
  194. switch (event) {
  195. case SND_SOC_DAPM_PRE_PMU:
  196. (*dmic_gpio_cnt)++;
  197. if (*dmic_gpio_cnt == 1) {
  198. ret = msm_cdc_pinctrl_select_active_state(
  199. dmic_gpio);
  200. if (ret < 0) {
  201. pr_err("%s: gpio set cannot be activated %sd",
  202. __func__, "dmic_gpio");
  203. return ret;
  204. }
  205. }
  206. break;
  207. case SND_SOC_DAPM_POST_PMD:
  208. (*dmic_gpio_cnt)--;
  209. if (*dmic_gpio_cnt == 0) {
  210. ret = msm_cdc_pinctrl_select_sleep_state(
  211. dmic_gpio);
  212. if (ret < 0) {
  213. pr_err("%s: gpio set cannot be de-activated %sd",
  214. __func__, "dmic_gpio");
  215. return ret;
  216. }
  217. }
  218. break;
  219. default:
  220. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  221. return -EINVAL;
  222. }
  223. return 0;
  224. }
  225. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  226. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  227. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  228. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  229. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  230. SND_SOC_DAPM_MIC("Analog Mic5", NULL),
  231. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  232. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  233. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  234. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  235. SND_SOC_DAPM_MIC("Digital Mic4", msm_dmic_event),
  236. SND_SOC_DAPM_MIC("Digital Mic5", msm_dmic_event),
  237. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  238. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  239. };
  240. static int msm_int_audrx_init(struct snd_soc_pcm_runtime *rtd)
  241. {
  242. int ret = 0;
  243. struct snd_soc_component *component;
  244. struct snd_soc_dapm_context *dapm;
  245. struct snd_card *card;
  246. struct snd_info_entry *entry;
  247. struct snd_soc_component *aux_comp;
  248. struct msm_asoc_mach_data *pdata =
  249. snd_soc_card_get_drvdata(rtd->card);
  250. component = snd_soc_rtdcom_lookup(rtd, "bolero_codec");
  251. if (!component) {
  252. ret = -EINVAL;
  253. pr_err("%s: could not find component for bolero_codec\n",
  254. __func__);
  255. return ret;
  256. }
  257. dapm = snd_soc_component_get_dapm(component);
  258. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  259. ARRAY_SIZE(msm_int_dapm_widgets));
  260. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  261. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  262. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  263. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  264. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic4");
  265. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic5");
  266. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic6");
  267. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic7");
  268. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  269. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  270. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  271. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  272. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic5");
  273. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK1 OUT");
  274. snd_soc_dapm_ignore_suspend(dapm, "WSA_SPK2 OUT");
  275. snd_soc_dapm_ignore_suspend(dapm, "WSA AIF VI");
  276. snd_soc_dapm_ignore_suspend(dapm, "VIINPUT_WSA");
  277. snd_soc_dapm_sync(dapm);
  278. /*
  279. * Send speaker configuration only for WSA8810.
  280. * Default configuration is for WSA8815.
  281. */
  282. dev_dbg(component->dev, "%s: Number of aux devices: %d\n",
  283. __func__, rtd->card->num_aux_devs);
  284. if (rtd->card->num_aux_devs &&
  285. !list_empty(&rtd->card->component_dev_list)) {
  286. list_for_each_entry(aux_comp,
  287. &rtd->card->aux_comp_list,
  288. card_aux_list) {
  289. if (aux_comp->name != NULL && (
  290. !strcmp(aux_comp->name, WSA8810_NAME_1) ||
  291. !strcmp(aux_comp->name, WSA8810_NAME_2))) {
  292. wsa_macro_set_spkr_mode(component,
  293. WSA_MACRO_SPKR_MODE_1);
  294. wsa_macro_set_spkr_gain_offset(component,
  295. WSA_MACRO_GAIN_OFFSET_M1P5_DB);
  296. }
  297. }
  298. if (pdata->lito_v2_enabled) {
  299. /*
  300. * Enable tx data line3 for saipan version v2 amd
  301. * write corresponding lpi register.
  302. */
  303. bolero_set_port_map(component, ARRAY_SIZE(sm_port_map_v2),
  304. sm_port_map_v2);
  305. } else {
  306. bolero_set_port_map(component, ARRAY_SIZE(sm_port_map),
  307. sm_port_map);
  308. }
  309. }
  310. card = rtd->card->snd_card;
  311. if (!pdata->codec_root) {
  312. entry = snd_info_create_subdir(card->module, "codecs",
  313. card->proc_root);
  314. if (!entry) {
  315. pr_debug("%s: Cannot create codecs module entry\n",
  316. __func__);
  317. ret = 0;
  318. goto err;
  319. }
  320. pdata->codec_root = entry;
  321. }
  322. bolero_info_create_codec_entry(pdata->codec_root, component);
  323. bolero_register_wake_irq(component, false);
  324. codec_reg_done = true;
  325. msm_common_dai_link_init(rtd);
  326. return 0;
  327. err:
  328. return ret;
  329. }
  330. static void *def_wcd_mbhc_cal(void)
  331. {
  332. void *wcd_mbhc_cal;
  333. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  334. u16 *btn_high;
  335. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  336. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  337. if (!wcd_mbhc_cal)
  338. return NULL;
  339. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  340. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  341. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  342. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  343. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  344. btn_high[0] = 75;
  345. btn_high[1] = 150;
  346. btn_high[2] = 237;
  347. btn_high[3] = 500;
  348. btn_high[4] = 500;
  349. btn_high[5] = 500;
  350. btn_high[6] = 500;
  351. btn_high[7] = 500;
  352. return wcd_mbhc_cal;
  353. }
  354. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  355. {
  356. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  357. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160};
  358. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  359. int ret = 0;
  360. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  361. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  362. if (ret)
  363. return ret;
  364. msm_common_dai_link_init(rtd);
  365. return ret;
  366. }
  367. static struct snd_soc_ops msm_common_be_ops = {
  368. .startup = msm_common_snd_startup,
  369. .shutdown = msm_common_snd_shutdown,
  370. };
  371. /* Digital audio interface glue - connects codec <---> CPU */
  372. static struct snd_soc_dai_link msm_common_dai_links[] = {
  373. {
  374. .name = LPASS_BE_WSA_CDC_DMA_RX_0,
  375. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_0,
  376. .cpu_dai_name = "snd-soc-dummy-dai",
  377. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  378. .dpcm_playback = 1,
  379. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  380. SND_SOC_DPCM_TRIGGER_POST},
  381. .codec_dai_name = "wsa_macro_rx1",
  382. .codec_name = "bolero_codec",
  383. .init = &msm_int_audrx_init,
  384. .ops = &msm_common_be_ops,
  385. .ignore_suspend = 1,
  386. /* this dainlink has playback support */
  387. .ignore_pmdown_time = 1,
  388. },
  389. {
  390. .name = LPASS_BE_WSA_CDC_DMA_RX_1,
  391. .stream_name = LPASS_BE_WSA_CDC_DMA_RX_1,
  392. .cpu_dai_name = "snd-soc-dummy-dai",
  393. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  394. .dpcm_playback = 1,
  395. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  396. SND_SOC_DPCM_TRIGGER_POST},
  397. .codec_dai_name = "wsa_macro_rx_mix",
  398. .codec_name = "bolero_codec",
  399. .ops = &msm_common_be_ops,
  400. .ignore_suspend = 1,
  401. /* this dainlink has playback support */
  402. .ignore_pmdown_time = 1,
  403. },
  404. {
  405. .name = LPASS_BE_WSA_CDC_DMA_TX_1,
  406. .stream_name = LPASS_BE_WSA_CDC_DMA_TX_1,
  407. .cpu_dai_name = "snd-soc-dummy-dai",
  408. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  409. .dpcm_capture = 1,
  410. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  411. SND_SOC_DPCM_TRIGGER_POST},
  412. .codec_dai_name = "wsa_macro_echo",
  413. .codec_name = "bolero_codec",
  414. .ops = &msm_common_be_ops,
  415. .ignore_suspend = 1,
  416. },
  417. {
  418. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  419. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  420. .cpu_dai_name = "snd-soc-dummy-dai",
  421. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  422. .dpcm_playback = 1,
  423. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  424. SND_SOC_DPCM_TRIGGER_POST},
  425. .codec_dai_name = "rx_macro_rx1",
  426. .codec_name = "bolero_codec",
  427. .ops = &msm_common_be_ops,
  428. .ignore_suspend = 1,
  429. /* this dainlink has playback support */
  430. .ignore_pmdown_time = 1,
  431. },
  432. {
  433. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  434. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  435. .cpu_dai_name = "snd-soc-dummy-dai",
  436. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  437. .dpcm_playback = 1,
  438. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  439. SND_SOC_DPCM_TRIGGER_POST},
  440. .codec_dai_name = "rx_macro_rx2",
  441. .codec_name = "bolero_codec",
  442. .ops = &msm_common_be_ops,
  443. .ignore_suspend = 1,
  444. /* this dainlink has playback support */
  445. .ignore_pmdown_time = 1,
  446. },
  447. {
  448. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  449. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  450. .cpu_dai_name = "snd-soc-dummy-dai",
  451. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  452. .dpcm_playback = 1,
  453. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  454. SND_SOC_DPCM_TRIGGER_POST},
  455. .codec_dai_name = "rx_macro_rx3",
  456. .codec_name = "bolero_codec",
  457. .ops = &msm_common_be_ops,
  458. .ignore_suspend = 1,
  459. /* this dainlink has playback support */
  460. .ignore_pmdown_time = 1,
  461. },
  462. {
  463. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  464. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  465. .cpu_dai_name = "snd-soc-dummy-dai",
  466. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  467. .dpcm_playback = 1,
  468. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  469. SND_SOC_DPCM_TRIGGER_POST},
  470. .codec_dai_name = "rx_macro_rx4",
  471. .codec_name = "bolero_codec",
  472. .ops = &msm_common_be_ops,
  473. .ignore_suspend = 1,
  474. /* this dainlink has playback support */
  475. .ignore_pmdown_time = 1,
  476. },
  477. {
  478. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  479. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  480. .cpu_dai_name = "snd-soc-dummy-dai",
  481. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  482. .dpcm_capture = 1,
  483. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  484. SND_SOC_DPCM_TRIGGER_POST},
  485. .codec_dai_name = "tx_macro_tx1",
  486. .codec_name = "bolero_codec",
  487. .ops = &msm_common_be_ops,
  488. .ignore_suspend = 1,
  489. },
  490. {
  491. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  492. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  493. .cpu_dai_name = "snd-soc-dummy-dai",
  494. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  495. .dpcm_capture = 1,
  496. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  497. SND_SOC_DPCM_TRIGGER_POST},
  498. .codec_dai_name = "tx_macro_tx2",
  499. .codec_name = "bolero_codec",
  500. .ops = &msm_common_be_ops,
  501. .ignore_suspend = 1,
  502. },
  503. {
  504. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  505. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  506. .cpu_dai_name = "snd-soc-dummy-dai",
  507. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  508. .dpcm_capture = 1,
  509. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  510. SND_SOC_DPCM_TRIGGER_POST},
  511. .codec_dai_name = "va_macro_tx1",
  512. .codec_name = "bolero_codec",
  513. .ops = &msm_common_be_ops,
  514. .ignore_suspend = 1,
  515. },
  516. {
  517. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  518. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  519. .cpu_dai_name = "snd-soc-dummy-dai",
  520. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  521. .dpcm_capture = 1,
  522. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  523. SND_SOC_DPCM_TRIGGER_POST},
  524. .codec_dai_name = "va_macro_tx2",
  525. .codec_name = "bolero_codec",
  526. .ops = &msm_common_be_ops,
  527. .ignore_suspend = 1,
  528. },
  529. {
  530. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  531. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  532. .cpu_dai_name = "snd-soc-dummy-dai",
  533. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  534. .dpcm_capture = 1,
  535. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  536. SND_SOC_DPCM_TRIGGER_POST},
  537. .codec_dai_name = "va_macro_tx3",
  538. .codec_name = "bolero_codec",
  539. .ops = &msm_common_be_ops,
  540. .ignore_suspend = 1,
  541. },
  542. {
  543. .name = LPASS_BE_SLIMBUS_7_RX,
  544. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  545. .cpu_dai_name = "snd-soc-dummy-dai",
  546. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  547. .dpcm_playback = 1,
  548. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  549. SND_SOC_DPCM_TRIGGER_POST},
  550. .codec_name = "btfmslim_slave",
  551. .ops = &msm_common_be_ops,
  552. .codec_dai_name = "btfm_bt_sco_a2dp_slim_rx",
  553. .ignore_suspend = 1,
  554. /* this dainlink has playback support */
  555. .ignore_pmdown_time = 1,
  556. .init = &msm_wcn_init,
  557. },
  558. {
  559. .name = LPASS_BE_SLIMBUS_7_TX,
  560. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  561. .cpu_dai_name = "snd-soc-dummy-dai",
  562. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  563. .dpcm_capture = 1,
  564. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  565. SND_SOC_DPCM_TRIGGER_POST},
  566. .codec_name = "btfmslim_slave",
  567. .ops = &msm_common_be_ops,
  568. .codec_dai_name = "btfm_bt_sco_slim_tx",
  569. .ignore_suspend = 1,
  570. },
  571. {
  572. .name = LPASS_BE_DISPLAY_PORT_RX,
  573. .stream_name = LPASS_BE_DISPLAY_PORT_RX,
  574. .cpu_dai_name = "snd-soc-dummy-dai",
  575. .codec_name = "msm-ext-disp-audio-codec-rx",
  576. .codec_dai_name = "msm_dp_audio_codec_rx_dai",
  577. .dpcm_playback = 1,
  578. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  579. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  580. SND_SOC_DPCM_TRIGGER_POST},
  581. .ignore_pmdown_time = 1,
  582. .ignore_suspend = 1,
  583. .ops = &msm_common_be_ops,
  584. },
  585. {
  586. .name = LPASS_BE_USB_AUDIO_RX,
  587. .stream_name = LPASS_BE_USB_AUDIO_RX,
  588. .cpu_dai_name = "snd-soc-dummy-dai",
  589. .codec_name = "snd-soc-dummy",
  590. .codec_dai_name = "snd-soc-dummy-dai",
  591. .dpcm_playback = 1,
  592. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  593. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  594. SND_SOC_DPCM_TRIGGER_POST},
  595. .ignore_suspend = 1,
  596. .ops = &msm_common_be_ops,
  597. },
  598. {
  599. .name = LPASS_BE_USB_AUDIO_TX,
  600. .stream_name = LPASS_BE_USB_AUDIO_TX,
  601. .cpu_dai_name = "snd-soc-dummy-dai",
  602. .codec_name = "snd-soc-dummy",
  603. .codec_dai_name = "snd-soc-dummy-dai",
  604. .dpcm_capture = 1,
  605. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  606. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  607. SND_SOC_DPCM_TRIGGER_POST},
  608. .ignore_suspend = 1,
  609. .ops = &msm_common_be_ops,
  610. },
  611. {
  612. .name = LPASS_BE_RT_PROXY_PCM_RX,
  613. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  614. .cpu_dai_name = "snd-soc-dummy-dai",
  615. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  616. .dpcm_playback = 1,
  617. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  618. SND_SOC_DPCM_TRIGGER_POST},
  619. .codec_dai_name = "snd-soc-dummy-dai",
  620. .codec_name = "snd-soc-dummy",
  621. .ignore_suspend = 1,
  622. /* this dainlink has playback support */
  623. .ignore_pmdown_time = 1,
  624. },
  625. {
  626. .name = LPASS_BE_RT_PROXY_PCM_TX,
  627. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  628. .cpu_dai_name = "snd-soc-dummy-dai",
  629. .async_ops = ASYNC_DPCM_SND_SOC_PREPARE,
  630. .dpcm_capture = 1,
  631. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  632. SND_SOC_DPCM_TRIGGER_POST},
  633. .codec_dai_name = "snd-soc-dummy-dai",
  634. .codec_name = "snd-soc-dummy",
  635. .ignore_suspend = 1,
  636. },
  637. };
  638. static struct snd_soc_dai_link msm_kona_dai_links[
  639. ARRAY_SIZE(msm_common_dai_links)];
  640. static int msm_populate_dai_link_component_of_node(
  641. struct snd_soc_card *card)
  642. {
  643. int i, index, ret = 0;
  644. struct device *cdev = card->dev;
  645. struct snd_soc_dai_link *dai_link = card->dai_link;
  646. struct device_node *np;
  647. if (!cdev) {
  648. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  649. return -ENODEV;
  650. }
  651. for (i = 0; i < card->num_links; i++) {
  652. if (dai_link[i].init == NULL)
  653. dai_link[i].init = &msm_common_dai_link_init;
  654. /* populate codec_of_node for snd card dai links */
  655. if (dai_link[i].codec_name && !dai_link[i].codec_of_node) {
  656. index = of_property_match_string(cdev->of_node,
  657. "asoc-codec-names",
  658. dai_link[i].codec_name);
  659. if (index < 0)
  660. continue;
  661. np = of_parse_phandle(cdev->of_node, "asoc-codec",
  662. index);
  663. if (!np) {
  664. dev_err(cdev, "%s: retrieving phandle for codec %s failed\n",
  665. __func__, dai_link[i].codec_name);
  666. ret = -ENODEV;
  667. goto err;
  668. }
  669. dai_link[i].codec_of_node = np;
  670. dai_link[i].codec_name = NULL;
  671. }
  672. }
  673. err:
  674. return ret;
  675. }
  676. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  677. {
  678. return 0;
  679. }
  680. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  681. struct snd_pcm_hw_params *params)
  682. {
  683. return 0;
  684. }
  685. static struct snd_soc_ops msm_stub_be_ops = {
  686. .hw_params = msm_snd_stub_hw_params,
  687. };
  688. struct snd_soc_card snd_soc_card_stub_msm = {
  689. .name = "kona-stub-snd-card",
  690. };
  691. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  692. /* Backend DAI Links */
  693. {
  694. .name = LPASS_BE_PRI_AUXPCM_RX,
  695. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  696. .cpu_dai_name = "snd-soc-dummy-dai",
  697. .codec_name = "msm-stub-codec.1",
  698. .codec_dai_name = "msm-stub-rx",
  699. .dpcm_playback = 1,
  700. .init = &msm_audrx_stub_init,
  701. .ignore_pmdown_time = 1,
  702. .ignore_suspend = 1,
  703. .ops = &msm_stub_be_ops,
  704. },
  705. {
  706. .name = LPASS_BE_PRI_AUXPCM_TX,
  707. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  708. .cpu_dai_name = "snd-soc-dummy-dai",
  709. .codec_name = "msm-stub-codec.1",
  710. .codec_dai_name = "msm-stub-tx",
  711. .dpcm_capture = 1,
  712. .ignore_suspend = 1,
  713. .ops = &msm_stub_be_ops,
  714. },
  715. };
  716. static struct snd_soc_dai_link msm_stub_dai_links[
  717. ARRAY_SIZE(msm_stub_be_dai_links)];
  718. static const struct of_device_id kona_asoc_machine_of_match[] = {
  719. { .compatible = "qcom,kona-asoc-snd",
  720. .data = "codec"},
  721. { .compatible = "qcom,kona-asoc-snd-stub",
  722. .data = "stub_codec"},
  723. {},
  724. };
  725. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  726. {
  727. struct snd_soc_card *card = NULL;
  728. struct snd_soc_dai_link *dailink = NULL;
  729. int total_links = 0;
  730. const struct of_device_id *match;
  731. match = of_match_node(kona_asoc_machine_of_match, dev->of_node);
  732. if (!match) {
  733. dev_err(dev, "%s: No DT match found for sound card\n",
  734. __func__);
  735. return NULL;
  736. }
  737. if (!strcmp(match->data, "codec")) {
  738. card = &snd_soc_card_kona_msm;
  739. memcpy(msm_kona_dai_links,
  740. msm_common_dai_links,
  741. sizeof(msm_common_dai_links));
  742. total_links += ARRAY_SIZE(msm_common_dai_links);
  743. dailink = msm_kona_dai_links;
  744. } else if(!strcmp(match->data, "stub_codec")) {
  745. card = &snd_soc_card_stub_msm;
  746. memcpy(msm_stub_dai_links,
  747. msm_stub_be_dai_links,
  748. sizeof(msm_stub_be_dai_links));
  749. total_links = ARRAY_SIZE(msm_stub_be_dai_links);
  750. dailink = msm_stub_dai_links;
  751. }
  752. if (card) {
  753. card->dai_link = dailink;
  754. card->num_links = total_links;
  755. }
  756. return card;
  757. }
  758. static int msm_wsa881x_init(struct snd_soc_component *component)
  759. {
  760. u8 spkleft_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  761. u8 spkright_ports[WSA881X_MAX_SWR_PORTS] = {0, 1, 2, 3};
  762. u8 spkleft_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_L, SPKR_L_COMP,
  763. SPKR_L_BOOST, SPKR_L_VI};
  764. u8 spkright_port_types[WSA881X_MAX_SWR_PORTS] = {SPKR_R, SPKR_R_COMP,
  765. SPKR_R_BOOST, SPKR_R_VI};
  766. unsigned int ch_rate[WSA881X_MAX_SWR_PORTS] = {2400, 600, 300, 1200};
  767. unsigned int ch_mask[WSA881X_MAX_SWR_PORTS] = {0x1, 0xF, 0x3, 0x3};
  768. struct msm_asoc_mach_data *pdata;
  769. struct snd_soc_dapm_context *dapm;
  770. struct snd_card *card;
  771. struct snd_info_entry *entry;
  772. int ret = 0;
  773. if (!component) {
  774. pr_err("%s component is NULL\n", __func__);
  775. return -EINVAL;
  776. }
  777. card = component->card->snd_card;
  778. dapm = snd_soc_component_get_dapm(component);
  779. if (!strcmp(component->name_prefix, "SpkrLeft")) {
  780. dev_dbg(component->dev, "%s: setting left ch map to codec %s\n",
  781. __func__, component->name);
  782. wsa881x_set_channel_map(component, &spkleft_ports[0],
  783. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  784. &ch_rate[0], &spkleft_port_types[0]);
  785. if (dapm->component) {
  786. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft IN");
  787. snd_soc_dapm_ignore_suspend(dapm, "SpkrLeft SPKR");
  788. }
  789. } else if (!strcmp(component->name_prefix, "SpkrRight")) {
  790. dev_dbg(component->dev, "%s: setting right ch map to codec %s\n",
  791. __func__, component->name);
  792. wsa881x_set_channel_map(component, &spkright_ports[0],
  793. WSA881X_MAX_SWR_PORTS, &ch_mask[0],
  794. &ch_rate[0], &spkright_port_types[0]);
  795. if (dapm->component) {
  796. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight IN");
  797. snd_soc_dapm_ignore_suspend(dapm, "SpkrRight SPKR");
  798. }
  799. } else {
  800. dev_err(component->dev, "%s: wrong codec name %s\n", __func__,
  801. component->name);
  802. ret = -EINVAL;
  803. goto err;
  804. }
  805. pdata = snd_soc_card_get_drvdata(component->card);
  806. if (!pdata->codec_root) {
  807. entry = snd_info_create_subdir(card->module, "codecs",
  808. card->proc_root);
  809. if (!entry) {
  810. pr_err("%s: Cannot create codecs module entry\n",
  811. __func__);
  812. ret = 0;
  813. goto err;
  814. }
  815. pdata->codec_root = entry;
  816. }
  817. wsa881x_codec_info_create_codec_entry(pdata->codec_root,
  818. component);
  819. err:
  820. return ret;
  821. }
  822. static int msm_aux_codec_init(struct snd_soc_component *component)
  823. {
  824. struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
  825. int ret = 0;
  826. int codec_variant = -1;
  827. void *mbhc_calibration;
  828. struct snd_info_entry *entry;
  829. struct snd_card *card = component->card->snd_card;
  830. struct msm_asoc_mach_data *pdata;
  831. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  832. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  833. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  834. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  835. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  836. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  837. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  838. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  839. snd_soc_dapm_sync(dapm);
  840. pdata = snd_soc_card_get_drvdata(component->card);
  841. if (!pdata->codec_root) {
  842. entry = snd_info_create_subdir(card->module, "codecs",
  843. card->proc_root);
  844. if (!entry) {
  845. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  846. __func__);
  847. ret = 0;
  848. goto mbhc_cfg_cal;
  849. }
  850. pdata->codec_root = entry;
  851. }
  852. wcd938x_info_create_codec_entry(pdata->codec_root, component);
  853. codec_variant = wcd938x_get_codec_variant(component);
  854. dev_dbg(component->dev, "%s: variant %d\n", __func__, codec_variant);
  855. mbhc_cfg_cal:
  856. mbhc_calibration = def_wcd_mbhc_cal();
  857. if (!mbhc_calibration)
  858. return -ENOMEM;
  859. wcd_mbhc_cfg.calibration = mbhc_calibration;
  860. ret = wcd938x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  861. if (ret) {
  862. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  863. __func__, ret);
  864. goto err_hs_detect;
  865. }
  866. return 0;
  867. err_hs_detect:
  868. kfree(mbhc_calibration);
  869. return ret;
  870. }
  871. static int msm_init_aux_dev(struct platform_device *pdev,
  872. struct snd_soc_card *card)
  873. {
  874. struct device_node *wsa_of_node;
  875. struct device_node *aux_codec_of_node;
  876. u32 wsa_max_devs;
  877. u32 wsa_dev_cnt;
  878. u32 codec_max_aux_devs = 0;
  879. u32 codec_aux_dev_cnt = 0;
  880. int i;
  881. struct msm_wsa881x_dev_info *wsa881x_dev_info;
  882. struct aux_codec_dev_info *aux_cdc_dev_info;
  883. const char *auxdev_name_prefix[1];
  884. char *dev_name_str = NULL;
  885. int found = 0;
  886. int codecs_found = 0;
  887. int ret = 0;
  888. /* Get maximum WSA device count for this platform */
  889. ret = of_property_read_u32(pdev->dev.of_node,
  890. "qcom,wsa-max-devs", &wsa_max_devs);
  891. if (ret) {
  892. dev_info(&pdev->dev,
  893. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  894. __func__, pdev->dev.of_node->full_name, ret);
  895. wsa_max_devs = 0;
  896. goto codec_aux_dev;
  897. }
  898. if (wsa_max_devs == 0) {
  899. dev_warn(&pdev->dev,
  900. "%s: Max WSA devices is 0 for this target?\n",
  901. __func__);
  902. goto codec_aux_dev;
  903. }
  904. /* Get count of WSA device phandles for this platform */
  905. wsa_dev_cnt = of_count_phandle_with_args(pdev->dev.of_node,
  906. "qcom,wsa-devs", NULL);
  907. if (wsa_dev_cnt == -ENOENT) {
  908. dev_warn(&pdev->dev, "%s: No wsa device defined in DT.\n",
  909. __func__);
  910. goto err;
  911. } else if (wsa_dev_cnt <= 0) {
  912. dev_err(&pdev->dev,
  913. "%s: Error reading wsa device from DT. wsa_dev_cnt = %d\n",
  914. __func__, wsa_dev_cnt);
  915. ret = -EINVAL;
  916. goto err;
  917. }
  918. /*
  919. * Expect total phandles count to be NOT less than maximum possible
  920. * WSA count. However, if it is less, then assign same value to
  921. * max count as well.
  922. */
  923. if (wsa_dev_cnt < wsa_max_devs) {
  924. dev_dbg(&pdev->dev,
  925. "%s: wsa_max_devs = %d cannot exceed wsa_dev_cnt = %d\n",
  926. __func__, wsa_max_devs, wsa_dev_cnt);
  927. wsa_max_devs = wsa_dev_cnt;
  928. }
  929. /* Make sure prefix string passed for each WSA device */
  930. ret = of_property_count_strings(pdev->dev.of_node,
  931. "qcom,wsa-aux-dev-prefix");
  932. if (ret != wsa_dev_cnt) {
  933. dev_err(&pdev->dev,
  934. "%s: expecting %d wsa prefix. Defined only %d in DT\n",
  935. __func__, wsa_dev_cnt, ret);
  936. ret = -EINVAL;
  937. goto err;
  938. }
  939. /*
  940. * Alloc mem to store phandle and index info of WSA device, if already
  941. * registered with ALSA core
  942. */
  943. wsa881x_dev_info = devm_kcalloc(&pdev->dev, wsa_max_devs,
  944. sizeof(struct msm_wsa881x_dev_info),
  945. GFP_KERNEL);
  946. if (!wsa881x_dev_info) {
  947. ret = -ENOMEM;
  948. goto err;
  949. }
  950. /*
  951. * search and check whether all WSA devices are already
  952. * registered with ALSA core or not. If found a node, store
  953. * the node and the index in a local array of struct for later
  954. * use.
  955. */
  956. for (i = 0; i < wsa_dev_cnt; i++) {
  957. wsa_of_node = of_parse_phandle(pdev->dev.of_node,
  958. "qcom,wsa-devs", i);
  959. if (unlikely(!wsa_of_node)) {
  960. /* we should not be here */
  961. dev_err(&pdev->dev,
  962. "%s: wsa dev node is not present\n",
  963. __func__);
  964. ret = -EINVAL;
  965. goto err;
  966. }
  967. if (soc_find_component(wsa_of_node, NULL)) {
  968. /* WSA device registered with ALSA core */
  969. wsa881x_dev_info[found].of_node = wsa_of_node;
  970. wsa881x_dev_info[found].index = i;
  971. found++;
  972. if (found == wsa_max_devs)
  973. break;
  974. }
  975. }
  976. if (found < wsa_max_devs) {
  977. dev_dbg(&pdev->dev,
  978. "%s: failed to find %d components. Found only %d\n",
  979. __func__, wsa_max_devs, found);
  980. return -EPROBE_DEFER;
  981. }
  982. dev_info(&pdev->dev,
  983. "%s: found %d wsa881x devices registered with ALSA core\n",
  984. __func__, found);
  985. codec_aux_dev:
  986. /* Get maximum aux codec device count for this platform */
  987. ret = of_property_read_u32(pdev->dev.of_node,
  988. "qcom,codec-max-aux-devs",
  989. &codec_max_aux_devs);
  990. if (ret) {
  991. dev_err(&pdev->dev,
  992. "%s: codec-max-aux-devs property missing in DT %s, ret = %d\n",
  993. __func__, pdev->dev.of_node->full_name, ret);
  994. codec_max_aux_devs = 0;
  995. goto aux_dev_register;
  996. }
  997. if (codec_max_aux_devs == 0) {
  998. dev_dbg(&pdev->dev,
  999. "%s: Max aux codec devices is 0 for this target?\n",
  1000. __func__);
  1001. goto aux_dev_register;
  1002. }
  1003. /* Get count of aux codec device phandles for this platform */
  1004. codec_aux_dev_cnt = of_count_phandle_with_args(
  1005. pdev->dev.of_node,
  1006. "qcom,codec-aux-devs", NULL);
  1007. if (codec_aux_dev_cnt == -ENOENT) {
  1008. dev_warn(&pdev->dev, "%s: No aux codec defined in DT.\n",
  1009. __func__);
  1010. goto err;
  1011. } else if (codec_aux_dev_cnt <= 0) {
  1012. dev_err(&pdev->dev,
  1013. "%s: Error reading aux codec device from DT, dev_cnt=%d\n",
  1014. __func__, codec_aux_dev_cnt);
  1015. ret = -EINVAL;
  1016. goto err;
  1017. }
  1018. /*
  1019. * Expect total phandles count to be NOT less than maximum possible
  1020. * AUX device count. However, if it is less, then assign same value to
  1021. * max count as well.
  1022. */
  1023. if (codec_aux_dev_cnt < codec_max_aux_devs) {
  1024. dev_dbg(&pdev->dev,
  1025. "%s: codec_max_aux_devs = %d cannot exceed codec_aux_dev_cnt = %d\n",
  1026. __func__, codec_max_aux_devs,
  1027. codec_aux_dev_cnt);
  1028. codec_max_aux_devs = codec_aux_dev_cnt;
  1029. }
  1030. /*
  1031. * Alloc mem to store phandle and index info of aux codec
  1032. * if already registered with ALSA core
  1033. */
  1034. aux_cdc_dev_info = devm_kcalloc(&pdev->dev, codec_aux_dev_cnt,
  1035. sizeof(struct aux_codec_dev_info),
  1036. GFP_KERNEL);
  1037. if (!aux_cdc_dev_info) {
  1038. ret = -ENOMEM;
  1039. goto err;
  1040. }
  1041. /*
  1042. * search and check whether all aux codecs are already
  1043. * registered with ALSA core or not. If found a node, store
  1044. * the node and the index in a local array of struct for later
  1045. * use.
  1046. */
  1047. for (i = 0; i < codec_aux_dev_cnt; i++) {
  1048. aux_codec_of_node = of_parse_phandle(pdev->dev.of_node,
  1049. "qcom,codec-aux-devs", i);
  1050. if (unlikely(!aux_codec_of_node)) {
  1051. /* we should not be here */
  1052. dev_err(&pdev->dev,
  1053. "%s: aux codec dev node is not present\n",
  1054. __func__);
  1055. ret = -EINVAL;
  1056. goto err;
  1057. }
  1058. if (soc_find_component(aux_codec_of_node, NULL)) {
  1059. /* AUX codec registered with ALSA core */
  1060. aux_cdc_dev_info[codecs_found].of_node =
  1061. aux_codec_of_node;
  1062. aux_cdc_dev_info[codecs_found].index = i;
  1063. codecs_found++;
  1064. }
  1065. }
  1066. if (codecs_found < codec_aux_dev_cnt) {
  1067. dev_dbg(&pdev->dev,
  1068. "%s: failed to find %d components. Found only %d\n",
  1069. __func__, codec_aux_dev_cnt, codecs_found);
  1070. return -EPROBE_DEFER;
  1071. }
  1072. dev_info(&pdev->dev,
  1073. "%s: found %d AUX codecs registered with ALSA core\n",
  1074. __func__, codecs_found);
  1075. aux_dev_register:
  1076. card->num_aux_devs = wsa_max_devs + codec_aux_dev_cnt;
  1077. card->num_configs = wsa_max_devs + codec_aux_dev_cnt;
  1078. /* Alloc array of AUX devs struct */
  1079. msm_aux_dev = devm_kcalloc(&pdev->dev, card->num_aux_devs,
  1080. sizeof(struct snd_soc_aux_dev),
  1081. GFP_KERNEL);
  1082. if (!msm_aux_dev) {
  1083. ret = -ENOMEM;
  1084. goto err;
  1085. }
  1086. /* Alloc array of codec conf struct */
  1087. msm_codec_conf = devm_kcalloc(&pdev->dev, card->num_configs,
  1088. sizeof(struct snd_soc_codec_conf),
  1089. GFP_KERNEL);
  1090. if (!msm_codec_conf) {
  1091. ret = -ENOMEM;
  1092. goto err;
  1093. }
  1094. for (i = 0; i < wsa_max_devs; i++) {
  1095. dev_name_str = devm_kzalloc(&pdev->dev, DEV_NAME_STR_LEN,
  1096. GFP_KERNEL);
  1097. if (!dev_name_str) {
  1098. ret = -ENOMEM;
  1099. goto err;
  1100. }
  1101. ret = of_property_read_string_index(pdev->dev.of_node,
  1102. "qcom,wsa-aux-dev-prefix",
  1103. wsa881x_dev_info[i].index,
  1104. auxdev_name_prefix);
  1105. if (ret) {
  1106. dev_err(&pdev->dev,
  1107. "%s: failed to read wsa aux dev prefix, ret = %d\n",
  1108. __func__, ret);
  1109. ret = -EINVAL;
  1110. goto err;
  1111. }
  1112. snprintf(dev_name_str, strlen("wsa881x.%d"), "wsa881x.%d", i);
  1113. msm_aux_dev[i].name = dev_name_str;
  1114. msm_aux_dev[i].codec_name = NULL;
  1115. msm_aux_dev[i].codec_of_node =
  1116. wsa881x_dev_info[i].of_node;
  1117. msm_aux_dev[i].init = msm_wsa881x_init;
  1118. msm_codec_conf[i].dev_name = NULL;
  1119. msm_codec_conf[i].name_prefix = auxdev_name_prefix[0];
  1120. msm_codec_conf[i].of_node =
  1121. wsa881x_dev_info[i].of_node;
  1122. }
  1123. for (i = 0; i < codec_aux_dev_cnt; i++) {
  1124. msm_aux_dev[wsa_max_devs + i].name = NULL;
  1125. msm_aux_dev[wsa_max_devs + i].codec_name = NULL;
  1126. msm_aux_dev[wsa_max_devs + i].codec_of_node =
  1127. aux_cdc_dev_info[i].of_node;
  1128. msm_aux_dev[wsa_max_devs + i].init = msm_aux_codec_init;
  1129. msm_codec_conf[wsa_max_devs + i].dev_name = NULL;
  1130. msm_codec_conf[wsa_max_devs + i].name_prefix =
  1131. NULL;
  1132. msm_codec_conf[wsa_max_devs + i].of_node =
  1133. aux_cdc_dev_info[i].of_node;
  1134. }
  1135. card->codec_conf = msm_codec_conf;
  1136. card->aux_dev = msm_aux_dev;
  1137. err:
  1138. return ret;
  1139. }
  1140. static int kona_ssr_enable(struct device *dev, void *data)
  1141. {
  1142. struct platform_device *pdev = to_platform_device(dev);
  1143. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1144. int ret = 0;
  1145. if (!card) {
  1146. dev_err(dev, "%s: card is NULL\n", __func__);
  1147. ret = -EINVAL;
  1148. goto err;
  1149. }
  1150. if (!strcmp(card->name, "kona-stub-snd-card")) {
  1151. /* TODO */
  1152. dev_dbg(dev, "%s: TODO \n", __func__);
  1153. }
  1154. snd_soc_card_change_online_state(card, 1);
  1155. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1156. err:
  1157. return ret;
  1158. }
  1159. static void kona_ssr_disable(struct device *dev, void *data)
  1160. {
  1161. struct platform_device *pdev = to_platform_device(dev);
  1162. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1163. if (!card) {
  1164. dev_err(dev, "%s: card is NULL\n", __func__);
  1165. return;
  1166. }
  1167. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1168. snd_soc_card_change_online_state(card, 0);
  1169. if (!strcmp(card->name, "kona-stub-snd-card")) {
  1170. /* TODO */
  1171. dev_dbg(dev, "%s: TODO \n", __func__);
  1172. }
  1173. }
  1174. static const struct snd_event_ops kona_ssr_ops = {
  1175. .enable = kona_ssr_enable,
  1176. .disable = kona_ssr_disable,
  1177. };
  1178. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1179. {
  1180. struct device_node *node = data;
  1181. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1182. __func__, dev->of_node, node);
  1183. return (dev->of_node && dev->of_node == node);
  1184. }
  1185. static int msm_audio_ssr_register(struct device *dev)
  1186. {
  1187. struct device_node *np = dev->of_node;
  1188. struct snd_event_clients *ssr_clients = NULL;
  1189. struct device_node *node = NULL;
  1190. int ret = 0;
  1191. int i = 0;
  1192. for (i = 0; ; i++) {
  1193. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1194. if (!node)
  1195. break;
  1196. snd_event_mstr_add_client(&ssr_clients,
  1197. msm_audio_ssr_compare, node);
  1198. }
  1199. ret = snd_event_master_register(dev, &kona_ssr_ops,
  1200. ssr_clients, NULL);
  1201. if (!ret)
  1202. snd_event_notify(dev, SND_EVENT_UP);
  1203. return ret;
  1204. }
  1205. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1206. {
  1207. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1208. if (!pdata)
  1209. return NULL;
  1210. return pdata->common_pdata;
  1211. }
  1212. void msm_common_set_pdata(struct snd_soc_card *card,
  1213. struct msm_common_pdata *common_pdata)
  1214. {
  1215. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1216. if (!pdata)
  1217. return;
  1218. pdata->common_pdata = common_pdata;
  1219. }
  1220. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1221. {
  1222. struct snd_soc_card *card = NULL;
  1223. struct msm_asoc_mach_data *pdata = NULL;
  1224. const char *mbhc_audio_jack_type = NULL;
  1225. int ret = 0;
  1226. if (!pdev->dev.of_node) {
  1227. dev_err(&pdev->dev, "%s: No platform supplied from device tree\n", __func__);
  1228. return -EINVAL;
  1229. }
  1230. pdata = devm_kzalloc(&pdev->dev,
  1231. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1232. if (!pdata)
  1233. return -ENOMEM;
  1234. of_property_read_u32(pdev->dev.of_node,
  1235. "qcom,lito-is-v2-enabled",
  1236. &pdata->lito_v2_enabled);
  1237. card = populate_snd_card_dailinks(&pdev->dev);
  1238. if (!card) {
  1239. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1240. ret = -EINVAL;
  1241. goto err;
  1242. }
  1243. card->dev = &pdev->dev;
  1244. platform_set_drvdata(pdev, card);
  1245. snd_soc_card_set_drvdata(card, pdata);
  1246. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1247. if (ret) {
  1248. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1249. __func__, ret);
  1250. goto err;
  1251. }
  1252. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1253. if (ret) {
  1254. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1255. __func__, ret);
  1256. goto err;
  1257. }
  1258. ret = msm_populate_dai_link_component_of_node(card);
  1259. if (ret) {
  1260. ret = -EPROBE_DEFER;
  1261. goto err;
  1262. }
  1263. ret = msm_init_aux_dev(pdev, card);
  1264. if (ret)
  1265. goto err;
  1266. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1267. if (ret == -EPROBE_DEFER) {
  1268. if (codec_reg_done)
  1269. ret = -EINVAL;
  1270. goto err;
  1271. } else if (ret) {
  1272. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1273. __func__, ret);
  1274. goto err;
  1275. }
  1276. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1277. __func__, card->name);
  1278. msm_common_snd_init(pdev, card);
  1279. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1280. "qcom,hph-en1-gpio", 0);
  1281. if (!pdata->hph_en1_gpio_p) {
  1282. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1283. __func__, "qcom,hph-en1-gpio",
  1284. pdev->dev.of_node->full_name);
  1285. }
  1286. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1287. "qcom,hph-en0-gpio", 0);
  1288. if (!pdata->hph_en0_gpio_p) {
  1289. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1290. __func__, "qcom,hph-en0-gpio",
  1291. pdev->dev.of_node->full_name);
  1292. }
  1293. ret = of_property_read_string(pdev->dev.of_node,
  1294. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  1295. if (ret) {
  1296. dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
  1297. __func__, "qcom,mbhc-audio-jack-type",
  1298. pdev->dev.of_node->full_name);
  1299. dev_dbg(&pdev->dev, "Jack type properties set to default\n");
  1300. } else {
  1301. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  1302. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1303. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  1304. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  1305. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1306. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  1307. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  1308. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1309. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  1310. } else {
  1311. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1312. dev_dbg(&pdev->dev, "Unknown value, set to default\n");
  1313. }
  1314. }
  1315. /*
  1316. * Parse US-Euro gpio info from DT. Report no error if us-euro
  1317. * entry is not found in DT file as some targets do not support
  1318. * US-Euro detection
  1319. */
  1320. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1321. "qcom,us-euro-gpios", 0);
  1322. if (!pdata->us_euro_gpio_p) {
  1323. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1324. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  1325. } else {
  1326. dev_dbg(&pdev->dev, "%s detected\n",
  1327. "qcom,us-euro-gpios");
  1328. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  1329. }
  1330. if (wcd_mbhc_cfg.enable_usbc_analog)
  1331. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1332. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1333. "fsa4480-i2c-handle", 0);
  1334. if (!pdata->fsa_handle)
  1335. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1336. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1337. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1338. "qcom,cdc-dmic01-gpios",
  1339. 0);
  1340. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1341. "qcom,cdc-dmic23-gpios",
  1342. 0);
  1343. pdata->dmic45_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1344. "qcom,cdc-dmic45-gpios",
  1345. 0);
  1346. if (pdata->dmic01_gpio_p)
  1347. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic01_gpio_p, false);
  1348. if (pdata->dmic23_gpio_p)
  1349. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic23_gpio_p, false);
  1350. if (pdata->dmic45_gpio_p)
  1351. msm_cdc_pinctrl_set_wakeup_capable(pdata->dmic45_gpio_p, false);
  1352. ret = msm_audio_ssr_register(&pdev->dev);
  1353. if (ret)
  1354. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1355. __func__, ret);
  1356. is_initial_boot = true;
  1357. return 0;
  1358. err:
  1359. devm_kfree(&pdev->dev, pdata);
  1360. return ret;
  1361. }
  1362. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1363. {
  1364. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1365. struct msm_asoc_mach_data *pdata = NULL;
  1366. struct msm_common_pdata *common_pdata = NULL;
  1367. if (card)
  1368. pdata = snd_soc_card_get_drvdata(card);
  1369. if (pdata)
  1370. common_pdata = pdata->common_pdata;
  1371. msm_common_snd_deinit(common_pdata);
  1372. snd_event_master_deregister(&pdev->dev);
  1373. snd_soc_unregister_card(card);
  1374. return 0;
  1375. }
  1376. static struct platform_driver kona_asoc_machine_driver = {
  1377. .driver = {
  1378. .name = DRV_NAME,
  1379. .owner = THIS_MODULE,
  1380. .pm = &snd_soc_pm_ops,
  1381. .of_match_table = kona_asoc_machine_of_match,
  1382. .suppress_bind_attrs = true,
  1383. },
  1384. .probe = msm_asoc_machine_probe,
  1385. .remove = msm_asoc_machine_remove,
  1386. };
  1387. module_platform_driver(kona_asoc_machine_driver);
  1388. MODULE_DESCRIPTION("ALSA SoC msm");
  1389. MODULE_LICENSE("GPL v2");
  1390. MODULE_ALIAS("platform:" DRV_NAME);
  1391. MODULE_DEVICE_TABLE(of, kona_asoc_machine_of_match);