va-macro.c 54 KB

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