rx-macro.c 107 KB

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