rx-macro.c 122 KB

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