rx-macro.c 128 KB

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