va-macro.c 48 KB

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