tx-macro.c 54 KB

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