gvm_auto_spf_dummy.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. 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/pm_qos.h>
  16. #include <sound/core.h>
  17. #include <sound/soc.h>
  18. #include <sound/soc-dapm.h>
  19. #include <sound/pcm.h>
  20. #include <sound/pcm_params.h>
  21. #include <sound/info.h>
  22. #include <dsp/audio_notifier.h>
  23. #include "msm_dailink.h"
  24. #include <soc/qcom/boot_stats.h>
  25. #include "msm_common.h"
  26. #include <linux/cdev.h>
  27. #include <linux/err.h>
  28. #define DRV_NAME "spf-asoc-snd"
  29. #define __CHIPSET__ "SA8xx5 "
  30. #define MSM_DAILINK_NAME(name) (__CHIPSET__#name)
  31. #define DEV_NAME_STR_LEN 32
  32. #define SAMPLING_RATE_8KHZ 8000
  33. #define SAMPLING_RATE_11P025KHZ 11025
  34. #define SAMPLING_RATE_16KHZ 16000
  35. #define SAMPLING_RATE_22P05KHZ 22050
  36. #define SAMPLING_RATE_32KHZ 32000
  37. #define SAMPLING_RATE_44P1KHZ 44100
  38. #define SAMPLING_RATE_48KHZ 48000
  39. #define SAMPLING_RATE_88P2KHZ 88200
  40. #define SAMPLING_RATE_96KHZ 96000
  41. #define SAMPLING_RATE_176P4KHZ 176400
  42. #define SAMPLING_RATE_192KHZ 192000
  43. #define SAMPLING_RATE_352P8KHZ 352800
  44. #define SAMPLING_RATE_384KHZ 384000
  45. #define WCD9XXX_MBHC_DEF_RLOADS 5
  46. #define WSA8810_NAME_1 "wsa881x.20170211"
  47. #define WSA8810_NAME_2 "wsa881x.20170212"
  48. #define WCN_CDC_SLIM_RX_CH_MAX 2
  49. #define WCN_CDC_SLIM_TX_CH_MAX 3
  50. #define TDM_CHANNEL_MAX 8
  51. #define ADSP_STATE_READY_TIMEOUT_MS 3000
  52. #define MSM_LL_QOS_VALUE 300 /* time in us to ensure LPM doesn't go in C3/C4 */
  53. #define MSM_HIFI_ON 1
  54. #define DIR_SZ 10
  55. #define AUTO_VIRT_SNDCARD_ONLINE 0
  56. #define AUTO_VIRT_SNDCARD_OFFLINE 1
  57. struct snd_card_pdata {
  58. struct kobject snd_card_kobj;
  59. int card_status;
  60. } *snd_card_pdata;
  61. static struct attribute card_state_attr = {
  62. .name = "card_state",
  63. .mode = 0666,
  64. };
  65. enum {
  66. SLIM_RX_0 = 0,
  67. SLIM_RX_1,
  68. SLIM_RX_2,
  69. SLIM_RX_3,
  70. SLIM_RX_4,
  71. SLIM_RX_5,
  72. SLIM_RX_6,
  73. SLIM_RX_7,
  74. SLIM_RX_MAX,
  75. };
  76. enum {
  77. SLIM_TX_0 = 0,
  78. SLIM_TX_1,
  79. SLIM_TX_2,
  80. SLIM_TX_3,
  81. SLIM_TX_4,
  82. SLIM_TX_5,
  83. SLIM_TX_6,
  84. SLIM_TX_7,
  85. SLIM_TX_8,
  86. SLIM_TX_MAX,
  87. };
  88. enum {
  89. PRIM_MI2S = 0,
  90. SEC_MI2S,
  91. TERT_MI2S,
  92. QUAT_MI2S,
  93. QUIN_MI2S,
  94. MI2S_MAX,
  95. };
  96. enum {
  97. PRIM_AUX_PCM = 0,
  98. SEC_AUX_PCM,
  99. TERT_AUX_PCM,
  100. QUAT_AUX_PCM,
  101. QUIN_AUX_PCM,
  102. AUX_PCM_MAX,
  103. };
  104. struct mi2s_conf {
  105. struct mutex lock;
  106. u32 ref_cnt;
  107. u32 msm_is_mi2s_master;
  108. };
  109. struct dev_config {
  110. u32 sample_rate;
  111. u32 bit_format;
  112. u32 channels;
  113. };
  114. enum {
  115. DP_RX_IDX = 0,
  116. EXT_DISP_RX_IDX_MAX,
  117. };
  118. struct msm_wsa881x_dev_info {
  119. struct device_node *of_node;
  120. u32 index;
  121. };
  122. enum pinctrl_pin_state {
  123. STATE_DISABLE = 0, /* All pins are in sleep state */
  124. STATE_MI2S_ACTIVE, /* IS2 = active, TDM = sleep */
  125. STATE_TDM_ACTIVE, /* IS2 = sleep, TDM = active */
  126. };
  127. struct msm_pinctrl_info {
  128. struct pinctrl *pinctrl;
  129. struct pinctrl_state *mi2s_disable;
  130. struct pinctrl_state *tdm_disable;
  131. struct pinctrl_state *mi2s_active;
  132. struct pinctrl_state *tdm_active;
  133. enum pinctrl_pin_state curr_state;
  134. };
  135. enum {
  136. TDM_0 = 0,
  137. TDM_1,
  138. TDM_2,
  139. TDM_3,
  140. TDM_4,
  141. TDM_5,
  142. TDM_6,
  143. TDM_7,
  144. TDM_PORT_MAX,
  145. };
  146. enum {
  147. TDM_PRI = 0,
  148. TDM_SEC,
  149. TDM_TERT,
  150. TDM_QUAT,
  151. TDM_QUIN,
  152. TDM_INTERFACE_MAX,
  153. };
  154. struct tdm_port {
  155. u32 mode;
  156. u32 channel;
  157. };
  158. struct tdm_conf {
  159. struct mutex lock;
  160. u32 ref_cnt;
  161. };
  162. struct msm_asoc_mach_data {
  163. struct snd_info_entry *codec_root;
  164. struct msm_common_pdata *common_pdata;
  165. struct msm_pinctrl_info pinctrl_info;
  166. struct device_node *us_euro_gpio_p; /* used by pinctrl API */
  167. struct device_node *hph_en1_gpio_p; /* used by pinctrl API */
  168. struct device_node *hph_en0_gpio_p; /* used by pinctrl API */
  169. struct device_node *fsa_handle;
  170. struct snd_soc_codec *codec;
  171. struct work_struct adsp_power_up_work;
  172. struct tdm_conf tdm_intf_conf[TDM_INTERFACE_MAX];
  173. struct snd_pcm_hardware hw_params;
  174. };
  175. static const char *const pin_states[] = {"sleep", "i2s-active",
  176. "tdm-active"};
  177. static struct platform_device *spdev;
  178. static bool codec_reg_done;
  179. /*
  180. * Need to report LINEIN
  181. * if R/L channel impedance is larger than 5K ohm
  182. */
  183. static const struct snd_soc_dapm_widget msm_dapm_widgets[] = {
  184. SND_SOC_DAPM_MIC("Handset Mic", NULL),
  185. SND_SOC_DAPM_MIC("Analog Mic3", NULL),
  186. SND_SOC_DAPM_MIC("Analog Mic4", NULL),
  187. SND_SOC_DAPM_MIC("Digital Mic0", NULL),
  188. SND_SOC_DAPM_MIC("Digital Mic1", NULL),
  189. SND_SOC_DAPM_MIC("Digital Mic2", NULL),
  190. SND_SOC_DAPM_MIC("Digital Mic3", NULL),
  191. SND_SOC_DAPM_MIC("Digital Mic4", NULL),
  192. SND_SOC_DAPM_MIC("Digital Mic5", NULL),
  193. SND_SOC_DAPM_MIC("Digital Mic6", NULL),
  194. SND_SOC_DAPM_MIC("Digital Mic7", NULL),
  195. };
  196. static int tdm_snd_startup(struct snd_pcm_substream *substream)
  197. {
  198. int ret = 0;
  199. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  200. struct snd_soc_card *card = rtd->card;
  201. struct snd_soc_dai_link *dai_link = rtd->dai_link;
  202. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  203. if (!dai_link->no_pcm)
  204. ret = snd_soc_set_runtime_hwparams(substream, &pdata->hw_params);
  205. return ret;
  206. }
  207. static const struct snd_soc_ops tdm_be_ops = {
  208. .startup = tdm_snd_startup,
  209. };
  210. static struct snd_soc_dai_link msm_gvm_auto_dai_links[] = {
  211. /* BackEnd DAI Links */
  212. {
  213. .name = "PRI_TDM_RX_0_DUMMY",
  214. .stream_name = "TDM-LPAIF-RX-PRIMARY",
  215. .dpcm_playback = 1,
  216. .ops = &tdm_be_ops,
  217. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  218. SND_SOC_DPCM_TRIGGER_POST},
  219. .ignore_suspend = 1,
  220. .ignore_pmdown_time = 1,
  221. SND_SOC_DAILINK_REG(primary_tdm_rx_0_dummy),
  222. },
  223. {
  224. .name = "PRI_TDM_TX_0_DUMMY",
  225. .stream_name = "TDM-LPAIF-TX-PRIMARY",
  226. .dpcm_capture = 1,
  227. .ops = &tdm_be_ops,
  228. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  229. SND_SOC_DPCM_TRIGGER_POST},
  230. .ignore_suspend = 1,
  231. .ignore_pmdown_time = 1,
  232. SND_SOC_DAILINK_REG(primary_tdm_tx_0_dummy),
  233. },
  234. {
  235. .name = "SEC_TDM_RX_0_DUMMY",
  236. .stream_name = "TDM-LPAIF-RX-SECONDARY",
  237. .dpcm_playback = 1,
  238. .ops = &tdm_be_ops,
  239. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  240. SND_SOC_DPCM_TRIGGER_POST},
  241. .ignore_suspend = 1,
  242. .ignore_pmdown_time = 1,
  243. SND_SOC_DAILINK_REG(secondary_tdm_rx_0_dummy),
  244. },
  245. {
  246. .name = "SEC_TDM_TX_0_DUMMY",
  247. .stream_name = "TDM-LPAIF-TX-SECONDARY",
  248. .dpcm_capture = 1,
  249. .ops = &tdm_be_ops,
  250. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  251. SND_SOC_DPCM_TRIGGER_POST},
  252. .ignore_suspend = 1,
  253. .ignore_pmdown_time = 1,
  254. SND_SOC_DAILINK_REG(secondary_tdm_tx_0_dummy),
  255. },
  256. {
  257. .name = "TERT_TDM_RX_0_DUMMY",
  258. .stream_name = "TDM-LPAIF-RX-TERTIARY",
  259. .dpcm_playback = 1,
  260. .ops = &tdm_be_ops,
  261. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  262. SND_SOC_DPCM_TRIGGER_POST},
  263. .ignore_suspend = 1,
  264. .ignore_pmdown_time = 1,
  265. SND_SOC_DAILINK_REG(tert_tdm_rx_0_dummy),
  266. },
  267. {
  268. .name = "TERT_TDM_TX_0_DUMMY",
  269. .stream_name = "TDM-LPAIF-TX-TERTIARY",
  270. .dpcm_capture = 1,
  271. .ops = &tdm_be_ops,
  272. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  273. SND_SOC_DPCM_TRIGGER_POST},
  274. .ignore_suspend = 1,
  275. .ignore_pmdown_time = 1,
  276. SND_SOC_DAILINK_REG(tert_tdm_tx_0_dummy),
  277. },
  278. {
  279. .name = "QUAT_TDM_RX_0_DUMMY",
  280. .stream_name = "TDM-LPAIF_RXTX-RX-PRIMARY",
  281. .dpcm_playback = 1,
  282. .ops = &tdm_be_ops,
  283. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  284. SND_SOC_DPCM_TRIGGER_POST},
  285. .ignore_suspend = 1,
  286. .ignore_pmdown_time = 1,
  287. SND_SOC_DAILINK_REG(quat_tdm_rx_0_dummy),
  288. },
  289. {
  290. .name = "QUAT_TDM_TX_0_DUMMY",
  291. .stream_name = "TDM-LPAIF_RXTX-TX-PRIMARY",
  292. .dpcm_capture = 1,
  293. .ops = &tdm_be_ops,
  294. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  295. SND_SOC_DPCM_TRIGGER_POST},
  296. .ignore_suspend = 1,
  297. .ignore_pmdown_time = 1,
  298. SND_SOC_DAILINK_REG(quat_tdm_tx_0_dummy),
  299. },
  300. {
  301. .name = "QUIN_TDM_RX_0_DUMMY",
  302. .stream_name = "TDM-LPAIF_VA-RX-PRIMARY",
  303. .dpcm_playback = 1,
  304. .ops = &tdm_be_ops,
  305. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  306. SND_SOC_DPCM_TRIGGER_POST},
  307. .ignore_suspend = 1,
  308. .ignore_pmdown_time = 1,
  309. SND_SOC_DAILINK_REG(quin_tdm_rx_0_dummy),
  310. },
  311. {
  312. .name = "QUIN_TDM_TX_0_DUMMY",
  313. .stream_name = "TDM-LPAIF_VA-TX-PRIMARY",
  314. .dpcm_capture = 1,
  315. .ops = &tdm_be_ops,
  316. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  317. SND_SOC_DPCM_TRIGGER_POST},
  318. .ignore_suspend = 1,
  319. .ignore_pmdown_time = 1,
  320. SND_SOC_DAILINK_REG(quin_tdm_tx_0_dummy),
  321. },
  322. {
  323. .name = "SEN_TDM_RX_0_DUMMY",
  324. .stream_name = "TDM-LPAIF_WSA-RX-PRIMARY",
  325. .dpcm_playback = 1,
  326. .ops = &tdm_be_ops,
  327. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  328. SND_SOC_DPCM_TRIGGER_POST},
  329. .ignore_suspend = 1,
  330. .ignore_pmdown_time = 1,
  331. SND_SOC_DAILINK_REG(sen_tdm_rx_0_dummy),
  332. },
  333. {
  334. .name = "SEN_TDM_TX_0_DUMMY",
  335. .stream_name = "TDM-LPAIF_WSA-TX-PRIMARY",
  336. .dpcm_capture = 1,
  337. .ops = &tdm_be_ops,
  338. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  339. SND_SOC_DPCM_TRIGGER_POST},
  340. .ignore_suspend = 1,
  341. .ignore_pmdown_time = 1,
  342. SND_SOC_DAILINK_REG(sen_tdm_tx_0_dummy),
  343. },
  344. {
  345. .name = "SEP_TDM_RX_0_DUMMY",
  346. .stream_name = "TDM-LPAIF_AUD-RX-PRIMARY",
  347. .dpcm_playback = 1,
  348. .ops = &tdm_be_ops,
  349. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  350. SND_SOC_DPCM_TRIGGER_POST},
  351. .ignore_suspend = 1,
  352. .ignore_pmdown_time = 1,
  353. SND_SOC_DAILINK_REG(sep_tdm_rx_0_dummy),
  354. },
  355. {
  356. .name = "SEP_TDM_TX_0_DUMMY",
  357. .stream_name = "TDM-LPAIF_AUD-TX-PRIMARY",
  358. .dpcm_capture = 1,
  359. .ops = &tdm_be_ops,
  360. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  361. SND_SOC_DPCM_TRIGGER_POST},
  362. .ignore_suspend = 1,
  363. .ignore_pmdown_time = 1,
  364. SND_SOC_DAILINK_REG(sep_tdm_tx_0_dummy),
  365. },
  366. {
  367. .name = "OCT_TDM_RX_0_DUMMY",
  368. .stream_name = "TDM-LPAIF_WSA2-RX-PRIMARY",
  369. .dpcm_playback = 1,
  370. .ops = &tdm_be_ops,
  371. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  372. SND_SOC_DPCM_TRIGGER_POST},
  373. .ignore_suspend = 1,
  374. .ignore_pmdown_time = 1,
  375. SND_SOC_DAILINK_REG(oct_tdm_rx_0_dummy),
  376. },
  377. {
  378. .name = "OCT_TDM_TX_0_DUMMY",
  379. .stream_name = "TDM-LPAIF_WSA2-TX-PRIMARY",
  380. .dpcm_capture = 1,
  381. .ops = &tdm_be_ops,
  382. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  383. SND_SOC_DPCM_TRIGGER_POST},
  384. .ignore_suspend = 1,
  385. .ignore_pmdown_time = 1,
  386. SND_SOC_DAILINK_REG(oct_tdm_tx_0_dummy),
  387. },
  388. {
  389. .name = "HS_IF0_TDM_RX_0_DUMMY",
  390. .stream_name = "TDM-LPAIF_SDR-RX-PRIMARY",
  391. .dpcm_playback = 1,
  392. .ops = &tdm_be_ops,
  393. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  394. SND_SOC_DPCM_TRIGGER_POST},
  395. .ignore_suspend = 1,
  396. .ignore_pmdown_time = 1,
  397. SND_SOC_DAILINK_REG(hs_if0_tdm_rx_0_dummy),
  398. },
  399. {
  400. .name = "HS_IF0_TDM_TX_0_DUMMY",
  401. .stream_name = "TDM-LPAIF_SDR-TX-PRIMARY",
  402. .dpcm_capture = 1,
  403. .ops = &tdm_be_ops,
  404. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  405. SND_SOC_DPCM_TRIGGER_POST},
  406. .ignore_suspend = 1,
  407. .ignore_pmdown_time = 1,
  408. SND_SOC_DAILINK_REG(hs_if0_tdm_tx_0_dummy),
  409. },
  410. {
  411. .name = "HS_IF1_TDM_RX_0_DUMMY",
  412. .stream_name = "TDM-LPAIF_SDR-RX-SECONDARY",
  413. .dpcm_playback = 1,
  414. .ops = &tdm_be_ops,
  415. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  416. SND_SOC_DPCM_TRIGGER_POST},
  417. .ignore_suspend = 1,
  418. .ignore_pmdown_time = 1,
  419. SND_SOC_DAILINK_REG(hs_if1_tdm_rx_0_dummy),
  420. },
  421. {
  422. .name = "HS_IF1_TDM_TX_0_DUMMY",
  423. .stream_name = "TDM-LPAIF_SDR-TX-SECONDARY",
  424. .dpcm_capture = 1,
  425. .ops = &tdm_be_ops,
  426. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  427. SND_SOC_DPCM_TRIGGER_POST},
  428. .ignore_suspend = 1,
  429. .ignore_pmdown_time = 1,
  430. SND_SOC_DAILINK_REG(hs_if1_tdm_tx_0_dummy),
  431. },
  432. {
  433. .name = "HS_IF2_TDM_RX_0_DUMMY",
  434. .stream_name = "TDM-LPAIF_SDR-RX-TERTIARY",
  435. .dpcm_playback = 1,
  436. .ops = &tdm_be_ops,
  437. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  438. SND_SOC_DPCM_TRIGGER_POST},
  439. .ignore_suspend = 1,
  440. .ignore_pmdown_time = 1,
  441. SND_SOC_DAILINK_REG(hs_if2_tdm_rx_0_dummy),
  442. },
  443. {
  444. .name = "HS_IF2_TDM_TX_0_DUMMY",
  445. .stream_name = "TDM-LPAIF_SDR-TX-TERTIARY",
  446. .dpcm_capture = 1,
  447. .ops = &tdm_be_ops,
  448. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  449. SND_SOC_DPCM_TRIGGER_POST},
  450. .ignore_suspend = 1,
  451. .ignore_pmdown_time = 1,
  452. SND_SOC_DAILINK_REG(hs_if2_tdm_tx_0_dummy),
  453. },
  454. {
  455. .name = "HS_IF3_TDM_RX_0",
  456. .stream_name = "TDM-LPAIF_SDR-RX-QUATERNARY",
  457. .dpcm_playback = 1,
  458. .ops = &tdm_be_ops,
  459. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  460. SND_SOC_DPCM_TRIGGER_POST},
  461. .ignore_suspend = 1,
  462. .ignore_pmdown_time = 1,
  463. SND_SOC_DAILINK_REG(hs_if3_tdm_rx_0_dummy),
  464. },
  465. {
  466. .name = "HS_IF3_TDM_TX_0",
  467. .stream_name = "TDM-LPAIF_SDR-TX-QUATERNARY",
  468. .dpcm_capture = 1,
  469. .ops = &tdm_be_ops,
  470. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  471. SND_SOC_DPCM_TRIGGER_POST},
  472. .ignore_suspend = 1,
  473. .ignore_pmdown_time = 1,
  474. SND_SOC_DAILINK_REG(hs_if3_tdm_tx_0_dummy),
  475. },
  476. {
  477. .name = "HS_IF4_TDM_RX_0",
  478. .stream_name = "TDM-LPAIF_SDR-RX-QUINARY",
  479. .dpcm_playback = 1,
  480. .ops = &tdm_be_ops,
  481. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  482. SND_SOC_DPCM_TRIGGER_POST},
  483. .ignore_suspend = 1,
  484. .ignore_pmdown_time = 1,
  485. SND_SOC_DAILINK_REG(hs_if4_tdm_rx_0_dummy),
  486. },
  487. {
  488. .name = "HS_IF4_TDM_TX_0",
  489. .stream_name = "TDM-LPAIF_SDR-TX-QUINARY",
  490. .dpcm_capture = 1,
  491. .ops = &tdm_be_ops,
  492. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  493. SND_SOC_DPCM_TRIGGER_POST},
  494. .ignore_suspend = 1,
  495. .ignore_pmdown_time = 1,
  496. SND_SOC_DAILINK_REG(hs_if4_tdm_tx_0_dummy),
  497. },
  498. {
  499. .name = "PCM_DUMMY-TX-0",
  500. .stream_name = "PCM_DUMMY-TX-0",
  501. .dpcm_capture = 1,
  502. .trigger = {SND_SOC_DPCM_TRIGGER_POST,
  503. SND_SOC_DPCM_TRIGGER_POST},
  504. .ignore_suspend = 1,
  505. .ignore_pmdown_time = 1,
  506. SND_SOC_DAILINK_REG(pcm_dummy_tx0),
  507. },
  508. };
  509. int snd_card_notify_user(snd_card_status_t card_status)
  510. {
  511. snd_card_pdata->card_status = card_status;
  512. sysfs_notify(&snd_card_pdata->snd_card_kobj, NULL, "card_state");
  513. return 0;
  514. }
  515. int snd_card_set_card_status(snd_card_status_t card_status)
  516. {
  517. snd_card_pdata->card_status = card_status;
  518. return 0;
  519. }
  520. static ssize_t snd_card_sysfs_show(struct kobject *kobj,
  521. struct attribute *attr, char *buf)
  522. {
  523. /* Max length of buf is PAGE_SIZE */
  524. return sysfs_emit(buf, "%d\n", snd_card_pdata->card_status);
  525. }
  526. static ssize_t snd_card_sysfs_store(struct kobject *kobj,
  527. struct attribute *attr, const char *buf, size_t count)
  528. {
  529. int result;
  530. result = kstrtoint (buf, 0, &snd_card_pdata->card_status);
  531. if (result)
  532. pr_err("%s: Failed to read buf result=%d\n", __func__, result);
  533. sysfs_notify(kobj, NULL, "card_state");
  534. return 0;
  535. }
  536. static const struct sysfs_ops snd_card_sysfs_ops = {
  537. .show = snd_card_sysfs_show,
  538. .store = snd_card_sysfs_store,
  539. };
  540. static void snd_card_sysfs_release(struct kobject *kobj)
  541. {
  542. kfree(snd_card_pdata); /* Free the memory */
  543. }
  544. static struct kobj_type snd_card_ktype = {
  545. .release = snd_card_sysfs_release,
  546. .sysfs_ops = &snd_card_sysfs_ops,
  547. };
  548. int snd_card_sysfs_init(void)
  549. {
  550. int ret = 0;
  551. char dir[DIR_SZ] = "snd_card";
  552. snd_card_pdata = kcalloc(1, sizeof(struct snd_card_pdata), GFP_KERNEL);
  553. if (!snd_card_pdata)
  554. return -ENOMEM;
  555. /* kernel_kobj is the kobject of /sys/kernel/ */
  556. ret = kobject_init_and_add(&snd_card_pdata->snd_card_kobj, &snd_card_ktype,
  557. kernel_kobj, dir);
  558. if (ret < 0) {
  559. pr_err("%s: Failed to init and add kobject %s, err = %d\n",
  560. __func__, dir, ret);
  561. goto fail;
  562. }
  563. ret = sysfs_create_file(&snd_card_pdata->snd_card_kobj, &card_state_attr);
  564. if (ret < 0) {
  565. pr_err("%s: Failed to add snd_card sysfs entry to %s\n",
  566. __func__, dir);
  567. goto fail;
  568. }
  569. return ret;
  570. fail:
  571. kobject_put(&snd_card_pdata->snd_card_kobj);
  572. return ret;
  573. }
  574. struct snd_soc_card snd_soc_card_gvm_auto_dummy_msm;
  575. static int msm_populate_dai_link_component_of_node(
  576. struct snd_soc_card *card)
  577. {
  578. int i, j, index, ret = 0;
  579. struct device *cdev = card->dev;
  580. struct snd_soc_dai_link *dai_link = card->dai_link;
  581. struct device_node *np;
  582. if (!cdev) {
  583. pr_err("%s: Sound card device memory NULL\n", __func__);
  584. return -ENODEV;
  585. }
  586. for (i = 0; i < card->num_links; i++) {
  587. if (dai_link[i].platforms->of_node && dai_link[i].cpus->of_node)
  588. continue;
  589. /* populate cpu_of_node for snd card dai links */
  590. if (dai_link[i].cpus->dai_name && !dai_link[i].cpus->of_node) {
  591. index = of_property_match_string(cdev->of_node,
  592. "asoc-cpu-names",
  593. dai_link[i].cpus->dai_name);
  594. pr_err("%s: retrieving cpu_of_node for %s\n",
  595. __func__,
  596. dai_link[i].cpus->dai_name);
  597. if (index >= 0) {
  598. np = of_parse_phandle(cdev->of_node, "asoc-cpu",
  599. index);
  600. if (!np) {
  601. pr_err("%s: retrieving phandle for cpu dai %s failed\n",
  602. __func__,
  603. dai_link[i].cpus->dai_name);
  604. ret = -ENODEV;
  605. goto err;
  606. }
  607. dai_link[i].cpus->of_node = np;
  608. dai_link[i].cpus->dai_name = NULL;
  609. }
  610. }
  611. /* populate codec_of_node for snd card dai links */
  612. if (dai_link[i].num_codecs > 0) {
  613. for (j = 0; j < dai_link[i].num_codecs; j++) {
  614. if (dai_link[i].codecs[j].of_node ||
  615. !dai_link[i].codecs[j].name)
  616. continue;
  617. index = of_property_match_string(cdev->of_node,
  618. "asoc-codec-names",
  619. dai_link[i].codecs[j].name);
  620. if (index < 0)
  621. continue;
  622. np = of_parse_phandle(cdev->of_node,
  623. "asoc-codec",
  624. index);
  625. if (!np) {
  626. pr_err("%s: retrieving phandle for codec %s failed\n",
  627. __func__, dai_link[i].codecs[j].name);
  628. ret = -ENODEV;
  629. goto err;
  630. }
  631. dai_link[i].codecs[j].of_node = np;
  632. dai_link[i].codecs[j].name = NULL;
  633. }
  634. }
  635. }
  636. err:
  637. return ret;
  638. }
  639. static const struct of_device_id gvm_asoc_machine_of_match[] = {
  640. { .compatible = "qcom,8155-spf-asoc-snd-adp-star",
  641. .data = "adp_star_codec"},
  642. { .compatible = "qcom,6155-spf-asoc-snd-adp-star",
  643. .data = "adp_star_codec"},
  644. { .compatible = "qcom,gvm-auto-spf-asoc-snd-adp-star",
  645. .data = "adp_star_codec"},
  646. {},
  647. };
  648. static struct snd_soc_card *populate_snd_card_dailinks(struct device *dev)
  649. {
  650. struct snd_soc_card *card = NULL;
  651. const struct of_device_id *match = NULL;
  652. match = of_match_node(gvm_asoc_machine_of_match, dev->of_node);
  653. if (!match) {
  654. dev_err(dev, "%s: No DT match found for sound card\n",
  655. __func__);
  656. return NULL;
  657. }
  658. card = &snd_soc_card_gvm_auto_dummy_msm;
  659. if (!strcmp(match->compatible, "qcom,gvm-auto-spf-asoc-snd-adp-star")) {
  660. card->dai_link = msm_gvm_auto_dai_links;
  661. card->num_links = ARRAY_SIZE(msm_gvm_auto_dai_links);
  662. }
  663. return card;
  664. }
  665. struct msm_common_pdata *msm_common_get_pdata(struct snd_soc_card *card)
  666. {
  667. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  668. if (!pdata)
  669. return NULL;
  670. return pdata->common_pdata;
  671. }
  672. void msm_common_set_pdata(struct snd_soc_card *card,
  673. struct msm_common_pdata *common_pdata)
  674. {
  675. struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card);
  676. if (!pdata)
  677. return;
  678. pdata->common_pdata = common_pdata;
  679. }
  680. static long virt_sndcard_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
  681. {
  682. int ret = 0;
  683. switch (cmd) {
  684. case AUTO_VIRT_SNDCARD_OFFLINE:
  685. snd_card_notify_user(SND_CARD_STATUS_OFFLINE);
  686. pr_debug("%s: mark sndcard offline\n", __func__);
  687. break;
  688. case AUTO_VIRT_SNDCARD_ONLINE:
  689. snd_card_notify_user(SND_CARD_STATUS_ONLINE);
  690. pr_debug("%s: mark sndcard online\n", __func__);
  691. break;
  692. default:
  693. pr_err("%s: Invalid command = %d\n", __func__, cmd);
  694. ret = -EFAULT;
  695. break;
  696. }
  697. return ret;
  698. }
  699. static const struct file_operations virt_sndcard_ctl_fops = {
  700. .owner = THIS_MODULE,
  701. .unlocked_ioctl = virt_sndcard_ioctl,
  702. };
  703. static struct cdev virt_sndcard_ctl = {
  704. .ops = &virt_sndcard_ctl_fops,
  705. };
  706. int msm_audio_ssr_register(struct cdev *virt_sndcard_ctl)
  707. {
  708. static struct class *dev_class;
  709. dev_t dev;
  710. if ((alloc_chrdev_region(&dev, 0, 1, "virt_sndcard_ctl")) < 0) {
  711. pr_err("%s: Cannot allocate major number\n", __func__);
  712. return -EINVAL;
  713. }
  714. pr_debug("Major = %d Minor = %d\n", MAJOR(dev), MINOR(dev));
  715. cdev_init(virt_sndcard_ctl, &virt_sndcard_ctl_fops);
  716. if ((cdev_add(virt_sndcard_ctl, dev, 1)) < 0) {
  717. pr_err("%s: Cannot add the device to the system\n", __func__);
  718. goto err;
  719. }
  720. dev_class = class_create(THIS_MODULE, "SSR");
  721. if (IS_ERR(dev_class)) {
  722. pr_err("%s: Cannot create the struct class\n", __func__);
  723. goto err;
  724. }
  725. if (IS_ERR(device_create(dev_class, NULL, dev, NULL, "virt_sndcard_ctl"))) {
  726. pr_err("%s: Cannot create the Device\n", __func__);
  727. goto fail;
  728. }
  729. return 0;
  730. fail:
  731. class_destroy(dev_class);
  732. err:
  733. unregister_chrdev_region(dev, 1);
  734. return -EINVAL;
  735. }
  736. static int msm_get_hwparams(struct platform_device *pdev)
  737. {
  738. struct snd_soc_card *card = NULL;
  739. struct msm_asoc_mach_data *pdata = NULL;
  740. u32 pcm_info = 0;
  741. u32 buffer_bytes_max = 0;
  742. u32 periods_bytes[2] = {0};
  743. u32 periods_count[2] = {0};
  744. int ret = 0;
  745. card = platform_get_drvdata(pdev);
  746. if (!card) {
  747. pr_err("%s: card is NULL\n",
  748. __func__);
  749. return -EINVAL;
  750. }
  751. pdata = snd_soc_card_get_drvdata(card);
  752. if (!pdata) {
  753. pr_err("%s: pdata is NULL\n",
  754. __func__);
  755. return -EINVAL;
  756. }
  757. ret = of_property_read_u32(pdev->dev.of_node,
  758. "qcom,hw_pcm_info",
  759. &pcm_info);
  760. if (ret) {
  761. pr_err("%s: read pcm info failed\n",
  762. __func__);
  763. return ret;
  764. }
  765. ret = of_property_read_u32(pdev->dev.of_node,
  766. "qcom,hw_buffer_size_max",
  767. &buffer_bytes_max);
  768. if (ret) {
  769. pr_err("%s: read buffer size max failed\n",
  770. __func__);
  771. return ret;
  772. }
  773. ret = of_property_read_u32_array(pdev->dev.of_node,
  774. "qcom,hw_period_byte_size",
  775. periods_bytes, 2);
  776. if (ret) {
  777. pr_err("%s: read period byte size failed\n",
  778. __func__);
  779. return ret;
  780. }
  781. ret = of_property_read_u32_array(pdev->dev.of_node,
  782. "qcom,hw_period_count_size",
  783. periods_count, 2);
  784. if (ret) {
  785. pr_err("%s: read period count size failed\n",
  786. __func__);
  787. return ret;
  788. }
  789. pdata->hw_params.info = pcm_info;
  790. pdata->hw_params.buffer_bytes_max = buffer_bytes_max;
  791. pdata->hw_params.period_bytes_min = periods_bytes[0];
  792. pdata->hw_params.period_bytes_max = periods_bytes[1];
  793. pdata->hw_params.periods_min = periods_count[0];
  794. pdata->hw_params.periods_max = periods_count[1];
  795. return ret;
  796. }
  797. static int msm_asoc_machine_probe(struct platform_device *pdev)
  798. {
  799. struct snd_soc_card *card;
  800. struct msm_asoc_mach_data *pdata;
  801. int ret;
  802. dev_info(&pdev->dev, "M - DRIVER Audio Init\n");
  803. if (!pdev->dev.of_node) {
  804. dev_err(&pdev->dev, "No platform supplied from device tree\n");
  805. return -EINVAL;
  806. }
  807. pdata = devm_kzalloc(&pdev->dev,
  808. sizeof(struct msm_asoc_mach_data), GFP_KERNEL);
  809. if (!pdata)
  810. return -ENOMEM;
  811. card = populate_snd_card_dailinks(&pdev->dev);
  812. if (!card) {
  813. dev_err(&pdev->dev, "%s: Card uninitialized\n", __func__);
  814. ret = -EINVAL;
  815. return ret;
  816. }
  817. card->dev = &pdev->dev;
  818. platform_set_drvdata(pdev, card);
  819. snd_soc_card_set_drvdata(card, pdata);
  820. ret = snd_soc_of_parse_card_name(card, "qcom,model");
  821. if (ret) {
  822. dev_err(&pdev->dev, "parse card name failed, err:%d\n",
  823. ret);
  824. return ret;
  825. }
  826. ret = msm_populate_dai_link_component_of_node(card);
  827. if (ret) {
  828. ret = -EPROBE_DEFER;
  829. return ret;
  830. }
  831. ret = devm_snd_soc_register_card(&pdev->dev, card);
  832. if (ret == -EPROBE_DEFER) {
  833. if (codec_reg_done)
  834. ret = -EINVAL;
  835. return ret;
  836. } else if (ret) {
  837. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  838. ret);
  839. pr_err("snd_soc_register_card failed (%d)\n",
  840. ret);
  841. return ret;
  842. }
  843. dev_info(&pdev->dev, "Sound card %s registered\n", card->name);
  844. pr_err("Sound card %s registered\n", card->name);
  845. dev_info(&pdev->dev, "M - DRIVER Audio Ready\n");
  846. ret = msm_get_hwparams(pdev);
  847. if (ret) {
  848. dev_err(&pdev->dev,
  849. "%s: hwparams get failed with %d\n",
  850. __func__, ret);
  851. return ret;
  852. }
  853. spdev = pdev;
  854. ret = msm_audio_ssr_register(&virt_sndcard_ctl);
  855. if (ret)
  856. pr_err("%s: Audio virtual sndcard ctrl register fail, ret=%d\n", __func__, ret);
  857. dev_info(&pdev->dev, "Audio virtual sndcard ctrl register complete\n");
  858. ret = snd_card_sysfs_init();
  859. if (ret)
  860. pr_err("snd_card_sysfs_init fail, ret=%d\n", ret);
  861. ret = snd_card_set_card_status(SND_CARD_STATUS_ONLINE);
  862. if (ret)
  863. pr_err("snd_card_set_card_status fail, ret=%d\n", ret);
  864. return 0;
  865. }
  866. static int msm_asoc_machine_remove(struct platform_device *pdev)
  867. {
  868. /* kobject_put decrease the kref count, once the count reaches 0.
  869. * Kobject core will automatically clean up the memory allocated by kobject.
  870. * The snd_card_sysfs_release release will help clean up memory allocated by us
  871. */
  872. kobject_put(&snd_card_pdata->snd_card_kobj);
  873. return 0;
  874. }
  875. static struct platform_driver gvm_asoc_machine_driver = {
  876. .driver = {
  877. .name = DRV_NAME,
  878. .pm = &snd_soc_pm_ops,
  879. .of_match_table = gvm_asoc_machine_of_match,
  880. },
  881. .probe = msm_asoc_machine_probe,
  882. .remove = msm_asoc_machine_remove,
  883. };
  884. int __init gvm_auto_spf_init(void)
  885. {
  886. return platform_driver_register(&gvm_asoc_machine_driver);
  887. }
  888. void gvm_auto_spf_exit(void)
  889. {
  890. platform_driver_unregister(&gvm_asoc_machine_driver);
  891. }
  892. module_init(gvm_auto_spf_init);
  893. module_exit(gvm_auto_spf_exit);
  894. MODULE_DESCRIPTION("ALSA SoC Machine Driver for SPF");
  895. MODULE_LICENSE("GPL");
  896. MODULE_ALIAS("platform:" DRV_NAME);
  897. MODULE_DEVICE_TABLE(of, gvm_asoc_machine_of_match);