rx-macro.c 125 KB

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