tx-macro.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  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/pm_runtime.h>
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include <sound/tlv.h>
  14. #include <soc/swr-common.h>
  15. #include <soc/swr-wcd.h>
  16. #include <asoc/msm-cdc-pinctrl.h>
  17. #include "bolero-cdc.h"
  18. #include "bolero-cdc-registers.h"
  19. #include "bolero-clk-rsc.h"
  20. #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
  21. #define TX_MACRO_MAX_OFFSET 0x1000
  22. #define NUM_DECIMATORS 8
  23. #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  24. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  25. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  26. #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  27. SNDRV_PCM_FMTBIT_S24_LE |\
  28. SNDRV_PCM_FMTBIT_S24_3LE)
  29. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  30. #define CF_MIN_3DB_4HZ 0x0
  31. #define CF_MIN_3DB_75HZ 0x1
  32. #define CF_MIN_3DB_150HZ 0x2
  33. #define TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  34. #define TX_MACRO_MCLK_FREQ 9600000
  35. #define TX_MACRO_TX_PATH_OFFSET 0x80
  36. #define TX_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
  37. #define TX_MACRO_ADC_MUX_CFG_OFFSET 0x2
  38. #define TX_MACRO_TX_UNMUTE_DELAY_MS 40
  39. static int tx_unmute_delay = TX_MACRO_TX_UNMUTE_DELAY_MS;
  40. module_param(tx_unmute_delay, int, 0664);
  41. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  42. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  43. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  44. struct snd_pcm_hw_params *params,
  45. struct snd_soc_dai *dai);
  46. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  47. unsigned int *tx_num, unsigned int *tx_slot,
  48. unsigned int *rx_num, unsigned int *rx_slot);
  49. #define TX_MACRO_SWR_STRING_LEN 80
  50. #define TX_MACRO_CHILD_DEVICES_MAX 3
  51. /* Hold instance to soundwire platform device */
  52. struct tx_macro_swr_ctrl_data {
  53. struct platform_device *tx_swr_pdev;
  54. };
  55. struct tx_macro_swr_ctrl_platform_data {
  56. void *handle; /* holds codec private data */
  57. int (*read)(void *handle, int reg);
  58. int (*write)(void *handle, int reg, int val);
  59. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  60. int (*clk)(void *handle, bool enable);
  61. int (*handle_irq)(void *handle,
  62. irqreturn_t (*swrm_irq_handler)(int irq,
  63. void *data),
  64. void *swrm_handle,
  65. int action);
  66. };
  67. enum {
  68. TX_MACRO_AIF_INVALID = 0,
  69. TX_MACRO_AIF1_CAP,
  70. TX_MACRO_AIF2_CAP,
  71. TX_MACRO_MAX_DAIS
  72. };
  73. enum {
  74. TX_MACRO_DEC0,
  75. TX_MACRO_DEC1,
  76. TX_MACRO_DEC2,
  77. TX_MACRO_DEC3,
  78. TX_MACRO_DEC4,
  79. TX_MACRO_DEC5,
  80. TX_MACRO_DEC6,
  81. TX_MACRO_DEC7,
  82. TX_MACRO_DEC_MAX,
  83. };
  84. enum {
  85. TX_MACRO_CLK_DIV_2,
  86. TX_MACRO_CLK_DIV_3,
  87. TX_MACRO_CLK_DIV_4,
  88. TX_MACRO_CLK_DIV_6,
  89. TX_MACRO_CLK_DIV_8,
  90. TX_MACRO_CLK_DIV_16,
  91. };
  92. enum {
  93. MSM_DMIC,
  94. SWR_MIC,
  95. ANC_FB_TUNE1
  96. };
  97. enum {
  98. TX_MCLK,
  99. VA_MCLK,
  100. };
  101. struct tx_mute_work {
  102. struct tx_macro_priv *tx_priv;
  103. u32 decimator;
  104. struct delayed_work dwork;
  105. };
  106. struct hpf_work {
  107. struct tx_macro_priv *tx_priv;
  108. u8 decimator;
  109. u8 hpf_cut_off_freq;
  110. struct delayed_work dwork;
  111. };
  112. struct tx_macro_priv {
  113. struct device *dev;
  114. bool dec_active[NUM_DECIMATORS];
  115. int tx_mclk_users;
  116. int swr_clk_users;
  117. bool dapm_mclk_enable;
  118. bool reset_swr;
  119. struct mutex mclk_lock;
  120. struct mutex swr_clk_lock;
  121. struct snd_soc_component *component;
  122. struct device_node *tx_swr_gpio_p;
  123. struct tx_macro_swr_ctrl_data *swr_ctrl_data;
  124. struct tx_macro_swr_ctrl_platform_data swr_plat_data;
  125. struct work_struct tx_macro_add_child_devices_work;
  126. struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  127. struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
  128. s32 dmic_0_1_clk_cnt;
  129. s32 dmic_2_3_clk_cnt;
  130. s32 dmic_4_5_clk_cnt;
  131. s32 dmic_6_7_clk_cnt;
  132. u16 dmic_clk_div;
  133. unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
  134. unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
  135. char __iomem *tx_io_base;
  136. struct platform_device *pdev_child_devices
  137. [TX_MACRO_CHILD_DEVICES_MAX];
  138. int child_count;
  139. int tx_swr_clk_cnt;
  140. int va_swr_clk_cnt;
  141. int va_clk_status;
  142. int tx_clk_status;
  143. };
  144. static bool tx_macro_get_data(struct snd_soc_component *component,
  145. struct device **tx_dev,
  146. struct tx_macro_priv **tx_priv,
  147. const char *func_name)
  148. {
  149. *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  150. if (!(*tx_dev)) {
  151. dev_err(component->dev,
  152. "%s: null device for macro!\n", func_name);
  153. return false;
  154. }
  155. *tx_priv = dev_get_drvdata((*tx_dev));
  156. if (!(*tx_priv)) {
  157. dev_err(component->dev,
  158. "%s: priv is null for macro!\n", func_name);
  159. return false;
  160. }
  161. if (!(*tx_priv)->component) {
  162. dev_err(component->dev,
  163. "%s: tx_priv->component not initialized!\n", func_name);
  164. return false;
  165. }
  166. return true;
  167. }
  168. static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
  169. bool mclk_enable)
  170. {
  171. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  172. int ret = 0;
  173. if (regmap == NULL) {
  174. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  175. return -EINVAL;
  176. }
  177. dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
  178. __func__, mclk_enable, tx_priv->tx_mclk_users);
  179. mutex_lock(&tx_priv->mclk_lock);
  180. if (mclk_enable) {
  181. if (tx_priv->tx_mclk_users == 0) {
  182. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  183. TX_CORE_CLK,
  184. TX_CORE_CLK,
  185. true);
  186. if (ret < 0) {
  187. dev_err_ratelimited(tx_priv->dev,
  188. "%s: request clock enable failed\n",
  189. __func__);
  190. goto exit;
  191. }
  192. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  193. true);
  194. regcache_mark_dirty(regmap);
  195. regcache_sync_region(regmap,
  196. TX_START_OFFSET,
  197. TX_MAX_OFFSET);
  198. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  199. regmap_update_bits(regmap,
  200. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
  201. regmap_update_bits(regmap,
  202. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  203. 0x01, 0x01);
  204. regmap_update_bits(regmap,
  205. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  206. 0x01, 0x01);
  207. }
  208. tx_priv->tx_mclk_users++;
  209. } else {
  210. if (tx_priv->tx_mclk_users <= 0) {
  211. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  212. __func__);
  213. tx_priv->tx_mclk_users = 0;
  214. goto exit;
  215. }
  216. tx_priv->tx_mclk_users--;
  217. if (tx_priv->tx_mclk_users == 0) {
  218. regmap_update_bits(regmap,
  219. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  220. 0x01, 0x00);
  221. regmap_update_bits(regmap,
  222. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  223. 0x01, 0x00);
  224. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  225. false);
  226. bolero_clk_rsc_request_clock(tx_priv->dev,
  227. TX_CORE_CLK,
  228. TX_CORE_CLK,
  229. false);
  230. }
  231. }
  232. exit:
  233. mutex_unlock(&tx_priv->mclk_lock);
  234. return ret;
  235. }
  236. static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
  237. struct snd_kcontrol *kcontrol, int event)
  238. {
  239. struct device *tx_dev = NULL;
  240. struct tx_macro_priv *tx_priv = NULL;
  241. struct snd_soc_component *component =
  242. snd_soc_dapm_to_component(w->dapm);
  243. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  244. return -EINVAL;
  245. if (SND_SOC_DAPM_EVENT_ON(event))
  246. ++tx_priv->va_swr_clk_cnt;
  247. if (SND_SOC_DAPM_EVENT_OFF(event))
  248. --tx_priv->va_swr_clk_cnt;
  249. return 0;
  250. }
  251. static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
  252. struct snd_kcontrol *kcontrol, int event)
  253. {
  254. struct device *tx_dev = NULL;
  255. struct tx_macro_priv *tx_priv = NULL;
  256. struct snd_soc_component *component =
  257. snd_soc_dapm_to_component(w->dapm);
  258. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  259. return -EINVAL;
  260. if (SND_SOC_DAPM_EVENT_ON(event))
  261. ++tx_priv->tx_swr_clk_cnt;
  262. if (SND_SOC_DAPM_EVENT_OFF(event))
  263. --tx_priv->tx_swr_clk_cnt;
  264. return 0;
  265. }
  266. static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  267. struct snd_kcontrol *kcontrol, int event)
  268. {
  269. struct snd_soc_component *component =
  270. snd_soc_dapm_to_component(w->dapm);
  271. int ret = 0;
  272. struct device *tx_dev = NULL;
  273. struct tx_macro_priv *tx_priv = NULL;
  274. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  275. return -EINVAL;
  276. dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
  277. switch (event) {
  278. case SND_SOC_DAPM_PRE_PMU:
  279. ret = tx_macro_mclk_enable(tx_priv, 1);
  280. if (ret)
  281. tx_priv->dapm_mclk_enable = false;
  282. else
  283. tx_priv->dapm_mclk_enable = true;
  284. break;
  285. case SND_SOC_DAPM_POST_PMD:
  286. if (tx_priv->dapm_mclk_enable)
  287. ret = tx_macro_mclk_enable(tx_priv, 0);
  288. break;
  289. default:
  290. dev_err(tx_priv->dev,
  291. "%s: invalid DAPM event %d\n", __func__, event);
  292. ret = -EINVAL;
  293. }
  294. return ret;
  295. }
  296. static int tx_macro_event_handler(struct snd_soc_component *component,
  297. u16 event, u32 data)
  298. {
  299. struct device *tx_dev = NULL;
  300. struct tx_macro_priv *tx_priv = NULL;
  301. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  302. return -EINVAL;
  303. switch (event) {
  304. case BOLERO_MACRO_EVT_SSR_DOWN:
  305. if (tx_priv->swr_ctrl_data) {
  306. swrm_wcd_notify(
  307. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  308. SWR_DEVICE_DOWN, NULL);
  309. swrm_wcd_notify(
  310. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  311. SWR_DEVICE_SSR_DOWN, NULL);
  312. }
  313. if (!pm_runtime_status_suspended(tx_dev))
  314. bolero_runtime_suspend(tx_dev);
  315. break;
  316. case BOLERO_MACRO_EVT_SSR_UP:
  317. /* reset swr after ssr/pdr */
  318. tx_priv->reset_swr = true;
  319. if (tx_priv->swr_ctrl_data)
  320. swrm_wcd_notify(
  321. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  322. SWR_DEVICE_SSR_UP, NULL);
  323. break;
  324. case BOLERO_MACRO_EVT_CLK_RESET:
  325. bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK);
  326. break;
  327. }
  328. return 0;
  329. }
  330. static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
  331. u32 data)
  332. {
  333. struct device *tx_dev = NULL;
  334. struct tx_macro_priv *tx_priv = NULL;
  335. u32 ipc_wakeup = data;
  336. int ret = 0;
  337. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  338. return -EINVAL;
  339. if (tx_priv->swr_ctrl_data)
  340. ret = swrm_wcd_notify(
  341. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  342. SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
  343. return ret;
  344. }
  345. static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  346. {
  347. struct delayed_work *hpf_delayed_work = NULL;
  348. struct hpf_work *hpf_work = NULL;
  349. struct tx_macro_priv *tx_priv = NULL;
  350. struct snd_soc_component *component = NULL;
  351. u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
  352. u8 hpf_cut_off_freq = 0;
  353. u16 adc_mux_reg = 0, adc_n = 0, adc_reg = 0;
  354. hpf_delayed_work = to_delayed_work(work);
  355. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  356. tx_priv = hpf_work->tx_priv;
  357. component = tx_priv->component;
  358. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  359. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  360. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  361. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  362. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  363. dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  364. __func__, hpf_work->decimator, hpf_cut_off_freq);
  365. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  366. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  367. if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
  368. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  369. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  370. adc_n = snd_soc_component_read32(component, adc_reg) &
  371. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  372. if (adc_n >= BOLERO_ADC_MAX)
  373. goto tx_hpf_set;
  374. /* analog mic clear TX hold */
  375. bolero_clear_amic_tx_hold(component->dev, adc_n);
  376. }
  377. tx_hpf_set:
  378. snd_soc_component_update_bits(component,
  379. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  380. hpf_cut_off_freq << 5);
  381. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x02);
  382. /* Minimum 1 clk cycle delay is required as per HW spec */
  383. usleep_range(1000, 1010);
  384. snd_soc_component_update_bits(component, hpf_gate_reg, 0x03, 0x01);
  385. }
  386. static void tx_macro_mute_update_callback(struct work_struct *work)
  387. {
  388. struct tx_mute_work *tx_mute_dwork = NULL;
  389. struct snd_soc_component *component = NULL;
  390. struct tx_macro_priv *tx_priv = NULL;
  391. struct delayed_work *delayed_work = NULL;
  392. u16 tx_vol_ctl_reg = 0;
  393. u8 decimator = 0;
  394. delayed_work = to_delayed_work(work);
  395. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  396. tx_priv = tx_mute_dwork->tx_priv;
  397. component = tx_priv->component;
  398. decimator = tx_mute_dwork->decimator;
  399. tx_vol_ctl_reg =
  400. BOLERO_CDC_TX0_TX_PATH_CTL +
  401. TX_MACRO_TX_PATH_OFFSET * decimator;
  402. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  403. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  404. __func__, decimator);
  405. }
  406. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  407. struct snd_ctl_elem_value *ucontrol)
  408. {
  409. struct snd_soc_dapm_widget *widget =
  410. snd_soc_dapm_kcontrol_widget(kcontrol);
  411. struct snd_soc_component *component =
  412. snd_soc_dapm_to_component(widget->dapm);
  413. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  414. unsigned int val = 0;
  415. u16 mic_sel_reg = 0;
  416. u16 dmic_clk_reg = 0;
  417. struct device *tx_dev = NULL;
  418. struct tx_macro_priv *tx_priv = NULL;
  419. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  420. return -EINVAL;
  421. val = ucontrol->value.enumerated.item[0];
  422. if (val > e->items - 1)
  423. return -EINVAL;
  424. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  425. widget->name, val);
  426. switch (e->reg) {
  427. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  428. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  429. break;
  430. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  431. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  432. break;
  433. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  434. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  435. break;
  436. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  437. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  438. break;
  439. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  440. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  441. break;
  442. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  443. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  444. break;
  445. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  446. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  447. break;
  448. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  449. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  450. break;
  451. default:
  452. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  453. __func__, e->reg);
  454. return -EINVAL;
  455. }
  456. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  457. if (val != 0) {
  458. if (val < 5) {
  459. snd_soc_component_update_bits(component,
  460. mic_sel_reg,
  461. 1 << 7, 0x0 << 7);
  462. } else {
  463. snd_soc_component_update_bits(component,
  464. mic_sel_reg,
  465. 1 << 7, 0x1 << 7);
  466. snd_soc_component_update_bits(component,
  467. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  468. 0x80, 0x00);
  469. dmic_clk_reg =
  470. BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
  471. ((val - 5)/2) * 4;
  472. snd_soc_component_update_bits(component,
  473. dmic_clk_reg,
  474. 0x0E, tx_priv->dmic_clk_div << 0x1);
  475. }
  476. }
  477. } else {
  478. /* DMIC selected */
  479. if (val != 0)
  480. snd_soc_component_update_bits(component, mic_sel_reg,
  481. 1 << 7, 1 << 7);
  482. }
  483. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  484. }
  485. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  486. struct snd_ctl_elem_value *ucontrol)
  487. {
  488. struct snd_soc_dapm_widget *widget =
  489. snd_soc_dapm_kcontrol_widget(kcontrol);
  490. struct snd_soc_component *component =
  491. snd_soc_dapm_to_component(widget->dapm);
  492. struct soc_multi_mixer_control *mixer =
  493. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  494. u32 dai_id = widget->shift;
  495. u32 dec_id = mixer->shift;
  496. struct device *tx_dev = NULL;
  497. struct tx_macro_priv *tx_priv = NULL;
  498. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  499. return -EINVAL;
  500. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  501. ucontrol->value.integer.value[0] = 1;
  502. else
  503. ucontrol->value.integer.value[0] = 0;
  504. return 0;
  505. }
  506. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  507. struct snd_ctl_elem_value *ucontrol)
  508. {
  509. struct snd_soc_dapm_widget *widget =
  510. snd_soc_dapm_kcontrol_widget(kcontrol);
  511. struct snd_soc_component *component =
  512. snd_soc_dapm_to_component(widget->dapm);
  513. struct snd_soc_dapm_update *update = NULL;
  514. struct soc_multi_mixer_control *mixer =
  515. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  516. u32 dai_id = widget->shift;
  517. u32 dec_id = mixer->shift;
  518. u32 enable = ucontrol->value.integer.value[0];
  519. struct device *tx_dev = NULL;
  520. struct tx_macro_priv *tx_priv = NULL;
  521. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  522. return -EINVAL;
  523. if (enable) {
  524. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  525. tx_priv->active_ch_cnt[dai_id]++;
  526. } else {
  527. tx_priv->active_ch_cnt[dai_id]--;
  528. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  529. }
  530. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  531. return 0;
  532. }
  533. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  534. struct snd_kcontrol *kcontrol, int event)
  535. {
  536. struct snd_soc_component *component =
  537. snd_soc_dapm_to_component(w->dapm);
  538. u8 dmic_clk_en = 0x01;
  539. u16 dmic_clk_reg = 0;
  540. s32 *dmic_clk_cnt = NULL;
  541. unsigned int dmic = 0;
  542. int ret = 0;
  543. char *wname = NULL;
  544. struct device *tx_dev = NULL;
  545. struct tx_macro_priv *tx_priv = NULL;
  546. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  547. return -EINVAL;
  548. wname = strpbrk(w->name, "01234567");
  549. if (!wname) {
  550. dev_err(component->dev, "%s: widget not found\n", __func__);
  551. return -EINVAL;
  552. }
  553. ret = kstrtouint(wname, 10, &dmic);
  554. if (ret < 0) {
  555. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  556. __func__);
  557. return -EINVAL;
  558. }
  559. switch (dmic) {
  560. case 0:
  561. case 1:
  562. dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt);
  563. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  564. break;
  565. case 2:
  566. case 3:
  567. dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt);
  568. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  569. break;
  570. case 4:
  571. case 5:
  572. dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt);
  573. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  574. break;
  575. case 6:
  576. case 7:
  577. dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt);
  578. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  579. break;
  580. default:
  581. dev_err(component->dev, "%s: Invalid DMIC Selection\n",
  582. __func__);
  583. return -EINVAL;
  584. }
  585. dev_dbg(component->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  586. __func__, event, dmic, *dmic_clk_cnt);
  587. switch (event) {
  588. case SND_SOC_DAPM_PRE_PMU:
  589. (*dmic_clk_cnt)++;
  590. if (*dmic_clk_cnt == 1) {
  591. snd_soc_component_update_bits(component,
  592. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  593. 0x80, 0x00);
  594. snd_soc_component_update_bits(component, dmic_clk_reg,
  595. 0x0E, tx_priv->dmic_clk_div << 0x1);
  596. snd_soc_component_update_bits(component, dmic_clk_reg,
  597. dmic_clk_en, dmic_clk_en);
  598. }
  599. break;
  600. case SND_SOC_DAPM_POST_PMD:
  601. (*dmic_clk_cnt)--;
  602. if (*dmic_clk_cnt == 0)
  603. snd_soc_component_update_bits(component, dmic_clk_reg,
  604. dmic_clk_en, 0);
  605. break;
  606. }
  607. return 0;
  608. }
  609. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  610. struct snd_kcontrol *kcontrol, int event)
  611. {
  612. struct snd_soc_component *component =
  613. snd_soc_dapm_to_component(w->dapm);
  614. unsigned int decimator = 0;
  615. u16 tx_vol_ctl_reg = 0;
  616. u16 dec_cfg_reg = 0;
  617. u16 hpf_gate_reg = 0;
  618. u16 tx_gain_ctl_reg = 0;
  619. u8 hpf_cut_off_freq = 0;
  620. struct device *tx_dev = NULL;
  621. struct tx_macro_priv *tx_priv = NULL;
  622. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  623. return -EINVAL;
  624. decimator = w->shift;
  625. dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
  626. w->name, decimator);
  627. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  628. TX_MACRO_TX_PATH_OFFSET * decimator;
  629. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  630. TX_MACRO_TX_PATH_OFFSET * decimator;
  631. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  632. TX_MACRO_TX_PATH_OFFSET * decimator;
  633. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  634. TX_MACRO_TX_PATH_OFFSET * decimator;
  635. switch (event) {
  636. case SND_SOC_DAPM_PRE_PMU:
  637. /* Enable TX PGA Mute */
  638. snd_soc_component_update_bits(component,
  639. tx_vol_ctl_reg, 0x10, 0x10);
  640. break;
  641. case SND_SOC_DAPM_POST_PMU:
  642. snd_soc_component_update_bits(component,
  643. tx_vol_ctl_reg, 0x20, 0x20);
  644. snd_soc_component_update_bits(component,
  645. hpf_gate_reg, 0x01, 0x00);
  646. hpf_cut_off_freq = (
  647. snd_soc_component_read32(component, dec_cfg_reg) &
  648. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  649. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  650. hpf_cut_off_freq;
  651. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  652. snd_soc_component_update_bits(component, dec_cfg_reg,
  653. TX_HPF_CUT_OFF_FREQ_MASK,
  654. CF_MIN_3DB_150HZ << 5);
  655. /* schedule work queue to Remove Mute */
  656. schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
  657. msecs_to_jiffies(tx_unmute_delay));
  658. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  659. CF_MIN_3DB_150HZ) {
  660. schedule_delayed_work(
  661. &tx_priv->tx_hpf_work[decimator].dwork,
  662. msecs_to_jiffies(50));
  663. snd_soc_component_update_bits(component,
  664. hpf_gate_reg, 0x02, 0x02);
  665. /*
  666. * Minimum 1 clk cycle delay is required as per HW spec
  667. */
  668. usleep_range(1000, 1010);
  669. snd_soc_component_update_bits(component,
  670. hpf_gate_reg, 0x02, 0x00);
  671. }
  672. /* apply gain after decimator is enabled */
  673. snd_soc_component_write(component, tx_gain_ctl_reg,
  674. snd_soc_component_read32(component,
  675. tx_gain_ctl_reg));
  676. break;
  677. case SND_SOC_DAPM_PRE_PMD:
  678. hpf_cut_off_freq =
  679. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  680. snd_soc_component_update_bits(component,
  681. tx_vol_ctl_reg, 0x10, 0x10);
  682. if (cancel_delayed_work_sync(
  683. &tx_priv->tx_hpf_work[decimator].dwork)) {
  684. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  685. snd_soc_component_update_bits(
  686. component, dec_cfg_reg,
  687. TX_HPF_CUT_OFF_FREQ_MASK,
  688. hpf_cut_off_freq << 5);
  689. snd_soc_component_update_bits(component,
  690. hpf_gate_reg,
  691. 0x02, 0x02);
  692. /*
  693. * Minimum 1 clk cycle delay is required
  694. * as per HW spec
  695. */
  696. usleep_range(1000, 1010);
  697. snd_soc_component_update_bits(component,
  698. hpf_gate_reg,
  699. 0x02, 0x00);
  700. }
  701. }
  702. cancel_delayed_work_sync(
  703. &tx_priv->tx_mute_dwork[decimator].dwork);
  704. break;
  705. case SND_SOC_DAPM_POST_PMD:
  706. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  707. 0x20, 0x00);
  708. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  709. 0x10, 0x00);
  710. break;
  711. }
  712. return 0;
  713. }
  714. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  715. struct snd_kcontrol *kcontrol, int event)
  716. {
  717. return 0;
  718. }
  719. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  720. struct snd_pcm_hw_params *params,
  721. struct snd_soc_dai *dai)
  722. {
  723. int tx_fs_rate = -EINVAL;
  724. struct snd_soc_component *component = dai->component;
  725. u32 decimator = 0;
  726. u32 sample_rate = 0;
  727. u16 tx_fs_reg = 0;
  728. struct device *tx_dev = NULL;
  729. struct tx_macro_priv *tx_priv = NULL;
  730. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  731. return -EINVAL;
  732. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  733. dai->name, dai->id, params_rate(params),
  734. params_channels(params));
  735. sample_rate = params_rate(params);
  736. switch (sample_rate) {
  737. case 8000:
  738. tx_fs_rate = 0;
  739. break;
  740. case 16000:
  741. tx_fs_rate = 1;
  742. break;
  743. case 32000:
  744. tx_fs_rate = 3;
  745. break;
  746. case 48000:
  747. tx_fs_rate = 4;
  748. break;
  749. case 96000:
  750. tx_fs_rate = 5;
  751. break;
  752. case 192000:
  753. tx_fs_rate = 6;
  754. break;
  755. case 384000:
  756. tx_fs_rate = 7;
  757. break;
  758. default:
  759. dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
  760. __func__, params_rate(params));
  761. return -EINVAL;
  762. }
  763. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  764. TX_MACRO_DEC_MAX) {
  765. if (decimator >= 0) {
  766. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  767. TX_MACRO_TX_PATH_OFFSET * decimator;
  768. dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
  769. __func__, decimator, sample_rate);
  770. snd_soc_component_update_bits(component, tx_fs_reg,
  771. 0x0F, tx_fs_rate);
  772. } else {
  773. dev_err(component->dev,
  774. "%s: ERROR: Invalid decimator: %d\n",
  775. __func__, decimator);
  776. return -EINVAL;
  777. }
  778. }
  779. return 0;
  780. }
  781. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  782. unsigned int *tx_num, unsigned int *tx_slot,
  783. unsigned int *rx_num, unsigned int *rx_slot)
  784. {
  785. struct snd_soc_component *component = dai->component;
  786. struct device *tx_dev = NULL;
  787. struct tx_macro_priv *tx_priv = NULL;
  788. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  789. return -EINVAL;
  790. switch (dai->id) {
  791. case TX_MACRO_AIF1_CAP:
  792. case TX_MACRO_AIF2_CAP:
  793. *tx_slot = tx_priv->active_ch_mask[dai->id];
  794. *tx_num = tx_priv->active_ch_cnt[dai->id];
  795. break;
  796. default:
  797. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  798. break;
  799. }
  800. return 0;
  801. }
  802. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  803. .hw_params = tx_macro_hw_params,
  804. .get_channel_map = tx_macro_get_channel_map,
  805. };
  806. static struct snd_soc_dai_driver tx_macro_dai[] = {
  807. {
  808. .name = "tx_macro_tx1",
  809. .id = TX_MACRO_AIF1_CAP,
  810. .capture = {
  811. .stream_name = "TX_AIF1 Capture",
  812. .rates = TX_MACRO_RATES,
  813. .formats = TX_MACRO_FORMATS,
  814. .rate_max = 192000,
  815. .rate_min = 8000,
  816. .channels_min = 1,
  817. .channels_max = 8,
  818. },
  819. .ops = &tx_macro_dai_ops,
  820. },
  821. {
  822. .name = "tx_macro_tx2",
  823. .id = TX_MACRO_AIF2_CAP,
  824. .capture = {
  825. .stream_name = "TX_AIF2 Capture",
  826. .rates = TX_MACRO_RATES,
  827. .formats = TX_MACRO_FORMATS,
  828. .rate_max = 192000,
  829. .rate_min = 8000,
  830. .channels_min = 1,
  831. .channels_max = 8,
  832. },
  833. .ops = &tx_macro_dai_ops,
  834. },
  835. };
  836. #define STRING(name) #name
  837. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  838. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  839. static const struct snd_kcontrol_new name##_mux = \
  840. SOC_DAPM_ENUM(STRING(name), name##_enum)
  841. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  842. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  843. static const struct snd_kcontrol_new name##_mux = \
  844. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  845. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  846. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  847. static const char * const adc_mux_text[] = {
  848. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  849. };
  850. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  851. 0, adc_mux_text);
  852. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  853. 0, adc_mux_text);
  854. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  855. 0, adc_mux_text);
  856. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  857. 0, adc_mux_text);
  858. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  859. 0, adc_mux_text);
  860. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  861. 0, adc_mux_text);
  862. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  863. 0, adc_mux_text);
  864. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  865. 0, adc_mux_text);
  866. static const char * const dmic_mux_text[] = {
  867. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  868. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  869. };
  870. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  871. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  872. tx_macro_put_dec_enum);
  873. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  874. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  875. tx_macro_put_dec_enum);
  876. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  877. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  878. tx_macro_put_dec_enum);
  879. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  880. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  881. tx_macro_put_dec_enum);
  882. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  883. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  884. tx_macro_put_dec_enum);
  885. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  886. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  887. tx_macro_put_dec_enum);
  888. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  889. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  890. tx_macro_put_dec_enum);
  891. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  892. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  893. tx_macro_put_dec_enum);
  894. static const char * const smic_mux_text[] = {
  895. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
  896. "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
  897. "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  898. };
  899. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  900. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  901. tx_macro_put_dec_enum);
  902. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  903. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  904. tx_macro_put_dec_enum);
  905. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  906. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  907. tx_macro_put_dec_enum);
  908. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  909. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  910. tx_macro_put_dec_enum);
  911. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  912. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  913. tx_macro_put_dec_enum);
  914. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  915. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  916. tx_macro_put_dec_enum);
  917. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  918. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  919. tx_macro_put_dec_enum);
  920. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  921. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  922. tx_macro_put_dec_enum);
  923. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  924. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  925. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  926. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  927. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  928. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  929. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  930. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  931. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  932. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  933. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  934. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  935. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  936. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  937. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  938. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  939. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  940. };
  941. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  942. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  943. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  944. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  945. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  946. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  947. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  948. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  949. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  950. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  951. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  952. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  953. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  954. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  955. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  956. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  957. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  958. };
  959. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  960. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  961. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  962. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  963. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  964. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  965. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  966. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  967. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  968. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  969. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  970. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  971. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  972. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  973. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  974. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  975. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  976. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  977. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  978. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  979. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  980. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  981. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  982. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  983. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  984. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  985. tx_macro_enable_micbias,
  986. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  987. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  988. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  989. SND_SOC_DAPM_POST_PMD),
  990. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  991. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  992. SND_SOC_DAPM_POST_PMD),
  993. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  994. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  995. SND_SOC_DAPM_POST_PMD),
  996. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  997. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  998. SND_SOC_DAPM_POST_PMD),
  999. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1000. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1001. SND_SOC_DAPM_POST_PMD),
  1002. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1003. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1004. SND_SOC_DAPM_POST_PMD),
  1005. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1006. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1007. SND_SOC_DAPM_POST_PMD),
  1008. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1009. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1010. SND_SOC_DAPM_POST_PMD),
  1011. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  1012. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  1013. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  1014. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  1015. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  1016. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  1017. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  1018. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  1019. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  1020. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  1021. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  1022. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  1023. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1024. TX_MACRO_DEC0, 0,
  1025. &tx_dec0_mux, tx_macro_enable_dec,
  1026. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1027. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1028. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1029. TX_MACRO_DEC1, 0,
  1030. &tx_dec1_mux, tx_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("TX DEC2 MUX", SND_SOC_NOPM,
  1034. TX_MACRO_DEC2, 0,
  1035. &tx_dec2_mux, tx_macro_enable_dec,
  1036. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1037. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1038. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1039. TX_MACRO_DEC3, 0,
  1040. &tx_dec3_mux, tx_macro_enable_dec,
  1041. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1042. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1043. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1044. TX_MACRO_DEC4, 0,
  1045. &tx_dec4_mux, tx_macro_enable_dec,
  1046. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1047. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1048. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1049. TX_MACRO_DEC5, 0,
  1050. &tx_dec5_mux, tx_macro_enable_dec,
  1051. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1052. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1053. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1054. TX_MACRO_DEC6, 0,
  1055. &tx_dec6_mux, tx_macro_enable_dec,
  1056. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1057. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1058. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1059. TX_MACRO_DEC7, 0,
  1060. &tx_dec7_mux, tx_macro_enable_dec,
  1061. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1062. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1063. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1064. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1065. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1066. tx_macro_tx_swr_clk_event,
  1067. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1068. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1069. tx_macro_va_swr_clk_event,
  1070. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1071. };
  1072. static const struct snd_soc_dapm_route tx_audio_map[] = {
  1073. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1074. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1075. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1076. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1077. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1078. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1079. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1080. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1081. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1082. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1083. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1084. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1085. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1086. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1087. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1088. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1089. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1090. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1091. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1092. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1093. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1094. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1095. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1096. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1097. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1098. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1099. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1100. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1101. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1102. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1103. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1104. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1105. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1106. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1107. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1108. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1109. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1110. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1111. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  1112. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  1113. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  1114. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  1115. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  1116. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  1117. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  1118. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  1119. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  1120. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  1121. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  1122. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  1123. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  1124. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1125. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1126. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1127. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1128. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1129. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1130. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1131. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1132. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1133. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1134. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  1135. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  1136. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  1137. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  1138. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  1139. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  1140. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  1141. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  1142. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  1143. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  1144. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  1145. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  1146. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  1147. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1148. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1149. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1150. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1151. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1152. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1153. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1154. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1155. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1156. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1157. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  1158. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  1159. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  1160. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  1161. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  1162. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  1163. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  1164. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  1165. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  1166. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  1167. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  1168. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  1169. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  1170. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1171. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1172. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1173. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1174. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1175. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1176. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1177. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1178. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1179. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1180. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  1181. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  1182. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  1183. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  1184. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  1185. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  1186. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  1187. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  1188. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  1189. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  1190. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  1191. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  1192. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  1193. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1194. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1195. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1196. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1197. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1198. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1199. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1200. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1201. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1202. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1203. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  1204. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  1205. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  1206. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  1207. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  1208. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  1209. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  1210. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  1211. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  1212. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  1213. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  1214. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  1215. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  1216. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1217. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1218. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1219. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1220. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1221. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1222. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1223. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1224. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1225. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1226. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  1227. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  1228. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  1229. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  1230. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  1231. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  1232. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  1233. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  1234. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  1235. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  1236. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  1237. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  1238. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  1239. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1240. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1241. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1242. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1243. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1244. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1245. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1246. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1247. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1248. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1249. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  1250. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  1251. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  1252. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  1253. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  1254. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  1255. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  1256. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  1257. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  1258. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  1259. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  1260. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  1261. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  1262. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1263. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1264. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1265. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1266. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1267. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1268. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1269. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1270. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1271. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1272. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  1273. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  1274. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  1275. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  1276. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  1277. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  1278. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  1279. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  1280. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  1281. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  1282. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  1283. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  1284. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  1285. };
  1286. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  1287. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1288. BOLERO_CDC_TX0_TX_VOL_CTL,
  1289. 0, -84, 40, digital_gain),
  1290. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1291. BOLERO_CDC_TX1_TX_VOL_CTL,
  1292. 0, -84, 40, digital_gain),
  1293. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1294. BOLERO_CDC_TX2_TX_VOL_CTL,
  1295. 0, -84, 40, digital_gain),
  1296. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1297. BOLERO_CDC_TX3_TX_VOL_CTL,
  1298. 0, -84, 40, digital_gain),
  1299. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1300. BOLERO_CDC_TX4_TX_VOL_CTL,
  1301. 0, -84, 40, digital_gain),
  1302. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1303. BOLERO_CDC_TX5_TX_VOL_CTL,
  1304. 0, -84, 40, digital_gain),
  1305. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1306. BOLERO_CDC_TX6_TX_VOL_CTL,
  1307. 0, -84, 40, digital_gain),
  1308. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1309. BOLERO_CDC_TX7_TX_VOL_CTL,
  1310. 0, -84, 40, digital_gain),
  1311. };
  1312. static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
  1313. struct regmap *regmap, int clk_type,
  1314. bool enable)
  1315. {
  1316. int ret = 0, clk_tx_ret = 0;
  1317. dev_dbg(tx_priv->dev,
  1318. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  1319. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  1320. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  1321. if (enable) {
  1322. if (tx_priv->swr_clk_users == 0)
  1323. msm_cdc_pinctrl_select_active_state(
  1324. tx_priv->tx_swr_gpio_p);
  1325. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1326. TX_CORE_CLK,
  1327. TX_CORE_CLK,
  1328. true);
  1329. if (clk_type == TX_MCLK) {
  1330. ret = tx_macro_mclk_enable(tx_priv, 1);
  1331. if (ret < 0) {
  1332. if (tx_priv->swr_clk_users == 0)
  1333. msm_cdc_pinctrl_select_sleep_state(
  1334. tx_priv->tx_swr_gpio_p);
  1335. dev_err_ratelimited(tx_priv->dev,
  1336. "%s: request clock enable failed\n",
  1337. __func__);
  1338. goto done;
  1339. }
  1340. }
  1341. if (clk_type == VA_MCLK) {
  1342. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1343. TX_CORE_CLK,
  1344. VA_CORE_CLK,
  1345. true);
  1346. if (ret < 0) {
  1347. if (tx_priv->swr_clk_users == 0)
  1348. msm_cdc_pinctrl_select_sleep_state(
  1349. tx_priv->tx_swr_gpio_p);
  1350. dev_err_ratelimited(tx_priv->dev,
  1351. "%s: swr request clk failed\n",
  1352. __func__);
  1353. goto done;
  1354. }
  1355. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  1356. true);
  1357. if (tx_priv->tx_mclk_users == 0) {
  1358. regmap_update_bits(regmap,
  1359. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
  1360. 0x01, 0x01);
  1361. regmap_update_bits(regmap,
  1362. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  1363. 0x01, 0x01);
  1364. regmap_update_bits(regmap,
  1365. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  1366. 0x01, 0x01);
  1367. }
  1368. }
  1369. if (tx_priv->swr_clk_users == 0) {
  1370. dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
  1371. __func__, tx_priv->reset_swr);
  1372. if (tx_priv->reset_swr)
  1373. regmap_update_bits(regmap,
  1374. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1375. 0x02, 0x02);
  1376. regmap_update_bits(regmap,
  1377. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1378. 0x01, 0x01);
  1379. if (tx_priv->reset_swr)
  1380. regmap_update_bits(regmap,
  1381. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1382. 0x02, 0x00);
  1383. tx_priv->reset_swr = false;
  1384. }
  1385. if (!clk_tx_ret)
  1386. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1387. TX_CORE_CLK,
  1388. TX_CORE_CLK,
  1389. false);
  1390. tx_priv->swr_clk_users++;
  1391. } else {
  1392. if (tx_priv->swr_clk_users <= 0) {
  1393. dev_err_ratelimited(tx_priv->dev,
  1394. "tx swrm clock users already 0\n");
  1395. tx_priv->swr_clk_users = 0;
  1396. return 0;
  1397. }
  1398. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1399. TX_CORE_CLK,
  1400. TX_CORE_CLK,
  1401. true);
  1402. tx_priv->swr_clk_users--;
  1403. if (tx_priv->swr_clk_users == 0)
  1404. regmap_update_bits(regmap,
  1405. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1406. 0x01, 0x00);
  1407. if (clk_type == TX_MCLK)
  1408. tx_macro_mclk_enable(tx_priv, 0);
  1409. if (clk_type == VA_MCLK) {
  1410. if (tx_priv->tx_mclk_users == 0) {
  1411. regmap_update_bits(regmap,
  1412. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  1413. 0x01, 0x00);
  1414. regmap_update_bits(regmap,
  1415. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  1416. 0x01, 0x00);
  1417. }
  1418. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  1419. false);
  1420. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1421. TX_CORE_CLK,
  1422. VA_CORE_CLK,
  1423. false);
  1424. if (ret < 0) {
  1425. dev_err_ratelimited(tx_priv->dev,
  1426. "%s: swr request clk failed\n",
  1427. __func__);
  1428. goto done;
  1429. }
  1430. }
  1431. if (!clk_tx_ret)
  1432. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  1433. TX_CORE_CLK,
  1434. TX_CORE_CLK,
  1435. false);
  1436. if (tx_priv->swr_clk_users == 0)
  1437. msm_cdc_pinctrl_select_sleep_state(
  1438. tx_priv->tx_swr_gpio_p);
  1439. }
  1440. return 0;
  1441. done:
  1442. if (!clk_tx_ret)
  1443. bolero_clk_rsc_request_clock(tx_priv->dev,
  1444. TX_CORE_CLK,
  1445. TX_CORE_CLK,
  1446. false);
  1447. return ret;
  1448. }
  1449. static int tx_macro_swrm_clock(void *handle, bool enable)
  1450. {
  1451. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  1452. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  1453. int ret = 0;
  1454. if (regmap == NULL) {
  1455. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  1456. return -EINVAL;
  1457. }
  1458. mutex_lock(&tx_priv->swr_clk_lock);
  1459. dev_dbg(tx_priv->dev,
  1460. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  1461. __func__, (enable ? "enable" : "disable"),
  1462. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  1463. if (enable) {
  1464. pm_runtime_get_sync(tx_priv->dev);
  1465. if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
  1466. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1467. VA_MCLK, enable);
  1468. if (ret)
  1469. goto done;
  1470. tx_priv->va_clk_status++;
  1471. } else {
  1472. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1473. TX_MCLK, enable);
  1474. if (ret)
  1475. goto done;
  1476. tx_priv->tx_clk_status++;
  1477. }
  1478. pm_runtime_mark_last_busy(tx_priv->dev);
  1479. pm_runtime_put_autosuspend(tx_priv->dev);
  1480. } else {
  1481. if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
  1482. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1483. VA_MCLK, enable);
  1484. if (ret)
  1485. goto done;
  1486. --tx_priv->va_clk_status;
  1487. } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  1488. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1489. TX_MCLK, enable);
  1490. if (ret)
  1491. goto done;
  1492. --tx_priv->tx_clk_status;
  1493. } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  1494. if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
  1495. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1496. VA_MCLK, enable);
  1497. if (ret)
  1498. goto done;
  1499. --tx_priv->va_clk_status;
  1500. } else {
  1501. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  1502. TX_MCLK, enable);
  1503. if (ret)
  1504. goto done;
  1505. --tx_priv->tx_clk_status;
  1506. }
  1507. } else {
  1508. dev_dbg(tx_priv->dev,
  1509. "%s: Both clocks are disabled\n", __func__);
  1510. }
  1511. }
  1512. dev_dbg(tx_priv->dev,
  1513. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  1514. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  1515. tx_priv->va_clk_status);
  1516. done:
  1517. mutex_unlock(&tx_priv->swr_clk_lock);
  1518. return ret;
  1519. }
  1520. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1521. struct tx_macro_priv *tx_priv)
  1522. {
  1523. u32 div_factor = TX_MACRO_CLK_DIV_2;
  1524. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  1525. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1526. mclk_rate % dmic_sample_rate != 0)
  1527. goto undefined_rate;
  1528. div_factor = mclk_rate / dmic_sample_rate;
  1529. switch (div_factor) {
  1530. case 2:
  1531. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1532. break;
  1533. case 3:
  1534. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  1535. break;
  1536. case 4:
  1537. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  1538. break;
  1539. case 6:
  1540. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  1541. break;
  1542. case 8:
  1543. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  1544. break;
  1545. case 16:
  1546. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  1547. break;
  1548. default:
  1549. /* Any other DIV factor is invalid */
  1550. goto undefined_rate;
  1551. }
  1552. /* Valid dmic DIV factors */
  1553. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1554. __func__, div_factor, mclk_rate);
  1555. return dmic_sample_rate;
  1556. undefined_rate:
  1557. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1558. __func__, dmic_sample_rate, mclk_rate);
  1559. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1560. return dmic_sample_rate;
  1561. }
  1562. static int tx_macro_init(struct snd_soc_component *component)
  1563. {
  1564. struct snd_soc_dapm_context *dapm =
  1565. snd_soc_component_get_dapm(component);
  1566. int ret = 0, i = 0;
  1567. struct device *tx_dev = NULL;
  1568. struct tx_macro_priv *tx_priv = NULL;
  1569. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  1570. if (!tx_dev) {
  1571. dev_err(component->dev,
  1572. "%s: null device for macro!\n", __func__);
  1573. return -EINVAL;
  1574. }
  1575. tx_priv = dev_get_drvdata(tx_dev);
  1576. if (!tx_priv) {
  1577. dev_err(component->dev,
  1578. "%s: priv is null for macro!\n", __func__);
  1579. return -EINVAL;
  1580. }
  1581. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  1582. ARRAY_SIZE(tx_macro_dapm_widgets));
  1583. if (ret < 0) {
  1584. dev_err(tx_dev, "%s: Failed to add controls\n", __func__);
  1585. return ret;
  1586. }
  1587. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  1588. ARRAY_SIZE(tx_audio_map));
  1589. if (ret < 0) {
  1590. dev_err(tx_dev, "%s: Failed to add routes\n", __func__);
  1591. return ret;
  1592. }
  1593. ret = snd_soc_dapm_new_widgets(dapm->card);
  1594. if (ret < 0) {
  1595. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  1596. return ret;
  1597. }
  1598. ret = snd_soc_add_component_controls(component, tx_macro_snd_controls,
  1599. ARRAY_SIZE(tx_macro_snd_controls));
  1600. if (ret < 0) {
  1601. dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__);
  1602. return ret;
  1603. }
  1604. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  1605. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  1606. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  1607. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  1608. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  1609. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  1610. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
  1611. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
  1612. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
  1613. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
  1614. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
  1615. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
  1616. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
  1617. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
  1618. snd_soc_dapm_sync(dapm);
  1619. for (i = 0; i < NUM_DECIMATORS; i++) {
  1620. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  1621. tx_priv->tx_hpf_work[i].decimator = i;
  1622. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  1623. tx_macro_tx_hpf_corner_freq_callback);
  1624. }
  1625. for (i = 0; i < NUM_DECIMATORS; i++) {
  1626. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  1627. tx_priv->tx_mute_dwork[i].decimator = i;
  1628. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  1629. tx_macro_mute_update_callback);
  1630. }
  1631. tx_priv->component = component;
  1632. return 0;
  1633. }
  1634. static int tx_macro_deinit(struct snd_soc_component *component)
  1635. {
  1636. struct device *tx_dev = NULL;
  1637. struct tx_macro_priv *tx_priv = NULL;
  1638. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1639. return -EINVAL;
  1640. tx_priv->component = NULL;
  1641. return 0;
  1642. }
  1643. static void tx_macro_add_child_devices(struct work_struct *work)
  1644. {
  1645. struct tx_macro_priv *tx_priv = NULL;
  1646. struct platform_device *pdev = NULL;
  1647. struct device_node *node = NULL;
  1648. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  1649. int ret = 0;
  1650. u16 count = 0, ctrl_num = 0;
  1651. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  1652. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  1653. bool tx_swr_master_node = false;
  1654. tx_priv = container_of(work, struct tx_macro_priv,
  1655. tx_macro_add_child_devices_work);
  1656. if (!tx_priv) {
  1657. pr_err("%s: Memory for tx_priv does not exist\n",
  1658. __func__);
  1659. return;
  1660. }
  1661. if (!tx_priv->dev) {
  1662. pr_err("%s: tx dev does not exist\n", __func__);
  1663. return;
  1664. }
  1665. if (!tx_priv->dev->of_node) {
  1666. dev_err(tx_priv->dev,
  1667. "%s: DT node for tx_priv does not exist\n", __func__);
  1668. return;
  1669. }
  1670. platdata = &tx_priv->swr_plat_data;
  1671. tx_priv->child_count = 0;
  1672. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  1673. tx_swr_master_node = false;
  1674. if (strnstr(node->name, "tx_swr_master",
  1675. strlen("tx_swr_master")) != NULL)
  1676. tx_swr_master_node = true;
  1677. if (tx_swr_master_node)
  1678. strlcpy(plat_dev_name, "tx_swr_ctrl",
  1679. (TX_MACRO_SWR_STRING_LEN - 1));
  1680. else
  1681. strlcpy(plat_dev_name, node->name,
  1682. (TX_MACRO_SWR_STRING_LEN - 1));
  1683. pdev = platform_device_alloc(plat_dev_name, -1);
  1684. if (!pdev) {
  1685. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  1686. __func__);
  1687. ret = -ENOMEM;
  1688. goto err;
  1689. }
  1690. pdev->dev.parent = tx_priv->dev;
  1691. pdev->dev.of_node = node;
  1692. if (tx_swr_master_node) {
  1693. ret = platform_device_add_data(pdev, platdata,
  1694. sizeof(*platdata));
  1695. if (ret) {
  1696. dev_err(&pdev->dev,
  1697. "%s: cannot add plat data ctrl:%d\n",
  1698. __func__, ctrl_num);
  1699. goto fail_pdev_add;
  1700. }
  1701. }
  1702. ret = platform_device_add(pdev);
  1703. if (ret) {
  1704. dev_err(&pdev->dev,
  1705. "%s: Cannot add platform device\n",
  1706. __func__);
  1707. goto fail_pdev_add;
  1708. }
  1709. if (tx_swr_master_node) {
  1710. temp = krealloc(swr_ctrl_data,
  1711. (ctrl_num + 1) * sizeof(
  1712. struct tx_macro_swr_ctrl_data),
  1713. GFP_KERNEL);
  1714. if (!temp) {
  1715. ret = -ENOMEM;
  1716. goto fail_pdev_add;
  1717. }
  1718. swr_ctrl_data = temp;
  1719. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  1720. ctrl_num++;
  1721. dev_dbg(&pdev->dev,
  1722. "%s: Added soundwire ctrl device(s)\n",
  1723. __func__);
  1724. tx_priv->swr_ctrl_data = swr_ctrl_data;
  1725. }
  1726. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  1727. tx_priv->pdev_child_devices[
  1728. tx_priv->child_count++] = pdev;
  1729. else
  1730. goto err;
  1731. }
  1732. return;
  1733. fail_pdev_add:
  1734. for (count = 0; count < tx_priv->child_count; count++)
  1735. platform_device_put(tx_priv->pdev_child_devices[count]);
  1736. err:
  1737. return;
  1738. }
  1739. static int tx_macro_set_port_map(struct snd_soc_component *component,
  1740. u32 usecase, u32 size, void *data)
  1741. {
  1742. struct device *tx_dev = NULL;
  1743. struct tx_macro_priv *tx_priv = NULL;
  1744. struct swrm_port_config port_cfg;
  1745. int ret = 0;
  1746. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1747. return -EINVAL;
  1748. memset(&port_cfg, 0, sizeof(port_cfg));
  1749. port_cfg.uc = usecase;
  1750. port_cfg.size = size;
  1751. port_cfg.params = data;
  1752. if (tx_priv->swr_ctrl_data)
  1753. ret = swrm_wcd_notify(
  1754. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  1755. SWR_SET_PORT_MAP, &port_cfg);
  1756. return ret;
  1757. }
  1758. static void tx_macro_init_ops(struct macro_ops *ops,
  1759. char __iomem *tx_io_base)
  1760. {
  1761. memset(ops, 0, sizeof(struct macro_ops));
  1762. ops->init = tx_macro_init;
  1763. ops->exit = tx_macro_deinit;
  1764. ops->io_base = tx_io_base;
  1765. ops->dai_ptr = tx_macro_dai;
  1766. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  1767. ops->event_handler = tx_macro_event_handler;
  1768. ops->reg_wake_irq = tx_macro_reg_wake_irq;
  1769. ops->set_port_map = tx_macro_set_port_map;
  1770. }
  1771. static int tx_macro_probe(struct platform_device *pdev)
  1772. {
  1773. struct macro_ops ops = {0};
  1774. struct tx_macro_priv *tx_priv = NULL;
  1775. u32 tx_base_addr = 0, sample_rate = 0;
  1776. char __iomem *tx_io_base = NULL;
  1777. int ret = 0;
  1778. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  1779. u32 is_used_tx_swr_gpio = 1;
  1780. const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  1781. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  1782. GFP_KERNEL);
  1783. if (!tx_priv)
  1784. return -ENOMEM;
  1785. platform_set_drvdata(pdev, tx_priv);
  1786. tx_priv->dev = &pdev->dev;
  1787. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1788. &tx_base_addr);
  1789. if (ret) {
  1790. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1791. __func__, "reg");
  1792. return ret;
  1793. }
  1794. dev_set_drvdata(&pdev->dev, tx_priv);
  1795. if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
  1796. NULL)) {
  1797. ret = of_property_read_u32(pdev->dev.of_node,
  1798. is_used_tx_swr_gpio_dt,
  1799. &is_used_tx_swr_gpio);
  1800. if (ret) {
  1801. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  1802. __func__, is_used_tx_swr_gpio_dt);
  1803. is_used_tx_swr_gpio = 1;
  1804. }
  1805. }
  1806. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1807. "qcom,tx-swr-gpios", 0);
  1808. if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
  1809. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  1810. __func__);
  1811. return -EINVAL;
  1812. }
  1813. if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0) {
  1814. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  1815. __func__);
  1816. return -EPROBE_DEFER;
  1817. }
  1818. tx_io_base = devm_ioremap(&pdev->dev,
  1819. tx_base_addr, TX_MACRO_MAX_OFFSET);
  1820. if (!tx_io_base) {
  1821. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1822. return -ENOMEM;
  1823. }
  1824. tx_priv->tx_io_base = tx_io_base;
  1825. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1826. &sample_rate);
  1827. if (ret) {
  1828. dev_err(&pdev->dev,
  1829. "%s: could not find sample_rate entry in dt\n",
  1830. __func__);
  1831. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1832. } else {
  1833. if (tx_macro_validate_dmic_sample_rate(
  1834. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1835. return -EINVAL;
  1836. }
  1837. tx_priv->reset_swr = true;
  1838. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  1839. tx_macro_add_child_devices);
  1840. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  1841. tx_priv->swr_plat_data.read = NULL;
  1842. tx_priv->swr_plat_data.write = NULL;
  1843. tx_priv->swr_plat_data.bulk_write = NULL;
  1844. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  1845. tx_priv->swr_plat_data.handle_irq = NULL;
  1846. mutex_init(&tx_priv->mclk_lock);
  1847. mutex_init(&tx_priv->swr_clk_lock);
  1848. tx_macro_init_ops(&ops, tx_io_base);
  1849. ops.clk_id_req = TX_CORE_CLK;
  1850. ops.default_clk_id = TX_CORE_CLK;
  1851. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  1852. if (ret) {
  1853. dev_err(&pdev->dev,
  1854. "%s: register macro failed\n", __func__);
  1855. goto err_reg_macro;
  1856. }
  1857. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  1858. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  1859. pm_runtime_use_autosuspend(&pdev->dev);
  1860. pm_runtime_set_suspended(&pdev->dev);
  1861. pm_suspend_ignore_children(&pdev->dev, true);
  1862. pm_runtime_enable(&pdev->dev);
  1863. return 0;
  1864. err_reg_macro:
  1865. mutex_destroy(&tx_priv->mclk_lock);
  1866. mutex_destroy(&tx_priv->swr_clk_lock);
  1867. return ret;
  1868. }
  1869. static int tx_macro_remove(struct platform_device *pdev)
  1870. {
  1871. struct tx_macro_priv *tx_priv = NULL;
  1872. u16 count = 0;
  1873. tx_priv = platform_get_drvdata(pdev);
  1874. if (!tx_priv)
  1875. return -EINVAL;
  1876. if (tx_priv->swr_ctrl_data)
  1877. kfree(tx_priv->swr_ctrl_data);
  1878. for (count = 0; count < tx_priv->child_count &&
  1879. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  1880. platform_device_unregister(tx_priv->pdev_child_devices[count]);
  1881. pm_runtime_disable(&pdev->dev);
  1882. pm_runtime_set_suspended(&pdev->dev);
  1883. mutex_destroy(&tx_priv->mclk_lock);
  1884. mutex_destroy(&tx_priv->swr_clk_lock);
  1885. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  1886. return 0;
  1887. }
  1888. static const struct of_device_id tx_macro_dt_match[] = {
  1889. {.compatible = "qcom,tx-macro"},
  1890. {}
  1891. };
  1892. static const struct dev_pm_ops bolero_dev_pm_ops = {
  1893. SET_RUNTIME_PM_OPS(
  1894. bolero_runtime_suspend,
  1895. bolero_runtime_resume,
  1896. NULL
  1897. )
  1898. };
  1899. static struct platform_driver tx_macro_driver = {
  1900. .driver = {
  1901. .name = "tx_macro",
  1902. .owner = THIS_MODULE,
  1903. .pm = &bolero_dev_pm_ops,
  1904. .of_match_table = tx_macro_dt_match,
  1905. .suppress_bind_attrs = true,
  1906. },
  1907. .probe = tx_macro_probe,
  1908. .remove = tx_macro_remove,
  1909. };
  1910. module_platform_driver(tx_macro_driver);
  1911. MODULE_DESCRIPTION("TX macro driver");
  1912. MODULE_LICENSE("GPL v2");