tx-macro.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  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, 0x02, 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, 0x02, 0x00);
  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, hpf_gate_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. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  353. TX_MACRO_TX_PATH_OFFSET * decimator;
  354. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x01);
  355. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  356. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  357. __func__, decimator);
  358. }
  359. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  360. struct snd_ctl_elem_value *ucontrol)
  361. {
  362. struct snd_soc_dapm_widget *widget =
  363. snd_soc_dapm_kcontrol_widget(kcontrol);
  364. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  365. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  366. unsigned int val = 0;
  367. u16 mic_sel_reg = 0;
  368. val = ucontrol->value.enumerated.item[0];
  369. if (val > e->items - 1)
  370. return -EINVAL;
  371. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  372. widget->name, val);
  373. switch (e->reg) {
  374. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  375. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  376. break;
  377. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  378. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  379. break;
  380. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  381. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  382. break;
  383. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  384. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  385. break;
  386. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  387. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  388. break;
  389. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  390. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  391. break;
  392. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  393. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  394. break;
  395. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  396. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  397. break;
  398. default:
  399. dev_err(codec->dev, "%s: e->reg: 0x%x not expected\n",
  400. __func__, e->reg);
  401. return -EINVAL;
  402. }
  403. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  404. if (val != 0) {
  405. if (val < 5)
  406. snd_soc_update_bits(codec, mic_sel_reg,
  407. 1 << 7, 0x0 << 7);
  408. else
  409. snd_soc_update_bits(codec, mic_sel_reg,
  410. 1 << 7, 0x1 << 7);
  411. }
  412. } else {
  413. /* DMIC selected */
  414. if (val != 0)
  415. snd_soc_update_bits(codec, mic_sel_reg, 1 << 7, 1 << 7);
  416. }
  417. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  418. }
  419. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  420. struct snd_ctl_elem_value *ucontrol)
  421. {
  422. struct snd_soc_dapm_widget *widget =
  423. snd_soc_dapm_kcontrol_widget(kcontrol);
  424. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  425. struct soc_multi_mixer_control *mixer =
  426. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  427. u32 dai_id = widget->shift;
  428. u32 dec_id = mixer->shift;
  429. struct device *tx_dev = NULL;
  430. struct tx_macro_priv *tx_priv = NULL;
  431. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  432. return -EINVAL;
  433. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  434. ucontrol->value.integer.value[0] = 1;
  435. else
  436. ucontrol->value.integer.value[0] = 0;
  437. return 0;
  438. }
  439. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  440. struct snd_ctl_elem_value *ucontrol)
  441. {
  442. struct snd_soc_dapm_widget *widget =
  443. snd_soc_dapm_kcontrol_widget(kcontrol);
  444. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  445. struct snd_soc_dapm_update *update = NULL;
  446. struct soc_multi_mixer_control *mixer =
  447. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  448. u32 dai_id = widget->shift;
  449. u32 dec_id = mixer->shift;
  450. u32 enable = ucontrol->value.integer.value[0];
  451. struct device *tx_dev = NULL;
  452. struct tx_macro_priv *tx_priv = NULL;
  453. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  454. return -EINVAL;
  455. if (enable) {
  456. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  457. tx_priv->active_ch_cnt[dai_id]++;
  458. } else {
  459. tx_priv->active_ch_cnt[dai_id]--;
  460. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  461. }
  462. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  463. return 0;
  464. }
  465. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  466. struct snd_kcontrol *kcontrol, int event)
  467. {
  468. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  469. u8 dmic_clk_en = 0x01;
  470. u16 dmic_clk_reg = 0;
  471. s32 *dmic_clk_cnt = NULL;
  472. unsigned int dmic = 0;
  473. int ret = 0;
  474. char *wname = NULL;
  475. struct device *tx_dev = NULL;
  476. struct tx_macro_priv *tx_priv = NULL;
  477. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  478. return -EINVAL;
  479. wname = strpbrk(w->name, "01234567");
  480. if (!wname) {
  481. dev_err(codec->dev, "%s: widget not found\n", __func__);
  482. return -EINVAL;
  483. }
  484. ret = kstrtouint(wname, 10, &dmic);
  485. if (ret < 0) {
  486. dev_err(codec->dev, "%s: Invalid DMIC line on the codec\n",
  487. __func__);
  488. return -EINVAL;
  489. }
  490. switch (dmic) {
  491. case 0:
  492. case 1:
  493. dmic_clk_cnt = &(tx_priv->dmic_0_1_clk_cnt);
  494. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC0_CTL;
  495. break;
  496. case 2:
  497. case 3:
  498. dmic_clk_cnt = &(tx_priv->dmic_2_3_clk_cnt);
  499. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC1_CTL;
  500. break;
  501. case 4:
  502. case 5:
  503. dmic_clk_cnt = &(tx_priv->dmic_4_5_clk_cnt);
  504. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC2_CTL;
  505. break;
  506. case 6:
  507. case 7:
  508. dmic_clk_cnt = &(tx_priv->dmic_6_7_clk_cnt);
  509. dmic_clk_reg = BOLERO_CDC_VA_TOP_CSR_DMIC3_CTL;
  510. break;
  511. default:
  512. dev_err(codec->dev, "%s: Invalid DMIC Selection\n",
  513. __func__);
  514. return -EINVAL;
  515. }
  516. dev_dbg(codec->dev, "%s: event %d DMIC%d dmic_clk_cnt %d\n",
  517. __func__, event, dmic, *dmic_clk_cnt);
  518. switch (event) {
  519. case SND_SOC_DAPM_PRE_PMU:
  520. (*dmic_clk_cnt)++;
  521. if (*dmic_clk_cnt == 1) {
  522. snd_soc_update_bits(codec, BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  523. 0x80, 0x00);
  524. snd_soc_update_bits(codec, dmic_clk_reg,
  525. 0x0E, tx_priv->dmic_clk_div << 0x1);
  526. snd_soc_update_bits(codec, dmic_clk_reg,
  527. dmic_clk_en, dmic_clk_en);
  528. }
  529. break;
  530. case SND_SOC_DAPM_POST_PMD:
  531. (*dmic_clk_cnt)--;
  532. if (*dmic_clk_cnt == 0)
  533. snd_soc_update_bits(codec, dmic_clk_reg,
  534. dmic_clk_en, 0);
  535. break;
  536. }
  537. return 0;
  538. }
  539. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  540. struct snd_kcontrol *kcontrol, int event)
  541. {
  542. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  543. unsigned int decimator = 0;
  544. u16 tx_vol_ctl_reg = 0;
  545. u16 dec_cfg_reg = 0;
  546. u16 hpf_gate_reg = 0;
  547. u16 tx_gain_ctl_reg = 0;
  548. u8 hpf_cut_off_freq = 0;
  549. struct device *tx_dev = NULL;
  550. struct tx_macro_priv *tx_priv = NULL;
  551. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  552. return -EINVAL;
  553. decimator = w->shift;
  554. dev_dbg(codec->dev, "%s(): widget = %s decimator = %u\n", __func__,
  555. w->name, decimator);
  556. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  557. TX_MACRO_TX_PATH_OFFSET * decimator;
  558. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  559. TX_MACRO_TX_PATH_OFFSET * decimator;
  560. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  561. TX_MACRO_TX_PATH_OFFSET * decimator;
  562. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  563. TX_MACRO_TX_PATH_OFFSET * decimator;
  564. switch (event) {
  565. case SND_SOC_DAPM_PRE_PMU:
  566. /* Enable TX PGA Mute */
  567. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  568. break;
  569. case SND_SOC_DAPM_POST_PMU:
  570. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x20);
  571. snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x00);
  572. hpf_cut_off_freq = (snd_soc_read(codec, dec_cfg_reg) &
  573. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  574. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  575. hpf_cut_off_freq;
  576. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  577. snd_soc_update_bits(codec, dec_cfg_reg,
  578. TX_HPF_CUT_OFF_FREQ_MASK,
  579. CF_MIN_3DB_150HZ << 5);
  580. /* schedule work queue to Remove Mute */
  581. schedule_delayed_work(&tx_priv->tx_mute_dwork[decimator].dwork,
  582. msecs_to_jiffies(tx_unmute_delay));
  583. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  584. CF_MIN_3DB_150HZ) {
  585. schedule_delayed_work(
  586. &tx_priv->tx_hpf_work[decimator].dwork,
  587. msecs_to_jiffies(300));
  588. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x02);
  589. /*
  590. * Minimum 1 clk cycle delay is required as per HW spec
  591. */
  592. usleep_range(1000, 1010);
  593. snd_soc_update_bits(codec, hpf_gate_reg, 0x02, 0x00);
  594. }
  595. /* apply gain after decimator is enabled */
  596. snd_soc_write(codec, tx_gain_ctl_reg,
  597. snd_soc_read(codec, tx_gain_ctl_reg));
  598. break;
  599. case SND_SOC_DAPM_PRE_PMD:
  600. hpf_cut_off_freq =
  601. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  602. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x10);
  603. if (cancel_delayed_work_sync(
  604. &tx_priv->tx_hpf_work[decimator].dwork)) {
  605. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  606. snd_soc_update_bits(codec, dec_cfg_reg,
  607. TX_HPF_CUT_OFF_FREQ_MASK,
  608. hpf_cut_off_freq << 5);
  609. snd_soc_update_bits(codec, hpf_gate_reg,
  610. 0x02, 0x02);
  611. /*
  612. * Minimum 1 clk cycle delay is required
  613. * as per HW spec
  614. */
  615. usleep_range(1000, 1010);
  616. snd_soc_update_bits(codec, hpf_gate_reg,
  617. 0x02, 0x00);
  618. }
  619. }
  620. cancel_delayed_work_sync(
  621. &tx_priv->tx_mute_dwork[decimator].dwork);
  622. break;
  623. case SND_SOC_DAPM_POST_PMD:
  624. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x20, 0x00);
  625. snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x10, 0x00);
  626. break;
  627. }
  628. return 0;
  629. }
  630. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  631. struct snd_kcontrol *kcontrol, int event)
  632. {
  633. return 0;
  634. }
  635. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  636. struct snd_pcm_hw_params *params,
  637. struct snd_soc_dai *dai)
  638. {
  639. int tx_fs_rate = -EINVAL;
  640. struct snd_soc_codec *codec = dai->codec;
  641. u32 decimator = 0;
  642. u32 sample_rate = 0;
  643. u16 tx_fs_reg = 0;
  644. struct device *tx_dev = NULL;
  645. struct tx_macro_priv *tx_priv = NULL;
  646. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  647. return -EINVAL;
  648. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  649. dai->name, dai->id, params_rate(params),
  650. params_channels(params));
  651. sample_rate = params_rate(params);
  652. switch (sample_rate) {
  653. case 8000:
  654. tx_fs_rate = 0;
  655. break;
  656. case 16000:
  657. tx_fs_rate = 1;
  658. break;
  659. case 32000:
  660. tx_fs_rate = 3;
  661. break;
  662. case 48000:
  663. tx_fs_rate = 4;
  664. break;
  665. case 96000:
  666. tx_fs_rate = 5;
  667. break;
  668. case 192000:
  669. tx_fs_rate = 6;
  670. break;
  671. case 384000:
  672. tx_fs_rate = 7;
  673. break;
  674. default:
  675. dev_err(codec->dev, "%s: Invalid TX sample rate: %d\n",
  676. __func__, params_rate(params));
  677. return -EINVAL;
  678. }
  679. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  680. TX_MACRO_DEC_MAX) {
  681. if (decimator >= 0) {
  682. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  683. TX_MACRO_TX_PATH_OFFSET * decimator;
  684. dev_dbg(codec->dev, "%s: set DEC%u rate to %u\n",
  685. __func__, decimator, sample_rate);
  686. snd_soc_update_bits(codec, tx_fs_reg, 0x0F,
  687. tx_fs_rate);
  688. } else {
  689. dev_err(codec->dev,
  690. "%s: ERROR: Invalid decimator: %d\n",
  691. __func__, decimator);
  692. return -EINVAL;
  693. }
  694. }
  695. return 0;
  696. }
  697. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  698. unsigned int *tx_num, unsigned int *tx_slot,
  699. unsigned int *rx_num, unsigned int *rx_slot)
  700. {
  701. struct snd_soc_codec *codec = dai->codec;
  702. struct device *tx_dev = NULL;
  703. struct tx_macro_priv *tx_priv = NULL;
  704. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  705. return -EINVAL;
  706. switch (dai->id) {
  707. case TX_MACRO_AIF1_CAP:
  708. case TX_MACRO_AIF2_CAP:
  709. *tx_slot = tx_priv->active_ch_mask[dai->id];
  710. *tx_num = tx_priv->active_ch_cnt[dai->id];
  711. break;
  712. default:
  713. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  714. break;
  715. }
  716. return 0;
  717. }
  718. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  719. .hw_params = tx_macro_hw_params,
  720. .get_channel_map = tx_macro_get_channel_map,
  721. };
  722. static struct snd_soc_dai_driver tx_macro_dai[] = {
  723. {
  724. .name = "tx_macro_tx1",
  725. .id = TX_MACRO_AIF1_CAP,
  726. .capture = {
  727. .stream_name = "TX_AIF1 Capture",
  728. .rates = TX_MACRO_RATES,
  729. .formats = TX_MACRO_FORMATS,
  730. .rate_max = 192000,
  731. .rate_min = 8000,
  732. .channels_min = 1,
  733. .channels_max = 8,
  734. },
  735. .ops = &tx_macro_dai_ops,
  736. },
  737. {
  738. .name = "tx_macro_tx2",
  739. .id = TX_MACRO_AIF2_CAP,
  740. .capture = {
  741. .stream_name = "TX_AIF2 Capture",
  742. .rates = TX_MACRO_RATES,
  743. .formats = TX_MACRO_FORMATS,
  744. .rate_max = 192000,
  745. .rate_min = 8000,
  746. .channels_min = 1,
  747. .channels_max = 8,
  748. },
  749. .ops = &tx_macro_dai_ops,
  750. },
  751. };
  752. #define STRING(name) #name
  753. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  754. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  755. static const struct snd_kcontrol_new name##_mux = \
  756. SOC_DAPM_ENUM(STRING(name), name##_enum)
  757. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  758. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  759. static const struct snd_kcontrol_new name##_mux = \
  760. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  761. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  762. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  763. static const char * const adc_mux_text[] = {
  764. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  765. };
  766. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  767. 0, adc_mux_text);
  768. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  769. 0, adc_mux_text);
  770. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  771. 0, adc_mux_text);
  772. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  773. 0, adc_mux_text);
  774. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  775. 0, adc_mux_text);
  776. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  777. 0, adc_mux_text);
  778. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  779. 0, adc_mux_text);
  780. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  781. 0, adc_mux_text);
  782. static const char * const dmic_mux_text[] = {
  783. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  784. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  785. };
  786. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_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_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_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_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_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_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_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_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_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_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_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_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  805. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  806. tx_macro_put_dec_enum);
  807. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  808. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  809. tx_macro_put_dec_enum);
  810. static const char * const smic_mux_text[] = {
  811. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3",
  812. "SWR_DMIC0", "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3",
  813. "SWR_DMIC4", "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  814. };
  815. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_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_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_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_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_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_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_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_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_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_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_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_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  834. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  835. tx_macro_put_dec_enum);
  836. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  837. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  838. tx_macro_put_dec_enum);
  839. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  840. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  841. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  842. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  843. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  844. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  845. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  846. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  847. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  848. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  849. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  850. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  851. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  852. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  853. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  854. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  855. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  856. };
  857. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  858. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  859. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  860. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  861. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  862. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  863. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  864. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  865. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  866. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  867. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  868. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  869. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  870. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  871. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  872. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  873. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  874. };
  875. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  876. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  877. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  878. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  879. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  880. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  881. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  882. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  883. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  884. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  885. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  886. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  887. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  888. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  889. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  890. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  891. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  892. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  893. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  894. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  895. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  896. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  897. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  898. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  899. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  900. SND_SOC_DAPM_MICBIAS_E("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  901. tx_macro_enable_micbias,
  902. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  903. SND_SOC_DAPM_ADC_E("TX DMIC0", 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 DMIC1", 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 DMIC2", 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 DMIC3", 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 DMIC4", 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 DMIC5", 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 DMIC6", 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_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  925. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  926. SND_SOC_DAPM_POST_PMD),
  927. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  928. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  929. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  930. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  931. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  932. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  933. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  934. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  935. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  936. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  937. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  938. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  939. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  940. TX_MACRO_DEC0, 0,
  941. &tx_dec0_mux, tx_macro_enable_dec,
  942. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  943. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  944. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  945. TX_MACRO_DEC1, 0,
  946. &tx_dec1_mux, tx_macro_enable_dec,
  947. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  948. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  949. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  950. TX_MACRO_DEC2, 0,
  951. &tx_dec2_mux, tx_macro_enable_dec,
  952. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  953. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  954. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  955. TX_MACRO_DEC3, 0,
  956. &tx_dec3_mux, tx_macro_enable_dec,
  957. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  958. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  959. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  960. TX_MACRO_DEC4, 0,
  961. &tx_dec4_mux, tx_macro_enable_dec,
  962. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  963. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  964. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  965. TX_MACRO_DEC5, 0,
  966. &tx_dec5_mux, tx_macro_enable_dec,
  967. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  968. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  969. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  970. TX_MACRO_DEC6, 0,
  971. &tx_dec6_mux, tx_macro_enable_dec,
  972. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  973. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  974. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  975. TX_MACRO_DEC7, 0,
  976. &tx_dec7_mux, tx_macro_enable_dec,
  977. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  978. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  979. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  980. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  981. };
  982. static const struct snd_soc_dapm_route tx_audio_map[] = {
  983. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  984. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  985. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  986. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  987. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  988. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  989. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  990. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  991. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  992. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  993. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  994. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  995. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  996. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  997. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  998. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  999. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1000. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1001. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1002. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1003. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1004. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1005. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1006. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1007. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1008. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1009. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1010. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1011. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1012. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1013. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1014. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1015. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1016. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1017. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1018. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1019. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1020. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1021. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  1022. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  1023. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  1024. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  1025. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  1026. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  1027. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  1028. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  1029. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  1030. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  1031. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  1032. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  1033. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1034. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1035. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1036. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1037. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1038. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1039. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1040. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1041. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1042. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1043. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  1044. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  1045. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  1046. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  1047. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  1048. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  1049. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  1050. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  1051. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  1052. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  1053. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  1054. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  1055. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1056. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1057. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1058. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1059. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1060. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1061. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1062. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1063. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1064. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1065. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  1066. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  1067. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  1068. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  1069. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  1070. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  1071. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  1072. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  1073. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  1074. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  1075. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  1076. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  1077. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1078. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1079. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1080. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1081. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1082. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1083. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1084. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1085. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1086. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1087. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  1088. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  1089. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  1090. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  1091. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  1092. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  1093. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  1094. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  1095. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  1096. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  1097. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  1098. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  1099. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1100. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1101. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1102. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1103. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1104. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1105. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1106. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1107. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1108. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1109. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  1110. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  1111. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  1112. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  1113. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  1114. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  1115. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  1116. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  1117. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  1118. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  1119. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  1120. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  1121. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1122. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1123. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1124. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1125. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1126. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1127. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1128. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1129. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1130. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1131. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  1132. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  1133. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  1134. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  1135. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  1136. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  1137. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  1138. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  1139. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  1140. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  1141. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  1142. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  1143. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1144. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1145. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1146. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1147. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1148. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1149. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1150. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1151. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1152. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1153. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  1154. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  1155. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  1156. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  1157. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  1158. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  1159. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  1160. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  1161. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  1162. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  1163. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  1164. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  1165. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1166. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1167. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1168. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1169. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1170. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1171. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1172. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1173. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1174. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1175. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  1176. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  1177. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  1178. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  1179. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  1180. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  1181. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  1182. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  1183. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  1184. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  1185. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  1186. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  1187. };
  1188. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  1189. SOC_SINGLE_SX_TLV("TX_DEC0 Volume",
  1190. BOLERO_CDC_TX0_TX_VOL_CTL,
  1191. 0, -84, 40, digital_gain),
  1192. SOC_SINGLE_SX_TLV("TX_DEC1 Volume",
  1193. BOLERO_CDC_TX1_TX_VOL_CTL,
  1194. 0, -84, 40, digital_gain),
  1195. SOC_SINGLE_SX_TLV("TX_DEC2 Volume",
  1196. BOLERO_CDC_TX2_TX_VOL_CTL,
  1197. 0, -84, 40, digital_gain),
  1198. SOC_SINGLE_SX_TLV("TX_DEC3 Volume",
  1199. BOLERO_CDC_TX3_TX_VOL_CTL,
  1200. 0, -84, 40, digital_gain),
  1201. SOC_SINGLE_SX_TLV("TX_DEC4 Volume",
  1202. BOLERO_CDC_TX4_TX_VOL_CTL,
  1203. 0, -84, 40, digital_gain),
  1204. SOC_SINGLE_SX_TLV("TX_DEC5 Volume",
  1205. BOLERO_CDC_TX5_TX_VOL_CTL,
  1206. 0, -84, 40, digital_gain),
  1207. SOC_SINGLE_SX_TLV("TX_DEC6 Volume",
  1208. BOLERO_CDC_TX6_TX_VOL_CTL,
  1209. 0, -84, 40, digital_gain),
  1210. SOC_SINGLE_SX_TLV("TX_DEC7 Volume",
  1211. BOLERO_CDC_TX7_TX_VOL_CTL,
  1212. 0, -84, 40, digital_gain),
  1213. };
  1214. static int tx_macro_swrm_clock(void *handle, bool enable)
  1215. {
  1216. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  1217. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  1218. int ret = 0;
  1219. if (regmap == NULL) {
  1220. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  1221. return -EINVAL;
  1222. }
  1223. mutex_lock(&tx_priv->swr_clk_lock);
  1224. dev_dbg(tx_priv->dev, "%s: swrm clock %s\n",
  1225. __func__, (enable ? "enable" : "disable"));
  1226. if (enable) {
  1227. if (tx_priv->swr_clk_users == 0) {
  1228. ret = tx_macro_mclk_enable(tx_priv, 1);
  1229. if (ret < 0) {
  1230. dev_err(tx_priv->dev,
  1231. "%s: request clock enable failed\n",
  1232. __func__);
  1233. goto exit;
  1234. }
  1235. regmap_update_bits(regmap,
  1236. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1237. 0x01, 0x01);
  1238. regmap_update_bits(regmap,
  1239. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1240. 0x1C, 0x0C);
  1241. msm_cdc_pinctrl_select_active_state(
  1242. tx_priv->tx_swr_gpio_p);
  1243. }
  1244. tx_priv->swr_clk_users++;
  1245. } else {
  1246. if (tx_priv->swr_clk_users <= 0) {
  1247. dev_err(tx_priv->dev,
  1248. "tx swrm clock users already 0\n");
  1249. tx_priv->swr_clk_users = 0;
  1250. goto exit;
  1251. }
  1252. tx_priv->swr_clk_users--;
  1253. if (tx_priv->swr_clk_users == 0) {
  1254. regmap_update_bits(regmap,
  1255. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  1256. 0x01, 0x00);
  1257. msm_cdc_pinctrl_select_sleep_state(
  1258. tx_priv->tx_swr_gpio_p);
  1259. tx_macro_mclk_enable(tx_priv, 0);
  1260. }
  1261. }
  1262. dev_dbg(tx_priv->dev, "%s: swrm clock users %d\n",
  1263. __func__, tx_priv->swr_clk_users);
  1264. exit:
  1265. mutex_unlock(&tx_priv->swr_clk_lock);
  1266. return ret;
  1267. }
  1268. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  1269. struct tx_macro_priv *tx_priv)
  1270. {
  1271. u32 div_factor = TX_MACRO_CLK_DIV_2;
  1272. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  1273. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  1274. mclk_rate % dmic_sample_rate != 0)
  1275. goto undefined_rate;
  1276. div_factor = mclk_rate / dmic_sample_rate;
  1277. switch (div_factor) {
  1278. case 2:
  1279. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1280. break;
  1281. case 3:
  1282. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  1283. break;
  1284. case 4:
  1285. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  1286. break;
  1287. case 6:
  1288. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  1289. break;
  1290. case 8:
  1291. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  1292. break;
  1293. case 16:
  1294. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  1295. break;
  1296. default:
  1297. /* Any other DIV factor is invalid */
  1298. goto undefined_rate;
  1299. }
  1300. /* Valid dmic DIV factors */
  1301. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  1302. __func__, div_factor, mclk_rate);
  1303. return dmic_sample_rate;
  1304. undefined_rate:
  1305. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  1306. __func__, dmic_sample_rate, mclk_rate);
  1307. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  1308. return dmic_sample_rate;
  1309. }
  1310. static int tx_macro_init(struct snd_soc_codec *codec)
  1311. {
  1312. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1313. int ret = 0, i = 0;
  1314. struct device *tx_dev = NULL;
  1315. struct tx_macro_priv *tx_priv = NULL;
  1316. tx_dev = bolero_get_device_ptr(codec->dev, TX_MACRO);
  1317. if (!tx_dev) {
  1318. dev_err(codec->dev,
  1319. "%s: null device for macro!\n", __func__);
  1320. return -EINVAL;
  1321. }
  1322. tx_priv = dev_get_drvdata(tx_dev);
  1323. if (!tx_priv) {
  1324. dev_err(codec->dev,
  1325. "%s: priv is null for macro!\n", __func__);
  1326. return -EINVAL;
  1327. }
  1328. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  1329. ARRAY_SIZE(tx_macro_dapm_widgets));
  1330. if (ret < 0) {
  1331. dev_err(tx_dev, "%s: Failed to add controls\n", __func__);
  1332. return ret;
  1333. }
  1334. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  1335. ARRAY_SIZE(tx_audio_map));
  1336. if (ret < 0) {
  1337. dev_err(tx_dev, "%s: Failed to add routes\n", __func__);
  1338. return ret;
  1339. }
  1340. ret = snd_soc_dapm_new_widgets(dapm->card);
  1341. if (ret < 0) {
  1342. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  1343. return ret;
  1344. }
  1345. ret = snd_soc_add_codec_controls(codec, tx_macro_snd_controls,
  1346. ARRAY_SIZE(tx_macro_snd_controls));
  1347. if (ret < 0) {
  1348. dev_err(tx_dev, "%s: Failed to add snd_ctls\n", __func__);
  1349. return ret;
  1350. }
  1351. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  1352. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  1353. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  1354. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  1355. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  1356. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  1357. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC0");
  1358. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC1");
  1359. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC2");
  1360. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC3");
  1361. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC4");
  1362. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC5");
  1363. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC6");
  1364. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_MIC7");
  1365. snd_soc_dapm_sync(dapm);
  1366. for (i = 0; i < NUM_DECIMATORS; i++) {
  1367. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  1368. tx_priv->tx_hpf_work[i].decimator = i;
  1369. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  1370. tx_macro_tx_hpf_corner_freq_callback);
  1371. }
  1372. for (i = 0; i < NUM_DECIMATORS; i++) {
  1373. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  1374. tx_priv->tx_mute_dwork[i].decimator = i;
  1375. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  1376. tx_macro_mute_update_callback);
  1377. }
  1378. tx_priv->codec = codec;
  1379. return 0;
  1380. }
  1381. static int tx_macro_deinit(struct snd_soc_codec *codec)
  1382. {
  1383. struct device *tx_dev = NULL;
  1384. struct tx_macro_priv *tx_priv = NULL;
  1385. if (!tx_macro_get_data(codec, &tx_dev, &tx_priv, __func__))
  1386. return -EINVAL;
  1387. tx_priv->codec = NULL;
  1388. return 0;
  1389. }
  1390. static void tx_macro_add_child_devices(struct work_struct *work)
  1391. {
  1392. struct tx_macro_priv *tx_priv = NULL;
  1393. struct platform_device *pdev = NULL;
  1394. struct device_node *node = NULL;
  1395. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  1396. int ret = 0;
  1397. u16 count = 0, ctrl_num = 0;
  1398. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  1399. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  1400. bool tx_swr_master_node = false;
  1401. tx_priv = container_of(work, struct tx_macro_priv,
  1402. tx_macro_add_child_devices_work);
  1403. if (!tx_priv) {
  1404. pr_err("%s: Memory for tx_priv does not exist\n",
  1405. __func__);
  1406. return;
  1407. }
  1408. if (!tx_priv->dev) {
  1409. pr_err("%s: tx dev does not exist\n", __func__);
  1410. return;
  1411. }
  1412. if (!tx_priv->dev->of_node) {
  1413. dev_err(tx_priv->dev,
  1414. "%s: DT node for tx_priv does not exist\n", __func__);
  1415. return;
  1416. }
  1417. platdata = &tx_priv->swr_plat_data;
  1418. tx_priv->child_count = 0;
  1419. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  1420. tx_swr_master_node = false;
  1421. if (strnstr(node->name, "tx_swr_master",
  1422. strlen("tx_swr_master")) != NULL)
  1423. tx_swr_master_node = true;
  1424. if (tx_swr_master_node)
  1425. strlcpy(plat_dev_name, "tx_swr_ctrl",
  1426. (TX_MACRO_SWR_STRING_LEN - 1));
  1427. else
  1428. strlcpy(plat_dev_name, node->name,
  1429. (TX_MACRO_SWR_STRING_LEN - 1));
  1430. pdev = platform_device_alloc(plat_dev_name, -1);
  1431. if (!pdev) {
  1432. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  1433. __func__);
  1434. ret = -ENOMEM;
  1435. goto err;
  1436. }
  1437. pdev->dev.parent = tx_priv->dev;
  1438. pdev->dev.of_node = node;
  1439. if (tx_swr_master_node) {
  1440. ret = platform_device_add_data(pdev, platdata,
  1441. sizeof(*platdata));
  1442. if (ret) {
  1443. dev_err(&pdev->dev,
  1444. "%s: cannot add plat data ctrl:%d\n",
  1445. __func__, ctrl_num);
  1446. goto fail_pdev_add;
  1447. }
  1448. }
  1449. ret = platform_device_add(pdev);
  1450. if (ret) {
  1451. dev_err(&pdev->dev,
  1452. "%s: Cannot add platform device\n",
  1453. __func__);
  1454. goto fail_pdev_add;
  1455. }
  1456. if (tx_swr_master_node) {
  1457. temp = krealloc(swr_ctrl_data,
  1458. (ctrl_num + 1) * sizeof(
  1459. struct tx_macro_swr_ctrl_data),
  1460. GFP_KERNEL);
  1461. if (!temp) {
  1462. ret = -ENOMEM;
  1463. goto fail_pdev_add;
  1464. }
  1465. swr_ctrl_data = temp;
  1466. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  1467. ctrl_num++;
  1468. dev_dbg(&pdev->dev,
  1469. "%s: Added soundwire ctrl device(s)\n",
  1470. __func__);
  1471. tx_priv->swr_ctrl_data = swr_ctrl_data;
  1472. }
  1473. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  1474. tx_priv->pdev_child_devices[
  1475. tx_priv->child_count++] = pdev;
  1476. else
  1477. goto err;
  1478. }
  1479. return;
  1480. fail_pdev_add:
  1481. for (count = 0; count < tx_priv->child_count; count++)
  1482. platform_device_put(tx_priv->pdev_child_devices[count]);
  1483. err:
  1484. return;
  1485. }
  1486. static void tx_macro_init_ops(struct macro_ops *ops,
  1487. char __iomem *tx_io_base)
  1488. {
  1489. memset(ops, 0, sizeof(struct macro_ops));
  1490. ops->init = tx_macro_init;
  1491. ops->exit = tx_macro_deinit;
  1492. ops->io_base = tx_io_base;
  1493. ops->dai_ptr = tx_macro_dai;
  1494. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  1495. ops->mclk_fn = tx_macro_mclk_ctrl;
  1496. ops->event_handler = tx_macro_event_handler;
  1497. }
  1498. static int tx_macro_probe(struct platform_device *pdev)
  1499. {
  1500. struct macro_ops ops = {0};
  1501. struct tx_macro_priv *tx_priv = NULL;
  1502. u32 tx_base_addr = 0, sample_rate = 0;
  1503. char __iomem *tx_io_base = NULL;
  1504. struct clk *tx_core_clk = NULL, *tx_npl_clk = NULL;
  1505. int ret = 0;
  1506. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  1507. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  1508. GFP_KERNEL);
  1509. if (!tx_priv)
  1510. return -ENOMEM;
  1511. platform_set_drvdata(pdev, tx_priv);
  1512. tx_priv->dev = &pdev->dev;
  1513. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1514. &tx_base_addr);
  1515. if (ret) {
  1516. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1517. __func__, "reg");
  1518. return ret;
  1519. }
  1520. dev_set_drvdata(&pdev->dev, tx_priv);
  1521. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1522. "qcom,tx-swr-gpios", 0);
  1523. if (!tx_priv->tx_swr_gpio_p) {
  1524. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  1525. __func__);
  1526. return -EINVAL;
  1527. }
  1528. tx_io_base = devm_ioremap(&pdev->dev,
  1529. tx_base_addr, TX_MACRO_MAX_OFFSET);
  1530. if (!tx_io_base) {
  1531. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1532. return -ENOMEM;
  1533. }
  1534. tx_priv->tx_io_base = tx_io_base;
  1535. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  1536. &sample_rate);
  1537. if (ret) {
  1538. dev_err(&pdev->dev,
  1539. "%s: could not find sample_rate entry in dt\n",
  1540. __func__);
  1541. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  1542. } else {
  1543. if (tx_macro_validate_dmic_sample_rate(
  1544. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  1545. return -EINVAL;
  1546. }
  1547. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  1548. tx_macro_add_child_devices);
  1549. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  1550. tx_priv->swr_plat_data.read = NULL;
  1551. tx_priv->swr_plat_data.write = NULL;
  1552. tx_priv->swr_plat_data.bulk_write = NULL;
  1553. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  1554. tx_priv->swr_plat_data.handle_irq = NULL;
  1555. /* Register MCLK for tx macro */
  1556. tx_core_clk = devm_clk_get(&pdev->dev, "tx_core_clk");
  1557. if (IS_ERR(tx_core_clk)) {
  1558. ret = PTR_ERR(tx_core_clk);
  1559. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  1560. __func__, "tx_core_clk", ret);
  1561. return ret;
  1562. }
  1563. tx_priv->tx_core_clk = tx_core_clk;
  1564. /* Register npl clk for soundwire */
  1565. tx_npl_clk = devm_clk_get(&pdev->dev, "tx_npl_clk");
  1566. if (IS_ERR(tx_npl_clk)) {
  1567. ret = PTR_ERR(tx_npl_clk);
  1568. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  1569. __func__, "tx_npl_clk", ret);
  1570. return ret;
  1571. }
  1572. tx_priv->tx_npl_clk = tx_npl_clk;
  1573. mutex_init(&tx_priv->mclk_lock);
  1574. mutex_init(&tx_priv->swr_clk_lock);
  1575. tx_macro_init_ops(&ops, tx_io_base);
  1576. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  1577. if (ret) {
  1578. dev_err(&pdev->dev,
  1579. "%s: register macro failed\n", __func__);
  1580. goto err_reg_macro;
  1581. }
  1582. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  1583. return 0;
  1584. err_reg_macro:
  1585. mutex_destroy(&tx_priv->mclk_lock);
  1586. mutex_destroy(&tx_priv->swr_clk_lock);
  1587. return ret;
  1588. }
  1589. static int tx_macro_remove(struct platform_device *pdev)
  1590. {
  1591. struct tx_macro_priv *tx_priv = NULL;
  1592. u16 count = 0;
  1593. tx_priv = platform_get_drvdata(pdev);
  1594. if (!tx_priv)
  1595. return -EINVAL;
  1596. kfree(tx_priv->swr_ctrl_data);
  1597. for (count = 0; count < tx_priv->child_count &&
  1598. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  1599. platform_device_unregister(tx_priv->pdev_child_devices[count]);
  1600. mutex_destroy(&tx_priv->mclk_lock);
  1601. mutex_destroy(&tx_priv->swr_clk_lock);
  1602. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  1603. return 0;
  1604. }
  1605. static const struct of_device_id tx_macro_dt_match[] = {
  1606. {.compatible = "qcom,tx-macro"},
  1607. {}
  1608. };
  1609. static struct platform_driver tx_macro_driver = {
  1610. .driver = {
  1611. .name = "tx_macro",
  1612. .owner = THIS_MODULE,
  1613. .of_match_table = tx_macro_dt_match,
  1614. },
  1615. .probe = tx_macro_probe,
  1616. .remove = tx_macro_remove,
  1617. };
  1618. module_platform_driver(tx_macro_driver);
  1619. MODULE_DESCRIPTION("TX macro driver");
  1620. MODULE_LICENSE("GPL v2");