rx-macro.c 128 KB

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