tx-macro.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/clk.h>
  7. #include <linux/io.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <linux/pm_runtime.h>
  11. #include <sound/soc.h>
  12. #include <sound/soc-dapm.h>
  13. #include <sound/tlv.h>
  14. #include <soc/swr-common.h>
  15. #include <soc/swr-wcd.h>
  16. #include <asoc/msm-cdc-pinctrl.h>
  17. #include "bolero-cdc.h"
  18. #include "bolero-cdc-registers.h"
  19. #include "bolero-clk-rsc.h"
  20. #define AUTO_SUSPEND_DELAY 50 /* delay in msec */
  21. #define TX_MACRO_MAX_OFFSET 0x1000
  22. #define NUM_DECIMATORS 8
  23. #define TX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  24. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  25. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  26. #define TX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  27. SNDRV_PCM_FMTBIT_S24_LE |\
  28. SNDRV_PCM_FMTBIT_S24_3LE)
  29. #define TX_HPF_CUT_OFF_FREQ_MASK 0x60
  30. #define CF_MIN_3DB_4HZ 0x0
  31. #define CF_MIN_3DB_75HZ 0x1
  32. #define CF_MIN_3DB_150HZ 0x2
  33. #define TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED 0
  34. #define TX_MACRO_MCLK_FREQ 9600000
  35. #define TX_MACRO_TX_PATH_OFFSET 0x80
  36. #define TX_MACRO_SWR_MIC_MUX_SEL_MASK 0xF
  37. #define TX_MACRO_ADC_MUX_CFG_OFFSET 0x8
  38. #define TX_MACRO_ADC_MODE_CFG0_SHIFT 1
  39. #define TX_MACRO_DMIC_UNMUTE_DELAY_MS 40
  40. #define TX_MACRO_AMIC_UNMUTE_DELAY_MS 100
  41. #define TX_MACRO_DMIC_HPF_DELAY_MS 300
  42. #define TX_MACRO_AMIC_HPF_DELAY_MS 300
  43. static int tx_unmute_delay = TX_MACRO_DMIC_UNMUTE_DELAY_MS;
  44. module_param(tx_unmute_delay, int, 0664);
  45. MODULE_PARM_DESC(tx_unmute_delay, "delay to unmute the tx path");
  46. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  47. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  48. struct snd_pcm_hw_params *params,
  49. struct snd_soc_dai *dai);
  50. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  51. unsigned int *tx_num, unsigned int *tx_slot,
  52. unsigned int *rx_num, unsigned int *rx_slot);
  53. #define TX_MACRO_SWR_STRING_LEN 80
  54. #define TX_MACRO_CHILD_DEVICES_MAX 3
  55. /* Hold instance to soundwire platform device */
  56. struct tx_macro_swr_ctrl_data {
  57. struct platform_device *tx_swr_pdev;
  58. };
  59. struct tx_macro_swr_ctrl_platform_data {
  60. void *handle; /* holds codec private data */
  61. int (*read)(void *handle, int reg);
  62. int (*write)(void *handle, int reg, int val);
  63. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  64. int (*clk)(void *handle, bool enable);
  65. int (*core_vote)(void *handle, bool enable);
  66. int (*handle_irq)(void *handle,
  67. irqreturn_t (*swrm_irq_handler)(int irq,
  68. void *data),
  69. void *swrm_handle,
  70. int action);
  71. };
  72. enum {
  73. TX_MACRO_AIF_INVALID = 0,
  74. TX_MACRO_AIF1_CAP,
  75. TX_MACRO_AIF2_CAP,
  76. TX_MACRO_AIF3_CAP,
  77. TX_MACRO_MAX_DAIS
  78. };
  79. enum {
  80. TX_MACRO_DEC0,
  81. TX_MACRO_DEC1,
  82. TX_MACRO_DEC2,
  83. TX_MACRO_DEC3,
  84. TX_MACRO_DEC4,
  85. TX_MACRO_DEC5,
  86. TX_MACRO_DEC6,
  87. TX_MACRO_DEC7,
  88. TX_MACRO_DEC_MAX,
  89. };
  90. enum {
  91. TX_MACRO_CLK_DIV_2,
  92. TX_MACRO_CLK_DIV_3,
  93. TX_MACRO_CLK_DIV_4,
  94. TX_MACRO_CLK_DIV_6,
  95. TX_MACRO_CLK_DIV_8,
  96. TX_MACRO_CLK_DIV_16,
  97. };
  98. enum {
  99. MSM_DMIC,
  100. SWR_MIC,
  101. ANC_FB_TUNE1
  102. };
  103. enum {
  104. TX_MCLK,
  105. VA_MCLK,
  106. };
  107. struct tx_macro_reg_mask_val {
  108. u16 reg;
  109. u8 mask;
  110. u8 val;
  111. };
  112. struct tx_mute_work {
  113. struct tx_macro_priv *tx_priv;
  114. u32 decimator;
  115. struct delayed_work dwork;
  116. };
  117. struct hpf_work {
  118. struct tx_macro_priv *tx_priv;
  119. u8 decimator;
  120. u8 hpf_cut_off_freq;
  121. struct delayed_work dwork;
  122. };
  123. struct tx_macro_priv {
  124. struct device *dev;
  125. bool dec_active[NUM_DECIMATORS];
  126. int tx_mclk_users;
  127. int swr_clk_users;
  128. bool dapm_mclk_enable;
  129. bool reset_swr;
  130. struct mutex mclk_lock;
  131. struct mutex swr_clk_lock;
  132. struct snd_soc_component *component;
  133. struct device_node *tx_swr_gpio_p;
  134. struct tx_macro_swr_ctrl_data *swr_ctrl_data;
  135. struct tx_macro_swr_ctrl_platform_data swr_plat_data;
  136. struct work_struct tx_macro_add_child_devices_work;
  137. struct hpf_work tx_hpf_work[NUM_DECIMATORS];
  138. struct tx_mute_work tx_mute_dwork[NUM_DECIMATORS];
  139. u16 dmic_clk_div;
  140. u32 version;
  141. u32 is_used_tx_swr_gpio;
  142. unsigned long active_ch_mask[TX_MACRO_MAX_DAIS];
  143. unsigned long active_ch_cnt[TX_MACRO_MAX_DAIS];
  144. char __iomem *tx_io_base;
  145. struct platform_device *pdev_child_devices
  146. [TX_MACRO_CHILD_DEVICES_MAX];
  147. int child_count;
  148. int tx_swr_clk_cnt;
  149. int va_swr_clk_cnt;
  150. int va_clk_status;
  151. int tx_clk_status;
  152. bool bcs_enable;
  153. int dec_mode[NUM_DECIMATORS];
  154. int bcs_ch;
  155. bool bcs_clk_en;
  156. bool hs_slow_insert_complete;
  157. int amic_sample_rate;
  158. bool lpi_enable;
  159. bool register_event_listener;
  160. };
  161. static bool tx_macro_get_data(struct snd_soc_component *component,
  162. struct device **tx_dev,
  163. struct tx_macro_priv **tx_priv,
  164. const char *func_name)
  165. {
  166. *tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  167. if (!(*tx_dev)) {
  168. dev_err(component->dev,
  169. "%s: null device for macro!\n", func_name);
  170. return false;
  171. }
  172. *tx_priv = dev_get_drvdata((*tx_dev));
  173. if (!(*tx_priv)) {
  174. dev_err(component->dev,
  175. "%s: priv is null for macro!\n", func_name);
  176. return false;
  177. }
  178. if (!(*tx_priv)->component) {
  179. dev_err(component->dev,
  180. "%s: tx_priv->component not initialized!\n", func_name);
  181. return false;
  182. }
  183. return true;
  184. }
  185. static int tx_macro_mclk_enable(struct tx_macro_priv *tx_priv,
  186. bool mclk_enable)
  187. {
  188. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  189. int ret = 0;
  190. if (regmap == NULL) {
  191. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  192. return -EINVAL;
  193. }
  194. dev_dbg(tx_priv->dev, "%s: mclk_enable = %u,clk_users= %d\n",
  195. __func__, mclk_enable, tx_priv->tx_mclk_users);
  196. mutex_lock(&tx_priv->mclk_lock);
  197. if (mclk_enable) {
  198. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  199. TX_CORE_CLK,
  200. TX_CORE_CLK,
  201. true);
  202. if (ret < 0) {
  203. dev_err_ratelimited(tx_priv->dev,
  204. "%s: request clock enable failed\n",
  205. __func__);
  206. goto exit;
  207. }
  208. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  209. true);
  210. regcache_mark_dirty(regmap);
  211. regcache_sync_region(regmap,
  212. TX_START_OFFSET,
  213. TX_MAX_OFFSET);
  214. if (tx_priv->tx_mclk_users == 0) {
  215. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  216. regmap_update_bits(regmap,
  217. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK, 0x01, 0x01);
  218. regmap_update_bits(regmap,
  219. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  220. 0x01, 0x01);
  221. regmap_update_bits(regmap,
  222. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  223. 0x01, 0x01);
  224. }
  225. tx_priv->tx_mclk_users++;
  226. } else {
  227. if (tx_priv->tx_mclk_users <= 0) {
  228. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  229. __func__);
  230. tx_priv->tx_mclk_users = 0;
  231. goto exit;
  232. }
  233. tx_priv->tx_mclk_users--;
  234. if (tx_priv->tx_mclk_users == 0) {
  235. regmap_update_bits(regmap,
  236. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  237. 0x01, 0x00);
  238. regmap_update_bits(regmap,
  239. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  240. 0x01, 0x00);
  241. }
  242. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  243. false);
  244. bolero_clk_rsc_request_clock(tx_priv->dev,
  245. TX_CORE_CLK,
  246. TX_CORE_CLK,
  247. false);
  248. }
  249. exit:
  250. mutex_unlock(&tx_priv->mclk_lock);
  251. return ret;
  252. }
  253. static int __tx_macro_mclk_enable(struct snd_soc_component *component,
  254. bool enable)
  255. {
  256. struct device *tx_dev = NULL;
  257. struct tx_macro_priv *tx_priv = NULL;
  258. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  259. return -EINVAL;
  260. return tx_macro_mclk_enable(tx_priv, enable);
  261. }
  262. static int tx_macro_va_swr_clk_event(struct snd_soc_dapm_widget *w,
  263. struct snd_kcontrol *kcontrol, int event)
  264. {
  265. struct device *tx_dev = NULL;
  266. struct tx_macro_priv *tx_priv = NULL;
  267. struct snd_soc_component *component =
  268. snd_soc_dapm_to_component(w->dapm);
  269. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  270. return -EINVAL;
  271. if (SND_SOC_DAPM_EVENT_ON(event))
  272. ++tx_priv->va_swr_clk_cnt;
  273. if (SND_SOC_DAPM_EVENT_OFF(event))
  274. --tx_priv->va_swr_clk_cnt;
  275. return 0;
  276. }
  277. static int tx_macro_tx_swr_clk_event(struct snd_soc_dapm_widget *w,
  278. struct snd_kcontrol *kcontrol, int event)
  279. {
  280. struct device *tx_dev = NULL;
  281. struct tx_macro_priv *tx_priv = NULL;
  282. struct snd_soc_component *component =
  283. snd_soc_dapm_to_component(w->dapm);
  284. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  285. return -EINVAL;
  286. if (SND_SOC_DAPM_EVENT_ON(event))
  287. ++tx_priv->tx_swr_clk_cnt;
  288. if (SND_SOC_DAPM_EVENT_OFF(event))
  289. --tx_priv->tx_swr_clk_cnt;
  290. return 0;
  291. }
  292. static int tx_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
  293. struct snd_kcontrol *kcontrol, int event)
  294. {
  295. struct snd_soc_component *component =
  296. snd_soc_dapm_to_component(w->dapm);
  297. int ret = 0;
  298. struct device *tx_dev = NULL;
  299. struct tx_macro_priv *tx_priv = NULL;
  300. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  301. return -EINVAL;
  302. dev_dbg(tx_dev, "%s: event = %d, lpi_enable = %d\n",
  303. __func__, event, tx_priv->lpi_enable);
  304. if (!tx_priv->lpi_enable)
  305. return ret;
  306. switch (event) {
  307. case SND_SOC_DAPM_PRE_PMU:
  308. if (tx_priv->lpi_enable) {
  309. bolero_register_event_listener(component, true);
  310. tx_priv->register_event_listener = true;
  311. }
  312. break;
  313. case SND_SOC_DAPM_POST_PMD:
  314. if (tx_priv->register_event_listener) {
  315. tx_priv->register_event_listener = false;
  316. bolero_register_event_listener(component, false);
  317. }
  318. break;
  319. default:
  320. dev_err(tx_priv->dev,
  321. "%s: invalid DAPM event %d\n", __func__, event);
  322. ret = -EINVAL;
  323. }
  324. return ret;
  325. }
  326. static int tx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  327. struct snd_kcontrol *kcontrol, int event)
  328. {
  329. struct snd_soc_component *component =
  330. snd_soc_dapm_to_component(w->dapm);
  331. int ret = 0;
  332. struct device *tx_dev = NULL;
  333. struct tx_macro_priv *tx_priv = NULL;
  334. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  335. return -EINVAL;
  336. dev_dbg(tx_dev, "%s: event = %d\n", __func__, event);
  337. switch (event) {
  338. case SND_SOC_DAPM_PRE_PMU:
  339. ret = tx_macro_mclk_enable(tx_priv, 1);
  340. if (ret)
  341. tx_priv->dapm_mclk_enable = false;
  342. else
  343. tx_priv->dapm_mclk_enable = true;
  344. break;
  345. case SND_SOC_DAPM_POST_PMD:
  346. if (tx_priv->dapm_mclk_enable)
  347. ret = tx_macro_mclk_enable(tx_priv, 0);
  348. break;
  349. default:
  350. dev_err(tx_priv->dev,
  351. "%s: invalid DAPM event %d\n", __func__, event);
  352. ret = -EINVAL;
  353. }
  354. return ret;
  355. }
  356. static int tx_macro_event_handler(struct snd_soc_component *component,
  357. u16 event, u32 data)
  358. {
  359. struct device *tx_dev = NULL;
  360. struct tx_macro_priv *tx_priv = NULL;
  361. int ret = 0;
  362. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  363. return -EINVAL;
  364. switch (event) {
  365. case BOLERO_MACRO_EVT_SSR_DOWN:
  366. trace_printk("%s, enter SSR down\n", __func__);
  367. if (tx_priv->swr_ctrl_data) {
  368. swrm_wcd_notify(
  369. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  370. SWR_DEVICE_SSR_DOWN, NULL);
  371. }
  372. if ((!pm_runtime_enabled(tx_dev) ||
  373. !pm_runtime_suspended(tx_dev))) {
  374. ret = bolero_runtime_suspend(tx_dev);
  375. if (!ret) {
  376. pm_runtime_disable(tx_dev);
  377. pm_runtime_set_suspended(tx_dev);
  378. pm_runtime_enable(tx_dev);
  379. }
  380. }
  381. break;
  382. case BOLERO_MACRO_EVT_SSR_UP:
  383. trace_printk("%s, enter SSR up\n", __func__);
  384. /* reset swr after ssr/pdr */
  385. tx_priv->reset_swr = true;
  386. if (tx_priv->swr_ctrl_data)
  387. swrm_wcd_notify(
  388. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  389. SWR_DEVICE_SSR_UP, NULL);
  390. break;
  391. case BOLERO_MACRO_EVT_CLK_RESET:
  392. bolero_rsc_clk_reset(tx_dev, TX_CORE_CLK);
  393. break;
  394. case BOLERO_MACRO_EVT_BCS_CLK_OFF:
  395. if (tx_priv->bcs_clk_en)
  396. snd_soc_component_update_bits(component,
  397. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, data << 6);
  398. if (data)
  399. tx_priv->hs_slow_insert_complete = true;
  400. else
  401. tx_priv->hs_slow_insert_complete = false;
  402. break;
  403. default:
  404. pr_debug("%s Invalid Event\n", __func__);
  405. break;
  406. }
  407. return 0;
  408. }
  409. static int tx_macro_reg_wake_irq(struct snd_soc_component *component,
  410. u32 data)
  411. {
  412. struct device *tx_dev = NULL;
  413. struct tx_macro_priv *tx_priv = NULL;
  414. u32 ipc_wakeup = data;
  415. int ret = 0;
  416. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  417. return -EINVAL;
  418. if (tx_priv->swr_ctrl_data)
  419. ret = swrm_wcd_notify(
  420. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  421. SWR_REGISTER_WAKE_IRQ, &ipc_wakeup);
  422. return ret;
  423. }
  424. static bool is_amic_enabled(struct snd_soc_component *component, int decimator)
  425. {
  426. u16 adc_mux_reg = 0, adc_reg = 0;
  427. u16 adc_n = BOLERO_ADC_MAX;
  428. bool ret = false;
  429. struct device *tx_dev = NULL;
  430. struct tx_macro_priv *tx_priv = NULL;
  431. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  432. return ret;
  433. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  434. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  435. if (snd_soc_component_read32(component, adc_mux_reg) & SWR_MIC) {
  436. if (tx_priv->version == BOLERO_VERSION_2_1)
  437. return true;
  438. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  439. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  440. adc_n = snd_soc_component_read32(component, adc_reg) &
  441. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  442. if (adc_n < BOLERO_ADC_MAX)
  443. return true;
  444. }
  445. return ret;
  446. }
  447. static void tx_macro_tx_hpf_corner_freq_callback(struct work_struct *work)
  448. {
  449. struct delayed_work *hpf_delayed_work = NULL;
  450. struct hpf_work *hpf_work = NULL;
  451. struct tx_macro_priv *tx_priv = NULL;
  452. struct snd_soc_component *component = NULL;
  453. u16 dec_cfg_reg = 0, hpf_gate_reg = 0;
  454. u8 hpf_cut_off_freq = 0;
  455. u16 adc_reg = 0, adc_n = 0;
  456. hpf_delayed_work = to_delayed_work(work);
  457. hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork);
  458. tx_priv = hpf_work->tx_priv;
  459. component = tx_priv->component;
  460. hpf_cut_off_freq = hpf_work->hpf_cut_off_freq;
  461. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  462. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  463. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  464. TX_MACRO_TX_PATH_OFFSET * hpf_work->decimator;
  465. dev_dbg(component->dev, "%s: decimator %u hpf_cut_of_freq 0x%x\n",
  466. __func__, hpf_work->decimator, hpf_cut_off_freq);
  467. if (is_amic_enabled(component, hpf_work->decimator)) {
  468. adc_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0 +
  469. TX_MACRO_ADC_MUX_CFG_OFFSET * hpf_work->decimator;
  470. adc_n = snd_soc_component_read32(component, adc_reg) &
  471. TX_MACRO_SWR_MIC_MUX_SEL_MASK;
  472. /* analog mic clear TX hold */
  473. bolero_clear_amic_tx_hold(component->dev, adc_n);
  474. snd_soc_component_update_bits(component,
  475. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  476. hpf_cut_off_freq << 5);
  477. snd_soc_component_update_bits(component, hpf_gate_reg,
  478. 0x03, 0x02);
  479. /* Add delay between toggle hpf gate based on sample rate */
  480. switch(tx_priv->amic_sample_rate) {
  481. case 8000:
  482. usleep_range(125, 130);
  483. break;
  484. case 16000:
  485. usleep_range(62, 65);
  486. break;
  487. case 32000:
  488. usleep_range(31, 32);
  489. break;
  490. case 48000:
  491. usleep_range(20, 21);
  492. break;
  493. case 96000:
  494. usleep_range(10, 11);
  495. break;
  496. case 192000:
  497. usleep_range(5, 6);
  498. break;
  499. default:
  500. usleep_range(125, 130);
  501. }
  502. snd_soc_component_update_bits(component, hpf_gate_reg,
  503. 0x03, 0x01);
  504. } else {
  505. snd_soc_component_update_bits(component,
  506. dec_cfg_reg, TX_HPF_CUT_OFF_FREQ_MASK,
  507. hpf_cut_off_freq << 5);
  508. snd_soc_component_update_bits(component, hpf_gate_reg,
  509. 0x02, 0x02);
  510. /* Minimum 1 clk cycle delay is required as per HW spec */
  511. usleep_range(1000, 1010);
  512. snd_soc_component_update_bits(component, hpf_gate_reg,
  513. 0x02, 0x00);
  514. }
  515. }
  516. static void tx_macro_mute_update_callback(struct work_struct *work)
  517. {
  518. struct tx_mute_work *tx_mute_dwork = NULL;
  519. struct snd_soc_component *component = NULL;
  520. struct tx_macro_priv *tx_priv = NULL;
  521. struct delayed_work *delayed_work = NULL;
  522. u16 tx_vol_ctl_reg = 0;
  523. u8 decimator = 0;
  524. delayed_work = to_delayed_work(work);
  525. tx_mute_dwork = container_of(delayed_work, struct tx_mute_work, dwork);
  526. tx_priv = tx_mute_dwork->tx_priv;
  527. component = tx_priv->component;
  528. decimator = tx_mute_dwork->decimator;
  529. tx_vol_ctl_reg =
  530. BOLERO_CDC_TX0_TX_PATH_CTL +
  531. TX_MACRO_TX_PATH_OFFSET * decimator;
  532. snd_soc_component_update_bits(component, tx_vol_ctl_reg, 0x10, 0x00);
  533. dev_dbg(tx_priv->dev, "%s: decimator %u unmute\n",
  534. __func__, decimator);
  535. }
  536. static int tx_macro_put_dec_enum(struct snd_kcontrol *kcontrol,
  537. struct snd_ctl_elem_value *ucontrol)
  538. {
  539. struct snd_soc_dapm_widget *widget =
  540. snd_soc_dapm_kcontrol_widget(kcontrol);
  541. struct snd_soc_component *component =
  542. snd_soc_dapm_to_component(widget->dapm);
  543. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  544. unsigned int val = 0;
  545. u16 mic_sel_reg = 0;
  546. u16 dmic_clk_reg = 0;
  547. struct device *tx_dev = NULL;
  548. struct tx_macro_priv *tx_priv = NULL;
  549. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  550. return -EINVAL;
  551. val = ucontrol->value.enumerated.item[0];
  552. if (val > e->items - 1)
  553. return -EINVAL;
  554. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  555. widget->name, val);
  556. switch (e->reg) {
  557. case BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0:
  558. mic_sel_reg = BOLERO_CDC_TX0_TX_PATH_CFG0;
  559. break;
  560. case BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0:
  561. mic_sel_reg = BOLERO_CDC_TX1_TX_PATH_CFG0;
  562. break;
  563. case BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0:
  564. mic_sel_reg = BOLERO_CDC_TX2_TX_PATH_CFG0;
  565. break;
  566. case BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0:
  567. mic_sel_reg = BOLERO_CDC_TX3_TX_PATH_CFG0;
  568. break;
  569. case BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0:
  570. mic_sel_reg = BOLERO_CDC_TX4_TX_PATH_CFG0;
  571. break;
  572. case BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0:
  573. mic_sel_reg = BOLERO_CDC_TX5_TX_PATH_CFG0;
  574. break;
  575. case BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0:
  576. mic_sel_reg = BOLERO_CDC_TX6_TX_PATH_CFG0;
  577. break;
  578. case BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0:
  579. mic_sel_reg = BOLERO_CDC_TX7_TX_PATH_CFG0;
  580. break;
  581. default:
  582. dev_err(component->dev, "%s: e->reg: 0x%x not expected\n",
  583. __func__, e->reg);
  584. return -EINVAL;
  585. }
  586. if (strnstr(widget->name, "SMIC", strlen(widget->name))) {
  587. if (val != 0) {
  588. if (val < 5) {
  589. snd_soc_component_update_bits(component,
  590. mic_sel_reg,
  591. 1 << 7, 0x0 << 7);
  592. } else {
  593. snd_soc_component_update_bits(component,
  594. mic_sel_reg,
  595. 1 << 7, 0x1 << 7);
  596. snd_soc_component_update_bits(component,
  597. BOLERO_CDC_VA_TOP_CSR_DMIC_CFG,
  598. 0x80, 0x00);
  599. dmic_clk_reg =
  600. BOLERO_CDC_TX_TOP_CSR_SWR_DMIC0_CTL +
  601. ((val - 5)/2) * 4;
  602. snd_soc_component_update_bits(component,
  603. dmic_clk_reg,
  604. 0x0E, tx_priv->dmic_clk_div << 0x1);
  605. }
  606. }
  607. } else {
  608. /* DMIC selected */
  609. if (val != 0)
  610. snd_soc_component_update_bits(component, mic_sel_reg,
  611. 1 << 7, 1 << 7);
  612. }
  613. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  614. }
  615. static int tx_macro_tx_mixer_get(struct snd_kcontrol *kcontrol,
  616. struct snd_ctl_elem_value *ucontrol)
  617. {
  618. struct snd_soc_dapm_widget *widget =
  619. snd_soc_dapm_kcontrol_widget(kcontrol);
  620. struct snd_soc_component *component =
  621. snd_soc_dapm_to_component(widget->dapm);
  622. struct soc_multi_mixer_control *mixer =
  623. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  624. u32 dai_id = widget->shift;
  625. u32 dec_id = mixer->shift;
  626. struct device *tx_dev = NULL;
  627. struct tx_macro_priv *tx_priv = NULL;
  628. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  629. return -EINVAL;
  630. if (test_bit(dec_id, &tx_priv->active_ch_mask[dai_id]))
  631. ucontrol->value.integer.value[0] = 1;
  632. else
  633. ucontrol->value.integer.value[0] = 0;
  634. return 0;
  635. }
  636. static int tx_macro_tx_mixer_put(struct snd_kcontrol *kcontrol,
  637. struct snd_ctl_elem_value *ucontrol)
  638. {
  639. struct snd_soc_dapm_widget *widget =
  640. snd_soc_dapm_kcontrol_widget(kcontrol);
  641. struct snd_soc_component *component =
  642. snd_soc_dapm_to_component(widget->dapm);
  643. struct snd_soc_dapm_update *update = NULL;
  644. struct soc_multi_mixer_control *mixer =
  645. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  646. u32 dai_id = widget->shift;
  647. u32 dec_id = mixer->shift;
  648. u32 enable = ucontrol->value.integer.value[0];
  649. struct device *tx_dev = NULL;
  650. struct tx_macro_priv *tx_priv = NULL;
  651. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  652. return -EINVAL;
  653. if (enable) {
  654. set_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  655. tx_priv->active_ch_cnt[dai_id]++;
  656. } else {
  657. tx_priv->active_ch_cnt[dai_id]--;
  658. clear_bit(dec_id, &tx_priv->active_ch_mask[dai_id]);
  659. }
  660. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, update);
  661. return 0;
  662. }
  663. static inline int tx_macro_path_get(const char *wname,
  664. unsigned int *path_num)
  665. {
  666. int ret = 0;
  667. char *widget_name = NULL;
  668. char *w_name = NULL;
  669. char *path_num_char = NULL;
  670. char *path_name = NULL;
  671. widget_name = kstrndup(wname, 10, GFP_KERNEL);
  672. if (!widget_name)
  673. return -EINVAL;
  674. w_name = widget_name;
  675. path_name = strsep(&widget_name, " ");
  676. if (!path_name) {
  677. pr_err("%s: Invalid widget name = %s\n",
  678. __func__, widget_name);
  679. ret = -EINVAL;
  680. goto err;
  681. }
  682. path_num_char = strpbrk(path_name, "01234567");
  683. if (!path_num_char) {
  684. pr_err("%s: tx path index not found\n",
  685. __func__);
  686. ret = -EINVAL;
  687. goto err;
  688. }
  689. ret = kstrtouint(path_num_char, 10, path_num);
  690. if (ret < 0)
  691. pr_err("%s: Invalid tx path = %s\n",
  692. __func__, w_name);
  693. err:
  694. kfree(w_name);
  695. return ret;
  696. }
  697. static int tx_macro_dec_mode_get(struct snd_kcontrol *kcontrol,
  698. struct snd_ctl_elem_value *ucontrol)
  699. {
  700. struct snd_soc_component *component =
  701. snd_soc_kcontrol_component(kcontrol);
  702. struct tx_macro_priv *tx_priv = NULL;
  703. struct device *tx_dev = NULL;
  704. int ret = 0;
  705. int path = 0;
  706. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  707. return -EINVAL;
  708. ret = tx_macro_path_get(kcontrol->id.name, &path);
  709. if (ret)
  710. return ret;
  711. ucontrol->value.integer.value[0] = tx_priv->dec_mode[path];
  712. return 0;
  713. }
  714. static int tx_macro_dec_mode_put(struct snd_kcontrol *kcontrol,
  715. struct snd_ctl_elem_value *ucontrol)
  716. {
  717. struct snd_soc_component *component =
  718. snd_soc_kcontrol_component(kcontrol);
  719. struct tx_macro_priv *tx_priv = NULL;
  720. struct device *tx_dev = NULL;
  721. int value = ucontrol->value.integer.value[0];
  722. int ret = 0;
  723. int path = 0;
  724. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  725. return -EINVAL;
  726. ret = tx_macro_path_get(kcontrol->id.name, &path);
  727. if (ret)
  728. return ret;
  729. tx_priv->dec_mode[path] = value;
  730. return 0;
  731. }
  732. static int tx_macro_lpi_get(struct snd_kcontrol *kcontrol,
  733. struct snd_ctl_elem_value *ucontrol)
  734. {
  735. struct snd_soc_component *component =
  736. snd_soc_kcontrol_component(kcontrol);
  737. struct device *tx_dev = NULL;
  738. struct tx_macro_priv *tx_priv = NULL;
  739. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  740. return -EINVAL;
  741. ucontrol->value.integer.value[0] = tx_priv->lpi_enable;
  742. return 0;
  743. }
  744. static int tx_macro_lpi_put(struct snd_kcontrol *kcontrol,
  745. struct snd_ctl_elem_value *ucontrol)
  746. {
  747. struct snd_soc_component *component =
  748. snd_soc_kcontrol_component(kcontrol);
  749. struct device *tx_dev = NULL;
  750. struct tx_macro_priv *tx_priv = NULL;
  751. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  752. return -EINVAL;
  753. tx_priv->lpi_enable = ucontrol->value.integer.value[0];
  754. return 0;
  755. }
  756. static int tx_macro_bcs_ch_get(struct snd_kcontrol *kcontrol,
  757. struct snd_ctl_elem_value *ucontrol)
  758. {
  759. struct snd_soc_component *component =
  760. snd_soc_kcontrol_component(kcontrol);
  761. struct tx_macro_priv *tx_priv = NULL;
  762. struct device *tx_dev = NULL;
  763. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  764. return -EINVAL;
  765. ucontrol->value.enumerated.item[0] = tx_priv->bcs_ch;
  766. return 0;
  767. }
  768. static int tx_macro_bcs_ch_put(struct snd_kcontrol *kcontrol,
  769. struct snd_ctl_elem_value *ucontrol)
  770. {
  771. struct snd_soc_component *component =
  772. snd_soc_kcontrol_component(kcontrol);
  773. struct tx_macro_priv *tx_priv = NULL;
  774. struct device *tx_dev = NULL;
  775. int value = ucontrol->value.enumerated.item[0];
  776. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  777. return -EINVAL;
  778. tx_priv->bcs_ch = value;
  779. return 0;
  780. }
  781. static int tx_macro_get_bcs(struct snd_kcontrol *kcontrol,
  782. struct snd_ctl_elem_value *ucontrol)
  783. {
  784. struct snd_soc_component *component =
  785. snd_soc_kcontrol_component(kcontrol);
  786. struct tx_macro_priv *tx_priv = NULL;
  787. struct device *tx_dev = NULL;
  788. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  789. return -EINVAL;
  790. ucontrol->value.integer.value[0] = tx_priv->bcs_enable;
  791. return 0;
  792. }
  793. static int tx_macro_set_bcs(struct snd_kcontrol *kcontrol,
  794. struct snd_ctl_elem_value *ucontrol)
  795. {
  796. struct snd_soc_component *component =
  797. snd_soc_kcontrol_component(kcontrol);
  798. struct tx_macro_priv *tx_priv = NULL;
  799. struct device *tx_dev = NULL;
  800. int value = ucontrol->value.integer.value[0];
  801. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  802. return -EINVAL;
  803. tx_priv->bcs_enable = value;
  804. return 0;
  805. }
  806. static const char * const bcs_ch_sel_mux_text[] = {
  807. "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  808. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  809. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11",
  810. };
  811. static const struct soc_enum bcs_ch_sel_mux_enum =
  812. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bcs_ch_sel_mux_text),
  813. bcs_ch_sel_mux_text);
  814. static int tx_macro_get_bcs_ch_sel(struct snd_kcontrol *kcontrol,
  815. struct snd_ctl_elem_value *ucontrol)
  816. {
  817. struct snd_soc_component *component =
  818. snd_soc_kcontrol_component(kcontrol);
  819. struct tx_macro_priv *tx_priv = NULL;
  820. struct device *tx_dev = NULL;
  821. int value = 0;
  822. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  823. return -EINVAL;
  824. if (tx_priv->version == BOLERO_VERSION_2_1)
  825. value = (snd_soc_component_read32(component,
  826. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL)) & 0x0F;
  827. else if (tx_priv->version == BOLERO_VERSION_2_0)
  828. value = (snd_soc_component_read32(component,
  829. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL)) & 0x0F;
  830. ucontrol->value.integer.value[0] = value;
  831. return 0;
  832. }
  833. static int tx_macro_put_bcs_ch_sel(struct snd_kcontrol *kcontrol,
  834. struct snd_ctl_elem_value *ucontrol)
  835. {
  836. struct snd_soc_component *component =
  837. snd_soc_kcontrol_component(kcontrol);
  838. struct tx_macro_priv *tx_priv = NULL;
  839. struct device *tx_dev = NULL;
  840. int value;
  841. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  842. return -EINVAL;
  843. if (ucontrol->value.integer.value[0] < 0 ||
  844. ucontrol->value.integer.value[0] > ARRAY_SIZE(bcs_ch_sel_mux_text))
  845. return -EINVAL;
  846. value = ucontrol->value.integer.value[0];
  847. if (tx_priv->version == BOLERO_VERSION_2_1)
  848. snd_soc_component_update_bits(component,
  849. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F, value);
  850. else if (tx_priv->version == BOLERO_VERSION_2_0)
  851. snd_soc_component_update_bits(component,
  852. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0x0F, value);
  853. return 0;
  854. }
  855. static int tx_macro_enable_dmic(struct snd_soc_dapm_widget *w,
  856. struct snd_kcontrol *kcontrol, int event)
  857. {
  858. struct snd_soc_component *component =
  859. snd_soc_dapm_to_component(w->dapm);
  860. unsigned int dmic = 0;
  861. int ret = 0;
  862. char *wname = NULL;
  863. wname = strpbrk(w->name, "01234567");
  864. if (!wname) {
  865. dev_err(component->dev, "%s: widget not found\n", __func__);
  866. return -EINVAL;
  867. }
  868. ret = kstrtouint(wname, 10, &dmic);
  869. if (ret < 0) {
  870. dev_err(component->dev, "%s: Invalid DMIC line on the codec\n",
  871. __func__);
  872. return -EINVAL;
  873. }
  874. dev_dbg(component->dev, "%s: event %d DMIC%d\n",
  875. __func__, event, dmic);
  876. switch (event) {
  877. case SND_SOC_DAPM_PRE_PMU:
  878. bolero_dmic_clk_enable(component, dmic, DMIC_TX, true);
  879. break;
  880. case SND_SOC_DAPM_POST_PMD:
  881. bolero_dmic_clk_enable(component, dmic, DMIC_TX, false);
  882. break;
  883. }
  884. return 0;
  885. }
  886. static int tx_macro_enable_dec(struct snd_soc_dapm_widget *w,
  887. struct snd_kcontrol *kcontrol, int event)
  888. {
  889. struct snd_soc_component *component =
  890. snd_soc_dapm_to_component(w->dapm);
  891. unsigned int decimator = 0;
  892. u16 tx_vol_ctl_reg = 0;
  893. u16 dec_cfg_reg = 0;
  894. u16 hpf_gate_reg = 0;
  895. u16 tx_gain_ctl_reg = 0;
  896. u16 tx_fs_reg = 0;
  897. u8 hpf_cut_off_freq = 0;
  898. u16 adc_mux_reg = 0;
  899. int hpf_delay = TX_MACRO_DMIC_HPF_DELAY_MS;
  900. int unmute_delay = TX_MACRO_DMIC_UNMUTE_DELAY_MS;
  901. struct device *tx_dev = NULL;
  902. struct tx_macro_priv *tx_priv = NULL;
  903. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  904. return -EINVAL;
  905. decimator = w->shift;
  906. dev_dbg(component->dev, "%s(): widget = %s decimator = %u\n", __func__,
  907. w->name, decimator);
  908. tx_vol_ctl_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  909. TX_MACRO_TX_PATH_OFFSET * decimator;
  910. hpf_gate_reg = BOLERO_CDC_TX0_TX_PATH_SEC2 +
  911. TX_MACRO_TX_PATH_OFFSET * decimator;
  912. dec_cfg_reg = BOLERO_CDC_TX0_TX_PATH_CFG0 +
  913. TX_MACRO_TX_PATH_OFFSET * decimator;
  914. tx_gain_ctl_reg = BOLERO_CDC_TX0_TX_VOL_CTL +
  915. TX_MACRO_TX_PATH_OFFSET * decimator;
  916. adc_mux_reg = BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1 +
  917. TX_MACRO_ADC_MUX_CFG_OFFSET * decimator;
  918. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  919. TX_MACRO_TX_PATH_OFFSET * decimator;
  920. tx_priv->amic_sample_rate = (snd_soc_component_read32(component,
  921. tx_fs_reg) & 0x0F);
  922. switch (event) {
  923. case SND_SOC_DAPM_PRE_PMU:
  924. snd_soc_component_update_bits(component,
  925. dec_cfg_reg, 0x06, tx_priv->dec_mode[decimator] <<
  926. TX_MACRO_ADC_MODE_CFG0_SHIFT);
  927. /* Enable TX PGA Mute */
  928. snd_soc_component_update_bits(component,
  929. tx_vol_ctl_reg, 0x10, 0x10);
  930. break;
  931. case SND_SOC_DAPM_POST_PMU:
  932. snd_soc_component_update_bits(component,
  933. tx_vol_ctl_reg, 0x20, 0x20);
  934. if (!is_amic_enabled(component, decimator)) {
  935. snd_soc_component_update_bits(component,
  936. hpf_gate_reg, 0x01, 0x00);
  937. /*
  938. * Minimum 1 clk cycle delay is required as per HW spec
  939. */
  940. usleep_range(1000, 1010);
  941. }
  942. hpf_cut_off_freq = (
  943. snd_soc_component_read32(component, dec_cfg_reg) &
  944. TX_HPF_CUT_OFF_FREQ_MASK) >> 5;
  945. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq =
  946. hpf_cut_off_freq;
  947. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ)
  948. snd_soc_component_update_bits(component, dec_cfg_reg,
  949. TX_HPF_CUT_OFF_FREQ_MASK,
  950. CF_MIN_3DB_150HZ << 5);
  951. if (is_amic_enabled(component, decimator)) {
  952. hpf_delay = TX_MACRO_AMIC_HPF_DELAY_MS;
  953. unmute_delay = TX_MACRO_AMIC_UNMUTE_DELAY_MS;
  954. }
  955. if (tx_unmute_delay < unmute_delay)
  956. tx_unmute_delay = unmute_delay;
  957. /* schedule work queue to Remove Mute */
  958. queue_delayed_work(system_freezable_wq,
  959. &tx_priv->tx_mute_dwork[decimator].dwork,
  960. msecs_to_jiffies(tx_unmute_delay));
  961. if (tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq !=
  962. CF_MIN_3DB_150HZ) {
  963. queue_delayed_work(system_freezable_wq,
  964. &tx_priv->tx_hpf_work[decimator].dwork,
  965. msecs_to_jiffies(hpf_delay));
  966. snd_soc_component_update_bits(component,
  967. hpf_gate_reg, 0x03, 0x02);
  968. if (!is_amic_enabled(component, decimator))
  969. snd_soc_component_update_bits(component,
  970. hpf_gate_reg, 0x03, 0x00);
  971. snd_soc_component_update_bits(component,
  972. hpf_gate_reg, 0x03, 0x01);
  973. /*
  974. * 6ms delay is required as per HW spec
  975. */
  976. usleep_range(6000, 6010);
  977. }
  978. /* apply gain after decimator is enabled */
  979. snd_soc_component_write(component, tx_gain_ctl_reg,
  980. snd_soc_component_read32(component,
  981. tx_gain_ctl_reg));
  982. if (tx_priv->bcs_enable) {
  983. if (tx_priv->version == BOLERO_VERSION_2_1)
  984. snd_soc_component_update_bits(component,
  985. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F,
  986. tx_priv->bcs_ch);
  987. else if (tx_priv->version == BOLERO_VERSION_2_0)
  988. snd_soc_component_update_bits(component,
  989. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0xF0,
  990. (tx_priv->bcs_ch << 4));
  991. snd_soc_component_update_bits(component, dec_cfg_reg,
  992. 0x01, 0x01);
  993. tx_priv->bcs_clk_en = true;
  994. if (tx_priv->hs_slow_insert_complete)
  995. snd_soc_component_update_bits(component,
  996. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40,
  997. 0x40);
  998. }
  999. if (tx_priv->version == BOLERO_VERSION_2_0) {
  1000. if (snd_soc_component_read32(component, adc_mux_reg)
  1001. & SWR_MIC) {
  1002. snd_soc_component_update_bits(component,
  1003. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1004. 0x01, 0x01);
  1005. snd_soc_component_update_bits(component,
  1006. BOLERO_CDC_TX_TOP_CSR_SWR_MIC0_CTL,
  1007. 0x0E, 0x0C);
  1008. snd_soc_component_update_bits(component,
  1009. BOLERO_CDC_TX_TOP_CSR_SWR_MIC1_CTL,
  1010. 0x0E, 0x0C);
  1011. snd_soc_component_update_bits(component,
  1012. BOLERO_CDC_TX_TOP_CSR_SWR_MIC2_CTL,
  1013. 0x0E, 0x00);
  1014. snd_soc_component_update_bits(component,
  1015. BOLERO_CDC_TX_TOP_CSR_SWR_MIC3_CTL,
  1016. 0x0E, 0x00);
  1017. snd_soc_component_update_bits(component,
  1018. BOLERO_CDC_TX_TOP_CSR_SWR_MIC4_CTL,
  1019. 0x0E, 0x00);
  1020. snd_soc_component_update_bits(component,
  1021. BOLERO_CDC_TX_TOP_CSR_SWR_MIC5_CTL,
  1022. 0x0E, 0x00);
  1023. }
  1024. }
  1025. break;
  1026. case SND_SOC_DAPM_PRE_PMD:
  1027. hpf_cut_off_freq =
  1028. tx_priv->tx_hpf_work[decimator].hpf_cut_off_freq;
  1029. snd_soc_component_update_bits(component,
  1030. tx_vol_ctl_reg, 0x10, 0x10);
  1031. if (cancel_delayed_work_sync(
  1032. &tx_priv->tx_hpf_work[decimator].dwork)) {
  1033. if (hpf_cut_off_freq != CF_MIN_3DB_150HZ) {
  1034. snd_soc_component_update_bits(
  1035. component, dec_cfg_reg,
  1036. TX_HPF_CUT_OFF_FREQ_MASK,
  1037. hpf_cut_off_freq << 5);
  1038. if (is_amic_enabled(component, decimator))
  1039. snd_soc_component_update_bits(component,
  1040. hpf_gate_reg,
  1041. 0x03, 0x02);
  1042. else
  1043. snd_soc_component_update_bits(component,
  1044. hpf_gate_reg,
  1045. 0x03, 0x03);
  1046. /*
  1047. * Minimum 1 clk cycle delay is required
  1048. * as per HW spec
  1049. */
  1050. usleep_range(1000, 1010);
  1051. snd_soc_component_update_bits(component,
  1052. hpf_gate_reg,
  1053. 0x03, 0x01);
  1054. }
  1055. }
  1056. cancel_delayed_work_sync(
  1057. &tx_priv->tx_mute_dwork[decimator].dwork);
  1058. if (tx_priv->version == BOLERO_VERSION_2_0) {
  1059. if (snd_soc_component_read32(component, adc_mux_reg)
  1060. & SWR_MIC)
  1061. snd_soc_component_update_bits(component,
  1062. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL,
  1063. 0x01, 0x00);
  1064. }
  1065. break;
  1066. case SND_SOC_DAPM_POST_PMD:
  1067. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1068. 0x20, 0x00);
  1069. snd_soc_component_update_bits(component,
  1070. dec_cfg_reg, 0x06, 0x00);
  1071. snd_soc_component_update_bits(component, tx_vol_ctl_reg,
  1072. 0x10, 0x00);
  1073. if (tx_priv->bcs_enable) {
  1074. snd_soc_component_update_bits(component, dec_cfg_reg,
  1075. 0x01, 0x00);
  1076. snd_soc_component_update_bits(component,
  1077. BOLERO_CDC_TX0_TX_PATH_SEC7, 0x40, 0x00);
  1078. tx_priv->bcs_clk_en = false;
  1079. if (tx_priv->version == BOLERO_VERSION_2_1)
  1080. snd_soc_component_update_bits(component,
  1081. BOLERO_CDC_VA_TOP_CSR_SWR_CTRL, 0x0F,
  1082. 0x00);
  1083. else if (tx_priv->version == BOLERO_VERSION_2_0)
  1084. snd_soc_component_update_bits(component,
  1085. BOLERO_CDC_TX_TOP_CSR_SWR_CTRL, 0xF0,
  1086. 0x00);
  1087. }
  1088. break;
  1089. }
  1090. return 0;
  1091. }
  1092. static int tx_macro_enable_micbias(struct snd_soc_dapm_widget *w,
  1093. struct snd_kcontrol *kcontrol, int event)
  1094. {
  1095. return 0;
  1096. }
  1097. /* Cutoff frequency for high pass filter */
  1098. static const char * const cf_text[] = {
  1099. "CF_NEG_3DB_4HZ", "CF_NEG_3DB_75HZ", "CF_NEG_3DB_150HZ"
  1100. };
  1101. static SOC_ENUM_SINGLE_DECL(cf_dec0_enum, BOLERO_CDC_TX0_TX_PATH_CFG0, 5,
  1102. cf_text);
  1103. static SOC_ENUM_SINGLE_DECL(cf_dec1_enum, BOLERO_CDC_TX1_TX_PATH_CFG0, 5,
  1104. cf_text);
  1105. static SOC_ENUM_SINGLE_DECL(cf_dec2_enum, BOLERO_CDC_TX2_TX_PATH_CFG0, 5,
  1106. cf_text);
  1107. static SOC_ENUM_SINGLE_DECL(cf_dec3_enum, BOLERO_CDC_TX3_TX_PATH_CFG0, 5,
  1108. cf_text);
  1109. static SOC_ENUM_SINGLE_DECL(cf_dec4_enum, BOLERO_CDC_TX4_TX_PATH_CFG0, 5,
  1110. cf_text);
  1111. static SOC_ENUM_SINGLE_DECL(cf_dec5_enum, BOLERO_CDC_TX5_TX_PATH_CFG0, 5,
  1112. cf_text);
  1113. static SOC_ENUM_SINGLE_DECL(cf_dec6_enum, BOLERO_CDC_TX6_TX_PATH_CFG0, 5,
  1114. cf_text);
  1115. static SOC_ENUM_SINGLE_DECL(cf_dec7_enum, BOLERO_CDC_TX7_TX_PATH_CFG0, 5,
  1116. cf_text);
  1117. static int tx_macro_hw_params(struct snd_pcm_substream *substream,
  1118. struct snd_pcm_hw_params *params,
  1119. struct snd_soc_dai *dai)
  1120. {
  1121. int tx_fs_rate = -EINVAL;
  1122. struct snd_soc_component *component = dai->component;
  1123. u32 decimator = 0;
  1124. u32 sample_rate = 0;
  1125. u16 tx_fs_reg = 0;
  1126. struct device *tx_dev = NULL;
  1127. struct tx_macro_priv *tx_priv = NULL;
  1128. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1129. return -EINVAL;
  1130. pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  1131. dai->name, dai->id, params_rate(params),
  1132. params_channels(params));
  1133. sample_rate = params_rate(params);
  1134. switch (sample_rate) {
  1135. case 8000:
  1136. tx_fs_rate = 0;
  1137. break;
  1138. case 16000:
  1139. tx_fs_rate = 1;
  1140. break;
  1141. case 32000:
  1142. tx_fs_rate = 3;
  1143. break;
  1144. case 48000:
  1145. tx_fs_rate = 4;
  1146. break;
  1147. case 96000:
  1148. tx_fs_rate = 5;
  1149. break;
  1150. case 192000:
  1151. tx_fs_rate = 6;
  1152. break;
  1153. case 384000:
  1154. tx_fs_rate = 7;
  1155. break;
  1156. default:
  1157. dev_err(component->dev, "%s: Invalid TX sample rate: %d\n",
  1158. __func__, params_rate(params));
  1159. return -EINVAL;
  1160. }
  1161. for_each_set_bit(decimator, &tx_priv->active_ch_mask[dai->id],
  1162. TX_MACRO_DEC_MAX) {
  1163. if (decimator >= 0) {
  1164. tx_fs_reg = BOLERO_CDC_TX0_TX_PATH_CTL +
  1165. TX_MACRO_TX_PATH_OFFSET * decimator;
  1166. dev_dbg(component->dev, "%s: set DEC%u rate to %u\n",
  1167. __func__, decimator, sample_rate);
  1168. snd_soc_component_update_bits(component, tx_fs_reg,
  1169. 0x0F, tx_fs_rate);
  1170. } else {
  1171. dev_err(component->dev,
  1172. "%s: ERROR: Invalid decimator: %d\n",
  1173. __func__, decimator);
  1174. return -EINVAL;
  1175. }
  1176. }
  1177. return 0;
  1178. }
  1179. static int tx_macro_get_channel_map(struct snd_soc_dai *dai,
  1180. unsigned int *tx_num, unsigned int *tx_slot,
  1181. unsigned int *rx_num, unsigned int *rx_slot)
  1182. {
  1183. struct snd_soc_component *component = dai->component;
  1184. struct device *tx_dev = NULL;
  1185. struct tx_macro_priv *tx_priv = NULL;
  1186. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  1187. return -EINVAL;
  1188. switch (dai->id) {
  1189. case TX_MACRO_AIF1_CAP:
  1190. case TX_MACRO_AIF2_CAP:
  1191. case TX_MACRO_AIF3_CAP:
  1192. *tx_slot = tx_priv->active_ch_mask[dai->id];
  1193. *tx_num = tx_priv->active_ch_cnt[dai->id];
  1194. break;
  1195. default:
  1196. dev_err(tx_dev, "%s: Invalid AIF\n", __func__);
  1197. break;
  1198. }
  1199. return 0;
  1200. }
  1201. static struct snd_soc_dai_ops tx_macro_dai_ops = {
  1202. .hw_params = tx_macro_hw_params,
  1203. .get_channel_map = tx_macro_get_channel_map,
  1204. };
  1205. static struct snd_soc_dai_driver tx_macro_dai[] = {
  1206. {
  1207. .name = "tx_macro_tx1",
  1208. .id = TX_MACRO_AIF1_CAP,
  1209. .capture = {
  1210. .stream_name = "TX_AIF1 Capture",
  1211. .rates = TX_MACRO_RATES,
  1212. .formats = TX_MACRO_FORMATS,
  1213. .rate_max = 192000,
  1214. .rate_min = 8000,
  1215. .channels_min = 1,
  1216. .channels_max = 8,
  1217. },
  1218. .ops = &tx_macro_dai_ops,
  1219. },
  1220. {
  1221. .name = "tx_macro_tx2",
  1222. .id = TX_MACRO_AIF2_CAP,
  1223. .capture = {
  1224. .stream_name = "TX_AIF2 Capture",
  1225. .rates = TX_MACRO_RATES,
  1226. .formats = TX_MACRO_FORMATS,
  1227. .rate_max = 192000,
  1228. .rate_min = 8000,
  1229. .channels_min = 1,
  1230. .channels_max = 8,
  1231. },
  1232. .ops = &tx_macro_dai_ops,
  1233. },
  1234. {
  1235. .name = "tx_macro_tx3",
  1236. .id = TX_MACRO_AIF3_CAP,
  1237. .capture = {
  1238. .stream_name = "TX_AIF3 Capture",
  1239. .rates = TX_MACRO_RATES,
  1240. .formats = TX_MACRO_FORMATS,
  1241. .rate_max = 192000,
  1242. .rate_min = 8000,
  1243. .channels_min = 1,
  1244. .channels_max = 8,
  1245. },
  1246. .ops = &tx_macro_dai_ops,
  1247. },
  1248. };
  1249. #define STRING(name) #name
  1250. #define TX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  1251. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1252. static const struct snd_kcontrol_new name##_mux = \
  1253. SOC_DAPM_ENUM(STRING(name), name##_enum)
  1254. #define TX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  1255. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  1256. static const struct snd_kcontrol_new name##_mux = \
  1257. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  1258. #define TX_MACRO_DAPM_MUX(name, shift, kctl) \
  1259. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  1260. static const char * const adc_mux_text[] = {
  1261. "MSM_DMIC", "SWR_MIC", "ANC_FB_TUNE1"
  1262. };
  1263. TX_MACRO_DAPM_ENUM(tx_dec0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG1,
  1264. 0, adc_mux_text);
  1265. TX_MACRO_DAPM_ENUM(tx_dec1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG1,
  1266. 0, adc_mux_text);
  1267. TX_MACRO_DAPM_ENUM(tx_dec2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG1,
  1268. 0, adc_mux_text);
  1269. TX_MACRO_DAPM_ENUM(tx_dec3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG1,
  1270. 0, adc_mux_text);
  1271. TX_MACRO_DAPM_ENUM(tx_dec4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG1,
  1272. 0, adc_mux_text);
  1273. TX_MACRO_DAPM_ENUM(tx_dec5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG1,
  1274. 0, adc_mux_text);
  1275. TX_MACRO_DAPM_ENUM(tx_dec6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG1,
  1276. 0, adc_mux_text);
  1277. TX_MACRO_DAPM_ENUM(tx_dec7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG1,
  1278. 0, adc_mux_text);
  1279. static const char * const dmic_mux_text[] = {
  1280. "ZERO", "DMIC0", "DMIC1", "DMIC2", "DMIC3",
  1281. "DMIC4", "DMIC5", "DMIC6", "DMIC7"
  1282. };
  1283. TX_MACRO_DAPM_ENUM_EXT(tx_dmic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1284. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1285. tx_macro_put_dec_enum);
  1286. TX_MACRO_DAPM_ENUM_EXT(tx_dmic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1287. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1288. tx_macro_put_dec_enum);
  1289. TX_MACRO_DAPM_ENUM_EXT(tx_dmic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1290. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1291. tx_macro_put_dec_enum);
  1292. TX_MACRO_DAPM_ENUM_EXT(tx_dmic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1293. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1294. tx_macro_put_dec_enum);
  1295. TX_MACRO_DAPM_ENUM_EXT(tx_dmic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1296. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1297. tx_macro_put_dec_enum);
  1298. TX_MACRO_DAPM_ENUM_EXT(tx_dmic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1299. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1300. tx_macro_put_dec_enum);
  1301. TX_MACRO_DAPM_ENUM_EXT(tx_dmic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1302. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1303. tx_macro_put_dec_enum);
  1304. TX_MACRO_DAPM_ENUM_EXT(tx_dmic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1305. 4, dmic_mux_text, snd_soc_dapm_get_enum_double,
  1306. tx_macro_put_dec_enum);
  1307. static const char * const smic_mux_text[] = {
  1308. "ZERO", "ADC0", "ADC1", "ADC2", "ADC3", "SWR_DMIC0",
  1309. "SWR_DMIC1", "SWR_DMIC2", "SWR_DMIC3", "SWR_DMIC4",
  1310. "SWR_DMIC5", "SWR_DMIC6", "SWR_DMIC7"
  1311. };
  1312. TX_MACRO_DAPM_ENUM_EXT(tx_smic0, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1313. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1314. tx_macro_put_dec_enum);
  1315. TX_MACRO_DAPM_ENUM_EXT(tx_smic1, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1316. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1317. tx_macro_put_dec_enum);
  1318. TX_MACRO_DAPM_ENUM_EXT(tx_smic2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1319. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1320. tx_macro_put_dec_enum);
  1321. TX_MACRO_DAPM_ENUM_EXT(tx_smic3, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1322. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1323. tx_macro_put_dec_enum);
  1324. TX_MACRO_DAPM_ENUM_EXT(tx_smic4, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1325. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1326. tx_macro_put_dec_enum);
  1327. TX_MACRO_DAPM_ENUM_EXT(tx_smic5, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1328. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1329. tx_macro_put_dec_enum);
  1330. TX_MACRO_DAPM_ENUM_EXT(tx_smic6, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1331. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1332. tx_macro_put_dec_enum);
  1333. TX_MACRO_DAPM_ENUM_EXT(tx_smic7, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1334. 0, smic_mux_text, snd_soc_dapm_get_enum_double,
  1335. tx_macro_put_dec_enum);
  1336. static const char * const smic_mux_text_v2[] = {
  1337. "ZERO", "SWR_MIC0", "SWR_MIC1", "SWR_MIC2", "SWR_MIC3",
  1338. "SWR_MIC4", "SWR_MIC5", "SWR_MIC6", "SWR_MIC7",
  1339. "SWR_MIC8", "SWR_MIC9", "SWR_MIC10", "SWR_MIC11"
  1340. };
  1341. TX_MACRO_DAPM_ENUM_EXT(tx_smic0_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX0_CFG0,
  1342. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1343. tx_macro_put_dec_enum);
  1344. TX_MACRO_DAPM_ENUM_EXT(tx_smic1_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX1_CFG0,
  1345. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1346. tx_macro_put_dec_enum);
  1347. TX_MACRO_DAPM_ENUM_EXT(tx_smic2_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX2_CFG0,
  1348. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1349. tx_macro_put_dec_enum);
  1350. TX_MACRO_DAPM_ENUM_EXT(tx_smic3_v2, BOLERO_CDC_TX_INP_MUX_ADC_MUX3_CFG0,
  1351. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1352. tx_macro_put_dec_enum);
  1353. TX_MACRO_DAPM_ENUM_EXT(tx_smic4_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX4_CFG0,
  1354. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1355. tx_macro_put_dec_enum);
  1356. TX_MACRO_DAPM_ENUM_EXT(tx_smic5_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX5_CFG0,
  1357. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1358. tx_macro_put_dec_enum);
  1359. TX_MACRO_DAPM_ENUM_EXT(tx_smic6_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX6_CFG0,
  1360. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1361. tx_macro_put_dec_enum);
  1362. TX_MACRO_DAPM_ENUM_EXT(tx_smic7_v3, BOLERO_CDC_TX_INP_MUX_ADC_MUX7_CFG0,
  1363. 0, smic_mux_text_v2, snd_soc_dapm_get_enum_double,
  1364. tx_macro_put_dec_enum);
  1365. static const char * const dec_mode_mux_text[] = {
  1366. "ADC_DEFAULT", "ADC_LOW_PWR", "ADC_HIGH_PERF",
  1367. };
  1368. static const struct soc_enum dec_mode_mux_enum =
  1369. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dec_mode_mux_text),
  1370. dec_mode_mux_text);
  1371. static const char * const bcs_ch_enum_text[] = {
  1372. "CH0", "CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8", "CH9",
  1373. "CH10", "CH11",
  1374. };
  1375. static const struct soc_enum bcs_ch_enum =
  1376. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bcs_ch_enum_text),
  1377. bcs_ch_enum_text);
  1378. static const struct snd_kcontrol_new tx_aif1_cap_mixer[] = {
  1379. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1380. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1381. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1382. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1383. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1384. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1385. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1386. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1387. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1388. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1389. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1390. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1391. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1392. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1393. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1394. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1395. };
  1396. static const struct snd_kcontrol_new tx_aif2_cap_mixer[] = {
  1397. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1398. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1399. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1400. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1401. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1402. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1403. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1404. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1405. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1406. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1407. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1408. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1409. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1410. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1411. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1412. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1413. };
  1414. static const struct snd_kcontrol_new tx_aif3_cap_mixer[] = {
  1415. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1416. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1417. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1418. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1419. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1420. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1421. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1422. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1423. SOC_SINGLE_EXT("DEC4", SND_SOC_NOPM, TX_MACRO_DEC4, 1, 0,
  1424. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1425. SOC_SINGLE_EXT("DEC5", SND_SOC_NOPM, TX_MACRO_DEC5, 1, 0,
  1426. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1427. SOC_SINGLE_EXT("DEC6", SND_SOC_NOPM, TX_MACRO_DEC6, 1, 0,
  1428. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1429. SOC_SINGLE_EXT("DEC7", SND_SOC_NOPM, TX_MACRO_DEC7, 1, 0,
  1430. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1431. };
  1432. static const struct snd_kcontrol_new tx_aif1_cap_mixer_v2[] = {
  1433. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1434. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1435. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1436. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1437. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1438. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1439. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1440. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1441. };
  1442. static const struct snd_kcontrol_new tx_aif2_cap_mixer_v2[] = {
  1443. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1444. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1445. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1446. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1447. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1448. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1449. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1450. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1451. };
  1452. static const struct snd_kcontrol_new tx_aif3_cap_mixer_v2[] = {
  1453. SOC_SINGLE_EXT("DEC0", SND_SOC_NOPM, TX_MACRO_DEC0, 1, 0,
  1454. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1455. SOC_SINGLE_EXT("DEC1", SND_SOC_NOPM, TX_MACRO_DEC1, 1, 0,
  1456. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1457. SOC_SINGLE_EXT("DEC2", SND_SOC_NOPM, TX_MACRO_DEC2, 1, 0,
  1458. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1459. SOC_SINGLE_EXT("DEC3", SND_SOC_NOPM, TX_MACRO_DEC3, 1, 0,
  1460. tx_macro_tx_mixer_get, tx_macro_tx_mixer_put),
  1461. };
  1462. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_common[] = {
  1463. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1464. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1465. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1466. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1467. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1468. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1469. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1470. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1471. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1472. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1473. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0_v2),
  1474. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1_v2),
  1475. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2_v2),
  1476. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3_v2),
  1477. SND_SOC_DAPM_SUPPLY("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1478. tx_macro_enable_micbias,
  1479. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1480. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1481. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1482. SND_SOC_DAPM_POST_PMD),
  1483. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1484. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1485. SND_SOC_DAPM_POST_PMD),
  1486. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1487. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1488. SND_SOC_DAPM_POST_PMD),
  1489. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1490. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1491. SND_SOC_DAPM_POST_PMD),
  1492. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1493. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1494. SND_SOC_DAPM_POST_PMD),
  1495. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1496. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1497. SND_SOC_DAPM_POST_PMD),
  1498. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1499. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1500. SND_SOC_DAPM_POST_PMD),
  1501. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1502. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1503. SND_SOC_DAPM_POST_PMD),
  1504. SND_SOC_DAPM_INPUT("TX SWR_INPUT"),
  1505. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1506. TX_MACRO_DEC0, 0,
  1507. &tx_dec0_mux, tx_macro_enable_dec,
  1508. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1509. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1510. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1511. TX_MACRO_DEC1, 0,
  1512. &tx_dec1_mux, tx_macro_enable_dec,
  1513. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1514. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1515. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1516. TX_MACRO_DEC2, 0,
  1517. &tx_dec2_mux, tx_macro_enable_dec,
  1518. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1519. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1520. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1521. TX_MACRO_DEC3, 0,
  1522. &tx_dec3_mux, tx_macro_enable_dec,
  1523. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1524. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1525. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1526. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1527. SND_SOC_DAPM_SUPPLY_S("TX_SWR_PWR", -1, SND_SOC_NOPM, 0, 0,
  1528. tx_macro_swr_pwr_event,
  1529. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1530. };
  1531. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v2[] = {
  1532. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1533. TX_MACRO_AIF1_CAP, 0,
  1534. tx_aif1_cap_mixer_v2, ARRAY_SIZE(tx_aif1_cap_mixer_v2)),
  1535. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1536. TX_MACRO_AIF2_CAP, 0,
  1537. tx_aif2_cap_mixer_v2, ARRAY_SIZE(tx_aif2_cap_mixer_v2)),
  1538. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1539. TX_MACRO_AIF3_CAP, 0,
  1540. tx_aif3_cap_mixer_v2, ARRAY_SIZE(tx_aif3_cap_mixer_v2)),
  1541. };
  1542. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets_v3[] = {
  1543. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM,
  1544. TX_MACRO_AIF1_CAP, 0,
  1545. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1546. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM,
  1547. TX_MACRO_AIF2_CAP, 0,
  1548. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1549. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM,
  1550. TX_MACRO_AIF3_CAP, 0,
  1551. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1552. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1553. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1554. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1555. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1556. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4_v3),
  1557. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5_v3),
  1558. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6_v3),
  1559. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7_v3),
  1560. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1561. TX_MACRO_DEC4, 0,
  1562. &tx_dec4_mux, tx_macro_enable_dec,
  1563. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1564. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1565. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1566. TX_MACRO_DEC5, 0,
  1567. &tx_dec5_mux, tx_macro_enable_dec,
  1568. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1569. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1570. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1571. TX_MACRO_DEC6, 0,
  1572. &tx_dec6_mux, tx_macro_enable_dec,
  1573. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1574. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1575. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1576. TX_MACRO_DEC7, 0,
  1577. &tx_dec7_mux, tx_macro_enable_dec,
  1578. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1579. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1580. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1581. tx_macro_tx_swr_clk_event,
  1582. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1583. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1584. tx_macro_va_swr_clk_event,
  1585. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1586. };
  1587. static const struct snd_soc_dapm_widget tx_macro_dapm_widgets[] = {
  1588. SND_SOC_DAPM_AIF_OUT("TX_AIF1 CAP", "TX_AIF1 Capture", 0,
  1589. SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0),
  1590. SND_SOC_DAPM_AIF_OUT("TX_AIF2 CAP", "TX_AIF2 Capture", 0,
  1591. SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0),
  1592. SND_SOC_DAPM_AIF_OUT("TX_AIF3 CAP", "TX_AIF3 Capture", 0,
  1593. SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0),
  1594. SND_SOC_DAPM_MIXER("TX_AIF1_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF1_CAP, 0,
  1595. tx_aif1_cap_mixer, ARRAY_SIZE(tx_aif1_cap_mixer)),
  1596. SND_SOC_DAPM_MIXER("TX_AIF2_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF2_CAP, 0,
  1597. tx_aif2_cap_mixer, ARRAY_SIZE(tx_aif2_cap_mixer)),
  1598. SND_SOC_DAPM_MIXER("TX_AIF3_CAP Mixer", SND_SOC_NOPM, TX_MACRO_AIF3_CAP, 0,
  1599. tx_aif3_cap_mixer, ARRAY_SIZE(tx_aif3_cap_mixer)),
  1600. TX_MACRO_DAPM_MUX("TX DMIC MUX0", 0, tx_dmic0),
  1601. TX_MACRO_DAPM_MUX("TX DMIC MUX1", 0, tx_dmic1),
  1602. TX_MACRO_DAPM_MUX("TX DMIC MUX2", 0, tx_dmic2),
  1603. TX_MACRO_DAPM_MUX("TX DMIC MUX3", 0, tx_dmic3),
  1604. TX_MACRO_DAPM_MUX("TX DMIC MUX4", 0, tx_dmic4),
  1605. TX_MACRO_DAPM_MUX("TX DMIC MUX5", 0, tx_dmic5),
  1606. TX_MACRO_DAPM_MUX("TX DMIC MUX6", 0, tx_dmic6),
  1607. TX_MACRO_DAPM_MUX("TX DMIC MUX7", 0, tx_dmic7),
  1608. TX_MACRO_DAPM_MUX("TX SMIC MUX0", 0, tx_smic0),
  1609. TX_MACRO_DAPM_MUX("TX SMIC MUX1", 0, tx_smic1),
  1610. TX_MACRO_DAPM_MUX("TX SMIC MUX2", 0, tx_smic2),
  1611. TX_MACRO_DAPM_MUX("TX SMIC MUX3", 0, tx_smic3),
  1612. TX_MACRO_DAPM_MUX("TX SMIC MUX4", 0, tx_smic4),
  1613. TX_MACRO_DAPM_MUX("TX SMIC MUX5", 0, tx_smic5),
  1614. TX_MACRO_DAPM_MUX("TX SMIC MUX6", 0, tx_smic6),
  1615. TX_MACRO_DAPM_MUX("TX SMIC MUX7", 0, tx_smic7),
  1616. SND_SOC_DAPM_SUPPLY("TX MIC BIAS1", SND_SOC_NOPM, 0, 0,
  1617. tx_macro_enable_micbias,
  1618. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1619. SND_SOC_DAPM_ADC_E("TX DMIC0", NULL, SND_SOC_NOPM, 0, 0,
  1620. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1621. SND_SOC_DAPM_POST_PMD),
  1622. SND_SOC_DAPM_ADC_E("TX DMIC1", NULL, SND_SOC_NOPM, 0, 0,
  1623. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1624. SND_SOC_DAPM_POST_PMD),
  1625. SND_SOC_DAPM_ADC_E("TX DMIC2", NULL, SND_SOC_NOPM, 0, 0,
  1626. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1627. SND_SOC_DAPM_POST_PMD),
  1628. SND_SOC_DAPM_ADC_E("TX DMIC3", NULL, SND_SOC_NOPM, 0, 0,
  1629. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1630. SND_SOC_DAPM_POST_PMD),
  1631. SND_SOC_DAPM_ADC_E("TX DMIC4", NULL, SND_SOC_NOPM, 0, 0,
  1632. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1633. SND_SOC_DAPM_POST_PMD),
  1634. SND_SOC_DAPM_ADC_E("TX DMIC5", NULL, SND_SOC_NOPM, 0, 0,
  1635. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1636. SND_SOC_DAPM_POST_PMD),
  1637. SND_SOC_DAPM_ADC_E("TX DMIC6", NULL, SND_SOC_NOPM, 0, 0,
  1638. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1639. SND_SOC_DAPM_POST_PMD),
  1640. SND_SOC_DAPM_ADC_E("TX DMIC7", NULL, SND_SOC_NOPM, 0, 0,
  1641. tx_macro_enable_dmic, SND_SOC_DAPM_PRE_PMU |
  1642. SND_SOC_DAPM_POST_PMD),
  1643. SND_SOC_DAPM_INPUT("TX SWR_ADC0"),
  1644. SND_SOC_DAPM_INPUT("TX SWR_ADC1"),
  1645. SND_SOC_DAPM_INPUT("TX SWR_ADC2"),
  1646. SND_SOC_DAPM_INPUT("TX SWR_ADC3"),
  1647. SND_SOC_DAPM_INPUT("TX SWR_DMIC0"),
  1648. SND_SOC_DAPM_INPUT("TX SWR_DMIC1"),
  1649. SND_SOC_DAPM_INPUT("TX SWR_DMIC2"),
  1650. SND_SOC_DAPM_INPUT("TX SWR_DMIC3"),
  1651. SND_SOC_DAPM_INPUT("TX SWR_DMIC4"),
  1652. SND_SOC_DAPM_INPUT("TX SWR_DMIC5"),
  1653. SND_SOC_DAPM_INPUT("TX SWR_DMIC6"),
  1654. SND_SOC_DAPM_INPUT("TX SWR_DMIC7"),
  1655. SND_SOC_DAPM_MUX_E("TX DEC0 MUX", SND_SOC_NOPM,
  1656. TX_MACRO_DEC0, 0,
  1657. &tx_dec0_mux, tx_macro_enable_dec,
  1658. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1659. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1660. SND_SOC_DAPM_MUX_E("TX DEC1 MUX", SND_SOC_NOPM,
  1661. TX_MACRO_DEC1, 0,
  1662. &tx_dec1_mux, tx_macro_enable_dec,
  1663. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1664. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1665. SND_SOC_DAPM_MUX_E("TX DEC2 MUX", SND_SOC_NOPM,
  1666. TX_MACRO_DEC2, 0,
  1667. &tx_dec2_mux, tx_macro_enable_dec,
  1668. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1669. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1670. SND_SOC_DAPM_MUX_E("TX DEC3 MUX", SND_SOC_NOPM,
  1671. TX_MACRO_DEC3, 0,
  1672. &tx_dec3_mux, tx_macro_enable_dec,
  1673. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1674. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1675. SND_SOC_DAPM_MUX_E("TX DEC4 MUX", SND_SOC_NOPM,
  1676. TX_MACRO_DEC4, 0,
  1677. &tx_dec4_mux, tx_macro_enable_dec,
  1678. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1679. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1680. SND_SOC_DAPM_MUX_E("TX DEC5 MUX", SND_SOC_NOPM,
  1681. TX_MACRO_DEC5, 0,
  1682. &tx_dec5_mux, tx_macro_enable_dec,
  1683. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1684. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1685. SND_SOC_DAPM_MUX_E("TX DEC6 MUX", SND_SOC_NOPM,
  1686. TX_MACRO_DEC6, 0,
  1687. &tx_dec6_mux, tx_macro_enable_dec,
  1688. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1689. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1690. SND_SOC_DAPM_MUX_E("TX DEC7 MUX", SND_SOC_NOPM,
  1691. TX_MACRO_DEC7, 0,
  1692. &tx_dec7_mux, tx_macro_enable_dec,
  1693. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1694. SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
  1695. SND_SOC_DAPM_SUPPLY_S("TX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1696. tx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1697. SND_SOC_DAPM_SUPPLY_S("TX_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1698. tx_macro_tx_swr_clk_event,
  1699. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1700. SND_SOC_DAPM_SUPPLY_S("VA_SWR_CLK", 0, SND_SOC_NOPM, 0, 0,
  1701. tx_macro_va_swr_clk_event,
  1702. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1703. };
  1704. static const struct snd_soc_dapm_route tx_audio_map_common[] = {
  1705. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1706. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1707. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1708. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1709. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1710. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1711. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1712. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1713. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1714. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1715. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1716. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1717. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1718. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1719. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1720. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1721. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1722. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1723. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1724. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1725. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1726. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1727. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1728. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1729. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1730. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1731. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1732. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1733. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1734. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1735. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1736. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1737. {"TX SMIC MUX0", "SWR_MIC0", "TX SWR_INPUT"},
  1738. {"TX SMIC MUX0", "SWR_MIC1", "TX SWR_INPUT"},
  1739. {"TX SMIC MUX0", "SWR_MIC2", "TX SWR_INPUT"},
  1740. {"TX SMIC MUX0", "SWR_MIC3", "TX SWR_INPUT"},
  1741. {"TX SMIC MUX0", "SWR_MIC4", "TX SWR_INPUT"},
  1742. {"TX SMIC MUX0", "SWR_MIC5", "TX SWR_INPUT"},
  1743. {"TX SMIC MUX0", "SWR_MIC6", "TX SWR_INPUT"},
  1744. {"TX SMIC MUX0", "SWR_MIC7", "TX SWR_INPUT"},
  1745. {"TX SMIC MUX0", "SWR_MIC8", "TX SWR_INPUT"},
  1746. {"TX SMIC MUX0", "SWR_MIC9", "TX SWR_INPUT"},
  1747. {"TX SMIC MUX0", "SWR_MIC10", "TX SWR_INPUT"},
  1748. {"TX SMIC MUX0", "SWR_MIC11", "TX SWR_INPUT"},
  1749. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  1750. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  1751. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  1752. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  1753. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  1754. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  1755. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  1756. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  1757. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  1758. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  1759. {"TX SMIC MUX1", "SWR_MIC0", "TX SWR_INPUT"},
  1760. {"TX SMIC MUX1", "SWR_MIC1", "TX SWR_INPUT"},
  1761. {"TX SMIC MUX1", "SWR_MIC2", "TX SWR_INPUT"},
  1762. {"TX SMIC MUX1", "SWR_MIC3", "TX SWR_INPUT"},
  1763. {"TX SMIC MUX1", "SWR_MIC4", "TX SWR_INPUT"},
  1764. {"TX SMIC MUX1", "SWR_MIC5", "TX SWR_INPUT"},
  1765. {"TX SMIC MUX1", "SWR_MIC6", "TX SWR_INPUT"},
  1766. {"TX SMIC MUX1", "SWR_MIC7", "TX SWR_INPUT"},
  1767. {"TX SMIC MUX1", "SWR_MIC8", "TX SWR_INPUT"},
  1768. {"TX SMIC MUX1", "SWR_MIC9", "TX SWR_INPUT"},
  1769. {"TX SMIC MUX1", "SWR_MIC10", "TX SWR_INPUT"},
  1770. {"TX SMIC MUX1", "SWR_MIC11", "TX SWR_INPUT"},
  1771. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  1772. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  1773. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  1774. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  1775. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  1776. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  1777. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  1778. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  1779. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  1780. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  1781. {"TX SMIC MUX2", "SWR_MIC0", "TX SWR_INPUT"},
  1782. {"TX SMIC MUX2", "SWR_MIC1", "TX SWR_INPUT"},
  1783. {"TX SMIC MUX2", "SWR_MIC2", "TX SWR_INPUT"},
  1784. {"TX SMIC MUX2", "SWR_MIC3", "TX SWR_INPUT"},
  1785. {"TX SMIC MUX2", "SWR_MIC4", "TX SWR_INPUT"},
  1786. {"TX SMIC MUX2", "SWR_MIC5", "TX SWR_INPUT"},
  1787. {"TX SMIC MUX2", "SWR_MIC6", "TX SWR_INPUT"},
  1788. {"TX SMIC MUX2", "SWR_MIC7", "TX SWR_INPUT"},
  1789. {"TX SMIC MUX2", "SWR_MIC8", "TX SWR_INPUT"},
  1790. {"TX SMIC MUX2", "SWR_MIC9", "TX SWR_INPUT"},
  1791. {"TX SMIC MUX2", "SWR_MIC10", "TX SWR_INPUT"},
  1792. {"TX SMIC MUX2", "SWR_MIC11", "TX SWR_INPUT"},
  1793. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  1794. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  1795. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  1796. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  1797. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  1798. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  1799. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  1800. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  1801. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  1802. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  1803. {"TX SMIC MUX3", "SWR_MIC0", "TX SWR_INPUT"},
  1804. {"TX SMIC MUX3", "SWR_MIC1", "TX SWR_INPUT"},
  1805. {"TX SMIC MUX3", "SWR_MIC2", "TX SWR_INPUT"},
  1806. {"TX SMIC MUX3", "SWR_MIC3", "TX SWR_INPUT"},
  1807. {"TX SMIC MUX3", "SWR_MIC4", "TX SWR_INPUT"},
  1808. {"TX SMIC MUX3", "SWR_MIC5", "TX SWR_INPUT"},
  1809. {"TX SMIC MUX3", "SWR_MIC6", "TX SWR_INPUT"},
  1810. {"TX SMIC MUX3", "SWR_MIC7", "TX SWR_INPUT"},
  1811. {"TX SMIC MUX3", "SWR_MIC8", "TX SWR_INPUT"},
  1812. {"TX SMIC MUX3", "SWR_MIC9", "TX SWR_INPUT"},
  1813. {"TX SMIC MUX3", "SWR_MIC10", "TX SWR_INPUT"},
  1814. {"TX SMIC MUX3", "SWR_MIC11", "TX SWR_INPUT"},
  1815. };
  1816. static const struct snd_soc_dapm_route tx_audio_map_v3[] = {
  1817. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1818. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1819. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1820. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1821. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1822. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1823. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1824. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1825. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1826. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1827. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1828. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1829. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1830. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1831. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1832. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1833. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  1834. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  1835. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  1836. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  1837. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  1838. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  1839. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  1840. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  1841. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  1842. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  1843. {"TX SMIC MUX4", "SWR_MIC0", "TX SWR_INPUT"},
  1844. {"TX SMIC MUX4", "SWR_MIC1", "TX SWR_INPUT"},
  1845. {"TX SMIC MUX4", "SWR_MIC2", "TX SWR_INPUT"},
  1846. {"TX SMIC MUX4", "SWR_MIC3", "TX SWR_INPUT"},
  1847. {"TX SMIC MUX4", "SWR_MIC4", "TX SWR_INPUT"},
  1848. {"TX SMIC MUX4", "SWR_MIC5", "TX SWR_INPUT"},
  1849. {"TX SMIC MUX4", "SWR_MIC6", "TX SWR_INPUT"},
  1850. {"TX SMIC MUX4", "SWR_MIC7", "TX SWR_INPUT"},
  1851. {"TX SMIC MUX4", "SWR_MIC8", "TX SWR_INPUT"},
  1852. {"TX SMIC MUX4", "SWR_MIC9", "TX SWR_INPUT"},
  1853. {"TX SMIC MUX4", "SWR_MIC10", "TX SWR_INPUT"},
  1854. {"TX SMIC MUX4", "SWR_MIC11", "TX SWR_INPUT"},
  1855. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  1856. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  1857. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  1858. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  1859. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  1860. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  1861. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  1862. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  1863. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  1864. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  1865. {"TX SMIC MUX5", "SWR_MIC0", "TX SWR_INPUT"},
  1866. {"TX SMIC MUX5", "SWR_MIC1", "TX SWR_INPUT"},
  1867. {"TX SMIC MUX5", "SWR_MIC2", "TX SWR_INPUT"},
  1868. {"TX SMIC MUX5", "SWR_MIC3", "TX SWR_INPUT"},
  1869. {"TX SMIC MUX5", "SWR_MIC4", "TX SWR_INPUT"},
  1870. {"TX SMIC MUX5", "SWR_MIC5", "TX SWR_INPUT"},
  1871. {"TX SMIC MUX5", "SWR_MIC6", "TX SWR_INPUT"},
  1872. {"TX SMIC MUX5", "SWR_MIC7", "TX SWR_INPUT"},
  1873. {"TX SMIC MUX5", "SWR_MIC8", "TX SWR_INPUT"},
  1874. {"TX SMIC MUX5", "SWR_MIC9", "TX SWR_INPUT"},
  1875. {"TX SMIC MUX5", "SWR_MIC10", "TX SWR_INPUT"},
  1876. {"TX SMIC MUX5", "SWR_MIC11", "TX SWR_INPUT"},
  1877. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  1878. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  1879. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  1880. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  1881. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  1882. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  1883. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  1884. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  1885. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  1886. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  1887. {"TX SMIC MUX6", "SWR_MIC0", "TX SWR_INPUT"},
  1888. {"TX SMIC MUX6", "SWR_MIC1", "TX SWR_INPUT"},
  1889. {"TX SMIC MUX6", "SWR_MIC2", "TX SWR_INPUT"},
  1890. {"TX SMIC MUX6", "SWR_MIC3", "TX SWR_INPUT"},
  1891. {"TX SMIC MUX6", "SWR_MIC4", "TX SWR_INPUT"},
  1892. {"TX SMIC MUX6", "SWR_MIC5", "TX SWR_INPUT"},
  1893. {"TX SMIC MUX6", "SWR_MIC6", "TX SWR_INPUT"},
  1894. {"TX SMIC MUX6", "SWR_MIC7", "TX SWR_INPUT"},
  1895. {"TX SMIC MUX6", "SWR_MIC8", "TX SWR_INPUT"},
  1896. {"TX SMIC MUX6", "SWR_MIC9", "TX SWR_INPUT"},
  1897. {"TX SMIC MUX6", "SWR_MIC10", "TX SWR_INPUT"},
  1898. {"TX SMIC MUX6", "SWR_MIC11", "TX SWR_INPUT"},
  1899. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  1900. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  1901. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  1902. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  1903. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  1904. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  1905. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  1906. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  1907. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  1908. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  1909. {"TX SMIC MUX7", "SWR_MIC0", "TX SWR_INPUT"},
  1910. {"TX SMIC MUX7", "SWR_MIC1", "TX SWR_INPUT"},
  1911. {"TX SMIC MUX7", "SWR_MIC2", "TX SWR_INPUT"},
  1912. {"TX SMIC MUX7", "SWR_MIC3", "TX SWR_INPUT"},
  1913. {"TX SMIC MUX7", "SWR_MIC4", "TX SWR_INPUT"},
  1914. {"TX SMIC MUX7", "SWR_MIC5", "TX SWR_INPUT"},
  1915. {"TX SMIC MUX7", "SWR_MIC6", "TX SWR_INPUT"},
  1916. {"TX SMIC MUX7", "SWR_MIC7", "TX SWR_INPUT"},
  1917. {"TX SMIC MUX7", "SWR_MIC8", "TX SWR_INPUT"},
  1918. {"TX SMIC MUX7", "SWR_MIC9", "TX SWR_INPUT"},
  1919. {"TX SMIC MUX7", "SWR_MIC10", "TX SWR_INPUT"},
  1920. {"TX SMIC MUX7", "SWR_MIC11", "TX SWR_INPUT"},
  1921. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  1922. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  1923. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  1924. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  1925. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  1926. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  1927. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  1928. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  1929. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1930. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1931. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1932. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1933. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1934. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1935. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1936. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1937. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1938. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1939. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1940. {"TX SWR_INPUT", NULL, "TX_SWR_PWR"},
  1941. };
  1942. static const struct snd_soc_dapm_route tx_audio_map[] = {
  1943. {"TX_AIF1 CAP", NULL, "TX_MCLK"},
  1944. {"TX_AIF2 CAP", NULL, "TX_MCLK"},
  1945. {"TX_AIF3 CAP", NULL, "TX_MCLK"},
  1946. {"TX_AIF1 CAP", NULL, "TX_AIF1_CAP Mixer"},
  1947. {"TX_AIF2 CAP", NULL, "TX_AIF2_CAP Mixer"},
  1948. {"TX_AIF3 CAP", NULL, "TX_AIF3_CAP Mixer"},
  1949. {"TX_AIF1_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1950. {"TX_AIF1_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1951. {"TX_AIF1_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1952. {"TX_AIF1_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1953. {"TX_AIF1_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1954. {"TX_AIF1_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1955. {"TX_AIF1_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1956. {"TX_AIF1_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1957. {"TX_AIF2_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1958. {"TX_AIF2_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1959. {"TX_AIF2_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1960. {"TX_AIF2_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1961. {"TX_AIF2_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1962. {"TX_AIF2_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1963. {"TX_AIF2_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1964. {"TX_AIF2_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1965. {"TX_AIF3_CAP Mixer", "DEC0", "TX DEC0 MUX"},
  1966. {"TX_AIF3_CAP Mixer", "DEC1", "TX DEC1 MUX"},
  1967. {"TX_AIF3_CAP Mixer", "DEC2", "TX DEC2 MUX"},
  1968. {"TX_AIF3_CAP Mixer", "DEC3", "TX DEC3 MUX"},
  1969. {"TX_AIF3_CAP Mixer", "DEC4", "TX DEC4 MUX"},
  1970. {"TX_AIF3_CAP Mixer", "DEC5", "TX DEC5 MUX"},
  1971. {"TX_AIF3_CAP Mixer", "DEC6", "TX DEC6 MUX"},
  1972. {"TX_AIF3_CAP Mixer", "DEC7", "TX DEC7 MUX"},
  1973. {"TX DEC0 MUX", NULL, "TX_MCLK"},
  1974. {"TX DEC1 MUX", NULL, "TX_MCLK"},
  1975. {"TX DEC2 MUX", NULL, "TX_MCLK"},
  1976. {"TX DEC3 MUX", NULL, "TX_MCLK"},
  1977. {"TX DEC4 MUX", NULL, "TX_MCLK"},
  1978. {"TX DEC5 MUX", NULL, "TX_MCLK"},
  1979. {"TX DEC6 MUX", NULL, "TX_MCLK"},
  1980. {"TX DEC7 MUX", NULL, "TX_MCLK"},
  1981. {"TX DEC0 MUX", "MSM_DMIC", "TX DMIC MUX0"},
  1982. {"TX DMIC MUX0", "DMIC0", "TX DMIC0"},
  1983. {"TX DMIC MUX0", "DMIC1", "TX DMIC1"},
  1984. {"TX DMIC MUX0", "DMIC2", "TX DMIC2"},
  1985. {"TX DMIC MUX0", "DMIC3", "TX DMIC3"},
  1986. {"TX DMIC MUX0", "DMIC4", "TX DMIC4"},
  1987. {"TX DMIC MUX0", "DMIC5", "TX DMIC5"},
  1988. {"TX DMIC MUX0", "DMIC6", "TX DMIC6"},
  1989. {"TX DMIC MUX0", "DMIC7", "TX DMIC7"},
  1990. {"TX DEC0 MUX", "SWR_MIC", "TX SMIC MUX0"},
  1991. {"TX SMIC MUX0", NULL, "TX_SWR_CLK"},
  1992. {"TX SMIC MUX0", "ADC0", "TX SWR_ADC0"},
  1993. {"TX SMIC MUX0", "ADC1", "TX SWR_ADC1"},
  1994. {"TX SMIC MUX0", "ADC2", "TX SWR_ADC2"},
  1995. {"TX SMIC MUX0", "ADC3", "TX SWR_ADC3"},
  1996. {"TX SMIC MUX0", "SWR_DMIC0", "TX SWR_DMIC0"},
  1997. {"TX SMIC MUX0", "SWR_DMIC1", "TX SWR_DMIC1"},
  1998. {"TX SMIC MUX0", "SWR_DMIC2", "TX SWR_DMIC2"},
  1999. {"TX SMIC MUX0", "SWR_DMIC3", "TX SWR_DMIC3"},
  2000. {"TX SMIC MUX0", "SWR_DMIC4", "TX SWR_DMIC4"},
  2001. {"TX SMIC MUX0", "SWR_DMIC5", "TX SWR_DMIC5"},
  2002. {"TX SMIC MUX0", "SWR_DMIC6", "TX SWR_DMIC6"},
  2003. {"TX SMIC MUX0", "SWR_DMIC7", "TX SWR_DMIC7"},
  2004. {"TX DEC1 MUX", "MSM_DMIC", "TX DMIC MUX1"},
  2005. {"TX DMIC MUX1", "DMIC0", "TX DMIC0"},
  2006. {"TX DMIC MUX1", "DMIC1", "TX DMIC1"},
  2007. {"TX DMIC MUX1", "DMIC2", "TX DMIC2"},
  2008. {"TX DMIC MUX1", "DMIC3", "TX DMIC3"},
  2009. {"TX DMIC MUX1", "DMIC4", "TX DMIC4"},
  2010. {"TX DMIC MUX1", "DMIC5", "TX DMIC5"},
  2011. {"TX DMIC MUX1", "DMIC6", "TX DMIC6"},
  2012. {"TX DMIC MUX1", "DMIC7", "TX DMIC7"},
  2013. {"TX DEC1 MUX", "SWR_MIC", "TX SMIC MUX1"},
  2014. {"TX SMIC MUX1", NULL, "TX_SWR_CLK"},
  2015. {"TX SMIC MUX1", "ADC0", "TX SWR_ADC0"},
  2016. {"TX SMIC MUX1", "ADC1", "TX SWR_ADC1"},
  2017. {"TX SMIC MUX1", "ADC2", "TX SWR_ADC2"},
  2018. {"TX SMIC MUX1", "ADC3", "TX SWR_ADC3"},
  2019. {"TX SMIC MUX1", "SWR_DMIC0", "TX SWR_DMIC0"},
  2020. {"TX SMIC MUX1", "SWR_DMIC1", "TX SWR_DMIC1"},
  2021. {"TX SMIC MUX1", "SWR_DMIC2", "TX SWR_DMIC2"},
  2022. {"TX SMIC MUX1", "SWR_DMIC3", "TX SWR_DMIC3"},
  2023. {"TX SMIC MUX1", "SWR_DMIC4", "TX SWR_DMIC4"},
  2024. {"TX SMIC MUX1", "SWR_DMIC5", "TX SWR_DMIC5"},
  2025. {"TX SMIC MUX1", "SWR_DMIC6", "TX SWR_DMIC6"},
  2026. {"TX SMIC MUX1", "SWR_DMIC7", "TX SWR_DMIC7"},
  2027. {"TX DEC2 MUX", "MSM_DMIC", "TX DMIC MUX2"},
  2028. {"TX DMIC MUX2", "DMIC0", "TX DMIC0"},
  2029. {"TX DMIC MUX2", "DMIC1", "TX DMIC1"},
  2030. {"TX DMIC MUX2", "DMIC2", "TX DMIC2"},
  2031. {"TX DMIC MUX2", "DMIC3", "TX DMIC3"},
  2032. {"TX DMIC MUX2", "DMIC4", "TX DMIC4"},
  2033. {"TX DMIC MUX2", "DMIC5", "TX DMIC5"},
  2034. {"TX DMIC MUX2", "DMIC6", "TX DMIC6"},
  2035. {"TX DMIC MUX2", "DMIC7", "TX DMIC7"},
  2036. {"TX DEC2 MUX", "SWR_MIC", "TX SMIC MUX2"},
  2037. {"TX SMIC MUX2", NULL, "TX_SWR_CLK"},
  2038. {"TX SMIC MUX2", "ADC0", "TX SWR_ADC0"},
  2039. {"TX SMIC MUX2", "ADC1", "TX SWR_ADC1"},
  2040. {"TX SMIC MUX2", "ADC2", "TX SWR_ADC2"},
  2041. {"TX SMIC MUX2", "ADC3", "TX SWR_ADC3"},
  2042. {"TX SMIC MUX2", "SWR_DMIC0", "TX SWR_DMIC0"},
  2043. {"TX SMIC MUX2", "SWR_DMIC1", "TX SWR_DMIC1"},
  2044. {"TX SMIC MUX2", "SWR_DMIC2", "TX SWR_DMIC2"},
  2045. {"TX SMIC MUX2", "SWR_DMIC3", "TX SWR_DMIC3"},
  2046. {"TX SMIC MUX2", "SWR_DMIC4", "TX SWR_DMIC4"},
  2047. {"TX SMIC MUX2", "SWR_DMIC5", "TX SWR_DMIC5"},
  2048. {"TX SMIC MUX2", "SWR_DMIC6", "TX SWR_DMIC6"},
  2049. {"TX SMIC MUX2", "SWR_DMIC7", "TX SWR_DMIC7"},
  2050. {"TX DEC3 MUX", "MSM_DMIC", "TX DMIC MUX3"},
  2051. {"TX DMIC MUX3", "DMIC0", "TX DMIC0"},
  2052. {"TX DMIC MUX3", "DMIC1", "TX DMIC1"},
  2053. {"TX DMIC MUX3", "DMIC2", "TX DMIC2"},
  2054. {"TX DMIC MUX3", "DMIC3", "TX DMIC3"},
  2055. {"TX DMIC MUX3", "DMIC4", "TX DMIC4"},
  2056. {"TX DMIC MUX3", "DMIC5", "TX DMIC5"},
  2057. {"TX DMIC MUX3", "DMIC6", "TX DMIC6"},
  2058. {"TX DMIC MUX3", "DMIC7", "TX DMIC7"},
  2059. {"TX DEC3 MUX", "SWR_MIC", "TX SMIC MUX3"},
  2060. {"TX SMIC MUX3", NULL, "TX_SWR_CLK"},
  2061. {"TX SMIC MUX3", "ADC0", "TX SWR_ADC0"},
  2062. {"TX SMIC MUX3", "ADC1", "TX SWR_ADC1"},
  2063. {"TX SMIC MUX3", "ADC2", "TX SWR_ADC2"},
  2064. {"TX SMIC MUX3", "ADC3", "TX SWR_ADC3"},
  2065. {"TX SMIC MUX3", "SWR_DMIC0", "TX SWR_DMIC0"},
  2066. {"TX SMIC MUX3", "SWR_DMIC1", "TX SWR_DMIC1"},
  2067. {"TX SMIC MUX3", "SWR_DMIC2", "TX SWR_DMIC2"},
  2068. {"TX SMIC MUX3", "SWR_DMIC3", "TX SWR_DMIC3"},
  2069. {"TX SMIC MUX3", "SWR_DMIC4", "TX SWR_DMIC4"},
  2070. {"TX SMIC MUX3", "SWR_DMIC5", "TX SWR_DMIC5"},
  2071. {"TX SMIC MUX3", "SWR_DMIC6", "TX SWR_DMIC6"},
  2072. {"TX SMIC MUX3", "SWR_DMIC7", "TX SWR_DMIC7"},
  2073. {"TX DEC4 MUX", "MSM_DMIC", "TX DMIC MUX4"},
  2074. {"TX DMIC MUX4", "DMIC0", "TX DMIC0"},
  2075. {"TX DMIC MUX4", "DMIC1", "TX DMIC1"},
  2076. {"TX DMIC MUX4", "DMIC2", "TX DMIC2"},
  2077. {"TX DMIC MUX4", "DMIC3", "TX DMIC3"},
  2078. {"TX DMIC MUX4", "DMIC4", "TX DMIC4"},
  2079. {"TX DMIC MUX4", "DMIC5", "TX DMIC5"},
  2080. {"TX DMIC MUX4", "DMIC6", "TX DMIC6"},
  2081. {"TX DMIC MUX4", "DMIC7", "TX DMIC7"},
  2082. {"TX DEC4 MUX", "SWR_MIC", "TX SMIC MUX4"},
  2083. {"TX SMIC MUX4", NULL, "TX_SWR_CLK"},
  2084. {"TX SMIC MUX4", "ADC0", "TX SWR_ADC0"},
  2085. {"TX SMIC MUX4", "ADC1", "TX SWR_ADC1"},
  2086. {"TX SMIC MUX4", "ADC2", "TX SWR_ADC2"},
  2087. {"TX SMIC MUX4", "ADC3", "TX SWR_ADC3"},
  2088. {"TX SMIC MUX4", "SWR_DMIC0", "TX SWR_DMIC0"},
  2089. {"TX SMIC MUX4", "SWR_DMIC1", "TX SWR_DMIC1"},
  2090. {"TX SMIC MUX4", "SWR_DMIC2", "TX SWR_DMIC2"},
  2091. {"TX SMIC MUX4", "SWR_DMIC3", "TX SWR_DMIC3"},
  2092. {"TX SMIC MUX4", "SWR_DMIC4", "TX SWR_DMIC4"},
  2093. {"TX SMIC MUX4", "SWR_DMIC5", "TX SWR_DMIC5"},
  2094. {"TX SMIC MUX4", "SWR_DMIC6", "TX SWR_DMIC6"},
  2095. {"TX SMIC MUX4", "SWR_DMIC7", "TX SWR_DMIC7"},
  2096. {"TX DEC5 MUX", "MSM_DMIC", "TX DMIC MUX5"},
  2097. {"TX DMIC MUX5", "DMIC0", "TX DMIC0"},
  2098. {"TX DMIC MUX5", "DMIC1", "TX DMIC1"},
  2099. {"TX DMIC MUX5", "DMIC2", "TX DMIC2"},
  2100. {"TX DMIC MUX5", "DMIC3", "TX DMIC3"},
  2101. {"TX DMIC MUX5", "DMIC4", "TX DMIC4"},
  2102. {"TX DMIC MUX5", "DMIC5", "TX DMIC5"},
  2103. {"TX DMIC MUX5", "DMIC6", "TX DMIC6"},
  2104. {"TX DMIC MUX5", "DMIC7", "TX DMIC7"},
  2105. {"TX DEC5 MUX", "SWR_MIC", "TX SMIC MUX5"},
  2106. {"TX SMIC MUX5", NULL, "TX_SWR_CLK"},
  2107. {"TX SMIC MUX5", "ADC0", "TX SWR_ADC0"},
  2108. {"TX SMIC MUX5", "ADC1", "TX SWR_ADC1"},
  2109. {"TX SMIC MUX5", "ADC2", "TX SWR_ADC2"},
  2110. {"TX SMIC MUX5", "ADC3", "TX SWR_ADC3"},
  2111. {"TX SMIC MUX5", "SWR_DMIC0", "TX SWR_DMIC0"},
  2112. {"TX SMIC MUX5", "SWR_DMIC1", "TX SWR_DMIC1"},
  2113. {"TX SMIC MUX5", "SWR_DMIC2", "TX SWR_DMIC2"},
  2114. {"TX SMIC MUX5", "SWR_DMIC3", "TX SWR_DMIC3"},
  2115. {"TX SMIC MUX5", "SWR_DMIC4", "TX SWR_DMIC4"},
  2116. {"TX SMIC MUX5", "SWR_DMIC5", "TX SWR_DMIC5"},
  2117. {"TX SMIC MUX5", "SWR_DMIC6", "TX SWR_DMIC6"},
  2118. {"TX SMIC MUX5", "SWR_DMIC7", "TX SWR_DMIC7"},
  2119. {"TX DEC6 MUX", "MSM_DMIC", "TX DMIC MUX6"},
  2120. {"TX DMIC MUX6", "DMIC0", "TX DMIC0"},
  2121. {"TX DMIC MUX6", "DMIC1", "TX DMIC1"},
  2122. {"TX DMIC MUX6", "DMIC2", "TX DMIC2"},
  2123. {"TX DMIC MUX6", "DMIC3", "TX DMIC3"},
  2124. {"TX DMIC MUX6", "DMIC4", "TX DMIC4"},
  2125. {"TX DMIC MUX6", "DMIC5", "TX DMIC5"},
  2126. {"TX DMIC MUX6", "DMIC6", "TX DMIC6"},
  2127. {"TX DMIC MUX6", "DMIC7", "TX DMIC7"},
  2128. {"TX DEC6 MUX", "SWR_MIC", "TX SMIC MUX6"},
  2129. {"TX SMIC MUX6", NULL, "TX_SWR_CLK"},
  2130. {"TX SMIC MUX6", "ADC0", "TX SWR_ADC0"},
  2131. {"TX SMIC MUX6", "ADC1", "TX SWR_ADC1"},
  2132. {"TX SMIC MUX6", "ADC2", "TX SWR_ADC2"},
  2133. {"TX SMIC MUX6", "ADC3", "TX SWR_ADC3"},
  2134. {"TX SMIC MUX6", "SWR_DMIC0", "TX SWR_DMIC0"},
  2135. {"TX SMIC MUX6", "SWR_DMIC1", "TX SWR_DMIC1"},
  2136. {"TX SMIC MUX6", "SWR_DMIC2", "TX SWR_DMIC2"},
  2137. {"TX SMIC MUX6", "SWR_DMIC3", "TX SWR_DMIC3"},
  2138. {"TX SMIC MUX6", "SWR_DMIC4", "TX SWR_DMIC4"},
  2139. {"TX SMIC MUX6", "SWR_DMIC5", "TX SWR_DMIC5"},
  2140. {"TX SMIC MUX6", "SWR_DMIC6", "TX SWR_DMIC6"},
  2141. {"TX SMIC MUX6", "SWR_DMIC7", "TX SWR_DMIC7"},
  2142. {"TX DEC7 MUX", "MSM_DMIC", "TX DMIC MUX7"},
  2143. {"TX DMIC MUX7", "DMIC0", "TX DMIC0"},
  2144. {"TX DMIC MUX7", "DMIC1", "TX DMIC1"},
  2145. {"TX DMIC MUX7", "DMIC2", "TX DMIC2"},
  2146. {"TX DMIC MUX7", "DMIC3", "TX DMIC3"},
  2147. {"TX DMIC MUX7", "DMIC4", "TX DMIC4"},
  2148. {"TX DMIC MUX7", "DMIC5", "TX DMIC5"},
  2149. {"TX DMIC MUX7", "DMIC6", "TX DMIC6"},
  2150. {"TX DMIC MUX7", "DMIC7", "TX DMIC7"},
  2151. {"TX DEC7 MUX", "SWR_MIC", "TX SMIC MUX7"},
  2152. {"TX SMIC MUX7", NULL, "TX_SWR_CLK"},
  2153. {"TX SMIC MUX7", "ADC0", "TX SWR_ADC0"},
  2154. {"TX SMIC MUX7", "ADC1", "TX SWR_ADC1"},
  2155. {"TX SMIC MUX7", "ADC2", "TX SWR_ADC2"},
  2156. {"TX SMIC MUX7", "ADC3", "TX SWR_ADC3"},
  2157. {"TX SMIC MUX7", "SWR_DMIC0", "TX SWR_DMIC0"},
  2158. {"TX SMIC MUX7", "SWR_DMIC1", "TX SWR_DMIC1"},
  2159. {"TX SMIC MUX7", "SWR_DMIC2", "TX SWR_DMIC2"},
  2160. {"TX SMIC MUX7", "SWR_DMIC3", "TX SWR_DMIC3"},
  2161. {"TX SMIC MUX7", "SWR_DMIC4", "TX SWR_DMIC4"},
  2162. {"TX SMIC MUX7", "SWR_DMIC5", "TX SWR_DMIC5"},
  2163. {"TX SMIC MUX7", "SWR_DMIC6", "TX SWR_DMIC6"},
  2164. {"TX SMIC MUX7", "SWR_DMIC7", "TX SWR_DMIC7"},
  2165. };
  2166. static const struct snd_kcontrol_new tx_macro_snd_controls_common[] = {
  2167. SOC_SINGLE_S8_TLV("TX_DEC0 Volume",
  2168. BOLERO_CDC_TX0_TX_VOL_CTL,
  2169. -84, 40, digital_gain),
  2170. SOC_SINGLE_S8_TLV("TX_DEC1 Volume",
  2171. BOLERO_CDC_TX1_TX_VOL_CTL,
  2172. -84, 40, digital_gain),
  2173. SOC_SINGLE_S8_TLV("TX_DEC2 Volume",
  2174. BOLERO_CDC_TX2_TX_VOL_CTL,
  2175. -84, 40, digital_gain),
  2176. SOC_SINGLE_S8_TLV("TX_DEC3 Volume",
  2177. BOLERO_CDC_TX3_TX_VOL_CTL,
  2178. -84, 40, digital_gain),
  2179. SOC_SINGLE_EXT("TX LPI Enable", 0, 0, 1, 0,
  2180. tx_macro_lpi_get, tx_macro_lpi_put),
  2181. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  2182. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2183. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  2184. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2185. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  2186. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2187. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  2188. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2189. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  2190. tx_macro_get_bcs, tx_macro_set_bcs),
  2191. SOC_ENUM_EXT("BCS Channel", bcs_ch_enum,
  2192. tx_macro_bcs_ch_get, tx_macro_bcs_ch_put),
  2193. SOC_ENUM_EXT("BCS CH_SEL", bcs_ch_sel_mux_enum,
  2194. tx_macro_get_bcs_ch_sel, tx_macro_put_bcs_ch_sel),
  2195. };
  2196. static const struct snd_kcontrol_new tx_macro_snd_controls_v3[] = {
  2197. SOC_SINGLE_S8_TLV("TX_DEC4 Volume",
  2198. BOLERO_CDC_TX4_TX_VOL_CTL,
  2199. -84, 40, digital_gain),
  2200. SOC_SINGLE_S8_TLV("TX_DEC5 Volume",
  2201. BOLERO_CDC_TX5_TX_VOL_CTL,
  2202. -84, 40, digital_gain),
  2203. SOC_SINGLE_S8_TLV("TX_DEC6 Volume",
  2204. BOLERO_CDC_TX6_TX_VOL_CTL,
  2205. -84, 40, digital_gain),
  2206. SOC_SINGLE_S8_TLV("TX_DEC7 Volume",
  2207. BOLERO_CDC_TX7_TX_VOL_CTL,
  2208. -84, 40, digital_gain),
  2209. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  2210. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2211. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  2212. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2213. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  2214. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2215. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  2216. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2217. };
  2218. static const struct snd_kcontrol_new tx_macro_snd_controls[] = {
  2219. SOC_SINGLE_S8_TLV("TX_DEC0 Volume",
  2220. BOLERO_CDC_TX0_TX_VOL_CTL,
  2221. -84, 40, digital_gain),
  2222. SOC_SINGLE_S8_TLV("TX_DEC1 Volume",
  2223. BOLERO_CDC_TX1_TX_VOL_CTL,
  2224. -84, 40, digital_gain),
  2225. SOC_SINGLE_S8_TLV("TX_DEC2 Volume",
  2226. BOLERO_CDC_TX2_TX_VOL_CTL,
  2227. -84, 40, digital_gain),
  2228. SOC_SINGLE_S8_TLV("TX_DEC3 Volume",
  2229. BOLERO_CDC_TX3_TX_VOL_CTL,
  2230. -84, 40, digital_gain),
  2231. SOC_SINGLE_S8_TLV("TX_DEC4 Volume",
  2232. BOLERO_CDC_TX4_TX_VOL_CTL,
  2233. -84, 40, digital_gain),
  2234. SOC_SINGLE_S8_TLV("TX_DEC5 Volume",
  2235. BOLERO_CDC_TX5_TX_VOL_CTL,
  2236. -84, 40, digital_gain),
  2237. SOC_SINGLE_S8_TLV("TX_DEC6 Volume",
  2238. BOLERO_CDC_TX6_TX_VOL_CTL,
  2239. -84, 40, digital_gain),
  2240. SOC_SINGLE_S8_TLV("TX_DEC7 Volume",
  2241. BOLERO_CDC_TX7_TX_VOL_CTL,
  2242. -84, 40, digital_gain),
  2243. SOC_ENUM_EXT("DEC0 MODE", dec_mode_mux_enum,
  2244. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2245. SOC_ENUM_EXT("DEC1 MODE", dec_mode_mux_enum,
  2246. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2247. SOC_ENUM_EXT("DEC2 MODE", dec_mode_mux_enum,
  2248. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2249. SOC_ENUM_EXT("DEC3 MODE", dec_mode_mux_enum,
  2250. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2251. SOC_ENUM_EXT("DEC4 MODE", dec_mode_mux_enum,
  2252. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2253. SOC_ENUM_EXT("DEC5 MODE", dec_mode_mux_enum,
  2254. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2255. SOC_ENUM_EXT("DEC6 MODE", dec_mode_mux_enum,
  2256. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2257. SOC_ENUM_EXT("DEC7 MODE", dec_mode_mux_enum,
  2258. tx_macro_dec_mode_get, tx_macro_dec_mode_put),
  2259. SOC_ENUM("TX0 HPF cut off", cf_dec0_enum),
  2260. SOC_ENUM("TX1 HPF cut off", cf_dec1_enum),
  2261. SOC_ENUM("TX2 HPF cut off", cf_dec2_enum),
  2262. SOC_ENUM("TX3 HPF cut off", cf_dec3_enum),
  2263. SOC_ENUM("TX4 HPF cut off", cf_dec4_enum),
  2264. SOC_ENUM("TX5 HPF cut off", cf_dec5_enum),
  2265. SOC_ENUM("TX6 HPF cut off", cf_dec6_enum),
  2266. SOC_ENUM("TX7 HPF cut off", cf_dec7_enum),
  2267. SOC_SINGLE_EXT("DEC0_BCS Switch", SND_SOC_NOPM, 0, 1, 0,
  2268. tx_macro_get_bcs, tx_macro_set_bcs),
  2269. };
  2270. static int tx_macro_register_event_listener(struct snd_soc_component *component,
  2271. bool enable)
  2272. {
  2273. struct device *tx_dev = NULL;
  2274. struct tx_macro_priv *tx_priv = NULL;
  2275. int ret = 0;
  2276. if (!component)
  2277. return -EINVAL;
  2278. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2279. if (!tx_dev) {
  2280. dev_err(component->dev,
  2281. "%s: null device for macro!\n", __func__);
  2282. return -EINVAL;
  2283. }
  2284. tx_priv = dev_get_drvdata(tx_dev);
  2285. if (!tx_priv) {
  2286. dev_err(component->dev,
  2287. "%s: priv is null for macro!\n", __func__);
  2288. return -EINVAL;
  2289. }
  2290. if (tx_priv->swr_ctrl_data &&
  2291. (!tx_priv->tx_swr_clk_cnt || !tx_priv->va_swr_clk_cnt)) {
  2292. if (enable) {
  2293. ret = swrm_wcd_notify(
  2294. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2295. SWR_REGISTER_WAKEUP, NULL);
  2296. msm_cdc_pinctrl_set_wakeup_capable(
  2297. tx_priv->tx_swr_gpio_p, false);
  2298. } else {
  2299. msm_cdc_pinctrl_set_wakeup_capable(
  2300. tx_priv->tx_swr_gpio_p, true);
  2301. ret = swrm_wcd_notify(
  2302. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2303. SWR_DEREGISTER_WAKEUP, NULL);
  2304. }
  2305. }
  2306. return ret;
  2307. }
  2308. static int tx_macro_tx_va_mclk_enable(struct tx_macro_priv *tx_priv,
  2309. struct regmap *regmap, int clk_type,
  2310. bool enable)
  2311. {
  2312. int ret = 0, clk_tx_ret = 0;
  2313. trace_printk("%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  2314. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  2315. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  2316. dev_dbg(tx_priv->dev,
  2317. "%s: clock type %s, enable: %s tx_mclk_users: %d\n",
  2318. __func__, (clk_type ? "VA_MCLK" : "TX_MCLK"),
  2319. (enable ? "enable" : "disable"), tx_priv->tx_mclk_users);
  2320. if (enable) {
  2321. if (tx_priv->swr_clk_users == 0) {
  2322. trace_printk("%s: tx swr clk users 0\n", __func__);
  2323. ret = msm_cdc_pinctrl_select_active_state(
  2324. tx_priv->tx_swr_gpio_p);
  2325. if (ret < 0) {
  2326. dev_err_ratelimited(tx_priv->dev,
  2327. "%s: tx swr pinctrl enable failed\n",
  2328. __func__);
  2329. goto exit;
  2330. }
  2331. }
  2332. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2333. TX_CORE_CLK,
  2334. TX_CORE_CLK,
  2335. true);
  2336. if (clk_type == TX_MCLK) {
  2337. trace_printk("%s: requesting TX_MCLK\n", __func__);
  2338. ret = tx_macro_mclk_enable(tx_priv, 1);
  2339. if (ret < 0) {
  2340. if (tx_priv->swr_clk_users == 0)
  2341. msm_cdc_pinctrl_select_sleep_state(
  2342. tx_priv->tx_swr_gpio_p);
  2343. dev_err_ratelimited(tx_priv->dev,
  2344. "%s: request clock enable failed\n",
  2345. __func__);
  2346. goto done;
  2347. }
  2348. }
  2349. if (clk_type == VA_MCLK) {
  2350. trace_printk("%s: requesting VA_MCLK\n", __func__);
  2351. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2352. TX_CORE_CLK,
  2353. VA_CORE_CLK,
  2354. true);
  2355. if (ret < 0) {
  2356. if (tx_priv->swr_clk_users == 0)
  2357. msm_cdc_pinctrl_select_sleep_state(
  2358. tx_priv->tx_swr_gpio_p);
  2359. dev_err_ratelimited(tx_priv->dev,
  2360. "%s: swr request clk failed\n",
  2361. __func__);
  2362. goto done;
  2363. }
  2364. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2365. true);
  2366. if (tx_priv->tx_mclk_users == 0) {
  2367. regmap_update_bits(regmap,
  2368. BOLERO_CDC_TX_TOP_CSR_FREQ_MCLK,
  2369. 0x01, 0x01);
  2370. regmap_update_bits(regmap,
  2371. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2372. 0x01, 0x01);
  2373. regmap_update_bits(regmap,
  2374. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2375. 0x01, 0x01);
  2376. }
  2377. tx_priv->tx_mclk_users++;
  2378. }
  2379. if (tx_priv->swr_clk_users == 0) {
  2380. dev_dbg(tx_priv->dev, "%s: reset_swr: %d\n",
  2381. __func__, tx_priv->reset_swr);
  2382. trace_printk("%s: reset_swr: %d\n",
  2383. __func__, tx_priv->reset_swr);
  2384. if (tx_priv->reset_swr)
  2385. regmap_update_bits(regmap,
  2386. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2387. 0x02, 0x02);
  2388. regmap_update_bits(regmap,
  2389. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2390. 0x01, 0x01);
  2391. if (tx_priv->reset_swr)
  2392. regmap_update_bits(regmap,
  2393. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2394. 0x02, 0x00);
  2395. tx_priv->reset_swr = false;
  2396. }
  2397. if (!clk_tx_ret)
  2398. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2399. TX_CORE_CLK,
  2400. TX_CORE_CLK,
  2401. false);
  2402. tx_priv->swr_clk_users++;
  2403. } else {
  2404. if (tx_priv->swr_clk_users <= 0) {
  2405. dev_err_ratelimited(tx_priv->dev,
  2406. "tx swrm clock users already 0\n");
  2407. tx_priv->swr_clk_users = 0;
  2408. return 0;
  2409. }
  2410. clk_tx_ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2411. TX_CORE_CLK,
  2412. TX_CORE_CLK,
  2413. true);
  2414. tx_priv->swr_clk_users--;
  2415. if (tx_priv->swr_clk_users == 0)
  2416. regmap_update_bits(regmap,
  2417. BOLERO_CDC_TX_CLK_RST_CTRL_SWR_CONTROL,
  2418. 0x01, 0x00);
  2419. if (clk_type == TX_MCLK)
  2420. tx_macro_mclk_enable(tx_priv, 0);
  2421. if (clk_type == VA_MCLK) {
  2422. if (tx_priv->tx_mclk_users <= 0) {
  2423. dev_err(tx_priv->dev, "%s: clock already disabled\n",
  2424. __func__);
  2425. tx_priv->tx_mclk_users = 0;
  2426. goto tx_clk;
  2427. }
  2428. tx_priv->tx_mclk_users--;
  2429. if (tx_priv->tx_mclk_users == 0) {
  2430. regmap_update_bits(regmap,
  2431. BOLERO_CDC_TX_CLK_RST_CTRL_FS_CNT_CONTROL,
  2432. 0x01, 0x00);
  2433. regmap_update_bits(regmap,
  2434. BOLERO_CDC_TX_CLK_RST_CTRL_MCLK_CONTROL,
  2435. 0x01, 0x00);
  2436. }
  2437. bolero_clk_rsc_fs_gen_request(tx_priv->dev,
  2438. false);
  2439. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2440. TX_CORE_CLK,
  2441. VA_CORE_CLK,
  2442. false);
  2443. if (ret < 0) {
  2444. dev_err_ratelimited(tx_priv->dev,
  2445. "%s: swr request clk failed\n",
  2446. __func__);
  2447. goto done;
  2448. }
  2449. }
  2450. tx_clk:
  2451. if (!clk_tx_ret)
  2452. ret = bolero_clk_rsc_request_clock(tx_priv->dev,
  2453. TX_CORE_CLK,
  2454. TX_CORE_CLK,
  2455. false);
  2456. if (tx_priv->swr_clk_users == 0) {
  2457. ret = msm_cdc_pinctrl_select_sleep_state(
  2458. tx_priv->tx_swr_gpio_p);
  2459. if (ret < 0) {
  2460. dev_err_ratelimited(tx_priv->dev,
  2461. "%s: tx swr pinctrl disable failed\n",
  2462. __func__);
  2463. goto exit;
  2464. }
  2465. }
  2466. }
  2467. return 0;
  2468. done:
  2469. if (!clk_tx_ret)
  2470. bolero_clk_rsc_request_clock(tx_priv->dev,
  2471. TX_CORE_CLK,
  2472. TX_CORE_CLK,
  2473. false);
  2474. exit:
  2475. trace_printk("%s: exit\n", __func__);
  2476. return ret;
  2477. }
  2478. static int tx_macro_clk_div_get(struct snd_soc_component *component)
  2479. {
  2480. struct device *tx_dev = NULL;
  2481. struct tx_macro_priv *tx_priv = NULL;
  2482. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2483. return -EINVAL;
  2484. return tx_priv->dmic_clk_div;
  2485. }
  2486. static int tx_macro_core_vote(void *handle, bool enable)
  2487. {
  2488. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2489. if (tx_priv == NULL) {
  2490. pr_err("%s: tx priv data is NULL\n", __func__);
  2491. return -EINVAL;
  2492. }
  2493. if (enable) {
  2494. pm_runtime_get_sync(tx_priv->dev);
  2495. pm_runtime_put_autosuspend(tx_priv->dev);
  2496. pm_runtime_mark_last_busy(tx_priv->dev);
  2497. }
  2498. if (bolero_check_core_votes(tx_priv->dev))
  2499. return 0;
  2500. else
  2501. return -EINVAL;
  2502. }
  2503. static int tx_macro_swrm_clock(void *handle, bool enable)
  2504. {
  2505. struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
  2506. struct regmap *regmap = dev_get_regmap(tx_priv->dev->parent, NULL);
  2507. int ret = 0;
  2508. if (regmap == NULL) {
  2509. dev_err(tx_priv->dev, "%s: regmap is NULL\n", __func__);
  2510. return -EINVAL;
  2511. }
  2512. mutex_lock(&tx_priv->swr_clk_lock);
  2513. trace_printk("%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  2514. __func__,
  2515. (enable ? "enable" : "disable"),
  2516. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  2517. dev_dbg(tx_priv->dev,
  2518. "%s: swrm clock %s tx_swr_clk_cnt: %d va_swr_clk_cnt: %d\n",
  2519. __func__, (enable ? "enable" : "disable"),
  2520. tx_priv->tx_swr_clk_cnt, tx_priv->va_swr_clk_cnt);
  2521. if (enable) {
  2522. pm_runtime_get_sync(tx_priv->dev);
  2523. if (tx_priv->va_swr_clk_cnt && !tx_priv->tx_swr_clk_cnt) {
  2524. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2525. VA_MCLK, enable);
  2526. if (ret) {
  2527. pm_runtime_mark_last_busy(tx_priv->dev);
  2528. pm_runtime_put_autosuspend(tx_priv->dev);
  2529. goto done;
  2530. }
  2531. tx_priv->va_clk_status++;
  2532. } else {
  2533. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2534. TX_MCLK, enable);
  2535. if (ret) {
  2536. pm_runtime_mark_last_busy(tx_priv->dev);
  2537. pm_runtime_put_autosuspend(tx_priv->dev);
  2538. goto done;
  2539. }
  2540. tx_priv->tx_clk_status++;
  2541. }
  2542. pm_runtime_mark_last_busy(tx_priv->dev);
  2543. pm_runtime_put_autosuspend(tx_priv->dev);
  2544. } else {
  2545. if (tx_priv->va_clk_status && !tx_priv->tx_clk_status) {
  2546. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2547. VA_MCLK, enable);
  2548. if (ret)
  2549. goto done;
  2550. --tx_priv->va_clk_status;
  2551. } else if (!tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2552. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2553. TX_MCLK, enable);
  2554. if (ret)
  2555. goto done;
  2556. --tx_priv->tx_clk_status;
  2557. } else if (tx_priv->va_clk_status && tx_priv->tx_clk_status) {
  2558. if (!tx_priv->va_swr_clk_cnt && tx_priv->tx_swr_clk_cnt) {
  2559. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2560. VA_MCLK, enable);
  2561. if (ret)
  2562. goto done;
  2563. --tx_priv->va_clk_status;
  2564. } else {
  2565. ret = tx_macro_tx_va_mclk_enable(tx_priv, regmap,
  2566. TX_MCLK, enable);
  2567. if (ret)
  2568. goto done;
  2569. --tx_priv->tx_clk_status;
  2570. }
  2571. } else {
  2572. dev_dbg(tx_priv->dev,
  2573. "%s: Both clocks are disabled\n", __func__);
  2574. }
  2575. }
  2576. trace_printk("%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  2577. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  2578. tx_priv->va_clk_status);
  2579. dev_dbg(tx_priv->dev,
  2580. "%s: swrm clock users %d tx_clk_sts_cnt: %d va_clk_sts_cnt: %d\n",
  2581. __func__, tx_priv->swr_clk_users, tx_priv->tx_clk_status,
  2582. tx_priv->va_clk_status);
  2583. done:
  2584. mutex_unlock(&tx_priv->swr_clk_lock);
  2585. return ret;
  2586. }
  2587. static int tx_macro_validate_dmic_sample_rate(u32 dmic_sample_rate,
  2588. struct tx_macro_priv *tx_priv)
  2589. {
  2590. u32 div_factor = TX_MACRO_CLK_DIV_2;
  2591. u32 mclk_rate = TX_MACRO_MCLK_FREQ;
  2592. if (dmic_sample_rate == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED ||
  2593. mclk_rate % dmic_sample_rate != 0)
  2594. goto undefined_rate;
  2595. div_factor = mclk_rate / dmic_sample_rate;
  2596. switch (div_factor) {
  2597. case 2:
  2598. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  2599. break;
  2600. case 3:
  2601. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_3;
  2602. break;
  2603. case 4:
  2604. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_4;
  2605. break;
  2606. case 6:
  2607. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_6;
  2608. break;
  2609. case 8:
  2610. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_8;
  2611. break;
  2612. case 16:
  2613. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_16;
  2614. break;
  2615. default:
  2616. /* Any other DIV factor is invalid */
  2617. goto undefined_rate;
  2618. }
  2619. /* Valid dmic DIV factors */
  2620. dev_dbg(tx_priv->dev, "%s: DMIC_DIV = %u, mclk_rate = %u\n",
  2621. __func__, div_factor, mclk_rate);
  2622. return dmic_sample_rate;
  2623. undefined_rate:
  2624. dev_dbg(tx_priv->dev, "%s: Invalid rate %d, for mclk %d\n",
  2625. __func__, dmic_sample_rate, mclk_rate);
  2626. dmic_sample_rate = TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED;
  2627. return dmic_sample_rate;
  2628. }
  2629. static const struct tx_macro_reg_mask_val tx_macro_reg_init[] = {
  2630. {BOLERO_CDC_TX0_TX_PATH_SEC7, 0x3F, 0x0A},
  2631. };
  2632. static int tx_macro_init(struct snd_soc_component *component)
  2633. {
  2634. struct snd_soc_dapm_context *dapm =
  2635. snd_soc_component_get_dapm(component);
  2636. int ret = 0, i = 0;
  2637. struct device *tx_dev = NULL;
  2638. struct tx_macro_priv *tx_priv = NULL;
  2639. tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
  2640. if (!tx_dev) {
  2641. dev_err(component->dev,
  2642. "%s: null device for macro!\n", __func__);
  2643. return -EINVAL;
  2644. }
  2645. tx_priv = dev_get_drvdata(tx_dev);
  2646. if (!tx_priv) {
  2647. dev_err(component->dev,
  2648. "%s: priv is null for macro!\n", __func__);
  2649. return -EINVAL;
  2650. }
  2651. tx_priv->lpi_enable = false;
  2652. tx_priv->register_event_listener = false;
  2653. tx_priv->version = bolero_get_version(tx_dev);
  2654. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2655. ret = snd_soc_dapm_new_controls(dapm,
  2656. tx_macro_dapm_widgets_common,
  2657. ARRAY_SIZE(tx_macro_dapm_widgets_common));
  2658. if (ret < 0) {
  2659. dev_err(tx_dev, "%s: Failed to add controls\n",
  2660. __func__);
  2661. return ret;
  2662. }
  2663. if (tx_priv->version == BOLERO_VERSION_2_1)
  2664. ret = snd_soc_dapm_new_controls(dapm,
  2665. tx_macro_dapm_widgets_v2,
  2666. ARRAY_SIZE(tx_macro_dapm_widgets_v2));
  2667. else if (tx_priv->version == BOLERO_VERSION_2_0)
  2668. ret = snd_soc_dapm_new_controls(dapm,
  2669. tx_macro_dapm_widgets_v3,
  2670. ARRAY_SIZE(tx_macro_dapm_widgets_v3));
  2671. if (ret < 0) {
  2672. dev_err(tx_dev, "%s: Failed to add controls\n",
  2673. __func__);
  2674. return ret;
  2675. }
  2676. } else {
  2677. ret = snd_soc_dapm_new_controls(dapm, tx_macro_dapm_widgets,
  2678. ARRAY_SIZE(tx_macro_dapm_widgets));
  2679. if (ret < 0) {
  2680. dev_err(tx_dev, "%s: Failed to add controls\n",
  2681. __func__);
  2682. return ret;
  2683. }
  2684. }
  2685. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2686. ret = snd_soc_dapm_add_routes(dapm,
  2687. tx_audio_map_common,
  2688. ARRAY_SIZE(tx_audio_map_common));
  2689. if (ret < 0) {
  2690. dev_err(tx_dev, "%s: Failed to add routes\n",
  2691. __func__);
  2692. return ret;
  2693. }
  2694. if (tx_priv->version == BOLERO_VERSION_2_0)
  2695. ret = snd_soc_dapm_add_routes(dapm,
  2696. tx_audio_map_v3,
  2697. ARRAY_SIZE(tx_audio_map_v3));
  2698. if (ret < 0) {
  2699. dev_err(tx_dev, "%s: Failed to add routes\n",
  2700. __func__);
  2701. return ret;
  2702. }
  2703. } else {
  2704. ret = snd_soc_dapm_add_routes(dapm, tx_audio_map,
  2705. ARRAY_SIZE(tx_audio_map));
  2706. if (ret < 0) {
  2707. dev_err(tx_dev, "%s: Failed to add routes\n",
  2708. __func__);
  2709. return ret;
  2710. }
  2711. }
  2712. ret = snd_soc_dapm_new_widgets(dapm->card);
  2713. if (ret < 0) {
  2714. dev_err(tx_dev, "%s: Failed to add widgets\n", __func__);
  2715. return ret;
  2716. }
  2717. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2718. ret = snd_soc_add_component_controls(component,
  2719. tx_macro_snd_controls_common,
  2720. ARRAY_SIZE(tx_macro_snd_controls_common));
  2721. if (ret < 0) {
  2722. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2723. __func__);
  2724. return ret;
  2725. }
  2726. if (tx_priv->version == BOLERO_VERSION_2_0)
  2727. ret = snd_soc_add_component_controls(component,
  2728. tx_macro_snd_controls_v3,
  2729. ARRAY_SIZE(tx_macro_snd_controls_v3));
  2730. if (ret < 0) {
  2731. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2732. __func__);
  2733. return ret;
  2734. }
  2735. } else {
  2736. ret = snd_soc_add_component_controls(component,
  2737. tx_macro_snd_controls,
  2738. ARRAY_SIZE(tx_macro_snd_controls));
  2739. if (ret < 0) {
  2740. dev_err(tx_dev, "%s: Failed to add snd_ctls\n",
  2741. __func__);
  2742. return ret;
  2743. }
  2744. }
  2745. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF1 Capture");
  2746. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF2 Capture");
  2747. snd_soc_dapm_ignore_suspend(dapm, "TX_AIF3 Capture");
  2748. if (tx_priv->version >= BOLERO_VERSION_2_0) {
  2749. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_INPUT");
  2750. } else {
  2751. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC0");
  2752. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC1");
  2753. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC2");
  2754. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_ADC3");
  2755. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC0");
  2756. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC1");
  2757. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC2");
  2758. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC3");
  2759. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC4");
  2760. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC5");
  2761. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC6");
  2762. snd_soc_dapm_ignore_suspend(dapm, "TX SWR_DMIC7");
  2763. }
  2764. snd_soc_dapm_sync(dapm);
  2765. for (i = 0; i < NUM_DECIMATORS; i++) {
  2766. tx_priv->tx_hpf_work[i].tx_priv = tx_priv;
  2767. tx_priv->tx_hpf_work[i].decimator = i;
  2768. INIT_DELAYED_WORK(&tx_priv->tx_hpf_work[i].dwork,
  2769. tx_macro_tx_hpf_corner_freq_callback);
  2770. }
  2771. for (i = 0; i < NUM_DECIMATORS; i++) {
  2772. tx_priv->tx_mute_dwork[i].tx_priv = tx_priv;
  2773. tx_priv->tx_mute_dwork[i].decimator = i;
  2774. INIT_DELAYED_WORK(&tx_priv->tx_mute_dwork[i].dwork,
  2775. tx_macro_mute_update_callback);
  2776. }
  2777. tx_priv->component = component;
  2778. for (i = 0; i < ARRAY_SIZE(tx_macro_reg_init); i++)
  2779. snd_soc_component_update_bits(component,
  2780. tx_macro_reg_init[i].reg,
  2781. tx_macro_reg_init[i].mask,
  2782. tx_macro_reg_init[i].val);
  2783. return 0;
  2784. }
  2785. static int tx_macro_deinit(struct snd_soc_component *component)
  2786. {
  2787. struct device *tx_dev = NULL;
  2788. struct tx_macro_priv *tx_priv = NULL;
  2789. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2790. return -EINVAL;
  2791. tx_priv->component = NULL;
  2792. return 0;
  2793. }
  2794. static void tx_macro_add_child_devices(struct work_struct *work)
  2795. {
  2796. struct tx_macro_priv *tx_priv = NULL;
  2797. struct platform_device *pdev = NULL;
  2798. struct device_node *node = NULL;
  2799. struct tx_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2800. int ret = 0;
  2801. u16 count = 0, ctrl_num = 0;
  2802. struct tx_macro_swr_ctrl_platform_data *platdata = NULL;
  2803. char plat_dev_name[TX_MACRO_SWR_STRING_LEN] = "";
  2804. bool tx_swr_master_node = false;
  2805. tx_priv = container_of(work, struct tx_macro_priv,
  2806. tx_macro_add_child_devices_work);
  2807. if (!tx_priv) {
  2808. pr_err("%s: Memory for tx_priv does not exist\n",
  2809. __func__);
  2810. return;
  2811. }
  2812. if (!tx_priv->dev) {
  2813. pr_err("%s: tx dev does not exist\n", __func__);
  2814. return;
  2815. }
  2816. if (!tx_priv->dev->of_node) {
  2817. dev_err(tx_priv->dev,
  2818. "%s: DT node for tx_priv does not exist\n", __func__);
  2819. return;
  2820. }
  2821. platdata = &tx_priv->swr_plat_data;
  2822. tx_priv->child_count = 0;
  2823. for_each_available_child_of_node(tx_priv->dev->of_node, node) {
  2824. tx_swr_master_node = false;
  2825. if (strnstr(node->name, "tx_swr_master",
  2826. strlen("tx_swr_master")) != NULL)
  2827. tx_swr_master_node = true;
  2828. if (tx_swr_master_node)
  2829. strlcpy(plat_dev_name, "tx_swr_ctrl",
  2830. (TX_MACRO_SWR_STRING_LEN - 1));
  2831. else
  2832. strlcpy(plat_dev_name, node->name,
  2833. (TX_MACRO_SWR_STRING_LEN - 1));
  2834. pdev = platform_device_alloc(plat_dev_name, -1);
  2835. if (!pdev) {
  2836. dev_err(tx_priv->dev, "%s: pdev memory alloc failed\n",
  2837. __func__);
  2838. ret = -ENOMEM;
  2839. goto err;
  2840. }
  2841. pdev->dev.parent = tx_priv->dev;
  2842. pdev->dev.of_node = node;
  2843. if (tx_swr_master_node) {
  2844. ret = platform_device_add_data(pdev, platdata,
  2845. sizeof(*platdata));
  2846. if (ret) {
  2847. dev_err(&pdev->dev,
  2848. "%s: cannot add plat data ctrl:%d\n",
  2849. __func__, ctrl_num);
  2850. goto fail_pdev_add;
  2851. }
  2852. }
  2853. ret = platform_device_add(pdev);
  2854. if (ret) {
  2855. dev_err(&pdev->dev,
  2856. "%s: Cannot add platform device\n",
  2857. __func__);
  2858. goto fail_pdev_add;
  2859. }
  2860. if (tx_swr_master_node) {
  2861. temp = krealloc(swr_ctrl_data,
  2862. (ctrl_num + 1) * sizeof(
  2863. struct tx_macro_swr_ctrl_data),
  2864. GFP_KERNEL);
  2865. if (!temp) {
  2866. ret = -ENOMEM;
  2867. goto fail_pdev_add;
  2868. }
  2869. swr_ctrl_data = temp;
  2870. swr_ctrl_data[ctrl_num].tx_swr_pdev = pdev;
  2871. ctrl_num++;
  2872. dev_dbg(&pdev->dev,
  2873. "%s: Added soundwire ctrl device(s)\n",
  2874. __func__);
  2875. tx_priv->swr_ctrl_data = swr_ctrl_data;
  2876. }
  2877. if (tx_priv->child_count < TX_MACRO_CHILD_DEVICES_MAX)
  2878. tx_priv->pdev_child_devices[
  2879. tx_priv->child_count++] = pdev;
  2880. else
  2881. goto err;
  2882. }
  2883. return;
  2884. fail_pdev_add:
  2885. for (count = 0; count < tx_priv->child_count; count++)
  2886. platform_device_put(tx_priv->pdev_child_devices[count]);
  2887. err:
  2888. return;
  2889. }
  2890. static int tx_macro_set_port_map(struct snd_soc_component *component,
  2891. u32 usecase, u32 size, void *data)
  2892. {
  2893. struct device *tx_dev = NULL;
  2894. struct tx_macro_priv *tx_priv = NULL;
  2895. struct swrm_port_config port_cfg;
  2896. int ret = 0;
  2897. if (!tx_macro_get_data(component, &tx_dev, &tx_priv, __func__))
  2898. return -EINVAL;
  2899. memset(&port_cfg, 0, sizeof(port_cfg));
  2900. port_cfg.uc = usecase;
  2901. port_cfg.size = size;
  2902. port_cfg.params = data;
  2903. if (tx_priv->swr_ctrl_data)
  2904. ret = swrm_wcd_notify(
  2905. tx_priv->swr_ctrl_data[0].tx_swr_pdev,
  2906. SWR_SET_PORT_MAP, &port_cfg);
  2907. return ret;
  2908. }
  2909. static void tx_macro_init_ops(struct macro_ops *ops,
  2910. char __iomem *tx_io_base)
  2911. {
  2912. memset(ops, 0, sizeof(struct macro_ops));
  2913. ops->init = tx_macro_init;
  2914. ops->exit = tx_macro_deinit;
  2915. ops->io_base = tx_io_base;
  2916. ops->dai_ptr = tx_macro_dai;
  2917. ops->num_dais = ARRAY_SIZE(tx_macro_dai);
  2918. ops->event_handler = tx_macro_event_handler;
  2919. ops->reg_wake_irq = tx_macro_reg_wake_irq;
  2920. ops->set_port_map = tx_macro_set_port_map;
  2921. ops->clk_div_get = tx_macro_clk_div_get;
  2922. ops->reg_evt_listener = tx_macro_register_event_listener;
  2923. ops->clk_enable = __tx_macro_mclk_enable;
  2924. }
  2925. static int tx_macro_probe(struct platform_device *pdev)
  2926. {
  2927. struct macro_ops ops = {0};
  2928. struct tx_macro_priv *tx_priv = NULL;
  2929. u32 tx_base_addr = 0, sample_rate = 0;
  2930. char __iomem *tx_io_base = NULL;
  2931. int ret = 0;
  2932. const char *dmic_sample_rate = "qcom,tx-dmic-sample-rate";
  2933. u32 is_used_tx_swr_gpio = 1;
  2934. const char *is_used_tx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  2935. if (!bolero_is_va_macro_registered(&pdev->dev)) {
  2936. dev_err(&pdev->dev,
  2937. "%s: va-macro not registered yet, defer\n", __func__);
  2938. return -EPROBE_DEFER;
  2939. }
  2940. tx_priv = devm_kzalloc(&pdev->dev, sizeof(struct tx_macro_priv),
  2941. GFP_KERNEL);
  2942. if (!tx_priv)
  2943. return -ENOMEM;
  2944. platform_set_drvdata(pdev, tx_priv);
  2945. tx_priv->dev = &pdev->dev;
  2946. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2947. &tx_base_addr);
  2948. if (ret) {
  2949. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2950. __func__, "reg");
  2951. return ret;
  2952. }
  2953. dev_set_drvdata(&pdev->dev, tx_priv);
  2954. if (of_find_property(pdev->dev.of_node, is_used_tx_swr_gpio_dt,
  2955. NULL)) {
  2956. ret = of_property_read_u32(pdev->dev.of_node,
  2957. is_used_tx_swr_gpio_dt,
  2958. &is_used_tx_swr_gpio);
  2959. if (ret) {
  2960. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  2961. __func__, is_used_tx_swr_gpio_dt);
  2962. is_used_tx_swr_gpio = 1;
  2963. }
  2964. }
  2965. tx_priv->tx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2966. "qcom,tx-swr-gpios", 0);
  2967. if (!tx_priv->tx_swr_gpio_p && is_used_tx_swr_gpio) {
  2968. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2969. __func__);
  2970. return -EINVAL;
  2971. }
  2972. if (msm_cdc_pinctrl_get_state(tx_priv->tx_swr_gpio_p) < 0 &&
  2973. is_used_tx_swr_gpio) {
  2974. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  2975. __func__);
  2976. return -EPROBE_DEFER;
  2977. }
  2978. tx_io_base = devm_ioremap(&pdev->dev,
  2979. tx_base_addr, TX_MACRO_MAX_OFFSET);
  2980. if (!tx_io_base) {
  2981. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2982. return -ENOMEM;
  2983. }
  2984. tx_priv->tx_io_base = tx_io_base;
  2985. ret = of_property_read_u32(pdev->dev.of_node, dmic_sample_rate,
  2986. &sample_rate);
  2987. if (ret) {
  2988. dev_err(&pdev->dev,
  2989. "%s: could not find sample_rate entry in dt\n",
  2990. __func__);
  2991. tx_priv->dmic_clk_div = TX_MACRO_CLK_DIV_2;
  2992. } else {
  2993. if (tx_macro_validate_dmic_sample_rate(
  2994. sample_rate, tx_priv) == TX_MACRO_DMIC_SAMPLE_RATE_UNDEFINED)
  2995. return -EINVAL;
  2996. }
  2997. if (is_used_tx_swr_gpio) {
  2998. tx_priv->reset_swr = true;
  2999. INIT_WORK(&tx_priv->tx_macro_add_child_devices_work,
  3000. tx_macro_add_child_devices);
  3001. tx_priv->swr_plat_data.handle = (void *) tx_priv;
  3002. tx_priv->swr_plat_data.read = NULL;
  3003. tx_priv->swr_plat_data.write = NULL;
  3004. tx_priv->swr_plat_data.bulk_write = NULL;
  3005. tx_priv->swr_plat_data.clk = tx_macro_swrm_clock;
  3006. tx_priv->swr_plat_data.core_vote = tx_macro_core_vote;
  3007. tx_priv->swr_plat_data.handle_irq = NULL;
  3008. mutex_init(&tx_priv->swr_clk_lock);
  3009. }
  3010. tx_priv->is_used_tx_swr_gpio = is_used_tx_swr_gpio;
  3011. mutex_init(&tx_priv->mclk_lock);
  3012. tx_macro_init_ops(&ops, tx_io_base);
  3013. ops.clk_id_req = TX_CORE_CLK;
  3014. ops.default_clk_id = TX_CORE_CLK;
  3015. ret = bolero_register_macro(&pdev->dev, TX_MACRO, &ops);
  3016. if (ret) {
  3017. dev_err(&pdev->dev,
  3018. "%s: register macro failed\n", __func__);
  3019. goto err_reg_macro;
  3020. }
  3021. if (is_used_tx_swr_gpio)
  3022. schedule_work(&tx_priv->tx_macro_add_child_devices_work);
  3023. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  3024. pm_runtime_use_autosuspend(&pdev->dev);
  3025. pm_runtime_set_suspended(&pdev->dev);
  3026. pm_suspend_ignore_children(&pdev->dev, true);
  3027. pm_runtime_enable(&pdev->dev);
  3028. return 0;
  3029. err_reg_macro:
  3030. mutex_destroy(&tx_priv->mclk_lock);
  3031. if (is_used_tx_swr_gpio)
  3032. mutex_destroy(&tx_priv->swr_clk_lock);
  3033. return ret;
  3034. }
  3035. static int tx_macro_remove(struct platform_device *pdev)
  3036. {
  3037. struct tx_macro_priv *tx_priv = NULL;
  3038. u16 count = 0;
  3039. tx_priv = platform_get_drvdata(pdev);
  3040. if (!tx_priv)
  3041. return -EINVAL;
  3042. if (tx_priv->is_used_tx_swr_gpio) {
  3043. if (tx_priv->swr_ctrl_data)
  3044. kfree(tx_priv->swr_ctrl_data);
  3045. for (count = 0; count < tx_priv->child_count &&
  3046. count < TX_MACRO_CHILD_DEVICES_MAX; count++)
  3047. platform_device_unregister(
  3048. tx_priv->pdev_child_devices[count]);
  3049. }
  3050. pm_runtime_disable(&pdev->dev);
  3051. pm_runtime_set_suspended(&pdev->dev);
  3052. mutex_destroy(&tx_priv->mclk_lock);
  3053. if (tx_priv->is_used_tx_swr_gpio)
  3054. mutex_destroy(&tx_priv->swr_clk_lock);
  3055. bolero_unregister_macro(&pdev->dev, TX_MACRO);
  3056. return 0;
  3057. }
  3058. static const struct of_device_id tx_macro_dt_match[] = {
  3059. {.compatible = "qcom,tx-macro"},
  3060. {}
  3061. };
  3062. static const struct dev_pm_ops bolero_dev_pm_ops = {
  3063. SET_SYSTEM_SLEEP_PM_OPS(
  3064. pm_runtime_force_suspend,
  3065. pm_runtime_force_resume
  3066. )
  3067. SET_RUNTIME_PM_OPS(
  3068. bolero_runtime_suspend,
  3069. bolero_runtime_resume,
  3070. NULL
  3071. )
  3072. };
  3073. static struct platform_driver tx_macro_driver = {
  3074. .driver = {
  3075. .name = "tx_macro",
  3076. .owner = THIS_MODULE,
  3077. .pm = &bolero_dev_pm_ops,
  3078. .of_match_table = tx_macro_dt_match,
  3079. .suppress_bind_attrs = true,
  3080. },
  3081. .probe = tx_macro_probe,
  3082. .remove = tx_macro_remove,
  3083. };
  3084. module_platform_driver(tx_macro_driver);
  3085. MODULE_DESCRIPTION("TX macro driver");
  3086. MODULE_LICENSE("GPL v2");