va-macro.c 42 KB

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