va-macro.c 47 KB

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