rx-macro.c 100 KB

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