va-macro.c 51 KB

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