rx-macro.c 101 KB

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