tx-macro.c 108 KB

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