rx-macro.c 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425
  1. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/clk.h>
  17. #include <sound/soc.h>
  18. #include <sound/pcm.h>
  19. #include <sound/pcm_params.h>
  20. #include <sound/soc-dapm.h>
  21. #include <sound/tlv.h>
  22. #include <soc/swr-wcd.h>
  23. #include "bolero-cdc.h"
  24. #include "bolero-cdc-registers.h"
  25. #include "../msm-cdc-pinctrl.h"
  26. #define RX_MACRO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  27. SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\
  28. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000 |\
  29. SNDRV_PCM_RATE_384000)
  30. /* Fractional Rates */
  31. #define RX_MACRO_FRAC_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |\
  32. SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_352800)
  33. #define RX_MACRO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  34. SNDRV_PCM_FMTBIT_S24_LE |\
  35. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  36. #define RX_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  37. SNDRV_PCM_RATE_48000)
  38. #define RX_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  39. SNDRV_PCM_FMTBIT_S24_LE |\
  40. SNDRV_PCM_FMTBIT_S24_3LE)
  41. #define SAMPLING_RATE_44P1KHZ 44100
  42. #define SAMPLING_RATE_88P2KHZ 88200
  43. #define SAMPLING_RATE_176P4KHZ 176400
  44. #define SAMPLING_RATE_352P8KHZ 352800
  45. #define RX_MACRO_MAX_OFFSET 0x1000
  46. #define RX_MACRO_MAX_DMA_CH_PER_PORT 2
  47. #define RX_SWR_STRING_LEN 80
  48. #define RX_MACRO_CHILD_DEVICES_MAX 3
  49. #define RX_MACRO_INTERP_MUX_NUM_INPUTS 3
  50. #define RX_MACRO_SIDETONE_IIR_COEFF_MAX 5
  51. #define STRING(name) #name
  52. #define RX_MACRO_DAPM_ENUM(name, reg, offset, text) \
  53. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  54. static const struct snd_kcontrol_new name##_mux = \
  55. SOC_DAPM_ENUM(STRING(name), name##_enum)
  56. #define RX_MACRO_DAPM_ENUM_EXT(name, reg, offset, text, getname, putname) \
  57. static SOC_ENUM_SINGLE_DECL(name##_enum, reg, offset, text); \
  58. static const struct snd_kcontrol_new name##_mux = \
  59. SOC_DAPM_ENUM_EXT(STRING(name), name##_enum, getname, putname)
  60. #define RX_MACRO_DAPM_MUX(name, shift, kctl) \
  61. SND_SOC_DAPM_MUX(name, SND_SOC_NOPM, shift, 0, &kctl##_mux)
  62. #define RX_MACRO_RX_PATH_OFFSET 0x80
  63. #define RX_MACRO_COMP_OFFSET 0x40
  64. #define MAX_IMPED_PARAMS 6
  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 rx_macro_reg_mask_val {
  82. u16 reg;
  83. u8 mask;
  84. u8 val;
  85. };
  86. static const struct rx_macro_reg_mask_val imped_table[][MAX_IMPED_PARAMS] = {
  87. {
  88. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf2},
  89. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf2},
  90. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  91. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf2},
  92. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf2},
  93. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  94. },
  95. {
  96. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf4},
  97. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf4},
  98. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  99. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf4},
  100. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf4},
  101. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  102. },
  103. {
  104. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf7},
  105. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf7},
  106. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  107. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf7},
  108. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf7},
  109. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  110. },
  111. {
  112. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xf9},
  113. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xf9},
  114. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  115. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xf9},
  116. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xf9},
  117. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  118. },
  119. {
  120. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfa},
  121. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfa},
  122. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  123. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfa},
  124. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfa},
  125. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  126. },
  127. {
  128. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfb},
  129. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfb},
  130. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  131. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfb},
  132. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfb},
  133. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  134. },
  135. {
  136. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfc},
  137. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfc},
  138. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  139. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfc},
  140. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfc},
  141. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  142. },
  143. {
  144. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  145. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  146. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x00},
  147. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  148. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  149. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x00},
  150. },
  151. {
  152. {BOLERO_CDC_RX_RX0_RX_VOL_CTL, 0xff, 0xfd},
  153. {BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0xff, 0xfd},
  154. {BOLERO_CDC_RX_RX0_RX_PATH_SEC1, 0x01, 0x01},
  155. {BOLERO_CDC_RX_RX1_RX_VOL_CTL, 0xff, 0xfd},
  156. {BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
  157. {BOLERO_CDC_RX_RX1_RX_PATH_SEC1, 0x01, 0x01},
  158. },
  159. };
  160. enum {
  161. INTERP_HPHL,
  162. INTERP_HPHR,
  163. INTERP_AUX,
  164. INTERP_MAX
  165. };
  166. enum {
  167. RX_MACRO_RX0,
  168. RX_MACRO_RX1,
  169. RX_MACRO_RX2,
  170. RX_MACRO_RX3,
  171. RX_MACRO_RX4,
  172. RX_MACRO_RX5,
  173. RX_MACRO_PORTS_MAX
  174. };
  175. enum {
  176. RX_MACRO_COMP1, /* HPH_L */
  177. RX_MACRO_COMP2, /* HPH_R */
  178. RX_MACRO_COMP_MAX
  179. };
  180. enum {
  181. INTn_1_INP_SEL_ZERO = 0,
  182. INTn_1_INP_SEL_DEC0,
  183. INTn_1_INP_SEL_DEC1,
  184. INTn_1_INP_SEL_IIR0,
  185. INTn_1_INP_SEL_IIR1,
  186. INTn_1_INP_SEL_RX0,
  187. INTn_1_INP_SEL_RX1,
  188. INTn_1_INP_SEL_RX2,
  189. INTn_1_INP_SEL_RX3,
  190. INTn_1_INP_SEL_RX4,
  191. INTn_1_INP_SEL_RX5,
  192. };
  193. enum {
  194. INTn_2_INP_SEL_ZERO = 0,
  195. INTn_2_INP_SEL_RX0,
  196. INTn_2_INP_SEL_RX1,
  197. INTn_2_INP_SEL_RX2,
  198. INTn_2_INP_SEL_RX3,
  199. INTn_2_INP_SEL_RX4,
  200. INTn_2_INP_SEL_RX5,
  201. };
  202. enum {
  203. INTERP_MAIN_PATH,
  204. INTERP_MIX_PATH,
  205. };
  206. /* Codec supports 2 IIR filters */
  207. enum {
  208. IIR0 = 0,
  209. IIR1,
  210. IIR_MAX,
  211. };
  212. /* Each IIR has 5 Filter Stages */
  213. enum {
  214. BAND1 = 0,
  215. BAND2,
  216. BAND3,
  217. BAND4,
  218. BAND5,
  219. BAND_MAX,
  220. };
  221. struct rx_macro_idle_detect_config {
  222. u8 hph_idle_thr;
  223. u8 hph_idle_detect_en;
  224. };
  225. struct interp_sample_rate {
  226. int sample_rate;
  227. int rate_val;
  228. };
  229. static struct interp_sample_rate sr_val_tbl[] = {
  230. {8000, 0x0}, {16000, 0x1}, {32000, 0x3}, {48000, 0x4}, {96000, 0x5},
  231. {192000, 0x6}, {384000, 0x7}, {44100, 0x9}, {88200, 0xA},
  232. {176400, 0xB}, {352800, 0xC},
  233. };
  234. struct rx_macro_bcl_pmic_params {
  235. u8 id;
  236. u8 sid;
  237. u8 ppid;
  238. };
  239. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  240. struct snd_pcm_hw_params *params,
  241. struct snd_soc_dai *dai);
  242. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  243. unsigned int *tx_num, unsigned int *tx_slot,
  244. unsigned int *rx_num, unsigned int *rx_slot);
  245. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  246. struct snd_ctl_elem_value *ucontrol);
  247. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  248. struct snd_ctl_elem_value *ucontrol);
  249. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  250. struct snd_ctl_elem_value *ucontrol);
  251. static int rx_macro_enable_interp_clk(struct snd_soc_codec *codec,
  252. int event, int interp_idx);
  253. /* Hold instance to soundwire platform device */
  254. struct rx_swr_ctrl_data {
  255. struct platform_device *rx_swr_pdev;
  256. };
  257. struct rx_swr_ctrl_platform_data {
  258. void *handle; /* holds codec private data */
  259. int (*read)(void *handle, int reg);
  260. int (*write)(void *handle, int reg, int val);
  261. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  262. int (*clk)(void *handle, bool enable);
  263. int (*handle_irq)(void *handle,
  264. irqreturn_t (*swrm_irq_handler)(int irq,
  265. void *data),
  266. void *swrm_handle,
  267. int action);
  268. };
  269. enum {
  270. RX_MACRO_AIF_INVALID = 0,
  271. RX_MACRO_AIF1_PB,
  272. RX_MACRO_AIF2_PB,
  273. RX_MACRO_AIF3_PB,
  274. RX_MACRO_AIF4_PB,
  275. RX_MACRO_MAX_DAIS,
  276. };
  277. enum {
  278. RX_MACRO_AIF1_CAP = 0,
  279. RX_MACRO_AIF2_CAP,
  280. RX_MACRO_AIF3_CAP,
  281. RX_MACRO_MAX_AIF_CAP_DAIS
  282. };
  283. /*
  284. * @dev: rx macro device pointer
  285. * @comp_enabled: compander enable mixer value set
  286. * @prim_int_users: Users of interpolator
  287. * @rx_mclk_users: RX MCLK users count
  288. * @vi_feed_value: VI sense mask
  289. * @swr_clk_lock: to lock swr master clock operations
  290. * @swr_ctrl_data: SoundWire data structure
  291. * @swr_plat_data: Soundwire platform data
  292. * @rx_macro_add_child_devices_work: work for adding child devices
  293. * @rx_swr_gpio_p: used by pinctrl API
  294. * @rx_core_clk: MCLK for rx macro
  295. * @rx_npl_clk: NPL clock for RX soundwire
  296. * @codec: codec handle
  297. */
  298. struct rx_macro_priv {
  299. struct device *dev;
  300. int comp_enabled[RX_MACRO_COMP_MAX];
  301. /* Main path clock users count */
  302. int main_clk_users[INTERP_MAX];
  303. int rx_port_value[RX_MACRO_PORTS_MAX];
  304. u16 prim_int_users[INTERP_MAX];
  305. int rx_mclk_users;
  306. int swr_clk_users;
  307. int clsh_users;
  308. int rx_mclk_cnt;
  309. bool is_native_on;
  310. bool is_ear_mode_on;
  311. bool dev_up;
  312. bool hph_pwr_mode;
  313. bool hph_hd2_mode;
  314. u16 mclk_mux;
  315. struct mutex mclk_lock;
  316. struct mutex swr_clk_lock;
  317. struct rx_swr_ctrl_data *swr_ctrl_data;
  318. struct rx_swr_ctrl_platform_data swr_plat_data;
  319. struct work_struct rx_macro_add_child_devices_work;
  320. struct device_node *rx_swr_gpio_p;
  321. struct clk *rx_core_clk;
  322. struct clk *rx_npl_clk;
  323. struct snd_soc_codec *codec;
  324. unsigned long active_ch_mask[RX_MACRO_MAX_DAIS];
  325. unsigned long active_ch_cnt[RX_MACRO_MAX_DAIS];
  326. u16 bit_width[RX_MACRO_MAX_DAIS];
  327. char __iomem *rx_io_base;
  328. char __iomem *rx_mclk_mode_muxsel;
  329. struct rx_macro_idle_detect_config idle_det_cfg;
  330. u8 sidetone_coeff_array[IIR_MAX][BAND_MAX]
  331. [RX_MACRO_SIDETONE_IIR_COEFF_MAX * 4];
  332. struct platform_device *pdev_child_devices
  333. [RX_MACRO_CHILD_DEVICES_MAX];
  334. int child_count;
  335. int is_softclip_on;
  336. int softclip_clk_users;
  337. struct rx_macro_bcl_pmic_params bcl_pmic_params;
  338. };
  339. static struct snd_soc_dai_driver rx_macro_dai[];
  340. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  341. static const char * const rx_int_mix_mux_text[] = {
  342. "ZERO", "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  343. };
  344. static const char * const rx_prim_mix_text[] = {
  345. "ZERO", "DEC0", "DEC1", "IIR0", "IIR1", "RX0", "RX1", "RX2",
  346. "RX3", "RX4", "RX5"
  347. };
  348. static const char * const rx_sidetone_mix_text[] = {
  349. "ZERO", "SRC0", "SRC1", "SRC_SUM"
  350. };
  351. static const char * const rx_echo_mux_text[] = {
  352. "ZERO", "RX_MIX0", "RX_MIX1", "RX_MIX2"
  353. };
  354. static const char * const iir_inp_mux_text[] = {
  355. "ZERO", "DEC0", "DEC1", "DEC2", "DEC3",
  356. "RX0", "RX1", "RX2", "RX3", "RX4", "RX5"
  357. };
  358. static const char * const rx_int_dem_inp_mux_text[] = {
  359. "NORMAL_DSM_OUT", "CLSH_DSM_OUT",
  360. };
  361. static const char * const rx_int0_1_interp_mux_text[] = {
  362. "ZERO", "RX INT0_1 MIX1",
  363. };
  364. static const char * const rx_int1_1_interp_mux_text[] = {
  365. "ZERO", "RX INT1_1 MIX1",
  366. };
  367. static const char * const rx_int2_1_interp_mux_text[] = {
  368. "ZERO", "RX INT2_1 MIX1",
  369. };
  370. static const char * const rx_int0_2_interp_mux_text[] = {
  371. "ZERO", "RX INT0_2 MUX",
  372. };
  373. static const char * const rx_int1_2_interp_mux_text[] = {
  374. "ZERO", "RX INT1_2 MUX",
  375. };
  376. static const char * const rx_int2_2_interp_mux_text[] = {
  377. "ZERO", "RX INT2_2 MUX",
  378. };
  379. static const char *const rx_macro_mux_text[] = {
  380. "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB", "AIF4_PB"
  381. };
  382. static const char *const rx_macro_ear_mode_text[] = {"OFF", "ON"};
  383. static const struct soc_enum rx_macro_ear_mode_enum =
  384. SOC_ENUM_SINGLE_EXT(2, rx_macro_ear_mode_text);
  385. static const char *const rx_macro_hph_hd2_mode_text[] = {"OFF", "ON"};
  386. static const struct soc_enum rx_macro_hph_hd2_mode_enum =
  387. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_hd2_mode_text);
  388. static const char *const rx_macro_hph_pwr_mode_text[] = {"ULP", "LoHIFI"};
  389. static const struct soc_enum rx_macro_hph_pwr_mode_enum =
  390. SOC_ENUM_SINGLE_EXT(2, rx_macro_hph_pwr_mode_text);
  391. static const char * const rx_macro_vbat_bcl_gsm_mode_text[] = {"OFF", "ON"};
  392. static const struct soc_enum rx_macro_vbat_bcl_gsm_mode_enum =
  393. SOC_ENUM_SINGLE_EXT(2, rx_macro_vbat_bcl_gsm_mode_text);
  394. static const struct snd_kcontrol_new rx_int2_1_vbat_mix_switch[] = {
  395. SOC_DAPM_SINGLE("RX AUX VBAT Enable", SND_SOC_NOPM, 0, 1, 0)
  396. };
  397. RX_MACRO_DAPM_ENUM(rx_int0_2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 0,
  398. rx_int_mix_mux_text);
  399. RX_MACRO_DAPM_ENUM(rx_int1_2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 0,
  400. rx_int_mix_mux_text);
  401. RX_MACRO_DAPM_ENUM(rx_int2_2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 0,
  402. rx_int_mix_mux_text);
  403. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 0,
  404. rx_prim_mix_text);
  405. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0, 4,
  406. rx_prim_mix_text);
  407. RX_MACRO_DAPM_ENUM(rx_int0_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1, 4,
  408. rx_prim_mix_text);
  409. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 0,
  410. rx_prim_mix_text);
  411. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0, 4,
  412. rx_prim_mix_text);
  413. RX_MACRO_DAPM_ENUM(rx_int1_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG1, 4,
  414. rx_prim_mix_text);
  415. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp0, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 0,
  416. rx_prim_mix_text);
  417. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp1, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG0, 4,
  418. rx_prim_mix_text);
  419. RX_MACRO_DAPM_ENUM(rx_int2_1_mix_inp2, BOLERO_CDC_RX_INP_MUX_RX_INT2_CFG1, 4,
  420. rx_prim_mix_text);
  421. RX_MACRO_DAPM_ENUM(rx_int0_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 2,
  422. rx_sidetone_mix_text);
  423. RX_MACRO_DAPM_ENUM(rx_int1_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 4,
  424. rx_sidetone_mix_text);
  425. RX_MACRO_DAPM_ENUM(rx_int2_mix2_inp, BOLERO_CDC_RX_INP_MUX_SIDETONE_SRC_CFG0, 6,
  426. rx_sidetone_mix_text);
  427. RX_MACRO_DAPM_ENUM(rx_mix_tx0, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 4,
  428. rx_echo_mux_text);
  429. RX_MACRO_DAPM_ENUM(rx_mix_tx1, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  430. rx_echo_mux_text);
  431. RX_MACRO_DAPM_ENUM(rx_mix_tx2, BOLERO_CDC_RX_INP_MUX_RX_MIX_CFG4, 0,
  432. rx_echo_mux_text);
  433. RX_MACRO_DAPM_ENUM(iir0_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG0, 0,
  434. iir_inp_mux_text);
  435. RX_MACRO_DAPM_ENUM(iir0_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG1, 0,
  436. iir_inp_mux_text);
  437. RX_MACRO_DAPM_ENUM(iir0_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG2, 0,
  438. iir_inp_mux_text);
  439. RX_MACRO_DAPM_ENUM(iir0_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR0_MIX_CFG3, 0,
  440. iir_inp_mux_text);
  441. RX_MACRO_DAPM_ENUM(iir1_inp0, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG0, 0,
  442. iir_inp_mux_text);
  443. RX_MACRO_DAPM_ENUM(iir1_inp1, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG1, 0,
  444. iir_inp_mux_text);
  445. RX_MACRO_DAPM_ENUM(iir1_inp2, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG2, 0,
  446. iir_inp_mux_text);
  447. RX_MACRO_DAPM_ENUM(iir1_inp3, BOLERO_CDC_RX_IIR_INP_MUX_IIR1_MIX_CFG3, 0,
  448. iir_inp_mux_text);
  449. RX_MACRO_DAPM_ENUM(rx_int0_1_interp, SND_SOC_NOPM, 0,
  450. rx_int0_1_interp_mux_text);
  451. RX_MACRO_DAPM_ENUM(rx_int1_1_interp, SND_SOC_NOPM, 0,
  452. rx_int1_1_interp_mux_text);
  453. RX_MACRO_DAPM_ENUM(rx_int2_1_interp, SND_SOC_NOPM, 0,
  454. rx_int2_1_interp_mux_text);
  455. RX_MACRO_DAPM_ENUM(rx_int0_2_interp, SND_SOC_NOPM, 0,
  456. rx_int0_2_interp_mux_text);
  457. RX_MACRO_DAPM_ENUM(rx_int1_2_interp, SND_SOC_NOPM, 0,
  458. rx_int1_2_interp_mux_text);
  459. RX_MACRO_DAPM_ENUM(rx_int2_2_interp, SND_SOC_NOPM, 0,
  460. rx_int2_2_interp_mux_text);
  461. RX_MACRO_DAPM_ENUM_EXT(rx_int0_dem_inp, BOLERO_CDC_RX_RX0_RX_PATH_CFG1, 0,
  462. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  463. rx_macro_int_dem_inp_mux_put);
  464. RX_MACRO_DAPM_ENUM_EXT(rx_int1_dem_inp, BOLERO_CDC_RX_RX1_RX_PATH_CFG1, 0,
  465. rx_int_dem_inp_mux_text, snd_soc_dapm_get_enum_double,
  466. rx_macro_int_dem_inp_mux_put);
  467. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx0, SND_SOC_NOPM, 0, rx_macro_mux_text,
  468. rx_macro_mux_get, rx_macro_mux_put);
  469. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx1, SND_SOC_NOPM, 0, rx_macro_mux_text,
  470. rx_macro_mux_get, rx_macro_mux_put);
  471. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx2, SND_SOC_NOPM, 0, rx_macro_mux_text,
  472. rx_macro_mux_get, rx_macro_mux_put);
  473. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx3, SND_SOC_NOPM, 0, rx_macro_mux_text,
  474. rx_macro_mux_get, rx_macro_mux_put);
  475. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx4, SND_SOC_NOPM, 0, rx_macro_mux_text,
  476. rx_macro_mux_get, rx_macro_mux_put);
  477. RX_MACRO_DAPM_ENUM_EXT(rx_macro_rx5, SND_SOC_NOPM, 0, rx_macro_mux_text,
  478. rx_macro_mux_get, rx_macro_mux_put);
  479. static struct snd_soc_dai_ops rx_macro_dai_ops = {
  480. .hw_params = rx_macro_hw_params,
  481. .get_channel_map = rx_macro_get_channel_map,
  482. };
  483. static struct snd_soc_dai_driver rx_macro_dai[] = {
  484. {
  485. .name = "rx_macro_rx1",
  486. .id = RX_MACRO_AIF1_PB,
  487. .playback = {
  488. .stream_name = "RX_MACRO_AIF1 Playback",
  489. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  490. .formats = RX_MACRO_FORMATS,
  491. .rate_max = 384000,
  492. .rate_min = 8000,
  493. .channels_min = 1,
  494. .channels_max = 2,
  495. },
  496. .ops = &rx_macro_dai_ops,
  497. },
  498. {
  499. .name = "rx_macro_rx2",
  500. .id = RX_MACRO_AIF2_PB,
  501. .playback = {
  502. .stream_name = "RX_MACRO_AIF2 Playback",
  503. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  504. .formats = RX_MACRO_FORMATS,
  505. .rate_max = 384000,
  506. .rate_min = 8000,
  507. .channels_min = 1,
  508. .channels_max = 2,
  509. },
  510. .ops = &rx_macro_dai_ops,
  511. },
  512. {
  513. .name = "rx_macro_rx3",
  514. .id = RX_MACRO_AIF3_PB,
  515. .playback = {
  516. .stream_name = "RX_MACRO_AIF3 Playback",
  517. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  518. .formats = RX_MACRO_FORMATS,
  519. .rate_max = 384000,
  520. .rate_min = 8000,
  521. .channels_min = 1,
  522. .channels_max = 2,
  523. },
  524. .ops = &rx_macro_dai_ops,
  525. },
  526. {
  527. .name = "rx_macro_rx4",
  528. .id = RX_MACRO_AIF4_PB,
  529. .playback = {
  530. .stream_name = "RX_MACRO_AIF4 Playback",
  531. .rates = RX_MACRO_RATES | RX_MACRO_FRAC_RATES,
  532. .formats = RX_MACRO_FORMATS,
  533. .rate_max = 384000,
  534. .rate_min = 8000,
  535. .channels_min = 1,
  536. .channels_max = 2,
  537. },
  538. .ops = &rx_macro_dai_ops,
  539. },
  540. };
  541. static int get_impedance_index(int imped)
  542. {
  543. int i = 0;
  544. if (imped < imped_index[i].imped_val) {
  545. pr_debug("%s, detected impedance is less than %d Ohm\n",
  546. __func__, imped_index[i].imped_val);
  547. i = 0;
  548. goto ret;
  549. }
  550. if (imped >= imped_index[ARRAY_SIZE(imped_index) - 1].imped_val) {
  551. pr_debug("%s, detected impedance is greater than %d Ohm\n",
  552. __func__,
  553. imped_index[ARRAY_SIZE(imped_index) - 1].imped_val);
  554. i = ARRAY_SIZE(imped_index) - 1;
  555. goto ret;
  556. }
  557. for (i = 0; i < ARRAY_SIZE(imped_index) - 1; i++) {
  558. if (imped >= imped_index[i].imped_val &&
  559. imped < imped_index[i + 1].imped_val)
  560. break;
  561. }
  562. ret:
  563. pr_debug("%s: selected impedance index = %d\n",
  564. __func__, imped_index[i].index);
  565. return imped_index[i].index;
  566. }
  567. /*
  568. * rx_macro_wcd_clsh_imped_config -
  569. * This function updates HPHL and HPHR gain settings
  570. * according to the impedance value.
  571. *
  572. * @codec: codec pointer handle
  573. * @imped: impedance value of HPHL/R
  574. * @reset: bool variable to reset registers when teardown
  575. */
  576. static void rx_macro_wcd_clsh_imped_config(struct snd_soc_codec *codec,
  577. int imped, bool reset)
  578. {
  579. int i;
  580. int index = 0;
  581. int table_size;
  582. static const struct rx_macro_reg_mask_val
  583. (*imped_table_ptr)[MAX_IMPED_PARAMS];
  584. table_size = ARRAY_SIZE(imped_table);
  585. imped_table_ptr = imped_table;
  586. /* reset = 1, which means request is to reset the register values */
  587. if (reset) {
  588. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  589. snd_soc_update_bits(codec,
  590. imped_table_ptr[index][i].reg,
  591. imped_table_ptr[index][i].mask, 0);
  592. return;
  593. }
  594. index = get_impedance_index(imped);
  595. if (index >= (ARRAY_SIZE(imped_index) - 1)) {
  596. pr_debug("%s, impedance not in range = %d\n", __func__, imped);
  597. return;
  598. }
  599. if (index >= table_size) {
  600. pr_debug("%s, impedance index not in range = %d\n", __func__,
  601. index);
  602. return;
  603. }
  604. for (i = 0; i < MAX_IMPED_PARAMS; i++)
  605. snd_soc_update_bits(codec,
  606. imped_table_ptr[index][i].reg,
  607. imped_table_ptr[index][i].mask,
  608. imped_table_ptr[index][i].val);
  609. }
  610. static bool rx_macro_get_data(struct snd_soc_codec *codec,
  611. struct device **rx_dev,
  612. struct rx_macro_priv **rx_priv,
  613. const char *func_name)
  614. {
  615. *rx_dev = bolero_get_device_ptr(codec->dev, RX_MACRO);
  616. if (!(*rx_dev)) {
  617. dev_err(codec->dev,
  618. "%s: null device for macro!\n", func_name);
  619. return false;
  620. }
  621. *rx_priv = dev_get_drvdata((*rx_dev));
  622. if (!(*rx_priv)) {
  623. dev_err(codec->dev,
  624. "%s: priv is null for macro!\n", func_name);
  625. return false;
  626. }
  627. if (!(*rx_priv)->codec) {
  628. dev_err(codec->dev,
  629. "%s: tx_priv codec is not initialized!\n", func_name);
  630. return false;
  631. }
  632. return true;
  633. }
  634. static int rx_macro_int_dem_inp_mux_put(struct snd_kcontrol *kcontrol,
  635. struct snd_ctl_elem_value *ucontrol)
  636. {
  637. struct snd_soc_dapm_widget *widget =
  638. snd_soc_dapm_kcontrol_widget(kcontrol);
  639. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  640. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  641. unsigned int val = 0;
  642. unsigned short look_ahead_dly_reg =
  643. BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  644. val = ucontrol->value.enumerated.item[0];
  645. if (val >= e->items)
  646. return -EINVAL;
  647. dev_dbg(codec->dev, "%s: wname: %s, val: 0x%x\n", __func__,
  648. widget->name, val);
  649. if (e->reg == BOLERO_CDC_RX_RX0_RX_PATH_CFG1)
  650. look_ahead_dly_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  651. else if (e->reg == BOLERO_CDC_RX_RX1_RX_PATH_CFG1)
  652. look_ahead_dly_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  653. /* Set Look Ahead Delay */
  654. snd_soc_update_bits(codec, look_ahead_dly_reg,
  655. 0x08, (val ? 0x08 : 0x00));
  656. /* Set DEM INP Select */
  657. return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  658. }
  659. static int rx_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  660. u8 rate_reg_val,
  661. u32 sample_rate)
  662. {
  663. u8 int_1_mix1_inp = 0;
  664. u32 j = 0, port = 0;
  665. u16 int_mux_cfg0 = 0, int_mux_cfg1 = 0;
  666. u16 int_fs_reg = 0;
  667. u8 int_mux_cfg0_val = 0, int_mux_cfg1_val = 0;
  668. u8 inp0_sel = 0, inp1_sel = 0, inp2_sel = 0;
  669. struct snd_soc_codec *codec = dai->codec;
  670. struct device *rx_dev = NULL;
  671. struct rx_macro_priv *rx_priv = NULL;
  672. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  673. return -EINVAL;
  674. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  675. RX_MACRO_PORTS_MAX) {
  676. int_1_mix1_inp = port;
  677. if ((int_1_mix1_inp < RX_MACRO_RX0) ||
  678. (int_1_mix1_inp > RX_MACRO_PORTS_MAX)) {
  679. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  680. __func__, dai->id);
  681. return -EINVAL;
  682. }
  683. int_mux_cfg0 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG0;
  684. /*
  685. * Loop through all interpolator MUX inputs and find out
  686. * to which interpolator input, the rx port
  687. * is connected
  688. */
  689. for (j = 0; j < INTERP_MAX; j++) {
  690. int_mux_cfg1 = int_mux_cfg0 + 4;
  691. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  692. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  693. inp0_sel = int_mux_cfg0_val & 0x07;
  694. inp1_sel = (int_mux_cfg0_val >> 4) & 0x038;
  695. inp2_sel = (int_mux_cfg1_val >> 4) & 0x038;
  696. if ((inp0_sel == int_1_mix1_inp) ||
  697. (inp1_sel == int_1_mix1_inp) ||
  698. (inp2_sel == int_1_mix1_inp)) {
  699. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  700. 0x80 * j;
  701. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  702. __func__, dai->id, j);
  703. pr_debug("%s: set INT%u_1 sample rate to %u\n",
  704. __func__, j, sample_rate);
  705. /* sample_rate is in Hz */
  706. snd_soc_update_bits(codec, int_fs_reg,
  707. 0x0F, rate_reg_val);
  708. }
  709. int_mux_cfg0 += 8;
  710. }
  711. }
  712. return 0;
  713. }
  714. static int rx_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  715. u8 rate_reg_val,
  716. u32 sample_rate)
  717. {
  718. u8 int_2_inp = 0;
  719. u32 j = 0, port = 0;
  720. u16 int_mux_cfg1 = 0, int_fs_reg = 0;
  721. u8 int_mux_cfg1_val = 0;
  722. struct snd_soc_codec *codec = dai->codec;
  723. struct device *rx_dev = NULL;
  724. struct rx_macro_priv *rx_priv = NULL;
  725. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  726. return -EINVAL;
  727. for_each_set_bit(port, &rx_priv->active_ch_mask[dai->id],
  728. RX_MACRO_PORTS_MAX) {
  729. int_2_inp = port;
  730. if ((int_2_inp < RX_MACRO_RX0) ||
  731. (int_2_inp > RX_MACRO_PORTS_MAX)) {
  732. pr_err("%s: Invalid RX port, Dai ID is %d\n",
  733. __func__, dai->id);
  734. return -EINVAL;
  735. }
  736. int_mux_cfg1 = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1;
  737. for (j = 0; j < INTERP_MAX; j++) {
  738. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  739. 0x07;
  740. if (int_mux_cfg1_val == int_2_inp) {
  741. int_fs_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  742. 0x80 * j;
  743. pr_debug("%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  744. __func__, dai->id, j);
  745. pr_debug("%s: set INT%u_2 sample rate to %u\n",
  746. __func__, j, sample_rate);
  747. snd_soc_update_bits(codec, int_fs_reg,
  748. 0x0F, rate_reg_val);
  749. }
  750. int_mux_cfg1 += 8;
  751. }
  752. }
  753. return 0;
  754. }
  755. static bool rx_macro_is_fractional_sample_rate(u32 sample_rate)
  756. {
  757. switch (sample_rate) {
  758. case SAMPLING_RATE_44P1KHZ:
  759. case SAMPLING_RATE_88P2KHZ:
  760. case SAMPLING_RATE_176P4KHZ:
  761. case SAMPLING_RATE_352P8KHZ:
  762. return true;
  763. default:
  764. return false;
  765. }
  766. return false;
  767. }
  768. static int rx_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  769. u32 sample_rate)
  770. {
  771. struct snd_soc_codec *codec = dai->codec;
  772. int rate_val = 0;
  773. int i = 0, ret = 0;
  774. struct device *rx_dev = NULL;
  775. struct rx_macro_priv *rx_priv = NULL;
  776. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  777. return -EINVAL;
  778. for (i = 0; i < ARRAY_SIZE(sr_val_tbl); i++) {
  779. if (sample_rate == sr_val_tbl[i].sample_rate) {
  780. rate_val = sr_val_tbl[i].rate_val;
  781. if (rx_macro_is_fractional_sample_rate(sample_rate))
  782. rx_priv->is_native_on = true;
  783. else
  784. rx_priv->is_native_on = false;
  785. break;
  786. }
  787. }
  788. if ((i == ARRAY_SIZE(sr_val_tbl)) || (rate_val < 0)) {
  789. dev_err(codec->dev, "%s: Unsupported sample rate: %d\n",
  790. __func__, sample_rate);
  791. return -EINVAL;
  792. }
  793. ret = rx_macro_set_prim_interpolator_rate(dai, (u8)rate_val, sample_rate);
  794. if (ret)
  795. return ret;
  796. ret = rx_macro_set_mix_interpolator_rate(dai, (u8)rate_val, sample_rate);
  797. if (ret)
  798. return ret;
  799. return ret;
  800. }
  801. static int rx_macro_hw_params(struct snd_pcm_substream *substream,
  802. struct snd_pcm_hw_params *params,
  803. struct snd_soc_dai *dai)
  804. {
  805. struct snd_soc_codec *codec = dai->codec;
  806. int ret = 0;
  807. struct device *rx_dev = NULL;
  808. struct rx_macro_priv *rx_priv = NULL;
  809. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  810. return -EINVAL;
  811. dev_dbg(codec->dev,
  812. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  813. dai->name, dai->id, params_rate(params),
  814. params_channels(params));
  815. switch (substream->stream) {
  816. case SNDRV_PCM_STREAM_PLAYBACK:
  817. ret = rx_macro_set_interpolator_rate(dai, params_rate(params));
  818. if (ret) {
  819. pr_err("%s: cannot set sample rate: %u\n",
  820. __func__, params_rate(params));
  821. return ret;
  822. }
  823. rx_priv->bit_width[dai->id] = params_width(params);
  824. break;
  825. case SNDRV_PCM_STREAM_CAPTURE:
  826. default:
  827. break;
  828. }
  829. return 0;
  830. }
  831. static int rx_macro_get_channel_map(struct snd_soc_dai *dai,
  832. unsigned int *tx_num, unsigned int *tx_slot,
  833. unsigned int *rx_num, unsigned int *rx_slot)
  834. {
  835. struct snd_soc_codec *codec = dai->codec;
  836. struct device *rx_dev = NULL;
  837. struct rx_macro_priv *rx_priv = NULL;
  838. unsigned int temp = 0, ch_mask = 0;
  839. u16 i = 0;
  840. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  841. return -EINVAL;
  842. switch (dai->id) {
  843. case RX_MACRO_AIF1_PB:
  844. case RX_MACRO_AIF2_PB:
  845. case RX_MACRO_AIF3_PB:
  846. case RX_MACRO_AIF4_PB:
  847. for_each_set_bit(temp, &rx_priv->active_ch_mask[dai->id],
  848. RX_MACRO_PORTS_MAX) {
  849. ch_mask |= (1 << i);
  850. if (++i == RX_MACRO_MAX_DMA_CH_PER_PORT)
  851. break;
  852. }
  853. *rx_slot = ch_mask;
  854. *rx_num = rx_priv->active_ch_cnt[dai->id];
  855. break;
  856. default:
  857. dev_err(rx_dev, "%s: Invalid AIF\n", __func__);
  858. break;
  859. }
  860. return 0;
  861. }
  862. static int rx_macro_mclk_enable(struct rx_macro_priv *rx_priv,
  863. bool mclk_enable, bool dapm)
  864. {
  865. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  866. int ret = 0, mclk_mux = MCLK_MUX0;
  867. if (regmap == NULL) {
  868. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  869. return -EINVAL;
  870. }
  871. dev_dbg(rx_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  872. __func__, mclk_enable, dapm, rx_priv->rx_mclk_users);
  873. mutex_lock(&rx_priv->mclk_lock);
  874. if (mclk_enable) {
  875. if (rx_priv->rx_mclk_users == 0) {
  876. if (rx_priv->is_native_on)
  877. mclk_mux = MCLK_MUX1;
  878. ret = bolero_request_clock(rx_priv->dev,
  879. RX_MACRO, mclk_mux, true);
  880. if (ret < 0) {
  881. dev_err(rx_priv->dev,
  882. "%s: rx request clock enable failed\n",
  883. __func__);
  884. goto exit;
  885. }
  886. rx_priv->mclk_mux = mclk_mux;
  887. regcache_mark_dirty(regmap);
  888. regcache_sync_region(regmap,
  889. RX_START_OFFSET,
  890. RX_MAX_OFFSET);
  891. regmap_update_bits(regmap,
  892. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  893. 0x01, 0x01);
  894. regmap_update_bits(regmap,
  895. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  896. 0x02, 0x02);
  897. regmap_update_bits(regmap,
  898. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  899. 0x01, 0x01);
  900. }
  901. rx_priv->rx_mclk_users++;
  902. } else {
  903. if (rx_priv->rx_mclk_users <= 0) {
  904. dev_err(rx_priv->dev, "%s: clock already disabled\n",
  905. __func__);
  906. rx_priv->rx_mclk_users = 0;
  907. goto exit;
  908. }
  909. rx_priv->rx_mclk_users--;
  910. if (rx_priv->rx_mclk_users == 0) {
  911. regmap_update_bits(regmap,
  912. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  913. 0x01, 0x00);
  914. regmap_update_bits(regmap,
  915. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  916. 0x01, 0x00);
  917. mclk_mux = rx_priv->mclk_mux;
  918. bolero_request_clock(rx_priv->dev,
  919. RX_MACRO, mclk_mux, false);
  920. rx_priv->mclk_mux = MCLK_MUX0;
  921. }
  922. }
  923. exit:
  924. mutex_unlock(&rx_priv->mclk_lock);
  925. return ret;
  926. }
  927. static int rx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  928. struct snd_kcontrol *kcontrol, int event)
  929. {
  930. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  931. int ret = 0;
  932. struct device *rx_dev = NULL;
  933. struct rx_macro_priv *rx_priv = NULL;
  934. int mclk_freq = MCLK_FREQ;
  935. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  936. return -EINVAL;
  937. dev_dbg(rx_dev, "%s: event = %d\n", __func__, event);
  938. switch (event) {
  939. case SND_SOC_DAPM_PRE_PMU:
  940. /* if swr_clk_users > 0, call device down */
  941. if (rx_priv->swr_clk_users > 0) {
  942. if ((rx_priv->mclk_mux == MCLK_MUX0 &&
  943. rx_priv->is_native_on) ||
  944. (rx_priv->mclk_mux == MCLK_MUX1 &&
  945. !rx_priv->is_native_on)) {
  946. swrm_wcd_notify(
  947. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  948. SWR_DEVICE_DOWN, NULL);
  949. }
  950. }
  951. if (rx_priv->is_native_on)
  952. mclk_freq = MCLK_FREQ_NATIVE;
  953. swrm_wcd_notify(
  954. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  955. SWR_CLK_FREQ, &mclk_freq);
  956. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  957. break;
  958. case SND_SOC_DAPM_POST_PMD:
  959. ret = rx_macro_mclk_enable(rx_priv, 0, true);
  960. break;
  961. default:
  962. dev_err(rx_priv->dev,
  963. "%s: invalid DAPM event %d\n", __func__, event);
  964. ret = -EINVAL;
  965. }
  966. return ret;
  967. }
  968. static int rx_macro_mclk_ctrl(struct device *dev, bool enable)
  969. {
  970. struct rx_macro_priv *rx_priv = dev_get_drvdata(dev);
  971. int ret = 0;
  972. if (enable) {
  973. ret = clk_prepare_enable(rx_priv->rx_core_clk);
  974. if (ret < 0) {
  975. dev_err(dev, "%s:rx mclk enable failed\n", __func__);
  976. return ret;
  977. }
  978. ret = clk_prepare_enable(rx_priv->rx_npl_clk);
  979. if (ret < 0) {
  980. clk_disable_unprepare(rx_priv->rx_core_clk);
  981. dev_err(dev, "%s:rx npl_clk enable failed\n",
  982. __func__);
  983. return ret;
  984. }
  985. if (rx_priv->rx_mclk_cnt++ == 0) {
  986. if (rx_priv->dev_up)
  987. iowrite32(0x1, rx_priv->rx_mclk_mode_muxsel);
  988. }
  989. } else {
  990. if (rx_priv->rx_mclk_cnt <= 0) {
  991. dev_dbg(dev, "%s:rx mclk already disabled\n", __func__);
  992. rx_priv->rx_mclk_cnt = 0;
  993. return 0;
  994. }
  995. if (--rx_priv->rx_mclk_cnt == 0) {
  996. if (rx_priv->dev_up)
  997. iowrite32(0x0, rx_priv->rx_mclk_mode_muxsel);
  998. }
  999. clk_disable_unprepare(rx_priv->rx_npl_clk);
  1000. clk_disable_unprepare(rx_priv->rx_core_clk);
  1001. }
  1002. return 0;
  1003. }
  1004. static int rx_macro_event_handler(struct snd_soc_codec *codec, u16 event,
  1005. u32 data)
  1006. {
  1007. u16 reg = 0, reg_mix = 0, rx_idx = 0, mute = 0x0;
  1008. struct device *rx_dev = NULL;
  1009. struct rx_macro_priv *rx_priv = NULL;
  1010. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1011. return -EINVAL;
  1012. switch (event) {
  1013. case BOLERO_MACRO_EVT_RX_MUTE:
  1014. rx_idx = data >> 0x10;
  1015. mute = data & 0xffff;
  1016. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (rx_idx *
  1017. RX_MACRO_RX_PATH_OFFSET);
  1018. reg_mix = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL + (rx_idx *
  1019. RX_MACRO_RX_PATH_OFFSET);
  1020. snd_soc_update_bits(codec, reg, 0x10, mute << 0x10);
  1021. snd_soc_update_bits(codec, reg_mix, 0x10, mute << 0x10);
  1022. break;
  1023. case BOLERO_MACRO_EVT_IMPED_TRUE:
  1024. rx_macro_wcd_clsh_imped_config(codec, data, true);
  1025. break;
  1026. case BOLERO_MACRO_EVT_IMPED_FALSE:
  1027. rx_macro_wcd_clsh_imped_config(codec, data, false);
  1028. break;
  1029. case BOLERO_MACRO_EVT_SSR_DOWN:
  1030. rx_priv->dev_up = false;
  1031. swrm_wcd_notify(
  1032. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1033. SWR_DEVICE_SSR_DOWN, NULL);
  1034. swrm_wcd_notify(
  1035. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1036. SWR_DEVICE_DOWN, NULL);
  1037. break;
  1038. case BOLERO_MACRO_EVT_SSR_UP:
  1039. rx_priv->dev_up = true;
  1040. /* enable&disable MCLK_MUX1 to reset GFMUX reg */
  1041. bolero_request_clock(rx_priv->dev,
  1042. RX_MACRO, MCLK_MUX1, true);
  1043. bolero_request_clock(rx_priv->dev,
  1044. RX_MACRO, MCLK_MUX1, false);
  1045. swrm_wcd_notify(
  1046. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  1047. SWR_DEVICE_SSR_UP, NULL);
  1048. break;
  1049. }
  1050. return 0;
  1051. }
  1052. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  1053. struct rx_macro_priv *rx_priv)
  1054. {
  1055. int i = 0;
  1056. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  1057. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  1058. return i;
  1059. }
  1060. return -EINVAL;
  1061. }
  1062. static int rx_macro_set_idle_detect_thr(struct snd_soc_codec *codec,
  1063. struct rx_macro_priv *rx_priv,
  1064. int interp, int path_type)
  1065. {
  1066. int port_id[4] = { 0, 0, 0, 0 };
  1067. int *port_ptr = NULL;
  1068. int num_ports = 0;
  1069. int bit_width = 0, i = 0;
  1070. int mux_reg = 0, mux_reg_val = 0;
  1071. int dai_id = 0, idle_thr = 0;
  1072. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  1073. return 0;
  1074. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1075. return 0;
  1076. port_ptr = &port_id[0];
  1077. num_ports = 0;
  1078. /*
  1079. * Read interpolator MUX input registers and find
  1080. * which cdc_dma port is connected and store the port
  1081. * numbers in port_id array.
  1082. */
  1083. if (path_type == INTERP_MIX_PATH) {
  1084. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  1085. 2 * interp;
  1086. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  1087. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  1088. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  1089. *port_ptr++ = mux_reg_val - 1;
  1090. num_ports++;
  1091. }
  1092. }
  1093. if (path_type == INTERP_MAIN_PATH) {
  1094. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  1095. 2 * (interp - 1);
  1096. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  1097. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  1098. while (i) {
  1099. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  1100. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  1101. *port_ptr++ = mux_reg_val -
  1102. INTn_1_INP_SEL_RX0;
  1103. num_ports++;
  1104. }
  1105. mux_reg_val = (snd_soc_read(codec, mux_reg) &
  1106. 0xf0) >> 4;
  1107. mux_reg += 1;
  1108. i--;
  1109. }
  1110. }
  1111. dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  1112. __func__, num_ports, port_id[0], port_id[1],
  1113. port_id[2], port_id[3]);
  1114. i = 0;
  1115. while (num_ports) {
  1116. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  1117. rx_priv);
  1118. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  1119. dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n",
  1120. __func__, dai_id,
  1121. rx_priv->bit_width[dai_id]);
  1122. if (rx_priv->bit_width[dai_id] > bit_width)
  1123. bit_width = rx_priv->bit_width[dai_id];
  1124. }
  1125. num_ports--;
  1126. }
  1127. switch (bit_width) {
  1128. case 16:
  1129. idle_thr = 0xff; /* F16 */
  1130. break;
  1131. case 24:
  1132. case 32:
  1133. idle_thr = 0x03; /* F22 */
  1134. break;
  1135. default:
  1136. idle_thr = 0x00;
  1137. break;
  1138. }
  1139. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  1140. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  1141. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  1142. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  1143. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  1144. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  1145. }
  1146. return 0;
  1147. }
  1148. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  1149. struct snd_kcontrol *kcontrol, int event)
  1150. {
  1151. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1152. u16 gain_reg = 0, mix_reg = 0;
  1153. struct device *rx_dev = NULL;
  1154. struct rx_macro_priv *rx_priv = NULL;
  1155. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1156. return -EINVAL;
  1157. if (w->shift >= INTERP_MAX) {
  1158. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1159. __func__, w->shift, w->name);
  1160. return -EINVAL;
  1161. }
  1162. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  1163. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1164. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  1165. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  1166. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1167. switch (event) {
  1168. case SND_SOC_DAPM_PRE_PMU:
  1169. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  1170. INTERP_MIX_PATH);
  1171. rx_macro_enable_interp_clk(codec, event, w->shift);
  1172. /* Clk enable */
  1173. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  1174. break;
  1175. case SND_SOC_DAPM_POST_PMU:
  1176. snd_soc_write(codec, gain_reg,
  1177. snd_soc_read(codec, gain_reg));
  1178. break;
  1179. case SND_SOC_DAPM_POST_PMD:
  1180. /* Clk Disable */
  1181. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  1182. rx_macro_enable_interp_clk(codec, event, w->shift);
  1183. /* Reset enable and disable */
  1184. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  1185. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  1186. break;
  1187. }
  1188. return 0;
  1189. }
  1190. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  1191. struct snd_kcontrol *kcontrol,
  1192. int event)
  1193. {
  1194. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1195. u16 gain_reg = 0;
  1196. u16 reg = 0;
  1197. struct device *rx_dev = NULL;
  1198. struct rx_macro_priv *rx_priv = NULL;
  1199. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1200. return -EINVAL;
  1201. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1202. if (w->shift >= INTERP_MAX) {
  1203. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  1204. __func__, w->shift, w->name);
  1205. return -EINVAL;
  1206. }
  1207. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  1208. RX_MACRO_RX_PATH_OFFSET);
  1209. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  1210. RX_MACRO_RX_PATH_OFFSET);
  1211. switch (event) {
  1212. case SND_SOC_DAPM_PRE_PMU:
  1213. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  1214. INTERP_MAIN_PATH);
  1215. rx_macro_enable_interp_clk(codec, event, w->shift);
  1216. break;
  1217. case SND_SOC_DAPM_POST_PMU:
  1218. snd_soc_write(codec, gain_reg,
  1219. snd_soc_read(codec, gain_reg));
  1220. break;
  1221. case SND_SOC_DAPM_POST_PMD:
  1222. rx_macro_enable_interp_clk(codec, event, w->shift);
  1223. break;
  1224. }
  1225. return 0;
  1226. }
  1227. static int rx_macro_config_compander(struct snd_soc_codec *codec,
  1228. struct rx_macro_priv *rx_priv,
  1229. int interp_n, int event)
  1230. {
  1231. int comp = 0;
  1232. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  1233. /* AUX does not have compander */
  1234. if (interp_n == INTERP_AUX)
  1235. return 0;
  1236. comp = interp_n;
  1237. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  1238. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  1239. if (!rx_priv->comp_enabled[comp])
  1240. return 0;
  1241. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1242. (comp * RX_MACRO_COMP_OFFSET);
  1243. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  1244. (comp * RX_MACRO_RX_PATH_OFFSET);
  1245. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1246. /* Enable Compander Clock */
  1247. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  1248. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1249. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1250. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  1251. }
  1252. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1253. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  1254. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  1255. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1256. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1257. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  1258. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  1259. }
  1260. return 0;
  1261. }
  1262. static void rx_macro_enable_softclip_clk(struct snd_soc_codec *codec,
  1263. struct rx_macro_priv *rx_priv,
  1264. bool enable)
  1265. {
  1266. if (enable) {
  1267. if (rx_priv->softclip_clk_users == 0)
  1268. snd_soc_update_bits(codec,
  1269. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1270. 0x01, 0x01);
  1271. rx_priv->softclip_clk_users++;
  1272. } else {
  1273. rx_priv->softclip_clk_users--;
  1274. if (rx_priv->softclip_clk_users == 0)
  1275. snd_soc_update_bits(codec,
  1276. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1277. 0x01, 0x00);
  1278. }
  1279. }
  1280. static int rx_macro_config_softclip(struct snd_soc_codec *codec,
  1281. struct rx_macro_priv *rx_priv,
  1282. int event)
  1283. {
  1284. dev_dbg(codec->dev, "%s: event %d, enabled %d\n",
  1285. __func__, event, rx_priv->is_softclip_on);
  1286. if (!rx_priv->is_softclip_on)
  1287. return 0;
  1288. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1289. /* Enable Softclip clock */
  1290. rx_macro_enable_softclip_clk(codec, rx_priv, true);
  1291. /* Enable Softclip control */
  1292. snd_soc_update_bits(codec,
  1293. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x01);
  1294. }
  1295. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1296. snd_soc_update_bits(codec,
  1297. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x00);
  1298. rx_macro_enable_softclip_clk(codec, rx_priv, false);
  1299. }
  1300. return 0;
  1301. }
  1302. static inline void
  1303. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  1304. {
  1305. if ((enable && ++rx_priv->clsh_users == 1) ||
  1306. (!enable && --rx_priv->clsh_users == 0))
  1307. snd_soc_update_bits(rx_priv->codec,
  1308. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  1309. (u8) enable);
  1310. if (rx_priv->clsh_users < 0)
  1311. rx_priv->clsh_users = 0;
  1312. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1313. rx_priv->clsh_users, enable);
  1314. }
  1315. static int rx_macro_config_classh(struct snd_soc_codec *codec,
  1316. struct rx_macro_priv *rx_priv,
  1317. int interp_n, int event)
  1318. {
  1319. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1320. rx_macro_enable_clsh_block(rx_priv, false);
  1321. return 0;
  1322. }
  1323. if (!SND_SOC_DAPM_EVENT_ON(event))
  1324. return 0;
  1325. rx_macro_enable_clsh_block(rx_priv, true);
  1326. if (interp_n == INTERP_HPHL ||
  1327. interp_n == INTERP_HPHR) {
  1328. /*
  1329. * These K1 values depend on the Headphone Impedance
  1330. * For now it is assumed to be 16 ohm
  1331. */
  1332. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_LSB,
  1333. 0xFF, 0xC0);
  1334. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_MSB,
  1335. 0x0F, 0x00);
  1336. }
  1337. switch (interp_n) {
  1338. case INTERP_HPHL:
  1339. if (rx_priv->is_ear_mode_on)
  1340. snd_soc_update_bits(codec,
  1341. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1342. 0x3F, 0x39);
  1343. else
  1344. snd_soc_update_bits(codec,
  1345. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1346. 0x3F, 0x1C);
  1347. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1348. 0x07, 0x00);
  1349. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1350. 0x40, 0x40);
  1351. break;
  1352. case INTERP_HPHR:
  1353. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1354. 0x3F, 0x1C);
  1355. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1356. 0x07, 0x00);
  1357. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1358. 0x40, 0x40);
  1359. break;
  1360. case INTERP_AUX:
  1361. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1362. 0x10, 0x10);
  1363. break;
  1364. }
  1365. return 0;
  1366. }
  1367. static void rx_macro_hd2_control(struct snd_soc_codec *codec,
  1368. u16 interp_idx, int event)
  1369. {
  1370. u16 hd2_scale_reg = 0;
  1371. u16 hd2_enable_reg = 0;
  1372. switch (interp_idx) {
  1373. case INTERP_HPHL:
  1374. hd2_scale_reg = BOLERO_CDC_RX_RX0_RX_PATH_SEC3;
  1375. hd2_enable_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0;
  1376. break;
  1377. case INTERP_HPHR:
  1378. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1379. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1380. break;
  1381. }
  1382. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1383. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14);
  1384. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  1385. }
  1386. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1387. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  1388. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  1389. }
  1390. }
  1391. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1392. struct snd_ctl_elem_value *ucontrol)
  1393. {
  1394. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1395. int comp = ((struct soc_multi_mixer_control *)
  1396. kcontrol->private_value)->shift;
  1397. struct device *rx_dev = NULL;
  1398. struct rx_macro_priv *rx_priv = NULL;
  1399. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1400. return -EINVAL;
  1401. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1402. return 0;
  1403. }
  1404. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1405. struct snd_ctl_elem_value *ucontrol)
  1406. {
  1407. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1408. int comp = ((struct soc_multi_mixer_control *)
  1409. kcontrol->private_value)->shift;
  1410. int value = ucontrol->value.integer.value[0];
  1411. struct device *rx_dev = NULL;
  1412. struct rx_macro_priv *rx_priv = NULL;
  1413. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1414. return -EINVAL;
  1415. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  1416. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1417. rx_priv->comp_enabled[comp] = value;
  1418. return 0;
  1419. }
  1420. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1421. struct snd_ctl_elem_value *ucontrol)
  1422. {
  1423. struct snd_soc_dapm_widget *widget =
  1424. snd_soc_dapm_kcontrol_widget(kcontrol);
  1425. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1426. struct device *rx_dev = NULL;
  1427. struct rx_macro_priv *rx_priv = NULL;
  1428. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1429. return -EINVAL;
  1430. ucontrol->value.integer.value[0] =
  1431. rx_priv->rx_port_value[widget->shift];
  1432. return 0;
  1433. }
  1434. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1435. struct snd_ctl_elem_value *ucontrol)
  1436. {
  1437. struct snd_soc_dapm_widget *widget =
  1438. snd_soc_dapm_kcontrol_widget(kcontrol);
  1439. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1440. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1441. struct snd_soc_dapm_update *update = NULL;
  1442. u32 rx_port_value = ucontrol->value.integer.value[0];
  1443. u32 aif_rst = 0;
  1444. struct device *rx_dev = NULL;
  1445. struct rx_macro_priv *rx_priv = NULL;
  1446. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1447. return -EINVAL;
  1448. aif_rst = rx_priv->rx_port_value[widget->shift];
  1449. if (!rx_port_value) {
  1450. if (aif_rst == 0) {
  1451. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1452. return 0;
  1453. }
  1454. }
  1455. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1456. switch (rx_port_value) {
  1457. case 0:
  1458. clear_bit(widget->shift,
  1459. &rx_priv->active_ch_mask[aif_rst]);
  1460. rx_priv->active_ch_cnt[aif_rst]--;
  1461. break;
  1462. case 1:
  1463. case 2:
  1464. case 3:
  1465. case 4:
  1466. set_bit(widget->shift,
  1467. &rx_priv->active_ch_mask[rx_port_value]);
  1468. rx_priv->active_ch_cnt[rx_port_value]++;
  1469. break;
  1470. default:
  1471. dev_err(codec->dev,
  1472. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1473. goto err;
  1474. }
  1475. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1476. rx_port_value, e, update);
  1477. return 0;
  1478. err:
  1479. return -EINVAL;
  1480. }
  1481. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1482. struct snd_ctl_elem_value *ucontrol)
  1483. {
  1484. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1485. struct device *rx_dev = NULL;
  1486. struct rx_macro_priv *rx_priv = NULL;
  1487. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1488. return -EINVAL;
  1489. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1490. return 0;
  1491. }
  1492. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1493. struct snd_ctl_elem_value *ucontrol)
  1494. {
  1495. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1496. struct device *rx_dev = NULL;
  1497. struct rx_macro_priv *rx_priv = NULL;
  1498. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1499. return -EINVAL;
  1500. rx_priv->is_ear_mode_on =
  1501. (!ucontrol->value.integer.value[0] ? false : true);
  1502. return 0;
  1503. }
  1504. static int rx_macro_get_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1505. struct snd_ctl_elem_value *ucontrol)
  1506. {
  1507. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1508. struct device *rx_dev = NULL;
  1509. struct rx_macro_priv *rx_priv = NULL;
  1510. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1511. return -EINVAL;
  1512. ucontrol->value.integer.value[0] = rx_priv->hph_hd2_mode;
  1513. return 0;
  1514. }
  1515. static int rx_macro_put_hph_hd2_mode(struct snd_kcontrol *kcontrol,
  1516. struct snd_ctl_elem_value *ucontrol)
  1517. {
  1518. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1519. struct device *rx_dev = NULL;
  1520. struct rx_macro_priv *rx_priv = NULL;
  1521. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1522. return -EINVAL;
  1523. rx_priv->hph_hd2_mode = ucontrol->value.integer.value[0];
  1524. return 0;
  1525. }
  1526. static int rx_macro_get_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1527. struct snd_ctl_elem_value *ucontrol)
  1528. {
  1529. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1530. struct device *rx_dev = NULL;
  1531. struct rx_macro_priv *rx_priv = NULL;
  1532. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1533. return -EINVAL;
  1534. ucontrol->value.integer.value[0] = rx_priv->hph_pwr_mode;
  1535. return 0;
  1536. }
  1537. static int rx_macro_put_hph_pwr_mode(struct snd_kcontrol *kcontrol,
  1538. struct snd_ctl_elem_value *ucontrol)
  1539. {
  1540. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1541. struct device *rx_dev = NULL;
  1542. struct rx_macro_priv *rx_priv = NULL;
  1543. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1544. return -EINVAL;
  1545. rx_priv->hph_pwr_mode = ucontrol->value.integer.value[0];
  1546. return 0;
  1547. }
  1548. static int rx_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1549. struct snd_ctl_elem_value *ucontrol)
  1550. {
  1551. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1552. ucontrol->value.integer.value[0] =
  1553. ((snd_soc_read(codec, BOLERO_CDC_RX_BCL_VBAT_CFG) & 0x04) ?
  1554. 1 : 0);
  1555. dev_dbg(codec->dev, "%s: value: %lu\n", __func__,
  1556. ucontrol->value.integer.value[0]);
  1557. return 0;
  1558. }
  1559. static int rx_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1560. struct snd_ctl_elem_value *ucontrol)
  1561. {
  1562. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1563. dev_dbg(codec->dev, "%s: value: %lu\n", __func__,
  1564. ucontrol->value.integer.value[0]);
  1565. /* Set Vbat register configuration for GSM mode bit based on value */
  1566. if (ucontrol->value.integer.value[0])
  1567. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1568. 0x04, 0x04);
  1569. else
  1570. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1571. 0x04, 0x00);
  1572. return 0;
  1573. }
  1574. static int rx_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1575. struct snd_ctl_elem_value *ucontrol)
  1576. {
  1577. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1578. struct device *rx_dev = NULL;
  1579. struct rx_macro_priv *rx_priv = NULL;
  1580. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1581. return -EINVAL;
  1582. ucontrol->value.integer.value[0] = rx_priv->is_softclip_on;
  1583. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1584. __func__, ucontrol->value.integer.value[0]);
  1585. return 0;
  1586. }
  1587. static int rx_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1588. struct snd_ctl_elem_value *ucontrol)
  1589. {
  1590. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1591. struct device *rx_dev = NULL;
  1592. struct rx_macro_priv *rx_priv = NULL;
  1593. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1594. return -EINVAL;
  1595. rx_priv->is_softclip_on = ucontrol->value.integer.value[0];
  1596. dev_dbg(codec->dev, "%s: soft clip enable = %d\n", __func__,
  1597. rx_priv->is_softclip_on);
  1598. return 0;
  1599. }
  1600. static int rx_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1601. struct snd_kcontrol *kcontrol,
  1602. int event)
  1603. {
  1604. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1605. struct device *rx_dev = NULL;
  1606. struct rx_macro_priv *rx_priv = NULL;
  1607. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1608. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1609. return -EINVAL;
  1610. switch (event) {
  1611. case SND_SOC_DAPM_PRE_PMU:
  1612. /* Enable clock for VBAT block */
  1613. snd_soc_update_bits(codec,
  1614. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1615. /* Enable VBAT block */
  1616. snd_soc_update_bits(codec,
  1617. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x01);
  1618. /* Update interpolator with 384K path */
  1619. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1620. 0x80, 0x80);
  1621. /* Update DSM FS rate */
  1622. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1623. 0x02, 0x02);
  1624. /* Use attenuation mode */
  1625. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1626. 0x02, 0x00);
  1627. /* BCL block needs softclip clock to be enabled */
  1628. rx_macro_enable_softclip_clk(codec, rx_priv, true);
  1629. /* Enable VBAT at channel level */
  1630. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1631. 0x02, 0x02);
  1632. /* Set the ATTK1 gain */
  1633. snd_soc_update_bits(codec,
  1634. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1635. 0xFF, 0xFF);
  1636. snd_soc_update_bits(codec,
  1637. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1638. 0xFF, 0x03);
  1639. snd_soc_update_bits(codec,
  1640. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1641. 0xFF, 0x00);
  1642. /* Set the ATTK2 gain */
  1643. snd_soc_update_bits(codec,
  1644. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1645. 0xFF, 0xFF);
  1646. snd_soc_update_bits(codec,
  1647. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1648. 0xFF, 0x03);
  1649. snd_soc_update_bits(codec,
  1650. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1651. 0xFF, 0x00);
  1652. /* Set the ATTK3 gain */
  1653. snd_soc_update_bits(codec,
  1654. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1655. 0xFF, 0xFF);
  1656. snd_soc_update_bits(codec,
  1657. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1658. 0xFF, 0x03);
  1659. snd_soc_update_bits(codec,
  1660. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1661. 0xFF, 0x00);
  1662. break;
  1663. case SND_SOC_DAPM_POST_PMD:
  1664. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1665. 0x80, 0x00);
  1666. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1667. 0x02, 0x00);
  1668. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1669. 0x02, 0x02);
  1670. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1671. 0x02, 0x00);
  1672. snd_soc_update_bits(codec,
  1673. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1674. 0xFF, 0x00);
  1675. snd_soc_update_bits(codec,
  1676. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1677. 0xFF, 0x00);
  1678. snd_soc_update_bits(codec,
  1679. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1680. 0xFF, 0x00);
  1681. snd_soc_update_bits(codec,
  1682. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1683. 0xFF, 0x00);
  1684. snd_soc_update_bits(codec,
  1685. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1686. 0xFF, 0x00);
  1687. snd_soc_update_bits(codec,
  1688. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1689. 0xFF, 0x00);
  1690. snd_soc_update_bits(codec,
  1691. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1692. 0xFF, 0x00);
  1693. snd_soc_update_bits(codec,
  1694. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1695. 0xFF, 0x00);
  1696. snd_soc_update_bits(codec,
  1697. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1698. 0xFF, 0x00);
  1699. rx_macro_enable_softclip_clk(codec, rx_priv, false);
  1700. snd_soc_update_bits(codec,
  1701. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x00);
  1702. snd_soc_update_bits(codec,
  1703. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1704. break;
  1705. default:
  1706. dev_err(rx_dev, "%s: Invalid event %d\n", __func__, event);
  1707. break;
  1708. }
  1709. return 0;
  1710. }
  1711. static void rx_macro_idle_detect_control(struct snd_soc_codec *codec,
  1712. struct rx_macro_priv *rx_priv,
  1713. int interp, int event)
  1714. {
  1715. int reg = 0, mask = 0, val = 0;
  1716. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1717. return;
  1718. if (interp == INTERP_HPHL) {
  1719. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1720. mask = 0x01;
  1721. val = 0x01;
  1722. }
  1723. if (interp == INTERP_HPHR) {
  1724. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1725. mask = 0x02;
  1726. val = 0x02;
  1727. }
  1728. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1729. snd_soc_update_bits(codec, reg, mask, val);
  1730. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1731. snd_soc_update_bits(codec, reg, mask, 0x00);
  1732. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1733. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1734. }
  1735. }
  1736. static void rx_macro_hphdelay_lutbypass(struct snd_soc_codec *codec,
  1737. struct rx_macro_priv *rx_priv,
  1738. u16 interp_idx, int event)
  1739. {
  1740. u16 hph_lut_bypass_reg = 0;
  1741. u16 hph_comp_ctrl7 = 0;
  1742. switch (interp_idx) {
  1743. case INTERP_HPHL:
  1744. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1745. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1746. break;
  1747. case INTERP_HPHR:
  1748. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1749. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1750. break;
  1751. default:
  1752. break;
  1753. }
  1754. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1755. if (interp_idx == INTERP_HPHL) {
  1756. if (rx_priv->is_ear_mode_on)
  1757. snd_soc_update_bits(codec,
  1758. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1759. 0x02, 0x02);
  1760. else
  1761. snd_soc_update_bits(codec,
  1762. hph_lut_bypass_reg,
  1763. 0x80, 0x80);
  1764. } else {
  1765. snd_soc_update_bits(codec,
  1766. hph_lut_bypass_reg,
  1767. 0x80, 0x80);
  1768. }
  1769. if (rx_priv->hph_pwr_mode)
  1770. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x00);
  1771. }
  1772. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1773. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1774. 0x02, 0x00);
  1775. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  1776. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x20);
  1777. }
  1778. }
  1779. static int rx_macro_enable_interp_clk(struct snd_soc_codec *codec,
  1780. int event, int interp_idx)
  1781. {
  1782. u16 main_reg = 0;
  1783. struct device *rx_dev = NULL;
  1784. struct rx_macro_priv *rx_priv = NULL;
  1785. if (!codec) {
  1786. pr_err("%s: codec is NULL\n", __func__);
  1787. return -EINVAL;
  1788. }
  1789. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1790. return -EINVAL;
  1791. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1792. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1793. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1794. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1795. /* Main path PGA mute enable */
  1796. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  1797. /* Clk enable */
  1798. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  1799. rx_macro_idle_detect_control(codec, rx_priv,
  1800. interp_idx, event);
  1801. if (rx_priv->hph_hd2_mode)
  1802. rx_macro_hd2_control(codec, interp_idx, event);
  1803. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1804. event);
  1805. rx_macro_config_compander(codec, rx_priv,
  1806. interp_idx, event);
  1807. if (interp_idx == INTERP_AUX)
  1808. rx_macro_config_softclip(codec, rx_priv,
  1809. event);
  1810. rx_macro_config_classh(codec, rx_priv,
  1811. interp_idx, event);
  1812. }
  1813. rx_priv->main_clk_users[interp_idx]++;
  1814. }
  1815. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1816. rx_priv->main_clk_users[interp_idx]--;
  1817. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  1818. rx_priv->main_clk_users[interp_idx] = 0;
  1819. rx_macro_config_classh(codec, rx_priv,
  1820. interp_idx, event);
  1821. rx_macro_config_compander(codec, rx_priv,
  1822. interp_idx, event);
  1823. if (interp_idx == INTERP_AUX)
  1824. rx_macro_config_softclip(codec, rx_priv,
  1825. event);
  1826. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1827. event);
  1828. if (rx_priv->hph_hd2_mode)
  1829. rx_macro_hd2_control(codec, interp_idx, event);
  1830. rx_macro_idle_detect_control(codec, rx_priv,
  1831. interp_idx, event);
  1832. /* Clk Disable */
  1833. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  1834. /* Reset enable and disable */
  1835. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  1836. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  1837. /* Reset rate to 48K*/
  1838. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  1839. }
  1840. }
  1841. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  1842. __func__, event, rx_priv->main_clk_users[interp_idx]);
  1843. return rx_priv->main_clk_users[interp_idx];
  1844. }
  1845. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  1846. struct snd_kcontrol *kcontrol, int event)
  1847. {
  1848. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1849. u16 sidetone_reg = 0;
  1850. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  1851. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  1852. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  1853. switch (event) {
  1854. case SND_SOC_DAPM_PRE_PMU:
  1855. rx_macro_enable_interp_clk(codec, event, w->shift);
  1856. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  1857. break;
  1858. case SND_SOC_DAPM_POST_PMD:
  1859. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  1860. rx_macro_enable_interp_clk(codec, event, w->shift);
  1861. break;
  1862. default:
  1863. break;
  1864. };
  1865. return 0;
  1866. }
  1867. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  1868. int band_idx)
  1869. {
  1870. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  1871. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  1872. if (regmap == NULL) {
  1873. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  1874. return;
  1875. }
  1876. regmap_write(regmap,
  1877. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1878. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  1879. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  1880. /* 5 coefficients per band and 4 writes per coefficient */
  1881. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  1882. coeff_idx++) {
  1883. /* Four 8 bit values(one 32 bit) per coefficient */
  1884. regmap_write(regmap, reg_add,
  1885. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1886. regmap_write(regmap, reg_add,
  1887. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1888. regmap_write(regmap, reg_add,
  1889. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1890. regmap_write(regmap, reg_add,
  1891. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1892. }
  1893. }
  1894. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1895. struct snd_ctl_elem_value *ucontrol)
  1896. {
  1897. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1898. int iir_idx = ((struct soc_multi_mixer_control *)
  1899. kcontrol->private_value)->reg;
  1900. int band_idx = ((struct soc_multi_mixer_control *)
  1901. kcontrol->private_value)->shift;
  1902. /* IIR filter band registers are at integer multiples of 0x80 */
  1903. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1904. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  1905. (1 << band_idx)) != 0;
  1906. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1907. iir_idx, band_idx,
  1908. (uint32_t)ucontrol->value.integer.value[0]);
  1909. return 0;
  1910. }
  1911. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  1912. struct snd_ctl_elem_value *ucontrol)
  1913. {
  1914. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1915. int iir_idx = ((struct soc_multi_mixer_control *)
  1916. kcontrol->private_value)->reg;
  1917. int band_idx = ((struct soc_multi_mixer_control *)
  1918. kcontrol->private_value)->shift;
  1919. bool iir_band_en_status = 0;
  1920. int value = ucontrol->value.integer.value[0];
  1921. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1922. struct device *rx_dev = NULL;
  1923. struct rx_macro_priv *rx_priv = NULL;
  1924. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1925. return -EINVAL;
  1926. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  1927. /* Mask first 5 bits, 6-8 are reserved */
  1928. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  1929. (value << band_idx));
  1930. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  1931. (1 << band_idx)) != 0);
  1932. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1933. iir_idx, band_idx, iir_band_en_status);
  1934. return 0;
  1935. }
  1936. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  1937. int iir_idx, int band_idx,
  1938. int coeff_idx)
  1939. {
  1940. uint32_t value = 0;
  1941. /* Address does not automatically update if reading */
  1942. snd_soc_write(codec,
  1943. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1944. ((band_idx * BAND_MAX + coeff_idx)
  1945. * sizeof(uint32_t)) & 0x7F);
  1946. value |= snd_soc_read(codec,
  1947. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  1948. snd_soc_write(codec,
  1949. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1950. ((band_idx * BAND_MAX + coeff_idx)
  1951. * sizeof(uint32_t) + 1) & 0x7F);
  1952. value |= (snd_soc_read(codec,
  1953. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1954. 0x80 * iir_idx)) << 8);
  1955. snd_soc_write(codec,
  1956. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1957. ((band_idx * BAND_MAX + coeff_idx)
  1958. * sizeof(uint32_t) + 2) & 0x7F);
  1959. value |= (snd_soc_read(codec,
  1960. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1961. 0x80 * iir_idx)) << 16);
  1962. snd_soc_write(codec,
  1963. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1964. ((band_idx * BAND_MAX + coeff_idx)
  1965. * sizeof(uint32_t) + 3) & 0x7F);
  1966. /* Mask bits top 2 bits since they are reserved */
  1967. value |= ((snd_soc_read(codec,
  1968. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1969. 16 * iir_idx)) & 0x3F) << 24);
  1970. return value;
  1971. }
  1972. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1973. struct snd_ctl_elem_value *ucontrol)
  1974. {
  1975. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1976. int iir_idx = ((struct soc_multi_mixer_control *)
  1977. kcontrol->private_value)->reg;
  1978. int band_idx = ((struct soc_multi_mixer_control *)
  1979. kcontrol->private_value)->shift;
  1980. ucontrol->value.integer.value[0] =
  1981. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  1982. ucontrol->value.integer.value[1] =
  1983. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  1984. ucontrol->value.integer.value[2] =
  1985. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  1986. ucontrol->value.integer.value[3] =
  1987. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  1988. ucontrol->value.integer.value[4] =
  1989. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  1990. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  1991. "%s: IIR #%d band #%d b1 = 0x%x\n"
  1992. "%s: IIR #%d band #%d b2 = 0x%x\n"
  1993. "%s: IIR #%d band #%d a1 = 0x%x\n"
  1994. "%s: IIR #%d band #%d a2 = 0x%x\n",
  1995. __func__, iir_idx, band_idx,
  1996. (uint32_t)ucontrol->value.integer.value[0],
  1997. __func__, iir_idx, band_idx,
  1998. (uint32_t)ucontrol->value.integer.value[1],
  1999. __func__, iir_idx, band_idx,
  2000. (uint32_t)ucontrol->value.integer.value[2],
  2001. __func__, iir_idx, band_idx,
  2002. (uint32_t)ucontrol->value.integer.value[3],
  2003. __func__, iir_idx, band_idx,
  2004. (uint32_t)ucontrol->value.integer.value[4]);
  2005. return 0;
  2006. }
  2007. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  2008. int iir_idx, int band_idx,
  2009. uint32_t value)
  2010. {
  2011. snd_soc_write(codec,
  2012. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2013. (value & 0xFF));
  2014. snd_soc_write(codec,
  2015. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2016. (value >> 8) & 0xFF);
  2017. snd_soc_write(codec,
  2018. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2019. (value >> 16) & 0xFF);
  2020. /* Mask top 2 bits, 7-8 are reserved */
  2021. snd_soc_write(codec,
  2022. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  2023. (value >> 24) & 0x3F);
  2024. }
  2025. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  2026. struct snd_ctl_elem_value *ucontrol)
  2027. {
  2028. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  2029. int iir_idx = ((struct soc_multi_mixer_control *)
  2030. kcontrol->private_value)->reg;
  2031. int band_idx = ((struct soc_multi_mixer_control *)
  2032. kcontrol->private_value)->shift;
  2033. int coeff_idx, idx = 0;
  2034. struct device *rx_dev = NULL;
  2035. struct rx_macro_priv *rx_priv = NULL;
  2036. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2037. return -EINVAL;
  2038. /*
  2039. * Mask top bit it is reserved
  2040. * Updates addr automatically for each B2 write
  2041. */
  2042. snd_soc_write(codec,
  2043. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  2044. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  2045. /* Store the coefficients in sidetone coeff array */
  2046. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  2047. coeff_idx++) {
  2048. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  2049. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  2050. /* Four 8 bit values(one 32 bit) per coefficient */
  2051. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2052. (value & 0xFF);
  2053. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2054. (value >> 8) & 0xFF;
  2055. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2056. (value >> 16) & 0xFF;
  2057. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  2058. (value >> 24) & 0xFF;
  2059. }
  2060. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  2061. "%s: IIR #%d band #%d b1 = 0x%x\n"
  2062. "%s: IIR #%d band #%d b2 = 0x%x\n"
  2063. "%s: IIR #%d band #%d a1 = 0x%x\n"
  2064. "%s: IIR #%d band #%d a2 = 0x%x\n",
  2065. __func__, iir_idx, band_idx,
  2066. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  2067. __func__, iir_idx, band_idx,
  2068. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  2069. __func__, iir_idx, band_idx,
  2070. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  2071. __func__, iir_idx, band_idx,
  2072. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  2073. __func__, iir_idx, band_idx,
  2074. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  2075. return 0;
  2076. }
  2077. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  2078. struct snd_kcontrol *kcontrol, int event)
  2079. {
  2080. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  2081. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  2082. switch (event) {
  2083. case SND_SOC_DAPM_POST_PMU: /* fall through */
  2084. case SND_SOC_DAPM_PRE_PMD:
  2085. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  2086. snd_soc_write(codec,
  2087. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  2088. snd_soc_read(codec,
  2089. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  2090. snd_soc_write(codec,
  2091. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  2092. snd_soc_read(codec,
  2093. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  2094. snd_soc_write(codec,
  2095. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  2096. snd_soc_read(codec,
  2097. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  2098. snd_soc_write(codec,
  2099. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  2100. snd_soc_read(codec,
  2101. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  2102. } else {
  2103. snd_soc_write(codec,
  2104. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  2105. snd_soc_read(codec,
  2106. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  2107. snd_soc_write(codec,
  2108. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  2109. snd_soc_read(codec,
  2110. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  2111. snd_soc_write(codec,
  2112. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  2113. snd_soc_read(codec,
  2114. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  2115. snd_soc_write(codec,
  2116. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  2117. snd_soc_read(codec,
  2118. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  2119. }
  2120. break;
  2121. }
  2122. return 0;
  2123. }
  2124. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  2125. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  2126. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  2127. 0, -84, 40, digital_gain),
  2128. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  2129. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  2130. 0, -84, 40, digital_gain),
  2131. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  2132. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  2133. 0, -84, 40, digital_gain),
  2134. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  2135. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2136. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  2137. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2138. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  2139. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  2140. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  2141. rx_macro_get_compander, rx_macro_set_compander),
  2142. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  2143. rx_macro_get_compander, rx_macro_set_compander),
  2144. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  2145. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  2146. SOC_ENUM_EXT("RX_HPH HD2 Mode", rx_macro_hph_hd2_mode_enum,
  2147. rx_macro_get_hph_hd2_mode, rx_macro_put_hph_hd2_mode),
  2148. SOC_ENUM_EXT("RX_HPH_PWR_MODE", rx_macro_hph_pwr_mode_enum,
  2149. rx_macro_get_hph_pwr_mode, rx_macro_put_hph_pwr_mode),
  2150. SOC_ENUM_EXT("RX_GSM mode Enable", rx_macro_vbat_bcl_gsm_mode_enum,
  2151. rx_macro_vbat_bcl_gsm_mode_func_get,
  2152. rx_macro_vbat_bcl_gsm_mode_func_put),
  2153. SOC_SINGLE_EXT("RX_Softclip Enable", SND_SOC_NOPM, 0, 1, 0,
  2154. rx_macro_soft_clip_enable_get,
  2155. rx_macro_soft_clip_enable_put),
  2156. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  2157. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  2158. digital_gain),
  2159. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  2160. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  2161. digital_gain),
  2162. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  2163. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  2164. digital_gain),
  2165. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  2166. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  2167. digital_gain),
  2168. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  2169. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  2170. digital_gain),
  2171. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  2172. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  2173. digital_gain),
  2174. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  2175. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  2176. digital_gain),
  2177. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  2178. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  2179. digital_gain),
  2180. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  2181. rx_macro_iir_enable_audio_mixer_get,
  2182. rx_macro_iir_enable_audio_mixer_put),
  2183. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  2184. rx_macro_iir_enable_audio_mixer_get,
  2185. rx_macro_iir_enable_audio_mixer_put),
  2186. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  2187. rx_macro_iir_enable_audio_mixer_get,
  2188. rx_macro_iir_enable_audio_mixer_put),
  2189. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  2190. rx_macro_iir_enable_audio_mixer_get,
  2191. rx_macro_iir_enable_audio_mixer_put),
  2192. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  2193. rx_macro_iir_enable_audio_mixer_get,
  2194. rx_macro_iir_enable_audio_mixer_put),
  2195. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  2196. rx_macro_iir_enable_audio_mixer_get,
  2197. rx_macro_iir_enable_audio_mixer_put),
  2198. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  2199. rx_macro_iir_enable_audio_mixer_get,
  2200. rx_macro_iir_enable_audio_mixer_put),
  2201. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  2202. rx_macro_iir_enable_audio_mixer_get,
  2203. rx_macro_iir_enable_audio_mixer_put),
  2204. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  2205. rx_macro_iir_enable_audio_mixer_get,
  2206. rx_macro_iir_enable_audio_mixer_put),
  2207. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  2208. rx_macro_iir_enable_audio_mixer_get,
  2209. rx_macro_iir_enable_audio_mixer_put),
  2210. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  2211. rx_macro_iir_band_audio_mixer_get,
  2212. rx_macro_iir_band_audio_mixer_put),
  2213. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  2214. rx_macro_iir_band_audio_mixer_get,
  2215. rx_macro_iir_band_audio_mixer_put),
  2216. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  2217. rx_macro_iir_band_audio_mixer_get,
  2218. rx_macro_iir_band_audio_mixer_put),
  2219. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  2220. rx_macro_iir_band_audio_mixer_get,
  2221. rx_macro_iir_band_audio_mixer_put),
  2222. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  2223. rx_macro_iir_band_audio_mixer_get,
  2224. rx_macro_iir_band_audio_mixer_put),
  2225. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  2226. rx_macro_iir_band_audio_mixer_get,
  2227. rx_macro_iir_band_audio_mixer_put),
  2228. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  2229. rx_macro_iir_band_audio_mixer_get,
  2230. rx_macro_iir_band_audio_mixer_put),
  2231. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  2232. rx_macro_iir_band_audio_mixer_get,
  2233. rx_macro_iir_band_audio_mixer_put),
  2234. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  2235. rx_macro_iir_band_audio_mixer_get,
  2236. rx_macro_iir_band_audio_mixer_put),
  2237. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  2238. rx_macro_iir_band_audio_mixer_get,
  2239. rx_macro_iir_band_audio_mixer_put),
  2240. };
  2241. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  2242. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  2243. SND_SOC_NOPM, 0, 0),
  2244. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  2245. SND_SOC_NOPM, 0, 0),
  2246. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  2247. SND_SOC_NOPM, 0, 0),
  2248. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  2249. SND_SOC_NOPM, 0, 0),
  2250. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  2251. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  2252. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  2253. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  2254. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  2255. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  2256. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  2257. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2258. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2259. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  2260. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  2261. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  2262. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  2263. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  2264. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  2265. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  2266. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  2267. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  2268. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  2269. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  2270. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  2271. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2272. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2273. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  2274. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  2275. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  2276. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  2277. 4, 0, NULL, 0),
  2278. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  2279. 4, 0, NULL, 0),
  2280. RX_MACRO_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  2281. RX_MACRO_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  2282. RX_MACRO_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  2283. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  2284. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  2285. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2286. &rx_int0_2_mux, rx_macro_enable_mix_path,
  2287. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2288. SND_SOC_DAPM_POST_PMD),
  2289. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2290. &rx_int1_2_mux, rx_macro_enable_mix_path,
  2291. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2292. SND_SOC_DAPM_POST_PMD),
  2293. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  2294. &rx_int2_2_mux, rx_macro_enable_mix_path,
  2295. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2296. SND_SOC_DAPM_POST_PMD),
  2297. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  2298. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  2299. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  2300. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  2301. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  2302. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  2303. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  2304. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  2305. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  2306. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  2307. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  2308. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2309. SND_SOC_DAPM_POST_PMD),
  2310. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  2311. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  2312. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2313. SND_SOC_DAPM_POST_PMD),
  2314. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  2315. &rx_int2_1_interp_mux, rx_macro_enable_main_path,
  2316. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2317. SND_SOC_DAPM_POST_PMD),
  2318. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  2319. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2320. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2321. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2322. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2323. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2324. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2325. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2326. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2327. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  2328. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2329. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2330. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  2331. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2332. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2333. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  2334. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2335. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2336. SND_SOC_DAPM_MIXER_E("RX INT2_1 VBAT", SND_SOC_NOPM,
  2337. 0, 0, rx_int2_1_vbat_mix_switch,
  2338. ARRAY_SIZE(rx_int2_1_vbat_mix_switch),
  2339. rx_macro_enable_vbat,
  2340. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2341. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2342. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2343. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2344. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  2345. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  2346. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  2347. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  2348. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  2349. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  2350. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  2351. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2352. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2353. };
  2354. static const struct snd_soc_dapm_route rx_audio_map[] = {
  2355. {"RX AIF1 PB", NULL, "RX_MCLK"},
  2356. {"RX AIF2 PB", NULL, "RX_MCLK"},
  2357. {"RX AIF3 PB", NULL, "RX_MCLK"},
  2358. {"RX AIF4 PB", NULL, "RX_MCLK"},
  2359. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  2360. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  2361. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  2362. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  2363. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  2364. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  2365. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  2366. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  2367. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  2368. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  2369. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  2370. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  2371. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  2372. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  2373. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  2374. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  2375. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  2376. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  2377. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  2378. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  2379. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  2380. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  2381. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  2382. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  2383. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  2384. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  2385. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  2386. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  2387. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  2388. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  2389. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  2390. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  2391. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  2392. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  2393. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  2394. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  2395. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  2396. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  2397. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  2398. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  2399. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  2400. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  2401. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  2402. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  2403. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  2404. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  2405. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  2406. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  2407. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  2408. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  2409. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  2410. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  2411. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  2412. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  2413. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  2414. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  2415. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  2416. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  2417. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  2418. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  2419. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  2420. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  2421. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  2422. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  2423. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  2424. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  2425. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  2426. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  2427. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  2428. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  2429. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  2430. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  2431. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  2432. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  2433. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  2434. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  2435. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  2436. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  2437. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  2438. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  2439. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  2440. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  2441. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  2442. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  2443. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  2444. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  2445. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  2446. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  2447. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  2448. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  2449. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  2450. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  2451. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  2452. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  2453. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  2454. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  2455. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  2456. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  2457. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  2458. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  2459. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  2460. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  2461. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  2462. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  2463. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  2464. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  2465. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  2466. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  2467. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  2468. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  2469. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  2470. /* Mixing path INT0 */
  2471. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  2472. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  2473. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  2474. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  2475. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  2476. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  2477. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  2478. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  2479. /* Mixing path INT1 */
  2480. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  2481. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  2482. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  2483. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  2484. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  2485. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  2486. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  2487. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  2488. /* Mixing path INT2 */
  2489. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  2490. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  2491. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  2492. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  2493. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  2494. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  2495. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  2496. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  2497. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  2498. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  2499. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  2500. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  2501. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  2502. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  2503. {"HPHL_OUT", NULL, "RX_MCLK"},
  2504. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  2505. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  2506. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  2507. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  2508. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  2509. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  2510. {"HPHR_OUT", NULL, "RX_MCLK"},
  2511. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  2512. {"RX INT2_1 VBAT", "RX AUX VBAT Enable", "RX INT2_1 INTERP"},
  2513. {"RX INT2 SEC MIX", NULL, "RX INT2_1 VBAT"},
  2514. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  2515. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2516. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2517. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2518. {"AUX_OUT", NULL, "RX_MCLK"},
  2519. {"IIR0", NULL, "RX_MCLK"},
  2520. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2521. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2522. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2523. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2524. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2525. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2526. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2527. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2528. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2529. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2530. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2531. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2532. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2533. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2534. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2535. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2536. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2537. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2538. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2539. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2540. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2541. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2542. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2543. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2544. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2545. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2546. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2547. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2548. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2549. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2550. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2551. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2552. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2553. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2554. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2555. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2556. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2557. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2558. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2559. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2560. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2561. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2562. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2563. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2564. {"IIR1", NULL, "RX_MCLK"},
  2565. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2566. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2567. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2568. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2569. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2570. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2571. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2572. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2573. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2574. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2575. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2576. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2577. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2578. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2579. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2580. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2581. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2582. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2583. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2584. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2585. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2586. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2587. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2588. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2589. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2590. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2591. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2592. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2593. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2594. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2595. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2596. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2597. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2598. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2599. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2600. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2601. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2602. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2603. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2604. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2605. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2606. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2607. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2608. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2609. {"SRC0", NULL, "IIR0"},
  2610. {"SRC1", NULL, "IIR1"},
  2611. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2612. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2613. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2614. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2615. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2616. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2617. };
  2618. static int rx_swrm_clock(void *handle, bool enable)
  2619. {
  2620. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2621. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2622. int ret = 0;
  2623. if (regmap == NULL) {
  2624. dev_err(rx_priv->dev, "%s: regmap is NULL\n", __func__);
  2625. return -EINVAL;
  2626. }
  2627. mutex_lock(&rx_priv->swr_clk_lock);
  2628. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2629. __func__, (enable ? "enable" : "disable"));
  2630. if (enable) {
  2631. if (rx_priv->swr_clk_users == 0) {
  2632. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2633. if (ret < 0) {
  2634. dev_err(rx_priv->dev,
  2635. "%s: rx request clock enable failed\n",
  2636. __func__);
  2637. goto exit;
  2638. }
  2639. regmap_update_bits(regmap,
  2640. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2641. 0x02, 0x02);
  2642. regmap_update_bits(regmap,
  2643. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2644. 0x01, 0x01);
  2645. regmap_update_bits(regmap,
  2646. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2647. 0x02, 0x00);
  2648. msm_cdc_pinctrl_select_active_state(
  2649. rx_priv->rx_swr_gpio_p);
  2650. }
  2651. rx_priv->swr_clk_users++;
  2652. } else {
  2653. if (rx_priv->swr_clk_users <= 0) {
  2654. dev_err(rx_priv->dev,
  2655. "%s: rx swrm clock users already reset\n",
  2656. __func__);
  2657. rx_priv->swr_clk_users = 0;
  2658. goto exit;
  2659. }
  2660. rx_priv->swr_clk_users--;
  2661. if (rx_priv->swr_clk_users == 0) {
  2662. regmap_update_bits(regmap,
  2663. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2664. 0x01, 0x00);
  2665. msm_cdc_pinctrl_select_sleep_state(
  2666. rx_priv->rx_swr_gpio_p);
  2667. rx_macro_mclk_enable(rx_priv, 0, true);
  2668. }
  2669. }
  2670. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2671. __func__, rx_priv->swr_clk_users);
  2672. exit:
  2673. mutex_unlock(&rx_priv->swr_clk_lock);
  2674. return ret;
  2675. }
  2676. static void rx_macro_init_bcl_pmic_reg(struct snd_soc_codec *codec)
  2677. {
  2678. struct device *rx_dev = NULL;
  2679. struct rx_macro_priv *rx_priv = NULL;
  2680. if (!codec) {
  2681. pr_err("%s: NULL codec pointer!\n", __func__);
  2682. return;
  2683. }
  2684. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2685. return;
  2686. switch (rx_priv->bcl_pmic_params.id) {
  2687. case 0:
  2688. /* Enable ID0 to listen to respective PMIC group interrupts */
  2689. snd_soc_update_bits(codec,
  2690. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2691. /* Update MC_SID0 */
  2692. snd_soc_update_bits(codec,
  2693. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0x0F,
  2694. rx_priv->bcl_pmic_params.sid);
  2695. /* Update MC_PPID0 */
  2696. snd_soc_update_bits(codec,
  2697. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG2, 0xFF,
  2698. rx_priv->bcl_pmic_params.ppid);
  2699. break;
  2700. case 1:
  2701. /* Enable ID1 to listen to respective PMIC group interrupts */
  2702. snd_soc_update_bits(codec,
  2703. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2704. /* Update MC_SID1 */
  2705. snd_soc_update_bits(codec,
  2706. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG3, 0x0F,
  2707. rx_priv->bcl_pmic_params.sid);
  2708. /* Update MC_PPID1 */
  2709. snd_soc_update_bits(codec,
  2710. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0xFF,
  2711. rx_priv->bcl_pmic_params.ppid);
  2712. break;
  2713. default:
  2714. dev_err(rx_dev, "%s: PMIC ID is invalid\n",
  2715. __func__, rx_priv->bcl_pmic_params.id);
  2716. break;
  2717. }
  2718. }
  2719. static int rx_macro_init(struct snd_soc_codec *codec)
  2720. {
  2721. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2722. int ret = 0;
  2723. struct device *rx_dev = NULL;
  2724. struct rx_macro_priv *rx_priv = NULL;
  2725. rx_dev = bolero_get_device_ptr(codec->dev, RX_MACRO);
  2726. if (!rx_dev) {
  2727. dev_err(codec->dev,
  2728. "%s: null device for macro!\n", __func__);
  2729. return -EINVAL;
  2730. }
  2731. rx_priv = dev_get_drvdata(rx_dev);
  2732. if (!rx_priv) {
  2733. dev_err(codec->dev,
  2734. "%s: priv is null for macro!\n", __func__);
  2735. return -EINVAL;
  2736. }
  2737. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  2738. ARRAY_SIZE(rx_macro_dapm_widgets));
  2739. if (ret < 0) {
  2740. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  2741. return ret;
  2742. }
  2743. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  2744. ARRAY_SIZE(rx_audio_map));
  2745. if (ret < 0) {
  2746. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  2747. return ret;
  2748. }
  2749. ret = snd_soc_dapm_new_widgets(dapm->card);
  2750. if (ret < 0) {
  2751. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  2752. return ret;
  2753. }
  2754. ret = snd_soc_add_codec_controls(codec, rx_macro_snd_controls,
  2755. ARRAY_SIZE(rx_macro_snd_controls));
  2756. if (ret < 0) {
  2757. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  2758. return ret;
  2759. }
  2760. rx_priv->dev_up = true;
  2761. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF1 Playback");
  2762. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF2 Playback");
  2763. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF3 Playback");
  2764. snd_soc_dapm_ignore_suspend(dapm, "RX_MACRO_AIF4 Playback");
  2765. snd_soc_dapm_ignore_suspend(dapm, "HPHL_OUT");
  2766. snd_soc_dapm_ignore_suspend(dapm, "HPHR_OUT");
  2767. snd_soc_dapm_ignore_suspend(dapm, "AUX_OUT");
  2768. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC0_INP");
  2769. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC1_INP");
  2770. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC2_INP");
  2771. snd_soc_dapm_ignore_suspend(dapm, "RX_TX DEC3_INP");
  2772. snd_soc_dapm_sync(dapm);
  2773. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL, 0x01, 0x01);
  2774. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL, 0x01, 0x01);
  2775. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL, 0x01, 0x01);
  2776. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_SEC7, 0x07, 0x02);
  2777. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_SEC7, 0x07, 0x02);
  2778. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x07, 0x02);
  2779. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG3, 0x03, 0x02);
  2780. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG3, 0x03, 0x02);
  2781. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG3, 0x03, 0x02);
  2782. rx_macro_init_bcl_pmic_reg(codec);
  2783. rx_priv->codec = codec;
  2784. return 0;
  2785. }
  2786. static int rx_macro_deinit(struct snd_soc_codec *codec)
  2787. {
  2788. struct device *rx_dev = NULL;
  2789. struct rx_macro_priv *rx_priv = NULL;
  2790. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2791. return -EINVAL;
  2792. rx_priv->codec = NULL;
  2793. return 0;
  2794. }
  2795. static void rx_macro_add_child_devices(struct work_struct *work)
  2796. {
  2797. struct rx_macro_priv *rx_priv = NULL;
  2798. struct platform_device *pdev = NULL;
  2799. struct device_node *node = NULL;
  2800. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2801. int ret = 0;
  2802. u16 count = 0, ctrl_num = 0;
  2803. struct rx_swr_ctrl_platform_data *platdata = NULL;
  2804. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  2805. bool rx_swr_master_node = false;
  2806. rx_priv = container_of(work, struct rx_macro_priv,
  2807. rx_macro_add_child_devices_work);
  2808. if (!rx_priv) {
  2809. pr_err("%s: Memory for rx_priv does not exist\n",
  2810. __func__);
  2811. return;
  2812. }
  2813. if (!rx_priv->dev) {
  2814. pr_err("%s: RX device does not exist\n", __func__);
  2815. return;
  2816. }
  2817. if(!rx_priv->dev->of_node) {
  2818. dev_err(rx_priv->dev,
  2819. "%s: DT node for RX dev does not exist\n", __func__);
  2820. return;
  2821. }
  2822. platdata = &rx_priv->swr_plat_data;
  2823. rx_priv->child_count = 0;
  2824. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  2825. rx_swr_master_node = false;
  2826. if (strnstr(node->name, "rx_swr_master",
  2827. strlen("rx_swr_master")) != NULL)
  2828. rx_swr_master_node = true;
  2829. if(rx_swr_master_node)
  2830. strlcpy(plat_dev_name, "rx_swr_ctrl",
  2831. (RX_SWR_STRING_LEN - 1));
  2832. else
  2833. strlcpy(plat_dev_name, node->name,
  2834. (RX_SWR_STRING_LEN - 1));
  2835. pdev = platform_device_alloc(plat_dev_name, -1);
  2836. if (!pdev) {
  2837. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  2838. __func__);
  2839. ret = -ENOMEM;
  2840. goto err;
  2841. }
  2842. pdev->dev.parent = rx_priv->dev;
  2843. pdev->dev.of_node = node;
  2844. if (rx_swr_master_node) {
  2845. ret = platform_device_add_data(pdev, platdata,
  2846. sizeof(*platdata));
  2847. if (ret) {
  2848. dev_err(&pdev->dev,
  2849. "%s: cannot add plat data ctrl:%d\n",
  2850. __func__, ctrl_num);
  2851. goto fail_pdev_add;
  2852. }
  2853. }
  2854. ret = platform_device_add(pdev);
  2855. if (ret) {
  2856. dev_err(&pdev->dev,
  2857. "%s: Cannot add platform device\n",
  2858. __func__);
  2859. goto fail_pdev_add;
  2860. }
  2861. if (rx_swr_master_node) {
  2862. temp = krealloc(swr_ctrl_data,
  2863. (ctrl_num + 1) * sizeof(
  2864. struct rx_swr_ctrl_data),
  2865. GFP_KERNEL);
  2866. if (!temp) {
  2867. ret = -ENOMEM;
  2868. goto fail_pdev_add;
  2869. }
  2870. swr_ctrl_data = temp;
  2871. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  2872. ctrl_num++;
  2873. dev_dbg(&pdev->dev,
  2874. "%s: Added soundwire ctrl device(s)\n",
  2875. __func__);
  2876. rx_priv->swr_ctrl_data = swr_ctrl_data;
  2877. }
  2878. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  2879. rx_priv->pdev_child_devices[
  2880. rx_priv->child_count++] = pdev;
  2881. else
  2882. goto err;
  2883. }
  2884. return;
  2885. fail_pdev_add:
  2886. for (count = 0; count < rx_priv->child_count; count++)
  2887. platform_device_put(rx_priv->pdev_child_devices[count]);
  2888. err:
  2889. return;
  2890. }
  2891. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  2892. {
  2893. memset(ops, 0, sizeof(struct macro_ops));
  2894. ops->init = rx_macro_init;
  2895. ops->exit = rx_macro_deinit;
  2896. ops->io_base = rx_io_base;
  2897. ops->dai_ptr = rx_macro_dai;
  2898. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  2899. ops->mclk_fn = rx_macro_mclk_ctrl;
  2900. ops->event_handler = rx_macro_event_handler;
  2901. }
  2902. static int rx_macro_probe(struct platform_device *pdev)
  2903. {
  2904. struct macro_ops ops = {0};
  2905. struct rx_macro_priv *rx_priv = NULL;
  2906. u32 rx_base_addr = 0, muxsel = 0;
  2907. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  2908. int ret = 0;
  2909. struct clk *rx_core_clk = NULL, *rx_npl_clk = NULL;
  2910. u8 bcl_pmic_params[3];
  2911. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  2912. GFP_KERNEL);
  2913. if (!rx_priv)
  2914. return -ENOMEM;
  2915. rx_priv->dev = &pdev->dev;
  2916. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2917. &rx_base_addr);
  2918. if (ret) {
  2919. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2920. __func__, "reg");
  2921. return ret;
  2922. }
  2923. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  2924. &muxsel);
  2925. if (ret) {
  2926. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2927. __func__, "reg");
  2928. return ret;
  2929. }
  2930. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2931. "qcom,rx-swr-gpios", 0);
  2932. if (!rx_priv->rx_swr_gpio_p) {
  2933. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2934. __func__);
  2935. return -EINVAL;
  2936. }
  2937. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  2938. RX_MACRO_MAX_OFFSET);
  2939. if (!rx_io_base) {
  2940. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2941. return -ENOMEM;
  2942. }
  2943. rx_priv->rx_io_base = rx_io_base;
  2944. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  2945. if (!muxsel_io) {
  2946. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  2947. __func__);
  2948. return -ENOMEM;
  2949. }
  2950. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  2951. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  2952. rx_macro_add_child_devices);
  2953. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  2954. rx_priv->swr_plat_data.read = NULL;
  2955. rx_priv->swr_plat_data.write = NULL;
  2956. rx_priv->swr_plat_data.bulk_write = NULL;
  2957. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  2958. rx_priv->swr_plat_data.handle_irq = NULL;
  2959. /* Register MCLK for rx macro */
  2960. rx_core_clk = devm_clk_get(&pdev->dev, "rx_core_clk");
  2961. if (IS_ERR(rx_core_clk)) {
  2962. ret = PTR_ERR(rx_core_clk);
  2963. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2964. __func__, "rx_core_clk", ret);
  2965. return ret;
  2966. }
  2967. rx_priv->rx_core_clk = rx_core_clk;
  2968. /* Register npl clk for soundwire */
  2969. rx_npl_clk = devm_clk_get(&pdev->dev, "rx_npl_clk");
  2970. if (IS_ERR(rx_npl_clk)) {
  2971. ret = PTR_ERR(rx_npl_clk);
  2972. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2973. __func__, "rx_npl_clk", ret);
  2974. return ret;
  2975. }
  2976. rx_priv->rx_npl_clk = rx_npl_clk;
  2977. ret = of_property_read_u8_array(pdev->dev.of_node,
  2978. "qcom,rx-bcl-pmic-params", bcl_pmic_params,
  2979. sizeof(bcl_pmic_params));
  2980. if (ret) {
  2981. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  2982. __func__, "qcom,rx-bcl-pmic-params");
  2983. } else {
  2984. rx_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  2985. rx_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  2986. rx_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  2987. }
  2988. dev_set_drvdata(&pdev->dev, rx_priv);
  2989. mutex_init(&rx_priv->mclk_lock);
  2990. mutex_init(&rx_priv->swr_clk_lock);
  2991. rx_macro_init_ops(&ops, rx_io_base);
  2992. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  2993. if (ret) {
  2994. dev_err(&pdev->dev,
  2995. "%s: register macro failed\n", __func__);
  2996. goto err_reg_macro;
  2997. }
  2998. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  2999. return 0;
  3000. err_reg_macro:
  3001. mutex_destroy(&rx_priv->mclk_lock);
  3002. mutex_destroy(&rx_priv->swr_clk_lock);
  3003. return ret;
  3004. }
  3005. static int rx_macro_remove(struct platform_device *pdev)
  3006. {
  3007. struct rx_macro_priv *rx_priv = NULL;
  3008. u16 count = 0;
  3009. rx_priv = dev_get_drvdata(&pdev->dev);
  3010. if (!rx_priv)
  3011. return -EINVAL;
  3012. for (count = 0; count < rx_priv->child_count &&
  3013. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  3014. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  3015. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  3016. mutex_destroy(&rx_priv->mclk_lock);
  3017. mutex_destroy(&rx_priv->swr_clk_lock);
  3018. kfree(rx_priv->swr_ctrl_data);
  3019. return 0;
  3020. }
  3021. static const struct of_device_id rx_macro_dt_match[] = {
  3022. {.compatible = "qcom,rx-macro"},
  3023. {}
  3024. };
  3025. static struct platform_driver rx_macro_driver = {
  3026. .driver = {
  3027. .name = "rx_macro",
  3028. .owner = THIS_MODULE,
  3029. .of_match_table = rx_macro_dt_match,
  3030. },
  3031. .probe = rx_macro_probe,
  3032. .remove = rx_macro_remove,
  3033. };
  3034. module_platform_driver(rx_macro_driver);
  3035. MODULE_DESCRIPTION("RX macro driver");
  3036. MODULE_LICENSE("GPL v2");