rx-macro.c 125 KB

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