tx-macro.c 52 KB

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