rx-macro.c 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/module.h>
  5. #include <linux/init.h>
  6. #include <linux/io.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/clk.h>
  9. #include <linux/pm_runtime.h>
  10. #include <sound/soc.h>
  11. #include <sound/pcm.h>
  12. #include <sound/pcm_params.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 RX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  23. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  24. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  25. SNDRV_PCM_RATE_384000)
  26. /* Fractional Rates */
  27. #define RX_MACRO_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  28. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  29. #define RX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  30. SNDRV_PCM_FMTBIT_S24_LE |\
  31. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  32. #define RX_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  33. SNDRV_PCM_RATE_48000)
  34. #define RX_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  35. SNDRV_PCM_FMTBIT_S24_LE |\
  36. SNDRV_PCM_FMTBIT_S24_3LE)
  37. #define SAMPLING_RATE_44P1KHZ 44100
  38. #define SAMPLING_RATE_88P2KHZ 88200
  39. #define SAMPLING_RATE_176P4KHZ 176400
  40. #define SAMPLING_RATE_352P8KHZ 352800
  41. #define RX_MACRO_MAX_OFFSET 0x1000
  42. #define RX_MACRO_MAX_DMA_CH_PER_PORT 2
  43. #define RX_SWR_STRING_LEN 80
  44. #define RX_MACRO_CHILD_DEVICES_MAX 3
  45. #define RX_MACRO_INTERP_MUX_NUM_INPUTS 3
  46. #define RX_MACRO_SIDETONE_IIR_COEFF_MAX 5
  47. #define STRING(name) #name
  48. #define RX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  49. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  50. static const struct snd_kcontrol_new name##_mux = \
  51. SOC_DAPM_ENUM(STRING(name), name##_enum)
  52. #define RX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  53. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  54. static const struct snd_kcontrol_new name##_mux = \
  55. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  56. #define RX_MACRO_DAPM_MUX(name, shift, kctl) \
  57. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  58. #define RX_MACRO_RX_PATH_OFFSET 0x80
  59. #define RX_MACRO_COMP_OFFSET 0x40
  60. #define MAX_IMPED_PARAMS 6
  61. #define RX_MACRO_EC_MIX_TX0_MASK 0xf0
  62. #define RX_MACRO_EC_MIX_TX1_MASK 0x0f
  63. #define RX_MACRO_EC_MIX_TX2_MASK 0x0f
  64. struct wcd_imped_val {
  65. u32 imped_val;
  66. u8 index;
  67. };
  68. static const struct wcd_imped_val imped_index[] = {
  69. {4, 0},
  70. {5, 1},
  71. {6, 2},
  72. {7, 3},
  73. {8, 4},
  74. {9, 5},
  75. {10, 6},
  76. {11, 7},
  77. {12, 8},
  78. {13, 9},
  79. };
  80. struct rx_macro_reg_mask_val {
  81. u16 reg;
  82. u8 mask;
  83. u8 val;
  84. };
  85. static const struct rx_macro_reg_mask_val imped_table[][MAX_IMPED_PARAMS] = {
  86. {
  87. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf2},
  88. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf2},
  89. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  90. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf2},
  91. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf2},
  92. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  93. },
  94. {
  95. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf4},
  96. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf4},
  97. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  98. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf4},
  99. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf4},
  100. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  101. },
  102. {
  103. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf7},
  104. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf7},
  105. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  106. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf7},
  107. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf7},
  108. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  109. },
  110. {
  111. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf9},
  112. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf9},
  113. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  114. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf9},
  115. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf9},
  116. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  117. },
  118. {
  119. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfa},
  120. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfa},
  121. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  122. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfa},
  123. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfa},
  124. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  125. },
  126. {
  127. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfb},
  128. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfb},
  129. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  130. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfb},
  131. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfb},
  132. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  133. },
  134. {
  135. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfc},
  136. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfc},
  137. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  138. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfc},
  139. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfc},
  140. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  141. },
  142. {
  143. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  144. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  145. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  146. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  147. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  148. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  149. },
  150. {
  151. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  152. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  153. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  154. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  155. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  156. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  157. },
  158. };
  159. enum {
  160. INTERP_HPHL,
  161. INTERP_HPHR,
  162. INTERP_AUX,
  163. INTERP_MAX
  164. };
  165. enum {
  166. RX_MACRO_RX0,
  167. RX_MACRO_RX1,
  168. RX_MACRO_RX2,
  169. RX_MACRO_RX3,
  170. RX_MACRO_RX4,
  171. RX_MACRO_RX5,
  172. RX_MACRO_PORTS_MAX
  173. };
  174. enum {
  175. RX_MACRO_COMP1, /* HPH_L */
  176. RX_MACRO_COMP2, /* HPH_R */
  177. RX_MACRO_COMP_MAX
  178. };
  179. enum {
  180. RX_MACRO_EC0_MUX = 0,
  181. RX_MACRO_EC1_MUX,
  182. RX_MACRO_EC2_MUX,
  183. RX_MACRO_EC_MUX_MAX,
  184. };
  185. enum {
  186. INTn_1_INP_SEL_ZERO = 0,
  187. INTn_1_INP_SEL_DEC0,
  188. INTn_1_INP_SEL_DEC1,
  189. INTn_1_INP_SEL_IIR0,
  190. INTn_1_INP_SEL_IIR1,
  191. INTn_1_INP_SEL_RX0,
  192. INTn_1_INP_SEL_RX1,
  193. INTn_1_INP_SEL_RX2,
  194. INTn_1_INP_SEL_RX3,
  195. INTn_1_INP_SEL_RX4,
  196. INTn_1_INP_SEL_RX5,
  197. };
  198. enum {
  199. INTn_2_INP_SEL_ZERO = 0,
  200. INTn_2_INP_SEL_RX0,
  201. INTn_2_INP_SEL_RX1,
  202. INTn_2_INP_SEL_RX2,
  203. INTn_2_INP_SEL_RX3,
  204. INTn_2_INP_SEL_RX4,
  205. INTn_2_INP_SEL_RX5,
  206. };
  207. enum {
  208. INTERP_MAIN_PATH,
  209. INTERP_MIX_PATH,
  210. };
  211. /* Codec supports 2 IIR filters */
  212. enum {
  213. IIR0 = 0,
  214. IIR1,
  215. IIR_MAX,
  216. };
  217. /* Each IIR has 5 Filter Stages */
  218. enum {
  219. BAND1 = 0,
  220. BAND2,
  221. BAND3,
  222. BAND4,
  223. BAND5,
  224. BAND_MAX,
  225. };
  226. struct rx_macro_idle_detect_config {
  227. u8 hph_idle_thr;
  228. u8 hph_idle_detect_en;
  229. };
  230. struct interp_sample_rate {
  231. int sample_rate;
  232. int rate_val;
  233. };
  234. static struct interp_sample_rate sr_val_tbl[] = {
  235. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  236. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  237. {176400, 0xB}, {352800, 0xC},
  238. };
  239. struct rx_macro_bcl_pmic_params {
  240. u8 id;
  241. u8 sid;
  242. u8 ppid;
  243. };
  244. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  245. struct snd_pcm_hw_params *params,
  246. struct snd_soc_dai *dai);
  247. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  248. unsigned int *tx_num, unsigned int *tx_slot,
  249. unsigned int *rx_num, unsigned int *rx_slot);
  250. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  251. struct snd_ctl_elem_value *ucontrol);
  252. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  253. struct snd_ctl_elem_value *ucontrol);
  254. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  255. struct snd_ctl_elem_value *ucontrol);
  256. static int rx_macro_enable_interp_clk(struct snd_soc_component *component,
  257. int event, int interp_idx);
  258. /* Hold instance to soundwire platform device */
  259. struct rx_swr_ctrl_data {
  260. struct platform_device *rx_swr_pdev;
  261. };
  262. struct rx_swr_ctrl_platform_data {
  263. void *handle; /* holds codec private data */
  264. int (*read)(void *handle, int reg);
  265. int (*write)(void *handle, int reg, int val);
  266. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  267. int (*clk)(void *handle, bool enable);
  268. int (*handle_irq)(void *handle,
  269. irqreturn_t (*swrm_irq_handler)(int irq,
  270. void *data),
  271. void *swrm_handle,
  272. int action);
  273. };
  274. enum {
  275. RX_MACRO_AIF_INVALID = 0,
  276. RX_MACRO_AIF1_PB,
  277. RX_MACRO_AIF2_PB,
  278. RX_MACRO_AIF3_PB,
  279. RX_MACRO_AIF4_PB,
  280. RX_MACRO_AIF_ECHO,
  281. RX_MACRO_MAX_DAIS,
  282. };
  283. enum {
  284. RX_MACRO_AIF1_CAP = 0,
  285. RX_MACRO_AIF2_CAP,
  286. RX_MACRO_AIF3_CAP,
  287. RX_MACRO_MAX_AIF_CAP_DAIS
  288. };
  289. /*
  290. * @dev: rx macro device pointer
  291. * @comp_enabled: compander enable mixer value set
  292. * @prim_int_users: Users of interpolator
  293. * @rx_mclk_users: RX MCLK users count
  294. * @vi_feed_value: VI sense mask
  295. * @swr_clk_lock: to lock swr master clock operations
  296. * @swr_ctrl_data: SoundWire data structure
  297. * @swr_plat_data: Soundwire platform data
  298. * @rx_macro_add_child_devices_work: work for adding child devices
  299. * @rx_swr_gpio_p: used by pinctrl API
  300. * @component: codec handle
  301. */
  302. struct rx_macro_priv {
  303. struct device *dev;
  304. int comp_enabled[RX_MACRO_COMP_MAX];
  305. /* Main path clock users count */
  306. int main_clk_users[INTERP_MAX];
  307. int rx_port_value[RX_MACRO_PORTS_MAX];
  308. u16 prim_int_users[INTERP_MAX];
  309. int rx_mclk_users;
  310. int swr_clk_users;
  311. bool dapm_mclk_enable;
  312. bool reset_swr;
  313. int clsh_users;
  314. int rx_mclk_cnt;
  315. bool is_native_on;
  316. bool is_ear_mode_on;
  317. bool dev_up;
  318. bool hph_pwr_mode;
  319. bool hph_hd2_mode;
  320. struct mutex mclk_lock;
  321. struct mutex swr_clk_lock;
  322. struct rx_swr_ctrl_data *swr_ctrl_data;
  323. struct rx_swr_ctrl_platform_data swr_plat_data;
  324. struct work_struct rx_macro_add_child_devices_work;
  325. struct device_node *rx_swr_gpio_p;
  326. struct snd_soc_component *component;
  327. unsigned long active_ch_mask[RX_MACRO_MAX_DAIS];
  328. unsigned long active_ch_cnt[RX_MACRO_MAX_DAIS];
  329. u16 bit_width[RX_MACRO_MAX_DAIS];
  330. char __iomem *rx_io_base;
  331. char __iomem *rx_mclk_mode_muxsel;
  332. struct rx_macro_idle_detect_config idle_det_cfg;
  333. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  334. [RX_MACRO_SIDETONE_IIR_COEFF_MAX * 4];
  335. struct platform_device *pdev_child_devices
  336. [RX_MACRO_CHILD_DEVICES_MAX];
  337. int child_count;
  338. int is_softclip_on;
  339. int softclip_clk_users;
  340. struct rx_macro_bcl_pmic_params bcl_pmic_params;
  341. u16 clk_id;
  342. u16 default_clk_id;
  343. };
  344. static struct snd_soc_dai_driver rx_macro_dai[];
  345. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  346. static const char * const rx_int_mix_mux_text[] = {
  347. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  348. };
  349. static const char * const rx_prim_mix_text[] = {
  350. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  351. "RX3", "RX4", "RX5"
  352. };
  353. static const char * const rx_sidetone_mix_text[] = {
  354. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  355. };
  356. static const char * const iir_inp_mux_text[] = {
  357. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3",
  358. "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  359. };
  360. static const char * const rx_int_dem_inp_mux_text[] = {
  361. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  362. };
  363. static const char * const rx_int0_1_interp_mux_text[] = {
  364. "ZERO", "RX INT0_1 MIX1",
  365. };
  366. static const char * const rx_int1_1_interp_mux_text[] = {
  367. "ZERO", "RX INT1_1 MIX1",
  368. };
  369. static const char * const rx_int2_1_interp_mux_text[] = {
  370. "ZERO", "RX INT2_1 MIX1",
  371. };
  372. static const char * const rx_int0_2_interp_mux_text[] = {
  373. "ZERO", "RX INT0_2 MUX",
  374. };
  375. static const char * const rx_int1_2_interp_mux_text[] = {
  376. "ZERO", "RX INT1_2 MUX",
  377. };
  378. static const char * const rx_int2_2_interp_mux_text[] = {
  379. "ZERO", "RX INT2_2 MUX",
  380. };
  381. static const char *const rx_macro_mux_text[] = {
  382. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  383. };
  384. static const char *const rx_macro_ear_mode_text[] = {"OFF", "ON"};
  385. static const struct soc_enum rx_macro_ear_mode_enum =
  386. SOC_ENUM_SINGLE_EXT(2, rx_macro_ear_mode_text);
  387. static const char *const rx_macro_hph_hd2_mode_text[] = {"OFF", "ON"};
  388. static const struct soc_enum rx_macro_hph_hd2_mode_enum =
  389. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_hd2_mode_text);
  390. static const char *const rx_macro_hph_pwr_mode_text[] = {"ULP", "LOHIFI"};
  391. static const struct soc_enum rx_macro_hph_pwr_mode_enum =
  392. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_pwr_mode_text);
  393. static const char * const rx_macro_vbat_bcl_gsm_mode_text[] = {"OFF", "ON"};
  394. static const struct soc_enum rx_macro_vbat_bcl_gsm_mode_enum =
  395. SOC_ENUM_SINGLE_EXT(2, rx_macro_vbat_bcl_gsm_mode_text);
  396. static const struct snd_kcontrol_new rx_int2_1_vbat_mix_switch[] = {
  397. SOC_DAPM_SINGLE("RX AUX VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
  398. };
  399. static const char * const hph_idle_detect_text[] = {"OFF", "ON"};
  400. static SOC_ENUM_SINGLE_EXT_DECL(hph_idle_detect_enum, hph_idle_detect_text);
  401. RX_MACRO_DAPM_ENUM(rx_int0_2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  402. rx_int_mix_mux_text);
  403. RX_MACRO_DAPM_ENUM(rx_int1_2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  404. rx_int_mix_mux_text);
  405. RX_MACRO_DAPM_ENUM(rx_int2_2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  406. rx_int_mix_mux_text);
  407. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  408. rx_prim_mix_text);
  409. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  410. rx_prim_mix_text);
  411. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  412. rx_prim_mix_text);
  413. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  414. rx_prim_mix_text);
  415. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  416. rx_prim_mix_text);
  417. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  418. rx_prim_mix_text);
  419. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  420. rx_prim_mix_text);
  421. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  422. rx_prim_mix_text);
  423. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  424. rx_prim_mix_text);
  425. RX_MACRO_DAPM_ENUM(rx_int0_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  426. rx_sidetone_mix_text);
  427. RX_MACRO_DAPM_ENUM(rx_int1_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  428. rx_sidetone_mix_text);
  429. RX_MACRO_DAPM_ENUM(rx_int2_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  430. rx_sidetone_mix_text);
  431. RX_MACRO_DAPM_ENUM(iir0_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  432. iir_inp_mux_text);
  433. RX_MACRO_DAPM_ENUM(iir0_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  434. iir_inp_mux_text);
  435. RX_MACRO_DAPM_ENUM(iir0_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  436. iir_inp_mux_text);
  437. RX_MACRO_DAPM_ENUM(iir0_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  438. iir_inp_mux_text);
  439. RX_MACRO_DAPM_ENUM(iir1_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  440. iir_inp_mux_text);
  441. RX_MACRO_DAPM_ENUM(iir1_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  442. iir_inp_mux_text);
  443. RX_MACRO_DAPM_ENUM(iir1_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  444. iir_inp_mux_text);
  445. RX_MACRO_DAPM_ENUM(iir1_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  446. iir_inp_mux_text);
  447. RX_MACRO_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0,
  448. rx_int0_1_interp_mux_text);
  449. RX_MACRO_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0,
  450. rx_int1_1_interp_mux_text);
  451. RX_MACRO_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0,
  452. rx_int2_1_interp_mux_text);
  453. RX_MACRO_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0,
  454. rx_int0_2_interp_mux_text);
  455. RX_MACRO_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0,
  456. rx_int1_2_interp_mux_text);
  457. RX_MACRO_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0,
  458. rx_int2_2_interp_mux_text);
  459. RX_MACRO_DAPM_ENUM_EXT(rx_int0_dem_inp, BOLERO_CDC_RX_RX0_RX_PATH_CFG1, 0,
  460. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  461. rx_macro_int_dem_inp_mux_put);
  462. RX_MACRO_DAPM_ENUM_EXT(rx_int1_dem_inp, BOLERO_CDC_RX_RX1_RX_PATH_CFG1, 0,
  463. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  464. rx_macro_int_dem_inp_mux_put);
  465. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx0, SND_SOC_NOPM, 0, rx_macro_mux_text,
  466. rx_macro_mux_get, rx_macro_mux_put);
  467. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx1, SND_SOC_NOPM, 0, rx_macro_mux_text,
  468. rx_macro_mux_get, rx_macro_mux_put);
  469. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx2, SND_SOC_NOPM, 0, rx_macro_mux_text,
  470. rx_macro_mux_get, rx_macro_mux_put);
  471. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx3, SND_SOC_NOPM, 0, rx_macro_mux_text,
  472. rx_macro_mux_get, rx_macro_mux_put);
  473. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx4, SND_SOC_NOPM, 0, rx_macro_mux_text,
  474. rx_macro_mux_get, rx_macro_mux_put);
  475. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx5, SND_SOC_NOPM, 0, rx_macro_mux_text,
  476. rx_macro_mux_get, rx_macro_mux_put);
  477. static const char * const rx_echo_mux_text[] = {
  478. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2"
  479. };
  480. static const struct soc_enum rx_mix_tx2_mux_enum =
  481. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5, 0, 4,
  482. rx_echo_mux_text);
  483. static const struct snd_kcontrol_new rx_mix_tx2_mux =
  484. SOC_DAPM_ENUM("RX MIX TX2_MUX Mux", rx_mix_tx2_mux_enum);
  485. static const struct soc_enum rx_mix_tx1_mux_enum =
  486. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0, 4,
  487. rx_echo_mux_text);
  488. static const struct snd_kcontrol_new rx_mix_tx1_mux =
  489. SOC_DAPM_ENUM("RX MIX TX1_MUX Mux", rx_mix_tx1_mux_enum);
  490. static const struct soc_enum rx_mix_tx0_mux_enum =
  491. SOC_ENUM_SINGLE(BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 4, 4,
  492. rx_echo_mux_text);
  493. static const struct snd_kcontrol_new rx_mix_tx0_mux =
  494. SOC_DAPM_ENUM("RX MIX TX0_MUX Mux", rx_mix_tx0_mux_enum);
  495. static struct snd_soc_dai_ops rx_macro_dai_ops = {
  496. .hw_params = rx_macro_hw_params,
  497. .get_channel_map = rx_macro_get_channel_map,
  498. };
  499. static struct snd_soc_dai_driver rx_macro_dai[] = {
  500. {
  501. .name = "rx_macro_rx1",
  502. .id = RX_MACRO_AIF1_PB,
  503. .playback = {
  504. .stream_name = "RX_MACRO_AIF1 Playback",
  505. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  506. .formats = RX_MACRO_FORMATS,
  507. .rate_max = 384000,
  508. .rate_min = 8000,
  509. .channels_min = 1,
  510. .channels_max = 2,
  511. },
  512. .ops = &rx_macro_dai_ops,
  513. },
  514. {
  515. .name = "rx_macro_rx2",
  516. .id = RX_MACRO_AIF2_PB,
  517. .playback = {
  518. .stream_name = "RX_MACRO_AIF2 Playback",
  519. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  520. .formats = RX_MACRO_FORMATS,
  521. .rate_max = 384000,
  522. .rate_min = 8000,
  523. .channels_min = 1,
  524. .channels_max = 2,
  525. },
  526. .ops = &rx_macro_dai_ops,
  527. },
  528. {
  529. .name = "rx_macro_rx3",
  530. .id = RX_MACRO_AIF3_PB,
  531. .playback = {
  532. .stream_name = "RX_MACRO_AIF3 Playback",
  533. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  534. .formats = RX_MACRO_FORMATS,
  535. .rate_max = 384000,
  536. .rate_min = 8000,
  537. .channels_min = 1,
  538. .channels_max = 2,
  539. },
  540. .ops = &rx_macro_dai_ops,
  541. },
  542. {
  543. .name = "rx_macro_rx4",
  544. .id = RX_MACRO_AIF4_PB,
  545. .playback = {
  546. .stream_name = "RX_MACRO_AIF4 Playback",
  547. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  548. .formats = RX_MACRO_FORMATS,
  549. .rate_max = 384000,
  550. .rate_min = 8000,
  551. .channels_min = 1,
  552. .channels_max = 2,
  553. },
  554. .ops = &rx_macro_dai_ops,
  555. },
  556. {
  557. .name = "rx_macro_echo",
  558. .id = RX_MACRO_AIF_ECHO,
  559. .capture = {
  560. .stream_name = "RX_AIF_ECHO Capture",
  561. .rates = RX_MACRO_ECHO_RATES,
  562. .formats = RX_MACRO_ECHO_FORMATS,
  563. .rate_max = 48000,
  564. .rate_min = 8000,
  565. .channels_min = 1,
  566. .channels_max = 3,
  567. },
  568. .ops = &rx_macro_dai_ops,
  569. },
  570. };
  571. static int get_impedance_index(int imped)
  572. {
  573. int i = 0;
  574. if (imped < imped_index[i].imped_val) {
  575. pr_debug("%s, detected impedance is less than %d Ohm\n",
  576. __func__, imped_index[i].imped_val);
  577. i = 0;
  578. goto ret;
  579. }
  580. if (imped >= imped_index[ARRAY_SIZE(imped_index) - 1].imped_val) {
  581. pr_debug("%s, detected impedance is greater than %d Ohm\n",
  582. __func__,
  583. imped_index[ARRAY_SIZE(imped_index) - 1].imped_val);
  584. i = ARRAY_SIZE(imped_index) - 1;
  585. goto ret;
  586. }
  587. for (i = 0; i < ARRAY_SIZE(imped_index) - 1; i++) {
  588. if (imped >= imped_index[i].imped_val &&
  589. imped < imped_index[i + 1].imped_val)
  590. break;
  591. }
  592. ret:
  593. pr_debug("%s: selected impedance index = %d\n",
  594. __func__, imped_index[i].index);
  595. return imped_index[i].index;
  596. }
  597. /*
  598. * rx_macro_wcd_clsh_imped_config -
  599. * This function updates HPHL and HPHR gain settings
  600. * according to the impedance value.
  601. *
  602. * @component: codec pointer handle
  603. * @imped: impedance value of HPHL/R
  604. * @reset: bool variable to reset registers when teardown
  605. */
  606. static void rx_macro_wcd_clsh_imped_config(struct snd_soc_component *component,
  607. int imped, bool reset)
  608. {
  609. int i;
  610. int index = 0;
  611. int table_size;
  612. static const struct rx_macro_reg_mask_val
  613. (*imped_table_ptr)[MAX_IMPED_PARAMS];
  614. table_size = ARRAY_SIZE(imped_table);
  615. imped_table_ptr = imped_table;
  616. /* reset = 1, which means request is to reset the register values */
  617. if (reset) {
  618. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  619. snd_soc_component_update_bits(component,
  620. imped_table_ptr[index][i].reg,
  621. imped_table_ptr[index][i].mask, 0);
  622. return;
  623. }
  624. index = get_impedance_index(imped);
  625. if (index >= (ARRAY_SIZE(imped_index) - 1)) {
  626. pr_debug("%s, impedance not in range = %d\n", __func__, imped);
  627. return;
  628. }
  629. if (index >= table_size) {
  630. pr_debug("%s, impedance index not in range = %d\n", __func__,
  631. index);
  632. return;
  633. }
  634. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  635. snd_soc_component_update_bits(component,
  636. imped_table_ptr[index][i].reg,
  637. imped_table_ptr[index][i].mask,
  638. imped_table_ptr[index][i].val);
  639. }
  640. static bool rx_macro_get_data(struct snd_soc_component *component,
  641. struct device **rx_dev,
  642. struct rx_macro_priv **rx_priv,
  643. const char *func_name)
  644. {
  645. *rx_dev = bolero_get_device_ptr(component->dev, RX_MACRO);
  646. if (!(*rx_dev)) {
  647. dev_err(component->dev,
  648. "%s: null device for macro!\n", func_name);
  649. return false;
  650. }
  651. *rx_priv = dev_get_drvdata((*rx_dev));
  652. if (!(*rx_priv)) {
  653. dev_err(component->dev,
  654. "%s: priv is null for macro!\n", func_name);
  655. return false;
  656. }
  657. if (!(*rx_priv)->component) {
  658. dev_err(component->dev,
  659. "%s: rx_priv component is not initialized!\n", func_name);
  660. return false;
  661. }
  662. return true;
  663. }
  664. static int rx_macro_set_port_map(struct snd_soc_component *component,
  665. u32 usecase, u32 size, void *data)
  666. {
  667. struct device *rx_dev = NULL;
  668. struct rx_macro_priv *rx_priv = NULL;
  669. struct swrm_port_config port_cfg;
  670. int ret = 0;
  671. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  672. return -EINVAL;
  673. memset(&port_cfg, 0, sizeof(port_cfg));
  674. port_cfg.uc = usecase;
  675. port_cfg.size = size;
  676. port_cfg.params = data;
  677. if (rx_priv->swr_ctrl_data)
  678. ret = swrm_wcd_notify(
  679. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  680. SWR_SET_PORT_MAP, &port_cfg);
  681. return ret;
  682. }
  683. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  684. struct snd_ctl_elem_value *ucontrol)
  685. {
  686. struct snd_soc_dapm_widget *widget =
  687. snd_soc_dapm_kcontrol_widget(kcontrol);
  688. struct snd_soc_component *component =
  689. snd_soc_dapm_to_component(widget->dapm);
  690. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  691. unsigned int val = 0;
  692. unsigned short look_ahead_dly_reg =
  693. BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  694. val = ucontrol->value.enumerated.item[0];
  695. if (val >= e->items)
  696. return -EINVAL;
  697. dev_dbg(component->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  698. widget->name, val);
  699. if (e->reg == BOLERO_CDC_RX_RX0_RX_PATH_CFG1)
  700. look_ahead_dly_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  701. else if (e->reg == BOLERO_CDC_RX_RX1_RX_PATH_CFG1)
  702. look_ahead_dly_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  703. /* Set Look Ahead Delay */
  704. snd_soc_component_update_bits(component, look_ahead_dly_reg,
  705. 0x08, (val ? 0x08 : 0x00));
  706. /* Set DEM INP Select */
  707. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  708. }
  709. static int rx_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  710. u8 rate_reg_val,
  711. u32 sample_rate)
  712. {
  713. u8 int_1_mix1_inp = 0;
  714. u32 j = 0, port = 0;
  715. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  716. u16 int_fs_reg = 0;
  717. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  718. u8 inp0_sel = 0, inp1_sel = 0, inp2_sel = 0;
  719. struct snd_soc_component *component = dai->component;
  720. struct device *rx_dev = NULL;
  721. struct rx_macro_priv *rx_priv = NULL;
  722. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  723. return -EINVAL;
  724. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  725. RX_MACRO_PORTS_MAX) {
  726. int_1_mix1_inp = port;
  727. if ((int_1_mix1_inp < RX_MACRO_RX0) ||
  728. (int_1_mix1_inp > RX_MACRO_PORTS_MAX)) {
  729. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  730. __func__, dai->id);
  731. return -EINVAL;
  732. }
  733. int_mux_cfg0 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0;
  734. /*
  735. * Loop through all interpolator MUX inputs and find out
  736. * to which interpolator input, the rx port
  737. * is connected
  738. */
  739. for (j = 0; j < INTERP_MAX; j++) {
  740. int_mux_cfg1 = int_mux_cfg0 + 4;
  741. int_mux_cfg0_val = snd_soc_component_read32(
  742. component, int_mux_cfg0);
  743. int_mux_cfg1_val = snd_soc_component_read32(
  744. component, int_mux_cfg1);
  745. inp0_sel = int_mux_cfg0_val & 0x07;
  746. inp1_sel = (int_mux_cfg0_val >> 4) & 0x038;
  747. inp2_sel = (int_mux_cfg1_val >> 4) & 0x038;
  748. if ((inp0_sel == int_1_mix1_inp) ||
  749. (inp1_sel == int_1_mix1_inp) ||
  750. (inp2_sel == int_1_mix1_inp)) {
  751. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  752. 0x80 * j;
  753. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  754. __func__, dai->id, j);
  755. pr_debug("%s: set INT%u_1 sample rate to %u\n",
  756. __func__, j, sample_rate);
  757. /* sample_rate is in Hz */
  758. snd_soc_component_update_bits(component,
  759. int_fs_reg,
  760. 0x0F, rate_reg_val);
  761. }
  762. int_mux_cfg0 += 8;
  763. }
  764. }
  765. return 0;
  766. }
  767. static int rx_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  768. u8 rate_reg_val,
  769. u32 sample_rate)
  770. {
  771. u8 int_2_inp = 0;
  772. u32 j = 0, port = 0;
  773. u16 int_mux_cfg1 = 0, int_fs_reg = 0;
  774. u8 int_mux_cfg1_val = 0;
  775. struct snd_soc_component *component = dai->component;
  776. struct device *rx_dev = NULL;
  777. struct rx_macro_priv *rx_priv = NULL;
  778. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  779. return -EINVAL;
  780. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  781. RX_MACRO_PORTS_MAX) {
  782. int_2_inp = port;
  783. if ((int_2_inp < RX_MACRO_RX0) ||
  784. (int_2_inp > RX_MACRO_PORTS_MAX)) {
  785. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  786. __func__, dai->id);
  787. return -EINVAL;
  788. }
  789. int_mux_cfg1 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1;
  790. for (j = 0; j < INTERP_MAX; j++) {
  791. int_mux_cfg1_val = snd_soc_component_read32(
  792. component, int_mux_cfg1) &
  793. 0x07;
  794. if (int_mux_cfg1_val == int_2_inp) {
  795. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  796. 0x80 * j;
  797. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  798. __func__, dai->id, j);
  799. pr_debug("%s: set INT%u_2 sample rate to %u\n",
  800. __func__, j, sample_rate);
  801. snd_soc_component_update_bits(
  802. component, int_fs_reg,
  803. 0x0F, rate_reg_val);
  804. }
  805. int_mux_cfg1 += 8;
  806. }
  807. }
  808. return 0;
  809. }
  810. static bool rx_macro_is_fractional_sample_rate(u32 sample_rate)
  811. {
  812. switch (sample_rate) {
  813. case SAMPLING_RATE_44P1KHZ:
  814. case SAMPLING_RATE_88P2KHZ:
  815. case SAMPLING_RATE_176P4KHZ:
  816. case SAMPLING_RATE_352P8KHZ:
  817. return true;
  818. default:
  819. return false;
  820. }
  821. return false;
  822. }
  823. static int rx_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  824. u32 sample_rate)
  825. {
  826. struct snd_soc_component *component = dai->component;
  827. int rate_val = 0;
  828. int i = 0, ret = 0;
  829. struct device *rx_dev = NULL;
  830. struct rx_macro_priv *rx_priv = NULL;
  831. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  832. return -EINVAL;
  833. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  834. if (sample_rate == sr_val_tbl[i].sample_rate) {
  835. rate_val = sr_val_tbl[i].rate_val;
  836. if (rx_macro_is_fractional_sample_rate(sample_rate))
  837. rx_priv->is_native_on = true;
  838. else
  839. rx_priv->is_native_on = false;
  840. break;
  841. }
  842. }
  843. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  844. dev_err(component->dev, "%s: Unsupported sample rate: %d\n",
  845. __func__, sample_rate);
  846. return -EINVAL;
  847. }
  848. ret = rx_macro_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  849. if (ret)
  850. return ret;
  851. ret = rx_macro_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  852. if (ret)
  853. return ret;
  854. return ret;
  855. }
  856. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  857. struct snd_pcm_hw_params *params,
  858. struct snd_soc_dai *dai)
  859. {
  860. struct snd_soc_component *component = dai->component;
  861. int ret = 0;
  862. struct device *rx_dev = NULL;
  863. struct rx_macro_priv *rx_priv = NULL;
  864. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  865. return -EINVAL;
  866. dev_dbg(component->dev,
  867. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  868. dai->name, dai->id, params_rate(params),
  869. params_channels(params));
  870. switch (substream->stream) {
  871. case SNDRV_PCM_STREAM_PLAYBACK:
  872. ret = rx_macro_set_interpolator_rate(dai, params_rate(params));
  873. if (ret) {
  874. pr_err("%s: cannot set sample rate: %u\n",
  875. __func__, params_rate(params));
  876. return ret;
  877. }
  878. rx_priv->bit_width[dai->id] = params_width(params);
  879. break;
  880. case SNDRV_PCM_STREAM_CAPTURE:
  881. default:
  882. break;
  883. }
  884. return 0;
  885. }
  886. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  887. unsigned int *tx_num, unsigned int *tx_slot,
  888. unsigned int *rx_num, unsigned int *rx_slot)
  889. {
  890. struct snd_soc_component *component = dai->component;
  891. struct device *rx_dev = NULL;
  892. struct rx_macro_priv *rx_priv = NULL;
  893. unsigned int temp = 0, ch_mask = 0;
  894. u16 val = 0, mask = 0, cnt = 0, i = 0;
  895. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  896. return -EINVAL;
  897. switch (dai->id) {
  898. case RX_MACRO_AIF1_PB:
  899. case RX_MACRO_AIF2_PB:
  900. case RX_MACRO_AIF3_PB:
  901. case RX_MACRO_AIF4_PB:
  902. for_each_set_bit(temp, &rx_priv->active_ch_mask[dai->id],
  903. RX_MACRO_PORTS_MAX) {
  904. ch_mask |= (1 << temp);
  905. if (++i == RX_MACRO_MAX_DMA_CH_PER_PORT)
  906. break;
  907. }
  908. *rx_slot = ch_mask;
  909. *rx_num = rx_priv->active_ch_cnt[dai->id];
  910. break;
  911. case RX_MACRO_AIF_ECHO:
  912. val = snd_soc_component_read32(component,
  913. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4);
  914. if (val & RX_MACRO_EC_MIX_TX0_MASK) {
  915. mask |= 0x1;
  916. cnt++;
  917. }
  918. if (val & RX_MACRO_EC_MIX_TX1_MASK) {
  919. mask |= 0x2;
  920. cnt++;
  921. }
  922. val = snd_soc_component_read32(component,
  923. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5);
  924. if (val & RX_MACRO_EC_MIX_TX2_MASK) {
  925. mask |= 0x4;
  926. cnt++;
  927. }
  928. *tx_slot = mask;
  929. *tx_num = cnt;
  930. break;
  931. default:
  932. dev_err(rx_dev, "%s: Invalid AIF\n", __func__);
  933. break;
  934. }
  935. return 0;
  936. }
  937. static int rx_macro_mclk_enable(struct rx_macro_priv *rx_priv,
  938. bool mclk_enable, bool dapm)
  939. {
  940. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  941. int ret = 0;
  942. if (regmap == NULL) {
  943. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  944. return -EINVAL;
  945. }
  946. dev_dbg(rx_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  947. __func__, mclk_enable, dapm, rx_priv->rx_mclk_users);
  948. mutex_lock(&rx_priv->mclk_lock);
  949. if (mclk_enable) {
  950. if (rx_priv->rx_mclk_users == 0) {
  951. if (rx_priv->is_native_on)
  952. rx_priv->clk_id = RX_CORE_CLK;
  953. ret = bolero_clk_rsc_request_clock(rx_priv->dev,
  954. rx_priv->default_clk_id,
  955. rx_priv->clk_id,
  956. true);
  957. if (ret < 0) {
  958. dev_err(rx_priv->dev,
  959. "%s: rx request clock enable failed\n",
  960. __func__);
  961. goto exit;
  962. }
  963. bolero_clk_rsc_fs_gen_request(rx_priv->dev,
  964. true);
  965. regcache_mark_dirty(regmap);
  966. regcache_sync_region(regmap,
  967. RX_START_OFFSET,
  968. RX_MAX_OFFSET);
  969. regmap_update_bits(regmap,
  970. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  971. 0x01, 0x01);
  972. regmap_update_bits(regmap,
  973. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  974. 0x02, 0x02);
  975. regmap_update_bits(regmap,
  976. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  977. 0x01, 0x01);
  978. }
  979. rx_priv->rx_mclk_users++;
  980. } else {
  981. if (rx_priv->rx_mclk_users <= 0) {
  982. dev_err(rx_priv->dev, "%s: clock already disabled\n",
  983. __func__);
  984. rx_priv->rx_mclk_users = 0;
  985. goto exit;
  986. }
  987. rx_priv->rx_mclk_users--;
  988. if (rx_priv->rx_mclk_users == 0) {
  989. regmap_update_bits(regmap,
  990. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  991. 0x01, 0x00);
  992. regmap_update_bits(regmap,
  993. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  994. 0x01, 0x00);
  995. bolero_clk_rsc_fs_gen_request(rx_priv->dev,
  996. false);
  997. bolero_clk_rsc_request_clock(rx_priv->dev,
  998. rx_priv->default_clk_id,
  999. rx_priv->clk_id,
  1000. false);
  1001. rx_priv->clk_id = rx_priv->default_clk_id;
  1002. }
  1003. }
  1004. exit:
  1005. mutex_unlock(&rx_priv->mclk_lock);
  1006. return ret;
  1007. }
  1008. static int rx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  1009. struct snd_kcontrol *kcontrol, int event)
  1010. {
  1011. struct snd_soc_component *component =
  1012. snd_soc_dapm_to_component(w->dapm);
  1013. int ret = 0;
  1014. struct device *rx_dev = NULL;
  1015. struct rx_macro_priv *rx_priv = NULL;
  1016. int mclk_freq = MCLK_FREQ;
  1017. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1018. return -EINVAL;
  1019. dev_dbg(rx_dev, "%s: event = %d\n", __func__, event);
  1020. switch (event) {
  1021. case SND_SOC_DAPM_PRE_PMU:
  1022. /* if swr_clk_users > 0, call device down */
  1023. if (rx_priv->swr_clk_users > 0) {
  1024. if ((rx_priv->clk_id == rx_priv->default_clk_id &&
  1025. rx_priv->is_native_on) ||
  1026. (rx_priv->clk_id == RX_CORE_CLK &&
  1027. !rx_priv->is_native_on)) {
  1028. if (rx_priv->swr_ctrl_data)
  1029. swrm_wcd_notify(
  1030. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1031. SWR_DEVICE_DOWN, NULL);
  1032. }
  1033. }
  1034. if (rx_priv->is_native_on)
  1035. mclk_freq = MCLK_FREQ_NATIVE;
  1036. if (rx_priv->swr_ctrl_data)
  1037. swrm_wcd_notify(
  1038. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1039. SWR_CLK_FREQ, &mclk_freq);
  1040. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  1041. if (ret)
  1042. rx_priv->dapm_mclk_enable = false;
  1043. else
  1044. rx_priv->dapm_mclk_enable = true;
  1045. break;
  1046. case SND_SOC_DAPM_POST_PMD:
  1047. if (rx_priv->dapm_mclk_enable)
  1048. ret = rx_macro_mclk_enable(rx_priv, 0, true);
  1049. break;
  1050. default:
  1051. dev_err(rx_priv->dev,
  1052. "%s: invalid DAPM event %d\n", __func__, event);
  1053. ret = -EINVAL;
  1054. }
  1055. return ret;
  1056. }
  1057. static int rx_macro_event_handler(struct snd_soc_component *component,
  1058. u16 event, u32 data)
  1059. {
  1060. u16 reg = 0, reg_mix = 0, rx_idx = 0, mute = 0x0, val = 0;
  1061. struct device *rx_dev = NULL;
  1062. struct rx_macro_priv *rx_priv = NULL;
  1063. int ret = 0;
  1064. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1065. return -EINVAL;
  1066. switch (event) {
  1067. case BOLERO_MACRO_EVT_RX_MUTE:
  1068. rx_idx = data >> 0x10;
  1069. mute = data & 0xffff;
  1070. val = mute ? 0x10 : 0x00;
  1071. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (rx_idx *
  1072. RX_MACRO_RX_PATH_OFFSET);
  1073. reg_mix = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL + (rx_idx *
  1074. RX_MACRO_RX_PATH_OFFSET);
  1075. snd_soc_component_update_bits(component, reg,
  1076. 0x10, val);
  1077. snd_soc_component_update_bits(component, reg_mix,
  1078. 0x10, val);
  1079. break;
  1080. case BOLERO_MACRO_EVT_IMPED_TRUE:
  1081. rx_macro_wcd_clsh_imped_config(component, data, true);
  1082. break;
  1083. case BOLERO_MACRO_EVT_IMPED_FALSE:
  1084. rx_macro_wcd_clsh_imped_config(component, data, false);
  1085. break;
  1086. case BOLERO_MACRO_EVT_SSR_DOWN:
  1087. rx_priv->dev_up = false;
  1088. if (rx_priv->swr_ctrl_data) {
  1089. swrm_wcd_notify(
  1090. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1091. SWR_DEVICE_DOWN, NULL);
  1092. swrm_wcd_notify(
  1093. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1094. SWR_DEVICE_SSR_DOWN, NULL);
  1095. }
  1096. break;
  1097. case BOLERO_MACRO_EVT_SSR_UP:
  1098. rx_priv->dev_up = true;
  1099. /* reset swr after ssr/pdr */
  1100. rx_priv->reset_swr = true;
  1101. /* enable&disable RX_CORE_CLK to reset GFMUX reg */
  1102. ret = bolero_clk_rsc_request_clock(rx_priv->dev,
  1103. rx_priv->default_clk_id,
  1104. RX_CORE_CLK, true);
  1105. if (ret < 0)
  1106. dev_err_ratelimited(rx_priv->dev,
  1107. "%s, failed to enable clk, ret:%d\n",
  1108. __func__, ret);
  1109. else
  1110. bolero_clk_rsc_request_clock(rx_priv->dev,
  1111. rx_priv->default_clk_id,
  1112. RX_CORE_CLK, false);
  1113. if (rx_priv->swr_ctrl_data)
  1114. swrm_wcd_notify(
  1115. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1116. SWR_DEVICE_SSR_UP, NULL);
  1117. break;
  1118. }
  1119. return ret;
  1120. }
  1121. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  1122. struct rx_macro_priv *rx_priv)
  1123. {
  1124. int i = 0;
  1125. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  1126. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  1127. return i;
  1128. }
  1129. return -EINVAL;
  1130. }
  1131. static int rx_macro_set_idle_detect_thr(struct snd_soc_component *component,
  1132. struct rx_macro_priv *rx_priv,
  1133. int interp, int path_type)
  1134. {
  1135. int port_id[4] = { 0, 0, 0, 0 };
  1136. int *port_ptr = NULL;
  1137. int num_ports = 0;
  1138. int bit_width = 0, i = 0;
  1139. int mux_reg = 0, mux_reg_val = 0;
  1140. int dai_id = 0, idle_thr = 0;
  1141. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  1142. return 0;
  1143. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1144. return 0;
  1145. port_ptr = &port_id[0];
  1146. num_ports = 0;
  1147. /*
  1148. * Read interpolator MUX input registers and find
  1149. * which cdc_dma port is connected and store the port
  1150. * numbers in port_id array.
  1151. */
  1152. if (path_type == INTERP_MIX_PATH) {
  1153. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  1154. 2 * interp;
  1155. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1156. 0x0f;
  1157. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  1158. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  1159. *port_ptr++ = mux_reg_val - 1;
  1160. num_ports++;
  1161. }
  1162. }
  1163. if (path_type == INTERP_MAIN_PATH) {
  1164. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  1165. 2 * (interp - 1);
  1166. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1167. 0x0f;
  1168. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  1169. while (i) {
  1170. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  1171. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  1172. *port_ptr++ = mux_reg_val -
  1173. INTn_1_INP_SEL_RX0;
  1174. num_ports++;
  1175. }
  1176. mux_reg_val =
  1177. (snd_soc_component_read32(component, mux_reg) &
  1178. 0xf0) >> 4;
  1179. mux_reg += 1;
  1180. i--;
  1181. }
  1182. }
  1183. dev_dbg(component->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  1184. __func__, num_ports, port_id[0], port_id[1],
  1185. port_id[2], port_id[3]);
  1186. i = 0;
  1187. while (num_ports) {
  1188. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  1189. rx_priv);
  1190. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  1191. dev_dbg(component->dev, "%s: dai_id: %d bit_width: %d\n",
  1192. __func__, dai_id,
  1193. rx_priv->bit_width[dai_id]);
  1194. if (rx_priv->bit_width[dai_id] > bit_width)
  1195. bit_width = rx_priv->bit_width[dai_id];
  1196. }
  1197. num_ports--;
  1198. }
  1199. switch (bit_width) {
  1200. case 16:
  1201. idle_thr = 0xff; /* F16 */
  1202. break;
  1203. case 24:
  1204. case 32:
  1205. idle_thr = 0x03; /* F22 */
  1206. break;
  1207. default:
  1208. idle_thr = 0x00;
  1209. break;
  1210. }
  1211. dev_dbg(component->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  1212. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  1213. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  1214. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  1215. snd_soc_component_write(component,
  1216. BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  1217. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  1218. }
  1219. return 0;
  1220. }
  1221. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1222. struct snd_kcontrol *kcontrol, int event)
  1223. {
  1224. struct snd_soc_component *component =
  1225. snd_soc_dapm_to_component(w->dapm);
  1226. u16 gain_reg = 0, mix_reg = 0;
  1227. struct device *rx_dev = NULL;
  1228. struct rx_macro_priv *rx_priv = NULL;
  1229. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1230. return -EINVAL;
  1231. if (w->shift >= INTERP_MAX) {
  1232. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1233. __func__, w->shift, w->name);
  1234. return -EINVAL;
  1235. }
  1236. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  1237. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1238. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  1239. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1240. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1241. switch (event) {
  1242. case SND_SOC_DAPM_PRE_PMU:
  1243. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1244. INTERP_MIX_PATH);
  1245. rx_macro_enable_interp_clk(component, event, w->shift);
  1246. /* Clk enable */
  1247. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x20);
  1248. break;
  1249. case SND_SOC_DAPM_POST_PMU:
  1250. snd_soc_component_write(component, gain_reg,
  1251. snd_soc_component_read32(component, gain_reg));
  1252. break;
  1253. case SND_SOC_DAPM_POST_PMD:
  1254. /* Clk Disable */
  1255. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x00);
  1256. rx_macro_enable_interp_clk(component, event, w->shift);
  1257. /* Reset enable and disable */
  1258. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x40);
  1259. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x00);
  1260. break;
  1261. }
  1262. return 0;
  1263. }
  1264. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1265. struct snd_kcontrol *kcontrol,
  1266. int event)
  1267. {
  1268. struct snd_soc_component *component =
  1269. snd_soc_dapm_to_component(w->dapm);
  1270. u16 gain_reg = 0;
  1271. u16 reg = 0;
  1272. struct device *rx_dev = NULL;
  1273. struct rx_macro_priv *rx_priv = NULL;
  1274. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1275. return -EINVAL;
  1276. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1277. if (w->shift >= INTERP_MAX) {
  1278. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1279. __func__, w->shift, w->name);
  1280. return -EINVAL;
  1281. }
  1282. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  1283. RX_MACRO_RX_PATH_OFFSET);
  1284. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  1285. RX_MACRO_RX_PATH_OFFSET);
  1286. switch (event) {
  1287. case SND_SOC_DAPM_PRE_PMU:
  1288. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1289. INTERP_MAIN_PATH);
  1290. rx_macro_enable_interp_clk(component, event, w->shift);
  1291. break;
  1292. case SND_SOC_DAPM_POST_PMU:
  1293. snd_soc_component_write(component, gain_reg,
  1294. snd_soc_component_read32(component, gain_reg));
  1295. break;
  1296. case SND_SOC_DAPM_POST_PMD:
  1297. rx_macro_enable_interp_clk(component, event, w->shift);
  1298. break;
  1299. }
  1300. return 0;
  1301. }
  1302. static int rx_macro_config_compander(struct snd_soc_component *component,
  1303. struct rx_macro_priv *rx_priv,
  1304. int interp_n, int event)
  1305. {
  1306. int comp = 0;
  1307. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  1308. /* AUX does not have compander */
  1309. if (interp_n == INTERP_AUX)
  1310. return 0;
  1311. comp = interp_n;
  1312. dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
  1313. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  1314. if (!rx_priv->comp_enabled[comp])
  1315. return 0;
  1316. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1317. (comp * RX_MACRO_COMP_OFFSET);
  1318. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  1319. (comp * RX_MACRO_RX_PATH_OFFSET);
  1320. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1321. /* Enable Compander Clock */
  1322. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1323. 0x01, 0x01);
  1324. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1325. 0x02, 0x02);
  1326. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1327. 0x02, 0x00);
  1328. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1329. 0x02, 0x02);
  1330. }
  1331. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1332. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1333. 0x04, 0x04);
  1334. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1335. 0x02, 0x00);
  1336. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1337. 0x01, 0x00);
  1338. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1339. 0x04, 0x00);
  1340. }
  1341. return 0;
  1342. }
  1343. static void rx_macro_enable_softclip_clk(struct snd_soc_component *component,
  1344. struct rx_macro_priv *rx_priv,
  1345. bool enable)
  1346. {
  1347. if (enable) {
  1348. if (rx_priv->softclip_clk_users == 0)
  1349. snd_soc_component_update_bits(component,
  1350. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1351. 0x01, 0x01);
  1352. rx_priv->softclip_clk_users++;
  1353. } else {
  1354. rx_priv->softclip_clk_users--;
  1355. if (rx_priv->softclip_clk_users == 0)
  1356. snd_soc_component_update_bits(component,
  1357. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1358. 0x01, 0x00);
  1359. }
  1360. }
  1361. static int rx_macro_config_softclip(struct snd_soc_component *component,
  1362. struct rx_macro_priv *rx_priv,
  1363. int event)
  1364. {
  1365. dev_dbg(component->dev, "%s: event %d, enabled %d\n",
  1366. __func__, event, rx_priv->is_softclip_on);
  1367. if (!rx_priv->is_softclip_on)
  1368. return 0;
  1369. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1370. /* Enable Softclip clock */
  1371. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1372. /* Enable Softclip control */
  1373. snd_soc_component_update_bits(component,
  1374. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x01);
  1375. }
  1376. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1377. snd_soc_component_update_bits(component,
  1378. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x00);
  1379. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1380. }
  1381. return 0;
  1382. }
  1383. static inline void
  1384. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  1385. {
  1386. if ((enable && ++rx_priv->clsh_users == 1) ||
  1387. (!enable && --rx_priv->clsh_users == 0))
  1388. snd_soc_component_update_bits(rx_priv->component,
  1389. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  1390. (u8) enable);
  1391. if (rx_priv->clsh_users < 0)
  1392. rx_priv->clsh_users = 0;
  1393. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1394. rx_priv->clsh_users, enable);
  1395. }
  1396. static int rx_macro_config_classh(struct snd_soc_component *component,
  1397. struct rx_macro_priv *rx_priv,
  1398. int interp_n, int event)
  1399. {
  1400. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1401. rx_macro_enable_clsh_block(rx_priv, false);
  1402. return 0;
  1403. }
  1404. if (!SND_SOC_DAPM_EVENT_ON(event))
  1405. return 0;
  1406. rx_macro_enable_clsh_block(rx_priv, true);
  1407. if (interp_n == INTERP_HPHL ||
  1408. interp_n == INTERP_HPHR) {
  1409. /*
  1410. * These K1 values depend on the Headphone Impedance
  1411. * For now it is assumed to be 16 ohm
  1412. */
  1413. snd_soc_component_update_bits(component,
  1414. BOLERO_CDC_RX_CLSH_K1_LSB,
  1415. 0xFF, 0xC0);
  1416. snd_soc_component_update_bits(component,
  1417. BOLERO_CDC_RX_CLSH_K1_MSB,
  1418. 0x0F, 0x00);
  1419. }
  1420. switch (interp_n) {
  1421. case INTERP_HPHL:
  1422. if (rx_priv->is_ear_mode_on)
  1423. snd_soc_component_update_bits(component,
  1424. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1425. 0x3F, 0x39);
  1426. else
  1427. snd_soc_component_update_bits(component,
  1428. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1429. 0x3F, 0x1C);
  1430. snd_soc_component_update_bits(component,
  1431. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1432. 0x07, 0x00);
  1433. snd_soc_component_update_bits(component,
  1434. BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1435. 0x40, 0x40);
  1436. break;
  1437. case INTERP_HPHR:
  1438. snd_soc_component_update_bits(component,
  1439. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1440. 0x3F, 0x1C);
  1441. snd_soc_component_update_bits(component,
  1442. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1443. 0x07, 0x00);
  1444. snd_soc_component_update_bits(component,
  1445. BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1446. 0x40, 0x40);
  1447. break;
  1448. case INTERP_AUX:
  1449. snd_soc_component_update_bits(component,
  1450. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1451. 0x08, 0x08);
  1452. snd_soc_component_update_bits(component,
  1453. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1454. 0x10, 0x10);
  1455. break;
  1456. }
  1457. return 0;
  1458. }
  1459. static void rx_macro_hd2_control(struct snd_soc_component *component,
  1460. u16 interp_idx, int event)
  1461. {
  1462. u16 hd2_scale_reg = 0;
  1463. u16 hd2_enable_reg = 0;
  1464. switch (interp_idx) {
  1465. case INTERP_HPHL:
  1466. hd2_scale_reg = BOLERO_CDC_RX_RX0_RX_PATH_SEC3;
  1467. hd2_enable_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  1468. break;
  1469. case INTERP_HPHR:
  1470. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1471. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1472. break;
  1473. }
  1474. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1475. snd_soc_component_update_bits(component, hd2_scale_reg,
  1476. 0x3C, 0x14);
  1477. snd_soc_component_update_bits(component, hd2_enable_reg,
  1478. 0x04, 0x04);
  1479. }
  1480. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1481. snd_soc_component_update_bits(component, hd2_enable_reg,
  1482. 0x04, 0x00);
  1483. snd_soc_component_update_bits(component, hd2_scale_reg,
  1484. 0x3C, 0x00);
  1485. }
  1486. }
  1487. static int rx_macro_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  1488. struct snd_ctl_elem_value *ucontrol)
  1489. {
  1490. struct snd_soc_component *component =
  1491. snd_soc_kcontrol_component(kcontrol);
  1492. struct rx_macro_priv *rx_priv = NULL;
  1493. struct device *rx_dev = NULL;
  1494. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1495. return -EINVAL;
  1496. ucontrol->value.integer.value[0] =
  1497. rx_priv->idle_det_cfg.hph_idle_detect_en;
  1498. return 0;
  1499. }
  1500. static int rx_macro_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  1501. struct snd_ctl_elem_value *ucontrol)
  1502. {
  1503. struct snd_soc_component *component =
  1504. snd_soc_kcontrol_component(kcontrol);
  1505. struct rx_macro_priv *rx_priv = NULL;
  1506. struct device *rx_dev = NULL;
  1507. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1508. return -EINVAL;
  1509. rx_priv->idle_det_cfg.hph_idle_detect_en =
  1510. ucontrol->value.integer.value[0];
  1511. return 0;
  1512. }
  1513. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1514. struct snd_ctl_elem_value *ucontrol)
  1515. {
  1516. struct snd_soc_component *component =
  1517. snd_soc_kcontrol_component(kcontrol);
  1518. int comp = ((struct soc_multi_mixer_control *)
  1519. kcontrol->private_value)->shift;
  1520. struct device *rx_dev = NULL;
  1521. struct rx_macro_priv *rx_priv = NULL;
  1522. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1523. return -EINVAL;
  1524. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1525. return 0;
  1526. }
  1527. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1528. struct snd_ctl_elem_value *ucontrol)
  1529. {
  1530. struct snd_soc_component *component =
  1531. snd_soc_kcontrol_component(kcontrol);
  1532. int comp = ((struct soc_multi_mixer_control *)
  1533. kcontrol->private_value)->shift;
  1534. int value = ucontrol->value.integer.value[0];
  1535. struct device *rx_dev = NULL;
  1536. struct rx_macro_priv *rx_priv = NULL;
  1537. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1538. return -EINVAL;
  1539. dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
  1540. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1541. rx_priv->comp_enabled[comp] = value;
  1542. return 0;
  1543. }
  1544. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1545. struct snd_ctl_elem_value *ucontrol)
  1546. {
  1547. struct snd_soc_dapm_widget *widget =
  1548. snd_soc_dapm_kcontrol_widget(kcontrol);
  1549. struct snd_soc_component *component =
  1550. snd_soc_dapm_to_component(widget->dapm);
  1551. struct device *rx_dev = NULL;
  1552. struct rx_macro_priv *rx_priv = NULL;
  1553. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1554. return -EINVAL;
  1555. ucontrol->value.integer.value[0] =
  1556. rx_priv->rx_port_value[widget->shift];
  1557. return 0;
  1558. }
  1559. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1560. struct snd_ctl_elem_value *ucontrol)
  1561. {
  1562. struct snd_soc_dapm_widget *widget =
  1563. snd_soc_dapm_kcontrol_widget(kcontrol);
  1564. struct snd_soc_component *component =
  1565. snd_soc_dapm_to_component(widget->dapm);
  1566. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1567. struct snd_soc_dapm_update *update = NULL;
  1568. u32 rx_port_value = ucontrol->value.integer.value[0];
  1569. u32 aif_rst = 0;
  1570. struct device *rx_dev = NULL;
  1571. struct rx_macro_priv *rx_priv = NULL;
  1572. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1573. return -EINVAL;
  1574. aif_rst = rx_priv->rx_port_value[widget->shift];
  1575. if (!rx_port_value) {
  1576. if (aif_rst == 0) {
  1577. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1578. return 0;
  1579. }
  1580. }
  1581. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1582. switch (rx_port_value) {
  1583. case 0:
  1584. clear_bit(widget->shift,
  1585. &rx_priv->active_ch_mask[aif_rst]);
  1586. rx_priv->active_ch_cnt[aif_rst]--;
  1587. break;
  1588. case 1:
  1589. case 2:
  1590. case 3:
  1591. case 4:
  1592. set_bit(widget->shift,
  1593. &rx_priv->active_ch_mask[rx_port_value]);
  1594. rx_priv->active_ch_cnt[rx_port_value]++;
  1595. break;
  1596. default:
  1597. dev_err(component->dev,
  1598. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1599. goto err;
  1600. }
  1601. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1602. rx_port_value, e, update);
  1603. return 0;
  1604. err:
  1605. return -EINVAL;
  1606. }
  1607. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1608. struct snd_ctl_elem_value *ucontrol)
  1609. {
  1610. struct snd_soc_component *component =
  1611. snd_soc_kcontrol_component(kcontrol);
  1612. struct device *rx_dev = NULL;
  1613. struct rx_macro_priv *rx_priv = NULL;
  1614. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1615. return -EINVAL;
  1616. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1617. return 0;
  1618. }
  1619. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1620. struct snd_ctl_elem_value *ucontrol)
  1621. {
  1622. struct snd_soc_component *component =
  1623. snd_soc_kcontrol_component(kcontrol);
  1624. struct device *rx_dev = NULL;
  1625. struct rx_macro_priv *rx_priv = NULL;
  1626. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1627. return -EINVAL;
  1628. rx_priv->is_ear_mode_on =
  1629. (!ucontrol->value.integer.value[0] ? false : true);
  1630. return 0;
  1631. }
  1632. static int rx_macro_get_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1633. struct snd_ctl_elem_value *ucontrol)
  1634. {
  1635. struct snd_soc_component *component =
  1636. snd_soc_kcontrol_component(kcontrol);
  1637. struct device *rx_dev = NULL;
  1638. struct rx_macro_priv *rx_priv = NULL;
  1639. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1640. return -EINVAL;
  1641. ucontrol->value.integer.value[0] = rx_priv->hph_hd2_mode;
  1642. return 0;
  1643. }
  1644. static int rx_macro_put_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1645. struct snd_ctl_elem_value *ucontrol)
  1646. {
  1647. struct snd_soc_component *component =
  1648. snd_soc_kcontrol_component(kcontrol);
  1649. struct device *rx_dev = NULL;
  1650. struct rx_macro_priv *rx_priv = NULL;
  1651. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1652. return -EINVAL;
  1653. rx_priv->hph_hd2_mode = ucontrol->value.integer.value[0];
  1654. return 0;
  1655. }
  1656. static int rx_macro_get_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1657. struct snd_ctl_elem_value *ucontrol)
  1658. {
  1659. struct snd_soc_component *component =
  1660. snd_soc_kcontrol_component(kcontrol);
  1661. struct device *rx_dev = NULL;
  1662. struct rx_macro_priv *rx_priv = NULL;
  1663. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1664. return -EINVAL;
  1665. ucontrol->value.integer.value[0] = rx_priv->hph_pwr_mode;
  1666. return 0;
  1667. }
  1668. static int rx_macro_put_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1669. struct snd_ctl_elem_value *ucontrol)
  1670. {
  1671. struct snd_soc_component *component =
  1672. snd_soc_kcontrol_component(kcontrol);
  1673. struct device *rx_dev = NULL;
  1674. struct rx_macro_priv *rx_priv = NULL;
  1675. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1676. return -EINVAL;
  1677. rx_priv->hph_pwr_mode = ucontrol->value.integer.value[0];
  1678. return 0;
  1679. }
  1680. static int rx_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1681. struct snd_ctl_elem_value *ucontrol)
  1682. {
  1683. struct snd_soc_component *component =
  1684. snd_soc_kcontrol_component(kcontrol);
  1685. ucontrol->value.integer.value[0] =
  1686. ((snd_soc_component_read32(
  1687. component, BOLERO_CDC_RX_BCL_VBAT_CFG) & 0x04) ?
  1688. 1 : 0);
  1689. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1690. ucontrol->value.integer.value[0]);
  1691. return 0;
  1692. }
  1693. static int rx_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1694. struct snd_ctl_elem_value *ucontrol)
  1695. {
  1696. struct snd_soc_component *component =
  1697. snd_soc_kcontrol_component(kcontrol);
  1698. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1699. ucontrol->value.integer.value[0]);
  1700. /* Set Vbat register configuration for GSM mode bit based on value */
  1701. if (ucontrol->value.integer.value[0])
  1702. snd_soc_component_update_bits(component,
  1703. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1704. 0x04, 0x04);
  1705. else
  1706. snd_soc_component_update_bits(component,
  1707. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1708. 0x04, 0x00);
  1709. return 0;
  1710. }
  1711. static int rx_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1712. struct snd_ctl_elem_value *ucontrol)
  1713. {
  1714. struct snd_soc_component *component =
  1715. snd_soc_kcontrol_component(kcontrol);
  1716. struct device *rx_dev = NULL;
  1717. struct rx_macro_priv *rx_priv = NULL;
  1718. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1719. return -EINVAL;
  1720. ucontrol->value.integer.value[0] = rx_priv->is_softclip_on;
  1721. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1722. __func__, ucontrol->value.integer.value[0]);
  1723. return 0;
  1724. }
  1725. static int rx_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1726. struct snd_ctl_elem_value *ucontrol)
  1727. {
  1728. struct snd_soc_component *component =
  1729. snd_soc_kcontrol_component(kcontrol);
  1730. struct device *rx_dev = NULL;
  1731. struct rx_macro_priv *rx_priv = NULL;
  1732. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1733. return -EINVAL;
  1734. rx_priv->is_softclip_on = ucontrol->value.integer.value[0];
  1735. dev_dbg(component->dev, "%s: soft clip enable = %d\n", __func__,
  1736. rx_priv->is_softclip_on);
  1737. return 0;
  1738. }
  1739. static int rx_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1740. struct snd_kcontrol *kcontrol,
  1741. int event)
  1742. {
  1743. struct snd_soc_component *component =
  1744. snd_soc_dapm_to_component(w->dapm);
  1745. struct device *rx_dev = NULL;
  1746. struct rx_macro_priv *rx_priv = NULL;
  1747. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1748. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1749. return -EINVAL;
  1750. switch (event) {
  1751. case SND_SOC_DAPM_PRE_PMU:
  1752. /* Enable clock for VBAT block */
  1753. snd_soc_component_update_bits(component,
  1754. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1755. /* Enable VBAT block */
  1756. snd_soc_component_update_bits(component,
  1757. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x01);
  1758. /* Update interpolator with 384K path */
  1759. snd_soc_component_update_bits(component,
  1760. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x80, 0x80);
  1761. /* Update DSM FS rate */
  1762. snd_soc_component_update_bits(component,
  1763. BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x02, 0x02);
  1764. /* Use attenuation mode */
  1765. snd_soc_component_update_bits(component,
  1766. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x02, 0x00);
  1767. /* BCL block needs softclip clock to be enabled */
  1768. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1769. /* Enable VBAT at channel level */
  1770. snd_soc_component_update_bits(component,
  1771. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x02, 0x02);
  1772. /* Set the ATTK1 gain */
  1773. snd_soc_component_update_bits(component,
  1774. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1775. 0xFF, 0xFF);
  1776. snd_soc_component_update_bits(component,
  1777. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1778. 0xFF, 0x03);
  1779. snd_soc_component_update_bits(component,
  1780. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1781. 0xFF, 0x00);
  1782. /* Set the ATTK2 gain */
  1783. snd_soc_component_update_bits(component,
  1784. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1785. 0xFF, 0xFF);
  1786. snd_soc_component_update_bits(component,
  1787. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1788. 0xFF, 0x03);
  1789. snd_soc_component_update_bits(component,
  1790. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1791. 0xFF, 0x00);
  1792. /* Set the ATTK3 gain */
  1793. snd_soc_component_update_bits(component,
  1794. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1795. 0xFF, 0xFF);
  1796. snd_soc_component_update_bits(component,
  1797. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1798. 0xFF, 0x03);
  1799. snd_soc_component_update_bits(component,
  1800. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1801. 0xFF, 0x00);
  1802. break;
  1803. case SND_SOC_DAPM_POST_PMD:
  1804. snd_soc_component_update_bits(component,
  1805. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1806. 0x80, 0x00);
  1807. snd_soc_component_update_bits(component,
  1808. BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1809. 0x02, 0x00);
  1810. snd_soc_component_update_bits(component,
  1811. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1812. 0x02, 0x02);
  1813. snd_soc_component_update_bits(component,
  1814. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1815. 0x02, 0x00);
  1816. snd_soc_component_update_bits(component,
  1817. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1818. 0xFF, 0x00);
  1819. snd_soc_component_update_bits(component,
  1820. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1821. 0xFF, 0x00);
  1822. snd_soc_component_update_bits(component,
  1823. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1824. 0xFF, 0x00);
  1825. snd_soc_component_update_bits(component,
  1826. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1827. 0xFF, 0x00);
  1828. snd_soc_component_update_bits(component,
  1829. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1830. 0xFF, 0x00);
  1831. snd_soc_component_update_bits(component,
  1832. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1833. 0xFF, 0x00);
  1834. snd_soc_component_update_bits(component,
  1835. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1836. 0xFF, 0x00);
  1837. snd_soc_component_update_bits(component,
  1838. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1839. 0xFF, 0x00);
  1840. snd_soc_component_update_bits(component,
  1841. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1842. 0xFF, 0x00);
  1843. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1844. snd_soc_component_update_bits(component,
  1845. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x00);
  1846. snd_soc_component_update_bits(component,
  1847. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1848. break;
  1849. default:
  1850. dev_err(rx_dev, "%s: Invalid event %d\n", __func__, event);
  1851. break;
  1852. }
  1853. return 0;
  1854. }
  1855. static void rx_macro_idle_detect_control(struct snd_soc_component *component,
  1856. struct rx_macro_priv *rx_priv,
  1857. int interp, int event)
  1858. {
  1859. int reg = 0, mask = 0, val = 0;
  1860. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1861. return;
  1862. if (interp == INTERP_HPHL) {
  1863. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1864. mask = 0x01;
  1865. val = 0x01;
  1866. }
  1867. if (interp == INTERP_HPHR) {
  1868. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1869. mask = 0x02;
  1870. val = 0x02;
  1871. }
  1872. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1873. snd_soc_component_update_bits(component, reg, mask, val);
  1874. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1875. snd_soc_component_update_bits(component, reg, mask, 0x00);
  1876. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1877. snd_soc_component_write(component,
  1878. BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1879. }
  1880. }
  1881. static void rx_macro_hphdelay_lutbypass(struct snd_soc_component *component,
  1882. struct rx_macro_priv *rx_priv,
  1883. u16 interp_idx, int event)
  1884. {
  1885. u16 hph_lut_bypass_reg = 0;
  1886. u16 hph_comp_ctrl7 = 0;
  1887. switch (interp_idx) {
  1888. case INTERP_HPHL:
  1889. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1890. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1891. break;
  1892. case INTERP_HPHR:
  1893. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1894. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1895. break;
  1896. default:
  1897. break;
  1898. }
  1899. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1900. if (interp_idx == INTERP_HPHL) {
  1901. if (rx_priv->is_ear_mode_on)
  1902. snd_soc_component_update_bits(component,
  1903. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1904. 0x02, 0x02);
  1905. else
  1906. snd_soc_component_update_bits(component,
  1907. hph_lut_bypass_reg,
  1908. 0x80, 0x80);
  1909. } else {
  1910. snd_soc_component_update_bits(component,
  1911. hph_lut_bypass_reg,
  1912. 0x80, 0x80);
  1913. }
  1914. if (rx_priv->hph_pwr_mode)
  1915. snd_soc_component_update_bits(component,
  1916. hph_comp_ctrl7,
  1917. 0x20, 0x00);
  1918. }
  1919. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1920. snd_soc_component_update_bits(component,
  1921. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1922. 0x02, 0x00);
  1923. snd_soc_component_update_bits(component, hph_lut_bypass_reg,
  1924. 0x80, 0x00);
  1925. snd_soc_component_update_bits(component, hph_comp_ctrl7,
  1926. 0x20, 0x20);
  1927. }
  1928. }
  1929. static int rx_macro_enable_interp_clk(struct snd_soc_component *component,
  1930. int event, int interp_idx)
  1931. {
  1932. u16 main_reg = 0, dsm_reg = 0, rx_cfg2_reg = 0;
  1933. struct device *rx_dev = NULL;
  1934. struct rx_macro_priv *rx_priv = NULL;
  1935. if (!component) {
  1936. pr_err("%s: component is NULL\n", __func__);
  1937. return -EINVAL;
  1938. }
  1939. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1940. return -EINVAL;
  1941. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1942. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1943. dsm_reg = BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL +
  1944. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1945. if (interp_idx == INTERP_AUX)
  1946. dsm_reg = BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL;
  1947. rx_cfg2_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG2 +
  1948. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1949. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1950. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1951. /* Main path PGA mute enable */
  1952. snd_soc_component_update_bits(component, main_reg,
  1953. 0x10, 0x10);
  1954. snd_soc_component_update_bits(component, dsm_reg,
  1955. 0x01, 0x01);
  1956. /* Clk enable */
  1957. snd_soc_component_update_bits(component, main_reg,
  1958. 0x20, 0x20);
  1959. snd_soc_component_update_bits(component, rx_cfg2_reg,
  1960. 0x03, 0x03);
  1961. rx_macro_idle_detect_control(component, rx_priv,
  1962. interp_idx, event);
  1963. if (rx_priv->hph_hd2_mode)
  1964. rx_macro_hd2_control(
  1965. component, interp_idx, event);
  1966. rx_macro_hphdelay_lutbypass(component, rx_priv,
  1967. interp_idx, event);
  1968. rx_macro_config_compander(component, rx_priv,
  1969. interp_idx, event);
  1970. if (interp_idx == INTERP_AUX)
  1971. rx_macro_config_softclip(component, rx_priv,
  1972. event);
  1973. rx_macro_config_classh(component, rx_priv,
  1974. interp_idx, event);
  1975. }
  1976. rx_priv->main_clk_users[interp_idx]++;
  1977. }
  1978. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1979. rx_priv->main_clk_users[interp_idx]--;
  1980. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  1981. rx_priv->main_clk_users[interp_idx] = 0;
  1982. /* Clk Disable */
  1983. snd_soc_component_update_bits(component, dsm_reg,
  1984. 0x01, 0x00);
  1985. snd_soc_component_update_bits(component, main_reg,
  1986. 0x20, 0x00);
  1987. /* Reset enable and disable */
  1988. snd_soc_component_update_bits(component, main_reg,
  1989. 0x40, 0x40);
  1990. snd_soc_component_update_bits(component, main_reg,
  1991. 0x40, 0x00);
  1992. /* Reset rate to 48K*/
  1993. snd_soc_component_update_bits(component, main_reg,
  1994. 0x0F, 0x04);
  1995. snd_soc_component_update_bits(component, rx_cfg2_reg,
  1996. 0x03, 0x00);
  1997. rx_macro_config_classh(component, rx_priv,
  1998. interp_idx, event);
  1999. rx_macro_config_compander(component, rx_priv,
  2000. interp_idx, event);
  2001. if (interp_idx == INTERP_AUX)
  2002. rx_macro_config_softclip(component, rx_priv,
  2003. event);
  2004. rx_macro_hphdelay_lutbypass(component, rx_priv,
  2005. interp_idx, event);
  2006. if (rx_priv->hph_hd2_mode)
  2007. rx_macro_hd2_control(component, interp_idx,
  2008. event);
  2009. rx_macro_idle_detect_control(component, rx_priv,
  2010. interp_idx, event);
  2011. }
  2012. }
  2013. dev_dbg(component->dev, "%s event %d main_clk_users %d\n",
  2014. __func__, event, rx_priv->main_clk_users[interp_idx]);
  2015. return rx_priv->main_clk_users[interp_idx];
  2016. }
  2017. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  2018. struct snd_kcontrol *kcontrol, int event)
  2019. {
  2020. struct snd_soc_component *component =
  2021. snd_soc_dapm_to_component(w->dapm);
  2022. u16 sidetone_reg = 0;
  2023. dev_dbg(component->dev, "%s %d %d\n", __func__, event, w->shift);
  2024. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  2025. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  2026. switch (event) {
  2027. case SND_SOC_DAPM_PRE_PMU:
  2028. rx_macro_enable_interp_clk(component, event, w->shift);
  2029. snd_soc_component_update_bits(component, sidetone_reg,
  2030. 0x10, 0x10);
  2031. break;
  2032. case SND_SOC_DAPM_POST_PMD:
  2033. snd_soc_component_update_bits(component, sidetone_reg,
  2034. 0x10, 0x00);
  2035. rx_macro_enable_interp_clk(component, event, w->shift);
  2036. break;
  2037. default:
  2038. break;
  2039. };
  2040. return 0;
  2041. }
  2042. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  2043. int band_idx)
  2044. {
  2045. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  2046. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2047. if (regmap == NULL) {
  2048. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2049. return;
  2050. }
  2051. regmap_write(regmap,
  2052. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2053. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2054. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  2055. /* 5 coefficients per band and 4 writes per coefficient */
  2056. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2057. coeff_idx++) {
  2058. /* Four 8 bit values(one 32 bit) per coefficient */
  2059. regmap_write(regmap, reg_add,
  2060. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2061. regmap_write(regmap, reg_add,
  2062. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2063. regmap_write(regmap, reg_add,
  2064. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2065. regmap_write(regmap, reg_add,
  2066. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2067. }
  2068. }
  2069. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2070. struct snd_ctl_elem_value *ucontrol)
  2071. {
  2072. struct snd_soc_component *component =
  2073. snd_soc_kcontrol_component(kcontrol);
  2074. int iir_idx = ((struct soc_multi_mixer_control *)
  2075. kcontrol->private_value)->reg;
  2076. int band_idx = ((struct soc_multi_mixer_control *)
  2077. kcontrol->private_value)->shift;
  2078. /* IIR filter band registers are at integer multiples of 0x80 */
  2079. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2080. ucontrol->value.integer.value[0] = (
  2081. snd_soc_component_read32(component, iir_reg) &
  2082. (1 << band_idx)) != 0;
  2083. dev_dbg(component->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  2084. iir_idx, band_idx,
  2085. (uint32_t)ucontrol->value.integer.value[0]);
  2086. return 0;
  2087. }
  2088. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2089. struct snd_ctl_elem_value *ucontrol)
  2090. {
  2091. struct snd_soc_component *component =
  2092. snd_soc_kcontrol_component(kcontrol);
  2093. int iir_idx = ((struct soc_multi_mixer_control *)
  2094. kcontrol->private_value)->reg;
  2095. int band_idx = ((struct soc_multi_mixer_control *)
  2096. kcontrol->private_value)->shift;
  2097. bool iir_band_en_status = 0;
  2098. int value = ucontrol->value.integer.value[0];
  2099. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2100. struct device *rx_dev = NULL;
  2101. struct rx_macro_priv *rx_priv = NULL;
  2102. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2103. return -EINVAL;
  2104. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  2105. /* Mask first 5 bits, 6-8 are reserved */
  2106. snd_soc_component_update_bits(component, iir_reg, (1 << band_idx),
  2107. (value << band_idx));
  2108. iir_band_en_status = ((snd_soc_component_read32(component, iir_reg) &
  2109. (1 << band_idx)) != 0);
  2110. dev_dbg(component->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  2111. iir_idx, band_idx, iir_band_en_status);
  2112. return 0;
  2113. }
  2114. static uint32_t get_iir_band_coeff(struct snd_soc_component *component,
  2115. int iir_idx, int band_idx,
  2116. int coeff_idx)
  2117. {
  2118. uint32_t value = 0;
  2119. /* Address does not automatically update if reading */
  2120. snd_soc_component_write(component,
  2121. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2122. ((band_idx * BAND_MAX + coeff_idx)
  2123. * sizeof(uint32_t)) & 0x7F);
  2124. value |= snd_soc_component_read32(component,
  2125. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  2126. snd_soc_component_write(component,
  2127. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2128. ((band_idx * BAND_MAX + coeff_idx)
  2129. * sizeof(uint32_t) + 1) & 0x7F);
  2130. value |= (snd_soc_component_read32(component,
  2131. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2132. 0x80 * iir_idx)) << 8);
  2133. snd_soc_component_write(component,
  2134. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2135. ((band_idx * BAND_MAX + coeff_idx)
  2136. * sizeof(uint32_t) + 2) & 0x7F);
  2137. value |= (snd_soc_component_read32(component,
  2138. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2139. 0x80 * iir_idx)) << 16);
  2140. snd_soc_component_write(component,
  2141. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2142. ((band_idx * BAND_MAX + coeff_idx)
  2143. * sizeof(uint32_t) + 3) & 0x7F);
  2144. /* Mask bits top 2 bits since they are reserved */
  2145. value |= ((snd_soc_component_read32(component,
  2146. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2147. 16 * iir_idx)) & 0x3F) << 24);
  2148. return value;
  2149. }
  2150. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2151. struct snd_ctl_elem_value *ucontrol)
  2152. {
  2153. struct snd_soc_component *component =
  2154. snd_soc_kcontrol_component(kcontrol);
  2155. int iir_idx = ((struct soc_multi_mixer_control *)
  2156. kcontrol->private_value)->reg;
  2157. int band_idx = ((struct soc_multi_mixer_control *)
  2158. kcontrol->private_value)->shift;
  2159. ucontrol->value.integer.value[0] =
  2160. get_iir_band_coeff(component, iir_idx, band_idx, 0);
  2161. ucontrol->value.integer.value[1] =
  2162. get_iir_band_coeff(component, iir_idx, band_idx, 1);
  2163. ucontrol->value.integer.value[2] =
  2164. get_iir_band_coeff(component, iir_idx, band_idx, 2);
  2165. ucontrol->value.integer.value[3] =
  2166. get_iir_band_coeff(component, iir_idx, band_idx, 3);
  2167. ucontrol->value.integer.value[4] =
  2168. get_iir_band_coeff(component, iir_idx, band_idx, 4);
  2169. dev_dbg(component->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  2170. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2171. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2172. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2173. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2174. __func__, iir_idx, band_idx,
  2175. (uint32_t)ucontrol->value.integer.value[0],
  2176. __func__, iir_idx, band_idx,
  2177. (uint32_t)ucontrol->value.integer.value[1],
  2178. __func__, iir_idx, band_idx,
  2179. (uint32_t)ucontrol->value.integer.value[2],
  2180. __func__, iir_idx, band_idx,
  2181. (uint32_t)ucontrol->value.integer.value[3],
  2182. __func__, iir_idx, band_idx,
  2183. (uint32_t)ucontrol->value.integer.value[4]);
  2184. return 0;
  2185. }
  2186. static void set_iir_band_coeff(struct snd_soc_component *component,
  2187. int iir_idx, int band_idx,
  2188. uint32_t value)
  2189. {
  2190. snd_soc_component_write(component,
  2191. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2192. (value & 0xFF));
  2193. snd_soc_component_write(component,
  2194. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2195. (value >> 8) & 0xFF);
  2196. snd_soc_component_write(component,
  2197. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2198. (value >> 16) & 0xFF);
  2199. /* Mask top 2 bits, 7-8 are reserved */
  2200. snd_soc_component_write(component,
  2201. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2202. (value >> 24) & 0x3F);
  2203. }
  2204. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2205. struct snd_ctl_elem_value *ucontrol)
  2206. {
  2207. struct snd_soc_component *component =
  2208. snd_soc_kcontrol_component(kcontrol);
  2209. int iir_idx = ((struct soc_multi_mixer_control *)
  2210. kcontrol->private_value)->reg;
  2211. int band_idx = ((struct soc_multi_mixer_control *)
  2212. kcontrol->private_value)->shift;
  2213. int coeff_idx, idx = 0;
  2214. struct device *rx_dev = NULL;
  2215. struct rx_macro_priv *rx_priv = NULL;
  2216. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2217. return -EINVAL;
  2218. /*
  2219. * Mask top bit it is reserved
  2220. * Updates addr automatically for each B2 write
  2221. */
  2222. snd_soc_component_write(component,
  2223. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  2224. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2225. /* Store the coefficients in sidetone coeff array */
  2226. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2227. coeff_idx++) {
  2228. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  2229. set_iir_band_coeff(component, iir_idx, band_idx, value);
  2230. /* Four 8 bit values(one 32 bit) per coefficient */
  2231. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2232. (value & 0xFF);
  2233. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2234. (value >> 8) & 0xFF;
  2235. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2236. (value >> 16) & 0xFF;
  2237. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2238. (value >> 24) & 0xFF;
  2239. }
  2240. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  2241. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2242. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2243. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2244. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2245. __func__, iir_idx, band_idx,
  2246. get_iir_band_coeff(component, iir_idx, band_idx, 0),
  2247. __func__, iir_idx, band_idx,
  2248. get_iir_band_coeff(component, iir_idx, band_idx, 1),
  2249. __func__, iir_idx, band_idx,
  2250. get_iir_band_coeff(component, iir_idx, band_idx, 2),
  2251. __func__, iir_idx, band_idx,
  2252. get_iir_band_coeff(component, iir_idx, band_idx, 3),
  2253. __func__, iir_idx, band_idx,
  2254. get_iir_band_coeff(component, iir_idx, band_idx, 4));
  2255. return 0;
  2256. }
  2257. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  2258. struct snd_kcontrol *kcontrol, int event)
  2259. {
  2260. struct snd_soc_component *component =
  2261. snd_soc_dapm_to_component(w->dapm);
  2262. dev_dbg(component->dev, "%s: event = %d\n", __func__, event);
  2263. switch (event) {
  2264. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2265. case SND_SOC_DAPM_PRE_PMD:
  2266. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  2267. snd_soc_component_write(component,
  2268. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2269. snd_soc_component_read32(component,
  2270. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2271. snd_soc_component_write(component,
  2272. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2273. snd_soc_component_read32(component,
  2274. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2275. snd_soc_component_write(component,
  2276. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2277. snd_soc_component_read32(component,
  2278. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2279. snd_soc_component_write(component,
  2280. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2281. snd_soc_component_read32(component,
  2282. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2283. } else {
  2284. snd_soc_component_write(component,
  2285. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  2286. snd_soc_component_read32(component,
  2287. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  2288. snd_soc_component_write(component,
  2289. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  2290. snd_soc_component_read32(component,
  2291. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  2292. snd_soc_component_write(component,
  2293. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  2294. snd_soc_component_read32(component,
  2295. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  2296. snd_soc_component_write(component,
  2297. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  2298. snd_soc_component_read32(component,
  2299. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  2300. }
  2301. break;
  2302. }
  2303. return 0;
  2304. }
  2305. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  2306. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  2307. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  2308. 0, -84, 40, digital_gain),
  2309. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  2310. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  2311. 0, -84, 40, digital_gain),
  2312. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  2313. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  2314. 0, -84, 40, digital_gain),
  2315. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  2316. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2317. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  2318. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2319. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  2320. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2321. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  2322. rx_macro_get_compander, rx_macro_set_compander),
  2323. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  2324. rx_macro_get_compander, rx_macro_set_compander),
  2325. SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum,
  2326. rx_macro_hph_idle_detect_get, rx_macro_hph_idle_detect_put),
  2327. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  2328. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  2329. SOC_ENUM_EXT("RX_HPH HD2 Mode", rx_macro_hph_hd2_mode_enum,
  2330. rx_macro_get_hph_hd2_mode, rx_macro_put_hph_hd2_mode),
  2331. SOC_ENUM_EXT("RX_HPH_PWR_MODE", rx_macro_hph_pwr_mode_enum,
  2332. rx_macro_get_hph_pwr_mode, rx_macro_put_hph_pwr_mode),
  2333. SOC_ENUM_EXT("RX_GSM mode Enable", rx_macro_vbat_bcl_gsm_mode_enum,
  2334. rx_macro_vbat_bcl_gsm_mode_func_get,
  2335. rx_macro_vbat_bcl_gsm_mode_func_put),
  2336. SOC_SINGLE_EXT("RX_Softclip Enable", SND_SOC_NOPM, 0, 1, 0,
  2337. rx_macro_soft_clip_enable_get,
  2338. rx_macro_soft_clip_enable_put),
  2339. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  2340. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  2341. digital_gain),
  2342. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  2343. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  2344. digital_gain),
  2345. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  2346. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  2347. digital_gain),
  2348. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  2349. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  2350. digital_gain),
  2351. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  2352. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  2353. digital_gain),
  2354. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  2355. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  2356. digital_gain),
  2357. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  2358. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  2359. digital_gain),
  2360. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  2361. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  2362. digital_gain),
  2363. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  2364. rx_macro_iir_enable_audio_mixer_get,
  2365. rx_macro_iir_enable_audio_mixer_put),
  2366. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  2367. rx_macro_iir_enable_audio_mixer_get,
  2368. rx_macro_iir_enable_audio_mixer_put),
  2369. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  2370. rx_macro_iir_enable_audio_mixer_get,
  2371. rx_macro_iir_enable_audio_mixer_put),
  2372. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  2373. rx_macro_iir_enable_audio_mixer_get,
  2374. rx_macro_iir_enable_audio_mixer_put),
  2375. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  2376. rx_macro_iir_enable_audio_mixer_get,
  2377. rx_macro_iir_enable_audio_mixer_put),
  2378. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  2379. rx_macro_iir_enable_audio_mixer_get,
  2380. rx_macro_iir_enable_audio_mixer_put),
  2381. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  2382. rx_macro_iir_enable_audio_mixer_get,
  2383. rx_macro_iir_enable_audio_mixer_put),
  2384. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  2385. rx_macro_iir_enable_audio_mixer_get,
  2386. rx_macro_iir_enable_audio_mixer_put),
  2387. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  2388. rx_macro_iir_enable_audio_mixer_get,
  2389. rx_macro_iir_enable_audio_mixer_put),
  2390. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  2391. rx_macro_iir_enable_audio_mixer_get,
  2392. rx_macro_iir_enable_audio_mixer_put),
  2393. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  2394. rx_macro_iir_band_audio_mixer_get,
  2395. rx_macro_iir_band_audio_mixer_put),
  2396. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  2397. rx_macro_iir_band_audio_mixer_get,
  2398. rx_macro_iir_band_audio_mixer_put),
  2399. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  2400. rx_macro_iir_band_audio_mixer_get,
  2401. rx_macro_iir_band_audio_mixer_put),
  2402. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  2403. rx_macro_iir_band_audio_mixer_get,
  2404. rx_macro_iir_band_audio_mixer_put),
  2405. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  2406. rx_macro_iir_band_audio_mixer_get,
  2407. rx_macro_iir_band_audio_mixer_put),
  2408. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  2409. rx_macro_iir_band_audio_mixer_get,
  2410. rx_macro_iir_band_audio_mixer_put),
  2411. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  2412. rx_macro_iir_band_audio_mixer_get,
  2413. rx_macro_iir_band_audio_mixer_put),
  2414. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  2415. rx_macro_iir_band_audio_mixer_get,
  2416. rx_macro_iir_band_audio_mixer_put),
  2417. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  2418. rx_macro_iir_band_audio_mixer_get,
  2419. rx_macro_iir_band_audio_mixer_put),
  2420. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  2421. rx_macro_iir_band_audio_mixer_get,
  2422. rx_macro_iir_band_audio_mixer_put),
  2423. };
  2424. static int rx_macro_enable_echo(struct snd_soc_dapm_widget *w,
  2425. struct snd_kcontrol *kcontrol,
  2426. int event)
  2427. {
  2428. struct snd_soc_component *component =
  2429. snd_soc_dapm_to_component(w->dapm);
  2430. struct device *rx_dev = NULL;
  2431. struct rx_macro_priv *rx_priv = NULL;
  2432. u16 val = 0, ec_hq_reg = 0;
  2433. int ec_tx = 0;
  2434. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2435. return -EINVAL;
  2436. dev_dbg(rx_dev, "%s %d %s\n", __func__, event, w->name);
  2437. val = snd_soc_component_read32(component,
  2438. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4);
  2439. if (!(strcmp(w->name, "RX MIX TX0 MUX")))
  2440. ec_tx = ((val & 0xf0) >> 0x4) - 1;
  2441. else if (!(strcmp(w->name, "RX MIX TX1 MUX")))
  2442. ec_tx = (val & 0x0f) - 1;
  2443. val = snd_soc_component_read32(component,
  2444. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5);
  2445. if (!(strcmp(w->name, "RX MIX TX2 MUX")))
  2446. ec_tx = (val & 0x0f) - 1;
  2447. if (ec_tx < 0 || (ec_tx >= RX_MACRO_EC_MUX_MAX)) {
  2448. dev_err(rx_dev, "%s: EC mix control not set correctly\n",
  2449. __func__);
  2450. return -EINVAL;
  2451. }
  2452. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_PATH_CTL +
  2453. 0x40 * ec_tx;
  2454. snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
  2455. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_CFG0 +
  2456. 0x40 * ec_tx;
  2457. /* default set to 48k */
  2458. snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
  2459. return 0;
  2460. }
  2461. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  2462. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  2463. SND_SOC_NOPM, 0, 0),
  2464. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  2465. SND_SOC_NOPM, 0, 0),
  2466. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  2467. SND_SOC_NOPM, 0, 0),
  2468. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  2469. SND_SOC_NOPM, 0, 0),
  2470. SND_SOC_DAPM_AIF_OUT("RX AIF_ECHO", "RX_AIF_ECHO Capture", 0,
  2471. SND_SOC_NOPM, 0, 0),
  2472. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  2473. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  2474. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  2475. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  2476. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  2477. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  2478. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2479. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2480. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2481. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2482. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2483. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2484. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  2485. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  2486. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  2487. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  2488. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  2489. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  2490. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  2491. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  2492. SND_SOC_DAPM_MUX_E("RX MIX TX0 MUX", SND_SOC_NOPM,
  2493. RX_MACRO_EC0_MUX, 0,
  2494. &rx_mix_tx0_mux, rx_macro_enable_echo,
  2495. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2496. SND_SOC_DAPM_MUX_E("RX MIX TX1 MUX", SND_SOC_NOPM,
  2497. RX_MACRO_EC1_MUX, 0,
  2498. &rx_mix_tx1_mux, rx_macro_enable_echo,
  2499. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2500. SND_SOC_DAPM_MUX_E("RX MIX TX2 MUX", SND_SOC_NOPM,
  2501. RX_MACRO_EC2_MUX, 0,
  2502. &rx_mix_tx2_mux, rx_macro_enable_echo,
  2503. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2504. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  2505. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2506. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2507. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  2508. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2509. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2510. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  2511. 4, 0, NULL, 0),
  2512. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  2513. 4, 0, NULL, 0),
  2514. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  2515. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  2516. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2517. &rx_int0_2_mux, rx_macro_enable_mix_path,
  2518. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2519. SND_SOC_DAPM_POST_PMD),
  2520. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2521. &rx_int1_2_mux, rx_macro_enable_mix_path,
  2522. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2523. SND_SOC_DAPM_POST_PMD),
  2524. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  2525. &rx_int2_2_mux, rx_macro_enable_mix_path,
  2526. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2527. SND_SOC_DAPM_POST_PMD),
  2528. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  2529. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  2530. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  2531. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  2532. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  2533. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  2534. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  2535. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  2536. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  2537. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  2538. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  2539. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2540. SND_SOC_DAPM_POST_PMD),
  2541. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  2542. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  2543. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2544. SND_SOC_DAPM_POST_PMD),
  2545. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  2546. &rx_int2_1_interp_mux, rx_macro_enable_main_path,
  2547. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2548. SND_SOC_DAPM_POST_PMD),
  2549. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  2550. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2551. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2552. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2553. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2554. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2555. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2556. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2557. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2558. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  2559. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2560. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2561. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  2562. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2563. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2564. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  2565. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2566. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2567. SND_SOC_DAPM_MIXER_E("RX INT2_1 VBAT", SND_SOC_NOPM,
  2568. 0, 0, rx_int2_1_vbat_mix_switch,
  2569. ARRAY_SIZE(rx_int2_1_vbat_mix_switch),
  2570. rx_macro_enable_vbat,
  2571. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2572. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2573. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2574. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2575. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  2576. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  2577. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  2578. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  2579. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  2580. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  2581. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  2582. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2583. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2584. };
  2585. static const struct snd_soc_dapm_route rx_audio_map[] = {
  2586. {"RX AIF1 PB", NULL, "RX_MCLK"},
  2587. {"RX AIF2 PB", NULL, "RX_MCLK"},
  2588. {"RX AIF3 PB", NULL, "RX_MCLK"},
  2589. {"RX AIF4 PB", NULL, "RX_MCLK"},
  2590. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  2591. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  2592. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  2593. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  2594. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  2595. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  2596. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  2597. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  2598. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  2599. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  2600. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  2601. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  2602. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  2603. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  2604. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  2605. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  2606. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  2607. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  2608. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  2609. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  2610. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  2611. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  2612. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  2613. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  2614. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  2615. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  2616. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  2617. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  2618. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  2619. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  2620. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  2621. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  2622. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  2623. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  2624. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  2625. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  2626. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  2627. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  2628. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  2629. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  2630. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  2631. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  2632. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  2633. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  2634. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  2635. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  2636. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  2637. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  2638. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  2639. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  2640. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  2641. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  2642. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  2643. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  2644. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  2645. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  2646. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  2647. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  2648. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  2649. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  2650. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  2651. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  2652. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  2653. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  2654. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  2655. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  2656. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  2657. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  2658. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  2659. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  2660. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  2661. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  2662. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  2663. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  2664. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  2665. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  2666. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  2667. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  2668. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  2669. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  2670. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  2671. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  2672. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  2673. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  2674. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  2675. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  2676. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  2677. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  2678. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  2679. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  2680. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  2681. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  2682. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  2683. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  2684. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  2685. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  2686. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  2687. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  2688. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  2689. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  2690. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  2691. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  2692. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  2693. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  2694. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  2695. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  2696. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  2697. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  2698. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  2699. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  2700. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  2701. {"RX MIX TX0 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2702. {"RX MIX TX0 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2703. {"RX MIX TX0 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2704. {"RX MIX TX1 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2705. {"RX MIX TX1 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2706. {"RX MIX TX1 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2707. {"RX MIX TX2 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2708. {"RX MIX TX2 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2709. {"RX MIX TX2 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2710. {"RX AIF_ECHO", NULL, "RX MIX TX0 MUX"},
  2711. {"RX AIF_ECHO", NULL, "RX MIX TX1 MUX"},
  2712. {"RX AIF_ECHO", NULL, "RX MIX TX2 MUX"},
  2713. {"RX AIF_ECHO", NULL, "RX_MCLK"},
  2714. /* Mixing path INT0 */
  2715. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  2716. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  2717. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  2718. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  2719. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  2720. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  2721. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  2722. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  2723. /* Mixing path INT1 */
  2724. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  2725. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  2726. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  2727. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  2728. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  2729. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  2730. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  2731. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  2732. /* Mixing path INT2 */
  2733. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  2734. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  2735. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  2736. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  2737. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  2738. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  2739. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  2740. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  2741. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  2742. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  2743. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  2744. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  2745. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  2746. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  2747. {"HPHL_OUT", NULL, "RX_MCLK"},
  2748. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  2749. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  2750. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  2751. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  2752. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  2753. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  2754. {"HPHR_OUT", NULL, "RX_MCLK"},
  2755. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  2756. {"RX INT2_1 VBAT", "RX AUX VBAT Enable", "RX INT2_1 INTERP"},
  2757. {"RX INT2 SEC MIX", NULL, "RX INT2_1 VBAT"},
  2758. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  2759. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2760. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2761. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2762. {"AUX_OUT", NULL, "RX_MCLK"},
  2763. {"IIR0", NULL, "RX_MCLK"},
  2764. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2765. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2766. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2767. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2768. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2769. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2770. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2771. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2772. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2773. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2774. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2775. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2776. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2777. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2778. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2779. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2780. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2781. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2782. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2783. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2784. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2785. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2786. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2787. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2788. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2789. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2790. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2791. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2792. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2793. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2794. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2795. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2796. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2797. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2798. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2799. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2800. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2801. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2802. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2803. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2804. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2805. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2806. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2807. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2808. {"IIR1", NULL, "RX_MCLK"},
  2809. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2810. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2811. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2812. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2813. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2814. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2815. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2816. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2817. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2818. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2819. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2820. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2821. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2822. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2823. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2824. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2825. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2826. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2827. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2828. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2829. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2830. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2831. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2832. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2833. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2834. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2835. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2836. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2837. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2838. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2839. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2840. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2841. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2842. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2843. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2844. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2845. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2846. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2847. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2848. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2849. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2850. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2851. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2852. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2853. {"SRC0", NULL, "IIR0"},
  2854. {"SRC1", NULL, "IIR1"},
  2855. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2856. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2857. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2858. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2859. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2860. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2861. };
  2862. static int rx_swrm_clock(void *handle, bool enable)
  2863. {
  2864. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2865. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2866. int ret = 0;
  2867. if (regmap == NULL) {
  2868. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2869. return -EINVAL;
  2870. }
  2871. mutex_lock(&rx_priv->swr_clk_lock);
  2872. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2873. __func__, (enable ? "enable" : "disable"));
  2874. if (enable) {
  2875. pm_runtime_get_sync(rx_priv->dev);
  2876. if (rx_priv->swr_clk_users == 0) {
  2877. msm_cdc_pinctrl_select_active_state(
  2878. rx_priv->rx_swr_gpio_p);
  2879. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2880. if (ret < 0) {
  2881. msm_cdc_pinctrl_select_sleep_state(
  2882. rx_priv->rx_swr_gpio_p);
  2883. dev_err(rx_priv->dev,
  2884. "%s: rx request clock enable failed\n",
  2885. __func__);
  2886. goto exit;
  2887. }
  2888. if (rx_priv->reset_swr)
  2889. regmap_update_bits(regmap,
  2890. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2891. 0x02, 0x02);
  2892. regmap_update_bits(regmap,
  2893. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2894. 0x01, 0x01);
  2895. if (rx_priv->reset_swr)
  2896. regmap_update_bits(regmap,
  2897. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2898. 0x02, 0x00);
  2899. rx_priv->reset_swr = false;
  2900. }
  2901. pm_runtime_mark_last_busy(rx_priv->dev);
  2902. pm_runtime_put_autosuspend(rx_priv->dev);
  2903. rx_priv->swr_clk_users++;
  2904. } else {
  2905. if (rx_priv->swr_clk_users <= 0) {
  2906. dev_err(rx_priv->dev,
  2907. "%s: rx swrm clock users already reset\n",
  2908. __func__);
  2909. rx_priv->swr_clk_users = 0;
  2910. goto exit;
  2911. }
  2912. rx_priv->swr_clk_users--;
  2913. if (rx_priv->swr_clk_users == 0) {
  2914. regmap_update_bits(regmap,
  2915. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2916. 0x01, 0x00);
  2917. rx_macro_mclk_enable(rx_priv, 0, true);
  2918. msm_cdc_pinctrl_select_sleep_state(
  2919. rx_priv->rx_swr_gpio_p);
  2920. }
  2921. }
  2922. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2923. __func__, rx_priv->swr_clk_users);
  2924. exit:
  2925. mutex_unlock(&rx_priv->swr_clk_lock);
  2926. return ret;
  2927. }
  2928. static void rx_macro_init_bcl_pmic_reg(struct snd_soc_component *component)
  2929. {
  2930. struct device *rx_dev = NULL;
  2931. struct rx_macro_priv *rx_priv = NULL;
  2932. if (!component) {
  2933. pr_err("%s: NULL component pointer!\n", __func__);
  2934. return;
  2935. }
  2936. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2937. return;
  2938. switch (rx_priv->bcl_pmic_params.id) {
  2939. case 0:
  2940. /* Enable ID0 to listen to respective PMIC group interrupts */
  2941. snd_soc_component_update_bits(component,
  2942. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2943. /* Update MC_SID0 */
  2944. snd_soc_component_update_bits(component,
  2945. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0x0F,
  2946. rx_priv->bcl_pmic_params.sid);
  2947. /* Update MC_PPID0 */
  2948. snd_soc_component_update_bits(component,
  2949. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG2, 0xFF,
  2950. rx_priv->bcl_pmic_params.ppid);
  2951. break;
  2952. case 1:
  2953. /* Enable ID1 to listen to respective PMIC group interrupts */
  2954. snd_soc_component_update_bits(component,
  2955. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2956. /* Update MC_SID1 */
  2957. snd_soc_component_update_bits(component,
  2958. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG3, 0x0F,
  2959. rx_priv->bcl_pmic_params.sid);
  2960. /* Update MC_PPID1 */
  2961. snd_soc_component_update_bits(component,
  2962. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0xFF,
  2963. rx_priv->bcl_pmic_params.ppid);
  2964. break;
  2965. default:
  2966. dev_err(rx_dev, "%s: PMIC ID is invalid %d\n",
  2967. __func__, rx_priv->bcl_pmic_params.id);
  2968. break;
  2969. }
  2970. }
  2971. static int rx_macro_init(struct snd_soc_component *component)
  2972. {
  2973. struct snd_soc_dapm_context *dapm =
  2974. snd_soc_component_get_dapm(component);
  2975. int ret = 0;
  2976. struct device *rx_dev = NULL;
  2977. struct rx_macro_priv *rx_priv = NULL;
  2978. rx_dev = bolero_get_device_ptr(component->dev, RX_MACRO);
  2979. if (!rx_dev) {
  2980. dev_err(component->dev,
  2981. "%s: null device for macro!\n", __func__);
  2982. return -EINVAL;
  2983. }
  2984. rx_priv = dev_get_drvdata(rx_dev);
  2985. if (!rx_priv) {
  2986. dev_err(component->dev,
  2987. "%s: priv is null for macro!\n", __func__);
  2988. return -EINVAL;
  2989. }
  2990. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  2991. ARRAY_SIZE(rx_macro_dapm_widgets));
  2992. if (ret < 0) {
  2993. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  2994. return ret;
  2995. }
  2996. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  2997. ARRAY_SIZE(rx_audio_map));
  2998. if (ret < 0) {
  2999. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  3000. return ret;
  3001. }
  3002. ret = snd_soc_dapm_new_widgets(dapm->card);
  3003. if (ret < 0) {
  3004. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  3005. return ret;
  3006. }
  3007. ret = snd_soc_add_component_controls(component, rx_macro_snd_controls,
  3008. ARRAY_SIZE(rx_macro_snd_controls));
  3009. if (ret < 0) {
  3010. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  3011. return ret;
  3012. }
  3013. rx_priv->dev_up = true;
  3014. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF1 Playback");
  3015. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF2 Playback");
  3016. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF3 Playback");
  3017. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF4 Playback");
  3018. snd_soc_dapm_ignore_suspend(dapm, "HPHL_OUT");
  3019. snd_soc_dapm_ignore_suspend(dapm, "HPHR_OUT");
  3020. snd_soc_dapm_ignore_suspend(dapm, "AUX_OUT");
  3021. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC0_INP");
  3022. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC1_INP");
  3023. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC2_INP");
  3024. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC3_INP");
  3025. snd_soc_dapm_sync(dapm);
  3026. snd_soc_component_update_bits(component,
  3027. BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL,
  3028. 0x01, 0x01);
  3029. snd_soc_component_update_bits(component,
  3030. BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL,
  3031. 0x01, 0x01);
  3032. snd_soc_component_update_bits(component,
  3033. BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL,
  3034. 0x01, 0x01);
  3035. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_SEC7,
  3036. 0x07, 0x02);
  3037. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_SEC7,
  3038. 0x07, 0x02);
  3039. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  3040. 0x07, 0x02);
  3041. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_CFG3,
  3042. 0x03, 0x02);
  3043. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_CFG3,
  3044. 0x03, 0x02);
  3045. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_CFG3,
  3046. 0x03, 0x02);
  3047. rx_priv->component = component;
  3048. rx_macro_init_bcl_pmic_reg(component);
  3049. return 0;
  3050. }
  3051. static int rx_macro_deinit(struct snd_soc_component *component)
  3052. {
  3053. struct device *rx_dev = NULL;
  3054. struct rx_macro_priv *rx_priv = NULL;
  3055. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  3056. return -EINVAL;
  3057. rx_priv->component = NULL;
  3058. return 0;
  3059. }
  3060. static void rx_macro_add_child_devices(struct work_struct *work)
  3061. {
  3062. struct rx_macro_priv *rx_priv = NULL;
  3063. struct platform_device *pdev = NULL;
  3064. struct device_node *node = NULL;
  3065. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  3066. int ret = 0;
  3067. u16 count = 0, ctrl_num = 0;
  3068. struct rx_swr_ctrl_platform_data *platdata = NULL;
  3069. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  3070. bool rx_swr_master_node = false;
  3071. rx_priv = container_of(work, struct rx_macro_priv,
  3072. rx_macro_add_child_devices_work);
  3073. if (!rx_priv) {
  3074. pr_err("%s: Memory for rx_priv does not exist\n",
  3075. __func__);
  3076. return;
  3077. }
  3078. if (!rx_priv->dev) {
  3079. pr_err("%s: RX device does not exist\n", __func__);
  3080. return;
  3081. }
  3082. if(!rx_priv->dev->of_node) {
  3083. dev_err(rx_priv->dev,
  3084. "%s: DT node for RX dev does not exist\n", __func__);
  3085. return;
  3086. }
  3087. platdata = &rx_priv->swr_plat_data;
  3088. rx_priv->child_count = 0;
  3089. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  3090. rx_swr_master_node = false;
  3091. if (strnstr(node->name, "rx_swr_master",
  3092. strlen("rx_swr_master")) != NULL)
  3093. rx_swr_master_node = true;
  3094. if(rx_swr_master_node)
  3095. strlcpy(plat_dev_name, "rx_swr_ctrl",
  3096. (RX_SWR_STRING_LEN - 1));
  3097. else
  3098. strlcpy(plat_dev_name, node->name,
  3099. (RX_SWR_STRING_LEN - 1));
  3100. pdev = platform_device_alloc(plat_dev_name, -1);
  3101. if (!pdev) {
  3102. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  3103. __func__);
  3104. ret = -ENOMEM;
  3105. goto err;
  3106. }
  3107. pdev->dev.parent = rx_priv->dev;
  3108. pdev->dev.of_node = node;
  3109. if (rx_swr_master_node) {
  3110. ret = platform_device_add_data(pdev, platdata,
  3111. sizeof(*platdata));
  3112. if (ret) {
  3113. dev_err(&pdev->dev,
  3114. "%s: cannot add plat data ctrl:%d\n",
  3115. __func__, ctrl_num);
  3116. goto fail_pdev_add;
  3117. }
  3118. }
  3119. ret = platform_device_add(pdev);
  3120. if (ret) {
  3121. dev_err(&pdev->dev,
  3122. "%s: Cannot add platform device\n",
  3123. __func__);
  3124. goto fail_pdev_add;
  3125. }
  3126. if (rx_swr_master_node) {
  3127. temp = krealloc(swr_ctrl_data,
  3128. (ctrl_num + 1) * sizeof(
  3129. struct rx_swr_ctrl_data),
  3130. GFP_KERNEL);
  3131. if (!temp) {
  3132. ret = -ENOMEM;
  3133. goto fail_pdev_add;
  3134. }
  3135. swr_ctrl_data = temp;
  3136. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  3137. ctrl_num++;
  3138. dev_dbg(&pdev->dev,
  3139. "%s: Added soundwire ctrl device(s)\n",
  3140. __func__);
  3141. rx_priv->swr_ctrl_data = swr_ctrl_data;
  3142. }
  3143. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  3144. rx_priv->pdev_child_devices[
  3145. rx_priv->child_count++] = pdev;
  3146. else
  3147. goto err;
  3148. }
  3149. return;
  3150. fail_pdev_add:
  3151. for (count = 0; count < rx_priv->child_count; count++)
  3152. platform_device_put(rx_priv->pdev_child_devices[count]);
  3153. err:
  3154. return;
  3155. }
  3156. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  3157. {
  3158. memset(ops, 0, sizeof(struct macro_ops));
  3159. ops->init = rx_macro_init;
  3160. ops->exit = rx_macro_deinit;
  3161. ops->io_base = rx_io_base;
  3162. ops->dai_ptr = rx_macro_dai;
  3163. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  3164. ops->event_handler = rx_macro_event_handler;
  3165. ops->set_port_map = rx_macro_set_port_map;
  3166. }
  3167. static int rx_macro_probe(struct platform_device *pdev)
  3168. {
  3169. struct macro_ops ops = {0};
  3170. struct rx_macro_priv *rx_priv = NULL;
  3171. u32 rx_base_addr = 0, muxsel = 0;
  3172. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  3173. int ret = 0;
  3174. u8 bcl_pmic_params[3];
  3175. u32 default_clk_id = 0;
  3176. u32 is_used_rx_swr_gpio = 1;
  3177. const char *is_used_rx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  3178. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  3179. GFP_KERNEL);
  3180. if (!rx_priv)
  3181. return -ENOMEM;
  3182. rx_priv->dev = &pdev->dev;
  3183. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  3184. &rx_base_addr);
  3185. if (ret) {
  3186. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3187. __func__, "reg");
  3188. return ret;
  3189. }
  3190. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  3191. &muxsel);
  3192. if (ret) {
  3193. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3194. __func__, "reg");
  3195. return ret;
  3196. }
  3197. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  3198. &default_clk_id);
  3199. if (ret) {
  3200. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3201. __func__, "qcom,default-clk-id");
  3202. default_clk_id = RX_CORE_CLK;
  3203. }
  3204. if (of_find_property(pdev->dev.of_node, is_used_rx_swr_gpio_dt,
  3205. NULL)) {
  3206. ret = of_property_read_u32(pdev->dev.of_node,
  3207. is_used_rx_swr_gpio_dt,
  3208. &is_used_rx_swr_gpio);
  3209. if (ret) {
  3210. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  3211. __func__, is_used_rx_swr_gpio_dt);
  3212. is_used_rx_swr_gpio = 1;
  3213. }
  3214. }
  3215. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3216. "qcom,rx-swr-gpios", 0);
  3217. if (!rx_priv->rx_swr_gpio_p && is_used_rx_swr_gpio) {
  3218. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  3219. __func__);
  3220. return -EINVAL;
  3221. }
  3222. if (msm_cdc_pinctrl_get_state(rx_priv->rx_swr_gpio_p) < 0) {
  3223. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  3224. __func__);
  3225. return -EPROBE_DEFER;
  3226. }
  3227. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  3228. RX_MACRO_MAX_OFFSET);
  3229. if (!rx_io_base) {
  3230. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  3231. return -ENOMEM;
  3232. }
  3233. rx_priv->rx_io_base = rx_io_base;
  3234. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  3235. if (!muxsel_io) {
  3236. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  3237. __func__);
  3238. return -ENOMEM;
  3239. }
  3240. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  3241. rx_priv->reset_swr = true;
  3242. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  3243. rx_macro_add_child_devices);
  3244. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  3245. rx_priv->swr_plat_data.read = NULL;
  3246. rx_priv->swr_plat_data.write = NULL;
  3247. rx_priv->swr_plat_data.bulk_write = NULL;
  3248. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  3249. rx_priv->swr_plat_data.handle_irq = NULL;
  3250. ret = of_property_read_u8_array(pdev->dev.of_node,
  3251. "qcom,rx-bcl-pmic-params", bcl_pmic_params,
  3252. sizeof(bcl_pmic_params));
  3253. if (ret) {
  3254. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  3255. __func__, "qcom,rx-bcl-pmic-params");
  3256. } else {
  3257. rx_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  3258. rx_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  3259. rx_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  3260. }
  3261. rx_priv->clk_id = default_clk_id;
  3262. rx_priv->default_clk_id = default_clk_id;
  3263. ops.clk_id_req = rx_priv->clk_id;
  3264. ops.default_clk_id = default_clk_id;
  3265. dev_set_drvdata(&pdev->dev, rx_priv);
  3266. mutex_init(&rx_priv->mclk_lock);
  3267. mutex_init(&rx_priv->swr_clk_lock);
  3268. rx_macro_init_ops(&ops, rx_io_base);
  3269. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  3270. if (ret) {
  3271. dev_err(&pdev->dev,
  3272. "%s: register macro failed\n", __func__);
  3273. goto err_reg_macro;
  3274. }
  3275. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  3276. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  3277. pm_runtime_use_autosuspend(&pdev->dev);
  3278. pm_runtime_set_suspended(&pdev->dev);
  3279. pm_runtime_enable(&pdev->dev);
  3280. return 0;
  3281. err_reg_macro:
  3282. mutex_destroy(&rx_priv->mclk_lock);
  3283. mutex_destroy(&rx_priv->swr_clk_lock);
  3284. return ret;
  3285. }
  3286. static int rx_macro_remove(struct platform_device *pdev)
  3287. {
  3288. struct rx_macro_priv *rx_priv = NULL;
  3289. u16 count = 0;
  3290. rx_priv = dev_get_drvdata(&pdev->dev);
  3291. if (!rx_priv)
  3292. return -EINVAL;
  3293. for (count = 0; count < rx_priv->child_count &&
  3294. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  3295. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  3296. pm_runtime_disable(&pdev->dev);
  3297. pm_runtime_set_suspended(&pdev->dev);
  3298. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  3299. mutex_destroy(&rx_priv->mclk_lock);
  3300. mutex_destroy(&rx_priv->swr_clk_lock);
  3301. kfree(rx_priv->swr_ctrl_data);
  3302. return 0;
  3303. }
  3304. static const struct of_device_id rx_macro_dt_match[] = {
  3305. {.compatible = "qcom,rx-macro"},
  3306. {}
  3307. };
  3308. static const struct dev_pm_ops bolero_dev_pm_ops = {
  3309. SET_RUNTIME_PM_OPS(
  3310. bolero_runtime_suspend,
  3311. bolero_runtime_resume,
  3312. NULL
  3313. )
  3314. };
  3315. static struct platform_driver rx_macro_driver = {
  3316. .driver = {
  3317. .name = "rx_macro",
  3318. .owner = THIS_MODULE,
  3319. .pm = &bolero_dev_pm_ops,
  3320. .of_match_table = rx_macro_dt_match,
  3321. .suppress_bind_attrs = true,
  3322. },
  3323. .probe = rx_macro_probe,
  3324. .remove = rx_macro_remove,
  3325. };
  3326. module_platform_driver(rx_macro_driver);
  3327. MODULE_DESCRIPTION("RX macro driver");
  3328. MODULE_LICENSE("GPL v2");