rx-macro.c 99 KB

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