rx-macro.c 102 KB

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