va-macro.c 57 KB

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