rx-macro.c 113 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776
  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_RX_COMPANDER_SOFT_RST:
  1081. rx_idx = data >> 0x10;
  1082. if (rx_idx == INTERP_AUX)
  1083. goto done;
  1084. reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1085. (rx_idx * RX_MACRO_COMP_OFFSET);
  1086. snd_soc_component_update_bits(component, reg,
  1087. 0x20, 0x20);
  1088. snd_soc_component_update_bits(component, reg,
  1089. 0x20, 0x00);
  1090. break;
  1091. case BOLERO_MACRO_EVT_IMPED_TRUE:
  1092. rx_macro_wcd_clsh_imped_config(component, data, true);
  1093. break;
  1094. case BOLERO_MACRO_EVT_IMPED_FALSE:
  1095. rx_macro_wcd_clsh_imped_config(component, data, false);
  1096. break;
  1097. case BOLERO_MACRO_EVT_SSR_DOWN:
  1098. rx_priv->dev_up = false;
  1099. if (rx_priv->swr_ctrl_data) {
  1100. swrm_wcd_notify(
  1101. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1102. SWR_DEVICE_DOWN, NULL);
  1103. swrm_wcd_notify(
  1104. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1105. SWR_DEVICE_SSR_DOWN, NULL);
  1106. }
  1107. if ((!pm_runtime_enabled(rx_dev) ||
  1108. !pm_runtime_suspended(rx_dev))) {
  1109. ret = bolero_runtime_suspend(rx_dev);
  1110. if (!ret) {
  1111. pm_runtime_disable(rx_dev);
  1112. pm_runtime_set_suspended(rx_dev);
  1113. pm_runtime_enable(rx_dev);
  1114. }
  1115. }
  1116. break;
  1117. case BOLERO_MACRO_EVT_SSR_UP:
  1118. rx_priv->dev_up = true;
  1119. /* reset swr after ssr/pdr */
  1120. rx_priv->reset_swr = true;
  1121. /* enable&disable RX_CORE_CLK to reset GFMUX reg */
  1122. ret = bolero_clk_rsc_request_clock(rx_priv->dev,
  1123. rx_priv->default_clk_id,
  1124. RX_CORE_CLK, true);
  1125. if (ret < 0)
  1126. dev_err_ratelimited(rx_priv->dev,
  1127. "%s, failed to enable clk, ret:%d\n",
  1128. __func__, ret);
  1129. else
  1130. bolero_clk_rsc_request_clock(rx_priv->dev,
  1131. rx_priv->default_clk_id,
  1132. RX_CORE_CLK, false);
  1133. if (rx_priv->swr_ctrl_data)
  1134. swrm_wcd_notify(
  1135. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1136. SWR_DEVICE_SSR_UP, NULL);
  1137. break;
  1138. case BOLERO_MACRO_EVT_CLK_RESET:
  1139. bolero_rsc_clk_reset(rx_dev, RX_CORE_CLK);
  1140. break;
  1141. }
  1142. done:
  1143. return ret;
  1144. }
  1145. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  1146. struct rx_macro_priv *rx_priv)
  1147. {
  1148. int i = 0;
  1149. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  1150. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  1151. return i;
  1152. }
  1153. return -EINVAL;
  1154. }
  1155. static int rx_macro_set_idle_detect_thr(struct snd_soc_component *component,
  1156. struct rx_macro_priv *rx_priv,
  1157. int interp, int path_type)
  1158. {
  1159. int port_id[4] = { 0, 0, 0, 0 };
  1160. int *port_ptr = NULL;
  1161. int num_ports = 0;
  1162. int bit_width = 0, i = 0;
  1163. int mux_reg = 0, mux_reg_val = 0;
  1164. int dai_id = 0, idle_thr = 0;
  1165. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  1166. return 0;
  1167. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1168. return 0;
  1169. port_ptr = &port_id[0];
  1170. num_ports = 0;
  1171. /*
  1172. * Read interpolator MUX input registers and find
  1173. * which cdc_dma port is connected and store the port
  1174. * numbers in port_id array.
  1175. */
  1176. if (path_type == INTERP_MIX_PATH) {
  1177. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  1178. 2 * interp;
  1179. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1180. 0x0f;
  1181. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  1182. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  1183. *port_ptr++ = mux_reg_val - 1;
  1184. num_ports++;
  1185. }
  1186. }
  1187. if (path_type == INTERP_MAIN_PATH) {
  1188. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  1189. 2 * (interp - 1);
  1190. mux_reg_val = snd_soc_component_read32(component, mux_reg) &
  1191. 0x0f;
  1192. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  1193. while (i) {
  1194. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  1195. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  1196. *port_ptr++ = mux_reg_val -
  1197. INTn_1_INP_SEL_RX0;
  1198. num_ports++;
  1199. }
  1200. mux_reg_val =
  1201. (snd_soc_component_read32(component, mux_reg) &
  1202. 0xf0) >> 4;
  1203. mux_reg += 1;
  1204. i--;
  1205. }
  1206. }
  1207. dev_dbg(component->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  1208. __func__, num_ports, port_id[0], port_id[1],
  1209. port_id[2], port_id[3]);
  1210. i = 0;
  1211. while (num_ports) {
  1212. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  1213. rx_priv);
  1214. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  1215. dev_dbg(component->dev, "%s: dai_id: %d bit_width: %d\n",
  1216. __func__, dai_id,
  1217. rx_priv->bit_width[dai_id]);
  1218. if (rx_priv->bit_width[dai_id] > bit_width)
  1219. bit_width = rx_priv->bit_width[dai_id];
  1220. }
  1221. num_ports--;
  1222. }
  1223. switch (bit_width) {
  1224. case 16:
  1225. idle_thr = 0xff; /* F16 */
  1226. break;
  1227. case 24:
  1228. case 32:
  1229. idle_thr = 0x03; /* F22 */
  1230. break;
  1231. default:
  1232. idle_thr = 0x00;
  1233. break;
  1234. }
  1235. dev_dbg(component->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  1236. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  1237. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  1238. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  1239. snd_soc_component_write(component,
  1240. BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  1241. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  1242. }
  1243. return 0;
  1244. }
  1245. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1246. struct snd_kcontrol *kcontrol, int event)
  1247. {
  1248. struct snd_soc_component *component =
  1249. snd_soc_dapm_to_component(w->dapm);
  1250. u16 gain_reg = 0, mix_reg = 0;
  1251. struct device *rx_dev = NULL;
  1252. struct rx_macro_priv *rx_priv = NULL;
  1253. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1254. return -EINVAL;
  1255. if (w->shift >= INTERP_MAX) {
  1256. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1257. __func__, w->shift, w->name);
  1258. return -EINVAL;
  1259. }
  1260. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  1261. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1262. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  1263. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1264. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1265. switch (event) {
  1266. case SND_SOC_DAPM_PRE_PMU:
  1267. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1268. INTERP_MIX_PATH);
  1269. rx_macro_enable_interp_clk(component, event, w->shift);
  1270. /* Clk enable */
  1271. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x20);
  1272. break;
  1273. case SND_SOC_DAPM_POST_PMU:
  1274. snd_soc_component_write(component, gain_reg,
  1275. snd_soc_component_read32(component, gain_reg));
  1276. break;
  1277. case SND_SOC_DAPM_POST_PMD:
  1278. /* Clk Disable */
  1279. snd_soc_component_update_bits(component, mix_reg, 0x20, 0x00);
  1280. rx_macro_enable_interp_clk(component, event, w->shift);
  1281. /* Reset enable and disable */
  1282. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x40);
  1283. snd_soc_component_update_bits(component, mix_reg, 0x40, 0x00);
  1284. break;
  1285. }
  1286. return 0;
  1287. }
  1288. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1289. struct snd_kcontrol *kcontrol,
  1290. int event)
  1291. {
  1292. struct snd_soc_component *component =
  1293. snd_soc_dapm_to_component(w->dapm);
  1294. u16 gain_reg = 0;
  1295. u16 reg = 0;
  1296. struct device *rx_dev = NULL;
  1297. struct rx_macro_priv *rx_priv = NULL;
  1298. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1299. return -EINVAL;
  1300. dev_dbg(component->dev, "%s %d %s\n", __func__, event, w->name);
  1301. if (w->shift >= INTERP_MAX) {
  1302. dev_err(component->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1303. __func__, w->shift, w->name);
  1304. return -EINVAL;
  1305. }
  1306. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  1307. RX_MACRO_RX_PATH_OFFSET);
  1308. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  1309. RX_MACRO_RX_PATH_OFFSET);
  1310. switch (event) {
  1311. case SND_SOC_DAPM_PRE_PMU:
  1312. rx_macro_set_idle_detect_thr(component, rx_priv, w->shift,
  1313. INTERP_MAIN_PATH);
  1314. rx_macro_enable_interp_clk(component, event, w->shift);
  1315. break;
  1316. case SND_SOC_DAPM_POST_PMU:
  1317. snd_soc_component_write(component, gain_reg,
  1318. snd_soc_component_read32(component, gain_reg));
  1319. break;
  1320. case SND_SOC_DAPM_POST_PMD:
  1321. rx_macro_enable_interp_clk(component, event, w->shift);
  1322. break;
  1323. }
  1324. return 0;
  1325. }
  1326. static int rx_macro_config_compander(struct snd_soc_component *component,
  1327. struct rx_macro_priv *rx_priv,
  1328. int interp_n, int event)
  1329. {
  1330. int comp = 0;
  1331. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  1332. /* AUX does not have compander */
  1333. if (interp_n == INTERP_AUX)
  1334. return 0;
  1335. comp = interp_n;
  1336. dev_dbg(component->dev, "%s: event %d compander %d, enabled %d\n",
  1337. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  1338. if (!rx_priv->comp_enabled[comp])
  1339. return 0;
  1340. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1341. (comp * RX_MACRO_COMP_OFFSET);
  1342. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  1343. (comp * RX_MACRO_RX_PATH_OFFSET);
  1344. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1345. /* Enable Compander Clock */
  1346. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1347. 0x01, 0x01);
  1348. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1349. 0x02, 0x02);
  1350. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1351. 0x02, 0x00);
  1352. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1353. 0x02, 0x02);
  1354. }
  1355. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1356. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1357. 0x04, 0x04);
  1358. snd_soc_component_update_bits(component, rx_path_cfg0_reg,
  1359. 0x02, 0x00);
  1360. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1361. 0x01, 0x00);
  1362. snd_soc_component_update_bits(component, comp_ctl0_reg,
  1363. 0x04, 0x00);
  1364. }
  1365. return 0;
  1366. }
  1367. static void rx_macro_enable_softclip_clk(struct snd_soc_component *component,
  1368. struct rx_macro_priv *rx_priv,
  1369. bool enable)
  1370. {
  1371. if (enable) {
  1372. if (rx_priv->softclip_clk_users == 0)
  1373. snd_soc_component_update_bits(component,
  1374. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1375. 0x01, 0x01);
  1376. rx_priv->softclip_clk_users++;
  1377. } else {
  1378. rx_priv->softclip_clk_users--;
  1379. if (rx_priv->softclip_clk_users == 0)
  1380. snd_soc_component_update_bits(component,
  1381. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1382. 0x01, 0x00);
  1383. }
  1384. }
  1385. static int rx_macro_config_softclip(struct snd_soc_component *component,
  1386. struct rx_macro_priv *rx_priv,
  1387. int event)
  1388. {
  1389. dev_dbg(component->dev, "%s: event %d, enabled %d\n",
  1390. __func__, event, rx_priv->is_softclip_on);
  1391. if (!rx_priv->is_softclip_on)
  1392. return 0;
  1393. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1394. /* Enable Softclip clock */
  1395. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1396. /* Enable Softclip control */
  1397. snd_soc_component_update_bits(component,
  1398. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x01);
  1399. }
  1400. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1401. snd_soc_component_update_bits(component,
  1402. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x00);
  1403. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1404. }
  1405. return 0;
  1406. }
  1407. static inline void
  1408. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  1409. {
  1410. if ((enable && ++rx_priv->clsh_users == 1) ||
  1411. (!enable && --rx_priv->clsh_users == 0))
  1412. snd_soc_component_update_bits(rx_priv->component,
  1413. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  1414. (u8) enable);
  1415. if (rx_priv->clsh_users < 0)
  1416. rx_priv->clsh_users = 0;
  1417. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1418. rx_priv->clsh_users, enable);
  1419. }
  1420. static int rx_macro_config_classh(struct snd_soc_component *component,
  1421. struct rx_macro_priv *rx_priv,
  1422. int interp_n, int event)
  1423. {
  1424. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1425. rx_macro_enable_clsh_block(rx_priv, false);
  1426. return 0;
  1427. }
  1428. if (!SND_SOC_DAPM_EVENT_ON(event))
  1429. return 0;
  1430. rx_macro_enable_clsh_block(rx_priv, true);
  1431. if (interp_n == INTERP_HPHL ||
  1432. interp_n == INTERP_HPHR) {
  1433. /*
  1434. * These K1 values depend on the Headphone Impedance
  1435. * For now it is assumed to be 16 ohm
  1436. */
  1437. snd_soc_component_update_bits(component,
  1438. BOLERO_CDC_RX_CLSH_K1_LSB,
  1439. 0xFF, 0xC0);
  1440. snd_soc_component_update_bits(component,
  1441. BOLERO_CDC_RX_CLSH_K1_MSB,
  1442. 0x0F, 0x00);
  1443. }
  1444. switch (interp_n) {
  1445. case INTERP_HPHL:
  1446. if (rx_priv->is_ear_mode_on)
  1447. snd_soc_component_update_bits(component,
  1448. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1449. 0x3F, 0x39);
  1450. else
  1451. snd_soc_component_update_bits(component,
  1452. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1453. 0x3F, 0x1C);
  1454. snd_soc_component_update_bits(component,
  1455. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1456. 0x07, 0x00);
  1457. snd_soc_component_update_bits(component,
  1458. BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1459. 0x40, 0x40);
  1460. break;
  1461. case INTERP_HPHR:
  1462. snd_soc_component_update_bits(component,
  1463. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1464. 0x3F, 0x1C);
  1465. snd_soc_component_update_bits(component,
  1466. BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1467. 0x07, 0x00);
  1468. snd_soc_component_update_bits(component,
  1469. BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1470. 0x40, 0x40);
  1471. break;
  1472. case INTERP_AUX:
  1473. snd_soc_component_update_bits(component,
  1474. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1475. 0x08, 0x08);
  1476. snd_soc_component_update_bits(component,
  1477. BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1478. 0x10, 0x10);
  1479. break;
  1480. }
  1481. return 0;
  1482. }
  1483. static void rx_macro_hd2_control(struct snd_soc_component *component,
  1484. u16 interp_idx, int event)
  1485. {
  1486. u16 hd2_scale_reg = 0;
  1487. u16 hd2_enable_reg = 0;
  1488. switch (interp_idx) {
  1489. case INTERP_HPHL:
  1490. hd2_scale_reg = BOLERO_CDC_RX_RX0_RX_PATH_SEC3;
  1491. hd2_enable_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  1492. break;
  1493. case INTERP_HPHR:
  1494. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1495. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1496. break;
  1497. }
  1498. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1499. snd_soc_component_update_bits(component, hd2_scale_reg,
  1500. 0x3C, 0x14);
  1501. snd_soc_component_update_bits(component, hd2_enable_reg,
  1502. 0x04, 0x04);
  1503. }
  1504. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1505. snd_soc_component_update_bits(component, hd2_enable_reg,
  1506. 0x04, 0x00);
  1507. snd_soc_component_update_bits(component, hd2_scale_reg,
  1508. 0x3C, 0x00);
  1509. }
  1510. }
  1511. static int rx_macro_hph_idle_detect_get(struct snd_kcontrol *kcontrol,
  1512. struct snd_ctl_elem_value *ucontrol)
  1513. {
  1514. struct snd_soc_component *component =
  1515. snd_soc_kcontrol_component(kcontrol);
  1516. struct rx_macro_priv *rx_priv = NULL;
  1517. struct device *rx_dev = NULL;
  1518. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1519. return -EINVAL;
  1520. ucontrol->value.integer.value[0] =
  1521. rx_priv->idle_det_cfg.hph_idle_detect_en;
  1522. return 0;
  1523. }
  1524. static int rx_macro_hph_idle_detect_put(struct snd_kcontrol *kcontrol,
  1525. struct snd_ctl_elem_value *ucontrol)
  1526. {
  1527. struct snd_soc_component *component =
  1528. snd_soc_kcontrol_component(kcontrol);
  1529. struct rx_macro_priv *rx_priv = NULL;
  1530. struct device *rx_dev = NULL;
  1531. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1532. return -EINVAL;
  1533. rx_priv->idle_det_cfg.hph_idle_detect_en =
  1534. ucontrol->value.integer.value[0];
  1535. return 0;
  1536. }
  1537. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1538. struct snd_ctl_elem_value *ucontrol)
  1539. {
  1540. struct snd_soc_component *component =
  1541. snd_soc_kcontrol_component(kcontrol);
  1542. int comp = ((struct soc_multi_mixer_control *)
  1543. kcontrol->private_value)->shift;
  1544. struct device *rx_dev = NULL;
  1545. struct rx_macro_priv *rx_priv = NULL;
  1546. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1547. return -EINVAL;
  1548. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1549. return 0;
  1550. }
  1551. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1552. struct snd_ctl_elem_value *ucontrol)
  1553. {
  1554. struct snd_soc_component *component =
  1555. snd_soc_kcontrol_component(kcontrol);
  1556. int comp = ((struct soc_multi_mixer_control *)
  1557. kcontrol->private_value)->shift;
  1558. int value = ucontrol->value.integer.value[0];
  1559. struct device *rx_dev = NULL;
  1560. struct rx_macro_priv *rx_priv = NULL;
  1561. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1562. return -EINVAL;
  1563. dev_dbg(component->dev, "%s: Compander %d enable current %d, new %d\n",
  1564. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1565. rx_priv->comp_enabled[comp] = value;
  1566. return 0;
  1567. }
  1568. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1569. struct snd_ctl_elem_value *ucontrol)
  1570. {
  1571. struct snd_soc_dapm_widget *widget =
  1572. snd_soc_dapm_kcontrol_widget(kcontrol);
  1573. struct snd_soc_component *component =
  1574. snd_soc_dapm_to_component(widget->dapm);
  1575. struct device *rx_dev = NULL;
  1576. struct rx_macro_priv *rx_priv = NULL;
  1577. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1578. return -EINVAL;
  1579. ucontrol->value.integer.value[0] =
  1580. rx_priv->rx_port_value[widget->shift];
  1581. return 0;
  1582. }
  1583. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1584. struct snd_ctl_elem_value *ucontrol)
  1585. {
  1586. struct snd_soc_dapm_widget *widget =
  1587. snd_soc_dapm_kcontrol_widget(kcontrol);
  1588. struct snd_soc_component *component =
  1589. snd_soc_dapm_to_component(widget->dapm);
  1590. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1591. struct snd_soc_dapm_update *update = NULL;
  1592. u32 rx_port_value = ucontrol->value.integer.value[0];
  1593. u32 aif_rst = 0;
  1594. struct device *rx_dev = NULL;
  1595. struct rx_macro_priv *rx_priv = NULL;
  1596. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1597. return -EINVAL;
  1598. aif_rst = rx_priv->rx_port_value[widget->shift];
  1599. if (!rx_port_value) {
  1600. if (aif_rst == 0) {
  1601. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1602. return 0;
  1603. }
  1604. }
  1605. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1606. switch (rx_port_value) {
  1607. case 0:
  1608. clear_bit(widget->shift,
  1609. &rx_priv->active_ch_mask[aif_rst]);
  1610. rx_priv->active_ch_cnt[aif_rst]--;
  1611. break;
  1612. case 1:
  1613. case 2:
  1614. case 3:
  1615. case 4:
  1616. set_bit(widget->shift,
  1617. &rx_priv->active_ch_mask[rx_port_value]);
  1618. rx_priv->active_ch_cnt[rx_port_value]++;
  1619. break;
  1620. default:
  1621. dev_err(component->dev,
  1622. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1623. goto err;
  1624. }
  1625. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1626. rx_port_value, e, update);
  1627. return 0;
  1628. err:
  1629. return -EINVAL;
  1630. }
  1631. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1632. struct snd_ctl_elem_value *ucontrol)
  1633. {
  1634. struct snd_soc_component *component =
  1635. snd_soc_kcontrol_component(kcontrol);
  1636. struct device *rx_dev = NULL;
  1637. struct rx_macro_priv *rx_priv = NULL;
  1638. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1639. return -EINVAL;
  1640. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1641. return 0;
  1642. }
  1643. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1644. struct snd_ctl_elem_value *ucontrol)
  1645. {
  1646. struct snd_soc_component *component =
  1647. snd_soc_kcontrol_component(kcontrol);
  1648. struct device *rx_dev = NULL;
  1649. struct rx_macro_priv *rx_priv = NULL;
  1650. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1651. return -EINVAL;
  1652. rx_priv->is_ear_mode_on =
  1653. (!ucontrol->value.integer.value[0] ? false : true);
  1654. return 0;
  1655. }
  1656. static int rx_macro_get_hph_hd2_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_hd2_mode;
  1666. return 0;
  1667. }
  1668. static int rx_macro_put_hph_hd2_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_hd2_mode = ucontrol->value.integer.value[0];
  1678. return 0;
  1679. }
  1680. static int rx_macro_get_hph_pwr_mode(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. struct device *rx_dev = NULL;
  1686. struct rx_macro_priv *rx_priv = NULL;
  1687. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1688. return -EINVAL;
  1689. ucontrol->value.integer.value[0] = rx_priv->hph_pwr_mode;
  1690. return 0;
  1691. }
  1692. static int rx_macro_put_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1693. struct snd_ctl_elem_value *ucontrol)
  1694. {
  1695. struct snd_soc_component *component =
  1696. snd_soc_kcontrol_component(kcontrol);
  1697. struct device *rx_dev = NULL;
  1698. struct rx_macro_priv *rx_priv = NULL;
  1699. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1700. return -EINVAL;
  1701. rx_priv->hph_pwr_mode = ucontrol->value.integer.value[0];
  1702. return 0;
  1703. }
  1704. static int rx_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1705. struct snd_ctl_elem_value *ucontrol)
  1706. {
  1707. struct snd_soc_component *component =
  1708. snd_soc_kcontrol_component(kcontrol);
  1709. ucontrol->value.integer.value[0] =
  1710. ((snd_soc_component_read32(
  1711. component, BOLERO_CDC_RX_BCL_VBAT_CFG) & 0x04) ?
  1712. 1 : 0);
  1713. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1714. ucontrol->value.integer.value[0]);
  1715. return 0;
  1716. }
  1717. static int rx_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1718. struct snd_ctl_elem_value *ucontrol)
  1719. {
  1720. struct snd_soc_component *component =
  1721. snd_soc_kcontrol_component(kcontrol);
  1722. dev_dbg(component->dev, "%s: value: %lu\n", __func__,
  1723. ucontrol->value.integer.value[0]);
  1724. /* Set Vbat register configuration for GSM mode bit based on value */
  1725. if (ucontrol->value.integer.value[0])
  1726. snd_soc_component_update_bits(component,
  1727. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1728. 0x04, 0x04);
  1729. else
  1730. snd_soc_component_update_bits(component,
  1731. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1732. 0x04, 0x00);
  1733. return 0;
  1734. }
  1735. static int rx_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1736. struct snd_ctl_elem_value *ucontrol)
  1737. {
  1738. struct snd_soc_component *component =
  1739. snd_soc_kcontrol_component(kcontrol);
  1740. struct device *rx_dev = NULL;
  1741. struct rx_macro_priv *rx_priv = NULL;
  1742. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1743. return -EINVAL;
  1744. ucontrol->value.integer.value[0] = rx_priv->is_softclip_on;
  1745. dev_dbg(component->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1746. __func__, ucontrol->value.integer.value[0]);
  1747. return 0;
  1748. }
  1749. static int rx_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1750. struct snd_ctl_elem_value *ucontrol)
  1751. {
  1752. struct snd_soc_component *component =
  1753. snd_soc_kcontrol_component(kcontrol);
  1754. struct device *rx_dev = NULL;
  1755. struct rx_macro_priv *rx_priv = NULL;
  1756. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1757. return -EINVAL;
  1758. rx_priv->is_softclip_on = ucontrol->value.integer.value[0];
  1759. dev_dbg(component->dev, "%s: soft clip enable = %d\n", __func__,
  1760. rx_priv->is_softclip_on);
  1761. return 0;
  1762. }
  1763. static int rx_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1764. struct snd_kcontrol *kcontrol,
  1765. int event)
  1766. {
  1767. struct snd_soc_component *component =
  1768. snd_soc_dapm_to_component(w->dapm);
  1769. struct device *rx_dev = NULL;
  1770. struct rx_macro_priv *rx_priv = NULL;
  1771. dev_dbg(component->dev, "%s %s %d\n", __func__, w->name, event);
  1772. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1773. return -EINVAL;
  1774. switch (event) {
  1775. case SND_SOC_DAPM_PRE_PMU:
  1776. /* Enable clock for VBAT block */
  1777. snd_soc_component_update_bits(component,
  1778. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1779. /* Enable VBAT block */
  1780. snd_soc_component_update_bits(component,
  1781. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x01);
  1782. /* Update interpolator with 384K path */
  1783. snd_soc_component_update_bits(component,
  1784. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x80, 0x80);
  1785. /* Update DSM FS rate */
  1786. snd_soc_component_update_bits(component,
  1787. BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x02, 0x02);
  1788. /* Use attenuation mode */
  1789. snd_soc_component_update_bits(component,
  1790. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x02, 0x00);
  1791. /* BCL block needs softclip clock to be enabled */
  1792. rx_macro_enable_softclip_clk(component, rx_priv, true);
  1793. /* Enable VBAT at channel level */
  1794. snd_soc_component_update_bits(component,
  1795. BOLERO_CDC_RX_RX2_RX_PATH_CFG1, 0x02, 0x02);
  1796. /* Set the ATTK1 gain */
  1797. snd_soc_component_update_bits(component,
  1798. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1799. 0xFF, 0xFF);
  1800. snd_soc_component_update_bits(component,
  1801. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1802. 0xFF, 0x03);
  1803. snd_soc_component_update_bits(component,
  1804. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1805. 0xFF, 0x00);
  1806. /* Set the ATTK2 gain */
  1807. snd_soc_component_update_bits(component,
  1808. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1809. 0xFF, 0xFF);
  1810. snd_soc_component_update_bits(component,
  1811. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1812. 0xFF, 0x03);
  1813. snd_soc_component_update_bits(component,
  1814. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1815. 0xFF, 0x00);
  1816. /* Set the ATTK3 gain */
  1817. snd_soc_component_update_bits(component,
  1818. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1819. 0xFF, 0xFF);
  1820. snd_soc_component_update_bits(component,
  1821. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1822. 0xFF, 0x03);
  1823. snd_soc_component_update_bits(component,
  1824. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1825. 0xFF, 0x00);
  1826. break;
  1827. case SND_SOC_DAPM_POST_PMD:
  1828. snd_soc_component_update_bits(component,
  1829. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1830. 0x80, 0x00);
  1831. snd_soc_component_update_bits(component,
  1832. BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1833. 0x02, 0x00);
  1834. snd_soc_component_update_bits(component,
  1835. BOLERO_CDC_RX_BCL_VBAT_CFG,
  1836. 0x02, 0x02);
  1837. snd_soc_component_update_bits(component,
  1838. BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1839. 0x02, 0x00);
  1840. snd_soc_component_update_bits(component,
  1841. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1842. 0xFF, 0x00);
  1843. snd_soc_component_update_bits(component,
  1844. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1845. 0xFF, 0x00);
  1846. snd_soc_component_update_bits(component,
  1847. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1848. 0xFF, 0x00);
  1849. snd_soc_component_update_bits(component,
  1850. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1851. 0xFF, 0x00);
  1852. snd_soc_component_update_bits(component,
  1853. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1854. 0xFF, 0x00);
  1855. snd_soc_component_update_bits(component,
  1856. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1857. 0xFF, 0x00);
  1858. snd_soc_component_update_bits(component,
  1859. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1860. 0xFF, 0x00);
  1861. snd_soc_component_update_bits(component,
  1862. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1863. 0xFF, 0x00);
  1864. snd_soc_component_update_bits(component,
  1865. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1866. 0xFF, 0x00);
  1867. rx_macro_enable_softclip_clk(component, rx_priv, false);
  1868. snd_soc_component_update_bits(component,
  1869. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x00);
  1870. snd_soc_component_update_bits(component,
  1871. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1872. break;
  1873. default:
  1874. dev_err(rx_dev, "%s: Invalid event %d\n", __func__, event);
  1875. break;
  1876. }
  1877. return 0;
  1878. }
  1879. static void rx_macro_idle_detect_control(struct snd_soc_component *component,
  1880. struct rx_macro_priv *rx_priv,
  1881. int interp, int event)
  1882. {
  1883. int reg = 0, mask = 0, val = 0;
  1884. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1885. return;
  1886. if (interp == INTERP_HPHL) {
  1887. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1888. mask = 0x01;
  1889. val = 0x01;
  1890. }
  1891. if (interp == INTERP_HPHR) {
  1892. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1893. mask = 0x02;
  1894. val = 0x02;
  1895. }
  1896. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1897. snd_soc_component_update_bits(component, reg, mask, val);
  1898. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1899. snd_soc_component_update_bits(component, reg, mask, 0x00);
  1900. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1901. snd_soc_component_write(component,
  1902. BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1903. }
  1904. }
  1905. static void rx_macro_hphdelay_lutbypass(struct snd_soc_component *component,
  1906. struct rx_macro_priv *rx_priv,
  1907. u16 interp_idx, int event)
  1908. {
  1909. u16 hph_lut_bypass_reg = 0;
  1910. u16 hph_comp_ctrl7 = 0;
  1911. switch (interp_idx) {
  1912. case INTERP_HPHL:
  1913. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1914. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1915. break;
  1916. case INTERP_HPHR:
  1917. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1918. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1919. break;
  1920. default:
  1921. break;
  1922. }
  1923. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1924. if (interp_idx == INTERP_HPHL) {
  1925. if (rx_priv->is_ear_mode_on)
  1926. snd_soc_component_update_bits(component,
  1927. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1928. 0x02, 0x02);
  1929. else
  1930. snd_soc_component_update_bits(component,
  1931. hph_lut_bypass_reg,
  1932. 0x80, 0x80);
  1933. } else {
  1934. snd_soc_component_update_bits(component,
  1935. hph_lut_bypass_reg,
  1936. 0x80, 0x80);
  1937. }
  1938. if (rx_priv->hph_pwr_mode)
  1939. snd_soc_component_update_bits(component,
  1940. hph_comp_ctrl7,
  1941. 0x20, 0x00);
  1942. }
  1943. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1944. snd_soc_component_update_bits(component,
  1945. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1946. 0x02, 0x00);
  1947. snd_soc_component_update_bits(component, hph_lut_bypass_reg,
  1948. 0x80, 0x00);
  1949. snd_soc_component_update_bits(component, hph_comp_ctrl7,
  1950. 0x20, 0x20);
  1951. }
  1952. }
  1953. static int rx_macro_enable_interp_clk(struct snd_soc_component *component,
  1954. int event, int interp_idx)
  1955. {
  1956. u16 main_reg = 0, dsm_reg = 0, rx_cfg2_reg = 0;
  1957. struct device *rx_dev = NULL;
  1958. struct rx_macro_priv *rx_priv = NULL;
  1959. if (!component) {
  1960. pr_err("%s: component is NULL\n", __func__);
  1961. return -EINVAL;
  1962. }
  1963. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  1964. return -EINVAL;
  1965. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1966. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1967. dsm_reg = BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL +
  1968. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1969. if (interp_idx == INTERP_AUX)
  1970. dsm_reg = BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL;
  1971. rx_cfg2_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG2 +
  1972. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1973. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1974. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1975. /* Main path PGA mute enable */
  1976. snd_soc_component_update_bits(component, main_reg,
  1977. 0x10, 0x10);
  1978. snd_soc_component_update_bits(component, dsm_reg,
  1979. 0x01, 0x01);
  1980. /* Clk enable */
  1981. snd_soc_component_update_bits(component, main_reg,
  1982. 0x20, 0x20);
  1983. snd_soc_component_update_bits(component, rx_cfg2_reg,
  1984. 0x03, 0x03);
  1985. rx_macro_idle_detect_control(component, rx_priv,
  1986. interp_idx, event);
  1987. if (rx_priv->hph_hd2_mode)
  1988. rx_macro_hd2_control(
  1989. component, interp_idx, event);
  1990. rx_macro_hphdelay_lutbypass(component, rx_priv,
  1991. interp_idx, event);
  1992. rx_macro_config_compander(component, rx_priv,
  1993. interp_idx, event);
  1994. if (interp_idx == INTERP_AUX)
  1995. rx_macro_config_softclip(component, rx_priv,
  1996. event);
  1997. rx_macro_config_classh(component, rx_priv,
  1998. interp_idx, event);
  1999. }
  2000. rx_priv->main_clk_users[interp_idx]++;
  2001. }
  2002. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  2003. rx_priv->main_clk_users[interp_idx]--;
  2004. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  2005. rx_priv->main_clk_users[interp_idx] = 0;
  2006. /* Main path PGA mute enable */
  2007. snd_soc_component_update_bits(component, main_reg,
  2008. 0x10, 0x10);
  2009. /* Clk Disable */
  2010. snd_soc_component_update_bits(component, dsm_reg,
  2011. 0x01, 0x00);
  2012. snd_soc_component_update_bits(component, main_reg,
  2013. 0x20, 0x00);
  2014. /* Reset enable and disable */
  2015. snd_soc_component_update_bits(component, main_reg,
  2016. 0x40, 0x40);
  2017. snd_soc_component_update_bits(component, main_reg,
  2018. 0x40, 0x00);
  2019. /* Reset rate to 48K*/
  2020. snd_soc_component_update_bits(component, main_reg,
  2021. 0x0F, 0x04);
  2022. snd_soc_component_update_bits(component, rx_cfg2_reg,
  2023. 0x03, 0x00);
  2024. rx_macro_config_classh(component, rx_priv,
  2025. interp_idx, event);
  2026. rx_macro_config_compander(component, rx_priv,
  2027. interp_idx, event);
  2028. if (interp_idx == INTERP_AUX)
  2029. rx_macro_config_softclip(component, rx_priv,
  2030. event);
  2031. rx_macro_hphdelay_lutbypass(component, rx_priv,
  2032. interp_idx, event);
  2033. if (rx_priv->hph_hd2_mode)
  2034. rx_macro_hd2_control(component, interp_idx,
  2035. event);
  2036. rx_macro_idle_detect_control(component, rx_priv,
  2037. interp_idx, event);
  2038. }
  2039. }
  2040. dev_dbg(component->dev, "%s event %d main_clk_users %d\n",
  2041. __func__, event, rx_priv->main_clk_users[interp_idx]);
  2042. return rx_priv->main_clk_users[interp_idx];
  2043. }
  2044. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  2045. struct snd_kcontrol *kcontrol, int event)
  2046. {
  2047. struct snd_soc_component *component =
  2048. snd_soc_dapm_to_component(w->dapm);
  2049. u16 sidetone_reg = 0;
  2050. dev_dbg(component->dev, "%s %d %d\n", __func__, event, w->shift);
  2051. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  2052. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  2053. switch (event) {
  2054. case SND_SOC_DAPM_PRE_PMU:
  2055. rx_macro_enable_interp_clk(component, event, w->shift);
  2056. snd_soc_component_update_bits(component, sidetone_reg,
  2057. 0x10, 0x10);
  2058. break;
  2059. case SND_SOC_DAPM_POST_PMD:
  2060. snd_soc_component_update_bits(component, sidetone_reg,
  2061. 0x10, 0x00);
  2062. rx_macro_enable_interp_clk(component, event, w->shift);
  2063. break;
  2064. default:
  2065. break;
  2066. };
  2067. return 0;
  2068. }
  2069. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  2070. int band_idx)
  2071. {
  2072. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  2073. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2074. if (regmap == NULL) {
  2075. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2076. return;
  2077. }
  2078. regmap_write(regmap,
  2079. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2080. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2081. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  2082. /* 5 coefficients per band and 4 writes per coefficient */
  2083. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2084. coeff_idx++) {
  2085. /* Four 8 bit values(one 32 bit) per coefficient */
  2086. regmap_write(regmap, reg_add,
  2087. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2088. regmap_write(regmap, reg_add,
  2089. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2090. regmap_write(regmap, reg_add,
  2091. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2092. regmap_write(regmap, reg_add,
  2093. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  2094. }
  2095. }
  2096. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2097. struct snd_ctl_elem_value *ucontrol)
  2098. {
  2099. struct snd_soc_component *component =
  2100. snd_soc_kcontrol_component(kcontrol);
  2101. int iir_idx = ((struct soc_multi_mixer_control *)
  2102. kcontrol->private_value)->reg;
  2103. int band_idx = ((struct soc_multi_mixer_control *)
  2104. kcontrol->private_value)->shift;
  2105. /* IIR filter band registers are at integer multiples of 0x80 */
  2106. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2107. ucontrol->value.integer.value[0] = (
  2108. 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,
  2112. (uint32_t)ucontrol->value.integer.value[0]);
  2113. return 0;
  2114. }
  2115. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2116. struct snd_ctl_elem_value *ucontrol)
  2117. {
  2118. struct snd_soc_component *component =
  2119. snd_soc_kcontrol_component(kcontrol);
  2120. int iir_idx = ((struct soc_multi_mixer_control *)
  2121. kcontrol->private_value)->reg;
  2122. int band_idx = ((struct soc_multi_mixer_control *)
  2123. kcontrol->private_value)->shift;
  2124. bool iir_band_en_status = 0;
  2125. int value = ucontrol->value.integer.value[0];
  2126. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  2127. struct device *rx_dev = NULL;
  2128. struct rx_macro_priv *rx_priv = NULL;
  2129. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2130. return -EINVAL;
  2131. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  2132. /* Mask first 5 bits, 6-8 are reserved */
  2133. snd_soc_component_update_bits(component, iir_reg, (1 << band_idx),
  2134. (value << band_idx));
  2135. iir_band_en_status = ((snd_soc_component_read32(component, iir_reg) &
  2136. (1 << band_idx)) != 0);
  2137. dev_dbg(component->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  2138. iir_idx, band_idx, iir_band_en_status);
  2139. return 0;
  2140. }
  2141. static uint32_t get_iir_band_coeff(struct snd_soc_component *component,
  2142. int iir_idx, int band_idx,
  2143. int coeff_idx)
  2144. {
  2145. uint32_t value = 0;
  2146. /* Address does not automatically update if reading */
  2147. snd_soc_component_write(component,
  2148. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2149. ((band_idx * BAND_MAX + coeff_idx)
  2150. * sizeof(uint32_t)) & 0x7F);
  2151. value |= snd_soc_component_read32(component,
  2152. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  2153. snd_soc_component_write(component,
  2154. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2155. ((band_idx * BAND_MAX + coeff_idx)
  2156. * sizeof(uint32_t) + 1) & 0x7F);
  2157. value |= (snd_soc_component_read32(component,
  2158. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2159. 0x80 * iir_idx)) << 8);
  2160. snd_soc_component_write(component,
  2161. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2162. ((band_idx * BAND_MAX + coeff_idx)
  2163. * sizeof(uint32_t) + 2) & 0x7F);
  2164. value |= (snd_soc_component_read32(component,
  2165. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2166. 0x80 * iir_idx)) << 16);
  2167. snd_soc_component_write(component,
  2168. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  2169. ((band_idx * BAND_MAX + coeff_idx)
  2170. * sizeof(uint32_t) + 3) & 0x7F);
  2171. /* Mask bits top 2 bits since they are reserved */
  2172. value |= ((snd_soc_component_read32(component,
  2173. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  2174. 16 * iir_idx)) & 0x3F) << 24);
  2175. return value;
  2176. }
  2177. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  2178. struct snd_ctl_elem_value *ucontrol)
  2179. {
  2180. struct snd_soc_component *component =
  2181. snd_soc_kcontrol_component(kcontrol);
  2182. int iir_idx = ((struct soc_multi_mixer_control *)
  2183. kcontrol->private_value)->reg;
  2184. int band_idx = ((struct soc_multi_mixer_control *)
  2185. kcontrol->private_value)->shift;
  2186. ucontrol->value.integer.value[0] =
  2187. get_iir_band_coeff(component, iir_idx, band_idx, 0);
  2188. ucontrol->value.integer.value[1] =
  2189. get_iir_band_coeff(component, iir_idx, band_idx, 1);
  2190. ucontrol->value.integer.value[2] =
  2191. get_iir_band_coeff(component, iir_idx, band_idx, 2);
  2192. ucontrol->value.integer.value[3] =
  2193. get_iir_band_coeff(component, iir_idx, band_idx, 3);
  2194. ucontrol->value.integer.value[4] =
  2195. get_iir_band_coeff(component, iir_idx, band_idx, 4);
  2196. dev_dbg(component->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  2197. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2198. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2199. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2200. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2201. __func__, iir_idx, band_idx,
  2202. (uint32_t)ucontrol->value.integer.value[0],
  2203. __func__, iir_idx, band_idx,
  2204. (uint32_t)ucontrol->value.integer.value[1],
  2205. __func__, iir_idx, band_idx,
  2206. (uint32_t)ucontrol->value.integer.value[2],
  2207. __func__, iir_idx, band_idx,
  2208. (uint32_t)ucontrol->value.integer.value[3],
  2209. __func__, iir_idx, band_idx,
  2210. (uint32_t)ucontrol->value.integer.value[4]);
  2211. return 0;
  2212. }
  2213. static void set_iir_band_coeff(struct snd_soc_component *component,
  2214. int iir_idx, int band_idx,
  2215. uint32_t value)
  2216. {
  2217. snd_soc_component_write(component,
  2218. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2219. (value & 0xFF));
  2220. snd_soc_component_write(component,
  2221. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2222. (value >> 8) & 0xFF);
  2223. snd_soc_component_write(component,
  2224. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2225. (value >> 16) & 0xFF);
  2226. /* Mask top 2 bits, 7-8 are reserved */
  2227. snd_soc_component_write(component,
  2228. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2229. (value >> 24) & 0x3F);
  2230. }
  2231. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2232. struct snd_ctl_elem_value *ucontrol)
  2233. {
  2234. struct snd_soc_component *component =
  2235. snd_soc_kcontrol_component(kcontrol);
  2236. int iir_idx = ((struct soc_multi_mixer_control *)
  2237. kcontrol->private_value)->reg;
  2238. int band_idx = ((struct soc_multi_mixer_control *)
  2239. kcontrol->private_value)->shift;
  2240. int coeff_idx, idx = 0;
  2241. struct device *rx_dev = NULL;
  2242. struct rx_macro_priv *rx_priv = NULL;
  2243. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2244. return -EINVAL;
  2245. /*
  2246. * Mask top bit it is reserved
  2247. * Updates addr automatically for each B2 write
  2248. */
  2249. snd_soc_component_write(component,
  2250. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  2251. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2252. /* Store the coefficients in sidetone coeff array */
  2253. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2254. coeff_idx++) {
  2255. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  2256. set_iir_band_coeff(component, iir_idx, band_idx, value);
  2257. /* Four 8 bit values(one 32 bit) per coefficient */
  2258. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2259. (value & 0xFF);
  2260. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2261. (value >> 8) & 0xFF;
  2262. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2263. (value >> 16) & 0xFF;
  2264. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2265. (value >> 24) & 0xFF;
  2266. }
  2267. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  2268. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2269. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2270. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2271. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2272. __func__, iir_idx, band_idx,
  2273. get_iir_band_coeff(component, iir_idx, band_idx, 0),
  2274. __func__, iir_idx, band_idx,
  2275. get_iir_band_coeff(component, iir_idx, band_idx, 1),
  2276. __func__, iir_idx, band_idx,
  2277. get_iir_band_coeff(component, iir_idx, band_idx, 2),
  2278. __func__, iir_idx, band_idx,
  2279. get_iir_band_coeff(component, iir_idx, band_idx, 3),
  2280. __func__, iir_idx, band_idx,
  2281. get_iir_band_coeff(component, iir_idx, band_idx, 4));
  2282. return 0;
  2283. }
  2284. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  2285. struct snd_kcontrol *kcontrol, int event)
  2286. {
  2287. struct snd_soc_component *component =
  2288. snd_soc_dapm_to_component(w->dapm);
  2289. dev_dbg(component->dev, "%s: event = %d\n", __func__, event);
  2290. switch (event) {
  2291. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2292. case SND_SOC_DAPM_PRE_PMD:
  2293. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  2294. snd_soc_component_write(component,
  2295. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2296. snd_soc_component_read32(component,
  2297. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2298. snd_soc_component_write(component,
  2299. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2300. snd_soc_component_read32(component,
  2301. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2302. snd_soc_component_write(component,
  2303. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2304. snd_soc_component_read32(component,
  2305. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2306. snd_soc_component_write(component,
  2307. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2308. snd_soc_component_read32(component,
  2309. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2310. } else {
  2311. snd_soc_component_write(component,
  2312. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  2313. snd_soc_component_read32(component,
  2314. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  2315. snd_soc_component_write(component,
  2316. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  2317. snd_soc_component_read32(component,
  2318. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  2319. snd_soc_component_write(component,
  2320. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  2321. snd_soc_component_read32(component,
  2322. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  2323. snd_soc_component_write(component,
  2324. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  2325. snd_soc_component_read32(component,
  2326. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  2327. }
  2328. break;
  2329. }
  2330. return 0;
  2331. }
  2332. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  2333. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  2334. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  2335. 0, -84, 40, digital_gain),
  2336. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  2337. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  2338. 0, -84, 40, digital_gain),
  2339. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  2340. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  2341. 0, -84, 40, digital_gain),
  2342. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  2343. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2344. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  2345. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2346. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  2347. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2348. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  2349. rx_macro_get_compander, rx_macro_set_compander),
  2350. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  2351. rx_macro_get_compander, rx_macro_set_compander),
  2352. SOC_ENUM_EXT("HPH Idle Detect", hph_idle_detect_enum,
  2353. rx_macro_hph_idle_detect_get, rx_macro_hph_idle_detect_put),
  2354. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  2355. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  2356. SOC_ENUM_EXT("RX_HPH HD2 Mode", rx_macro_hph_hd2_mode_enum,
  2357. rx_macro_get_hph_hd2_mode, rx_macro_put_hph_hd2_mode),
  2358. SOC_ENUM_EXT("RX_HPH_PWR_MODE", rx_macro_hph_pwr_mode_enum,
  2359. rx_macro_get_hph_pwr_mode, rx_macro_put_hph_pwr_mode),
  2360. SOC_ENUM_EXT("RX_GSM mode Enable", rx_macro_vbat_bcl_gsm_mode_enum,
  2361. rx_macro_vbat_bcl_gsm_mode_func_get,
  2362. rx_macro_vbat_bcl_gsm_mode_func_put),
  2363. SOC_SINGLE_EXT("RX_Softclip Enable", SND_SOC_NOPM, 0, 1, 0,
  2364. rx_macro_soft_clip_enable_get,
  2365. rx_macro_soft_clip_enable_put),
  2366. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  2367. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  2368. digital_gain),
  2369. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  2370. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  2371. digital_gain),
  2372. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  2373. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  2374. digital_gain),
  2375. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  2376. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  2377. digital_gain),
  2378. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  2379. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  2380. digital_gain),
  2381. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  2382. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  2383. digital_gain),
  2384. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  2385. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  2386. digital_gain),
  2387. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  2388. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  2389. digital_gain),
  2390. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  2391. rx_macro_iir_enable_audio_mixer_get,
  2392. rx_macro_iir_enable_audio_mixer_put),
  2393. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  2394. rx_macro_iir_enable_audio_mixer_get,
  2395. rx_macro_iir_enable_audio_mixer_put),
  2396. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  2397. rx_macro_iir_enable_audio_mixer_get,
  2398. rx_macro_iir_enable_audio_mixer_put),
  2399. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  2400. rx_macro_iir_enable_audio_mixer_get,
  2401. rx_macro_iir_enable_audio_mixer_put),
  2402. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  2403. rx_macro_iir_enable_audio_mixer_get,
  2404. rx_macro_iir_enable_audio_mixer_put),
  2405. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  2406. rx_macro_iir_enable_audio_mixer_get,
  2407. rx_macro_iir_enable_audio_mixer_put),
  2408. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  2409. rx_macro_iir_enable_audio_mixer_get,
  2410. rx_macro_iir_enable_audio_mixer_put),
  2411. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  2412. rx_macro_iir_enable_audio_mixer_get,
  2413. rx_macro_iir_enable_audio_mixer_put),
  2414. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  2415. rx_macro_iir_enable_audio_mixer_get,
  2416. rx_macro_iir_enable_audio_mixer_put),
  2417. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  2418. rx_macro_iir_enable_audio_mixer_get,
  2419. rx_macro_iir_enable_audio_mixer_put),
  2420. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  2421. rx_macro_iir_band_audio_mixer_get,
  2422. rx_macro_iir_band_audio_mixer_put),
  2423. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  2424. rx_macro_iir_band_audio_mixer_get,
  2425. rx_macro_iir_band_audio_mixer_put),
  2426. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  2427. rx_macro_iir_band_audio_mixer_get,
  2428. rx_macro_iir_band_audio_mixer_put),
  2429. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  2430. rx_macro_iir_band_audio_mixer_get,
  2431. rx_macro_iir_band_audio_mixer_put),
  2432. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  2433. rx_macro_iir_band_audio_mixer_get,
  2434. rx_macro_iir_band_audio_mixer_put),
  2435. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  2436. rx_macro_iir_band_audio_mixer_get,
  2437. rx_macro_iir_band_audio_mixer_put),
  2438. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  2439. rx_macro_iir_band_audio_mixer_get,
  2440. rx_macro_iir_band_audio_mixer_put),
  2441. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  2442. rx_macro_iir_band_audio_mixer_get,
  2443. rx_macro_iir_band_audio_mixer_put),
  2444. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  2445. rx_macro_iir_band_audio_mixer_get,
  2446. rx_macro_iir_band_audio_mixer_put),
  2447. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  2448. rx_macro_iir_band_audio_mixer_get,
  2449. rx_macro_iir_band_audio_mixer_put),
  2450. };
  2451. static int rx_macro_enable_echo(struct snd_soc_dapm_widget *w,
  2452. struct snd_kcontrol *kcontrol,
  2453. int event)
  2454. {
  2455. struct snd_soc_component *component =
  2456. snd_soc_dapm_to_component(w->dapm);
  2457. struct device *rx_dev = NULL;
  2458. struct rx_macro_priv *rx_priv = NULL;
  2459. u16 val = 0, ec_hq_reg = 0;
  2460. int ec_tx = 0;
  2461. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2462. return -EINVAL;
  2463. dev_dbg(rx_dev, "%s %d %s\n", __func__, event, w->name);
  2464. val = snd_soc_component_read32(component,
  2465. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4);
  2466. if (!(strcmp(w->name, "RX MIX TX0 MUX")))
  2467. ec_tx = ((val & 0xf0) >> 0x4) - 1;
  2468. else if (!(strcmp(w->name, "RX MIX TX1 MUX")))
  2469. ec_tx = (val & 0x0f) - 1;
  2470. val = snd_soc_component_read32(component,
  2471. BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG5);
  2472. if (!(strcmp(w->name, "RX MIX TX2 MUX")))
  2473. ec_tx = (val & 0x0f) - 1;
  2474. if (ec_tx < 0 || (ec_tx >= RX_MACRO_EC_MUX_MAX)) {
  2475. dev_err(rx_dev, "%s: EC mix control not set correctly\n",
  2476. __func__);
  2477. return -EINVAL;
  2478. }
  2479. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_PATH_CTL +
  2480. 0x40 * ec_tx;
  2481. snd_soc_component_update_bits(component, ec_hq_reg, 0x01, 0x01);
  2482. ec_hq_reg = BOLERO_CDC_RX_EC_REF_HQ0_EC_REF_HQ_CFG0 +
  2483. 0x40 * ec_tx;
  2484. /* default set to 48k */
  2485. snd_soc_component_update_bits(component, ec_hq_reg, 0x1E, 0x08);
  2486. return 0;
  2487. }
  2488. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  2489. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  2490. SND_SOC_NOPM, 0, 0),
  2491. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  2492. SND_SOC_NOPM, 0, 0),
  2493. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  2494. SND_SOC_NOPM, 0, 0),
  2495. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  2496. SND_SOC_NOPM, 0, 0),
  2497. SND_SOC_DAPM_AIF_OUT("RX AIF_ECHO", "RX_AIF_ECHO Capture", 0,
  2498. SND_SOC_NOPM, 0, 0),
  2499. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  2500. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  2501. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  2502. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  2503. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  2504. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  2505. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2506. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2507. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2508. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2509. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2510. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2511. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  2512. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  2513. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  2514. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  2515. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  2516. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  2517. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  2518. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  2519. SND_SOC_DAPM_MUX_E("RX MIX TX0 MUX", SND_SOC_NOPM,
  2520. RX_MACRO_EC0_MUX, 0,
  2521. &rx_mix_tx0_mux, rx_macro_enable_echo,
  2522. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2523. SND_SOC_DAPM_MUX_E("RX MIX TX1 MUX", SND_SOC_NOPM,
  2524. RX_MACRO_EC1_MUX, 0,
  2525. &rx_mix_tx1_mux, rx_macro_enable_echo,
  2526. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2527. SND_SOC_DAPM_MUX_E("RX MIX TX2 MUX", SND_SOC_NOPM,
  2528. RX_MACRO_EC2_MUX, 0,
  2529. &rx_mix_tx2_mux, rx_macro_enable_echo,
  2530. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2531. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  2532. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2533. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2534. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  2535. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2536. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2537. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  2538. 4, 0, NULL, 0),
  2539. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  2540. 4, 0, NULL, 0),
  2541. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  2542. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  2543. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2544. &rx_int0_2_mux, rx_macro_enable_mix_path,
  2545. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2546. SND_SOC_DAPM_POST_PMD),
  2547. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2548. &rx_int1_2_mux, rx_macro_enable_mix_path,
  2549. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2550. SND_SOC_DAPM_POST_PMD),
  2551. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  2552. &rx_int2_2_mux, rx_macro_enable_mix_path,
  2553. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2554. SND_SOC_DAPM_POST_PMD),
  2555. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  2556. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  2557. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  2558. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  2559. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  2560. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  2561. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  2562. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  2563. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  2564. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  2565. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  2566. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2567. SND_SOC_DAPM_POST_PMD),
  2568. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  2569. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  2570. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2571. SND_SOC_DAPM_POST_PMD),
  2572. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  2573. &rx_int2_1_interp_mux, rx_macro_enable_main_path,
  2574. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2575. SND_SOC_DAPM_POST_PMD),
  2576. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  2577. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2578. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2579. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2580. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2581. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2582. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2583. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2584. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2585. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  2586. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2587. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2588. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  2589. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2590. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2591. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  2592. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2593. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2594. SND_SOC_DAPM_MIXER_E("RX INT2_1 VBAT", SND_SOC_NOPM,
  2595. 0, 0, rx_int2_1_vbat_mix_switch,
  2596. ARRAY_SIZE(rx_int2_1_vbat_mix_switch),
  2597. rx_macro_enable_vbat,
  2598. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2599. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2600. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2601. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2602. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  2603. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  2604. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  2605. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  2606. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  2607. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  2608. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  2609. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2610. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2611. };
  2612. static const struct snd_soc_dapm_route rx_audio_map[] = {
  2613. {"RX AIF1 PB", NULL, "RX_MCLK"},
  2614. {"RX AIF2 PB", NULL, "RX_MCLK"},
  2615. {"RX AIF3 PB", NULL, "RX_MCLK"},
  2616. {"RX AIF4 PB", NULL, "RX_MCLK"},
  2617. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  2618. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  2619. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  2620. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  2621. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  2622. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  2623. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  2624. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  2625. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  2626. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  2627. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  2628. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  2629. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  2630. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  2631. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  2632. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  2633. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  2634. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  2635. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  2636. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  2637. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  2638. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  2639. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  2640. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  2641. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  2642. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  2643. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  2644. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  2645. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  2646. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  2647. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  2648. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  2649. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  2650. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  2651. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  2652. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  2653. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  2654. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  2655. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  2656. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  2657. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  2658. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  2659. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  2660. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  2661. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  2662. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  2663. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  2664. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  2665. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  2666. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  2667. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  2668. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  2669. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  2670. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  2671. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  2672. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  2673. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  2674. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  2675. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  2676. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  2677. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  2678. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  2679. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  2680. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  2681. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  2682. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  2683. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  2684. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  2685. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  2686. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  2687. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  2688. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  2689. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  2690. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  2691. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  2692. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  2693. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  2694. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  2695. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  2696. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  2697. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  2698. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  2699. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  2700. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  2701. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  2702. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  2703. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  2704. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  2705. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  2706. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  2707. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  2708. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  2709. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  2710. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  2711. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  2712. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  2713. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  2714. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  2715. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  2716. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  2717. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  2718. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  2719. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  2720. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  2721. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  2722. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  2723. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  2724. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  2725. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  2726. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  2727. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  2728. {"RX MIX TX0 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2729. {"RX MIX TX0 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2730. {"RX MIX TX0 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2731. {"RX MIX TX1 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2732. {"RX MIX TX1 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2733. {"RX MIX TX1 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2734. {"RX MIX TX2 MUX", "RX_MIX0", "RX INT0 SEC MIX"},
  2735. {"RX MIX TX2 MUX", "RX_MIX1", "RX INT1 SEC MIX"},
  2736. {"RX MIX TX2 MUX", "RX_MIX2", "RX INT2 SEC MIX"},
  2737. {"RX AIF_ECHO", NULL, "RX MIX TX0 MUX"},
  2738. {"RX AIF_ECHO", NULL, "RX MIX TX1 MUX"},
  2739. {"RX AIF_ECHO", NULL, "RX MIX TX2 MUX"},
  2740. {"RX AIF_ECHO", NULL, "RX_MCLK"},
  2741. /* Mixing path INT0 */
  2742. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  2743. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  2744. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  2745. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  2746. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  2747. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  2748. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  2749. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  2750. /* Mixing path INT1 */
  2751. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  2752. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  2753. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  2754. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  2755. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  2756. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  2757. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  2758. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  2759. /* Mixing path INT2 */
  2760. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  2761. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  2762. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  2763. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  2764. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  2765. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  2766. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  2767. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  2768. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  2769. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  2770. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  2771. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  2772. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  2773. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  2774. {"HPHL_OUT", NULL, "RX_MCLK"},
  2775. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  2776. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  2777. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  2778. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  2779. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  2780. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  2781. {"HPHR_OUT", NULL, "RX_MCLK"},
  2782. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  2783. {"RX INT2_1 VBAT", "RX AUX VBAT Enable", "RX INT2_1 INTERP"},
  2784. {"RX INT2 SEC MIX", NULL, "RX INT2_1 VBAT"},
  2785. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  2786. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2787. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2788. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2789. {"AUX_OUT", NULL, "RX_MCLK"},
  2790. {"IIR0", NULL, "RX_MCLK"},
  2791. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2792. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2793. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2794. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2795. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2796. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2797. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2798. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2799. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2800. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2801. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2802. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2803. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2804. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2805. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2806. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2807. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2808. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2809. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2810. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2811. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2812. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2813. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2814. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2815. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2816. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2817. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2818. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2819. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2820. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2821. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2822. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2823. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2824. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2825. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2826. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2827. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2828. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2829. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2830. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2831. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2832. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2833. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2834. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2835. {"IIR1", NULL, "RX_MCLK"},
  2836. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2837. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2838. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2839. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2840. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2841. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2842. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2843. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2844. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2845. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2846. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2847. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2848. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2849. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2850. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2851. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2852. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2853. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2854. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2855. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2856. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2857. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2858. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2859. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2860. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2861. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2862. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2863. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2864. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2865. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2866. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2867. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2868. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2869. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2870. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2871. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2872. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2873. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2874. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2875. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2876. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2877. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2878. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2879. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2880. {"SRC0", NULL, "IIR0"},
  2881. {"SRC1", NULL, "IIR1"},
  2882. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2883. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2884. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2885. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2886. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2887. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2888. };
  2889. static int rx_swrm_clock(void *handle, bool enable)
  2890. {
  2891. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2892. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2893. int ret = 0;
  2894. if (regmap == NULL) {
  2895. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2896. return -EINVAL;
  2897. }
  2898. mutex_lock(&rx_priv->swr_clk_lock);
  2899. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2900. __func__, (enable ? "enable" : "disable"));
  2901. if (enable) {
  2902. pm_runtime_get_sync(rx_priv->dev);
  2903. if (rx_priv->swr_clk_users == 0) {
  2904. msm_cdc_pinctrl_select_active_state(
  2905. rx_priv->rx_swr_gpio_p);
  2906. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2907. if (ret < 0) {
  2908. msm_cdc_pinctrl_select_sleep_state(
  2909. rx_priv->rx_swr_gpio_p);
  2910. dev_err(rx_priv->dev,
  2911. "%s: rx request clock enable failed\n",
  2912. __func__);
  2913. goto exit;
  2914. }
  2915. if (rx_priv->reset_swr)
  2916. regmap_update_bits(regmap,
  2917. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2918. 0x02, 0x02);
  2919. regmap_update_bits(regmap,
  2920. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2921. 0x01, 0x01);
  2922. if (rx_priv->reset_swr)
  2923. regmap_update_bits(regmap,
  2924. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2925. 0x02, 0x00);
  2926. rx_priv->reset_swr = false;
  2927. }
  2928. pm_runtime_mark_last_busy(rx_priv->dev);
  2929. pm_runtime_put_autosuspend(rx_priv->dev);
  2930. rx_priv->swr_clk_users++;
  2931. } else {
  2932. if (rx_priv->swr_clk_users <= 0) {
  2933. dev_err(rx_priv->dev,
  2934. "%s: rx swrm clock users already reset\n",
  2935. __func__);
  2936. rx_priv->swr_clk_users = 0;
  2937. goto exit;
  2938. }
  2939. rx_priv->swr_clk_users--;
  2940. if (rx_priv->swr_clk_users == 0) {
  2941. regmap_update_bits(regmap,
  2942. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2943. 0x01, 0x00);
  2944. rx_macro_mclk_enable(rx_priv, 0, true);
  2945. msm_cdc_pinctrl_select_sleep_state(
  2946. rx_priv->rx_swr_gpio_p);
  2947. }
  2948. }
  2949. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2950. __func__, rx_priv->swr_clk_users);
  2951. exit:
  2952. mutex_unlock(&rx_priv->swr_clk_lock);
  2953. return ret;
  2954. }
  2955. static void rx_macro_init_bcl_pmic_reg(struct snd_soc_component *component)
  2956. {
  2957. struct device *rx_dev = NULL;
  2958. struct rx_macro_priv *rx_priv = NULL;
  2959. if (!component) {
  2960. pr_err("%s: NULL component pointer!\n", __func__);
  2961. return;
  2962. }
  2963. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  2964. return;
  2965. switch (rx_priv->bcl_pmic_params.id) {
  2966. case 0:
  2967. /* Enable ID0 to listen to respective PMIC group interrupts */
  2968. snd_soc_component_update_bits(component,
  2969. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2970. /* Update MC_SID0 */
  2971. snd_soc_component_update_bits(component,
  2972. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0x0F,
  2973. rx_priv->bcl_pmic_params.sid);
  2974. /* Update MC_PPID0 */
  2975. snd_soc_component_update_bits(component,
  2976. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG2, 0xFF,
  2977. rx_priv->bcl_pmic_params.ppid);
  2978. break;
  2979. case 1:
  2980. /* Enable ID1 to listen to respective PMIC group interrupts */
  2981. snd_soc_component_update_bits(component,
  2982. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2983. /* Update MC_SID1 */
  2984. snd_soc_component_update_bits(component,
  2985. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG3, 0x0F,
  2986. rx_priv->bcl_pmic_params.sid);
  2987. /* Update MC_PPID1 */
  2988. snd_soc_component_update_bits(component,
  2989. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0xFF,
  2990. rx_priv->bcl_pmic_params.ppid);
  2991. break;
  2992. default:
  2993. dev_err(rx_dev, "%s: PMIC ID is invalid %d\n",
  2994. __func__, rx_priv->bcl_pmic_params.id);
  2995. break;
  2996. }
  2997. }
  2998. static int rx_macro_init(struct snd_soc_component *component)
  2999. {
  3000. struct snd_soc_dapm_context *dapm =
  3001. snd_soc_component_get_dapm(component);
  3002. int ret = 0;
  3003. struct device *rx_dev = NULL;
  3004. struct rx_macro_priv *rx_priv = NULL;
  3005. rx_dev = bolero_get_device_ptr(component->dev, RX_MACRO);
  3006. if (!rx_dev) {
  3007. dev_err(component->dev,
  3008. "%s: null device for macro!\n", __func__);
  3009. return -EINVAL;
  3010. }
  3011. rx_priv = dev_get_drvdata(rx_dev);
  3012. if (!rx_priv) {
  3013. dev_err(component->dev,
  3014. "%s: priv is null for macro!\n", __func__);
  3015. return -EINVAL;
  3016. }
  3017. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  3018. ARRAY_SIZE(rx_macro_dapm_widgets));
  3019. if (ret < 0) {
  3020. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  3021. return ret;
  3022. }
  3023. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  3024. ARRAY_SIZE(rx_audio_map));
  3025. if (ret < 0) {
  3026. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  3027. return ret;
  3028. }
  3029. ret = snd_soc_dapm_new_widgets(dapm->card);
  3030. if (ret < 0) {
  3031. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  3032. return ret;
  3033. }
  3034. ret = snd_soc_add_component_controls(component, rx_macro_snd_controls,
  3035. ARRAY_SIZE(rx_macro_snd_controls));
  3036. if (ret < 0) {
  3037. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  3038. return ret;
  3039. }
  3040. rx_priv->dev_up = true;
  3041. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF1 Playback");
  3042. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF2 Playback");
  3043. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF3 Playback");
  3044. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF4 Playback");
  3045. snd_soc_dapm_ignore_suspend(dapm, "HPHL_OUT");
  3046. snd_soc_dapm_ignore_suspend(dapm, "HPHR_OUT");
  3047. snd_soc_dapm_ignore_suspend(dapm, "AUX_OUT");
  3048. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC0_INP");
  3049. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC1_INP");
  3050. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC2_INP");
  3051. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC3_INP");
  3052. snd_soc_dapm_sync(dapm);
  3053. snd_soc_component_update_bits(component,
  3054. BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL,
  3055. 0x01, 0x01);
  3056. snd_soc_component_update_bits(component,
  3057. BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL,
  3058. 0x01, 0x01);
  3059. snd_soc_component_update_bits(component,
  3060. BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL,
  3061. 0x01, 0x01);
  3062. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_SEC7,
  3063. 0x07, 0x02);
  3064. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_SEC7,
  3065. 0x07, 0x02);
  3066. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  3067. 0x07, 0x02);
  3068. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX0_RX_PATH_CFG3,
  3069. 0x03, 0x02);
  3070. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX1_RX_PATH_CFG3,
  3071. 0x03, 0x02);
  3072. snd_soc_component_update_bits(component, BOLERO_CDC_RX_RX2_RX_PATH_CFG3,
  3073. 0x03, 0x02);
  3074. rx_priv->component = component;
  3075. rx_macro_init_bcl_pmic_reg(component);
  3076. return 0;
  3077. }
  3078. static int rx_macro_deinit(struct snd_soc_component *component)
  3079. {
  3080. struct device *rx_dev = NULL;
  3081. struct rx_macro_priv *rx_priv = NULL;
  3082. if (!rx_macro_get_data(component, &rx_dev, &rx_priv, __func__))
  3083. return -EINVAL;
  3084. rx_priv->component = NULL;
  3085. return 0;
  3086. }
  3087. static void rx_macro_add_child_devices(struct work_struct *work)
  3088. {
  3089. struct rx_macro_priv *rx_priv = NULL;
  3090. struct platform_device *pdev = NULL;
  3091. struct device_node *node = NULL;
  3092. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  3093. int ret = 0;
  3094. u16 count = 0, ctrl_num = 0;
  3095. struct rx_swr_ctrl_platform_data *platdata = NULL;
  3096. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  3097. bool rx_swr_master_node = false;
  3098. rx_priv = container_of(work, struct rx_macro_priv,
  3099. rx_macro_add_child_devices_work);
  3100. if (!rx_priv) {
  3101. pr_err("%s: Memory for rx_priv does not exist\n",
  3102. __func__);
  3103. return;
  3104. }
  3105. if (!rx_priv->dev) {
  3106. pr_err("%s: RX device does not exist\n", __func__);
  3107. return;
  3108. }
  3109. if(!rx_priv->dev->of_node) {
  3110. dev_err(rx_priv->dev,
  3111. "%s: DT node for RX dev does not exist\n", __func__);
  3112. return;
  3113. }
  3114. platdata = &rx_priv->swr_plat_data;
  3115. rx_priv->child_count = 0;
  3116. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  3117. rx_swr_master_node = false;
  3118. if (strnstr(node->name, "rx_swr_master",
  3119. strlen("rx_swr_master")) != NULL)
  3120. rx_swr_master_node = true;
  3121. if(rx_swr_master_node)
  3122. strlcpy(plat_dev_name, "rx_swr_ctrl",
  3123. (RX_SWR_STRING_LEN - 1));
  3124. else
  3125. strlcpy(plat_dev_name, node->name,
  3126. (RX_SWR_STRING_LEN - 1));
  3127. pdev = platform_device_alloc(plat_dev_name, -1);
  3128. if (!pdev) {
  3129. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  3130. __func__);
  3131. ret = -ENOMEM;
  3132. goto err;
  3133. }
  3134. pdev->dev.parent = rx_priv->dev;
  3135. pdev->dev.of_node = node;
  3136. if (rx_swr_master_node) {
  3137. ret = platform_device_add_data(pdev, platdata,
  3138. sizeof(*platdata));
  3139. if (ret) {
  3140. dev_err(&pdev->dev,
  3141. "%s: cannot add plat data ctrl:%d\n",
  3142. __func__, ctrl_num);
  3143. goto fail_pdev_add;
  3144. }
  3145. }
  3146. ret = platform_device_add(pdev);
  3147. if (ret) {
  3148. dev_err(&pdev->dev,
  3149. "%s: Cannot add platform device\n",
  3150. __func__);
  3151. goto fail_pdev_add;
  3152. }
  3153. if (rx_swr_master_node) {
  3154. temp = krealloc(swr_ctrl_data,
  3155. (ctrl_num + 1) * sizeof(
  3156. struct rx_swr_ctrl_data),
  3157. GFP_KERNEL);
  3158. if (!temp) {
  3159. ret = -ENOMEM;
  3160. goto fail_pdev_add;
  3161. }
  3162. swr_ctrl_data = temp;
  3163. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  3164. ctrl_num++;
  3165. dev_dbg(&pdev->dev,
  3166. "%s: Added soundwire ctrl device(s)\n",
  3167. __func__);
  3168. rx_priv->swr_ctrl_data = swr_ctrl_data;
  3169. }
  3170. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  3171. rx_priv->pdev_child_devices[
  3172. rx_priv->child_count++] = pdev;
  3173. else
  3174. goto err;
  3175. }
  3176. return;
  3177. fail_pdev_add:
  3178. for (count = 0; count < rx_priv->child_count; count++)
  3179. platform_device_put(rx_priv->pdev_child_devices[count]);
  3180. err:
  3181. return;
  3182. }
  3183. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  3184. {
  3185. memset(ops, 0, sizeof(struct macro_ops));
  3186. ops->init = rx_macro_init;
  3187. ops->exit = rx_macro_deinit;
  3188. ops->io_base = rx_io_base;
  3189. ops->dai_ptr = rx_macro_dai;
  3190. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  3191. ops->event_handler = rx_macro_event_handler;
  3192. ops->set_port_map = rx_macro_set_port_map;
  3193. }
  3194. static int rx_macro_probe(struct platform_device *pdev)
  3195. {
  3196. struct macro_ops ops = {0};
  3197. struct rx_macro_priv *rx_priv = NULL;
  3198. u32 rx_base_addr = 0, muxsel = 0;
  3199. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  3200. int ret = 0;
  3201. u8 bcl_pmic_params[3];
  3202. u32 default_clk_id = 0;
  3203. u32 is_used_rx_swr_gpio = 1;
  3204. const char *is_used_rx_swr_gpio_dt = "qcom,is-used-swr-gpio";
  3205. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  3206. GFP_KERNEL);
  3207. if (!rx_priv)
  3208. return -ENOMEM;
  3209. rx_priv->dev = &pdev->dev;
  3210. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  3211. &rx_base_addr);
  3212. if (ret) {
  3213. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3214. __func__, "reg");
  3215. return ret;
  3216. }
  3217. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  3218. &muxsel);
  3219. if (ret) {
  3220. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3221. __func__, "reg");
  3222. return ret;
  3223. }
  3224. ret = of_property_read_u32(pdev->dev.of_node, "qcom,default-clk-id",
  3225. &default_clk_id);
  3226. if (ret) {
  3227. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  3228. __func__, "qcom,default-clk-id");
  3229. default_clk_id = RX_CORE_CLK;
  3230. }
  3231. if (of_find_property(pdev->dev.of_node, is_used_rx_swr_gpio_dt,
  3232. NULL)) {
  3233. ret = of_property_read_u32(pdev->dev.of_node,
  3234. is_used_rx_swr_gpio_dt,
  3235. &is_used_rx_swr_gpio);
  3236. if (ret) {
  3237. dev_err(&pdev->dev, "%s: error reading %s in dt\n",
  3238. __func__, is_used_rx_swr_gpio_dt);
  3239. is_used_rx_swr_gpio = 1;
  3240. }
  3241. }
  3242. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  3243. "qcom,rx-swr-gpios", 0);
  3244. if (!rx_priv->rx_swr_gpio_p && is_used_rx_swr_gpio) {
  3245. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  3246. __func__);
  3247. return -EINVAL;
  3248. }
  3249. if (msm_cdc_pinctrl_get_state(rx_priv->rx_swr_gpio_p) < 0) {
  3250. dev_err(&pdev->dev, "%s: failed to get swr pin state\n",
  3251. __func__);
  3252. return -EPROBE_DEFER;
  3253. }
  3254. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  3255. RX_MACRO_MAX_OFFSET);
  3256. if (!rx_io_base) {
  3257. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  3258. return -ENOMEM;
  3259. }
  3260. rx_priv->rx_io_base = rx_io_base;
  3261. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  3262. if (!muxsel_io) {
  3263. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  3264. __func__);
  3265. return -ENOMEM;
  3266. }
  3267. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  3268. rx_priv->reset_swr = true;
  3269. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  3270. rx_macro_add_child_devices);
  3271. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  3272. rx_priv->swr_plat_data.read = NULL;
  3273. rx_priv->swr_plat_data.write = NULL;
  3274. rx_priv->swr_plat_data.bulk_write = NULL;
  3275. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  3276. rx_priv->swr_plat_data.handle_irq = NULL;
  3277. ret = of_property_read_u8_array(pdev->dev.of_node,
  3278. "qcom,rx-bcl-pmic-params", bcl_pmic_params,
  3279. sizeof(bcl_pmic_params));
  3280. if (ret) {
  3281. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  3282. __func__, "qcom,rx-bcl-pmic-params");
  3283. } else {
  3284. rx_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  3285. rx_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  3286. rx_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  3287. }
  3288. rx_priv->clk_id = default_clk_id;
  3289. rx_priv->default_clk_id = default_clk_id;
  3290. ops.clk_id_req = rx_priv->clk_id;
  3291. ops.default_clk_id = default_clk_id;
  3292. dev_set_drvdata(&pdev->dev, rx_priv);
  3293. mutex_init(&rx_priv->mclk_lock);
  3294. mutex_init(&rx_priv->swr_clk_lock);
  3295. rx_macro_init_ops(&ops, rx_io_base);
  3296. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  3297. if (ret) {
  3298. dev_err(&pdev->dev,
  3299. "%s: register macro failed\n", __func__);
  3300. goto err_reg_macro;
  3301. }
  3302. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  3303. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_DELAY);
  3304. pm_runtime_use_autosuspend(&pdev->dev);
  3305. pm_runtime_set_suspended(&pdev->dev);
  3306. pm_runtime_enable(&pdev->dev);
  3307. return 0;
  3308. err_reg_macro:
  3309. mutex_destroy(&rx_priv->mclk_lock);
  3310. mutex_destroy(&rx_priv->swr_clk_lock);
  3311. return ret;
  3312. }
  3313. static int rx_macro_remove(struct platform_device *pdev)
  3314. {
  3315. struct rx_macro_priv *rx_priv = NULL;
  3316. u16 count = 0;
  3317. rx_priv = dev_get_drvdata(&pdev->dev);
  3318. if (!rx_priv)
  3319. return -EINVAL;
  3320. for (count = 0; count < rx_priv->child_count &&
  3321. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  3322. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  3323. pm_runtime_disable(&pdev->dev);
  3324. pm_runtime_set_suspended(&pdev->dev);
  3325. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  3326. mutex_destroy(&rx_priv->mclk_lock);
  3327. mutex_destroy(&rx_priv->swr_clk_lock);
  3328. kfree(rx_priv->swr_ctrl_data);
  3329. return 0;
  3330. }
  3331. static const struct of_device_id rx_macro_dt_match[] = {
  3332. {.compatible = "qcom,rx-macro"},
  3333. {}
  3334. };
  3335. static const struct dev_pm_ops bolero_dev_pm_ops = {
  3336. SET_RUNTIME_PM_OPS(
  3337. bolero_runtime_suspend,
  3338. bolero_runtime_resume,
  3339. NULL
  3340. )
  3341. };
  3342. static struct platform_driver rx_macro_driver = {
  3343. .driver = {
  3344. .name = "rx_macro",
  3345. .owner = THIS_MODULE,
  3346. .pm = &bolero_dev_pm_ops,
  3347. .of_match_table = rx_macro_dt_match,
  3348. .suppress_bind_attrs = true,
  3349. },
  3350. .probe = rx_macro_probe,
  3351. .remove = rx_macro_remove,
  3352. };
  3353. module_platform_driver(rx_macro_driver);
  3354. MODULE_DESCRIPTION("RX macro driver");
  3355. MODULE_LICENSE("GPL v2");