va-macro.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  1. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/clk.h>
  15. #include <linux/io.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/regmap.h>
  18. #include <linux/regulator/consumer.h>
  19. #include <sound/soc.h>
  20. #include <sound/soc-dapm.h>
  21. #include <sound/tlv.h>
  22. #include "bolero-cdc.h"
  23. #include "bolero-cdc-registers.h"
  24. #define VA_MACRO_MAX_OFFSET 0x1000
  25. #define VA_MACRO_NUM_DECIMATORS 8
  26. #define VA_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  27. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  28. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  29. #define VA_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  30. SNDRV_PCM_FMTBIT_S24_LE |\
  31. SNDRV_PCM_FMTBIT_S24_3LE)
  32. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  33. #define CF_MIN_3DB_4HZ 0x0
  34. #define CF_MIN_3DB_75HZ 0x1
  35. #define CF_MIN_3DB_150HZ 0x2
  36. #define VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  37. #define VA_MACRO_MCLK_FREQ 9600000
  38. #define VA_MACRO_TX_PATH_OFFSET 0x80
  39. #define VA_MACRO_TX_DMIC_CLK_DIV_MASK 0x0E
  40. #define VA_MACRO_TX_DMIC_CLK_DIV_SHFT 0x01
  41. #define BOLERO_CDC_VA_TX_UNMUTE_DELAY_MS 40
  42. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  43. static int va_tx_unmute_delay = BOLERO_CDC_VA_TX_UNMUTE_DELAY_MS;
  44. module_param(va_tx_unmute_delay, int, 0664);
  45. MODULE_PARM_DESC(va_tx_unmute_delay, "delay to unmute the tx path");
  46. enum {
  47. VA_MACRO_AIF1_CAP = 0,
  48. VA_MACRO_AIF2_CAP,
  49. VA_MACRO_MAX_DAIS,
  50. };
  51. enum {
  52. VA_MACRO_DEC0,
  53. VA_MACRO_DEC1,
  54. VA_MACRO_DEC2,
  55. VA_MACRO_DEC3,
  56. VA_MACRO_DEC4,
  57. VA_MACRO_DEC5,
  58. VA_MACRO_DEC6,
  59. VA_MACRO_DEC7,
  60. VA_MACRO_DEC_MAX,
  61. };
  62. enum {
  63. VA_MACRO_CLK_DIV_2,
  64. VA_MACRO_CLK_DIV_3,
  65. VA_MACRO_CLK_DIV_4,
  66. VA_MACRO_CLK_DIV_6,
  67. VA_MACRO_CLK_DIV_8,
  68. VA_MACRO_CLK_DIV_16,
  69. };
  70. struct va_mute_work {
  71. struct va_macro_priv *va_priv;
  72. u32 decimator;
  73. struct delayed_work dwork;
  74. };
  75. struct hpf_work {
  76. struct va_macro_priv *va_priv;
  77. u8 decimator;
  78. u8 hpf_cut_off_freq;
  79. struct delayed_work dwork;
  80. };
  81. struct va_macro_priv {
  82. struct device *dev;
  83. bool dec_active[VA_MACRO_NUM_DECIMATORS];
  84. bool va_without_decimation;
  85. struct clk *va_core_clk;
  86. struct mutex mclk_lock;
  87. struct snd_soc_codec *codec;
  88. struct hpf_work va_hpf_work[VA_MACRO_NUM_DECIMATORS];
  89. struct va_mute_work va_mute_dwork[VA_MACRO_NUM_DECIMATORS];
  90. unsigned long active_ch_mask[VA_MACRO_MAX_DAIS];
  91. unsigned long active_ch_cnt[VA_MACRO_MAX_DAIS];
  92. s32 dmic_0_1_clk_cnt;
  93. s32 dmic_2_3_clk_cnt;
  94. s32 dmic_4_5_clk_cnt;
  95. s32 dmic_6_7_clk_cnt;
  96. u16 dmic_clk_div;
  97. u16 va_mclk_users;
  98. char __iomem *va_io_base;
  99. struct regulator *micb_supply;
  100. u32 micb_voltage;
  101. u32 micb_current;
  102. int micb_users;
  103. };
  104. static bool va_macro_get_data(struct snd_soc_codec *codec,
  105. struct device **va_dev,
  106. struct va_macro_priv **va_priv,
  107. const char *func_name)
  108. {
  109. *va_dev = bolero_get_device_ptr(codec->dev, VA_MACRO);
  110. if (!(*va_dev)) {
  111. dev_err(codec->dev,
  112. "%s: null device for macro!\n", func_name);
  113. return false;
  114. }
  115. *va_priv = dev_get_drvdata((*va_dev));
  116. if (!(*va_priv) || !(*va_priv)->codec) {
  117. dev_err(codec->dev,
  118. "%s: priv is null for macro!\n", func_name);
  119. return false;
  120. }
  121. return true;
  122. }
  123. static int va_macro_mclk_enable(struct va_macro_priv *va_priv,
  124. bool mclk_enable, bool dapm)
  125. {
  126. struct regmap *regmap = dev_get_regmap(va_priv->dev->parent, NULL);
  127. int ret = 0;
  128. dev_dbg(va_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  129. __func__, mclk_enable, dapm, va_priv->va_mclk_users);
  130. mutex_lock(&va_priv->mclk_lock);
  131. if (mclk_enable) {
  132. va_priv->va_mclk_users++;
  133. if (va_priv->va_mclk_users == 1) {
  134. ret = bolero_request_clock(va_priv->dev,
  135. VA_MACRO, MCLK_MUX0, true);
  136. if (ret < 0) {
  137. dev_err(va_priv->dev,
  138. "%s: va request clock en failed\n",
  139. __func__);
  140. goto exit;
  141. }
  142. regcache_mark_dirty(regmap);
  143. regcache_sync_region(regmap,
  144. VA_START_OFFSET,
  145. VA_MAX_OFFSET);
  146. regmap_update_bits(regmap,
  147. BOLERO_CDC_VA_CLK_RST_CTRL_MCLK_CONTROL,
  148. 0x01, 0x01);
  149. regmap_update_bits(regmap,
  150. BOLERO_CDC_VA_CLK_RST_CTRL_FS_CNT_CONTROL,
  151. 0x01, 0x01);
  152. regmap_update_bits(regmap,
  153. BOLERO_CDC_VA_TOP_CSR_TOP_CFG0,
  154. 0x02, 0x02);
  155. }
  156. } else {
  157. va_priv->va_mclk_users--;
  158. if (va_priv->va_mclk_users == 0) {
  159. regmap_update_bits(regmap,
  160. BOLERO_CDC_VA_TOP_CSR_TOP_CFG0,
  161. 0x02, 0x00);
  162. regmap_update_bits(regmap,
  163. BOLERO_CDC_VA_CLK_RST_CTRL_FS_CNT_CONTROL,
  164. 0x01, 0x00);
  165. regmap_update_bits(regmap,
  166. BOLERO_CDC_VA_CLK_RST_CTRL_MCLK_CONTROL,
  167. 0x01, 0x00);
  168. bolero_request_clock(va_priv->dev,
  169. VA_MACRO, MCLK_MUX0, false);
  170. }
  171. }
  172. exit:
  173. mutex_unlock(&va_priv->mclk_lock);
  174. return ret;
  175. }
  176. static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
  177. struct snd_kcontrol *kcontrol, int event)
  178. {
  179. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  180. int ret = 0;
  181. struct device *va_dev = NULL;
  182. struct va_macro_priv *va_priv = NULL;
  183. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  184. return -EINVAL;
  185. dev_dbg(va_dev, "%s: event = %d\n", __func__, event);
  186. switch (event) {
  187. case SND_SOC_DAPM_PRE_PMU:
  188. ret = va_macro_mclk_enable(va_priv, 1, true);
  189. break;
  190. case SND_SOC_DAPM_POST_PMD:
  191. va_macro_mclk_enable(va_priv, 0, true);
  192. break;
  193. default:
  194. dev_err(va_priv->dev,
  195. "%s: invalid DAPM event %d\n", __func__, event);
  196. ret = -EINVAL;
  197. }
  198. return ret;
  199. }
  200. static int va_macro_mclk_ctrl(struct device *dev, bool enable)
  201. {
  202. struct va_macro_priv *va_priv = dev_get_drvdata(dev);
  203. int ret = 0;
  204. if (enable) {
  205. ret = clk_prepare_enable(va_priv->va_core_clk);
  206. if (ret < 0) {
  207. dev_err(dev, "%s:va mclk enable failed\n", __func__);
  208. goto exit;
  209. }
  210. } else {
  211. clk_disable_unprepare(va_priv->va_core_clk);
  212. }
  213. exit:
  214. return ret;
  215. }
  216. static void va_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  217. {
  218. struct delayed_work *hpf_delayed_work;
  219. struct hpf_work *hpf_work;
  220. struct va_macro_priv *va_priv;
  221. struct snd_soc_codec *codec;
  222. u16 dec_cfg_reg;
  223. u8 hpf_cut_off_freq;
  224. hpf_delayed_work = to_delayed_work(work);
  225. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  226. va_priv = hpf_work->va_priv;
  227. codec = va_priv->codec;
  228. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  229. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  230. VA_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  231. dev_dbg(va_priv->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  232. __func__, hpf_work->decimator, hpf_cut_off_freq);
  233. snd_soc_update_bits(codec, dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  234. hpf_cut_off_freq << 5);
  235. }
  236. static void va_macro_mute_update_callback(struct work_struct *work)
  237. {
  238. struct va_mute_work *va_mute_dwork;
  239. struct snd_soc_codec *codec = NULL;
  240. struct va_macro_priv *va_priv;
  241. struct delayed_work *delayed_work;
  242. u16 tx_vol_ctl_reg, hpf_gate_reg, decimator;
  243. delayed_work = to_delayed_work(work);
  244. va_mute_dwork = container_of(delayed_work, struct va_mute_work, dwork);
  245. va_priv = va_mute_dwork->va_priv;
  246. codec = va_priv->codec;
  247. decimator = va_mute_dwork->decimator;
  248. tx_vol_ctl_reg =
  249. BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  250. VA_MACRO_TX_PATH_OFFSET * decimator;
  251. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  252. VA_MACRO_TX_PATH_OFFSET * decimator;
  253. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x01);
  254. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00);
  255. dev_dbg(va_priv->dev, "%s: decimator %u unmute\n",
  256. __func__, decimator);
  257. }
  258. static int va_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  259. struct snd_ctl_elem_value *ucontrol)
  260. {
  261. struct snd_soc_dapm_widget *widget =
  262. snd_soc_dapm_kcontrol_widget(kcontrol);
  263. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  264. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  265. unsigned int val;
  266. u16 mic_sel_reg;
  267. val = ucontrol->value.enumerated.item[0];
  268. if (val > e->items - 1)
  269. return -EINVAL;
  270. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  271. widget->name, val);
  272. switch (e->reg) {
  273. case BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0:
  274. mic_sel_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0;
  275. break;
  276. case BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0:
  277. mic_sel_reg = BOLERO_CDC_VA_TX1_TX_PATH_CFG0;
  278. break;
  279. case BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0:
  280. mic_sel_reg = BOLERO_CDC_VA_TX2_TX_PATH_CFG0;
  281. break;
  282. case BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0:
  283. mic_sel_reg = BOLERO_CDC_VA_TX3_TX_PATH_CFG0;
  284. break;
  285. case BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0:
  286. mic_sel_reg = BOLERO_CDC_VA_TX4_TX_PATH_CFG0;
  287. break;
  288. case BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0:
  289. mic_sel_reg = BOLERO_CDC_VA_TX5_TX_PATH_CFG0;
  290. break;
  291. case BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0:
  292. mic_sel_reg = BOLERO_CDC_VA_TX6_TX_PATH_CFG0;
  293. break;
  294. case BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0:
  295. mic_sel_reg = BOLERO_CDC_VA_TX7_TX_PATH_CFG0;
  296. break;
  297. default:
  298. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  299. __func__, e->reg);
  300. return -EINVAL;
  301. }
  302. /* DMIC selected */
  303. if (val != 0)
  304. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, 1 << 7);
  305. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  306. }
  307. static int va_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  308. struct snd_ctl_elem_value *ucontrol)
  309. {
  310. struct snd_soc_dapm_widget *widget =
  311. snd_soc_dapm_kcontrol_widget(kcontrol);
  312. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  313. struct soc_multi_mixer_control *mixer =
  314. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  315. u32 dai_id = widget->shift;
  316. u32 dec_id = mixer->shift;
  317. struct device *va_dev = NULL;
  318. struct va_macro_priv *va_priv = NULL;
  319. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  320. return -EINVAL;
  321. if (test_bit(dec_id, &va_priv->active_ch_mask[dai_id]))
  322. ucontrol->value.integer.value[0] = 1;
  323. else
  324. ucontrol->value.integer.value[0] = 0;
  325. return 0;
  326. }
  327. static int va_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  328. struct snd_ctl_elem_value *ucontrol)
  329. {
  330. struct snd_soc_dapm_widget *widget =
  331. snd_soc_dapm_kcontrol_widget(kcontrol);
  332. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  333. struct snd_soc_dapm_update *update = NULL;
  334. struct soc_multi_mixer_control *mixer =
  335. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  336. u32 dai_id = widget->shift;
  337. u32 dec_id = mixer->shift;
  338. u32 enable = ucontrol->value.integer.value[0];
  339. struct device *va_dev = NULL;
  340. struct va_macro_priv *va_priv = NULL;
  341. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  342. return -EINVAL;
  343. if (enable) {
  344. set_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  345. va_priv->active_ch_cnt[dai_id]++;
  346. } else {
  347. clear_bit(dec_id, &va_priv->active_ch_mask[dai_id]);
  348. va_priv->active_ch_cnt[dai_id]--;
  349. }
  350. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  351. return 0;
  352. }
  353. static int va_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  354. struct snd_kcontrol *kcontrol, int event)
  355. {
  356. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  357. u8 dmic_clk_en = 0x01;
  358. u16 dmic_clk_reg;
  359. s32 *dmic_clk_cnt;
  360. unsigned int dmic;
  361. int ret;
  362. char *wname;
  363. struct device *va_dev = NULL;
  364. struct va_macro_priv *va_priv = NULL;
  365. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  366. return -EINVAL;
  367. wname = strpbrk(w->name, "01234567");
  368. if (!wname) {
  369. dev_err(va_dev, "%s: widget not found\n", __func__);
  370. return -EINVAL;
  371. }
  372. ret = kstrtouint(wname, 10, &dmic);
  373. if (ret < 0) {
  374. dev_err(va_dev, "%s: Invalid DMIC line on the codec\n",
  375. __func__);
  376. return -EINVAL;
  377. }
  378. switch (dmic) {
  379. case 0:
  380. case 1:
  381. dmic_clk_cnt = &(va_priv->dmic_0_1_clk_cnt);
  382. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  383. break;
  384. case 2:
  385. case 3:
  386. dmic_clk_cnt = &(va_priv->dmic_2_3_clk_cnt);
  387. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  388. break;
  389. case 4:
  390. case 5:
  391. dmic_clk_cnt = &(va_priv->dmic_4_5_clk_cnt);
  392. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  393. break;
  394. case 6:
  395. case 7:
  396. dmic_clk_cnt = &(va_priv->dmic_6_7_clk_cnt);
  397. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  398. break;
  399. default:
  400. dev_err(va_dev, "%s: Invalid DMIC Selection\n",
  401. __func__);
  402. return -EINVAL;
  403. }
  404. dev_dbg(va_dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  405. __func__, event, dmic, *dmic_clk_cnt);
  406. switch (event) {
  407. case SND_SOC_DAPM_PRE_PMU:
  408. (*dmic_clk_cnt)++;
  409. if (*dmic_clk_cnt == 1) {
  410. snd_soc_update_bits(codec, dmic_clk_reg,
  411. dmic_clk_en, dmic_clk_en);
  412. snd_soc_update_bits(codec, dmic_clk_reg,
  413. VA_MACRO_TX_DMIC_CLK_DIV_MASK,
  414. va_priv->dmic_clk_div <<
  415. VA_MACRO_TX_DMIC_CLK_DIV_SHFT);
  416. }
  417. break;
  418. case SND_SOC_DAPM_POST_PMD:
  419. (*dmic_clk_cnt)--;
  420. if (*dmic_clk_cnt == 0) {
  421. snd_soc_update_bits(codec, dmic_clk_reg,
  422. dmic_clk_en, 0);
  423. }
  424. break;
  425. }
  426. return 0;
  427. }
  428. static int va_macro_enable_dec(struct snd_soc_dapm_widget *w,
  429. struct snd_kcontrol *kcontrol, int event)
  430. {
  431. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  432. unsigned int decimator;
  433. u16 tx_vol_ctl_reg, dec_cfg_reg, hpf_gate_reg;
  434. u16 tx_gain_ctl_reg;
  435. u8 hpf_cut_off_freq;
  436. struct device *va_dev = NULL;
  437. struct va_macro_priv *va_priv = NULL;
  438. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  439. return -EINVAL;
  440. decimator = w->shift;
  441. dev_dbg(va_dev, "%s(): widget = %s decimator = %u\n", __func__,
  442. w->name, decimator);
  443. tx_vol_ctl_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  444. VA_MACRO_TX_PATH_OFFSET * decimator;
  445. hpf_gate_reg = BOLERO_CDC_VA_TX0_TX_PATH_SEC2 +
  446. VA_MACRO_TX_PATH_OFFSET * decimator;
  447. dec_cfg_reg = BOLERO_CDC_VA_TX0_TX_PATH_CFG0 +
  448. VA_MACRO_TX_PATH_OFFSET * decimator;
  449. tx_gain_ctl_reg = BOLERO_CDC_VA_TX0_TX_VOL_CTL +
  450. VA_MACRO_TX_PATH_OFFSET * decimator;
  451. switch (event) {
  452. case SND_SOC_DAPM_PRE_PMU:
  453. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  454. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  455. va_priv->va_hpf_work[decimator].hpf_cut_off_freq =
  456. hpf_cut_off_freq;
  457. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  458. snd_soc_update_bits(codec, dec_cfg_reg,
  459. TX_HPF_CUT_OFF_FREQ_MASK,
  460. CF_MIN_3DB_150HZ << 5);
  461. /* Enable TX PGA Mute */
  462. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  463. break;
  464. case SND_SOC_DAPM_POST_PMU:
  465. /* Enable TX CLK */
  466. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x20);
  467. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x00);
  468. /* schedule work queue to Remove Mute */
  469. schedule_delayed_work(&va_priv->va_mute_dwork[decimator].dwork,
  470. msecs_to_jiffies(va_tx_unmute_delay));
  471. if (va_priv->va_hpf_work[decimator].hpf_cut_off_freq !=
  472. CF_MIN_3DB_150HZ)
  473. schedule_delayed_work(
  474. &va_priv->va_hpf_work[decimator].dwork,
  475. msecs_to_jiffies(300));
  476. /* apply gain after decimator is enabled */
  477. snd_soc_write(codec, tx_gain_ctl_reg,
  478. snd_soc_read(codec, tx_gain_ctl_reg));
  479. break;
  480. case SND_SOC_DAPM_PRE_PMD:
  481. hpf_cut_off_freq =
  482. va_priv->va_hpf_work[decimator].hpf_cut_off_freq;
  483. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  484. if (cancel_delayed_work_sync(
  485. &va_priv->va_hpf_work[decimator].dwork)) {
  486. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  487. snd_soc_update_bits(codec, dec_cfg_reg,
  488. TX_HPF_CUT_OFF_FREQ_MASK,
  489. hpf_cut_off_freq << 5);
  490. }
  491. }
  492. cancel_delayed_work_sync(
  493. &va_priv->va_mute_dwork[decimator].dwork);
  494. break;
  495. case SND_SOC_DAPM_POST_PMD:
  496. /* Disable TX CLK */
  497. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x00);
  498. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  499. break;
  500. }
  501. return 0;
  502. }
  503. static int va_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  504. struct snd_kcontrol *kcontrol, int event)
  505. {
  506. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  507. struct device *va_dev = NULL;
  508. struct va_macro_priv *va_priv = NULL;
  509. int ret = 0;
  510. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  511. return -EINVAL;
  512. if (!va_priv->micb_supply) {
  513. dev_err(va_dev,
  514. "%s:regulator not provided in dtsi\n", __func__);
  515. return -EINVAL;
  516. }
  517. switch (event) {
  518. case SND_SOC_DAPM_PRE_PMU:
  519. if (va_priv->micb_users++ > 0)
  520. return 0;
  521. ret = regulator_set_voltage(va_priv->micb_supply,
  522. va_priv->micb_voltage,
  523. va_priv->micb_voltage);
  524. if (ret) {
  525. dev_err(va_dev, "%s: Setting voltage failed, err = %d\n",
  526. __func__, ret);
  527. return ret;
  528. }
  529. ret = regulator_set_load(va_priv->micb_supply,
  530. va_priv->micb_current);
  531. if (ret) {
  532. dev_err(va_dev, "%s: Setting current failed, err = %d\n",
  533. __func__, ret);
  534. return ret;
  535. }
  536. ret = regulator_enable(va_priv->micb_supply);
  537. if (ret) {
  538. dev_err(va_dev, "%s: regulator enable failed, err = %d\n",
  539. __func__, ret);
  540. return ret;
  541. }
  542. break;
  543. case SND_SOC_DAPM_POST_PMD:
  544. if (--va_priv->micb_users > 0)
  545. return 0;
  546. if (va_priv->micb_users < 0) {
  547. va_priv->micb_users = 0;
  548. dev_dbg(va_dev, "%s: regulator already disabled\n",
  549. __func__);
  550. return 0;
  551. }
  552. ret = regulator_disable(va_priv->micb_supply);
  553. if (ret) {
  554. dev_err(va_dev, "%s: regulator disable failed, err = %d\n",
  555. __func__, ret);
  556. return ret;
  557. }
  558. regulator_set_voltage(va_priv->micb_supply, 0,
  559. va_priv->micb_voltage);
  560. regulator_set_load(va_priv->micb_supply, 0);
  561. break;
  562. }
  563. return 0;
  564. }
  565. static int va_macro_hw_params(struct snd_pcm_substream *substream,
  566. struct snd_pcm_hw_params *params,
  567. struct snd_soc_dai *dai)
  568. {
  569. int tx_fs_rate = -EINVAL;
  570. struct snd_soc_codec *codec = dai->codec;
  571. u32 decimator, sample_rate;
  572. u16 tx_fs_reg = 0;
  573. struct device *va_dev = NULL;
  574. struct va_macro_priv *va_priv = NULL;
  575. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  576. return -EINVAL;
  577. dev_dbg(va_dev,
  578. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  579. dai->name, dai->id, params_rate(params),
  580. params_channels(params));
  581. sample_rate = params_rate(params);
  582. switch (sample_rate) {
  583. case 8000:
  584. tx_fs_rate = 0;
  585. break;
  586. case 16000:
  587. tx_fs_rate = 1;
  588. break;
  589. case 32000:
  590. tx_fs_rate = 3;
  591. break;
  592. case 48000:
  593. tx_fs_rate = 4;
  594. break;
  595. case 96000:
  596. tx_fs_rate = 5;
  597. break;
  598. case 192000:
  599. tx_fs_rate = 6;
  600. break;
  601. case 384000:
  602. tx_fs_rate = 7;
  603. break;
  604. default:
  605. dev_err(va_dev, "%s: Invalid TX sample rate: %d\n",
  606. __func__, params_rate(params));
  607. return -EINVAL;
  608. }
  609. for_each_set_bit(decimator, &va_priv->active_ch_mask[dai->id],
  610. VA_MACRO_DEC_MAX) {
  611. if (decimator >= 0) {
  612. tx_fs_reg = BOLERO_CDC_VA_TX0_TX_PATH_CTL +
  613. VA_MACRO_TX_PATH_OFFSET * decimator;
  614. dev_dbg(va_dev, "%s: set DEC%u rate to %u\n",
  615. __func__, decimator, sample_rate);
  616. snd_soc_update_bits(codec, tx_fs_reg, 0x0F,
  617. tx_fs_rate);
  618. } else {
  619. dev_err(va_dev,
  620. "%s: ERROR: Invalid decimator: %d\n",
  621. __func__, decimator);
  622. return -EINVAL;
  623. }
  624. }
  625. return 0;
  626. }
  627. static int va_macro_get_channel_map(struct snd_soc_dai *dai,
  628. unsigned int *tx_num, unsigned int *tx_slot,
  629. unsigned int *rx_num, unsigned int *rx_slot)
  630. {
  631. struct snd_soc_codec *codec = dai->codec;
  632. struct device *va_dev = NULL;
  633. struct va_macro_priv *va_priv = NULL;
  634. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  635. return -EINVAL;
  636. switch (dai->id) {
  637. case VA_MACRO_AIF1_CAP:
  638. case VA_MACRO_AIF2_CAP:
  639. *tx_slot = va_priv->active_ch_mask[dai->id];
  640. *tx_num = va_priv->active_ch_cnt[dai->id];
  641. break;
  642. default:
  643. dev_err(va_dev, "%s: Invalid AIF\n", __func__);
  644. break;
  645. }
  646. return 0;
  647. }
  648. static struct snd_soc_dai_ops va_macro_dai_ops = {
  649. .hw_params = va_macro_hw_params,
  650. .get_channel_map = va_macro_get_channel_map,
  651. };
  652. static struct snd_soc_dai_driver va_macro_dai[] = {
  653. {
  654. .name = "va_macro_tx1",
  655. .id = VA_MACRO_AIF1_CAP,
  656. .capture = {
  657. .stream_name = "VA_AIF1 Capture",
  658. .rates = VA_MACRO_RATES,
  659. .formats = VA_MACRO_FORMATS,
  660. .rate_max = 192000,
  661. .rate_min = 8000,
  662. .channels_min = 1,
  663. .channels_max = 8,
  664. },
  665. .ops = &va_macro_dai_ops,
  666. },
  667. {
  668. .name = "va_macro_tx2",
  669. .id = VA_MACRO_AIF2_CAP,
  670. .capture = {
  671. .stream_name = "VA_AIF2 Capture",
  672. .rates = VA_MACRO_RATES,
  673. .formats = VA_MACRO_FORMATS,
  674. .rate_max = 192000,
  675. .rate_min = 8000,
  676. .channels_min = 1,
  677. .channels_max = 8,
  678. },
  679. .ops = &va_macro_dai_ops,
  680. },
  681. };
  682. #define STRING(name) #name
  683. #define VA_MACRO_DAPM_ENUM(name, reg, offset, text) \
  684. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  685. static const struct snd_kcontrol_new name##_mux = \
  686. SOC_DAPM_ENUM(STRING(name), name##_enum)
  687. #define VA_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  688. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  689. static const struct snd_kcontrol_new name##_mux = \
  690. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  691. #define VA_MACRO_DAPM_MUX(name, shift, kctl) \
  692. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  693. static const char * const adc_mux_text[] = {
  694. "MSM_DMIC", "SWR_MIC"
  695. };
  696. VA_MACRO_DAPM_ENUM(va_dec0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG1,
  697. 0, adc_mux_text);
  698. VA_MACRO_DAPM_ENUM(va_dec1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG1,
  699. 0, adc_mux_text);
  700. VA_MACRO_DAPM_ENUM(va_dec2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG1,
  701. 0, adc_mux_text);
  702. VA_MACRO_DAPM_ENUM(va_dec3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG1,
  703. 0, adc_mux_text);
  704. VA_MACRO_DAPM_ENUM(va_dec4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG1,
  705. 0, adc_mux_text);
  706. VA_MACRO_DAPM_ENUM(va_dec5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG1,
  707. 0, adc_mux_text);
  708. VA_MACRO_DAPM_ENUM(va_dec6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG1,
  709. 0, adc_mux_text);
  710. VA_MACRO_DAPM_ENUM(va_dec7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG1,
  711. 0, adc_mux_text);
  712. static const char * const dmic_mux_text[] = {
  713. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  714. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  715. };
  716. VA_MACRO_DAPM_ENUM_EXT(va_dmic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  717. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  718. va_macro_put_dec_enum);
  719. VA_MACRO_DAPM_ENUM_EXT(va_dmic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  720. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  721. va_macro_put_dec_enum);
  722. VA_MACRO_DAPM_ENUM_EXT(va_dmic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  723. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  724. va_macro_put_dec_enum);
  725. VA_MACRO_DAPM_ENUM_EXT(va_dmic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  726. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  727. va_macro_put_dec_enum);
  728. VA_MACRO_DAPM_ENUM_EXT(va_dmic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  729. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  730. va_macro_put_dec_enum);
  731. VA_MACRO_DAPM_ENUM_EXT(va_dmic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  732. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  733. va_macro_put_dec_enum);
  734. VA_MACRO_DAPM_ENUM_EXT(va_dmic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  735. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  736. va_macro_put_dec_enum);
  737. VA_MACRO_DAPM_ENUM_EXT(va_dmic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  738. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  739. va_macro_put_dec_enum);
  740. static const char * const smic_mux_text[] = {
  741. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3",
  742. "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
  743. "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  744. };
  745. VA_MACRO_DAPM_ENUM_EXT(va_smic0, BOLERO_CDC_VA_INP_MUX_ADC_MUX0_CFG0,
  746. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  747. va_macro_put_dec_enum);
  748. VA_MACRO_DAPM_ENUM_EXT(va_smic1, BOLERO_CDC_VA_INP_MUX_ADC_MUX1_CFG0,
  749. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  750. va_macro_put_dec_enum);
  751. VA_MACRO_DAPM_ENUM_EXT(va_smic2, BOLERO_CDC_VA_INP_MUX_ADC_MUX2_CFG0,
  752. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  753. va_macro_put_dec_enum);
  754. VA_MACRO_DAPM_ENUM_EXT(va_smic3, BOLERO_CDC_VA_INP_MUX_ADC_MUX3_CFG0,
  755. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  756. va_macro_put_dec_enum);
  757. VA_MACRO_DAPM_ENUM_EXT(va_smic4, BOLERO_CDC_VA_INP_MUX_ADC_MUX4_CFG0,
  758. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  759. va_macro_put_dec_enum);
  760. VA_MACRO_DAPM_ENUM_EXT(va_smic5, BOLERO_CDC_VA_INP_MUX_ADC_MUX5_CFG0,
  761. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  762. va_macro_put_dec_enum);
  763. VA_MACRO_DAPM_ENUM_EXT(va_smic6, BOLERO_CDC_VA_INP_MUX_ADC_MUX6_CFG0,
  764. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  765. va_macro_put_dec_enum);
  766. VA_MACRO_DAPM_ENUM_EXT(va_smic7, BOLERO_CDC_VA_INP_MUX_ADC_MUX7_CFG0,
  767. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  768. va_macro_put_dec_enum);
  769. static const struct snd_kcontrol_new va_aif1_cap_mixer[] = {
  770. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  771. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  772. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  773. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  774. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  775. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  776. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  777. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  778. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  779. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  780. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  781. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  782. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  783. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  784. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  785. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  786. };
  787. static const struct snd_kcontrol_new va_aif2_cap_mixer[] = {
  788. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, VA_MACRO_DEC0, 1, 0,
  789. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  790. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, VA_MACRO_DEC1, 1, 0,
  791. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  792. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, VA_MACRO_DEC2, 1, 0,
  793. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  794. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, VA_MACRO_DEC3, 1, 0,
  795. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  796. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, VA_MACRO_DEC4, 1, 0,
  797. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  798. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, VA_MACRO_DEC5, 1, 0,
  799. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  800. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, VA_MACRO_DEC6, 1, 0,
  801. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  802. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, VA_MACRO_DEC7, 1, 0,
  803. va_macro_tx_mixer_get, va_macro_tx_mixer_put),
  804. };
  805. static const struct snd_soc_dapm_widget va_macro_dapm_widgets[] = {
  806. SND_SOC_DAPM_AIF_OUT("VA_AIF1 CAP", "VA_AIF1 Capture", 0,
  807. SND_SOC_NOPM, VA_MACRO_AIF1_CAP, 0),
  808. SND_SOC_DAPM_AIF_OUT("VA_AIF2 CAP", "VA_AIF2 Capture", 0,
  809. SND_SOC_NOPM, VA_MACRO_AIF2_CAP, 0),
  810. SND_SOC_DAPM_MIXER("VA_AIF1_CAP Mixer", SND_SOC_NOPM,
  811. VA_MACRO_AIF1_CAP, 0,
  812. va_aif1_cap_mixer, ARRAY_SIZE(va_aif1_cap_mixer)),
  813. SND_SOC_DAPM_MIXER("VA_AIF2_CAP Mixer", SND_SOC_NOPM,
  814. VA_MACRO_AIF2_CAP, 0,
  815. va_aif2_cap_mixer, ARRAY_SIZE(va_aif2_cap_mixer)),
  816. VA_MACRO_DAPM_MUX("VA DMIC MUX0", 0, va_dmic0),
  817. VA_MACRO_DAPM_MUX("VA DMIC MUX1", 0, va_dmic1),
  818. VA_MACRO_DAPM_MUX("VA DMIC MUX2", 0, va_dmic2),
  819. VA_MACRO_DAPM_MUX("VA DMIC MUX3", 0, va_dmic3),
  820. VA_MACRO_DAPM_MUX("VA DMIC MUX4", 0, va_dmic4),
  821. VA_MACRO_DAPM_MUX("VA DMIC MUX5", 0, va_dmic5),
  822. VA_MACRO_DAPM_MUX("VA DMIC MUX6", 0, va_dmic6),
  823. VA_MACRO_DAPM_MUX("VA DMIC MUX7", 0, va_dmic7),
  824. VA_MACRO_DAPM_MUX("VA SMIC MUX0", 0, va_smic0),
  825. VA_MACRO_DAPM_MUX("VA SMIC MUX1", 0, va_smic1),
  826. VA_MACRO_DAPM_MUX("VA SMIC MUX2", 0, va_smic2),
  827. VA_MACRO_DAPM_MUX("VA SMIC MUX3", 0, va_smic3),
  828. VA_MACRO_DAPM_MUX("VA SMIC MUX4", 0, va_smic4),
  829. VA_MACRO_DAPM_MUX("VA SMIC MUX5", 0, va_smic5),
  830. VA_MACRO_DAPM_MUX("VA SMIC MUX6", 0, va_smic6),
  831. VA_MACRO_DAPM_MUX("VA SMIC MUX7", 0, va_smic7),
  832. SND_SOC_DAPM_MICBIAS_E("VA MIC BIAS1", SND_SOC_NOPM, 0, 0,
  833. va_macro_enable_micbias,
  834. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  835. SND_SOC_DAPM_ADC_E("VA DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  836. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  837. SND_SOC_DAPM_POST_PMD),
  838. SND_SOC_DAPM_ADC_E("VA DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  839. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  840. SND_SOC_DAPM_POST_PMD),
  841. SND_SOC_DAPM_ADC_E("VA DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  842. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  843. SND_SOC_DAPM_POST_PMD),
  844. SND_SOC_DAPM_ADC_E("VA DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  845. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  846. SND_SOC_DAPM_POST_PMD),
  847. SND_SOC_DAPM_ADC_E("VA DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  848. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  849. SND_SOC_DAPM_POST_PMD),
  850. SND_SOC_DAPM_ADC_E("VA DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  851. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  852. SND_SOC_DAPM_POST_PMD),
  853. SND_SOC_DAPM_ADC_E("VA DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  854. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  855. SND_SOC_DAPM_POST_PMD),
  856. SND_SOC_DAPM_ADC_E("VA DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  857. va_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  858. SND_SOC_DAPM_POST_PMD),
  859. SND_SOC_DAPM_INPUT("VA SWR_ADC0"),
  860. SND_SOC_DAPM_INPUT("VA SWR_ADC1"),
  861. SND_SOC_DAPM_INPUT("VA SWR_ADC2"),
  862. SND_SOC_DAPM_INPUT("VA SWR_ADC3"),
  863. SND_SOC_DAPM_INPUT("VA SWR_MIC0"),
  864. SND_SOC_DAPM_INPUT("VA SWR_MIC1"),
  865. SND_SOC_DAPM_INPUT("VA SWR_MIC2"),
  866. SND_SOC_DAPM_INPUT("VA SWR_MIC3"),
  867. SND_SOC_DAPM_INPUT("VA SWR_MIC4"),
  868. SND_SOC_DAPM_INPUT("VA SWR_MIC5"),
  869. SND_SOC_DAPM_INPUT("VA SWR_MIC6"),
  870. SND_SOC_DAPM_INPUT("VA SWR_MIC7"),
  871. SND_SOC_DAPM_MUX_E("VA DEC0 MUX", SND_SOC_NOPM, VA_MACRO_DEC0, 0,
  872. &va_dec0_mux, va_macro_enable_dec,
  873. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  874. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  875. SND_SOC_DAPM_MUX_E("VA DEC1 MUX", SND_SOC_NOPM, VA_MACRO_DEC1, 0,
  876. &va_dec1_mux, va_macro_enable_dec,
  877. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  878. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  879. SND_SOC_DAPM_MUX_E("VA DEC2 MUX", SND_SOC_NOPM, VA_MACRO_DEC2, 0,
  880. &va_dec2_mux, va_macro_enable_dec,
  881. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  882. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  883. SND_SOC_DAPM_MUX_E("VA DEC3 MUX", SND_SOC_NOPM, VA_MACRO_DEC3, 0,
  884. &va_dec3_mux, va_macro_enable_dec,
  885. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  886. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  887. SND_SOC_DAPM_MUX_E("VA DEC4 MUX", SND_SOC_NOPM, VA_MACRO_DEC4, 0,
  888. &va_dec4_mux, va_macro_enable_dec,
  889. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  890. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  891. SND_SOC_DAPM_MUX_E("VA DEC5 MUX", SND_SOC_NOPM, VA_MACRO_DEC5, 0,
  892. &va_dec5_mux, va_macro_enable_dec,
  893. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  894. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  895. SND_SOC_DAPM_MUX_E("VA DEC6 MUX", SND_SOC_NOPM, VA_MACRO_DEC6, 0,
  896. &va_dec6_mux, va_macro_enable_dec,
  897. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  898. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  899. SND_SOC_DAPM_MUX_E("VA DEC7 MUX", SND_SOC_NOPM, VA_MACRO_DEC7, 0,
  900. &va_dec7_mux, va_macro_enable_dec,
  901. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  902. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  903. SND_SOC_DAPM_SUPPLY_S("VA_MCLK", 0, SND_SOC_NOPM, 0, 0,
  904. va_macro_mclk_event,
  905. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  906. };
  907. static const struct snd_soc_dapm_route va_audio_map[] = {
  908. {"VA_AIF1 CAP", NULL, "VA_MCLK"},
  909. {"VA_AIF2 CAP", NULL, "VA_MCLK"},
  910. {"VA_AIF1 CAP", NULL, "VA_AIF1_CAP Mixer"},
  911. {"VA_AIF2 CAP", NULL, "VA_AIF2_CAP Mixer"},
  912. {"VA_AIF1_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  913. {"VA_AIF1_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  914. {"VA_AIF1_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  915. {"VA_AIF1_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  916. {"VA_AIF1_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  917. {"VA_AIF1_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  918. {"VA_AIF1_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  919. {"VA_AIF1_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  920. {"VA_AIF2_CAP Mixer", "DEC0", "VA DEC0 MUX"},
  921. {"VA_AIF2_CAP Mixer", "DEC1", "VA DEC1 MUX"},
  922. {"VA_AIF2_CAP Mixer", "DEC2", "VA DEC2 MUX"},
  923. {"VA_AIF2_CAP Mixer", "DEC3", "VA DEC3 MUX"},
  924. {"VA_AIF2_CAP Mixer", "DEC4", "VA DEC4 MUX"},
  925. {"VA_AIF2_CAP Mixer", "DEC5", "VA DEC5 MUX"},
  926. {"VA_AIF2_CAP Mixer", "DEC6", "VA DEC6 MUX"},
  927. {"VA_AIF2_CAP Mixer", "DEC7", "VA DEC7 MUX"},
  928. {"VA DEC0 MUX", "MSM_DMIC", "VA DMIC MUX0"},
  929. {"VA DMIC MUX0", "DMIC0", "VA DMIC0"},
  930. {"VA DMIC MUX0", "DMIC1", "VA DMIC1"},
  931. {"VA DMIC MUX0", "DMIC2", "VA DMIC2"},
  932. {"VA DMIC MUX0", "DMIC3", "VA DMIC3"},
  933. {"VA DMIC MUX0", "DMIC4", "VA DMIC4"},
  934. {"VA DMIC MUX0", "DMIC5", "VA DMIC5"},
  935. {"VA DMIC MUX0", "DMIC6", "VA DMIC6"},
  936. {"VA DMIC MUX0", "DMIC7", "VA DMIC7"},
  937. {"VA DEC0 MUX", "SWR_MIC", "VA SMIC MUX0"},
  938. {"VA SMIC MUX0", "ADC0", "VA SWR_ADC0"},
  939. {"VA SMIC MUX0", "ADC1", "VA SWR_ADC1"},
  940. {"VA SMIC MUX0", "ADC2", "VA SWR_ADC2"},
  941. {"VA SMIC MUX0", "ADC3", "VA SWR_ADC3"},
  942. {"VA SMIC MUX0", "SWR_DMIC0", "VA SWR_MIC0"},
  943. {"VA SMIC MUX0", "SWR_DMIC1", "VA SWR_MIC1"},
  944. {"VA SMIC MUX0", "SWR_DMIC2", "VA SWR_MIC2"},
  945. {"VA SMIC MUX0", "SWR_DMIC3", "VA SWR_MIC3"},
  946. {"VA SMIC MUX0", "SWR_DMIC4", "VA SWR_MIC4"},
  947. {"VA SMIC MUX0", "SWR_DMIC5", "VA SWR_MIC5"},
  948. {"VA SMIC MUX0", "SWR_DMIC6", "VA SWR_MIC6"},
  949. {"VA SMIC MUX0", "SWR_DMIC7", "VA SWR_MIC7"},
  950. {"VA DEC1 MUX", "MSM_DMIC", "VA DMIC MUX1"},
  951. {"VA DMIC MUX1", "DMIC0", "VA DMIC0"},
  952. {"VA DMIC MUX1", "DMIC1", "VA DMIC1"},
  953. {"VA DMIC MUX1", "DMIC2", "VA DMIC2"},
  954. {"VA DMIC MUX1", "DMIC3", "VA DMIC3"},
  955. {"VA DMIC MUX1", "DMIC4", "VA DMIC4"},
  956. {"VA DMIC MUX1", "DMIC5", "VA DMIC5"},
  957. {"VA DMIC MUX1", "DMIC6", "VA DMIC6"},
  958. {"VA DMIC MUX1", "DMIC7", "VA DMIC7"},
  959. {"VA DEC1 MUX", "SWR_MIC", "VA SMIC MUX1"},
  960. {"VA SMIC MUX1", "ADC0", "VA SWR_ADC0"},
  961. {"VA SMIC MUX1", "ADC1", "VA SWR_ADC1"},
  962. {"VA SMIC MUX1", "ADC2", "VA SWR_ADC2"},
  963. {"VA SMIC MUX1", "ADC3", "VA SWR_ADC3"},
  964. {"VA SMIC MUX1", "SWR_DMIC0", "VA SWR_MIC0"},
  965. {"VA SMIC MUX1", "SWR_DMIC1", "VA SWR_MIC1"},
  966. {"VA SMIC MUX1", "SWR_DMIC2", "VA SWR_MIC2"},
  967. {"VA SMIC MUX1", "SWR_DMIC3", "VA SWR_MIC3"},
  968. {"VA SMIC MUX1", "SWR_DMIC4", "VA SWR_MIC4"},
  969. {"VA SMIC MUX1", "SWR_DMIC5", "VA SWR_MIC5"},
  970. {"VA SMIC MUX1", "SWR_DMIC6", "VA SWR_MIC6"},
  971. {"VA SMIC MUX1", "SWR_DMIC7", "VA SWR_MIC7"},
  972. {"VA DEC2 MUX", "MSM_DMIC", "VA DMIC MUX2"},
  973. {"VA DMIC MUX2", "DMIC0", "VA DMIC0"},
  974. {"VA DMIC MUX2", "DMIC1", "VA DMIC1"},
  975. {"VA DMIC MUX2", "DMIC2", "VA DMIC2"},
  976. {"VA DMIC MUX2", "DMIC3", "VA DMIC3"},
  977. {"VA DMIC MUX2", "DMIC4", "VA DMIC4"},
  978. {"VA DMIC MUX2", "DMIC5", "VA DMIC5"},
  979. {"VA DMIC MUX2", "DMIC6", "VA DMIC6"},
  980. {"VA DMIC MUX2", "DMIC7", "VA DMIC7"},
  981. {"VA DEC2 MUX", "SWR_MIC", "VA SMIC MUX2"},
  982. {"VA SMIC MUX2", "ADC0", "VA SWR_ADC0"},
  983. {"VA SMIC MUX2", "ADC1", "VA SWR_ADC1"},
  984. {"VA SMIC MUX2", "ADC2", "VA SWR_ADC2"},
  985. {"VA SMIC MUX2", "ADC3", "VA SWR_ADC3"},
  986. {"VA SMIC MUX2", "SWR_DMIC0", "VA SWR_MIC0"},
  987. {"VA SMIC MUX2", "SWR_DMIC1", "VA SWR_MIC1"},
  988. {"VA SMIC MUX2", "SWR_DMIC2", "VA SWR_MIC2"},
  989. {"VA SMIC MUX2", "SWR_DMIC3", "VA SWR_MIC3"},
  990. {"VA SMIC MUX2", "SWR_DMIC4", "VA SWR_MIC4"},
  991. {"VA SMIC MUX2", "SWR_DMIC5", "VA SWR_MIC5"},
  992. {"VA SMIC MUX2", "SWR_DMIC6", "VA SWR_MIC6"},
  993. {"VA SMIC MUX2", "SWR_DMIC7", "VA SWR_MIC7"},
  994. {"VA DEC3 MUX", "MSM_DMIC", "VA DMIC MUX3"},
  995. {"VA DMIC MUX3", "DMIC0", "VA DMIC0"},
  996. {"VA DMIC MUX3", "DMIC1", "VA DMIC1"},
  997. {"VA DMIC MUX3", "DMIC2", "VA DMIC2"},
  998. {"VA DMIC MUX3", "DMIC3", "VA DMIC3"},
  999. {"VA DMIC MUX3", "DMIC4", "VA DMIC4"},
  1000. {"VA DMIC MUX3", "DMIC5", "VA DMIC5"},
  1001. {"VA DMIC MUX3", "DMIC6", "VA DMIC6"},
  1002. {"VA DMIC MUX3", "DMIC7", "VA DMIC7"},
  1003. {"VA DEC3 MUX", "SWR_MIC", "VA SMIC MUX3"},
  1004. {"VA SMIC MUX3", "ADC0", "VA SWR_ADC0"},
  1005. {"VA SMIC MUX3", "ADC1", "VA SWR_ADC1"},
  1006. {"VA SMIC MUX3", "ADC2", "VA SWR_ADC2"},
  1007. {"VA SMIC MUX3", "ADC3", "VA SWR_ADC3"},
  1008. {"VA SMIC MUX3", "SWR_DMIC0", "VA SWR_MIC0"},
  1009. {"VA SMIC MUX3", "SWR_DMIC1", "VA SWR_MIC1"},
  1010. {"VA SMIC MUX3", "SWR_DMIC2", "VA SWR_MIC2"},
  1011. {"VA SMIC MUX3", "SWR_DMIC3", "VA SWR_MIC3"},
  1012. {"VA SMIC MUX3", "SWR_DMIC4", "VA SWR_MIC4"},
  1013. {"VA SMIC MUX3", "SWR_DMIC5", "VA SWR_MIC5"},
  1014. {"VA SMIC MUX3", "SWR_DMIC6", "VA SWR_MIC6"},
  1015. {"VA SMIC MUX3", "SWR_DMIC7", "VA SWR_MIC7"},
  1016. {"VA DEC4 MUX", "MSM_DMIC", "VA DMIC MUX4"},
  1017. {"VA DMIC MUX4", "DMIC0", "VA DMIC0"},
  1018. {"VA DMIC MUX4", "DMIC1", "VA DMIC1"},
  1019. {"VA DMIC MUX4", "DMIC2", "VA DMIC2"},
  1020. {"VA DMIC MUX4", "DMIC3", "VA DMIC3"},
  1021. {"VA DMIC MUX4", "DMIC4", "VA DMIC4"},
  1022. {"VA DMIC MUX4", "DMIC5", "VA DMIC5"},
  1023. {"VA DMIC MUX4", "DMIC6", "VA DMIC6"},
  1024. {"VA DMIC MUX4", "DMIC7", "VA DMIC7"},
  1025. {"VA DEC4 MUX", "SWR_MIC", "VA SMIC MUX4"},
  1026. {"VA SMIC MUX4", "ADC0", "VA SWR_ADC0"},
  1027. {"VA SMIC MUX4", "ADC1", "VA SWR_ADC1"},
  1028. {"VA SMIC MUX4", "ADC2", "VA SWR_ADC2"},
  1029. {"VA SMIC MUX4", "ADC3", "VA SWR_ADC3"},
  1030. {"VA SMIC MUX4", "SWR_DMIC0", "VA SWR_MIC0"},
  1031. {"VA SMIC MUX4", "SWR_DMIC1", "VA SWR_MIC1"},
  1032. {"VA SMIC MUX4", "SWR_DMIC2", "VA SWR_MIC2"},
  1033. {"VA SMIC MUX4", "SWR_DMIC3", "VA SWR_MIC3"},
  1034. {"VA SMIC MUX4", "SWR_DMIC4", "VA SWR_MIC4"},
  1035. {"VA SMIC MUX4", "SWR_DMIC5", "VA SWR_MIC5"},
  1036. {"VA SMIC MUX4", "SWR_DMIC6", "VA SWR_MIC6"},
  1037. {"VA SMIC MUX4", "SWR_DMIC7", "VA SWR_MIC7"},
  1038. {"VA DEC5 MUX", "MSM_DMIC", "VA DMIC MUX5"},
  1039. {"VA DMIC MUX5", "DMIC0", "VA DMIC0"},
  1040. {"VA DMIC MUX5", "DMIC1", "VA DMIC1"},
  1041. {"VA DMIC MUX5", "DMIC2", "VA DMIC2"},
  1042. {"VA DMIC MUX5", "DMIC3", "VA DMIC3"},
  1043. {"VA DMIC MUX5", "DMIC4", "VA DMIC4"},
  1044. {"VA DMIC MUX5", "DMIC5", "VA DMIC5"},
  1045. {"VA DMIC MUX5", "DMIC6", "VA DMIC6"},
  1046. {"VA DMIC MUX5", "DMIC7", "VA DMIC7"},
  1047. {"VA DEC5 MUX", "SWR_MIC", "VA SMIC MUX5"},
  1048. {"VA SMIC MUX5", "ADC0", "VA SWR_ADC0"},
  1049. {"VA SMIC MUX5", "ADC1", "VA SWR_ADC1"},
  1050. {"VA SMIC MUX5", "ADC2", "VA SWR_ADC2"},
  1051. {"VA SMIC MUX5", "ADC3", "VA SWR_ADC3"},
  1052. {"VA SMIC MUX5", "SWR_DMIC0", "VA SWR_MIC0"},
  1053. {"VA SMIC MUX5", "SWR_DMIC1", "VA SWR_MIC1"},
  1054. {"VA SMIC MUX5", "SWR_DMIC2", "VA SWR_MIC2"},
  1055. {"VA SMIC MUX5", "SWR_DMIC3", "VA SWR_MIC3"},
  1056. {"VA SMIC MUX5", "SWR_DMIC4", "VA SWR_MIC4"},
  1057. {"VA SMIC MUX5", "SWR_DMIC5", "VA SWR_MIC5"},
  1058. {"VA SMIC MUX5", "SWR_DMIC6", "VA SWR_MIC6"},
  1059. {"VA SMIC MUX5", "SWR_DMIC7", "VA SWR_MIC7"},
  1060. {"VA DEC6 MUX", "MSM_DMIC", "VA DMIC MUX6"},
  1061. {"VA DMIC MUX6", "DMIC0", "VA DMIC0"},
  1062. {"VA DMIC MUX6", "DMIC1", "VA DMIC1"},
  1063. {"VA DMIC MUX6", "DMIC2", "VA DMIC2"},
  1064. {"VA DMIC MUX6", "DMIC3", "VA DMIC3"},
  1065. {"VA DMIC MUX6", "DMIC4", "VA DMIC4"},
  1066. {"VA DMIC MUX6", "DMIC5", "VA DMIC5"},
  1067. {"VA DMIC MUX6", "DMIC6", "VA DMIC6"},
  1068. {"VA DMIC MUX6", "DMIC7", "VA DMIC7"},
  1069. {"VA DEC6 MUX", "SWR_MIC", "VA SMIC MUX6"},
  1070. {"VA SMIC MUX6", "ADC0", "VA SWR_ADC0"},
  1071. {"VA SMIC MUX6", "ADC1", "VA SWR_ADC1"},
  1072. {"VA SMIC MUX6", "ADC2", "VA SWR_ADC2"},
  1073. {"VA SMIC MUX6", "ADC3", "VA SWR_ADC3"},
  1074. {"VA SMIC MUX6", "SWR_DMIC0", "VA SWR_MIC0"},
  1075. {"VA SMIC MUX6", "SWR_DMIC1", "VA SWR_MIC1"},
  1076. {"VA SMIC MUX6", "SWR_DMIC2", "VA SWR_MIC2"},
  1077. {"VA SMIC MUX6", "SWR_DMIC3", "VA SWR_MIC3"},
  1078. {"VA SMIC MUX6", "SWR_DMIC4", "VA SWR_MIC4"},
  1079. {"VA SMIC MUX6", "SWR_DMIC5", "VA SWR_MIC5"},
  1080. {"VA SMIC MUX6", "SWR_DMIC6", "VA SWR_MIC6"},
  1081. {"VA SMIC MUX6", "SWR_DMIC7", "VA SWR_MIC7"},
  1082. {"VA DEC7 MUX", "MSM_DMIC", "VA DMIC MUX7"},
  1083. {"VA DMIC MUX7", "DMIC0", "VA DMIC0"},
  1084. {"VA DMIC MUX7", "DMIC1", "VA DMIC1"},
  1085. {"VA DMIC MUX7", "DMIC2", "VA DMIC2"},
  1086. {"VA DMIC MUX7", "DMIC3", "VA DMIC3"},
  1087. {"VA DMIC MUX7", "DMIC4", "VA DMIC4"},
  1088. {"VA DMIC MUX7", "DMIC5", "VA DMIC5"},
  1089. {"VA DMIC MUX7", "DMIC6", "VA DMIC6"},
  1090. {"VA DMIC MUX7", "DMIC7", "VA DMIC7"},
  1091. {"VA DEC7 MUX", "SWR_MIC", "VA SMIC MUX7"},
  1092. {"VA SMIC MUX7", "ADC0", "VA SWR_ADC0"},
  1093. {"VA SMIC MUX7", "ADC1", "VA SWR_ADC1"},
  1094. {"VA SMIC MUX7", "ADC2", "VA SWR_ADC2"},
  1095. {"VA SMIC MUX7", "ADC3", "VA SWR_ADC3"},
  1096. {"VA SMIC MUX7", "SWR_DMIC0", "VA SWR_MIC0"},
  1097. {"VA SMIC MUX7", "SWR_DMIC1", "VA SWR_MIC1"},
  1098. {"VA SMIC MUX7", "SWR_DMIC2", "VA SWR_MIC2"},
  1099. {"VA SMIC MUX7", "SWR_DMIC3", "VA SWR_MIC3"},
  1100. {"VA SMIC MUX7", "SWR_DMIC4", "VA SWR_MIC4"},
  1101. {"VA SMIC MUX7", "SWR_DMIC5", "VA SWR_MIC5"},
  1102. {"VA SMIC MUX7", "SWR_DMIC6", "VA SWR_MIC6"},
  1103. {"VA SMIC MUX7", "SWR_DMIC7", "VA SWR_MIC7"},
  1104. };
  1105. static const struct snd_kcontrol_new va_macro_snd_controls[] = {
  1106. SOC_SINGLE_SX_TLV("VA_DEC0 Volume",
  1107. BOLERO_CDC_VA_TX0_TX_VOL_CTL,
  1108. 0, -84, 40, digital_gain),
  1109. SOC_SINGLE_SX_TLV("VA_DEC1 Volume",
  1110. BOLERO_CDC_VA_TX1_TX_VOL_CTL,
  1111. 0, -84, 40, digital_gain),
  1112. SOC_SINGLE_SX_TLV("VA_DEC2 Volume",
  1113. BOLERO_CDC_VA_TX2_TX_VOL_CTL,
  1114. 0, -84, 40, digital_gain),
  1115. SOC_SINGLE_SX_TLV("VA_DEC3 Volume",
  1116. BOLERO_CDC_VA_TX3_TX_VOL_CTL,
  1117. 0, -84, 40, digital_gain),
  1118. SOC_SINGLE_SX_TLV("VA_DEC4 Volume",
  1119. BOLERO_CDC_VA_TX4_TX_VOL_CTL,
  1120. 0, -84, 40, digital_gain),
  1121. SOC_SINGLE_SX_TLV("VA_DEC5 Volume",
  1122. BOLERO_CDC_VA_TX5_TX_VOL_CTL,
  1123. 0, -84, 40, digital_gain),
  1124. SOC_SINGLE_SX_TLV("VA_DEC6 Volume",
  1125. BOLERO_CDC_VA_TX6_TX_VOL_CTL,
  1126. 0, -84, 40, digital_gain),
  1127. SOC_SINGLE_SX_TLV("VA_DEC7 Volume",
  1128. BOLERO_CDC_VA_TX7_TX_VOL_CTL,
  1129. 0, -84, 40, digital_gain),
  1130. };
  1131. static int va_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1132. struct va_macro_priv *va_priv)
  1133. {
  1134. u32 div_factor;
  1135. u32 mclk_rate = VA_MACRO_MCLK_FREQ;
  1136. if (dmic_sample_rate == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1137. mclk_rate % dmic_sample_rate != 0)
  1138. goto undefined_rate;
  1139. div_factor = mclk_rate / dmic_sample_rate;
  1140. switch (div_factor) {
  1141. case 2:
  1142. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  1143. break;
  1144. case 3:
  1145. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_3;
  1146. break;
  1147. case 4:
  1148. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_4;
  1149. break;
  1150. case 6:
  1151. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_6;
  1152. break;
  1153. case 8:
  1154. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_8;
  1155. break;
  1156. case 16:
  1157. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_16;
  1158. break;
  1159. default:
  1160. /* Any other DIV factor is invalid */
  1161. goto undefined_rate;
  1162. }
  1163. /* Valid dmic DIV factors */
  1164. dev_dbg(va_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1165. __func__, div_factor, mclk_rate);
  1166. return dmic_sample_rate;
  1167. undefined_rate:
  1168. dev_dbg(va_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1169. __func__, dmic_sample_rate, mclk_rate);
  1170. dmic_sample_rate = VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1171. return dmic_sample_rate;
  1172. }
  1173. static int va_macro_init(struct snd_soc_codec *codec)
  1174. {
  1175. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1176. int ret, i;
  1177. struct device *va_dev = NULL;
  1178. struct va_macro_priv *va_priv = NULL;
  1179. va_dev = bolero_get_device_ptr(codec->dev, VA_MACRO);
  1180. if (!va_dev) {
  1181. dev_err(codec->dev,
  1182. "%s: null device for macro!\n", __func__);
  1183. return -EINVAL;
  1184. }
  1185. va_priv = dev_get_drvdata(va_dev);
  1186. if (!va_priv) {
  1187. dev_err(codec->dev,
  1188. "%s: priv is null for macro!\n", __func__);
  1189. return -EINVAL;
  1190. }
  1191. ret = snd_soc_dapm_new_controls(dapm, va_macro_dapm_widgets,
  1192. ARRAY_SIZE(va_macro_dapm_widgets));
  1193. if (ret < 0) {
  1194. dev_err(va_dev, "%s: Failed to add controls\n", __func__);
  1195. return ret;
  1196. }
  1197. ret = snd_soc_dapm_add_routes(dapm, va_audio_map,
  1198. ARRAY_SIZE(va_audio_map));
  1199. if (ret < 0) {
  1200. dev_err(va_dev, "%s: Failed to add routes\n", __func__);
  1201. return ret;
  1202. }
  1203. ret = snd_soc_dapm_new_widgets(dapm->card);
  1204. if (ret < 0) {
  1205. dev_err(va_dev, "%s: Failed to add widgets\n", __func__);
  1206. return ret;
  1207. }
  1208. ret = snd_soc_add_codec_controls(codec, va_macro_snd_controls,
  1209. ARRAY_SIZE(va_macro_snd_controls));
  1210. if (ret < 0) {
  1211. dev_err(va_dev, "%s: Failed to add snd_ctls\n", __func__);
  1212. return ret;
  1213. }
  1214. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  1215. va_priv->va_hpf_work[i].va_priv = va_priv;
  1216. va_priv->va_hpf_work[i].decimator = i;
  1217. INIT_DELAYED_WORK(&va_priv->va_hpf_work[i].dwork,
  1218. va_macro_tx_hpf_corner_freq_callback);
  1219. }
  1220. for (i = 0; i < VA_MACRO_NUM_DECIMATORS; i++) {
  1221. va_priv->va_mute_dwork[i].va_priv = va_priv;
  1222. va_priv->va_mute_dwork[i].decimator = i;
  1223. INIT_DELAYED_WORK(&va_priv->va_mute_dwork[i].dwork,
  1224. va_macro_mute_update_callback);
  1225. }
  1226. va_priv->codec = codec;
  1227. return 0;
  1228. }
  1229. static int va_macro_deinit(struct snd_soc_codec *codec)
  1230. {
  1231. struct device *va_dev = NULL;
  1232. struct va_macro_priv *va_priv = NULL;
  1233. if (!va_macro_get_data(codec, &va_dev, &va_priv, __func__))
  1234. return -EINVAL;
  1235. va_priv->codec = NULL;
  1236. return 0;
  1237. }
  1238. static void va_macro_init_ops(struct macro_ops *ops,
  1239. char __iomem *va_io_base,
  1240. bool va_without_decimation)
  1241. {
  1242. memset(ops, 0, sizeof(struct macro_ops));
  1243. if (!va_without_decimation) {
  1244. ops->init = va_macro_init;
  1245. ops->exit = va_macro_deinit;
  1246. ops->dai_ptr = va_macro_dai;
  1247. ops->num_dais = ARRAY_SIZE(va_macro_dai);
  1248. } else {
  1249. ops->init = NULL;
  1250. ops->exit = NULL;
  1251. ops->dai_ptr = NULL;
  1252. ops->num_dais = 0;
  1253. }
  1254. ops->io_base = va_io_base;
  1255. ops->mclk_fn = va_macro_mclk_ctrl;
  1256. }
  1257. static int va_macro_probe(struct platform_device *pdev)
  1258. {
  1259. struct macro_ops ops;
  1260. struct va_macro_priv *va_priv;
  1261. u32 va_base_addr, sample_rate = 0;
  1262. char __iomem *va_io_base;
  1263. struct clk *va_core_clk;
  1264. bool va_without_decimation = false;
  1265. const char *micb_supply_str = "va-vdd-micb-supply";
  1266. const char *micb_voltage_str = "qcom,va-vdd-micb-voltage";
  1267. const char *micb_current_str = "qcom,va-vdd-micb-current";
  1268. int ret = 0;
  1269. const char *dmic_sample_rate = "qcom,va-dmic-sample-rate";
  1270. va_priv = devm_kzalloc(&pdev->dev, sizeof(struct va_macro_priv),
  1271. GFP_KERNEL);
  1272. if (!va_priv)
  1273. return -ENOMEM;
  1274. va_priv->dev = &pdev->dev;
  1275. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1276. &va_base_addr);
  1277. if (ret) {
  1278. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1279. __func__, "reg");
  1280. return ret;
  1281. }
  1282. va_without_decimation = of_property_read_bool(pdev->dev.parent->of_node,
  1283. "qcom,va-without-decimation");
  1284. va_priv->va_without_decimation = va_without_decimation;
  1285. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1286. &sample_rate);
  1287. if (ret) {
  1288. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1289. __func__, sample_rate);
  1290. va_priv->dmic_clk_div = VA_MACRO_CLK_DIV_2;
  1291. } else {
  1292. if (va_macro_validate_dmic_sample_rate(
  1293. sample_rate, va_priv) == VA_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1294. return -EINVAL;
  1295. }
  1296. va_io_base = devm_ioremap(&pdev->dev, va_base_addr,
  1297. VA_MAX_OFFSET);
  1298. if (!va_io_base) {
  1299. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1300. return -EINVAL;
  1301. }
  1302. va_priv->va_io_base = va_io_base;
  1303. /* Register MCLK for va macro */
  1304. va_core_clk = devm_clk_get(&pdev->dev, "va_core_clk");
  1305. if (IS_ERR(va_core_clk)) {
  1306. dev_err(&pdev->dev, "%s: clk get %s failed\n",
  1307. __func__, "va_core_clk");
  1308. return -EINVAL;
  1309. }
  1310. va_priv->va_core_clk = va_core_clk;
  1311. if (of_parse_phandle(pdev->dev.of_node, micb_supply_str, 0)) {
  1312. va_priv->micb_supply = devm_regulator_get(&pdev->dev,
  1313. micb_supply_str);
  1314. if (IS_ERR(va_priv->micb_supply)) {
  1315. ret = PTR_ERR(va_priv->micb_supply);
  1316. dev_err(&pdev->dev,
  1317. "%s:Failed to get micbias supply for VA Mic\n",
  1318. __func__, ret);
  1319. return ret;
  1320. }
  1321. ret = of_property_read_u32(pdev->dev.of_node,
  1322. micb_voltage_str,
  1323. &va_priv->micb_voltage);
  1324. if (ret) {
  1325. dev_err(&pdev->dev,
  1326. "%s:Looking up %s property in node %s failed\n",
  1327. __func__, micb_voltage_str,
  1328. pdev->dev.of_node->full_name);
  1329. return ret;
  1330. }
  1331. ret = of_property_read_u32(pdev->dev.of_node,
  1332. micb_current_str,
  1333. &va_priv->micb_current);
  1334. if (ret) {
  1335. dev_err(&pdev->dev,
  1336. "%s:Looking up %s property in node %s failed\n",
  1337. __func__, micb_current_str,
  1338. pdev->dev.of_node->full_name);
  1339. return ret;
  1340. }
  1341. }
  1342. mutex_init(&va_priv->mclk_lock);
  1343. dev_set_drvdata(&pdev->dev, va_priv);
  1344. va_macro_init_ops(&ops, va_io_base, va_without_decimation);
  1345. ret = bolero_register_macro(&pdev->dev, VA_MACRO, &ops);
  1346. if (ret < 0) {
  1347. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  1348. goto reg_macro_fail;
  1349. }
  1350. return ret;
  1351. reg_macro_fail:
  1352. mutex_destroy(&va_priv->mclk_lock);
  1353. return ret;
  1354. }
  1355. static int va_macro_remove(struct platform_device *pdev)
  1356. {
  1357. struct va_macro_priv *va_priv;
  1358. va_priv = dev_get_drvdata(&pdev->dev);
  1359. if (!va_priv)
  1360. return -EINVAL;
  1361. bolero_unregister_macro(&pdev->dev, VA_MACRO);
  1362. mutex_destroy(&va_priv->mclk_lock);
  1363. return 0;
  1364. }
  1365. static const struct of_device_id va_macro_dt_match[] = {
  1366. {.compatible = "qcom,va-macro"},
  1367. {}
  1368. };
  1369. static struct platform_driver va_macro_driver = {
  1370. .driver = {
  1371. .name = "va_macro",
  1372. .owner = THIS_MODULE,
  1373. .of_match_table = va_macro_dt_match,
  1374. },
  1375. .probe = va_macro_probe,
  1376. .remove = va_macro_remove,
  1377. };
  1378. module_platform_driver(va_macro_driver);
  1379. MODULE_DESCRIPTION("VA macro driver");
  1380. MODULE_LICENSE("GPL v2");