va-macro.c 58 KB

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