tx-macro.c 62 KB

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