va-macro.c 58 KB

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