va-macro.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/clk.h>
  7. #include <linux/io.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <linux/regulator/consumer.h>
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include <sound/tlv.h>
  14. #include <linux/pm_runtime.h>
  15. #include "bolero-cdc.h"
  16. #include "bolero-cdc-registers.h"
  17. #include "bolero-clk-rsc.h"
  18. /* pm runtime auto suspend timer in msecs */
  19. #define VA_AUTO_SUSPEND_DELAY 100 /* delay in msec */
  20. #define VA_MACRO_MAX_OFFSET 0x1000
  21. #define VA_MACRO_NUM_DECIMATORS 8
  22. #define VA_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  23. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  24. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  25. #define VA_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  26. SNDRV_PCM_FMTBIT_S24_LE |\
  27. SNDRV_PCM_FMTBIT_S24_3LE)
  28. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  29. #define CF_MIN_3DB_4HZ 0x0
  30. #define CF_MIN_3DB_75HZ 0x1
  31. #define CF_MIN_3DB_150HZ 0x2
  32. #define VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  33. #define VA_MACRO_MCLK_FREQ 9600000
  34. #define VA_MACRO_TX_PATH_OFFSET 0x80
  35. #define VA_MACRO_TX_DMIC_CLK_DIV_MASK 0x0E
  36. #define VA_MACRO_TX_DMIC_CLK_DIV_SHFT 0x01
  37. #define VA_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
  38. #define VA_MACRO_ADC_MUX_CFG_OFFSET 0x2
  39. #define BOLERO_CDC_VA_TX_UNMUTE_DELAY_MS 40
  40. #define MAX_RETRY_ATTEMPTS 500
  41. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  42. static int va_tx_unmute_delay = BOLERO_CDC_VA_TX_UNMUTE_DELAY_MS;
  43. module_param(va_tx_unmute_delay, int, 0664);
  44. MODULE_PARM_DESC(va_tx_unmute_delay, "delay to unmute the tx path");
  45. enum {
  46. VA_MACRO_AIF_INVALID = 0,
  47. VA_MACRO_AIF1_CAP,
  48. VA_MACRO_AIF2_CAP,
  49. VA_MACRO_AIF3_CAP,
  50. VA_MACRO_MAX_DAIS,
  51. };
  52. enum {
  53. VA_MACRO_DEC0,
  54. VA_MACRO_DEC1,
  55. VA_MACRO_DEC2,
  56. VA_MACRO_DEC3,
  57. VA_MACRO_DEC4,
  58. VA_MACRO_DEC5,
  59. VA_MACRO_DEC6,
  60. VA_MACRO_DEC7,
  61. VA_MACRO_DEC_MAX,
  62. };
  63. enum {
  64. VA_MACRO_CLK_DIV_2,
  65. VA_MACRO_CLK_DIV_3,
  66. VA_MACRO_CLK_DIV_4,
  67. VA_MACRO_CLK_DIV_6,
  68. VA_MACRO_CLK_DIV_8,
  69. VA_MACRO_CLK_DIV_16,
  70. };
  71. enum {
  72. MSM_DMIC,
  73. SWR_MIC,
  74. };
  75. struct va_mute_work {
  76. struct va_macro_priv *va_priv;
  77. u32 decimator;
  78. struct delayed_work dwork;
  79. };
  80. struct hpf_work {
  81. struct va_macro_priv *va_priv;
  82. u8 decimator;
  83. u8 hpf_cut_off_freq;
  84. struct delayed_work dwork;
  85. };
  86. struct va_macro_priv {
  87. struct device *dev;
  88. bool dec_active[VA_MACRO_NUM_DECIMATORS];
  89. bool va_without_decimation;
  90. struct clk *lpass_audio_hw_vote;
  91. struct mutex mclk_lock;
  92. struct snd_soc_component *component;
  93. struct hpf_work va_hpf_work[VA_MACRO_NUM_DECIMATORS];
  94. struct va_mute_work va_mute_dwork[VA_MACRO_NUM_DECIMATORS];
  95. unsigned long active_ch_mask[VA_MACRO_MAX_DAIS];
  96. unsigned long active_ch_cnt[VA_MACRO_MAX_DAIS];
  97. s32 dmic_0_1_clk_cnt;
  98. s32 dmic_2_3_clk_cnt;
  99. s32 dmic_4_5_clk_cnt;
  100. s32 dmic_6_7_clk_cnt;
  101. u16 dmic_clk_div;
  102. u16 va_mclk_users;
  103. u16 mclk_mux_sel;
  104. char __iomem *va_io_base;
  105. char __iomem *va_island_mode_muxsel;
  106. struct regulator *micb_supply;
  107. u32 micb_voltage;
  108. u32 micb_current;
  109. int micb_users;
  110. u16 default_clk_id;
  111. u16 clk_id;
  112. int tx_clk_status;
  113. };
  114. static bool va_macro_get_data(struct snd_soc_component *component,
  115. struct device **va_dev,
  116. struct va_macro_priv **va_priv,
  117. const char *func_name)
  118. {
  119. *va_dev = bolero_get_device_ptr(component->dev, VA_MACRO);
  120. if (!(*va_dev)) {
  121. dev_err(component->dev,
  122. "%s: null device for macro!\n", func_name);
  123. return false;
  124. }
  125. *va_priv = dev_get_drvdata((*va_dev));
  126. if (!(*va_priv) || !(*va_priv)->component) {
  127. dev_err(component->dev,
  128. "%s: priv is null for macro!\n", func_name);
  129. return false;
  130. }
  131. return true;
  132. }
  133. static int va_macro_mclk_enable(struct va_macro_priv *va_priv,
  134. bool mclk_enable, bool dapm)
  135. {
  136. struct regmap *regmap = dev_get_regmap(va_priv->dev->parent, NULL);
  137. int ret = 0;
  138. if (regmap == NULL) {
  139. dev_err(va_priv->dev, "%s: regmap is NULL\n", __func__);
  140. return -EINVAL;
  141. }
  142. dev_dbg(va_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  143. __func__, mclk_enable, dapm, va_priv->va_mclk_users);
  144. mutex_lock(&va_priv->mclk_lock);
  145. if (mclk_enable) {
  146. if (va_priv->va_mclk_users == 0) {
  147. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  148. va_priv->default_clk_id,
  149. va_priv->clk_id,
  150. true);
  151. if (ret < 0) {
  152. dev_err(va_priv->dev,
  153. "%s: va request clock en failed\n",
  154. __func__);
  155. goto exit;
  156. }
  157. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  158. true);
  159. regcache_mark_dirty(regmap);
  160. regcache_sync_region(regmap,
  161. VA_START_OFFSET,
  162. VA_MAX_OFFSET);
  163. }
  164. va_priv->va_mclk_users++;
  165. } else {
  166. if (va_priv->va_mclk_users <= 0) {
  167. dev_err(va_priv->dev, "%s: clock already disabled\n",
  168. __func__);
  169. va_priv->va_mclk_users = 0;
  170. goto exit;
  171. }
  172. va_priv->va_mclk_users--;
  173. if (va_priv->va_mclk_users == 0) {
  174. bolero_clk_rsc_fs_gen_request(va_priv->dev,
  175. false);
  176. bolero_clk_rsc_request_clock(va_priv->dev,
  177. va_priv->default_clk_id,
  178. va_priv->clk_id,
  179. false);
  180. }
  181. }
  182. exit:
  183. mutex_unlock(&va_priv->mclk_lock);
  184. return ret;
  185. }
  186. static int va_macro_event_handler(struct snd_soc_component *component,
  187. u16 event, u32 data)
  188. {
  189. struct device *va_dev = NULL;
  190. struct va_macro_priv *va_priv = NULL;
  191. int retry_cnt = MAX_RETRY_ATTEMPTS;
  192. int ret = 0;
  193. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  194. return -EINVAL;
  195. switch (event) {
  196. case BOLERO_MACRO_EVT_WAIT_VA_CLK_RESET:
  197. while ((va_priv->va_mclk_users != 0) && (retry_cnt != 0)) {
  198. dev_dbg_ratelimited(va_dev, "%s:retry_cnt: %d\n",
  199. __func__, retry_cnt);
  200. /*
  201. * Userspace takes 10 seconds to close
  202. * the session when pcm_start fails due to concurrency
  203. * with PDR/SSR. Loop and check every 20ms till 10
  204. * seconds for va_mclk user count to get reset to 0
  205. * which ensures userspace teardown is done and SSR
  206. * powerup seq can proceed.
  207. */
  208. msleep(20);
  209. retry_cnt--;
  210. }
  211. if (retry_cnt == 0)
  212. dev_err(va_dev,
  213. "%s: va_mclk_users is non-zero still, audio SSR fail!!\n",
  214. __func__);
  215. break;
  216. case BOLERO_MACRO_EVT_SSR_UP:
  217. /* enable&disable VA_CORE_CLK to reset GFMUX reg */
  218. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  219. va_priv->default_clk_id,
  220. VA_CORE_CLK, true);
  221. if (ret < 0)
  222. dev_err_ratelimited(va_priv->dev,
  223. "%s, failed to enable clk, ret:%d\n",
  224. __func__, ret);
  225. else
  226. bolero_clk_rsc_request_clock(va_priv->dev,
  227. va_priv->default_clk_id,
  228. VA_CORE_CLK, false);
  229. case BOLERO_MACRO_EVT_CLK_RESET:
  230. bolero_rsc_clk_reset(va_dev, VA_CORE_CLK);
  231. break;
  232. case BOLERO_MACRO_EVT_SSR_DOWN:
  233. if ((!pm_runtime_enabled(va_dev) ||
  234. !pm_runtime_suspended(va_dev))) {
  235. ret = bolero_runtime_suspend(va_dev);
  236. if (!ret) {
  237. pm_runtime_disable(va_dev);
  238. pm_runtime_set_suspended(va_dev);
  239. pm_runtime_enable(va_dev);
  240. }
  241. }
  242. break;
  243. default:
  244. break;
  245. }
  246. return 0;
  247. }
  248. static int va_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
  249. struct snd_kcontrol *kcontrol, int event)
  250. {
  251. struct snd_soc_component *component =
  252. snd_soc_dapm_to_component(w->dapm);
  253. int ret = 0;
  254. struct device *va_dev = NULL;
  255. struct va_macro_priv *va_priv = NULL;
  256. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  257. return -EINVAL;
  258. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  259. switch (event) {
  260. case SND_SOC_DAPM_PRE_PMU:
  261. if (va_priv->lpass_audio_hw_vote) {
  262. ret = clk_prepare_enable(va_priv->lpass_audio_hw_vote);
  263. if (ret)
  264. dev_err(va_dev,
  265. "%s: lpass audio hw enable failed\n",
  266. __func__);
  267. }
  268. if (!ret)
  269. if (bolero_tx_clk_switch(component))
  270. dev_dbg(va_dev, "%s: clock switch failed\n",
  271. __func__);
  272. bolero_register_event_listener(component, true);
  273. break;
  274. case SND_SOC_DAPM_POST_PMD:
  275. bolero_register_event_listener(component, false);
  276. if (bolero_tx_clk_switch(component))
  277. dev_dbg(va_dev, "%s: clock switch failed\n",__func__);
  278. if (va_priv->lpass_audio_hw_vote)
  279. clk_disable_unprepare(va_priv->lpass_audio_hw_vote);
  280. break;
  281. default:
  282. dev_err(va_priv->dev,
  283. "%s: invalid DAPM event %d\n", __func__, event);
  284. ret = -EINVAL;
  285. }
  286. return ret;
  287. }
  288. static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
  289. struct snd_kcontrol *kcontrol, int event)
  290. {
  291. struct snd_soc_component *component =
  292. snd_soc_dapm_to_component(w->dapm);
  293. int ret = 0;
  294. struct device *va_dev = NULL;
  295. struct va_macro_priv *va_priv = NULL;
  296. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  297. return -EINVAL;
  298. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  299. switch (event) {
  300. case SND_SOC_DAPM_PRE_PMU:
  301. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  302. va_priv->default_clk_id,
  303. TX_CORE_CLK,
  304. true);
  305. if (!ret)
  306. va_priv->tx_clk_status++;
  307. ret = va_macro_mclk_enable(va_priv, 1, true);
  308. break;
  309. case SND_SOC_DAPM_POST_PMD:
  310. if (bolero_tx_clk_switch(component))
  311. dev_dbg(va_dev, "%s: clock switch failed\n",__func__);
  312. va_macro_mclk_enable(va_priv, 0, true);
  313. if (va_priv->tx_clk_status > 0) {
  314. bolero_clk_rsc_request_clock(va_priv->dev,
  315. va_priv->default_clk_id,
  316. TX_CORE_CLK,
  317. false);
  318. va_priv->tx_clk_status--;
  319. }
  320. break;
  321. default:
  322. dev_err(va_priv->dev,
  323. "%s: invalid DAPM event %d\n", __func__, event);
  324. ret = -EINVAL;
  325. }
  326. return ret;
  327. }
  328. static void va_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  329. {
  330. struct delayed_work *hpf_delayed_work;
  331. struct hpf_work *hpf_work;
  332. struct va_macro_priv *va_priv;
  333. struct snd_soc_component *component;
  334. u16 dec_cfg_reg, hpf_gate_reg;
  335. u8 hpf_cut_off_freq;
  336. u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0;
  337. hpf_delayed_work = to_delayed_work(work);
  338. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  339. va_priv = hpf_work->va_priv;
  340. component = va_priv->component;
  341. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  342. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  343. VA_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  344. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  345. VA_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  346. dev_dbg(va_priv->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  347. __func__, hpf_work->decimator, hpf_cut_off_freq);
  348. adc_mux_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1 +
  349. VA_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  350. if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
  351. adc_reg = BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0 +
  352. VA_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  353. adc_n = snd_soc_component_read32(component, adc_reg) &
  354. VA_MACRO_SWR_MIC_MUX_SEL_MASK;
  355. if (adc_n >= BOLERO_ADC_MAX)
  356. goto va_hpf_set;
  357. /* analog mic clear TX hold */
  358. bolero_clear_amic_tx_hold(component->dev, adc_n);
  359. }
  360. va_hpf_set:
  361. snd_soc_component_update_bits(component,
  362. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  363. hpf_cut_off_freq << 5);
  364. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x02);
  365. /* Minimum 1 clk cycle delay is required as per HW spec */
  366. usleep_range(1000, 1010);
  367. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x01);
  368. }
  369. static void va_macro_mute_update_callback(struct work_struct *work)
  370. {
  371. struct va_mute_work *va_mute_dwork;
  372. struct snd_soc_component *component = NULL;
  373. struct va_macro_priv *va_priv;
  374. struct delayed_work *delayed_work;
  375. u16 tx_vol_ctl_reg, decimator;
  376. delayed_work = to_delayed_work(work);
  377. va_mute_dwork = container_of(delayed_work, struct va_mute_work, dwork);
  378. va_priv = va_mute_dwork->va_priv;
  379. component = va_priv->component;
  380. decimator = va_mute_dwork->decimator;
  381. tx_vol_ctl_reg =
  382. BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  383. VA_MACRO_TX_PATH_OFFSET * decimator;
  384. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  385. dev_dbg(va_priv->dev, "%s: decimator %u unmute\n",
  386. __func__, decimator);
  387. }
  388. static int va_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  389. struct snd_ctl_elem_value *ucontrol)
  390. {
  391. struct snd_soc_dapm_widget *widget =
  392. snd_soc_dapm_kcontrol_widget(kcontrol);
  393. struct snd_soc_component *component =
  394. snd_soc_dapm_to_component(widget->dapm);
  395. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  396. unsigned int val;
  397. u16 mic_sel_reg, dmic_clk_reg;
  398. struct device *va_dev = NULL;
  399. struct va_macro_priv *va_priv = NULL;
  400. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  401. return -EINVAL;
  402. val = ucontrol->value.enumerated.item[0];
  403. if (val > e->items - 1)
  404. return -EINVAL;
  405. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  406. widget->name, val);
  407. switch (e->reg) {
  408. case BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0:
  409. mic_sel_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0;
  410. break;
  411. case BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0:
  412. mic_sel_reg = BOLERO_CDC_VA_TX1_TX_PATH_CFG0;
  413. break;
  414. case BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0:
  415. mic_sel_reg = BOLERO_CDC_VA_TX2_TX_PATH_CFG0;
  416. break;
  417. case BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0:
  418. mic_sel_reg = BOLERO_CDC_VA_TX3_TX_PATH_CFG0;
  419. break;
  420. case BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0:
  421. mic_sel_reg = BOLERO_CDC_VA_TX4_TX_PATH_CFG0;
  422. break;
  423. case BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0:
  424. mic_sel_reg = BOLERO_CDC_VA_TX5_TX_PATH_CFG0;
  425. break;
  426. case BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0:
  427. mic_sel_reg = BOLERO_CDC_VA_TX6_TX_PATH_CFG0;
  428. break;
  429. case BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0:
  430. mic_sel_reg = BOLERO_CDC_VA_TX7_TX_PATH_CFG0;
  431. break;
  432. default:
  433. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  434. __func__, e->reg);
  435. return -EINVAL;
  436. }
  437. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  438. if (val != 0) {
  439. if (val < 5) {
  440. snd_soc_component_update_bits(component,
  441. mic_sel_reg,
  442. 1 << 7, 0x0 << 7);
  443. } else {
  444. snd_soc_component_update_bits(component,
  445. mic_sel_reg,
  446. 1 << 7, 0x1 << 7);
  447. snd_soc_component_update_bits(component,
  448. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  449. 0x80, 0x00);
  450. dmic_clk_reg =
  451. BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
  452. ((val - 5)/2) * 4;
  453. snd_soc_component_update_bits(component,
  454. dmic_clk_reg,
  455. 0x0E, va_priv->dmic_clk_div << 0x1);
  456. }
  457. }
  458. } else {
  459. /* DMIC selected */
  460. if (val != 0)
  461. snd_soc_component_update_bits(component, mic_sel_reg,
  462. 1 << 7, 1 << 7);
  463. }
  464. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  465. }
  466. static int va_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  467. struct snd_ctl_elem_value *ucontrol)
  468. {
  469. struct snd_soc_dapm_widget *widget =
  470. snd_soc_dapm_kcontrol_widget(kcontrol);
  471. struct snd_soc_component *component =
  472. snd_soc_dapm_to_component(widget->dapm);
  473. struct soc_multi_mixer_control *mixer =
  474. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  475. u32 dai_id = widget->shift;
  476. u32 dec_id = mixer->shift;
  477. struct device *va_dev = NULL;
  478. struct va_macro_priv *va_priv = NULL;
  479. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  480. return -EINVAL;
  481. if (test_bit(dec_id, &va_priv->active_ch_mask[dai_id]))
  482. ucontrol->value.integer.value[0] = 1;
  483. else
  484. ucontrol->value.integer.value[0] = 0;
  485. return 0;
  486. }
  487. static int va_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  488. struct snd_ctl_elem_value *ucontrol)
  489. {
  490. struct snd_soc_dapm_widget *widget =
  491. snd_soc_dapm_kcontrol_widget(kcontrol);
  492. struct snd_soc_component *component =
  493. snd_soc_dapm_to_component(widget->dapm);
  494. struct snd_soc_dapm_update *update = NULL;
  495. struct soc_multi_mixer_control *mixer =
  496. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  497. u32 dai_id = widget->shift;
  498. u32 dec_id = mixer->shift;
  499. u32 enable = ucontrol->value.integer.value[0];
  500. struct device *va_dev = NULL;
  501. struct va_macro_priv *va_priv = NULL;
  502. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  503. return -EINVAL;
  504. if (enable) {
  505. set_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  506. va_priv->active_ch_cnt[dai_id]++;
  507. } else {
  508. clear_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  509. va_priv->active_ch_cnt[dai_id]--;
  510. }
  511. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  512. return 0;
  513. }
  514. static int va_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  515. struct snd_kcontrol *kcontrol, int event)
  516. {
  517. struct snd_soc_component *component =
  518. snd_soc_dapm_to_component(w->dapm);
  519. u8 dmic_clk_en = 0x01;
  520. u16 dmic_clk_reg;
  521. s32 *dmic_clk_cnt;
  522. unsigned int dmic;
  523. int ret;
  524. char *wname;
  525. struct device *va_dev = NULL;
  526. struct va_macro_priv *va_priv = NULL;
  527. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  528. return -EINVAL;
  529. wname = strpbrk(w->name, "01234567");
  530. if (!wname) {
  531. dev_err(va_dev, "%s: widget not found\n", __func__);
  532. return -EINVAL;
  533. }
  534. ret = kstrtouint(wname, 10, &dmic);
  535. if (ret < 0) {
  536. dev_err(va_dev, "%s: Invalid DMIC line on the codec\n",
  537. __func__);
  538. return -EINVAL;
  539. }
  540. switch (dmic) {
  541. case 0:
  542. case 1:
  543. dmic_clk_cnt = &(va_priv->dmic_0_1_clk_cnt);
  544. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  545. break;
  546. case 2:
  547. case 3:
  548. dmic_clk_cnt = &(va_priv->dmic_2_3_clk_cnt);
  549. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  550. break;
  551. case 4:
  552. case 5:
  553. dmic_clk_cnt = &(va_priv->dmic_4_5_clk_cnt);
  554. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  555. break;
  556. case 6:
  557. case 7:
  558. dmic_clk_cnt = &(va_priv->dmic_6_7_clk_cnt);
  559. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  560. break;
  561. default:
  562. dev_err(va_dev, "%s: Invalid DMIC Selection\n",
  563. __func__);
  564. return -EINVAL;
  565. }
  566. dev_dbg(va_dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  567. __func__, event, dmic, *dmic_clk_cnt);
  568. switch (event) {
  569. case SND_SOC_DAPM_PRE_PMU:
  570. (*dmic_clk_cnt)++;
  571. if (*dmic_clk_cnt == 1) {
  572. snd_soc_component_update_bits(component,
  573. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  574. 0x80, 0x00);
  575. snd_soc_component_update_bits(component, dmic_clk_reg,
  576. VA_MACRO_TX_DMIC_CLK_DIV_MASK,
  577. va_priv->dmic_clk_div <<
  578. VA_MACRO_TX_DMIC_CLK_DIV_SHFT);
  579. snd_soc_component_update_bits(component, dmic_clk_reg,
  580. dmic_clk_en, dmic_clk_en);
  581. }
  582. break;
  583. case SND_SOC_DAPM_POST_PMD:
  584. (*dmic_clk_cnt)--;
  585. if (*dmic_clk_cnt == 0) {
  586. snd_soc_component_update_bits(component, dmic_clk_reg,
  587. dmic_clk_en, 0);
  588. }
  589. break;
  590. }
  591. return 0;
  592. }
  593. static int va_macro_enable_dec(struct snd_soc_dapm_widget *w,
  594. struct snd_kcontrol *kcontrol, int event)
  595. {
  596. struct snd_soc_component *component =
  597. snd_soc_dapm_to_component(w->dapm);
  598. unsigned int decimator;
  599. u16 tx_vol_ctl_reg, dec_cfg_reg, hpf_gate_reg;
  600. u16 tx_gain_ctl_reg;
  601. u8 hpf_cut_off_freq;
  602. struct device *va_dev = NULL;
  603. struct va_macro_priv *va_priv = NULL;
  604. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  605. return -EINVAL;
  606. decimator = w->shift;
  607. dev_dbg(va_dev, "%s(): widget = %s decimator = %u\n", __func__,
  608. w->name, decimator);
  609. tx_vol_ctl_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  610. VA_MACRO_TX_PATH_OFFSET * decimator;
  611. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  612. VA_MACRO_TX_PATH_OFFSET * decimator;
  613. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  614. VA_MACRO_TX_PATH_OFFSET * decimator;
  615. tx_gain_ctl_reg = BOLERO_CDC_VA_TX0_TX_VOL_CTL +
  616. VA_MACRO_TX_PATH_OFFSET * decimator;
  617. switch (event) {
  618. case SND_SOC_DAPM_PRE_PMU:
  619. /* Enable TX PGA Mute */
  620. snd_soc_component_update_bits(component,
  621. tx_vol_ctl_reg, 0x10, 0x10);
  622. break;
  623. case SND_SOC_DAPM_POST_PMU:
  624. /* Enable TX CLK */
  625. snd_soc_component_update_bits(component,
  626. tx_vol_ctl_reg, 0x20, 0x20);
  627. snd_soc_component_update_bits(component,
  628. hpf_gate_reg, 0x01, 0x00);
  629. hpf_cut_off_freq = (snd_soc_component_read32(
  630. component, dec_cfg_reg) &
  631. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  632. va_priv->va_hpf_work[decimator].hpf_cut_off_freq =
  633. hpf_cut_off_freq;
  634. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  635. snd_soc_component_update_bits(component, dec_cfg_reg,
  636. TX_HPF_CUT_OFF_FREQ_MASK,
  637. CF_MIN_3DB_150HZ << 5);
  638. snd_soc_component_update_bits(component,
  639. hpf_gate_reg, 0x02, 0x02);
  640. /*
  641. * Minimum 1 clk cycle delay is required as per HW spec
  642. */
  643. usleep_range(1000, 1010);
  644. snd_soc_component_update_bits(component,
  645. hpf_gate_reg, 0x02, 0x00);
  646. }
  647. /* schedule work queue to Remove Mute */
  648. schedule_delayed_work(&va_priv->va_mute_dwork[decimator].dwork,
  649. msecs_to_jiffies(va_tx_unmute_delay));
  650. if (va_priv->va_hpf_work[decimator].hpf_cut_off_freq !=
  651. CF_MIN_3DB_150HZ)
  652. schedule_delayed_work(
  653. &va_priv->va_hpf_work[decimator].dwork,
  654. msecs_to_jiffies(50));
  655. /* apply gain after decimator is enabled */
  656. snd_soc_component_write(component, tx_gain_ctl_reg,
  657. snd_soc_component_read32(component, tx_gain_ctl_reg));
  658. break;
  659. case SND_SOC_DAPM_PRE_PMD:
  660. hpf_cut_off_freq =
  661. va_priv->va_hpf_work[decimator].hpf_cut_off_freq;
  662. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  663. 0x10, 0x10);
  664. if (cancel_delayed_work_sync(
  665. &va_priv->va_hpf_work[decimator].dwork)) {
  666. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  667. snd_soc_component_update_bits(component,
  668. dec_cfg_reg,
  669. TX_HPF_CUT_OFF_FREQ_MASK,
  670. hpf_cut_off_freq << 5);
  671. snd_soc_component_update_bits(component,
  672. hpf_gate_reg,
  673. 0x02, 0x02);
  674. /*
  675. * Minimum 1 clk cycle delay is required
  676. * as per HW spec
  677. */
  678. usleep_range(1000, 1010);
  679. snd_soc_component_update_bits(component,
  680. hpf_gate_reg,
  681. 0x02, 0x00);
  682. }
  683. }
  684. cancel_delayed_work_sync(
  685. &va_priv->va_mute_dwork[decimator].dwork);
  686. break;
  687. case SND_SOC_DAPM_POST_PMD:
  688. /* Disable TX CLK */
  689. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  690. 0x20, 0x00);
  691. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  692. 0x10, 0x00);
  693. break;
  694. }
  695. return 0;
  696. }
  697. static int va_macro_enable_tx(struct snd_soc_dapm_widget *w,
  698. struct snd_kcontrol *kcontrol, int event)
  699. {
  700. struct snd_soc_component *component =
  701. snd_soc_dapm_to_component(w->dapm);
  702. struct device *va_dev = NULL;
  703. struct va_macro_priv *va_priv = NULL;
  704. int ret = 0;
  705. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  706. return -EINVAL;
  707. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  708. switch (event) {
  709. case SND_SOC_DAPM_POST_PMU:
  710. if (bolero_tx_clk_switch(component))
  711. dev_dbg(va_dev, "%s: clock switch failed\n",__func__);
  712. if (va_priv->tx_clk_status > 0) {
  713. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  714. va_priv->default_clk_id,
  715. TX_CORE_CLK,
  716. false);
  717. va_priv->tx_clk_status--;
  718. }
  719. break;
  720. case SND_SOC_DAPM_PRE_PMD:
  721. ret = bolero_clk_rsc_request_clock(va_priv->dev,
  722. va_priv->default_clk_id,
  723. TX_CORE_CLK,
  724. true);
  725. if (!ret)
  726. va_priv->tx_clk_status++;
  727. break;
  728. default:
  729. dev_err(va_priv->dev,
  730. "%s: invalid DAPM event %d\n", __func__, event);
  731. ret = -EINVAL;
  732. break;
  733. }
  734. return ret;
  735. }
  736. static int va_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  737. struct snd_kcontrol *kcontrol, int event)
  738. {
  739. struct snd_soc_component *component =
  740. snd_soc_dapm_to_component(w->dapm);
  741. struct device *va_dev = NULL;
  742. struct va_macro_priv *va_priv = NULL;
  743. int ret = 0;
  744. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  745. return -EINVAL;
  746. if (!va_priv->micb_supply) {
  747. dev_err(va_dev,
  748. "%s:regulator not provided in dtsi\n", __func__);
  749. return -EINVAL;
  750. }
  751. switch (event) {
  752. case SND_SOC_DAPM_PRE_PMU:
  753. if (va_priv->micb_users++ > 0)
  754. return 0;
  755. ret = regulator_set_voltage(va_priv->micb_supply,
  756. va_priv->micb_voltage,
  757. va_priv->micb_voltage);
  758. if (ret) {
  759. dev_err(va_dev, "%s: Setting voltage failed, err = %d\n",
  760. __func__, ret);
  761. return ret;
  762. }
  763. ret = regulator_set_load(va_priv->micb_supply,
  764. va_priv->micb_current);
  765. if (ret) {
  766. dev_err(va_dev, "%s: Setting current failed, err = %d\n",
  767. __func__, ret);
  768. return ret;
  769. }
  770. ret = regulator_enable(va_priv->micb_supply);
  771. if (ret) {
  772. dev_err(va_dev, "%s: regulator enable failed, err = %d\n",
  773. __func__, ret);
  774. return ret;
  775. }
  776. break;
  777. case SND_SOC_DAPM_POST_PMD:
  778. if (--va_priv->micb_users > 0)
  779. return 0;
  780. if (va_priv->micb_users < 0) {
  781. va_priv->micb_users = 0;
  782. dev_dbg(va_dev, "%s: regulator already disabled\n",
  783. __func__);
  784. return 0;
  785. }
  786. ret = regulator_disable(va_priv->micb_supply);
  787. if (ret) {
  788. dev_err(va_dev, "%s: regulator disable failed, err = %d\n",
  789. __func__, ret);
  790. return ret;
  791. }
  792. regulator_set_voltage(va_priv->micb_supply, 0,
  793. va_priv->micb_voltage);
  794. regulator_set_load(va_priv->micb_supply, 0);
  795. break;
  796. }
  797. return 0;
  798. }
  799. static int va_macro_hw_params(struct snd_pcm_substream *substream,
  800. struct snd_pcm_hw_params *params,
  801. struct snd_soc_dai *dai)
  802. {
  803. int tx_fs_rate = -EINVAL;
  804. struct snd_soc_component *component = dai->component;
  805. u32 decimator, sample_rate;
  806. u16 tx_fs_reg = 0;
  807. struct device *va_dev = NULL;
  808. struct va_macro_priv *va_priv = NULL;
  809. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  810. return -EINVAL;
  811. dev_dbg(va_dev,
  812. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  813. dai->name, dai->id, params_rate(params),
  814. params_channels(params));
  815. sample_rate = params_rate(params);
  816. switch (sample_rate) {
  817. case 8000:
  818. tx_fs_rate = 0;
  819. break;
  820. case 16000:
  821. tx_fs_rate = 1;
  822. break;
  823. case 32000:
  824. tx_fs_rate = 3;
  825. break;
  826. case 48000:
  827. tx_fs_rate = 4;
  828. break;
  829. case 96000:
  830. tx_fs_rate = 5;
  831. break;
  832. case 192000:
  833. tx_fs_rate = 6;
  834. break;
  835. case 384000:
  836. tx_fs_rate = 7;
  837. break;
  838. default:
  839. dev_err(va_dev, "%s: Invalid TX sample rate: %d\n",
  840. __func__, params_rate(params));
  841. return -EINVAL;
  842. }
  843. for_each_set_bit(decimator, &va_priv->active_ch_mask[dai->id],
  844. VA_MACRO_DEC_MAX) {
  845. if (decimator >= 0) {
  846. tx_fs_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  847. VA_MACRO_TX_PATH_OFFSET * decimator;
  848. dev_dbg(va_dev, "%s: set DEC%u rate to %u\n",
  849. __func__, decimator, sample_rate);
  850. snd_soc_component_update_bits(component, tx_fs_reg,
  851. 0x0F, tx_fs_rate);
  852. } else {
  853. dev_err(va_dev,
  854. "%s: ERROR: Invalid decimator: %d\n",
  855. __func__, decimator);
  856. return -EINVAL;
  857. }
  858. }
  859. return 0;
  860. }
  861. static int va_macro_get_channel_map(struct snd_soc_dai *dai,
  862. unsigned int *tx_num, unsigned int *tx_slot,
  863. unsigned int *rx_num, unsigned int *rx_slot)
  864. {
  865. struct snd_soc_component *component = dai->component;
  866. struct device *va_dev = NULL;
  867. struct va_macro_priv *va_priv = NULL;
  868. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  869. return -EINVAL;
  870. switch (dai->id) {
  871. case VA_MACRO_AIF1_CAP:
  872. case VA_MACRO_AIF2_CAP:
  873. case VA_MACRO_AIF3_CAP:
  874. *tx_slot = va_priv->active_ch_mask[dai->id];
  875. *tx_num = va_priv->active_ch_cnt[dai->id];
  876. break;
  877. default:
  878. dev_err(va_dev, "%s: Invalid AIF\n", __func__);
  879. break;
  880. }
  881. return 0;
  882. }
  883. static struct snd_soc_dai_ops va_macro_dai_ops = {
  884. .hw_params = va_macro_hw_params,
  885. .get_channel_map = va_macro_get_channel_map,
  886. };
  887. static struct snd_soc_dai_driver va_macro_dai[] = {
  888. {
  889. .name = "va_macro_tx1",
  890. .id = VA_MACRO_AIF1_CAP,
  891. .capture = {
  892. .stream_name = "VA_AIF1 Capture",
  893. .rates = VA_MACRO_RATES,
  894. .formats = VA_MACRO_FORMATS,
  895. .rate_max = 192000,
  896. .rate_min = 8000,
  897. .channels_min = 1,
  898. .channels_max = 8,
  899. },
  900. .ops = &va_macro_dai_ops,
  901. },
  902. {
  903. .name = "va_macro_tx2",
  904. .id = VA_MACRO_AIF2_CAP,
  905. .capture = {
  906. .stream_name = "VA_AIF2 Capture",
  907. .rates = VA_MACRO_RATES,
  908. .formats = VA_MACRO_FORMATS,
  909. .rate_max = 192000,
  910. .rate_min = 8000,
  911. .channels_min = 1,
  912. .channels_max = 8,
  913. },
  914. .ops = &va_macro_dai_ops,
  915. },
  916. {
  917. .name = "va_macro_tx3",
  918. .id = VA_MACRO_AIF3_CAP,
  919. .capture = {
  920. .stream_name = "VA_AIF3 Capture",
  921. .rates = VA_MACRO_RATES,
  922. .formats = VA_MACRO_FORMATS,
  923. .rate_max = 192000,
  924. .rate_min = 8000,
  925. .channels_min = 1,
  926. .channels_max = 8,
  927. },
  928. .ops = &va_macro_dai_ops,
  929. },
  930. };
  931. #define STRING(name) #name
  932. #define VA_MACRO_DAPM_ENUM(name, reg, offset, text) \
  933. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  934. static const struct snd_kcontrol_new name##_mux = \
  935. SOC_DAPM_ENUM(STRING(name), name##_enum)
  936. #define VA_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  937. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  938. static const struct snd_kcontrol_new name##_mux = \
  939. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  940. #define VA_MACRO_DAPM_MUX(name, shift, kctl) \
  941. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  942. static const char * const adc_mux_text[] = {
  943. "MSM_DMIC", "SWR_MIC"
  944. };
  945. VA_MACRO_DAPM_ENUM(va_dec0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1,
  946. 0, adc_mux_text);
  947. VA_MACRO_DAPM_ENUM(va_dec1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG1,
  948. 0, adc_mux_text);
  949. VA_MACRO_DAPM_ENUM(va_dec2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG1,
  950. 0, adc_mux_text);
  951. VA_MACRO_DAPM_ENUM(va_dec3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG1,
  952. 0, adc_mux_text);
  953. VA_MACRO_DAPM_ENUM(va_dec4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG1,
  954. 0, adc_mux_text);
  955. VA_MACRO_DAPM_ENUM(va_dec5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG1,
  956. 0, adc_mux_text);
  957. VA_MACRO_DAPM_ENUM(va_dec6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG1,
  958. 0, adc_mux_text);
  959. VA_MACRO_DAPM_ENUM(va_dec7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG1,
  960. 0, adc_mux_text);
  961. static const char * const dmic_mux_text[] = {
  962. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  963. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  964. };
  965. VA_MACRO_DAPM_ENUM_EXT(va_dmic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  966. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  967. va_macro_put_dec_enum);
  968. VA_MACRO_DAPM_ENUM_EXT(va_dmic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  969. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  970. va_macro_put_dec_enum);
  971. VA_MACRO_DAPM_ENUM_EXT(va_dmic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  972. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  973. va_macro_put_dec_enum);
  974. VA_MACRO_DAPM_ENUM_EXT(va_dmic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  975. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  976. va_macro_put_dec_enum);
  977. VA_MACRO_DAPM_ENUM_EXT(va_dmic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  978. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  979. va_macro_put_dec_enum);
  980. VA_MACRO_DAPM_ENUM_EXT(va_dmic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  981. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  982. va_macro_put_dec_enum);
  983. VA_MACRO_DAPM_ENUM_EXT(va_dmic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  984. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  985. va_macro_put_dec_enum);
  986. VA_MACRO_DAPM_ENUM_EXT(va_dmic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  987. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  988. va_macro_put_dec_enum);
  989. static const char * const smic_mux_text[] = {
  990. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3",
  991. "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
  992. "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  993. };
  994. VA_MACRO_DAPM_ENUM_EXT(va_smic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  995. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  996. va_macro_put_dec_enum);
  997. VA_MACRO_DAPM_ENUM_EXT(va_smic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  998. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  999. va_macro_put_dec_enum);
  1000. VA_MACRO_DAPM_ENUM_EXT(va_smic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  1001. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1002. va_macro_put_dec_enum);
  1003. VA_MACRO_DAPM_ENUM_EXT(va_smic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  1004. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1005. va_macro_put_dec_enum);
  1006. VA_MACRO_DAPM_ENUM_EXT(va_smic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  1007. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1008. va_macro_put_dec_enum);
  1009. VA_MACRO_DAPM_ENUM_EXT(va_smic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  1010. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1011. va_macro_put_dec_enum);
  1012. VA_MACRO_DAPM_ENUM_EXT(va_smic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  1013. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1014. va_macro_put_dec_enum);
  1015. VA_MACRO_DAPM_ENUM_EXT(va_smic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  1016. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1017. va_macro_put_dec_enum);
  1018. static const struct snd_kcontrol_new va_aif1_cap_mixer[] = {
  1019. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1020. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1021. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1022. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1023. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1024. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1025. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1026. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1027. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1028. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1029. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1030. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1031. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1032. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1033. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1034. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1035. };
  1036. static const struct snd_kcontrol_new va_aif2_cap_mixer[] = {
  1037. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1038. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1039. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1040. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1041. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1042. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1043. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1044. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1045. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1046. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1047. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1048. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1049. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1050. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1051. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1052. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1053. };
  1054. static const struct snd_kcontrol_new va_aif3_cap_mixer[] = {
  1055. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  1056. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1057. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  1058. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1059. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  1060. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1061. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  1062. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1063. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  1064. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1065. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  1066. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1067. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  1068. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1069. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  1070. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  1071. };
  1072. static const struct snd_soc_dapm_widget va_macro_dapm_widgets[] = {
  1073. SND_SOC_DAPM_AIF_OUT_E("VA_AIF1 CAP", "VA_AIF1 Capture", 0,
  1074. SND_SOC_NOPM, VA_MACRO_AIF1_CAP, 0,
  1075. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1076. SND_SOC_DAPM_PRE_PMD),
  1077. SND_SOC_DAPM_AIF_OUT_E("VA_AIF2 CAP", "VA_AIF2 Capture", 0,
  1078. SND_SOC_NOPM, VA_MACRO_AIF2_CAP, 0,
  1079. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1080. SND_SOC_DAPM_PRE_PMD),
  1081. SND_SOC_DAPM_AIF_OUT_E("VA_AIF3 CAP", "VA_AIF3 Capture", 0,
  1082. SND_SOC_NOPM, VA_MACRO_AIF3_CAP, 0,
  1083. va_macro_enable_tx, SND_SOC_DAPM_POST_PMU |
  1084. SND_SOC_DAPM_PRE_PMD),
  1085. SND_SOC_DAPM_MIXER("VA_AIF1_CAP Mixer", SND_SOC_NOPM,
  1086. VA_MACRO_AIF1_CAP, 0,
  1087. va_aif1_cap_mixer, ARRAY_SIZE(va_aif1_cap_mixer)),
  1088. SND_SOC_DAPM_MIXER("VA_AIF2_CAP Mixer", SND_SOC_NOPM,
  1089. VA_MACRO_AIF2_CAP, 0,
  1090. va_aif2_cap_mixer, ARRAY_SIZE(va_aif2_cap_mixer)),
  1091. SND_SOC_DAPM_MIXER("VA_AIF3_CAP Mixer", SND_SOC_NOPM,
  1092. VA_MACRO_AIF3_CAP, 0,
  1093. va_aif3_cap_mixer, ARRAY_SIZE(va_aif3_cap_mixer)),
  1094. VA_MACRO_DAPM_MUX("VA DMIC MUX0", 0, va_dmic0),
  1095. VA_MACRO_DAPM_MUX("VA DMIC MUX1", 0, va_dmic1),
  1096. VA_MACRO_DAPM_MUX("VA DMIC MUX2", 0, va_dmic2),
  1097. VA_MACRO_DAPM_MUX("VA DMIC MUX3", 0, va_dmic3),
  1098. VA_MACRO_DAPM_MUX("VA DMIC MUX4", 0, va_dmic4),
  1099. VA_MACRO_DAPM_MUX("VA DMIC MUX5", 0, va_dmic5),
  1100. VA_MACRO_DAPM_MUX("VA DMIC MUX6", 0, va_dmic6),
  1101. VA_MACRO_DAPM_MUX("VA DMIC MUX7", 0, va_dmic7),
  1102. VA_MACRO_DAPM_MUX("VA SMIC MUX0", 0, va_smic0),
  1103. VA_MACRO_DAPM_MUX("VA SMIC MUX1", 0, va_smic1),
  1104. VA_MACRO_DAPM_MUX("VA SMIC MUX2", 0, va_smic2),
  1105. VA_MACRO_DAPM_MUX("VA SMIC MUX3", 0, va_smic3),
  1106. VA_MACRO_DAPM_MUX("VA SMIC MUX4", 0, va_smic4),
  1107. VA_MACRO_DAPM_MUX("VA SMIC MUX5", 0, va_smic5),
  1108. VA_MACRO_DAPM_MUX("VA SMIC MUX6", 0, va_smic6),
  1109. VA_MACRO_DAPM_MUX("VA SMIC MUX7", 0, va_smic7),
  1110. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1111. va_macro_enable_micbias,
  1112. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1113. SND_SOC_DAPM_ADC_E("VA DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1114. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1115. SND_SOC_DAPM_POST_PMD),
  1116. SND_SOC_DAPM_ADC_E("VA DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1117. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1118. SND_SOC_DAPM_POST_PMD),
  1119. SND_SOC_DAPM_ADC_E("VA DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1120. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1121. SND_SOC_DAPM_POST_PMD),
  1122. SND_SOC_DAPM_ADC_E("VA DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1123. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1124. SND_SOC_DAPM_POST_PMD),
  1125. SND_SOC_DAPM_ADC_E("VA DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1126. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1127. SND_SOC_DAPM_POST_PMD),
  1128. SND_SOC_DAPM_ADC_E("VA DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1129. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1130. SND_SOC_DAPM_POST_PMD),
  1131. SND_SOC_DAPM_ADC_E("VA DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1132. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1133. SND_SOC_DAPM_POST_PMD),
  1134. SND_SOC_DAPM_ADC_E("VA DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1135. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1136. SND_SOC_DAPM_POST_PMD),
  1137. SND_SOC_DAPM_INPUT("VA SWR_ADC0"),
  1138. SND_SOC_DAPM_INPUT("VA SWR_ADC1"),
  1139. SND_SOC_DAPM_INPUT("VA SWR_ADC2"),
  1140. SND_SOC_DAPM_INPUT("VA SWR_ADC3"),
  1141. SND_SOC_DAPM_INPUT("VA SWR_MIC0"),
  1142. SND_SOC_DAPM_INPUT("VA SWR_MIC1"),
  1143. SND_SOC_DAPM_INPUT("VA SWR_MIC2"),
  1144. SND_SOC_DAPM_INPUT("VA SWR_MIC3"),
  1145. SND_SOC_DAPM_INPUT("VA SWR_MIC4"),
  1146. SND_SOC_DAPM_INPUT("VA SWR_MIC5"),
  1147. SND_SOC_DAPM_INPUT("VA SWR_MIC6"),
  1148. SND_SOC_DAPM_INPUT("VA SWR_MIC7"),
  1149. SND_SOC_DAPM_MUX_E("VA DEC0 MUX", SND_SOC_NOPM, VA_MACRO_DEC0, 0,
  1150. &va_dec0_mux, va_macro_enable_dec,
  1151. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1152. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1153. SND_SOC_DAPM_MUX_E("VA DEC1 MUX", SND_SOC_NOPM, VA_MACRO_DEC1, 0,
  1154. &va_dec1_mux, va_macro_enable_dec,
  1155. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1156. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1157. SND_SOC_DAPM_MUX_E("VA DEC2 MUX", SND_SOC_NOPM, VA_MACRO_DEC2, 0,
  1158. &va_dec2_mux, va_macro_enable_dec,
  1159. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1160. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1161. SND_SOC_DAPM_MUX_E("VA DEC3 MUX", SND_SOC_NOPM, VA_MACRO_DEC3, 0,
  1162. &va_dec3_mux, va_macro_enable_dec,
  1163. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1164. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1165. SND_SOC_DAPM_MUX_E("VA DEC4 MUX", SND_SOC_NOPM, VA_MACRO_DEC4, 0,
  1166. &va_dec4_mux, va_macro_enable_dec,
  1167. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1168. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1169. SND_SOC_DAPM_MUX_E("VA DEC5 MUX", SND_SOC_NOPM, VA_MACRO_DEC5, 0,
  1170. &va_dec5_mux, va_macro_enable_dec,
  1171. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1172. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1173. SND_SOC_DAPM_MUX_E("VA DEC6 MUX", SND_SOC_NOPM, VA_MACRO_DEC6, 0,
  1174. &va_dec6_mux, va_macro_enable_dec,
  1175. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1176. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1177. SND_SOC_DAPM_MUX_E("VA DEC7 MUX", SND_SOC_NOPM, VA_MACRO_DEC7, 0,
  1178. &va_dec7_mux, va_macro_enable_dec,
  1179. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1180. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1181. SND_SOC_DAPM_SUPPLY_S("VA_SWR_PWR", -1, SND_SOC_NOPM, 0, 0,
  1182. va_macro_swr_pwr_event,
  1183. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1184. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", -1, SND_SOC_NOPM, 0, 0,
  1185. va_macro_mclk_event,
  1186. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1187. };
  1188. static const struct snd_soc_dapm_widget va_macro_wod_dapm_widgets[] = {
  1189. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", -1, SND_SOC_NOPM, 0, 0,
  1190. va_macro_mclk_event,
  1191. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1192. };
  1193. static const struct snd_soc_dapm_route va_audio_map[] = {
  1194. {"VA_AIF1 CAP", NULL, "VA_MCLK"},
  1195. {"VA_AIF2 CAP", NULL, "VA_MCLK"},
  1196. {"VA_AIF3 CAP", NULL, "VA_MCLK"},
  1197. {"VA_AIF1 CAP", NULL, "VA_AIF1_CAP Mixer"},
  1198. {"VA_AIF2 CAP", NULL, "VA_AIF2_CAP Mixer"},
  1199. {"VA_AIF3 CAP", NULL, "VA_AIF3_CAP Mixer"},
  1200. {"VA_AIF1_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1201. {"VA_AIF1_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1202. {"VA_AIF1_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  1203. {"VA_AIF1_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  1204. {"VA_AIF1_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  1205. {"VA_AIF1_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  1206. {"VA_AIF1_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  1207. {"VA_AIF1_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  1208. {"VA_AIF2_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1209. {"VA_AIF2_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1210. {"VA_AIF2_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  1211. {"VA_AIF2_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  1212. {"VA_AIF2_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  1213. {"VA_AIF2_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  1214. {"VA_AIF2_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  1215. {"VA_AIF2_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  1216. {"VA_AIF3_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  1217. {"VA_AIF3_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  1218. {"VA_AIF3_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  1219. {"VA_AIF3_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  1220. {"VA_AIF3_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  1221. {"VA_AIF3_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  1222. {"VA_AIF3_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  1223. {"VA_AIF3_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  1224. {"VA DEC0 MUX", "MSM_DMIC", "VA DMIC MUX0"},
  1225. {"VA DMIC MUX0", "DMIC0", "VA DMIC0"},
  1226. {"VA DMIC MUX0", "DMIC1", "VA DMIC1"},
  1227. {"VA DMIC MUX0", "DMIC2", "VA DMIC2"},
  1228. {"VA DMIC MUX0", "DMIC3", "VA DMIC3"},
  1229. {"VA DMIC MUX0", "DMIC4", "VA DMIC4"},
  1230. {"VA DMIC MUX0", "DMIC5", "VA DMIC5"},
  1231. {"VA DMIC MUX0", "DMIC6", "VA DMIC6"},
  1232. {"VA DMIC MUX0", "DMIC7", "VA DMIC7"},
  1233. {"VA DEC0 MUX", "SWR_MIC", "VA SMIC MUX0"},
  1234. {"VA SMIC MUX0", "ADC0", "VA SWR_ADC0"},
  1235. {"VA SMIC MUX0", "ADC1", "VA SWR_ADC1"},
  1236. {"VA SMIC MUX0", "ADC2", "VA SWR_ADC2"},
  1237. {"VA SMIC MUX0", "ADC3", "VA SWR_ADC3"},
  1238. {"VA SMIC MUX0", "SWR_DMIC0", "VA SWR_MIC0"},
  1239. {"VA SMIC MUX0", "SWR_DMIC1", "VA SWR_MIC1"},
  1240. {"VA SMIC MUX0", "SWR_DMIC2", "VA SWR_MIC2"},
  1241. {"VA SMIC MUX0", "SWR_DMIC3", "VA SWR_MIC3"},
  1242. {"VA SMIC MUX0", "SWR_DMIC4", "VA SWR_MIC4"},
  1243. {"VA SMIC MUX0", "SWR_DMIC5", "VA SWR_MIC5"},
  1244. {"VA SMIC MUX0", "SWR_DMIC6", "VA SWR_MIC6"},
  1245. {"VA SMIC MUX0", "SWR_DMIC7", "VA SWR_MIC7"},
  1246. {"VA DEC1 MUX", "MSM_DMIC", "VA DMIC MUX1"},
  1247. {"VA DMIC MUX1", "DMIC0", "VA DMIC0"},
  1248. {"VA DMIC MUX1", "DMIC1", "VA DMIC1"},
  1249. {"VA DMIC MUX1", "DMIC2", "VA DMIC2"},
  1250. {"VA DMIC MUX1", "DMIC3", "VA DMIC3"},
  1251. {"VA DMIC MUX1", "DMIC4", "VA DMIC4"},
  1252. {"VA DMIC MUX1", "DMIC5", "VA DMIC5"},
  1253. {"VA DMIC MUX1", "DMIC6", "VA DMIC6"},
  1254. {"VA DMIC MUX1", "DMIC7", "VA DMIC7"},
  1255. {"VA DEC1 MUX", "SWR_MIC", "VA SMIC MUX1"},
  1256. {"VA SMIC MUX1", "ADC0", "VA SWR_ADC0"},
  1257. {"VA SMIC MUX1", "ADC1", "VA SWR_ADC1"},
  1258. {"VA SMIC MUX1", "ADC2", "VA SWR_ADC2"},
  1259. {"VA SMIC MUX1", "ADC3", "VA SWR_ADC3"},
  1260. {"VA SMIC MUX1", "SWR_DMIC0", "VA SWR_MIC0"},
  1261. {"VA SMIC MUX1", "SWR_DMIC1", "VA SWR_MIC1"},
  1262. {"VA SMIC MUX1", "SWR_DMIC2", "VA SWR_MIC2"},
  1263. {"VA SMIC MUX1", "SWR_DMIC3", "VA SWR_MIC3"},
  1264. {"VA SMIC MUX1", "SWR_DMIC4", "VA SWR_MIC4"},
  1265. {"VA SMIC MUX1", "SWR_DMIC5", "VA SWR_MIC5"},
  1266. {"VA SMIC MUX1", "SWR_DMIC6", "VA SWR_MIC6"},
  1267. {"VA SMIC MUX1", "SWR_DMIC7", "VA SWR_MIC7"},
  1268. {"VA DEC2 MUX", "MSM_DMIC", "VA DMIC MUX2"},
  1269. {"VA DMIC MUX2", "DMIC0", "VA DMIC0"},
  1270. {"VA DMIC MUX2", "DMIC1", "VA DMIC1"},
  1271. {"VA DMIC MUX2", "DMIC2", "VA DMIC2"},
  1272. {"VA DMIC MUX2", "DMIC3", "VA DMIC3"},
  1273. {"VA DMIC MUX2", "DMIC4", "VA DMIC4"},
  1274. {"VA DMIC MUX2", "DMIC5", "VA DMIC5"},
  1275. {"VA DMIC MUX2", "DMIC6", "VA DMIC6"},
  1276. {"VA DMIC MUX2", "DMIC7", "VA DMIC7"},
  1277. {"VA DEC2 MUX", "SWR_MIC", "VA SMIC MUX2"},
  1278. {"VA SMIC MUX2", "ADC0", "VA SWR_ADC0"},
  1279. {"VA SMIC MUX2", "ADC1", "VA SWR_ADC1"},
  1280. {"VA SMIC MUX2", "ADC2", "VA SWR_ADC2"},
  1281. {"VA SMIC MUX2", "ADC3", "VA SWR_ADC3"},
  1282. {"VA SMIC MUX2", "SWR_DMIC0", "VA SWR_MIC0"},
  1283. {"VA SMIC MUX2", "SWR_DMIC1", "VA SWR_MIC1"},
  1284. {"VA SMIC MUX2", "SWR_DMIC2", "VA SWR_MIC2"},
  1285. {"VA SMIC MUX2", "SWR_DMIC3", "VA SWR_MIC3"},
  1286. {"VA SMIC MUX2", "SWR_DMIC4", "VA SWR_MIC4"},
  1287. {"VA SMIC MUX2", "SWR_DMIC5", "VA SWR_MIC5"},
  1288. {"VA SMIC MUX2", "SWR_DMIC6", "VA SWR_MIC6"},
  1289. {"VA SMIC MUX2", "SWR_DMIC7", "VA SWR_MIC7"},
  1290. {"VA DEC3 MUX", "MSM_DMIC", "VA DMIC MUX3"},
  1291. {"VA DMIC MUX3", "DMIC0", "VA DMIC0"},
  1292. {"VA DMIC MUX3", "DMIC1", "VA DMIC1"},
  1293. {"VA DMIC MUX3", "DMIC2", "VA DMIC2"},
  1294. {"VA DMIC MUX3", "DMIC3", "VA DMIC3"},
  1295. {"VA DMIC MUX3", "DMIC4", "VA DMIC4"},
  1296. {"VA DMIC MUX3", "DMIC5", "VA DMIC5"},
  1297. {"VA DMIC MUX3", "DMIC6", "VA DMIC6"},
  1298. {"VA DMIC MUX3", "DMIC7", "VA DMIC7"},
  1299. {"VA DEC3 MUX", "SWR_MIC", "VA SMIC MUX3"},
  1300. {"VA SMIC MUX3", "ADC0", "VA SWR_ADC0"},
  1301. {"VA SMIC MUX3", "ADC1", "VA SWR_ADC1"},
  1302. {"VA SMIC MUX3", "ADC2", "VA SWR_ADC2"},
  1303. {"VA SMIC MUX3", "ADC3", "VA SWR_ADC3"},
  1304. {"VA SMIC MUX3", "SWR_DMIC0", "VA SWR_MIC0"},
  1305. {"VA SMIC MUX3", "SWR_DMIC1", "VA SWR_MIC1"},
  1306. {"VA SMIC MUX3", "SWR_DMIC2", "VA SWR_MIC2"},
  1307. {"VA SMIC MUX3", "SWR_DMIC3", "VA SWR_MIC3"},
  1308. {"VA SMIC MUX3", "SWR_DMIC4", "VA SWR_MIC4"},
  1309. {"VA SMIC MUX3", "SWR_DMIC5", "VA SWR_MIC5"},
  1310. {"VA SMIC MUX3", "SWR_DMIC6", "VA SWR_MIC6"},
  1311. {"VA SMIC MUX3", "SWR_DMIC7", "VA SWR_MIC7"},
  1312. {"VA DEC4 MUX", "MSM_DMIC", "VA DMIC MUX4"},
  1313. {"VA DMIC MUX4", "DMIC0", "VA DMIC0"},
  1314. {"VA DMIC MUX4", "DMIC1", "VA DMIC1"},
  1315. {"VA DMIC MUX4", "DMIC2", "VA DMIC2"},
  1316. {"VA DMIC MUX4", "DMIC3", "VA DMIC3"},
  1317. {"VA DMIC MUX4", "DMIC4", "VA DMIC4"},
  1318. {"VA DMIC MUX4", "DMIC5", "VA DMIC5"},
  1319. {"VA DMIC MUX4", "DMIC6", "VA DMIC6"},
  1320. {"VA DMIC MUX4", "DMIC7", "VA DMIC7"},
  1321. {"VA DEC4 MUX", "SWR_MIC", "VA SMIC MUX4"},
  1322. {"VA SMIC MUX4", "ADC0", "VA SWR_ADC0"},
  1323. {"VA SMIC MUX4", "ADC1", "VA SWR_ADC1"},
  1324. {"VA SMIC MUX4", "ADC2", "VA SWR_ADC2"},
  1325. {"VA SMIC MUX4", "ADC3", "VA SWR_ADC3"},
  1326. {"VA SMIC MUX4", "SWR_DMIC0", "VA SWR_MIC0"},
  1327. {"VA SMIC MUX4", "SWR_DMIC1", "VA SWR_MIC1"},
  1328. {"VA SMIC MUX4", "SWR_DMIC2", "VA SWR_MIC2"},
  1329. {"VA SMIC MUX4", "SWR_DMIC3", "VA SWR_MIC3"},
  1330. {"VA SMIC MUX4", "SWR_DMIC4", "VA SWR_MIC4"},
  1331. {"VA SMIC MUX4", "SWR_DMIC5", "VA SWR_MIC5"},
  1332. {"VA SMIC MUX4", "SWR_DMIC6", "VA SWR_MIC6"},
  1333. {"VA SMIC MUX4", "SWR_DMIC7", "VA SWR_MIC7"},
  1334. {"VA DEC5 MUX", "MSM_DMIC", "VA DMIC MUX5"},
  1335. {"VA DMIC MUX5", "DMIC0", "VA DMIC0"},
  1336. {"VA DMIC MUX5", "DMIC1", "VA DMIC1"},
  1337. {"VA DMIC MUX5", "DMIC2", "VA DMIC2"},
  1338. {"VA DMIC MUX5", "DMIC3", "VA DMIC3"},
  1339. {"VA DMIC MUX5", "DMIC4", "VA DMIC4"},
  1340. {"VA DMIC MUX5", "DMIC5", "VA DMIC5"},
  1341. {"VA DMIC MUX5", "DMIC6", "VA DMIC6"},
  1342. {"VA DMIC MUX5", "DMIC7", "VA DMIC7"},
  1343. {"VA DEC5 MUX", "SWR_MIC", "VA SMIC MUX5"},
  1344. {"VA SMIC MUX5", "ADC0", "VA SWR_ADC0"},
  1345. {"VA SMIC MUX5", "ADC1", "VA SWR_ADC1"},
  1346. {"VA SMIC MUX5", "ADC2", "VA SWR_ADC2"},
  1347. {"VA SMIC MUX5", "ADC3", "VA SWR_ADC3"},
  1348. {"VA SMIC MUX5", "SWR_DMIC0", "VA SWR_MIC0"},
  1349. {"VA SMIC MUX5", "SWR_DMIC1", "VA SWR_MIC1"},
  1350. {"VA SMIC MUX5", "SWR_DMIC2", "VA SWR_MIC2"},
  1351. {"VA SMIC MUX5", "SWR_DMIC3", "VA SWR_MIC3"},
  1352. {"VA SMIC MUX5", "SWR_DMIC4", "VA SWR_MIC4"},
  1353. {"VA SMIC MUX5", "SWR_DMIC5", "VA SWR_MIC5"},
  1354. {"VA SMIC MUX5", "SWR_DMIC6", "VA SWR_MIC6"},
  1355. {"VA SMIC MUX5", "SWR_DMIC7", "VA SWR_MIC7"},
  1356. {"VA DEC6 MUX", "MSM_DMIC", "VA DMIC MUX6"},
  1357. {"VA DMIC MUX6", "DMIC0", "VA DMIC0"},
  1358. {"VA DMIC MUX6", "DMIC1", "VA DMIC1"},
  1359. {"VA DMIC MUX6", "DMIC2", "VA DMIC2"},
  1360. {"VA DMIC MUX6", "DMIC3", "VA DMIC3"},
  1361. {"VA DMIC MUX6", "DMIC4", "VA DMIC4"},
  1362. {"VA DMIC MUX6", "DMIC5", "VA DMIC5"},
  1363. {"VA DMIC MUX6", "DMIC6", "VA DMIC6"},
  1364. {"VA DMIC MUX6", "DMIC7", "VA DMIC7"},
  1365. {"VA DEC6 MUX", "SWR_MIC", "VA SMIC MUX6"},
  1366. {"VA SMIC MUX6", "ADC0", "VA SWR_ADC0"},
  1367. {"VA SMIC MUX6", "ADC1", "VA SWR_ADC1"},
  1368. {"VA SMIC MUX6", "ADC2", "VA SWR_ADC2"},
  1369. {"VA SMIC MUX6", "ADC3", "VA SWR_ADC3"},
  1370. {"VA SMIC MUX6", "SWR_DMIC0", "VA SWR_MIC0"},
  1371. {"VA SMIC MUX6", "SWR_DMIC1", "VA SWR_MIC1"},
  1372. {"VA SMIC MUX6", "SWR_DMIC2", "VA SWR_MIC2"},
  1373. {"VA SMIC MUX6", "SWR_DMIC3", "VA SWR_MIC3"},
  1374. {"VA SMIC MUX6", "SWR_DMIC4", "VA SWR_MIC4"},
  1375. {"VA SMIC MUX6", "SWR_DMIC5", "VA SWR_MIC5"},
  1376. {"VA SMIC MUX6", "SWR_DMIC6", "VA SWR_MIC6"},
  1377. {"VA SMIC MUX6", "SWR_DMIC7", "VA SWR_MIC7"},
  1378. {"VA DEC7 MUX", "MSM_DMIC", "VA DMIC MUX7"},
  1379. {"VA DMIC MUX7", "DMIC0", "VA DMIC0"},
  1380. {"VA DMIC MUX7", "DMIC1", "VA DMIC1"},
  1381. {"VA DMIC MUX7", "DMIC2", "VA DMIC2"},
  1382. {"VA DMIC MUX7", "DMIC3", "VA DMIC3"},
  1383. {"VA DMIC MUX7", "DMIC4", "VA DMIC4"},
  1384. {"VA DMIC MUX7", "DMIC5", "VA DMIC5"},
  1385. {"VA DMIC MUX7", "DMIC6", "VA DMIC6"},
  1386. {"VA DMIC MUX7", "DMIC7", "VA DMIC7"},
  1387. {"VA DEC7 MUX", "SWR_MIC", "VA SMIC MUX7"},
  1388. {"VA SMIC MUX7", "ADC0", "VA SWR_ADC0"},
  1389. {"VA SMIC MUX7", "ADC1", "VA SWR_ADC1"},
  1390. {"VA SMIC MUX7", "ADC2", "VA SWR_ADC2"},
  1391. {"VA SMIC MUX7", "ADC3", "VA SWR_ADC3"},
  1392. {"VA SMIC MUX7", "SWR_DMIC0", "VA SWR_MIC0"},
  1393. {"VA SMIC MUX7", "SWR_DMIC1", "VA SWR_MIC1"},
  1394. {"VA SMIC MUX7", "SWR_DMIC2", "VA SWR_MIC2"},
  1395. {"VA SMIC MUX7", "SWR_DMIC3", "VA SWR_MIC3"},
  1396. {"VA SMIC MUX7", "SWR_DMIC4", "VA SWR_MIC4"},
  1397. {"VA SMIC MUX7", "SWR_DMIC5", "VA SWR_MIC5"},
  1398. {"VA SMIC MUX7", "SWR_DMIC6", "VA SWR_MIC6"},
  1399. {"VA SMIC MUX7", "SWR_DMIC7", "VA SWR_MIC7"},
  1400. {"VA SWR_ADC0", NULL, "VA_SWR_PWR"},
  1401. {"VA SWR_ADC1", NULL, "VA_SWR_PWR"},
  1402. {"VA SWR_ADC2", NULL, "VA_SWR_PWR"},
  1403. {"VA SWR_ADC3", NULL, "VA_SWR_PWR"},
  1404. };
  1405. static const struct snd_kcontrol_new va_macro_snd_controls[] = {
  1406. SOC_SINGLE_SX_TLV("VA_DEC0 Volume",
  1407. BOLERO_CDC_VA_TX0_TX_VOL_CTL,
  1408. 0, -84, 40, digital_gain),
  1409. SOC_SINGLE_SX_TLV("VA_DEC1 Volume",
  1410. BOLERO_CDC_VA_TX1_TX_VOL_CTL,
  1411. 0, -84, 40, digital_gain),
  1412. SOC_SINGLE_SX_TLV("VA_DEC2 Volume",
  1413. BOLERO_CDC_VA_TX2_TX_VOL_CTL,
  1414. 0, -84, 40, digital_gain),
  1415. SOC_SINGLE_SX_TLV("VA_DEC3 Volume",
  1416. BOLERO_CDC_VA_TX3_TX_VOL_CTL,
  1417. 0, -84, 40, digital_gain),
  1418. SOC_SINGLE_SX_TLV("VA_DEC4 Volume",
  1419. BOLERO_CDC_VA_TX4_TX_VOL_CTL,
  1420. 0, -84, 40, digital_gain),
  1421. SOC_SINGLE_SX_TLV("VA_DEC5 Volume",
  1422. BOLERO_CDC_VA_TX5_TX_VOL_CTL,
  1423. 0, -84, 40, digital_gain),
  1424. SOC_SINGLE_SX_TLV("VA_DEC6 Volume",
  1425. BOLERO_CDC_VA_TX6_TX_VOL_CTL,
  1426. 0, -84, 40, digital_gain),
  1427. SOC_SINGLE_SX_TLV("VA_DEC7 Volume",
  1428. BOLERO_CDC_VA_TX7_TX_VOL_CTL,
  1429. 0, -84, 40, digital_gain),
  1430. };
  1431. static int va_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1432. struct va_macro_priv *va_priv)
  1433. {
  1434. u32 div_factor;
  1435. u32 mclk_rate = VA_MACRO_MCLK_FREQ;
  1436. if (dmic_sample_rate == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1437. mclk_rate % dmic_sample_rate != 0)
  1438. goto undefined_rate;
  1439. div_factor = mclk_rate / dmic_sample_rate;
  1440. switch (div_factor) {
  1441. case 2:
  1442. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  1443. break;
  1444. case 3:
  1445. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_3;
  1446. break;
  1447. case 4:
  1448. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_4;
  1449. break;
  1450. case 6:
  1451. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_6;
  1452. break;
  1453. case 8:
  1454. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_8;
  1455. break;
  1456. case 16:
  1457. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_16;
  1458. break;
  1459. default:
  1460. /* Any other DIV factor is invalid */
  1461. goto undefined_rate;
  1462. }
  1463. /* Valid dmic DIV factors */
  1464. dev_dbg(va_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1465. __func__, div_factor, mclk_rate);
  1466. return dmic_sample_rate;
  1467. undefined_rate:
  1468. dev_dbg(va_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1469. __func__, dmic_sample_rate, mclk_rate);
  1470. dmic_sample_rate = VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1471. return dmic_sample_rate;
  1472. }
  1473. static int va_macro_init(struct snd_soc_component *component)
  1474. {
  1475. struct snd_soc_dapm_context *dapm =
  1476. snd_soc_component_get_dapm(component);
  1477. int ret, i;
  1478. struct device *va_dev = NULL;
  1479. struct va_macro_priv *va_priv = NULL;
  1480. va_dev = bolero_get_device_ptr(component->dev, VA_MACRO);
  1481. if (!va_dev) {
  1482. dev_err(component->dev,
  1483. "%s: null device for macro!\n", __func__);
  1484. return -EINVAL;
  1485. }
  1486. va_priv = dev_get_drvdata(va_dev);
  1487. if (!va_priv) {
  1488. dev_err(component->dev,
  1489. "%s: priv is null for macro!\n", __func__);
  1490. return -EINVAL;
  1491. }
  1492. if (va_priv->va_without_decimation) {
  1493. ret = snd_soc_dapm_new_controls(dapm, va_macro_wod_dapm_widgets,
  1494. ARRAY_SIZE(va_macro_wod_dapm_widgets));
  1495. if (ret < 0) {
  1496. dev_err(va_dev,
  1497. "%s: Failed to add without dec controls\n",
  1498. __func__);
  1499. return ret;
  1500. }
  1501. va_priv->component = component;
  1502. return 0;
  1503. }
  1504. ret = snd_soc_dapm_new_controls(dapm, va_macro_dapm_widgets,
  1505. ARRAY_SIZE(va_macro_dapm_widgets));
  1506. if (ret < 0) {
  1507. dev_err(va_dev, "%s: Failed to add controls\n", __func__);
  1508. return ret;
  1509. }
  1510. ret = snd_soc_dapm_add_routes(dapm, va_audio_map,
  1511. ARRAY_SIZE(va_audio_map));
  1512. if (ret < 0) {
  1513. dev_err(va_dev, "%s: Failed to add routes\n", __func__);
  1514. return ret;
  1515. }
  1516. ret = snd_soc_dapm_new_widgets(dapm->card);
  1517. if (ret < 0) {
  1518. dev_err(va_dev, "%s: Failed to add widgets\n", __func__);
  1519. return ret;
  1520. }
  1521. ret = snd_soc_add_component_controls(component, va_macro_snd_controls,
  1522. ARRAY_SIZE(va_macro_snd_controls));
  1523. if (ret < 0) {
  1524. dev_err(va_dev, "%s: Failed to add snd_ctls\n", __func__);
  1525. return ret;
  1526. }
  1527. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF1 Capture");
  1528. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF2 Capture");
  1529. snd_soc_dapm_ignore_suspend(dapm, "VA_AIF3 Capture");
  1530. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC0");
  1531. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC1");
  1532. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC2");
  1533. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_ADC3");
  1534. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC0");
  1535. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC1");
  1536. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC2");
  1537. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC3");
  1538. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC4");
  1539. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC5");
  1540. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC6");
  1541. snd_soc_dapm_ignore_suspend(dapm, "VA SWR_MIC7");
  1542. snd_soc_dapm_sync(dapm);
  1543. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  1544. va_priv->va_hpf_work[i].va_priv = va_priv;
  1545. va_priv->va_hpf_work[i].decimator = i;
  1546. INIT_DELAYED_WORK(&va_priv->va_hpf_work[i].dwork,
  1547. va_macro_tx_hpf_corner_freq_callback);
  1548. }
  1549. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  1550. va_priv->va_mute_dwork[i].va_priv = va_priv;
  1551. va_priv->va_mute_dwork[i].decimator = i;
  1552. INIT_DELAYED_WORK(&va_priv->va_mute_dwork[i].dwork,
  1553. va_macro_mute_update_callback);
  1554. }
  1555. va_priv->component = component;
  1556. return 0;
  1557. }
  1558. static int va_macro_deinit(struct snd_soc_component *component)
  1559. {
  1560. struct device *va_dev = NULL;
  1561. struct va_macro_priv *va_priv = NULL;
  1562. if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
  1563. return -EINVAL;
  1564. va_priv->component = NULL;
  1565. return 0;
  1566. }
  1567. static void va_macro_init_ops(struct macro_ops *ops,
  1568. char __iomem *va_io_base,
  1569. bool va_without_decimation)
  1570. {
  1571. memset(ops, 0, sizeof(struct macro_ops));
  1572. if (!va_without_decimation) {
  1573. ops->dai_ptr = va_macro_dai;
  1574. ops->num_dais = ARRAY_SIZE(va_macro_dai);
  1575. } else {
  1576. ops->dai_ptr = NULL;
  1577. ops->num_dais = 0;
  1578. }
  1579. ops->init = va_macro_init;
  1580. ops->exit = va_macro_deinit;
  1581. ops->io_base = va_io_base;
  1582. ops->event_handler = va_macro_event_handler;
  1583. }
  1584. static int va_macro_probe(struct platform_device *pdev)
  1585. {
  1586. struct macro_ops ops;
  1587. struct va_macro_priv *va_priv;
  1588. u32 va_base_addr, sample_rate = 0;
  1589. char __iomem *va_io_base;
  1590. bool va_without_decimation = false;
  1591. const char *micb_supply_str = "va-vdd-micb-supply";
  1592. const char *micb_supply_str1 = "va-vdd-micb";
  1593. const char *micb_voltage_str = "qcom,va-vdd-micb-voltage";
  1594. const char *micb_current_str = "qcom,va-vdd-micb-current";
  1595. int ret = 0;
  1596. const char *dmic_sample_rate = "qcom,va-dmic-sample-rate";
  1597. u32 default_clk_id = 0;
  1598. struct clk *lpass_audio_hw_vote = NULL;
  1599. va_priv = devm_kzalloc(&pdev->dev, sizeof(struct va_macro_priv),
  1600. GFP_KERNEL);
  1601. if (!va_priv)
  1602. return -ENOMEM;
  1603. va_priv->dev = &pdev->dev;
  1604. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1605. &va_base_addr);
  1606. if (ret) {
  1607. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1608. __func__, "reg");
  1609. return ret;
  1610. }
  1611. va_without_decimation = of_property_read_bool(pdev->dev.parent->of_node,
  1612. "qcom,va-without-decimation");
  1613. va_priv->va_without_decimation = va_without_decimation;
  1614. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1615. &sample_rate);
  1616. if (ret) {
  1617. dev_err(&pdev->dev, "%s: could not find %d entry in dt\n",
  1618. __func__, sample_rate);
  1619. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  1620. } else {
  1621. if (va_macro_validate_dmic_sample_rate(
  1622. sample_rate, va_priv) == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1623. return -EINVAL;
  1624. }
  1625. va_io_base = devm_ioremap(&pdev->dev, va_base_addr,
  1626. VA_MACRO_MAX_OFFSET);
  1627. if (!va_io_base) {
  1628. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1629. return -EINVAL;
  1630. }
  1631. va_priv->va_io_base = va_io_base;
  1632. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1633. if (IS_ERR(lpass_audio_hw_vote)) {
  1634. ret = PTR_ERR(lpass_audio_hw_vote);
  1635. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1636. __func__, "lpass_audio_hw_vote", ret);
  1637. lpass_audio_hw_vote = NULL;
  1638. ret = 0;
  1639. }
  1640. va_priv->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1641. if (of_parse_phandle(pdev->dev.of_node, micb_supply_str, 0)) {
  1642. va_priv->micb_supply = devm_regulator_get(&pdev->dev,
  1643. micb_supply_str1);
  1644. if (IS_ERR(va_priv->micb_supply)) {
  1645. ret = PTR_ERR(va_priv->micb_supply);
  1646. dev_err(&pdev->dev,
  1647. "%s:Failed to get micbias supply for VA Mic %d\n",
  1648. __func__, ret);
  1649. return ret;
  1650. }
  1651. ret = of_property_read_u32(pdev->dev.of_node,
  1652. micb_voltage_str,
  1653. &va_priv->micb_voltage);
  1654. if (ret) {
  1655. dev_err(&pdev->dev,
  1656. "%s:Looking up %s property in node %s failed\n",
  1657. __func__, micb_voltage_str,
  1658. pdev->dev.of_node->full_name);
  1659. return ret;
  1660. }
  1661. ret = of_property_read_u32(pdev->dev.of_node,
  1662. micb_current_str,
  1663. &va_priv->micb_current);
  1664. if (ret) {
  1665. dev_err(&pdev->dev,
  1666. "%s:Looking up %s property in node %s failed\n",
  1667. __func__, micb_current_str,
  1668. pdev->dev.of_node->full_name);
  1669. return ret;
  1670. }
  1671. }
  1672. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  1673. &default_clk_id);
  1674. if (ret) {
  1675. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1676. __func__, "qcom,default-clk-id");
  1677. default_clk_id = VA_CORE_CLK;
  1678. }
  1679. va_priv->clk_id = VA_CORE_CLK;
  1680. va_priv->default_clk_id = default_clk_id;
  1681. mutex_init(&va_priv->mclk_lock);
  1682. dev_set_drvdata(&pdev->dev, va_priv);
  1683. va_macro_init_ops(&ops, va_io_base, va_without_decimation);
  1684. ops.clk_id_req = va_priv->default_clk_id;
  1685. ops.default_clk_id = va_priv->default_clk_id;
  1686. ret = bolero_register_macro(&pdev->dev, VA_MACRO, &ops);
  1687. if (ret < 0) {
  1688. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  1689. goto reg_macro_fail;
  1690. }
  1691. pm_runtime_set_autosuspend_delay(&pdev->dev, VA_AUTO_SUSPEND_DELAY);
  1692. pm_runtime_use_autosuspend(&pdev->dev);
  1693. pm_runtime_set_suspended(&pdev->dev);
  1694. pm_runtime_enable(&pdev->dev);
  1695. return ret;
  1696. reg_macro_fail:
  1697. mutex_destroy(&va_priv->mclk_lock);
  1698. return ret;
  1699. }
  1700. static int va_macro_remove(struct platform_device *pdev)
  1701. {
  1702. struct va_macro_priv *va_priv;
  1703. va_priv = dev_get_drvdata(&pdev->dev);
  1704. if (!va_priv)
  1705. return -EINVAL;
  1706. pm_runtime_disable(&pdev->dev);
  1707. pm_runtime_set_suspended(&pdev->dev);
  1708. bolero_unregister_macro(&pdev->dev, VA_MACRO);
  1709. mutex_destroy(&va_priv->mclk_lock);
  1710. return 0;
  1711. }
  1712. static const struct of_device_id va_macro_dt_match[] = {
  1713. {.compatible = "qcom,va-macro"},
  1714. {}
  1715. };
  1716. static const struct dev_pm_ops bolero_dev_pm_ops = {
  1717. SET_RUNTIME_PM_OPS(
  1718. bolero_runtime_suspend,
  1719. bolero_runtime_resume,
  1720. NULL
  1721. )
  1722. };
  1723. static struct platform_driver va_macro_driver = {
  1724. .driver = {
  1725. .name = "va_macro",
  1726. .owner = THIS_MODULE,
  1727. .pm = &bolero_dev_pm_ops,
  1728. .of_match_table = va_macro_dt_match,
  1729. .suppress_bind_attrs = true,
  1730. },
  1731. .probe = va_macro_probe,
  1732. .remove = va_macro_remove,
  1733. };
  1734. module_platform_driver(va_macro_driver);
  1735. MODULE_DESCRIPTION("VA macro driver");
  1736. MODULE_LICENSE("GPL v2");