va-macro.c 57 KB

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