rx-macro.c 111 KB

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