tx-macro.c 61 KB

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