rx-macro.c 128 KB

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