rx-macro.c 125 KB

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