va-macro.c 58 KB

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