rx-macro.c 93 KB

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