va-macro.c 49 KB

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