bengal.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022. Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/delay.h>
  8. #include <linux/gpio.h>
  9. #include <linux/of_gpio.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/slab.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/input.h>
  15. #include <linux/of_device.h>
  16. #include <linux/soc/qcom/fsa4480-i2c.h>
  17. #include <linux/pm_qos.h>
  18. #include <linux/nvmem-consumer.h>
  19. #include <sound/control.h>
  20. #include <sound/core.h>
  21. #include <sound/soc.h>
  22. #include <sound/soc-dapm.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/info.h>
  26. #include <soc/snd_event.h>
  27. #include <dsp/audio_prm.h>
  28. #include <soc/swr-common.h>
  29. #include <soc/soundwire.h>
  30. #include "device_event.h"
  31. #include "asoc/msm-cdc-pinctrl.h"
  32. #include "asoc/wcd-mbhc-v2.h"
  33. #include "codecs/wcd937x/wcd937x-mbhc.h"
  34. #include "codecs/rouleur/rouleur-mbhc.h"
  35. #include "codecs/wsa881x-analog.h"
  36. #include "codecs/wcd937x/wcd937x.h"
  37. #include "codecs/rouleur/rouleur.h"
  38. #include "codecs/bolero/bolero-cdc.h"
  39. #include <bindings/audio-codec-port-types.h>
  40. #include "bengal-port-config.h"
  41. #include "msm-audio-defs.h"
  42. #include "msm_common.h"
  43. #include "msm_bengal_dailink.h"
  44. #define DRV_NAME "bengal-asoc-snd"
  45. #define __CHIPSET__ "BENGAL "
  46. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  47. #define WCD9XXX_MBHC_DEF_RLOADS 5
  48. #define WCD9XXX_MBHC_DEF_BUTTONS 8
  49. #define DEV_NAME_STR_LEN 32
  50. #define WCD_MBHC_HS_V_MAX 1600
  51. #define WCN_CDC_SLIM_RX_CH_MAX 2
  52. #define WCN_CDC_SLIM_TX_CH_MAX 3
  53. enum {
  54. PRIM_MI2S = 0,
  55. SEC_MI2S,
  56. TERT_MI2S,
  57. QUAT_MI2S,
  58. MI2S_MAX,
  59. };
  60. struct msm_asoc_mach_data {
  61. struct snd_info_entry *codec_root;
  62. struct msm_common_pdata *common_pdata;
  63. int usbc_en2_gpio; /* used by gpio driver API */
  64. struct device_node *dmic01_gpio_p; /* used by pinctrl API */
  65. struct device_node *dmic23_gpio_p; /* used by pinctrl API */
  66. struct device_node *mi2s_gpio_p[MI2S_MAX]; /* used by pinctrl API */
  67. atomic_t mi2s_gpio_ref_count[MI2S_MAX]; /* used by pinctrl API */
  68. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  69. struct pinctrl *usbc_en2_gpio_p; /* used by pinctrl API */
  70. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  71. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  72. struct device_node *fsa_handle;
  73. u32 wsa_max_devs;
  74. };
  75. static bool va_disable;
  76. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd);
  77. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd);
  78. static bool is_initial_boot;
  79. static bool codec_reg_done;
  80. static struct snd_soc_card snd_soc_card_bengal_msm;
  81. static int dmic_0_1_gpio_cnt;
  82. static int dmic_2_3_gpio_cnt;
  83. static void *def_wcd_mbhc_cal(void);
  84. /*
  85. * Need to report LINEIN
  86. * if R/L channel impedance is larger than 5K ohm
  87. */
  88. static struct wcd_mbhc_config wcd_mbhc_cfg = {
  89. .read_fw_bin = false,
  90. .calibration = NULL,
  91. .detect_extn_cable = true,
  92. .mono_stero_detection = false,
  93. .swap_gnd_mic = NULL,
  94. .hs_ext_micbias = true,
  95. .key_code[0] = KEY_MEDIA,
  96. .key_code[1] = KEY_VOICECOMMAND,
  97. .key_code[2] = KEY_VOLUMEUP,
  98. .key_code[3] = KEY_VOLUMEDOWN,
  99. .key_code[4] = 0,
  100. .key_code[5] = 0,
  101. .key_code[6] = 0,
  102. .key_code[7] = 0,
  103. .linein_th = 5000,
  104. .moisture_en = false,
  105. .mbhc_micbias = MIC_BIAS_2,
  106. .anc_micbias = MIC_BIAS_2,
  107. .enable_anc_mic_detect = false,
  108. .moisture_duty_cycle_en = true,
  109. };
  110. static bool msm_usbc_swap_gnd_mic(struct snd_soc_component *component,
  111. bool active)
  112. {
  113. struct snd_soc_card *card = component->card;
  114. struct msm_asoc_mach_data *pdata =
  115. snd_soc_card_get_drvdata(card);
  116. if (!pdata->fsa_handle)
  117. return false;
  118. return fsa4480_switch_event(pdata->fsa_handle, FSA_MIC_GND_SWAP);
  119. }
  120. static bool msm_swap_gnd_mic(struct snd_soc_component *component, bool active)
  121. {
  122. int value = 0;
  123. bool ret = false;
  124. struct snd_soc_card *card;
  125. struct msm_asoc_mach_data *pdata;
  126. if (!component) {
  127. pr_err("%s component is NULL\n", __func__);
  128. return false;
  129. }
  130. card = component->card;
  131. pdata = snd_soc_card_get_drvdata(card);
  132. if (!pdata)
  133. return false;
  134. if (wcd_mbhc_cfg.enable_usbc_analog)
  135. return msm_usbc_swap_gnd_mic(component, active);
  136. /* if usbc is not defined, swap using us_euro_gpio_p */
  137. if (pdata->us_euro_gpio_p) {
  138. value = msm_cdc_pinctrl_get_state(
  139. pdata->us_euro_gpio_p);
  140. if (value)
  141. msm_cdc_pinctrl_select_sleep_state(
  142. pdata->us_euro_gpio_p);
  143. else
  144. msm_cdc_pinctrl_select_active_state(
  145. pdata->us_euro_gpio_p);
  146. dev_dbg(component->dev, "%s: swap select switch %d to %d\n",
  147. __func__, value, !value);
  148. ret = true;
  149. }
  150. return ret;
  151. }
  152. static int msm_dmic_event(struct snd_soc_dapm_widget *w,
  153. struct snd_kcontrol *kcontrol, int event)
  154. {
  155. struct msm_asoc_mach_data *pdata = NULL;
  156. struct snd_soc_component *component =
  157. snd_soc_dapm_to_component(w->dapm);
  158. int ret = 0;
  159. u32 dmic_idx;
  160. int *dmic_gpio_cnt;
  161. struct device_node *dmic_gpio;
  162. char *wname;
  163. wname = strpbrk(w->name, "0123");
  164. if (!wname) {
  165. dev_err(component->dev, "%s: widget not found\n", __func__);
  166. return -EINVAL;
  167. }
  168. ret = kstrtouint(wname, 10, &dmic_idx);
  169. if (ret < 0) {
  170. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  171. __func__);
  172. return -EINVAL;
  173. }
  174. pdata = snd_soc_card_get_drvdata(component->card);
  175. switch (dmic_idx) {
  176. case 0:
  177. case 1:
  178. dmic_gpio_cnt = &dmic_0_1_gpio_cnt;
  179. dmic_gpio = pdata->dmic01_gpio_p;
  180. break;
  181. case 2:
  182. case 3:
  183. dmic_gpio_cnt = &dmic_2_3_gpio_cnt;
  184. dmic_gpio = pdata->dmic23_gpio_p;
  185. break;
  186. default:
  187. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  188. __func__);
  189. return -EINVAL;
  190. }
  191. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_gpio_cnt %d\n",
  192. __func__, event, dmic_idx, *dmic_gpio_cnt);
  193. switch (event) {
  194. case SND_SOC_DAPM_PRE_PMU:
  195. (*dmic_gpio_cnt)++;
  196. if (*dmic_gpio_cnt == 1) {
  197. ret = msm_cdc_pinctrl_select_active_state(
  198. dmic_gpio);
  199. if (ret < 0) {
  200. pr_err("%s: gpio set cannot be activated %sd",
  201. __func__, "dmic_gpio");
  202. return ret;
  203. }
  204. }
  205. break;
  206. case SND_SOC_DAPM_POST_PMD:
  207. (*dmic_gpio_cnt)--;
  208. if (*dmic_gpio_cnt == 0) {
  209. ret = msm_cdc_pinctrl_select_sleep_state(
  210. dmic_gpio);
  211. if (ret < 0) {
  212. pr_err("%s: gpio set cannot be de-activated %sd",
  213. __func__, "dmic_gpio");
  214. return ret;
  215. }
  216. }
  217. break;
  218. default:
  219. pr_err("%s: invalid DAPM event %d\n", __func__, event);
  220. return -EINVAL;
  221. }
  222. return 0;
  223. }
  224. static const struct snd_soc_dapm_widget msm_int_dapm_widgets[] = {
  225. SND_SOC_DAPM_MIC("Analog Mic1", NULL),
  226. SND_SOC_DAPM_MIC("Analog Mic2", NULL),
  227. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  228. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  229. SND_SOC_DAPM_MIC("Digital Mic0", msm_dmic_event),
  230. SND_SOC_DAPM_MIC("Digital Mic1", msm_dmic_event),
  231. SND_SOC_DAPM_MIC("Digital Mic2", msm_dmic_event),
  232. SND_SOC_DAPM_MIC("Digital Mic3", msm_dmic_event),
  233. };
  234. static int msm_wcn_init(struct snd_soc_pcm_runtime *rtd)
  235. {
  236. unsigned int rx_ch[WCN_CDC_SLIM_RX_CH_MAX] = {157, 158};
  237. unsigned int tx_ch[WCN_CDC_SLIM_TX_CH_MAX] = {159, 160, 161};
  238. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  239. int ret = 0;
  240. ret = snd_soc_dai_set_channel_map(codec_dai, ARRAY_SIZE(tx_ch),
  241. tx_ch, ARRAY_SIZE(rx_ch), rx_ch);
  242. if (ret)
  243. return ret;
  244. msm_common_dai_link_init(rtd);
  245. return ret;
  246. }
  247. static struct snd_info_entry *msm_snd_info_create_subdir(struct module *mod,
  248. const char *name,
  249. struct snd_info_entry *parent)
  250. {
  251. struct snd_info_entry *entry;
  252. entry = snd_info_create_module_entry(mod, name, parent);
  253. if (!entry)
  254. return NULL;
  255. entry->mode = S_IFDIR | 0555;
  256. if (snd_info_register(entry) < 0) {
  257. snd_info_free_entry(entry);
  258. return NULL;
  259. }
  260. return entry;
  261. }
  262. static void *def_wcd_mbhc_cal(void)
  263. {
  264. void *wcd_mbhc_cal;
  265. struct wcd_mbhc_btn_detect_cfg *btn_cfg;
  266. u16 *btn_high;
  267. wcd_mbhc_cal = kzalloc(WCD_MBHC_CAL_SIZE(WCD_MBHC_DEF_BUTTONS,
  268. WCD9XXX_MBHC_DEF_RLOADS), GFP_KERNEL);
  269. if (!wcd_mbhc_cal)
  270. return NULL;
  271. WCD_MBHC_CAL_PLUG_TYPE_PTR(wcd_mbhc_cal)->v_hs_max = WCD_MBHC_HS_V_MAX;
  272. WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal)->num_btn = WCD_MBHC_DEF_BUTTONS;
  273. btn_cfg = WCD_MBHC_CAL_BTN_DET_PTR(wcd_mbhc_cal);
  274. btn_high = ((void *)&btn_cfg->_v_btn_low) +
  275. (sizeof(btn_cfg->_v_btn_low[0]) * btn_cfg->num_btn);
  276. btn_high[0] = 75;
  277. btn_high[1] = 150;
  278. btn_high[2] = 237;
  279. btn_high[3] = 500;
  280. btn_high[4] = 500;
  281. btn_high[5] = 500;
  282. btn_high[6] = 500;
  283. btn_high[7] = 500;
  284. return wcd_mbhc_cal;
  285. }
  286. static struct snd_soc_ops msm_common_be_ops = {
  287. .hw_params = msm_common_snd_hw_params,
  288. .startup = msm_common_snd_startup,
  289. .shutdown = msm_common_snd_shutdown,
  290. };
  291. static struct snd_soc_dai_link msm_common_be_dai_links[] = {
  292. /* Backend AFE DAI Links */
  293. #if 0
  294. /* Incall Record Uplink BACK END DAI Link */
  295. {
  296. .name = LPASS_BE_INCALL_RECORD_TX,
  297. .stream_name = "Voice Uplink Capture",
  298. .cpu_dai_name = "msm-dai-q6-dev.32772",
  299. .platform_name = "msm-pcm-routing",
  300. .codec_name = "msm-stub-codec.1",
  301. .codec_dai_name = "msm-stub-tx",
  302. .no_pcm = 1,
  303. .dpcm_capture = 1,
  304. .id = MSM_BACKEND_DAI_INCALL_RECORD_TX,
  305. .be_hw_params_fixup = msm_be_hw_params_fixup,
  306. .ignore_suspend = 1,
  307. },
  308. /* Incall Record Downlink BACK END DAI Link */
  309. {
  310. .name = LPASS_BE_INCALL_RECORD_RX,
  311. .stream_name = "Voice Downlink Capture",
  312. .cpu_dai_name = "msm-dai-q6-dev.32771",
  313. .platform_name = "msm-pcm-routing",
  314. .codec_name = "msm-stub-codec.1",
  315. .codec_dai_name = "msm-stub-tx",
  316. .no_pcm = 1,
  317. .dpcm_capture = 1,
  318. .id = MSM_BACKEND_DAI_INCALL_RECORD_RX,
  319. .be_hw_params_fixup = msm_be_hw_params_fixup,
  320. .ignore_suspend = 1,
  321. },
  322. /* Incall Music BACK END DAI Link */
  323. {
  324. .name = LPASS_BE_VOICE_PLAYBACK_TX,
  325. .stream_name = "Voice Farend Playback",
  326. .cpu_dai_name = "msm-dai-q6-dev.32773",
  327. .platform_name = "msm-pcm-routing",
  328. .codec_name = "msm-stub-codec.1",
  329. .codec_dai_name = "msm-stub-rx",
  330. .no_pcm = 1,
  331. .dpcm_playback = 1,
  332. .id = MSM_BACKEND_DAI_VOICE_PLAYBACK_TX,
  333. .be_hw_params_fixup = msm_be_hw_params_fixup,
  334. .ignore_suspend = 1,
  335. .ignore_pmdown_time = 1,
  336. },
  337. /* Incall Music 2 BACK END DAI Link */
  338. {
  339. .name = LPASS_BE_VOICE2_PLAYBACK_TX,
  340. .stream_name = "Voice2 Farend Playback",
  341. .cpu_dai_name = "msm-dai-q6-dev.32770",
  342. .platform_name = "msm-pcm-routing",
  343. .codec_name = "msm-stub-codec.1",
  344. .codec_dai_name = "msm-stub-rx",
  345. .no_pcm = 1,
  346. .dpcm_playback = 1,
  347. .id = MSM_BACKEND_DAI_VOICE2_PLAYBACK_TX,
  348. .be_hw_params_fixup = msm_be_hw_params_fixup,
  349. .ignore_suspend = 1,
  350. .ignore_pmdown_time = 1,
  351. },
  352. #endif
  353. /* Proxy Tx BACK END DAI Link */
  354. {
  355. .name = LPASS_BE_RT_PROXY_PCM_TX,
  356. .stream_name = LPASS_BE_RT_PROXY_PCM_TX,
  357. .capture_only = 1,
  358. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  359. SND_SOC_DPCM_TRIGGER_POST},
  360. .ignore_suspend = 1,
  361. .ops = &msm_common_be_ops,
  362. SND_SOC_DAILINK_REG(proxy_tx),
  363. },
  364. /* Proxy Rx BACK END DAI Link */
  365. {
  366. .name = LPASS_BE_RT_PROXY_PCM_RX,
  367. .stream_name = LPASS_BE_RT_PROXY_PCM_RX,
  368. .playback_only = 1,
  369. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  370. SND_SOC_DPCM_TRIGGER_POST},
  371. .ignore_pmdown_time = 1,
  372. .ignore_suspend = 1,
  373. .ops = &msm_common_be_ops,
  374. SND_SOC_DAILINK_REG(proxy_rx),
  375. },
  376. {
  377. .name = LPASS_BE_USB_AUDIO_RX,
  378. .stream_name = LPASS_BE_USB_AUDIO_RX,
  379. .playback_only = 1,
  380. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  381. SND_SOC_DPCM_TRIGGER_POST},
  382. .ignore_pmdown_time = 1,
  383. .ignore_suspend = 1,
  384. .ops = &msm_common_be_ops,
  385. SND_SOC_DAILINK_REG(usb_audio_rx),
  386. },
  387. {
  388. .name = LPASS_BE_USB_AUDIO_TX,
  389. .stream_name = LPASS_BE_USB_AUDIO_TX,
  390. .capture_only = 1,
  391. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  392. SND_SOC_DPCM_TRIGGER_POST},
  393. .ignore_suspend = 1,
  394. .ops = &msm_common_be_ops,
  395. SND_SOC_DAILINK_REG(usb_audio_tx),
  396. },
  397. };
  398. static struct snd_soc_dai_link msm_tdm_be_dai_links[] = {
  399. {
  400. .name = LPASS_BE_PRI_TDM_RX_0,
  401. .stream_name = LPASS_BE_PRI_TDM_RX_0,
  402. .playback_only = 1,
  403. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  404. SND_SOC_DPCM_TRIGGER_POST},
  405. .ops = &msm_common_be_ops,
  406. .ignore_suspend = 1,
  407. .ignore_pmdown_time = 1,
  408. SND_SOC_DAILINK_REG(pri_tdm_rx_0),
  409. },
  410. {
  411. .name = LPASS_BE_PRI_TDM_TX_0,
  412. .stream_name = LPASS_BE_PRI_TDM_TX_0,
  413. .capture_only = 1,
  414. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  415. SND_SOC_DPCM_TRIGGER_POST},
  416. .ops = &msm_common_be_ops,
  417. .ignore_suspend = 1,
  418. SND_SOC_DAILINK_REG(pri_tdm_tx_0),
  419. },
  420. {
  421. .name = LPASS_BE_SEC_TDM_RX_0,
  422. .stream_name = LPASS_BE_SEC_TDM_RX_0,
  423. .playback_only = 1,
  424. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  425. SND_SOC_DPCM_TRIGGER_POST},
  426. .ops = &msm_common_be_ops,
  427. .ignore_suspend = 1,
  428. .ignore_pmdown_time = 1,
  429. SND_SOC_DAILINK_REG(sec_tdm_rx_0),
  430. },
  431. {
  432. .name = LPASS_BE_SEC_TDM_TX_0,
  433. .stream_name = LPASS_BE_SEC_TDM_TX_0,
  434. .capture_only = 1,
  435. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  436. SND_SOC_DPCM_TRIGGER_POST},
  437. .ops = &msm_common_be_ops,
  438. .ignore_suspend = 1,
  439. SND_SOC_DAILINK_REG(sec_tdm_tx_0),
  440. },
  441. {
  442. .name = LPASS_BE_TERT_TDM_RX_0,
  443. .stream_name = LPASS_BE_TERT_TDM_RX_0,
  444. .playback_only = 1,
  445. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  446. SND_SOC_DPCM_TRIGGER_POST},
  447. .ops = &msm_common_be_ops,
  448. .ignore_suspend = 1,
  449. .ignore_pmdown_time = 1,
  450. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  451. },
  452. {
  453. .name = LPASS_BE_TERT_TDM_TX_0,
  454. .stream_name = LPASS_BE_TERT_TDM_TX_0,
  455. .capture_only = 1,
  456. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  457. SND_SOC_DPCM_TRIGGER_POST},
  458. .ops = &msm_common_be_ops,
  459. .ignore_suspend = 1,
  460. SND_SOC_DAILINK_REG(tert_tdm_tx_0),
  461. },
  462. {
  463. .name = LPASS_BE_QUAT_TDM_RX_0,
  464. .stream_name = LPASS_BE_QUAT_TDM_RX_0,
  465. .playback_only = 1,
  466. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  467. SND_SOC_DPCM_TRIGGER_POST},
  468. .ops = &msm_common_be_ops,
  469. .ignore_suspend = 1,
  470. .ignore_pmdown_time = 1,
  471. SND_SOC_DAILINK_REG(quat_tdm_rx_0),
  472. },
  473. {
  474. .name = LPASS_BE_QUAT_TDM_TX_0,
  475. .stream_name = LPASS_BE_QUAT_TDM_TX_0,
  476. .capture_only = 1,
  477. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  478. SND_SOC_DPCM_TRIGGER_POST},
  479. .ops = &msm_common_be_ops,
  480. .ignore_suspend = 1,
  481. SND_SOC_DAILINK_REG(quat_tdm_tx_0),
  482. },
  483. };
  484. static struct snd_soc_dai_link msm_wcn_btfm_be_dai_links[] = {
  485. {
  486. .name = LPASS_BE_SLIMBUS_7_RX,
  487. .stream_name = LPASS_BE_SLIMBUS_7_RX,
  488. .playback_only = 1,
  489. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  490. SND_SOC_DPCM_TRIGGER_POST},
  491. .init = &msm_wcn_init,
  492. .ops = &msm_common_be_ops,
  493. /* dai link has playback support */
  494. .ignore_pmdown_time = 1,
  495. .ignore_suspend = 1,
  496. SND_SOC_DAILINK_REG(slimbus_7_rx),
  497. },
  498. {
  499. .name = LPASS_BE_SLIMBUS_7_TX,
  500. .stream_name = LPASS_BE_SLIMBUS_7_TX,
  501. .capture_only = 1,
  502. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  503. SND_SOC_DPCM_TRIGGER_POST},
  504. .ops = &msm_common_be_ops,
  505. .ignore_suspend = 1,
  506. SND_SOC_DAILINK_REG(slimbus_7_tx),
  507. },
  508. {
  509. .name = LPASS_BE_SLIMBUS_8_TX,
  510. .stream_name = LPASS_BE_SLIMBUS_8_TX,
  511. .capture_only = 1,
  512. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  513. SND_SOC_DPCM_TRIGGER_POST},
  514. .ops = &msm_common_be_ops,
  515. .ignore_suspend = 1,
  516. SND_SOC_DAILINK_REG(slimbus_8_tx),
  517. },
  518. };
  519. static struct snd_soc_dai_link msm_mi2s_be_dai_links[] = {
  520. {
  521. .name = LPASS_BE_PRI_MI2S_RX,
  522. .stream_name = LPASS_BE_PRI_MI2S_RX,
  523. .playback_only = 1,
  524. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  525. SND_SOC_DPCM_TRIGGER_POST},
  526. .ops = &msm_common_be_ops,
  527. .ignore_suspend = 1,
  528. .ignore_pmdown_time = 1,
  529. SND_SOC_DAILINK_REG(pri_mi2s_rx),
  530. },
  531. {
  532. .name = LPASS_BE_PRI_MI2S_TX,
  533. .stream_name = LPASS_BE_PRI_MI2S_TX,
  534. .capture_only = 1,
  535. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  536. SND_SOC_DPCM_TRIGGER_POST},
  537. .ops = &msm_common_be_ops,
  538. .ignore_suspend = 1,
  539. SND_SOC_DAILINK_REG(pri_mi2s_tx),
  540. },
  541. {
  542. .name = LPASS_BE_SEC_MI2S_RX,
  543. .stream_name = LPASS_BE_SEC_MI2S_RX,
  544. .playback_only = 1,
  545. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  546. SND_SOC_DPCM_TRIGGER_POST},
  547. .ops = &msm_common_be_ops,
  548. .ignore_suspend = 1,
  549. .ignore_pmdown_time = 1,
  550. SND_SOC_DAILINK_REG(sec_mi2s_rx),
  551. },
  552. {
  553. .name = LPASS_BE_SEC_MI2S_TX,
  554. .stream_name = LPASS_BE_SEC_MI2S_TX,
  555. .capture_only = 1,
  556. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  557. SND_SOC_DPCM_TRIGGER_POST},
  558. .ops = &msm_common_be_ops,
  559. .ignore_suspend = 1,
  560. SND_SOC_DAILINK_REG(sec_mi2s_tx),
  561. },
  562. {
  563. .name = LPASS_BE_TERT_MI2S_RX,
  564. .stream_name = LPASS_BE_TERT_MI2S_RX,
  565. .playback_only = 1,
  566. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  567. SND_SOC_DPCM_TRIGGER_POST},
  568. .ops = &msm_common_be_ops,
  569. .ignore_suspend = 1,
  570. .ignore_pmdown_time = 1,
  571. SND_SOC_DAILINK_REG(tert_mi2s_rx),
  572. },
  573. {
  574. .name = LPASS_BE_TERT_MI2S_TX,
  575. .stream_name = LPASS_BE_TERT_MI2S_TX,
  576. .capture_only = 1,
  577. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  578. SND_SOC_DPCM_TRIGGER_POST},
  579. .ops = &msm_common_be_ops,
  580. .ignore_suspend = 1,
  581. SND_SOC_DAILINK_REG(tert_mi2s_tx),
  582. },
  583. {
  584. .name = LPASS_BE_QUAT_MI2S_RX,
  585. .stream_name = LPASS_BE_QUAT_MI2S_RX,
  586. .playback_only = 1,
  587. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  588. SND_SOC_DPCM_TRIGGER_POST},
  589. .ops = &msm_common_be_ops,
  590. .ignore_suspend = 1,
  591. .ignore_pmdown_time = 1,
  592. SND_SOC_DAILINK_REG(quat_mi2s_rx),
  593. },
  594. {
  595. .name = LPASS_BE_QUAT_MI2S_TX,
  596. .stream_name = LPASS_BE_QUAT_MI2S_TX,
  597. .capture_only = 1,
  598. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  599. SND_SOC_DPCM_TRIGGER_POST},
  600. .ops = &msm_common_be_ops,
  601. .ignore_suspend = 1,
  602. SND_SOC_DAILINK_REG(quat_mi2s_tx),
  603. },
  604. };
  605. static struct snd_soc_dai_link msm_auxpcm_be_dai_links[] = {
  606. /* Primary AUX PCM Backend DAI Links */
  607. {
  608. .name = LPASS_BE_PRI_AUXPCM_RX,
  609. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  610. .playback_only = 1,
  611. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  612. SND_SOC_DPCM_TRIGGER_POST},
  613. .ops = &msm_common_be_ops,// TODO for AUX
  614. .ignore_pmdown_time = 1,
  615. .ignore_suspend = 1,
  616. SND_SOC_DAILINK_REG(auxpcm_rx),
  617. },
  618. {
  619. .name = LPASS_BE_PRI_AUXPCM_TX,
  620. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  621. .capture_only = 1,
  622. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  623. SND_SOC_DPCM_TRIGGER_POST},
  624. .ops = &msm_common_be_ops,
  625. .ignore_suspend = 1,
  626. SND_SOC_DAILINK_REG(auxpcm_tx),
  627. },
  628. /* Secondary AUX PCM Backend DAI Links */
  629. {
  630. .name = LPASS_BE_SEC_AUXPCM_RX,
  631. .stream_name = LPASS_BE_SEC_AUXPCM_RX,
  632. .playback_only = 1,
  633. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  634. SND_SOC_DPCM_TRIGGER_POST},
  635. .ops = &msm_common_be_ops,// TODO for AUX
  636. .ignore_pmdown_time = 1,
  637. .ignore_suspend = 1,
  638. SND_SOC_DAILINK_REG(sec_auxpcm_rx),
  639. },
  640. {
  641. .name = LPASS_BE_SEC_AUXPCM_TX,
  642. .stream_name = LPASS_BE_SEC_AUXPCM_TX,
  643. .capture_only = 1,
  644. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  645. SND_SOC_DPCM_TRIGGER_POST},
  646. .ops = &msm_common_be_ops,
  647. .ignore_suspend = 1,
  648. SND_SOC_DAILINK_REG(sec_auxpcm_tx),
  649. },
  650. /* Tertiary AUX PCM Backend DAI Links */
  651. {
  652. .name = LPASS_BE_TERT_AUXPCM_RX,
  653. .stream_name = LPASS_BE_TERT_AUXPCM_RX,
  654. .playback_only = 1,
  655. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  656. SND_SOC_DPCM_TRIGGER_POST},
  657. .ops = &msm_common_be_ops,// TODO for AUX
  658. .ignore_suspend = 1,
  659. SND_SOC_DAILINK_REG(tert_auxpcm_rx),
  660. },
  661. {
  662. .name = LPASS_BE_TERT_AUXPCM_TX,
  663. .stream_name = LPASS_BE_TERT_AUXPCM_TX,
  664. .capture_only = 1,
  665. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  666. SND_SOC_DPCM_TRIGGER_POST},
  667. .ops = &msm_common_be_ops,
  668. .ignore_suspend = 1,
  669. SND_SOC_DAILINK_REG(tert_auxpcm_tx),
  670. },
  671. /* Quaternary AUX PCM Backend DAI Links */
  672. {
  673. .name = LPASS_BE_QUAT_AUXPCM_RX,
  674. .stream_name = LPASS_BE_QUAT_AUXPCM_RX,
  675. .playback_only = 1,
  676. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  677. SND_SOC_DPCM_TRIGGER_POST},
  678. .ops = &msm_common_be_ops,// TODO for AUX
  679. .ignore_suspend = 1,
  680. SND_SOC_DAILINK_REG(quat_auxpcm_rx),
  681. },
  682. {
  683. .name = LPASS_BE_QUAT_AUXPCM_TX,
  684. .stream_name = LPASS_BE_QUAT_AUXPCM_TX,
  685. .capture_only = 1,
  686. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  687. SND_SOC_DPCM_TRIGGER_POST},
  688. .ops = &msm_common_be_ops,
  689. .ignore_suspend = 1,
  690. SND_SOC_DAILINK_REG(quat_auxpcm_tx),
  691. },
  692. };
  693. static struct snd_soc_dai_link msm_rx_tx_cdc_dma_be_dai_links[] = {
  694. /* RX CDC DMA Backend DAI Links */
  695. {
  696. .name = LPASS_BE_RX_CDC_DMA_RX_0,
  697. .stream_name = LPASS_BE_RX_CDC_DMA_RX_0,
  698. .playback_only = 1,
  699. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  700. SND_SOC_DPCM_TRIGGER_POST},
  701. .ignore_pmdown_time = 1,
  702. .ignore_suspend = 1,
  703. .ops = &msm_common_be_ops,
  704. SND_SOC_DAILINK_REG(rx_dma_rx0),
  705. .init = &msm_rx_tx_codec_init,
  706. },
  707. {
  708. .name = LPASS_BE_RX_CDC_DMA_RX_1,
  709. .stream_name = LPASS_BE_RX_CDC_DMA_RX_1,
  710. .playback_only = 1,
  711. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  712. SND_SOC_DPCM_TRIGGER_POST},
  713. .ignore_pmdown_time = 1,
  714. .ignore_suspend = 1,
  715. .ops = &msm_common_be_ops,
  716. SND_SOC_DAILINK_REG(rx_dma_rx1),
  717. .init = &msm_int_wsa_init,
  718. },
  719. {
  720. .name = LPASS_BE_RX_CDC_DMA_RX_2,
  721. .stream_name = LPASS_BE_RX_CDC_DMA_RX_2,
  722. .playback_only = 1,
  723. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  724. SND_SOC_DPCM_TRIGGER_POST},
  725. .ignore_pmdown_time = 1,
  726. .ignore_suspend = 1,
  727. .ops = &msm_common_be_ops,
  728. SND_SOC_DAILINK_REG(rx_dma_rx2),
  729. },
  730. {
  731. .name = LPASS_BE_RX_CDC_DMA_RX_3,
  732. .stream_name = LPASS_BE_RX_CDC_DMA_RX_3,
  733. .playback_only = 1,
  734. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  735. SND_SOC_DPCM_TRIGGER_POST},
  736. .ignore_pmdown_time = 1,
  737. .ignore_suspend = 1,
  738. .ops = &msm_common_be_ops,
  739. SND_SOC_DAILINK_REG(rx_dma_rx3),
  740. },
  741. /* TX CDC DMA Backend DAI Links */
  742. {
  743. .name = LPASS_BE_TX_CDC_DMA_TX_3,
  744. .stream_name = LPASS_BE_TX_CDC_DMA_TX_3,
  745. .capture_only = 1,
  746. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  747. SND_SOC_DPCM_TRIGGER_POST},
  748. .ignore_suspend = 1,
  749. .ops = &msm_common_be_ops,
  750. SND_SOC_DAILINK_REG(tx_dma_tx3),
  751. },
  752. {
  753. .name = LPASS_BE_TX_CDC_DMA_TX_4,
  754. .stream_name = LPASS_BE_TX_CDC_DMA_TX_4,
  755. .capture_only = 1,
  756. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  757. SND_SOC_DPCM_TRIGGER_POST},
  758. .ignore_suspend = 1,
  759. .ops = &msm_common_be_ops,
  760. SND_SOC_DAILINK_REG(tx_dma_tx4),
  761. },
  762. };
  763. static struct snd_soc_dai_link msm_va_cdc_dma_be_dai_links[] = {
  764. {
  765. .name = LPASS_BE_VA_CDC_DMA_TX_0,
  766. .stream_name = LPASS_BE_VA_CDC_DMA_TX_0,
  767. .capture_only = 1,
  768. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  769. SND_SOC_DPCM_TRIGGER_POST},
  770. .ignore_suspend = 1,
  771. .ops = &msm_common_be_ops,
  772. SND_SOC_DAILINK_REG(va_dma_tx0),
  773. },
  774. {
  775. .name = LPASS_BE_VA_CDC_DMA_TX_1,
  776. .stream_name = LPASS_BE_VA_CDC_DMA_TX_1,
  777. .capture_only = 1,
  778. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  779. SND_SOC_DPCM_TRIGGER_POST},
  780. .ignore_suspend = 1,
  781. .ops = &msm_common_be_ops,
  782. SND_SOC_DAILINK_REG(va_dma_tx1),
  783. },
  784. {
  785. .name = LPASS_BE_VA_CDC_DMA_TX_2,
  786. .stream_name = LPASS_BE_VA_CDC_DMA_TX_2,
  787. .capture_only = 1,
  788. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  789. SND_SOC_DPCM_TRIGGER_POST},
  790. .ignore_suspend = 1,
  791. .ops = &msm_common_be_ops,
  792. SND_SOC_DAILINK_REG(va_dma_tx2),
  793. },
  794. };
  795. static struct snd_soc_dai_link msm_bengal_dai_links[
  796. ARRAY_SIZE(msm_common_be_dai_links) +
  797. ARRAY_SIZE(msm_mi2s_be_dai_links) +
  798. ARRAY_SIZE(msm_auxpcm_be_dai_links) +
  799. ARRAY_SIZE(msm_rx_tx_cdc_dma_be_dai_links) +
  800. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links) +
  801. ARRAY_SIZE(msm_wcn_btfm_be_dai_links) +
  802. ARRAY_SIZE(msm_tdm_be_dai_links)];
  803. static int msm_populate_dai_link_component_of_node(
  804. struct snd_soc_card *card)
  805. {
  806. int i, j, index, ret = 0;
  807. struct device *cdev = card->dev;
  808. struct snd_soc_dai_link *dai_link = card->dai_link;
  809. struct device_node *np = NULL;
  810. int codecs_enabled = 0;
  811. struct snd_soc_dai_link_component *codecs_comp = NULL;
  812. if (!cdev) {
  813. dev_err(cdev, "%s: Sound card device memory NULL\n", __func__);
  814. return -ENODEV;
  815. }
  816. for (i = 0; i < card->num_links; i++) {
  817. if (dai_link[i].init == NULL)
  818. dai_link[i].init = &msm_common_dai_link_init;
  819. /* populate codec_of_node for snd card dai links */
  820. if (dai_link[i].num_codecs > 0) {
  821. for (j = 0; j < dai_link[i].num_codecs; j++) {
  822. if (dai_link[i].codecs[j].of_node ||
  823. !dai_link[i].codecs[j].name)
  824. continue;
  825. index = of_property_match_string(cdev->of_node,
  826. "asoc-codec-names",
  827. dai_link[i].codecs[j].name);
  828. if (index < 0)
  829. continue;
  830. np = of_parse_phandle(cdev->of_node, "asoc-codec",
  831. index);
  832. if (!np) {
  833. dev_err(cdev,
  834. "%s: retrieving phandle for codec %s failed\n",
  835. __func__, dai_link[i].codecs[j].name);
  836. ret = -ENODEV;
  837. goto err;
  838. }
  839. dai_link[i].codecs[j].of_node = np;
  840. dai_link[i].codecs[j].name = NULL;
  841. }
  842. }
  843. }
  844. /* In multi-codec scenario, check if codecs are enabled for this platform */
  845. for (i = 0; i < card->num_links; i++) {
  846. codecs_enabled = 0;
  847. if (dai_link[i].num_codecs > 1) {
  848. for (j = 0; j < dai_link[i].num_codecs; j++) {
  849. if (!dai_link[i].codecs[j].of_node)
  850. continue;
  851. np = dai_link[i].codecs[j].of_node;
  852. if (!of_device_is_available(np)) {
  853. dev_dbg(cdev, "%s: codec is disabled: %s\n",
  854. __func__,np->full_name);
  855. dai_link[i].codecs[j].of_node = NULL;
  856. continue;
  857. }
  858. codecs_enabled++;
  859. }
  860. if (codecs_enabled > 0 &&
  861. codecs_enabled < dai_link[i].num_codecs) {
  862. codecs_comp = devm_kzalloc(cdev,
  863. sizeof(struct snd_soc_dai_link_component)
  864. * codecs_enabled, GFP_KERNEL);
  865. if (!codecs_comp) {
  866. dev_err(cdev, "%s: %s dailink codec component alloc failed\n",
  867. __func__, dai_link[i].name);
  868. ret = -ENOMEM;
  869. goto err;
  870. }
  871. index = 0;
  872. for (j = 0; j < dai_link[i].num_codecs; j++) {
  873. if(dai_link[i].codecs[j].of_node) {
  874. codecs_comp[index].of_node =
  875. dai_link[i].codecs[j].of_node;
  876. codecs_comp[index].dai_name =
  877. dai_link[i].codecs[j].dai_name;
  878. codecs_comp[index].name = NULL;
  879. index++;
  880. }
  881. }
  882. dai_link[i].codecs = codecs_comp;
  883. dai_link[i].num_codecs = codecs_enabled;
  884. }
  885. }
  886. }
  887. err:
  888. return ret;
  889. }
  890. struct snd_soc_card snd_soc_card_stub_msm = {
  891. .name = "bengal-stub-snd-card",
  892. };
  893. static int msm_audrx_stub_init(struct snd_soc_pcm_runtime *rtd)
  894. {
  895. return 0;
  896. }
  897. static int msm_snd_stub_hw_params(struct snd_pcm_substream *substream,
  898. struct snd_pcm_hw_params *params)
  899. {
  900. return 0;
  901. }
  902. static struct snd_soc_ops msm_stub_be_ops = {
  903. .hw_params = msm_snd_stub_hw_params,
  904. };
  905. static struct snd_soc_dai_link msm_stub_be_dai_links[] = {
  906. /* Backend DAI Links */
  907. {
  908. .name = LPASS_BE_PRI_AUXPCM_RX,
  909. .stream_name = LPASS_BE_PRI_AUXPCM_RX,
  910. .playback_only = 1,
  911. .init = &msm_audrx_stub_init,
  912. .ignore_pmdown_time = 1,
  913. .ignore_suspend = 1,
  914. .ops = &msm_stub_be_ops,
  915. SND_SOC_DAILINK_REG(auxpcm_rx),
  916. },
  917. {
  918. .name = LPASS_BE_PRI_AUXPCM_TX,
  919. .stream_name = LPASS_BE_PRI_AUXPCM_TX,
  920. .capture_only = 1,
  921. .ignore_suspend = 1,
  922. .ops = &msm_stub_be_ops,
  923. SND_SOC_DAILINK_REG(auxpcm_tx),
  924. },
  925. };
  926. static struct snd_soc_dai_link msm_stub_dai_links[
  927. ARRAY_SIZE(msm_stub_be_dai_links)];
  928. static struct snd_soc_card snd_soc_card_bengal_msm;
  929. static const struct of_device_id bengal_asoc_machine_of_match[] = {
  930. { .compatible = "qcom,bengal-asoc-snd",
  931. .data = "codec"},
  932. { .compatible = "qcom,bengal-asoc-snd-stub",
  933. .data = "stub_codec"},
  934. {},
  935. };
  936. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  937. {
  938. struct snd_soc_card *card = NULL;
  939. struct snd_soc_dai_link *dailink = NULL;
  940. int total_links = 0;
  941. int len_1 = 0;
  942. int rc = 0;
  943. u32 mi2s_audio_intf = 0;
  944. u32 auxpcm_audio_intf = 0;
  945. u32 rxtx_bolero_codec = 0;
  946. u32 va_bolero_codec = 0;
  947. u32 val = 0;
  948. u32 wcn_btfm_intf = 0;
  949. const struct of_device_id *match;
  950. match = of_match_node(bengal_asoc_machine_of_match, dev->of_node);
  951. if (!match) {
  952. dev_err(dev, "%s: No DT match found for sound card\n",
  953. __func__);
  954. return NULL;
  955. }
  956. if (!strcmp(match->data, "codec")) {
  957. card = &snd_soc_card_bengal_msm;
  958. memcpy(msm_bengal_dai_links + total_links,
  959. msm_common_be_dai_links,
  960. sizeof(msm_common_be_dai_links));
  961. total_links += ARRAY_SIZE(msm_common_be_dai_links);
  962. rc = of_property_read_u32(dev->of_node,
  963. "qcom,rxtx-bolero-codec",
  964. &rxtx_bolero_codec);
  965. if (rc) {
  966. dev_dbg(dev, "%s: No DT match RXTX Macro codec\n",
  967. __func__);
  968. } else {
  969. if (rxtx_bolero_codec) {
  970. memcpy(msm_bengal_dai_links + total_links,
  971. msm_rx_tx_cdc_dma_be_dai_links,
  972. sizeof(msm_rx_tx_cdc_dma_be_dai_links));
  973. total_links +=
  974. ARRAY_SIZE(
  975. msm_rx_tx_cdc_dma_be_dai_links);
  976. }
  977. }
  978. rc = of_property_read_u32(dev->of_node, "qcom,va-bolero-codec",
  979. &va_bolero_codec);
  980. if (rc) {
  981. dev_dbg(dev, "%s: No DT match VA Macro codec\n",
  982. __func__);
  983. } else {
  984. if (va_bolero_codec) {
  985. memcpy(msm_bengal_dai_links + total_links,
  986. msm_va_cdc_dma_be_dai_links,
  987. sizeof(msm_va_cdc_dma_be_dai_links));
  988. total_links +=
  989. ARRAY_SIZE(msm_va_cdc_dma_be_dai_links);
  990. }
  991. }
  992. rc = of_property_read_u32(dev->of_node, "qcom,mi2s-audio-intf",
  993. &mi2s_audio_intf);
  994. if (rc) {
  995. dev_dbg(dev, "%s: No DT match MI2S audio interface\n",
  996. __func__);
  997. } else {
  998. if (mi2s_audio_intf) {
  999. memcpy(msm_bengal_dai_links + total_links,
  1000. msm_mi2s_be_dai_links,
  1001. sizeof(msm_mi2s_be_dai_links));
  1002. total_links +=
  1003. ARRAY_SIZE(msm_mi2s_be_dai_links);
  1004. }
  1005. }
  1006. rc = of_property_read_u32(dev->of_node,
  1007. "qcom,auxpcm-audio-intf",
  1008. &auxpcm_audio_intf);
  1009. if (rc) {
  1010. dev_dbg(dev, "%s: No DT match Aux PCM interface\n",
  1011. __func__);
  1012. } else {
  1013. if (auxpcm_audio_intf) {
  1014. memcpy(msm_bengal_dai_links + total_links,
  1015. msm_auxpcm_be_dai_links,
  1016. sizeof(msm_auxpcm_be_dai_links));
  1017. total_links +=
  1018. ARRAY_SIZE(msm_auxpcm_be_dai_links);
  1019. }
  1020. }
  1021. rc = of_property_read_u32(dev->of_node, "qcom,tdm-audio-intf",
  1022. &val);
  1023. if (!rc && val) {
  1024. memcpy(msm_bengal_dai_links + total_links,
  1025. msm_tdm_be_dai_links,
  1026. sizeof(msm_tdm_be_dai_links));
  1027. total_links +=
  1028. ARRAY_SIZE(msm_tdm_be_dai_links);
  1029. }
  1030. rc = of_property_read_u32(dev->of_node, "qcom,wcn-btfm",
  1031. &wcn_btfm_intf);
  1032. if (rc) {
  1033. dev_dbg(dev, "%s: No DT match wcn btfm interface\n",
  1034. __func__);
  1035. } else {
  1036. if (wcn_btfm_intf) {
  1037. memcpy(msm_bengal_dai_links + total_links,
  1038. msm_wcn_btfm_be_dai_links,
  1039. sizeof(msm_wcn_btfm_be_dai_links));
  1040. total_links +=
  1041. ARRAY_SIZE(msm_wcn_btfm_be_dai_links);
  1042. }
  1043. }
  1044. dailink = msm_bengal_dai_links;
  1045. }
  1046. else if (!strcmp(match->data, "stub_codec")) {
  1047. card = &snd_soc_card_stub_msm;
  1048. len_1 = ARRAY_SIZE(msm_stub_be_dai_links);
  1049. memcpy(msm_stub_dai_links + len_1,
  1050. msm_stub_be_dai_links,
  1051. sizeof(msm_stub_be_dai_links));
  1052. dailink = msm_stub_dai_links;
  1053. total_links = len_1;
  1054. }
  1055. if (card) {
  1056. card->dai_link = dailink;
  1057. card->num_links = total_links;
  1058. }
  1059. return card;
  1060. }
  1061. static int msm_rx_tx_codec_init(struct snd_soc_pcm_runtime *rtd)
  1062. {
  1063. struct snd_soc_component *bolero_component = NULL;
  1064. struct snd_soc_component *component = NULL;
  1065. struct snd_soc_dapm_context *dapm = NULL;
  1066. int ret = 0;
  1067. void *mbhc_calibration;
  1068. struct snd_info_entry *entry;
  1069. struct snd_card *card = NULL;
  1070. struct msm_asoc_mach_data *pdata =
  1071. snd_soc_card_get_drvdata(rtd->card);
  1072. pr_err("%s:: enter \n", __func__);
  1073. bolero_component = snd_soc_rtdcom_lookup(rtd, "bolero_codec");
  1074. if (!bolero_component) {
  1075. pr_err("%s: could not find component for bolero_codec\n",
  1076. __func__);
  1077. return -EINVAL;
  1078. }
  1079. pr_err("%s:: bolero comp lookup done\n", __func__);
  1080. dapm = snd_soc_component_get_dapm(bolero_component);
  1081. snd_soc_dapm_new_controls(dapm, msm_int_dapm_widgets,
  1082. ARRAY_SIZE(msm_int_dapm_widgets));
  1083. pr_err("%s:: dapm new controls msm_int_dapm_widgets \n", __func__);
  1084. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic0");
  1085. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic1");
  1086. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic2");
  1087. snd_soc_dapm_ignore_suspend(dapm, "Digital Mic3");
  1088. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic1");
  1089. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic2");
  1090. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic3");
  1091. snd_soc_dapm_ignore_suspend(dapm, "Analog Mic4");
  1092. snd_soc_dapm_sync(dapm);
  1093. card = rtd->card->snd_card;
  1094. if (!pdata->codec_root) {
  1095. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1096. card->proc_root);
  1097. if (!entry) {
  1098. pr_debug("%s: Cannot create codecs module entry\n",
  1099. __func__);
  1100. ret = 0;
  1101. goto err;
  1102. }
  1103. pdata->codec_root = entry;
  1104. }
  1105. bolero_info_create_codec_entry(pdata->codec_root, bolero_component);
  1106. bolero_register_wake_irq(bolero_component, false);
  1107. component = snd_soc_rtdcom_lookup(rtd, WCD937X_DRV_NAME);
  1108. if (!component)
  1109. component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
  1110. if (!component) {
  1111. pr_err("%s component is NULL\n", __func__);
  1112. return -EINVAL;
  1113. }
  1114. dapm = snd_soc_component_get_dapm(component);
  1115. card = component->card->snd_card;
  1116. pdata = snd_soc_card_get_drvdata(component->card);
  1117. if (!pdata)
  1118. return -EINVAL;
  1119. if (!pdata->codec_root) {
  1120. entry = msm_snd_info_create_subdir(card->module, "codecs",
  1121. card->proc_root);
  1122. if (!entry) {
  1123. dev_dbg(component->dev, "%s: Cannot create codecs module entry\n",
  1124. __func__);
  1125. ret = 0;
  1126. goto mbhc_cfg_cal;
  1127. }
  1128. pdata->codec_root = entry;
  1129. }
  1130. if (!strncmp(component->driver->name, WCD937X_DRV_NAME, 13)) {
  1131. wcd937x_info_create_codec_entry(pdata->codec_root, component);
  1132. bolero_set_port_map(bolero_component,
  1133. ARRAY_SIZE(sm_port_map),
  1134. sm_port_map);
  1135. }
  1136. snd_soc_dapm_ignore_suspend(dapm, "EAR");
  1137. snd_soc_dapm_ignore_suspend(dapm, "AUX");
  1138. snd_soc_dapm_ignore_suspend(dapm, "LO");
  1139. snd_soc_dapm_ignore_suspend(dapm, "HPHL");
  1140. snd_soc_dapm_ignore_suspend(dapm, "HPHR");
  1141. snd_soc_dapm_ignore_suspend(dapm, "AMIC1");
  1142. snd_soc_dapm_ignore_suspend(dapm, "AMIC2");
  1143. snd_soc_dapm_ignore_suspend(dapm, "AMIC3");
  1144. snd_soc_dapm_ignore_suspend(dapm, "AMIC4");
  1145. snd_soc_dapm_sync(dapm);
  1146. codec_reg_done = true;
  1147. msm_common_dai_link_init(rtd);
  1148. mbhc_cfg_cal:
  1149. if (!strncmp(component->driver->name, WCD937X_DRV_NAME, 13)) {
  1150. mbhc_calibration = def_wcd_mbhc_cal();
  1151. if (!mbhc_calibration)
  1152. return -ENOMEM;
  1153. wcd_mbhc_cfg.calibration = mbhc_calibration;
  1154. ret = wcd937x_mbhc_hs_detect(component, &wcd_mbhc_cfg);
  1155. }
  1156. if (ret) {
  1157. dev_err(component->dev, "%s: mbhc hs detect failed, err:%d\n",
  1158. __func__, ret);
  1159. goto err_hs_detect;
  1160. }
  1161. return 0;
  1162. err_hs_detect:
  1163. kfree(mbhc_calibration);
  1164. err:
  1165. pr_err("%s:: return %d \n", __func__, ret);
  1166. return ret;
  1167. }
  1168. static int msm_int_wsa_init(struct snd_soc_pcm_runtime *rtd)
  1169. {
  1170. struct msm_asoc_mach_data *pdata =
  1171. snd_soc_card_get_drvdata(rtd->card);
  1172. int ret = 0;
  1173. if (pdata->wsa_max_devs == 0)
  1174. pr_info("%s: WSA is not enabled\n", __func__);
  1175. msm_common_dai_link_init(rtd);
  1176. return ret;
  1177. }
  1178. static int bengal_ssr_enable(struct device *dev, void *data)
  1179. {
  1180. struct platform_device *pdev = to_platform_device(dev);
  1181. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1182. int ret = 0;
  1183. if (!card) {
  1184. dev_err_ratelimited(dev, "%s: card is NULL\n", __func__);
  1185. ret = -EINVAL;
  1186. goto err;
  1187. }
  1188. if (!strcmp(card->name, "bengal-stub-snd-card")) {
  1189. /* TODO */
  1190. dev_dbg(dev, "%s: TODO\n", __func__);
  1191. }
  1192. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  1193. dev_dbg(dev, "%s: setting snd_card to ONLINE\n", __func__);
  1194. err:
  1195. return ret;
  1196. }
  1197. static void bengal_ssr_disable(struct device *dev, void *data)
  1198. {
  1199. struct platform_device *pdev = to_platform_device(dev);
  1200. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1201. if (!card) {
  1202. dev_err(dev, "%s: card is NULL\n", __func__);
  1203. return;
  1204. }
  1205. dev_dbg(dev, "%s: setting snd_card to OFFLINE\n", __func__);
  1206. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  1207. if (!strcmp(card->name, "bengal-stub-snd-card")) {
  1208. /* TODO */
  1209. dev_dbg(dev, "%s: TODO\n", __func__);
  1210. }
  1211. }
  1212. static const struct snd_event_ops bengal_ssr_ops = {
  1213. .enable = bengal_ssr_enable,
  1214. .disable = bengal_ssr_disable,
  1215. };
  1216. static int msm_audio_ssr_compare(struct device *dev, void *data)
  1217. {
  1218. struct device_node *node = data;
  1219. dev_dbg(dev, "%s: dev->of_node = 0x%p, node = 0x%p\n",
  1220. __func__, dev->of_node, node);
  1221. return (dev->of_node && dev->of_node == node);
  1222. }
  1223. static int msm_audio_ssr_register(struct device *dev)
  1224. {
  1225. struct device_node *np = dev->of_node;
  1226. struct snd_event_clients *ssr_clients = NULL;
  1227. struct device_node *node = NULL;
  1228. int ret = 0;
  1229. int i = 0;
  1230. for (i = 0; ; i++) {
  1231. node = of_parse_phandle(np, "qcom,msm_audio_ssr_devs", i);
  1232. if (!node)
  1233. break;
  1234. snd_event_mstr_add_client(&ssr_clients,
  1235. msm_audio_ssr_compare, node);
  1236. }
  1237. ret = snd_event_master_register(dev, &bengal_ssr_ops,
  1238. ssr_clients, NULL);
  1239. if (!ret)
  1240. snd_event_notify(dev, SND_EVENT_UP);
  1241. return ret;
  1242. }
  1243. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  1244. {
  1245. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1246. if (!pdata)
  1247. return NULL;
  1248. return pdata->common_pdata;
  1249. }
  1250. void msm_common_set_pdata(struct snd_soc_card *card,
  1251. struct msm_common_pdata *common_pdata)
  1252. {
  1253. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  1254. if (!pdata)
  1255. return;
  1256. pdata->common_pdata = common_pdata;
  1257. }
  1258. static int msm_asoc_machine_probe(struct platform_device *pdev)
  1259. {
  1260. struct snd_soc_card *card = NULL;
  1261. struct msm_asoc_mach_data *pdata = NULL;
  1262. const char *mbhc_audio_jack_type = NULL;
  1263. int ret = 0;
  1264. uint index = 0;
  1265. struct nvmem_cell *cell;
  1266. size_t len;
  1267. u32 *buf;
  1268. u32 adsp_var_idx = 0;
  1269. if (!pdev->dev.of_node) {
  1270. dev_err(&pdev->dev,
  1271. "%s: No platform supplied from device tree\n",
  1272. __func__);
  1273. return -EINVAL;
  1274. }
  1275. pdata = devm_kzalloc(&pdev->dev,
  1276. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  1277. if (!pdata)
  1278. return -ENOMEM;
  1279. card = populate_snd_card_dailinks(&pdev->dev);
  1280. if (!card) {
  1281. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  1282. ret = -EINVAL;
  1283. goto err;
  1284. }
  1285. card->dev = &pdev->dev;
  1286. platform_set_drvdata(pdev, card);
  1287. snd_soc_card_set_drvdata(card, pdata);
  1288. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  1289. if (ret) {
  1290. dev_err(&pdev->dev, "%s: parse card name failed, err:%d\n",
  1291. __func__, ret);
  1292. goto err;
  1293. }
  1294. ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
  1295. if (ret) {
  1296. dev_err(&pdev->dev, "%s: parse audio routing failed, err:%d\n",
  1297. __func__, ret);
  1298. goto err;
  1299. }
  1300. ret = msm_populate_dai_link_component_of_node(card);
  1301. if (ret) {
  1302. ret = -EPROBE_DEFER;
  1303. goto err;
  1304. }
  1305. /* Get maximum WSA device count for this platform */
  1306. ret = of_property_read_u32(pdev->dev.of_node,
  1307. "qcom,wsa-max-devs", &pdata->wsa_max_devs);
  1308. if (ret) {
  1309. dev_info(&pdev->dev,
  1310. "%s: wsa-max-devs property missing in DT %s, ret = %d\n",
  1311. __func__, pdev->dev.of_node->full_name, ret);
  1312. pdata->wsa_max_devs = 0;
  1313. }
  1314. /* Make sure prefix string passed for each WSA device */
  1315. ret = of_property_count_strings(pdev->dev.of_node,
  1316. "qcom,wsa-aux-dev-prefix");
  1317. if (!ret) {
  1318. dev_err(&pdev->dev,
  1319. "property %s not defined in DT\n",
  1320. __func__, "qcom,wsa-aux-dev-prefix");
  1321. }
  1322. ret = devm_snd_soc_register_card(&pdev->dev, card);
  1323. if (ret == -EPROBE_DEFER) {
  1324. if (codec_reg_done)
  1325. ret = -EINVAL;
  1326. goto err;
  1327. } else if (ret) {
  1328. dev_err(&pdev->dev, "%s: snd_soc_register_card failed (%d)\n",
  1329. __func__, ret);
  1330. goto err;
  1331. }
  1332. dev_info(&pdev->dev, "%s: Sound card %s registered\n",
  1333. __func__, card->name);
  1334. pdata->hph_en1_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1335. "qcom,hph-en1-gpio", 0);
  1336. if (!pdata->hph_en1_gpio_p) {
  1337. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1338. __func__, "qcom,hph-en1-gpio",
  1339. pdev->dev.of_node->full_name);
  1340. }
  1341. pdata->hph_en0_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1342. "qcom,hph-en0-gpio", 0);
  1343. if (!pdata->hph_en0_gpio_p) {
  1344. dev_dbg(&pdev->dev, "%s: property %s not detected in node %s\n",
  1345. __func__, "qcom,hph-en0-gpio",
  1346. pdev->dev.of_node->full_name);
  1347. }
  1348. ret = of_property_read_string(pdev->dev.of_node,
  1349. "qcom,mbhc-audio-jack-type", &mbhc_audio_jack_type);
  1350. if (ret) {
  1351. dev_dbg(&pdev->dev, "%s: Looking up %s property in node %s failed\n",
  1352. __func__, "qcom,mbhc-audio-jack-type",
  1353. pdev->dev.of_node->full_name);
  1354. dev_dbg(&pdev->dev, "Jack type properties set to default\n");
  1355. } else {
  1356. if (!strcmp(mbhc_audio_jack_type, "4-pole-jack")) {
  1357. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1358. dev_dbg(&pdev->dev, "This hardware has 4 pole jack");
  1359. } else if (!strcmp(mbhc_audio_jack_type, "5-pole-jack")) {
  1360. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1361. dev_dbg(&pdev->dev, "This hardware has 5 pole jack");
  1362. } else if (!strcmp(mbhc_audio_jack_type, "6-pole-jack")) {
  1363. wcd_mbhc_cfg.enable_anc_mic_detect = true;
  1364. dev_dbg(&pdev->dev, "This hardware has 6 pole jack");
  1365. } else {
  1366. wcd_mbhc_cfg.enable_anc_mic_detect = false;
  1367. dev_dbg(&pdev->dev, "Unknown value, set to default\n");
  1368. }
  1369. }
  1370. /*
  1371. * Parse US-Euro gpio info from DT. Report no error if us-euro
  1372. * entry is not found in DT file as some targets do not support
  1373. * US-Euro detection
  1374. */
  1375. pdata->us_euro_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1376. "qcom,us-euro-gpios", 0);
  1377. if (!pdata->us_euro_gpio_p) {
  1378. dev_dbg(&pdev->dev, "property %s not detected in node %s",
  1379. "qcom,us-euro-gpios", pdev->dev.of_node->full_name);
  1380. } else {
  1381. dev_dbg(&pdev->dev, "%s detected\n",
  1382. "qcom,us-euro-gpios");
  1383. wcd_mbhc_cfg.swap_gnd_mic = msm_swap_gnd_mic;
  1384. }
  1385. if (wcd_mbhc_cfg.enable_usbc_analog)
  1386. wcd_mbhc_cfg.swap_gnd_mic = msm_usbc_swap_gnd_mic;
  1387. pdata->fsa_handle = of_parse_phandle(pdev->dev.of_node,
  1388. "fsa4480-i2c-handle", 0);
  1389. if (!pdata->fsa_handle)
  1390. dev_dbg(&pdev->dev, "property %s not detected in node %s\n",
  1391. "fsa4480-i2c-handle", pdev->dev.of_node->full_name);
  1392. pdata->dmic01_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1393. "qcom,cdc-dmic01-gpios",
  1394. 0);
  1395. pdata->dmic23_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1396. "qcom,cdc-dmic23-gpios",
  1397. 0);
  1398. pdata->mi2s_gpio_p[PRIM_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1399. "qcom,pri-mi2s-gpios", 0);
  1400. pdata->mi2s_gpio_p[SEC_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1401. "qcom,sec-mi2s-gpios", 0);
  1402. pdata->mi2s_gpio_p[TERT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1403. "qcom,tert-mi2s-gpios", 0);
  1404. pdata->mi2s_gpio_p[QUAT_MI2S] = of_parse_phandle(pdev->dev.of_node,
  1405. "qcom,quat-mi2s-gpios", 0);
  1406. for (index = PRIM_MI2S; index < MI2S_MAX; index++)
  1407. atomic_set(&(pdata->mi2s_gpio_ref_count[index]), 0);
  1408. msm_common_snd_init(pdev, card);
  1409. ret = msm_audio_ssr_register(&pdev->dev);
  1410. if (ret)
  1411. pr_err("%s: Registration with SND event FWK failed ret = %d\n",
  1412. __func__, ret);
  1413. is_initial_boot = true;
  1414. /* get adsp variant idx */
  1415. cell = nvmem_cell_get(&pdev->dev, "adsp_variant");
  1416. if (IS_ERR_OR_NULL(cell)) {
  1417. dev_dbg(&pdev->dev, "%s: FAILED to get nvmem cell \n", __func__);
  1418. goto ret;
  1419. }
  1420. buf = nvmem_cell_read(cell, &len);
  1421. nvmem_cell_put(cell);
  1422. if (IS_ERR_OR_NULL(buf)) {
  1423. dev_dbg(&pdev->dev, "%s: FAILED to read nvmem cell \n", __func__);
  1424. goto ret;
  1425. }
  1426. if (len <= 0 || len > sizeof(u32)) {
  1427. dev_dbg(&pdev->dev, "%s: nvmem cell length out of range: %d\n",
  1428. __func__, len);
  1429. kfree(buf);
  1430. goto ret;
  1431. }
  1432. memcpy(&adsp_var_idx, buf, len);
  1433. kfree(buf);
  1434. va_disable = adsp_var_idx;
  1435. ret:
  1436. return 0;
  1437. err:
  1438. devm_kfree(&pdev->dev, pdata);
  1439. return ret;
  1440. }
  1441. static int msm_asoc_machine_remove(struct platform_device *pdev)
  1442. {
  1443. struct snd_soc_card *card = platform_get_drvdata(pdev);
  1444. struct msm_asoc_mach_data *pdata = NULL;
  1445. struct msm_common_pdata *common_pdata = NULL;
  1446. if (card)
  1447. pdata = snd_soc_card_get_drvdata(card);
  1448. if (pdata)
  1449. common_pdata = pdata->common_pdata;
  1450. msm_common_snd_deinit(common_pdata);
  1451. snd_event_master_deregister(&pdev->dev);
  1452. snd_soc_unregister_card(card);
  1453. return 0;
  1454. }
  1455. static struct platform_driver bengal_asoc_machine_driver = {
  1456. .driver = {
  1457. .name = DRV_NAME,
  1458. .owner = THIS_MODULE,
  1459. .pm = &snd_soc_pm_ops,
  1460. .of_match_table = bengal_asoc_machine_of_match,
  1461. .suppress_bind_attrs = true,
  1462. },
  1463. .probe = msm_asoc_machine_probe,
  1464. .remove = msm_asoc_machine_remove,
  1465. };
  1466. static int __init msm_asoc_machine_init(void)
  1467. {
  1468. snd_card_sysfs_init();
  1469. return platform_driver_register(&bengal_asoc_machine_driver);
  1470. }
  1471. module_init(msm_asoc_machine_init);
  1472. static void __exit msm_asoc_machine_exit(void)
  1473. {
  1474. platform_driver_unregister(&bengal_asoc_machine_driver);
  1475. }
  1476. module_exit(msm_asoc_machine_exit);
  1477. MODULE_DESCRIPTION("ALSA SoC msm");
  1478. MODULE_LICENSE("GPL v2");
  1479. MODULE_ALIAS("platform:" DRV_NAME);
  1480. MODULE_DEVICE_TABLE(of, bengal_asoc_machine_of_match);