va-macro.c 50 KB

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