rx-macro.c 100 KB

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