tx-macro.c 53 KB

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