tx-macro.c 51 KB

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