rx-macro.c 128 KB

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