rx-macro.c 128 KB

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