tx-macro.c 63 KB

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