rx-macro.c 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096
  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. dev_dbg(rx_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  694. __func__, mclk_enable, dapm, rx_priv->rx_mclk_users);
  695. if (rx_priv->is_native_on)
  696. mclk_mux = MCLK_MUX1;
  697. mutex_lock(&rx_priv->mclk_lock);
  698. if (mclk_enable) {
  699. if (rx_priv->rx_mclk_users == 0) {
  700. ret = bolero_request_clock(rx_priv->dev,
  701. RX_MACRO, mclk_mux, true);
  702. if (ret < 0) {
  703. dev_err(rx_priv->dev,
  704. "%s: rx request clock enable failed\n",
  705. __func__);
  706. goto exit;
  707. }
  708. rx_priv->mclk_mux = mclk_mux;
  709. regcache_mark_dirty(regmap);
  710. regcache_sync_region(regmap,
  711. RX_START_OFFSET,
  712. RX_MAX_OFFSET);
  713. regmap_update_bits(regmap,
  714. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  715. 0x01, 0x01);
  716. regmap_update_bits(regmap,
  717. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  718. 0x02, 0x02);
  719. regmap_update_bits(regmap,
  720. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  721. 0x01, 0x01);
  722. }
  723. rx_priv->rx_mclk_users++;
  724. } else {
  725. if (rx_priv->rx_mclk_users <= 0) {
  726. dev_err(rx_priv->dev, "%s: clock already disabled\n",
  727. __func__);
  728. rx_priv->rx_mclk_users = 0;
  729. goto exit;
  730. }
  731. rx_priv->rx_mclk_users--;
  732. if (rx_priv->rx_mclk_users == 0) {
  733. regmap_update_bits(regmap,
  734. BOLERO_CDC_RX_CLK_RST_CTRL_FS_CNT_CONTROL,
  735. 0x01, 0x00);
  736. regmap_update_bits(regmap,
  737. BOLERO_CDC_RX_CLK_RST_CTRL_MCLK_CONTROL,
  738. 0x01, 0x00);
  739. bolero_request_clock(rx_priv->dev,
  740. RX_MACRO, mclk_mux, false);
  741. rx_priv->mclk_mux = MCLK_MUX0;
  742. }
  743. }
  744. exit:
  745. mutex_unlock(&rx_priv->mclk_lock);
  746. return ret;
  747. }
  748. static int rx_macro_mclk_event(struct snd_soc_dapm_widget *w,
  749. struct snd_kcontrol *kcontrol, int event)
  750. {
  751. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  752. int ret = 0;
  753. struct device *rx_dev = NULL;
  754. struct rx_macro_priv *rx_priv = NULL;
  755. int mclk_freq = MCLK_FREQ;
  756. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  757. return -EINVAL;
  758. dev_dbg(rx_dev, "%s: event = %d\n", __func__, event);
  759. switch (event) {
  760. case SND_SOC_DAPM_PRE_PMU:
  761. /* if swr_clk_users > 0, call device down */
  762. if (rx_priv->swr_clk_users > 0) {
  763. if ((rx_priv->mclk_mux == MCLK_MUX0 &&
  764. rx_priv->is_native_on) ||
  765. (rx_priv->mclk_mux == MCLK_MUX1 &&
  766. !rx_priv->is_native_on)) {
  767. swrm_wcd_notify(
  768. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  769. SWR_DEVICE_DOWN, NULL);
  770. }
  771. }
  772. if (rx_priv->is_native_on)
  773. mclk_freq = MCLK_FREQ_NATIVE;
  774. swrm_wcd_notify(
  775. rx_priv->swr_ctrl_data[0].rx_swr_pdev,
  776. SWR_CLK_FREQ, &mclk_freq);
  777. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  778. break;
  779. case SND_SOC_DAPM_POST_PMD:
  780. ret = rx_macro_mclk_enable(rx_priv, 0, true);
  781. break;
  782. default:
  783. dev_err(rx_priv->dev,
  784. "%s: invalid DAPM event %d\n", __func__, event);
  785. ret = -EINVAL;
  786. }
  787. return ret;
  788. }
  789. static int rx_macro_mclk_ctrl(struct device *dev, bool enable)
  790. {
  791. struct rx_macro_priv *rx_priv = dev_get_drvdata(dev);
  792. int ret = 0;
  793. if (enable) {
  794. ret = clk_prepare_enable(rx_priv->rx_core_clk);
  795. if (ret < 0) {
  796. dev_err(dev, "%s:rx mclk enable failed\n", __func__);
  797. return ret;
  798. }
  799. ret = clk_prepare_enable(rx_priv->rx_npl_clk);
  800. if (ret < 0) {
  801. clk_disable_unprepare(rx_priv->rx_core_clk);
  802. dev_err(dev, "%s:rx npl_clk enable failed\n",
  803. __func__);
  804. return ret;
  805. }
  806. if (rx_priv->rx_mclk_cnt++ == 0)
  807. iowrite32(0x1, rx_priv->rx_mclk_mode_muxsel);
  808. } else {
  809. if (rx_priv->rx_mclk_cnt <= 0) {
  810. dev_dbg(dev, "%s:rx mclk already disabled\n", __func__);
  811. rx_priv->rx_mclk_cnt = 0;
  812. return 0;
  813. }
  814. if (--rx_priv->rx_mclk_cnt == 0)
  815. iowrite32(0x0, rx_priv->rx_mclk_mode_muxsel);
  816. clk_disable_unprepare(rx_priv->rx_npl_clk);
  817. clk_disable_unprepare(rx_priv->rx_core_clk);
  818. }
  819. return 0;
  820. }
  821. static int rx_macro_find_playback_dai_id_for_port(int port_id,
  822. struct rx_macro_priv *rx_priv)
  823. {
  824. int i = 0;
  825. for (i = RX_MACRO_AIF1_PB; i < RX_MACRO_MAX_DAIS; i++) {
  826. if (test_bit(port_id, &rx_priv->active_ch_mask[i]))
  827. return i;
  828. }
  829. return -EINVAL;
  830. }
  831. static int rx_macro_set_idle_detect_thr(struct snd_soc_codec *codec,
  832. struct rx_macro_priv *rx_priv,
  833. int interp, int path_type)
  834. {
  835. int port_id[4] = { 0, 0, 0, 0 };
  836. int *port_ptr = NULL;
  837. int num_ports = 0;
  838. int bit_width = 0, i = 0;
  839. int mux_reg = 0, mux_reg_val = 0;
  840. int dai_id = 0, idle_thr = 0;
  841. if ((interp != INTERP_HPHL) && (interp != INTERP_HPHR))
  842. return 0;
  843. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  844. return 0;
  845. port_ptr = &port_id[0];
  846. num_ports = 0;
  847. /*
  848. * Read interpolator MUX input registers and find
  849. * which cdc_dma port is connected and store the port
  850. * numbers in port_id array.
  851. */
  852. if (path_type == INTERP_MIX_PATH) {
  853. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT0_CFG1 +
  854. 2 * interp;
  855. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  856. if ((mux_reg_val >= INTn_2_INP_SEL_RX0) &&
  857. (mux_reg_val <= INTn_2_INP_SEL_RX5)) {
  858. *port_ptr++ = mux_reg_val - 1;
  859. num_ports++;
  860. }
  861. }
  862. if (path_type == INTERP_MAIN_PATH) {
  863. mux_reg = BOLERO_CDC_RX_INP_MUX_RX_INT1_CFG0 +
  864. 2 * (interp - 1);
  865. mux_reg_val = snd_soc_read(codec, mux_reg) & 0x0f;
  866. i = RX_MACRO_INTERP_MUX_NUM_INPUTS;
  867. while (i) {
  868. if ((mux_reg_val >= INTn_1_INP_SEL_RX0) &&
  869. (mux_reg_val <= INTn_1_INP_SEL_RX5)) {
  870. *port_ptr++ = mux_reg_val -
  871. INTn_1_INP_SEL_RX0;
  872. num_ports++;
  873. }
  874. mux_reg_val = (snd_soc_read(codec, mux_reg) &
  875. 0xf0) >> 4;
  876. mux_reg += 1;
  877. i--;
  878. }
  879. }
  880. dev_dbg(codec->dev, "%s: num_ports: %d, ports[%d %d %d %d]\n",
  881. __func__, num_ports, port_id[0], port_id[1],
  882. port_id[2], port_id[3]);
  883. i = 0;
  884. while (num_ports) {
  885. dai_id = rx_macro_find_playback_dai_id_for_port(port_id[i++],
  886. rx_priv);
  887. if ((dai_id >= 0) && (dai_id < RX_MACRO_MAX_DAIS)) {
  888. dev_dbg(codec->dev, "%s: dai_id: %d bit_width: %d\n",
  889. __func__, dai_id,
  890. rx_priv->bit_width[dai_id]);
  891. if (rx_priv->bit_width[dai_id] > bit_width)
  892. bit_width = rx_priv->bit_width[dai_id];
  893. }
  894. num_ports--;
  895. }
  896. switch (bit_width) {
  897. case 16:
  898. idle_thr = 0xff; /* F16 */
  899. break;
  900. case 24:
  901. case 32:
  902. idle_thr = 0x03; /* F22 */
  903. break;
  904. default:
  905. idle_thr = 0x00;
  906. break;
  907. }
  908. dev_dbg(codec->dev, "%s: (new) idle_thr: %d, (cur) idle_thr: %d\n",
  909. __func__, idle_thr, rx_priv->idle_det_cfg.hph_idle_thr);
  910. if ((rx_priv->idle_det_cfg.hph_idle_thr == 0) ||
  911. (idle_thr < rx_priv->idle_det_cfg.hph_idle_thr)) {
  912. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, idle_thr);
  913. rx_priv->idle_det_cfg.hph_idle_thr = idle_thr;
  914. }
  915. return 0;
  916. }
  917. static int rx_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  918. struct snd_kcontrol *kcontrol, int event)
  919. {
  920. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  921. u16 gain_reg = 0, mix_reg = 0;
  922. struct device *rx_dev = NULL;
  923. struct rx_macro_priv *rx_priv = NULL;
  924. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  925. return -EINVAL;
  926. if (w->shift >= INTERP_MAX) {
  927. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  928. __func__, w->shift, w->name);
  929. return -EINVAL;
  930. }
  931. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL +
  932. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  933. mix_reg = BOLERO_CDC_RX_RX0_RX_PATH_MIX_CTL +
  934. (w->shift * RX_MACRO_RX_PATH_OFFSET);
  935. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  936. switch (event) {
  937. case SND_SOC_DAPM_PRE_PMU:
  938. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  939. INTERP_MIX_PATH);
  940. rx_macro_enable_interp_clk(codec, event, w->shift);
  941. /* Clk enable */
  942. snd_soc_update_bits(codec, mix_reg, 0x20, 0x20);
  943. break;
  944. case SND_SOC_DAPM_POST_PMU:
  945. snd_soc_write(codec, gain_reg,
  946. snd_soc_read(codec, gain_reg));
  947. snd_soc_update_bits(codec, mix_reg, 0x10, 0x00);
  948. break;
  949. case SND_SOC_DAPM_POST_PMD:
  950. /* Clk Disable */
  951. snd_soc_update_bits(codec, mix_reg, 0x20, 0x00);
  952. rx_macro_enable_interp_clk(codec, event, w->shift);
  953. /* Reset enable and disable */
  954. snd_soc_update_bits(codec, mix_reg, 0x40, 0x40);
  955. snd_soc_update_bits(codec, mix_reg, 0x40, 0x00);
  956. break;
  957. }
  958. return 0;
  959. }
  960. static int rx_macro_enable_main_path(struct snd_soc_dapm_widget *w,
  961. struct snd_kcontrol *kcontrol,
  962. int event)
  963. {
  964. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  965. u16 gain_reg = 0;
  966. u16 reg = 0;
  967. struct device *rx_dev = NULL;
  968. struct rx_macro_priv *rx_priv = NULL;
  969. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  970. return -EINVAL;
  971. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  972. if (w->shift >= INTERP_MAX) {
  973. dev_err(codec->dev, "%s: Invalid Interpolator value %d for name %s\n",
  974. __func__, w->shift, w->name);
  975. return -EINVAL;
  976. }
  977. reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL + (w->shift *
  978. RX_MACRO_RX_PATH_OFFSET);
  979. gain_reg = BOLERO_CDC_RX_RX0_RX_VOL_CTL + (w->shift *
  980. RX_MACRO_RX_PATH_OFFSET);
  981. switch (event) {
  982. case SND_SOC_DAPM_PRE_PMU:
  983. rx_macro_set_idle_detect_thr(codec, rx_priv, w->shift,
  984. INTERP_MAIN_PATH);
  985. rx_macro_enable_interp_clk(codec, event, w->shift);
  986. break;
  987. case SND_SOC_DAPM_POST_PMU:
  988. snd_soc_write(codec, gain_reg,
  989. snd_soc_read(codec, gain_reg));
  990. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  991. break;
  992. case SND_SOC_DAPM_POST_PMD:
  993. rx_macro_enable_interp_clk(codec, event, w->shift);
  994. break;
  995. }
  996. return 0;
  997. }
  998. static int rx_macro_config_compander(struct snd_soc_codec *codec,
  999. struct rx_macro_priv *rx_priv,
  1000. int interp_n, int event)
  1001. {
  1002. int comp = 0;
  1003. u16 comp_ctl0_reg = 0, rx_path_cfg0_reg = 0;
  1004. /* AUX does not have compander */
  1005. if (interp_n == INTERP_AUX)
  1006. return 0;
  1007. comp = interp_n;
  1008. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  1009. __func__, event, comp + 1, rx_priv->comp_enabled[comp]);
  1010. if (!rx_priv->comp_enabled[comp])
  1011. return 0;
  1012. comp_ctl0_reg = BOLERO_CDC_RX_COMPANDER0_CTL0 +
  1013. (comp * RX_MACRO_COMP_OFFSET);
  1014. rx_path_cfg0_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG0 +
  1015. (comp * RX_MACRO_RX_PATH_OFFSET);
  1016. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1017. /* Enable Compander Clock */
  1018. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  1019. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1020. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1021. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  1022. }
  1023. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1024. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  1025. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  1026. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  1027. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  1028. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  1029. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  1030. }
  1031. return 0;
  1032. }
  1033. static void rx_macro_enable_softclip_clk(struct snd_soc_codec *codec,
  1034. struct rx_macro_priv *rx_priv,
  1035. bool enable)
  1036. {
  1037. if (enable) {
  1038. if (rx_priv->softclip_clk_users == 0)
  1039. snd_soc_update_bits(codec,
  1040. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1041. 0x01, 0x01);
  1042. rx_priv->softclip_clk_users++;
  1043. } else {
  1044. rx_priv->softclip_clk_users--;
  1045. if (rx_priv->softclip_clk_users == 0)
  1046. snd_soc_update_bits(codec,
  1047. BOLERO_CDC_RX_SOFTCLIP_CRC,
  1048. 0x01, 0x00);
  1049. }
  1050. }
  1051. static int rx_macro_config_softclip(struct snd_soc_codec *codec,
  1052. struct rx_macro_priv *rx_priv,
  1053. int event)
  1054. {
  1055. dev_dbg(codec->dev, "%s: event %d, enabled %d\n",
  1056. __func__, event, rx_priv->is_softclip_on);
  1057. if (!rx_priv->is_softclip_on)
  1058. return 0;
  1059. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1060. /* Enable Softclip clock */
  1061. rx_macro_enable_softclip_clk(codec, rx_priv, true);
  1062. /* Enable Softclip control */
  1063. snd_soc_update_bits(codec,
  1064. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x01);
  1065. }
  1066. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1067. snd_soc_update_bits(codec,
  1068. BOLERO_CDC_RX_SOFTCLIP_SOFTCLIP_CTRL, 0x01, 0x00);
  1069. rx_macro_enable_softclip_clk(codec, rx_priv, false);
  1070. }
  1071. return 0;
  1072. }
  1073. static inline void
  1074. rx_macro_enable_clsh_block(struct rx_macro_priv *rx_priv, bool enable)
  1075. {
  1076. if ((enable && ++rx_priv->clsh_users == 1) ||
  1077. (!enable && --rx_priv->clsh_users == 0))
  1078. snd_soc_update_bits(rx_priv->codec,
  1079. BOLERO_CDC_RX_CLSH_CRC, 0x01,
  1080. (u8) enable);
  1081. if (rx_priv->clsh_users < 0)
  1082. rx_priv->clsh_users = 0;
  1083. dev_dbg(rx_priv->dev, "%s: clsh_users %d, enable %d", __func__,
  1084. rx_priv->clsh_users, enable);
  1085. }
  1086. static int rx_macro_config_classh(struct snd_soc_codec *codec,
  1087. struct rx_macro_priv *rx_priv,
  1088. int interp_n, int event)
  1089. {
  1090. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1091. rx_macro_enable_clsh_block(rx_priv, false);
  1092. return 0;
  1093. }
  1094. if (!SND_SOC_DAPM_EVENT_ON(event))
  1095. return 0;
  1096. rx_macro_enable_clsh_block(rx_priv, true);
  1097. if (interp_n == INTERP_HPHL ||
  1098. interp_n == INTERP_HPHR) {
  1099. /*
  1100. * These K1 values depend on the Headphone Impedance
  1101. * For now it is assumed to be 16 ohm
  1102. */
  1103. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_LSB,
  1104. 0xFF, 0xC0);
  1105. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_K1_MSB,
  1106. 0x0F, 0x00);
  1107. }
  1108. switch (interp_n) {
  1109. case INTERP_HPHL:
  1110. if (rx_priv->is_ear_mode_on)
  1111. snd_soc_update_bits(codec,
  1112. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1113. 0x3F, 0x39);
  1114. else
  1115. snd_soc_update_bits(codec,
  1116. BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1117. 0x3F, 0x1C);
  1118. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1119. 0x07, 0x00);
  1120. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG0,
  1121. 0x40, 0x40);
  1122. break;
  1123. case INTERP_HPHR:
  1124. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_HPH_V_PA,
  1125. 0x3F, 0x1C);
  1126. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_DECAY_CTRL,
  1127. 0x07, 0x00);
  1128. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG0,
  1129. 0x40, 0x40);
  1130. break;
  1131. case INTERP_AUX:
  1132. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG0,
  1133. 0x10, 0x10);
  1134. break;
  1135. }
  1136. return 0;
  1137. }
  1138. static void rx_macro_hd2_control(struct snd_soc_codec *codec,
  1139. u16 interp_idx, int event)
  1140. {
  1141. u16 hd2_scale_reg = 0;
  1142. u16 hd2_enable_reg = 0;
  1143. switch (interp_idx) {
  1144. case INTERP_HPHL:
  1145. hd2_scale_reg = BOLERO_CDC_RX_RX1_RX_PATH_SEC3;
  1146. hd2_enable_reg = BOLERO_CDC_RX_RX1_RX_PATH_CFG0;
  1147. break;
  1148. case INTERP_HPHR:
  1149. hd2_scale_reg = BOLERO_CDC_RX_RX2_RX_PATH_SEC3;
  1150. hd2_enable_reg = BOLERO_CDC_RX_RX2_RX_PATH_CFG0;
  1151. break;
  1152. }
  1153. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1154. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x14);
  1155. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  1156. }
  1157. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1158. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  1159. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  1160. }
  1161. }
  1162. static int rx_macro_get_compander(struct snd_kcontrol *kcontrol,
  1163. struct snd_ctl_elem_value *ucontrol)
  1164. {
  1165. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1166. int comp = ((struct soc_multi_mixer_control *)
  1167. kcontrol->private_value)->shift;
  1168. struct device *rx_dev = NULL;
  1169. struct rx_macro_priv *rx_priv = NULL;
  1170. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1171. return -EINVAL;
  1172. ucontrol->value.integer.value[0] = rx_priv->comp_enabled[comp];
  1173. return 0;
  1174. }
  1175. static int rx_macro_set_compander(struct snd_kcontrol *kcontrol,
  1176. struct snd_ctl_elem_value *ucontrol)
  1177. {
  1178. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1179. int comp = ((struct soc_multi_mixer_control *)
  1180. kcontrol->private_value)->shift;
  1181. int value = ucontrol->value.integer.value[0];
  1182. struct device *rx_dev = NULL;
  1183. struct rx_macro_priv *rx_priv = NULL;
  1184. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1185. return -EINVAL;
  1186. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  1187. __func__, comp + 1, rx_priv->comp_enabled[comp], value);
  1188. rx_priv->comp_enabled[comp] = value;
  1189. return 0;
  1190. }
  1191. static int rx_macro_mux_get(struct snd_kcontrol *kcontrol,
  1192. struct snd_ctl_elem_value *ucontrol)
  1193. {
  1194. struct snd_soc_dapm_widget *widget =
  1195. snd_soc_dapm_kcontrol_widget(kcontrol);
  1196. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1197. struct device *rx_dev = NULL;
  1198. struct rx_macro_priv *rx_priv = NULL;
  1199. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1200. return -EINVAL;
  1201. ucontrol->value.integer.value[0] =
  1202. rx_priv->rx_port_value[widget->shift];
  1203. return 0;
  1204. }
  1205. static int rx_macro_mux_put(struct snd_kcontrol *kcontrol,
  1206. struct snd_ctl_elem_value *ucontrol)
  1207. {
  1208. struct snd_soc_dapm_widget *widget =
  1209. snd_soc_dapm_kcontrol_widget(kcontrol);
  1210. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1211. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1212. struct snd_soc_dapm_update *update = NULL;
  1213. u32 rx_port_value = ucontrol->value.integer.value[0];
  1214. u32 aif_rst = 0;
  1215. struct device *rx_dev = NULL;
  1216. struct rx_macro_priv *rx_priv = NULL;
  1217. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1218. return -EINVAL;
  1219. aif_rst = rx_priv->rx_port_value[widget->shift];
  1220. if (!rx_port_value) {
  1221. if (aif_rst == 0) {
  1222. dev_err(rx_dev, "%s:AIF reset already\n", __func__);
  1223. return 0;
  1224. }
  1225. }
  1226. rx_priv->rx_port_value[widget->shift] = rx_port_value;
  1227. switch (rx_port_value) {
  1228. case 0:
  1229. clear_bit(widget->shift,
  1230. &rx_priv->active_ch_mask[aif_rst]);
  1231. rx_priv->active_ch_cnt[aif_rst]--;
  1232. break;
  1233. case 1:
  1234. case 2:
  1235. case 3:
  1236. case 4:
  1237. set_bit(widget->shift,
  1238. &rx_priv->active_ch_mask[rx_port_value]);
  1239. rx_priv->active_ch_cnt[rx_port_value]++;
  1240. break;
  1241. default:
  1242. dev_err(codec->dev,
  1243. "%s:Invalid AIF_ID for RX_MACRO MUX\n", __func__);
  1244. goto err;
  1245. }
  1246. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1247. rx_port_value, e, update);
  1248. return 0;
  1249. err:
  1250. return -EINVAL;
  1251. }
  1252. static int rx_macro_get_ear_mode(struct snd_kcontrol *kcontrol,
  1253. struct snd_ctl_elem_value *ucontrol)
  1254. {
  1255. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1256. struct device *rx_dev = NULL;
  1257. struct rx_macro_priv *rx_priv = NULL;
  1258. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1259. return -EINVAL;
  1260. ucontrol->value.integer.value[0] = rx_priv->is_ear_mode_on;
  1261. return 0;
  1262. }
  1263. static int rx_macro_put_ear_mode(struct snd_kcontrol *kcontrol,
  1264. struct snd_ctl_elem_value *ucontrol)
  1265. {
  1266. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1267. struct device *rx_dev = NULL;
  1268. struct rx_macro_priv *rx_priv = NULL;
  1269. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1270. return -EINVAL;
  1271. rx_priv->is_ear_mode_on =
  1272. (!ucontrol->value.integer.value[0] ? false : true);
  1273. return 0;
  1274. }
  1275. static int rx_macro_vbat_bcl_gsm_mode_func_get(struct snd_kcontrol *kcontrol,
  1276. struct snd_ctl_elem_value *ucontrol)
  1277. {
  1278. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1279. ucontrol->value.integer.value[0] =
  1280. ((snd_soc_read(codec, BOLERO_CDC_RX_BCL_VBAT_CFG) & 0x04) ?
  1281. 1 : 0);
  1282. dev_dbg(codec->dev, "%s: value: %lu\n", __func__,
  1283. ucontrol->value.integer.value[0]);
  1284. return 0;
  1285. }
  1286. static int rx_macro_vbat_bcl_gsm_mode_func_put(struct snd_kcontrol *kcontrol,
  1287. struct snd_ctl_elem_value *ucontrol)
  1288. {
  1289. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1290. dev_dbg(codec->dev, "%s: value: %lu\n", __func__,
  1291. ucontrol->value.integer.value[0]);
  1292. /* Set Vbat register configuration for GSM mode bit based on value */
  1293. if (ucontrol->value.integer.value[0])
  1294. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1295. 0x04, 0x04);
  1296. else
  1297. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1298. 0x04, 0x00);
  1299. return 0;
  1300. }
  1301. static int rx_macro_soft_clip_enable_get(struct snd_kcontrol *kcontrol,
  1302. struct snd_ctl_elem_value *ucontrol)
  1303. {
  1304. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1305. struct device *rx_dev = NULL;
  1306. struct rx_macro_priv *rx_priv = NULL;
  1307. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1308. return -EINVAL;
  1309. ucontrol->value.integer.value[0] = rx_priv->is_softclip_on;
  1310. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1311. __func__, ucontrol->value.integer.value[0]);
  1312. return 0;
  1313. }
  1314. static int rx_macro_soft_clip_enable_put(struct snd_kcontrol *kcontrol,
  1315. struct snd_ctl_elem_value *ucontrol)
  1316. {
  1317. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1318. struct device *rx_dev = NULL;
  1319. struct rx_macro_priv *rx_priv = NULL;
  1320. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1321. return -EINVAL;
  1322. rx_priv->is_softclip_on = ucontrol->value.integer.value[0];
  1323. dev_dbg(codec->dev, "%s: soft clip enable = %d\n", __func__,
  1324. rx_priv->is_softclip_on);
  1325. return 0;
  1326. }
  1327. static int rx_macro_enable_vbat(struct snd_soc_dapm_widget *w,
  1328. struct snd_kcontrol *kcontrol,
  1329. int event)
  1330. {
  1331. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1332. struct device *rx_dev = NULL;
  1333. struct rx_macro_priv *rx_priv = NULL;
  1334. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1335. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1336. return -EINVAL;
  1337. switch (event) {
  1338. case SND_SOC_DAPM_PRE_PMU:
  1339. /* Enable clock for VBAT block */
  1340. snd_soc_update_bits(codec,
  1341. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x10);
  1342. /* Enable VBAT block */
  1343. snd_soc_update_bits(codec,
  1344. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x01);
  1345. /* Update interpolator with 384K path */
  1346. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1347. 0x80, 0x80);
  1348. /* Update DSM FS rate */
  1349. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1350. 0x02, 0x02);
  1351. /* Use attenuation mode */
  1352. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1353. 0x02, 0x00);
  1354. /* BCL block needs softclip clock to be enabled */
  1355. rx_macro_enable_softclip_clk(codec, rx_priv, true);
  1356. /* Enable VBAT at channel level */
  1357. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1358. 0x02, 0x02);
  1359. /* Set the ATTK1 gain */
  1360. snd_soc_update_bits(codec,
  1361. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1362. 0xFF, 0xFF);
  1363. snd_soc_update_bits(codec,
  1364. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1365. 0xFF, 0x03);
  1366. snd_soc_update_bits(codec,
  1367. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1368. 0xFF, 0x00);
  1369. /* Set the ATTK2 gain */
  1370. snd_soc_update_bits(codec,
  1371. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1372. 0xFF, 0xFF);
  1373. snd_soc_update_bits(codec,
  1374. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1375. 0xFF, 0x03);
  1376. snd_soc_update_bits(codec,
  1377. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1378. 0xFF, 0x00);
  1379. /* Set the ATTK3 gain */
  1380. snd_soc_update_bits(codec,
  1381. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1382. 0xFF, 0xFF);
  1383. snd_soc_update_bits(codec,
  1384. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1385. 0xFF, 0x03);
  1386. snd_soc_update_bits(codec,
  1387. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1388. 0xFF, 0x00);
  1389. break;
  1390. case SND_SOC_DAPM_POST_PMD:
  1391. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1392. 0x80, 0x00);
  1393. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7,
  1394. 0x02, 0x00);
  1395. snd_soc_update_bits(codec, BOLERO_CDC_RX_BCL_VBAT_CFG,
  1396. 0x02, 0x02);
  1397. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG1,
  1398. 0x02, 0x00);
  1399. snd_soc_update_bits(codec,
  1400. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD1,
  1401. 0xFF, 0x00);
  1402. snd_soc_update_bits(codec,
  1403. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD2,
  1404. 0xFF, 0x00);
  1405. snd_soc_update_bits(codec,
  1406. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD3,
  1407. 0xFF, 0x00);
  1408. snd_soc_update_bits(codec,
  1409. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD4,
  1410. 0xFF, 0x00);
  1411. snd_soc_update_bits(codec,
  1412. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD5,
  1413. 0xFF, 0x00);
  1414. snd_soc_update_bits(codec,
  1415. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD6,
  1416. 0xFF, 0x00);
  1417. snd_soc_update_bits(codec,
  1418. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD7,
  1419. 0xFF, 0x00);
  1420. snd_soc_update_bits(codec,
  1421. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD8,
  1422. 0xFF, 0x00);
  1423. snd_soc_update_bits(codec,
  1424. BOLERO_CDC_RX_BCL_VBAT_BCL_GAIN_UPD9,
  1425. 0xFF, 0x00);
  1426. rx_macro_enable_softclip_clk(codec, rx_priv, false);
  1427. snd_soc_update_bits(codec,
  1428. BOLERO_CDC_RX_BCL_VBAT_CFG, 0x01, 0x00);
  1429. snd_soc_update_bits(codec,
  1430. BOLERO_CDC_RX_BCL_VBAT_PATH_CTL, 0x10, 0x00);
  1431. break;
  1432. default:
  1433. dev_err(rx_dev, "%s: Invalid event %d\n", __func__, event);
  1434. break;
  1435. }
  1436. return 0;
  1437. }
  1438. static void rx_macro_idle_detect_control(struct snd_soc_codec *codec,
  1439. struct rx_macro_priv *rx_priv,
  1440. int interp, int event)
  1441. {
  1442. int reg = 0, mask = 0, val = 0;
  1443. if (!rx_priv->idle_det_cfg.hph_idle_detect_en)
  1444. return;
  1445. if (interp == INTERP_HPHL) {
  1446. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1447. mask = 0x01;
  1448. val = 0x01;
  1449. }
  1450. if (interp == INTERP_HPHR) {
  1451. reg = BOLERO_CDC_RX_IDLE_DETECT_PATH_CTL;
  1452. mask = 0x02;
  1453. val = 0x02;
  1454. }
  1455. if (reg && SND_SOC_DAPM_EVENT_ON(event))
  1456. snd_soc_update_bits(codec, reg, mask, val);
  1457. if (reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1458. snd_soc_update_bits(codec, reg, mask, 0x00);
  1459. rx_priv->idle_det_cfg.hph_idle_thr = 0;
  1460. snd_soc_write(codec, BOLERO_CDC_RX_IDLE_DETECT_CFG3, 0x0);
  1461. }
  1462. }
  1463. static void rx_macro_hphdelay_lutbypass(struct snd_soc_codec *codec,
  1464. struct rx_macro_priv *rx_priv,
  1465. u16 interp_idx, int event)
  1466. {
  1467. u8 hph_dly_mask = 0;
  1468. u16 hph_lut_bypass_reg = 0;
  1469. u16 hph_comp_ctrl7 = 0;
  1470. switch (interp_idx) {
  1471. case INTERP_HPHL:
  1472. hph_dly_mask = 1;
  1473. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHL_COMP_LUT;
  1474. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER0_CTL7;
  1475. break;
  1476. case INTERP_HPHR:
  1477. hph_dly_mask = 2;
  1478. hph_lut_bypass_reg = BOLERO_CDC_RX_TOP_HPHR_COMP_LUT;
  1479. hph_comp_ctrl7 = BOLERO_CDC_RX_COMPANDER1_CTL7;
  1480. break;
  1481. default:
  1482. break;
  1483. }
  1484. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  1485. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_TEST0,
  1486. hph_dly_mask, 0x0);
  1487. if (interp_idx == INTERP_HPHL) {
  1488. if (rx_priv->is_ear_mode_on)
  1489. snd_soc_update_bits(codec,
  1490. BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1491. 0x02, 0x02);
  1492. else
  1493. snd_soc_update_bits(codec,
  1494. hph_lut_bypass_reg,
  1495. 0x80, 0x80);
  1496. } else {
  1497. snd_soc_update_bits(codec,
  1498. hph_lut_bypass_reg,
  1499. 0x80, 0x80);
  1500. }
  1501. }
  1502. if (hph_lut_bypass_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  1503. snd_soc_update_bits(codec, BOLERO_CDC_RX_CLSH_TEST0,
  1504. hph_dly_mask, hph_dly_mask);
  1505. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG1,
  1506. 0x02, 0x00);
  1507. snd_soc_update_bits(codec, hph_lut_bypass_reg, 0x80, 0x00);
  1508. snd_soc_update_bits(codec, hph_comp_ctrl7, 0x20, 0x0);
  1509. }
  1510. }
  1511. static int rx_macro_enable_interp_clk(struct snd_soc_codec *codec,
  1512. int event, int interp_idx)
  1513. {
  1514. u16 main_reg = 0;
  1515. struct device *rx_dev = NULL;
  1516. struct rx_macro_priv *rx_priv = NULL;
  1517. if (!codec) {
  1518. pr_err("%s: codec is NULL\n", __func__);
  1519. return -EINVAL;
  1520. }
  1521. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1522. return -EINVAL;
  1523. main_reg = BOLERO_CDC_RX_RX0_RX_PATH_CTL +
  1524. (interp_idx * RX_MACRO_RX_PATH_OFFSET);
  1525. if (SND_SOC_DAPM_EVENT_ON(event)) {
  1526. if (rx_priv->main_clk_users[interp_idx] == 0) {
  1527. /* Main path PGA mute enable */
  1528. snd_soc_update_bits(codec, main_reg, 0x10, 0x10);
  1529. /* Clk enable */
  1530. snd_soc_update_bits(codec, main_reg, 0x20, 0x20);
  1531. rx_macro_idle_detect_control(codec, rx_priv,
  1532. interp_idx, event);
  1533. rx_macro_hd2_control(codec, interp_idx, event);
  1534. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1535. event);
  1536. rx_macro_config_compander(codec, rx_priv,
  1537. interp_idx, event);
  1538. if (interp_idx == INTERP_AUX)
  1539. rx_macro_config_softclip(codec, rx_priv,
  1540. event);
  1541. rx_macro_config_classh(codec, rx_priv,
  1542. interp_idx, event);
  1543. }
  1544. rx_priv->main_clk_users[interp_idx]++;
  1545. }
  1546. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  1547. rx_priv->main_clk_users[interp_idx]--;
  1548. if (rx_priv->main_clk_users[interp_idx] <= 0) {
  1549. rx_priv->main_clk_users[interp_idx] = 0;
  1550. rx_macro_config_classh(codec, rx_priv,
  1551. interp_idx, event);
  1552. rx_macro_config_compander(codec, rx_priv,
  1553. interp_idx, event);
  1554. if (interp_idx == INTERP_AUX)
  1555. rx_macro_config_softclip(codec, rx_priv,
  1556. event);
  1557. rx_macro_hphdelay_lutbypass(codec, rx_priv, interp_idx,
  1558. event);
  1559. rx_macro_hd2_control(codec, interp_idx, event);
  1560. rx_macro_idle_detect_control(codec, rx_priv,
  1561. interp_idx, event);
  1562. /* Clk Disable */
  1563. snd_soc_update_bits(codec, main_reg, 0x20, 0x00);
  1564. /* Reset enable and disable */
  1565. snd_soc_update_bits(codec, main_reg, 0x40, 0x40);
  1566. snd_soc_update_bits(codec, main_reg, 0x40, 0x00);
  1567. /* Reset rate to 48K*/
  1568. snd_soc_update_bits(codec, main_reg, 0x0F, 0x04);
  1569. }
  1570. }
  1571. dev_dbg(codec->dev, "%s event %d main_clk_users %d\n",
  1572. __func__, event, rx_priv->main_clk_users[interp_idx]);
  1573. return rx_priv->main_clk_users[interp_idx];
  1574. }
  1575. static int rx_macro_enable_rx_path_clk(struct snd_soc_dapm_widget *w,
  1576. struct snd_kcontrol *kcontrol, int event)
  1577. {
  1578. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1579. u16 sidetone_reg = 0;
  1580. dev_dbg(codec->dev, "%s %d %d\n", __func__, event, w->shift);
  1581. sidetone_reg = BOLERO_CDC_RX_RX0_RX_PATH_CFG1 +
  1582. RX_MACRO_RX_PATH_OFFSET * (w->shift);
  1583. switch (event) {
  1584. case SND_SOC_DAPM_PRE_PMU:
  1585. rx_macro_enable_interp_clk(codec, event, w->shift);
  1586. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x10);
  1587. break;
  1588. case SND_SOC_DAPM_POST_PMD:
  1589. snd_soc_update_bits(codec, sidetone_reg, 0x10, 0x00);
  1590. rx_macro_enable_interp_clk(codec, event, w->shift);
  1591. break;
  1592. default:
  1593. break;
  1594. };
  1595. return 0;
  1596. }
  1597. static void rx_macro_restore_iir_coeff(struct rx_macro_priv *rx_priv, int iir_idx,
  1598. int band_idx)
  1599. {
  1600. u16 reg_add = 0, coeff_idx = 0, idx = 0;
  1601. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  1602. regmap_write(regmap,
  1603. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1604. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  1605. reg_add = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx;
  1606. /* 5 coefficients per band and 4 writes per coefficient */
  1607. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  1608. coeff_idx++) {
  1609. /* Four 8 bit values(one 32 bit) per coefficient */
  1610. regmap_write(regmap, reg_add,
  1611. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1612. regmap_write(regmap, reg_add,
  1613. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1614. regmap_write(regmap, reg_add,
  1615. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1616. regmap_write(regmap, reg_add,
  1617. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++]);
  1618. }
  1619. }
  1620. static int rx_macro_iir_enable_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1621. struct snd_ctl_elem_value *ucontrol)
  1622. {
  1623. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1624. int iir_idx = ((struct soc_multi_mixer_control *)
  1625. kcontrol->private_value)->reg;
  1626. int band_idx = ((struct soc_multi_mixer_control *)
  1627. kcontrol->private_value)->shift;
  1628. /* IIR filter band registers are at integer multiples of 0x80 */
  1629. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1630. ucontrol->value.integer.value[0] = (snd_soc_read(codec, iir_reg) &
  1631. (1 << band_idx)) != 0;
  1632. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1633. iir_idx, band_idx,
  1634. (uint32_t)ucontrol->value.integer.value[0]);
  1635. return 0;
  1636. }
  1637. static int rx_macro_iir_enable_audio_mixer_put(struct snd_kcontrol *kcontrol,
  1638. struct snd_ctl_elem_value *ucontrol)
  1639. {
  1640. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1641. int iir_idx = ((struct soc_multi_mixer_control *)
  1642. kcontrol->private_value)->reg;
  1643. int band_idx = ((struct soc_multi_mixer_control *)
  1644. kcontrol->private_value)->shift;
  1645. bool iir_band_en_status = 0;
  1646. int value = ucontrol->value.integer.value[0];
  1647. u16 iir_reg = BOLERO_CDC_RX_SIDETONE_IIR0_IIR_CTL + 0x80 * iir_idx;
  1648. struct device *rx_dev = NULL;
  1649. struct rx_macro_priv *rx_priv = NULL;
  1650. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1651. return -EINVAL;
  1652. rx_macro_restore_iir_coeff(rx_priv, iir_idx, band_idx);
  1653. /* Mask first 5 bits, 6-8 are reserved */
  1654. snd_soc_update_bits(codec, iir_reg, (1 << band_idx),
  1655. (value << band_idx));
  1656. iir_band_en_status = ((snd_soc_read(codec, iir_reg) &
  1657. (1 << band_idx)) != 0);
  1658. dev_dbg(codec->dev, "%s: IIR #%d band #%d enable %d\n", __func__,
  1659. iir_idx, band_idx, iir_band_en_status);
  1660. return 0;
  1661. }
  1662. static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec,
  1663. int iir_idx, int band_idx,
  1664. int coeff_idx)
  1665. {
  1666. uint32_t value = 0;
  1667. /* Address does not automatically update if reading */
  1668. snd_soc_write(codec,
  1669. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1670. ((band_idx * BAND_MAX + coeff_idx)
  1671. * sizeof(uint32_t)) & 0x7F);
  1672. value |= snd_soc_read(codec,
  1673. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx));
  1674. snd_soc_write(codec,
  1675. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1676. ((band_idx * BAND_MAX + coeff_idx)
  1677. * sizeof(uint32_t) + 1) & 0x7F);
  1678. value |= (snd_soc_read(codec,
  1679. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1680. 0x80 * iir_idx)) << 8);
  1681. snd_soc_write(codec,
  1682. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1683. ((band_idx * BAND_MAX + coeff_idx)
  1684. * sizeof(uint32_t) + 2) & 0x7F);
  1685. value |= (snd_soc_read(codec,
  1686. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1687. 0x80 * iir_idx)) << 16);
  1688. snd_soc_write(codec,
  1689. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 0x80 * iir_idx),
  1690. ((band_idx * BAND_MAX + coeff_idx)
  1691. * sizeof(uint32_t) + 3) & 0x7F);
  1692. /* Mask bits top 2 bits since they are reserved */
  1693. value |= ((snd_soc_read(codec,
  1694. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL +
  1695. 16 * iir_idx)) & 0x3F) << 24);
  1696. return value;
  1697. }
  1698. static int rx_macro_iir_band_audio_mixer_get(struct snd_kcontrol *kcontrol,
  1699. struct snd_ctl_elem_value *ucontrol)
  1700. {
  1701. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1702. int iir_idx = ((struct soc_multi_mixer_control *)
  1703. kcontrol->private_value)->reg;
  1704. int band_idx = ((struct soc_multi_mixer_control *)
  1705. kcontrol->private_value)->shift;
  1706. ucontrol->value.integer.value[0] =
  1707. get_iir_band_coeff(codec, iir_idx, band_idx, 0);
  1708. ucontrol->value.integer.value[1] =
  1709. get_iir_band_coeff(codec, iir_idx, band_idx, 1);
  1710. ucontrol->value.integer.value[2] =
  1711. get_iir_band_coeff(codec, iir_idx, band_idx, 2);
  1712. ucontrol->value.integer.value[3] =
  1713. get_iir_band_coeff(codec, iir_idx, band_idx, 3);
  1714. ucontrol->value.integer.value[4] =
  1715. get_iir_band_coeff(codec, iir_idx, band_idx, 4);
  1716. dev_dbg(codec->dev, "%s: IIR #%d band #%d b0 = 0x%x\n"
  1717. "%s: IIR #%d band #%d b1 = 0x%x\n"
  1718. "%s: IIR #%d band #%d b2 = 0x%x\n"
  1719. "%s: IIR #%d band #%d a1 = 0x%x\n"
  1720. "%s: IIR #%d band #%d a2 = 0x%x\n",
  1721. __func__, iir_idx, band_idx,
  1722. (uint32_t)ucontrol->value.integer.value[0],
  1723. __func__, iir_idx, band_idx,
  1724. (uint32_t)ucontrol->value.integer.value[1],
  1725. __func__, iir_idx, band_idx,
  1726. (uint32_t)ucontrol->value.integer.value[2],
  1727. __func__, iir_idx, band_idx,
  1728. (uint32_t)ucontrol->value.integer.value[3],
  1729. __func__, iir_idx, band_idx,
  1730. (uint32_t)ucontrol->value.integer.value[4]);
  1731. return 0;
  1732. }
  1733. static void set_iir_band_coeff(struct snd_soc_codec *codec,
  1734. int iir_idx, int band_idx,
  1735. uint32_t value)
  1736. {
  1737. snd_soc_write(codec,
  1738. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1739. (value & 0xFF));
  1740. snd_soc_write(codec,
  1741. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1742. (value >> 8) & 0xFF);
  1743. snd_soc_write(codec,
  1744. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1745. (value >> 16) & 0xFF);
  1746. /* Mask top 2 bits, 7-8 are reserved */
  1747. snd_soc_write(codec,
  1748. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B2_CTL + 0x80 * iir_idx),
  1749. (value >> 24) & 0x3F);
  1750. }
  1751. static int rx_macro_iir_band_audio_mixer_put(struct snd_kcontrol *kcontrol,
  1752. struct snd_ctl_elem_value *ucontrol)
  1753. {
  1754. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1755. int iir_idx = ((struct soc_multi_mixer_control *)
  1756. kcontrol->private_value)->reg;
  1757. int band_idx = ((struct soc_multi_mixer_control *)
  1758. kcontrol->private_value)->shift;
  1759. int coeff_idx, idx = 0;
  1760. struct device *rx_dev = NULL;
  1761. struct rx_macro_priv *rx_priv = NULL;
  1762. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  1763. return -EINVAL;
  1764. /*
  1765. * Mask top bit it is reserved
  1766. * Updates addr automatically for each B2 write
  1767. */
  1768. snd_soc_write(codec,
  1769. (BOLERO_CDC_RX_SIDETONE_IIR0_IIR_COEF_B1_CTL + 16 * iir_idx),
  1770. (band_idx * BAND_MAX * sizeof(uint32_t)) & 0x7F);
  1771. /* Store the coefficients in sidetone coeff array */
  1772. for (coeff_idx = 0; coeff_idx < RX_MACRO_SIDETONE_IIR_COEFF_MAX;
  1773. coeff_idx++) {
  1774. uint32_t value = ucontrol->value.integer.value[coeff_idx];
  1775. set_iir_band_coeff(codec, iir_idx, band_idx, value);
  1776. /* Four 8 bit values(one 32 bit) per coefficient */
  1777. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1778. (value & 0xFF);
  1779. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1780. (value >> 8) & 0xFF;
  1781. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1782. (value >> 16) & 0xFF;
  1783. rx_priv->sidetone_coeff_array[iir_idx][band_idx][idx++] =
  1784. (value >> 24) & 0xFF;
  1785. }
  1786. pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n"
  1787. "%s: IIR #%d band #%d b1 = 0x%x\n"
  1788. "%s: IIR #%d band #%d b2 = 0x%x\n"
  1789. "%s: IIR #%d band #%d a1 = 0x%x\n"
  1790. "%s: IIR #%d band #%d a2 = 0x%x\n",
  1791. __func__, iir_idx, band_idx,
  1792. get_iir_band_coeff(codec, iir_idx, band_idx, 0),
  1793. __func__, iir_idx, band_idx,
  1794. get_iir_band_coeff(codec, iir_idx, band_idx, 1),
  1795. __func__, iir_idx, band_idx,
  1796. get_iir_band_coeff(codec, iir_idx, band_idx, 2),
  1797. __func__, iir_idx, band_idx,
  1798. get_iir_band_coeff(codec, iir_idx, band_idx, 3),
  1799. __func__, iir_idx, band_idx,
  1800. get_iir_band_coeff(codec, iir_idx, band_idx, 4));
  1801. return 0;
  1802. }
  1803. static int rx_macro_set_iir_gain(struct snd_soc_dapm_widget *w,
  1804. struct snd_kcontrol *kcontrol, int event)
  1805. {
  1806. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1807. dev_dbg(codec->dev, "%s: event = %d\n", __func__, event);
  1808. switch (event) {
  1809. case SND_SOC_DAPM_POST_PMU: /* fall through */
  1810. case SND_SOC_DAPM_PRE_PMD:
  1811. if (strnstr(w->name, "IIR0", sizeof("IIR0"))) {
  1812. snd_soc_write(codec,
  1813. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL,
  1814. snd_soc_read(codec,
  1815. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL));
  1816. snd_soc_write(codec,
  1817. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL,
  1818. snd_soc_read(codec,
  1819. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL));
  1820. snd_soc_write(codec,
  1821. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL,
  1822. snd_soc_read(codec,
  1823. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL));
  1824. snd_soc_write(codec,
  1825. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL,
  1826. snd_soc_read(codec,
  1827. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL));
  1828. } else {
  1829. snd_soc_write(codec,
  1830. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL,
  1831. snd_soc_read(codec,
  1832. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL));
  1833. snd_soc_write(codec,
  1834. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL,
  1835. snd_soc_read(codec,
  1836. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL));
  1837. snd_soc_write(codec,
  1838. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL,
  1839. snd_soc_read(codec,
  1840. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL));
  1841. snd_soc_write(codec,
  1842. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL,
  1843. snd_soc_read(codec,
  1844. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL));
  1845. }
  1846. break;
  1847. }
  1848. return 0;
  1849. }
  1850. static const struct snd_kcontrol_new rx_macro_snd_controls[] = {
  1851. SOC_SINGLE_SX_TLV("RX_RX0 Digital Volume",
  1852. BOLERO_CDC_RX_RX0_RX_VOL_CTL,
  1853. 0, -84, 40, digital_gain),
  1854. SOC_SINGLE_SX_TLV("RX_RX1 Digital Volume",
  1855. BOLERO_CDC_RX_RX1_RX_VOL_CTL,
  1856. 0, -84, 40, digital_gain),
  1857. SOC_SINGLE_SX_TLV("RX_RX2 Digital Volume",
  1858. BOLERO_CDC_RX_RX2_RX_VOL_CTL,
  1859. 0, -84, 40, digital_gain),
  1860. SOC_SINGLE_SX_TLV("RX_RX0 Mix Digital Volume",
  1861. BOLERO_CDC_RX_RX0_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1862. SOC_SINGLE_SX_TLV("RX_RX1 Mix Digital Volume",
  1863. BOLERO_CDC_RX_RX1_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1864. SOC_SINGLE_SX_TLV("RX_RX2 Mix Digital Volume",
  1865. BOLERO_CDC_RX_RX2_RX_VOL_MIX_CTL, 0, -84, 40, digital_gain),
  1866. SOC_SINGLE_EXT("RX_COMP1 Switch", SND_SOC_NOPM, RX_MACRO_COMP1, 1, 0,
  1867. rx_macro_get_compander, rx_macro_set_compander),
  1868. SOC_SINGLE_EXT("RX_COMP2 Switch", SND_SOC_NOPM, RX_MACRO_COMP2, 1, 0,
  1869. rx_macro_get_compander, rx_macro_set_compander),
  1870. SOC_ENUM_EXT("RX_EAR Mode", rx_macro_ear_mode_enum,
  1871. rx_macro_get_ear_mode, rx_macro_put_ear_mode),
  1872. SOC_ENUM_EXT("RX_GSM mode Enable", rx_macro_vbat_bcl_gsm_mode_enum,
  1873. rx_macro_vbat_bcl_gsm_mode_func_get,
  1874. rx_macro_vbat_bcl_gsm_mode_func_put),
  1875. SOC_SINGLE_EXT("RX_Softclip Enable", SND_SOC_NOPM, 0, 1, 0,
  1876. rx_macro_soft_clip_enable_get,
  1877. rx_macro_soft_clip_enable_put),
  1878. SOC_SINGLE_SX_TLV("IIR0 INP0 Volume",
  1879. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B1_CTL, 0, -84, 40,
  1880. digital_gain),
  1881. SOC_SINGLE_SX_TLV("IIR0 INP1 Volume",
  1882. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B2_CTL, 0, -84, 40,
  1883. digital_gain),
  1884. SOC_SINGLE_SX_TLV("IIR0 INP2 Volume",
  1885. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B3_CTL, 0, -84, 40,
  1886. digital_gain),
  1887. SOC_SINGLE_SX_TLV("IIR0 INP3 Volume",
  1888. BOLERO_CDC_RX_SIDETONE_IIR0_IIR_GAIN_B4_CTL, 0, -84, 40,
  1889. digital_gain),
  1890. SOC_SINGLE_SX_TLV("IIR1 INP0 Volume",
  1891. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B1_CTL, 0, -84, 40,
  1892. digital_gain),
  1893. SOC_SINGLE_SX_TLV("IIR1 INP1 Volume",
  1894. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B2_CTL, 0, -84, 40,
  1895. digital_gain),
  1896. SOC_SINGLE_SX_TLV("IIR1 INP2 Volume",
  1897. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B3_CTL, 0, -84, 40,
  1898. digital_gain),
  1899. SOC_SINGLE_SX_TLV("IIR1 INP3 Volume",
  1900. BOLERO_CDC_RX_SIDETONE_IIR1_IIR_GAIN_B4_CTL, 0, -84, 40,
  1901. digital_gain),
  1902. SOC_SINGLE_EXT("IIR0 Enable Band1", IIR0, BAND1, 1, 0,
  1903. rx_macro_iir_enable_audio_mixer_get,
  1904. rx_macro_iir_enable_audio_mixer_put),
  1905. SOC_SINGLE_EXT("IIR0 Enable Band2", IIR0, BAND2, 1, 0,
  1906. rx_macro_iir_enable_audio_mixer_get,
  1907. rx_macro_iir_enable_audio_mixer_put),
  1908. SOC_SINGLE_EXT("IIR0 Enable Band3", IIR0, BAND3, 1, 0,
  1909. rx_macro_iir_enable_audio_mixer_get,
  1910. rx_macro_iir_enable_audio_mixer_put),
  1911. SOC_SINGLE_EXT("IIR0 Enable Band4", IIR0, BAND4, 1, 0,
  1912. rx_macro_iir_enable_audio_mixer_get,
  1913. rx_macro_iir_enable_audio_mixer_put),
  1914. SOC_SINGLE_EXT("IIR0 Enable Band5", IIR0, BAND5, 1, 0,
  1915. rx_macro_iir_enable_audio_mixer_get,
  1916. rx_macro_iir_enable_audio_mixer_put),
  1917. SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0,
  1918. rx_macro_iir_enable_audio_mixer_get,
  1919. rx_macro_iir_enable_audio_mixer_put),
  1920. SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0,
  1921. rx_macro_iir_enable_audio_mixer_get,
  1922. rx_macro_iir_enable_audio_mixer_put),
  1923. SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0,
  1924. rx_macro_iir_enable_audio_mixer_get,
  1925. rx_macro_iir_enable_audio_mixer_put),
  1926. SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0,
  1927. rx_macro_iir_enable_audio_mixer_get,
  1928. rx_macro_iir_enable_audio_mixer_put),
  1929. SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0,
  1930. rx_macro_iir_enable_audio_mixer_get,
  1931. rx_macro_iir_enable_audio_mixer_put),
  1932. SOC_SINGLE_MULTI_EXT("IIR0 Band1", IIR0, BAND1, 255, 0, 5,
  1933. rx_macro_iir_band_audio_mixer_get,
  1934. rx_macro_iir_band_audio_mixer_put),
  1935. SOC_SINGLE_MULTI_EXT("IIR0 Band2", IIR0, BAND2, 255, 0, 5,
  1936. rx_macro_iir_band_audio_mixer_get,
  1937. rx_macro_iir_band_audio_mixer_put),
  1938. SOC_SINGLE_MULTI_EXT("IIR0 Band3", IIR0, BAND3, 255, 0, 5,
  1939. rx_macro_iir_band_audio_mixer_get,
  1940. rx_macro_iir_band_audio_mixer_put),
  1941. SOC_SINGLE_MULTI_EXT("IIR0 Band4", IIR0, BAND4, 255, 0, 5,
  1942. rx_macro_iir_band_audio_mixer_get,
  1943. rx_macro_iir_band_audio_mixer_put),
  1944. SOC_SINGLE_MULTI_EXT("IIR0 Band5", IIR0, BAND5, 255, 0, 5,
  1945. rx_macro_iir_band_audio_mixer_get,
  1946. rx_macro_iir_band_audio_mixer_put),
  1947. SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5,
  1948. rx_macro_iir_band_audio_mixer_get,
  1949. rx_macro_iir_band_audio_mixer_put),
  1950. SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5,
  1951. rx_macro_iir_band_audio_mixer_get,
  1952. rx_macro_iir_band_audio_mixer_put),
  1953. SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5,
  1954. rx_macro_iir_band_audio_mixer_get,
  1955. rx_macro_iir_band_audio_mixer_put),
  1956. SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5,
  1957. rx_macro_iir_band_audio_mixer_get,
  1958. rx_macro_iir_band_audio_mixer_put),
  1959. SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5,
  1960. rx_macro_iir_band_audio_mixer_get,
  1961. rx_macro_iir_band_audio_mixer_put),
  1962. };
  1963. static const struct snd_soc_dapm_widget rx_macro_dapm_widgets[] = {
  1964. SND_SOC_DAPM_AIF_IN("RX AIF1 PB", "RX_MACRO_AIF1 Playback", 0,
  1965. SND_SOC_NOPM, 0, 0),
  1966. SND_SOC_DAPM_AIF_IN("RX AIF2 PB", "RX_MACRO_AIF2 Playback", 0,
  1967. SND_SOC_NOPM, 0, 0),
  1968. SND_SOC_DAPM_AIF_IN("RX AIF3 PB", "RX_MACRO_AIF3 Playback", 0,
  1969. SND_SOC_NOPM, 0, 0),
  1970. SND_SOC_DAPM_AIF_IN("RX AIF4 PB", "RX_MACRO_AIF4 Playback", 0,
  1971. SND_SOC_NOPM, 0, 0),
  1972. RX_MACRO_DAPM_MUX("RX_MACRO RX0 MUX", RX_MACRO_RX0, rx_macro_rx0),
  1973. RX_MACRO_DAPM_MUX("RX_MACRO RX1 MUX", RX_MACRO_RX1, rx_macro_rx1),
  1974. RX_MACRO_DAPM_MUX("RX_MACRO RX2 MUX", RX_MACRO_RX2, rx_macro_rx2),
  1975. RX_MACRO_DAPM_MUX("RX_MACRO RX3 MUX", RX_MACRO_RX3, rx_macro_rx3),
  1976. RX_MACRO_DAPM_MUX("RX_MACRO RX4 MUX", RX_MACRO_RX4, rx_macro_rx4),
  1977. RX_MACRO_DAPM_MUX("RX_MACRO RX5 MUX", RX_MACRO_RX5, rx_macro_rx5),
  1978. SND_SOC_DAPM_MIXER("RX_RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  1979. SND_SOC_DAPM_MIXER("RX_RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1980. SND_SOC_DAPM_MIXER("RX_RX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  1981. SND_SOC_DAPM_MIXER("RX_RX3", SND_SOC_NOPM, 0, 0, NULL, 0),
  1982. SND_SOC_DAPM_MIXER("RX_RX4", SND_SOC_NOPM, 0, 0, NULL, 0),
  1983. SND_SOC_DAPM_MIXER("RX_RX5", SND_SOC_NOPM, 0, 0, NULL, 0),
  1984. RX_MACRO_DAPM_MUX("IIR0 INP0 MUX", 0, iir0_inp0),
  1985. RX_MACRO_DAPM_MUX("IIR0 INP1 MUX", 0, iir0_inp1),
  1986. RX_MACRO_DAPM_MUX("IIR0 INP2 MUX", 0, iir0_inp2),
  1987. RX_MACRO_DAPM_MUX("IIR0 INP3 MUX", 0, iir0_inp3),
  1988. RX_MACRO_DAPM_MUX("IIR1 INP0 MUX", 0, iir1_inp0),
  1989. RX_MACRO_DAPM_MUX("IIR1 INP1 MUX", 0, iir1_inp1),
  1990. RX_MACRO_DAPM_MUX("IIR1 INP2 MUX", 0, iir1_inp2),
  1991. RX_MACRO_DAPM_MUX("IIR1 INP3 MUX", 0, iir1_inp3),
  1992. SND_SOC_DAPM_MIXER_E("IIR0", BOLERO_CDC_RX_SIDETONE_IIR0_IIR_PATH_CTL,
  1993. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  1994. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1995. SND_SOC_DAPM_MIXER_E("IIR1", BOLERO_CDC_RX_SIDETONE_IIR1_IIR_PATH_CTL,
  1996. 4, 0, NULL, 0, rx_macro_set_iir_gain,
  1997. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
  1998. SND_SOC_DAPM_MIXER("SRC0", BOLERO_CDC_RX_SIDETONE_SRC0_ST_SRC_PATH_CTL,
  1999. 4, 0, NULL, 0),
  2000. SND_SOC_DAPM_MIXER("SRC1", BOLERO_CDC_RX_SIDETONE_SRC1_ST_SRC_PATH_CTL,
  2001. 4, 0, NULL, 0),
  2002. RX_MACRO_DAPM_MUX("RX MIX TX0 MUX", 0, rx_mix_tx0),
  2003. RX_MACRO_DAPM_MUX("RX MIX TX1 MUX", 0, rx_mix_tx1),
  2004. RX_MACRO_DAPM_MUX("RX MIX TX2 MUX", 0, rx_mix_tx2),
  2005. RX_MACRO_DAPM_MUX("RX INT0 DEM MUX", 0, rx_int0_dem_inp),
  2006. RX_MACRO_DAPM_MUX("RX INT1 DEM MUX", 0, rx_int1_dem_inp),
  2007. SND_SOC_DAPM_MUX_E("RX INT0_2 MUX", SND_SOC_NOPM, INTERP_HPHL, 0,
  2008. &rx_int0_2_mux, rx_macro_enable_mix_path,
  2009. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2010. SND_SOC_DAPM_POST_PMD),
  2011. SND_SOC_DAPM_MUX_E("RX INT1_2 MUX", SND_SOC_NOPM, INTERP_HPHR, 0,
  2012. &rx_int1_2_mux, rx_macro_enable_mix_path,
  2013. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2014. SND_SOC_DAPM_POST_PMD),
  2015. SND_SOC_DAPM_MUX_E("RX INT2_2 MUX", SND_SOC_NOPM, INTERP_AUX, 0,
  2016. &rx_int2_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. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP0", 0, rx_int0_1_mix_inp0),
  2020. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP1", 0, rx_int0_1_mix_inp1),
  2021. RX_MACRO_DAPM_MUX("RX INT0_1 MIX1 INP2", 0, rx_int0_1_mix_inp2),
  2022. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP0", 0, rx_int1_1_mix_inp0),
  2023. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP1", 0, rx_int1_1_mix_inp1),
  2024. RX_MACRO_DAPM_MUX("RX INT1_1 MIX1 INP2", 0, rx_int1_1_mix_inp2),
  2025. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP0", 0, rx_int2_1_mix_inp0),
  2026. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP1", 0, rx_int2_1_mix_inp1),
  2027. RX_MACRO_DAPM_MUX("RX INT2_1 MIX1 INP2", 0, rx_int2_1_mix_inp2),
  2028. SND_SOC_DAPM_MUX_E("RX INT0_1 INTERP", SND_SOC_NOPM, INTERP_HPHL, 0,
  2029. &rx_int0_1_interp_mux, rx_macro_enable_main_path,
  2030. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2031. SND_SOC_DAPM_POST_PMD),
  2032. SND_SOC_DAPM_MUX_E("RX INT1_1 INTERP", SND_SOC_NOPM, INTERP_HPHR, 0,
  2033. &rx_int1_1_interp_mux, rx_macro_enable_main_path,
  2034. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  2035. SND_SOC_DAPM_POST_PMD),
  2036. SND_SOC_DAPM_MUX_E("RX INT2_1 INTERP", SND_SOC_NOPM, INTERP_AUX, 0,
  2037. &rx_int2_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. RX_MACRO_DAPM_MUX("RX INT0_2 INTERP", 0, rx_int0_2_interp),
  2041. RX_MACRO_DAPM_MUX("RX INT1_2 INTERP", 0, rx_int1_2_interp),
  2042. RX_MACRO_DAPM_MUX("RX INT2_2 INTERP", 0, rx_int2_2_interp),
  2043. SND_SOC_DAPM_MIXER("RX INT0_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2044. SND_SOC_DAPM_MIXER("RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2045. SND_SOC_DAPM_MIXER("RX INT1_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2046. SND_SOC_DAPM_MIXER("RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2047. SND_SOC_DAPM_MIXER("RX INT2_1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  2048. SND_SOC_DAPM_MIXER("RX INT2 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  2049. SND_SOC_DAPM_MUX_E("RX INT0 MIX2 INP", SND_SOC_NOPM, INTERP_HPHL,
  2050. 0, &rx_int0_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2051. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2052. SND_SOC_DAPM_MUX_E("RX INT1 MIX2 INP", SND_SOC_NOPM, INTERP_HPHR,
  2053. 0, &rx_int1_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2054. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2055. SND_SOC_DAPM_MUX_E("RX INT2 MIX2 INP", SND_SOC_NOPM, INTERP_AUX,
  2056. 0, &rx_int2_mix2_inp_mux, rx_macro_enable_rx_path_clk,
  2057. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2058. SND_SOC_DAPM_MIXER_E("RX INT2_1 VBAT", SND_SOC_NOPM,
  2059. 0, 0, rx_int2_1_vbat_mix_switch,
  2060. ARRAY_SIZE(rx_int2_1_vbat_mix_switch),
  2061. rx_macro_enable_vbat,
  2062. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2063. SND_SOC_DAPM_MIXER("RX INT0 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2064. SND_SOC_DAPM_MIXER("RX INT1 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2065. SND_SOC_DAPM_MIXER("RX INT2 MIX2", SND_SOC_NOPM, 0, 0, NULL, 0),
  2066. SND_SOC_DAPM_OUTPUT("HPHL_OUT"),
  2067. SND_SOC_DAPM_OUTPUT("HPHR_OUT"),
  2068. SND_SOC_DAPM_OUTPUT("AUX_OUT"),
  2069. SND_SOC_DAPM_INPUT("RX_TX DEC0_INP"),
  2070. SND_SOC_DAPM_INPUT("RX_TX DEC1_INP"),
  2071. SND_SOC_DAPM_INPUT("RX_TX DEC2_INP"),
  2072. SND_SOC_DAPM_INPUT("RX_TX DEC3_INP"),
  2073. SND_SOC_DAPM_SUPPLY_S("RX_MCLK", 0, SND_SOC_NOPM, 0, 0,
  2074. rx_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  2075. };
  2076. static const struct snd_soc_dapm_route rx_audio_map[] = {
  2077. {"RX AIF1 PB", NULL, "RX_MCLK"},
  2078. {"RX AIF2 PB", NULL, "RX_MCLK"},
  2079. {"RX AIF3 PB", NULL, "RX_MCLK"},
  2080. {"RX AIF4 PB", NULL, "RX_MCLK"},
  2081. {"RX_MACRO RX0 MUX", "AIF1_PB", "RX AIF1 PB"},
  2082. {"RX_MACRO RX1 MUX", "AIF1_PB", "RX AIF1 PB"},
  2083. {"RX_MACRO RX2 MUX", "AIF1_PB", "RX AIF1 PB"},
  2084. {"RX_MACRO RX3 MUX", "AIF1_PB", "RX AIF1 PB"},
  2085. {"RX_MACRO RX4 MUX", "AIF1_PB", "RX AIF1 PB"},
  2086. {"RX_MACRO RX5 MUX", "AIF1_PB", "RX AIF1 PB"},
  2087. {"RX_MACRO RX0 MUX", "AIF2_PB", "RX AIF2 PB"},
  2088. {"RX_MACRO RX1 MUX", "AIF2_PB", "RX AIF2 PB"},
  2089. {"RX_MACRO RX2 MUX", "AIF2_PB", "RX AIF2 PB"},
  2090. {"RX_MACRO RX3 MUX", "AIF2_PB", "RX AIF2 PB"},
  2091. {"RX_MACRO RX4 MUX", "AIF2_PB", "RX AIF2 PB"},
  2092. {"RX_MACRO RX5 MUX", "AIF2_PB", "RX AIF2 PB"},
  2093. {"RX_MACRO RX0 MUX", "AIF3_PB", "RX AIF3 PB"},
  2094. {"RX_MACRO RX1 MUX", "AIF3_PB", "RX AIF3 PB"},
  2095. {"RX_MACRO RX2 MUX", "AIF3_PB", "RX AIF3 PB"},
  2096. {"RX_MACRO RX3 MUX", "AIF3_PB", "RX AIF3 PB"},
  2097. {"RX_MACRO RX4 MUX", "AIF3_PB", "RX AIF3 PB"},
  2098. {"RX_MACRO RX5 MUX", "AIF3_PB", "RX AIF3 PB"},
  2099. {"RX_MACRO RX0 MUX", "AIF4_PB", "RX AIF4 PB"},
  2100. {"RX_MACRO RX1 MUX", "AIF4_PB", "RX AIF4 PB"},
  2101. {"RX_MACRO RX2 MUX", "AIF4_PB", "RX AIF4 PB"},
  2102. {"RX_MACRO RX3 MUX", "AIF4_PB", "RX AIF4 PB"},
  2103. {"RX_MACRO RX4 MUX", "AIF4_PB", "RX AIF4 PB"},
  2104. {"RX_MACRO RX5 MUX", "AIF4_PB", "RX AIF4 PB"},
  2105. {"RX_RX0", NULL, "RX_MACRO RX0 MUX"},
  2106. {"RX_RX1", NULL, "RX_MACRO RX1 MUX"},
  2107. {"RX_RX2", NULL, "RX_MACRO RX2 MUX"},
  2108. {"RX_RX3", NULL, "RX_MACRO RX3 MUX"},
  2109. {"RX_RX4", NULL, "RX_MACRO RX4 MUX"},
  2110. {"RX_RX5", NULL, "RX_MACRO RX5 MUX"},
  2111. {"RX INT0_1 MIX1 INP0", "RX0", "RX_RX0"},
  2112. {"RX INT0_1 MIX1 INP0", "RX1", "RX_RX1"},
  2113. {"RX INT0_1 MIX1 INP0", "RX2", "RX_RX2"},
  2114. {"RX INT0_1 MIX1 INP0", "RX3", "RX_RX3"},
  2115. {"RX INT0_1 MIX1 INP0", "RX4", "RX_RX4"},
  2116. {"RX INT0_1 MIX1 INP0", "RX5", "RX_RX5"},
  2117. {"RX INT0_1 MIX1 INP0", "IIR0", "IIR0"},
  2118. {"RX INT0_1 MIX1 INP0", "IIR1", "IIR1"},
  2119. {"RX INT0_1 MIX1 INP1", "RX0", "RX_RX0"},
  2120. {"RX INT0_1 MIX1 INP1", "RX1", "RX_RX1"},
  2121. {"RX INT0_1 MIX1 INP1", "RX2", "RX_RX2"},
  2122. {"RX INT0_1 MIX1 INP1", "RX3", "RX_RX3"},
  2123. {"RX INT0_1 MIX1 INP1", "RX4", "RX_RX4"},
  2124. {"RX INT0_1 MIX1 INP1", "RX5", "RX_RX5"},
  2125. {"RX INT0_1 MIX1 INP1", "IIR0", "IIR0"},
  2126. {"RX INT0_1 MIX1 INP1", "IIR1", "IIR1"},
  2127. {"RX INT0_1 MIX1 INP2", "RX0", "RX_RX0"},
  2128. {"RX INT0_1 MIX1 INP2", "RX1", "RX_RX1"},
  2129. {"RX INT0_1 MIX1 INP2", "RX2", "RX_RX2"},
  2130. {"RX INT0_1 MIX1 INP2", "RX3", "RX_RX3"},
  2131. {"RX INT0_1 MIX1 INP2", "RX4", "RX_RX4"},
  2132. {"RX INT0_1 MIX1 INP2", "RX5", "RX_RX5"},
  2133. {"RX INT0_1 MIX1 INP2", "IIR0", "IIR0"},
  2134. {"RX INT0_1 MIX1 INP2", "IIR1", "IIR1"},
  2135. {"RX INT1_1 MIX1 INP0", "RX0", "RX_RX0"},
  2136. {"RX INT1_1 MIX1 INP0", "RX1", "RX_RX1"},
  2137. {"RX INT1_1 MIX1 INP0", "RX2", "RX_RX2"},
  2138. {"RX INT1_1 MIX1 INP0", "RX3", "RX_RX3"},
  2139. {"RX INT1_1 MIX1 INP0", "RX4", "RX_RX4"},
  2140. {"RX INT1_1 MIX1 INP0", "RX5", "RX_RX5"},
  2141. {"RX INT1_1 MIX1 INP0", "IIR0", "IIR0"},
  2142. {"RX INT1_1 MIX1 INP0", "IIR1", "IIR1"},
  2143. {"RX INT1_1 MIX1 INP1", "RX0", "RX_RX0"},
  2144. {"RX INT1_1 MIX1 INP1", "RX1", "RX_RX1"},
  2145. {"RX INT1_1 MIX1 INP1", "RX2", "RX_RX2"},
  2146. {"RX INT1_1 MIX1 INP1", "RX3", "RX_RX3"},
  2147. {"RX INT1_1 MIX1 INP1", "RX4", "RX_RX4"},
  2148. {"RX INT1_1 MIX1 INP1", "RX5", "RX_RX5"},
  2149. {"RX INT1_1 MIX1 INP1", "IIR0", "IIR0"},
  2150. {"RX INT1_1 MIX1 INP1", "IIR1", "IIR1"},
  2151. {"RX INT1_1 MIX1 INP2", "RX0", "RX_RX0"},
  2152. {"RX INT1_1 MIX1 INP2", "RX1", "RX_RX1"},
  2153. {"RX INT1_1 MIX1 INP2", "RX2", "RX_RX2"},
  2154. {"RX INT1_1 MIX1 INP2", "RX3", "RX_RX3"},
  2155. {"RX INT1_1 MIX1 INP2", "RX4", "RX_RX4"},
  2156. {"RX INT1_1 MIX1 INP2", "RX5", "RX_RX5"},
  2157. {"RX INT1_1 MIX1 INP2", "IIR0", "IIR0"},
  2158. {"RX INT1_1 MIX1 INP2", "IIR1", "IIR1"},
  2159. {"RX INT2_1 MIX1 INP0", "RX0", "RX_RX0"},
  2160. {"RX INT2_1 MIX1 INP0", "RX1", "RX_RX1"},
  2161. {"RX INT2_1 MIX1 INP0", "RX2", "RX_RX2"},
  2162. {"RX INT2_1 MIX1 INP0", "RX3", "RX_RX3"},
  2163. {"RX INT2_1 MIX1 INP0", "RX4", "RX_RX4"},
  2164. {"RX INT2_1 MIX1 INP0", "RX5", "RX_RX5"},
  2165. {"RX INT2_1 MIX1 INP0", "IIR0", "IIR0"},
  2166. {"RX INT2_1 MIX1 INP0", "IIR1", "IIR1"},
  2167. {"RX INT2_1 MIX1 INP1", "RX0", "RX_RX0"},
  2168. {"RX INT2_1 MIX1 INP1", "RX1", "RX_RX1"},
  2169. {"RX INT2_1 MIX1 INP1", "RX2", "RX_RX2"},
  2170. {"RX INT2_1 MIX1 INP1", "RX3", "RX_RX3"},
  2171. {"RX INT2_1 MIX1 INP1", "RX4", "RX_RX4"},
  2172. {"RX INT2_1 MIX1 INP1", "RX5", "RX_RX5"},
  2173. {"RX INT2_1 MIX1 INP1", "IIR0", "IIR0"},
  2174. {"RX INT2_1 MIX1 INP1", "IIR1", "IIR1"},
  2175. {"RX INT2_1 MIX1 INP2", "RX0", "RX_RX0"},
  2176. {"RX INT2_1 MIX1 INP2", "RX1", "RX_RX1"},
  2177. {"RX INT2_1 MIX1 INP2", "RX2", "RX_RX2"},
  2178. {"RX INT2_1 MIX1 INP2", "RX3", "RX_RX3"},
  2179. {"RX INT2_1 MIX1 INP2", "RX4", "RX_RX4"},
  2180. {"RX INT2_1 MIX1 INP2", "RX5", "RX_RX5"},
  2181. {"RX INT2_1 MIX1 INP2", "IIR0", "IIR0"},
  2182. {"RX INT2_1 MIX1 INP2", "IIR1", "IIR1"},
  2183. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP0"},
  2184. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP1"},
  2185. {"RX INT0_1 MIX1", NULL, "RX INT0_1 MIX1 INP2"},
  2186. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP0"},
  2187. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP1"},
  2188. {"RX INT1_1 MIX1", NULL, "RX INT1_1 MIX1 INP2"},
  2189. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP0"},
  2190. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP1"},
  2191. {"RX INT2_1 MIX1", NULL, "RX INT2_1 MIX1 INP2"},
  2192. /* Mixing path INT0 */
  2193. {"RX INT0_2 MUX", "RX0", "RX_RX0"},
  2194. {"RX INT0_2 MUX", "RX1", "RX_RX1"},
  2195. {"RX INT0_2 MUX", "RX2", "RX_RX2"},
  2196. {"RX INT0_2 MUX", "RX3", "RX_RX3"},
  2197. {"RX INT0_2 MUX", "RX4", "RX_RX4"},
  2198. {"RX INT0_2 MUX", "RX5", "RX_RX5"},
  2199. {"RX INT0_2 INTERP", NULL, "RX INT0_2 MUX"},
  2200. {"RX INT0 SEC MIX", NULL, "RX INT0_2 INTERP"},
  2201. /* Mixing path INT1 */
  2202. {"RX INT1_2 MUX", "RX0", "RX_RX0"},
  2203. {"RX INT1_2 MUX", "RX1", "RX_RX1"},
  2204. {"RX INT1_2 MUX", "RX2", "RX_RX2"},
  2205. {"RX INT1_2 MUX", "RX3", "RX_RX3"},
  2206. {"RX INT1_2 MUX", "RX4", "RX_RX4"},
  2207. {"RX INT1_2 MUX", "RX5", "RX_RX5"},
  2208. {"RX INT1_2 INTERP", NULL, "RX INT1_2 MUX"},
  2209. {"RX INT1 SEC MIX", NULL, "RX INT1_2 INTERP"},
  2210. /* Mixing path INT2 */
  2211. {"RX INT2_2 MUX", "RX0", "RX_RX0"},
  2212. {"RX INT2_2 MUX", "RX1", "RX_RX1"},
  2213. {"RX INT2_2 MUX", "RX2", "RX_RX2"},
  2214. {"RX INT2_2 MUX", "RX3", "RX_RX3"},
  2215. {"RX INT2_2 MUX", "RX4", "RX_RX4"},
  2216. {"RX INT2_2 MUX", "RX5", "RX_RX5"},
  2217. {"RX INT2_2 INTERP", NULL, "RX INT2_2 MUX"},
  2218. {"RX INT2 SEC MIX", NULL, "RX INT2_2 INTERP"},
  2219. {"RX INT0_1 INTERP", NULL, "RX INT0_1 MIX1"},
  2220. {"RX INT0 SEC MIX", NULL, "RX INT0_1 INTERP"},
  2221. {"RX INT0 MIX2", NULL, "RX INT0 SEC MIX"},
  2222. {"RX INT0 MIX2", NULL, "RX INT0 MIX2 INP"},
  2223. {"RX INT0 DEM MUX", "CLSH_DSM_OUT", "RX INT0 MIX2"},
  2224. {"HPHL_OUT", NULL, "RX INT0 DEM MUX"},
  2225. {"HPHL_OUT", NULL, "RX_MCLK"},
  2226. {"RX INT1_1 INTERP", NULL, "RX INT1_1 MIX1"},
  2227. {"RX INT1 SEC MIX", NULL, "RX INT1_1 INTERP"},
  2228. {"RX INT1 MIX2", NULL, "RX INT1 SEC MIX"},
  2229. {"RX INT1 MIX2", NULL, "RX INT1 MIX2 INP"},
  2230. {"RX INT1 DEM MUX", "CLSH_DSM_OUT", "RX INT1 MIX2"},
  2231. {"HPHR_OUT", NULL, "RX INT1 DEM MUX"},
  2232. {"HPHR_OUT", NULL, "RX_MCLK"},
  2233. {"RX INT2_1 INTERP", NULL, "RX INT2_1 MIX1"},
  2234. {"RX INT2_1 VBAT", "RX AUX VBAT Enable", "RX INT2_1 INTERP"},
  2235. {"RX INT2 SEC MIX", NULL, "RX INT2_1 VBAT"},
  2236. {"RX INT2 SEC MIX", NULL, "RX INT2_1 INTERP"},
  2237. {"RX INT2 MIX2", NULL, "RX INT2 SEC MIX"},
  2238. {"RX INT2 MIX2", NULL, "RX INT2 MIX2 INP"},
  2239. {"AUX_OUT", NULL, "RX INT2 MIX2"},
  2240. {"AUX_OUT", NULL, "RX_MCLK"},
  2241. {"IIR0", NULL, "RX_MCLK"},
  2242. {"IIR0", NULL, "IIR0 INP0 MUX"},
  2243. {"IIR0 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2244. {"IIR0 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2245. {"IIR0 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2246. {"IIR0 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2247. {"IIR0 INP0 MUX", "RX0", "RX_RX0"},
  2248. {"IIR0 INP0 MUX", "RX1", "RX_RX1"},
  2249. {"IIR0 INP0 MUX", "RX2", "RX_RX2"},
  2250. {"IIR0 INP0 MUX", "RX3", "RX_RX3"},
  2251. {"IIR0 INP0 MUX", "RX4", "RX_RX4"},
  2252. {"IIR0 INP0 MUX", "RX5", "RX_RX5"},
  2253. {"IIR0", NULL, "IIR0 INP1 MUX"},
  2254. {"IIR0 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2255. {"IIR0 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2256. {"IIR0 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2257. {"IIR0 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2258. {"IIR0 INP1 MUX", "RX0", "RX_RX0"},
  2259. {"IIR0 INP1 MUX", "RX1", "RX_RX1"},
  2260. {"IIR0 INP1 MUX", "RX2", "RX_RX2"},
  2261. {"IIR0 INP1 MUX", "RX3", "RX_RX3"},
  2262. {"IIR0 INP1 MUX", "RX4", "RX_RX4"},
  2263. {"IIR0 INP1 MUX", "RX5", "RX_RX5"},
  2264. {"IIR0", NULL, "IIR0 INP2 MUX"},
  2265. {"IIR0 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2266. {"IIR0 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2267. {"IIR0 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2268. {"IIR0 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2269. {"IIR0 INP2 MUX", "RX0", "RX_RX0"},
  2270. {"IIR0 INP2 MUX", "RX1", "RX_RX1"},
  2271. {"IIR0 INP2 MUX", "RX2", "RX_RX2"},
  2272. {"IIR0 INP2 MUX", "RX3", "RX_RX3"},
  2273. {"IIR0 INP2 MUX", "RX4", "RX_RX4"},
  2274. {"IIR0 INP2 MUX", "RX5", "RX_RX5"},
  2275. {"IIR0", NULL, "IIR0 INP3 MUX"},
  2276. {"IIR0 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2277. {"IIR0 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2278. {"IIR0 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2279. {"IIR0 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2280. {"IIR0 INP3 MUX", "RX0", "RX_RX0"},
  2281. {"IIR0 INP3 MUX", "RX1", "RX_RX1"},
  2282. {"IIR0 INP3 MUX", "RX2", "RX_RX2"},
  2283. {"IIR0 INP3 MUX", "RX3", "RX_RX3"},
  2284. {"IIR0 INP3 MUX", "RX4", "RX_RX4"},
  2285. {"IIR0 INP3 MUX", "RX5", "RX_RX5"},
  2286. {"IIR1", NULL, "RX_MCLK"},
  2287. {"IIR1", NULL, "IIR1 INP0 MUX"},
  2288. {"IIR1 INP0 MUX", "DEC0", "RX_TX DEC0_INP"},
  2289. {"IIR1 INP0 MUX", "DEC1", "RX_TX DEC1_INP"},
  2290. {"IIR1 INP0 MUX", "DEC2", "RX_TX DEC2_INP"},
  2291. {"IIR1 INP0 MUX", "DEC3", "RX_TX DEC3_INP"},
  2292. {"IIR1 INP0 MUX", "RX0", "RX_RX0"},
  2293. {"IIR1 INP0 MUX", "RX1", "RX_RX1"},
  2294. {"IIR1 INP0 MUX", "RX2", "RX_RX2"},
  2295. {"IIR1 INP0 MUX", "RX3", "RX_RX3"},
  2296. {"IIR1 INP0 MUX", "RX4", "RX_RX4"},
  2297. {"IIR1 INP0 MUX", "RX5", "RX_RX5"},
  2298. {"IIR1", NULL, "IIR1 INP1 MUX"},
  2299. {"IIR1 INP1 MUX", "DEC0", "RX_TX DEC0_INP"},
  2300. {"IIR1 INP1 MUX", "DEC1", "RX_TX DEC1_INP"},
  2301. {"IIR1 INP1 MUX", "DEC2", "RX_TX DEC2_INP"},
  2302. {"IIR1 INP1 MUX", "DEC3", "RX_TX DEC3_INP"},
  2303. {"IIR1 INP1 MUX", "RX0", "RX_RX0"},
  2304. {"IIR1 INP1 MUX", "RX1", "RX_RX1"},
  2305. {"IIR1 INP1 MUX", "RX2", "RX_RX2"},
  2306. {"IIR1 INP1 MUX", "RX3", "RX_RX3"},
  2307. {"IIR1 INP1 MUX", "RX4", "RX_RX4"},
  2308. {"IIR1 INP1 MUX", "RX5", "RX_RX5"},
  2309. {"IIR1", NULL, "IIR1 INP2 MUX"},
  2310. {"IIR1 INP2 MUX", "DEC0", "RX_TX DEC0_INP"},
  2311. {"IIR1 INP2 MUX", "DEC1", "RX_TX DEC1_INP"},
  2312. {"IIR1 INP2 MUX", "DEC2", "RX_TX DEC2_INP"},
  2313. {"IIR1 INP2 MUX", "DEC3", "RX_TX DEC3_INP"},
  2314. {"IIR1 INP2 MUX", "RX0", "RX_RX0"},
  2315. {"IIR1 INP2 MUX", "RX1", "RX_RX1"},
  2316. {"IIR1 INP2 MUX", "RX2", "RX_RX2"},
  2317. {"IIR1 INP2 MUX", "RX3", "RX_RX3"},
  2318. {"IIR1 INP2 MUX", "RX4", "RX_RX4"},
  2319. {"IIR1 INP2 MUX", "RX5", "RX_RX5"},
  2320. {"IIR1", NULL, "IIR1 INP3 MUX"},
  2321. {"IIR1 INP3 MUX", "DEC0", "RX_TX DEC0_INP"},
  2322. {"IIR1 INP3 MUX", "DEC1", "RX_TX DEC1_INP"},
  2323. {"IIR1 INP3 MUX", "DEC2", "RX_TX DEC2_INP"},
  2324. {"IIR1 INP3 MUX", "DEC3", "RX_TX DEC3_INP"},
  2325. {"IIR1 INP3 MUX", "RX0", "RX_RX0"},
  2326. {"IIR1 INP3 MUX", "RX1", "RX_RX1"},
  2327. {"IIR1 INP3 MUX", "RX2", "RX_RX2"},
  2328. {"IIR1 INP3 MUX", "RX3", "RX_RX3"},
  2329. {"IIR1 INP3 MUX", "RX4", "RX_RX4"},
  2330. {"IIR1 INP3 MUX", "RX5", "RX_RX5"},
  2331. {"SRC0", NULL, "IIR0"},
  2332. {"SRC1", NULL, "IIR1"},
  2333. {"RX INT0 MIX2 INP", "SRC0", "SRC0"},
  2334. {"RX INT0 MIX2 INP", "SRC1", "SRC1"},
  2335. {"RX INT1 MIX2 INP", "SRC0", "SRC0"},
  2336. {"RX INT1 MIX2 INP", "SRC1", "SRC1"},
  2337. {"RX INT2 MIX2 INP", "SRC0", "SRC0"},
  2338. {"RX INT2 MIX2 INP", "SRC1", "SRC1"},
  2339. };
  2340. static int rx_swrm_clock(void *handle, bool enable)
  2341. {
  2342. struct rx_macro_priv *rx_priv = (struct rx_macro_priv *) handle;
  2343. struct regmap *regmap = dev_get_regmap(rx_priv->dev->parent, NULL);
  2344. int ret = 0;
  2345. mutex_lock(&rx_priv->swr_clk_lock);
  2346. dev_dbg(rx_priv->dev, "%s: swrm clock %s\n",
  2347. __func__, (enable ? "enable" : "disable"));
  2348. if (enable) {
  2349. if (rx_priv->swr_clk_users == 0) {
  2350. ret = rx_macro_mclk_enable(rx_priv, 1, true);
  2351. if (ret < 0) {
  2352. dev_err(rx_priv->dev,
  2353. "%s: rx request clock enable failed\n",
  2354. __func__);
  2355. goto exit;
  2356. }
  2357. regmap_update_bits(regmap,
  2358. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2359. 0x02, 0x02);
  2360. regmap_update_bits(regmap,
  2361. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2362. 0x01, 0x01);
  2363. regmap_update_bits(regmap,
  2364. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2365. 0x02, 0x00);
  2366. msm_cdc_pinctrl_select_active_state(
  2367. rx_priv->rx_swr_gpio_p);
  2368. }
  2369. rx_priv->swr_clk_users++;
  2370. } else {
  2371. if (rx_priv->swr_clk_users <= 0) {
  2372. dev_err(rx_priv->dev,
  2373. "%s: rx swrm clock users already reset\n",
  2374. __func__);
  2375. rx_priv->swr_clk_users = 0;
  2376. goto exit;
  2377. }
  2378. rx_priv->swr_clk_users--;
  2379. if (rx_priv->swr_clk_users == 0) {
  2380. regmap_update_bits(regmap,
  2381. BOLERO_CDC_RX_CLK_RST_CTRL_SWR_CONTROL,
  2382. 0x01, 0x00);
  2383. msm_cdc_pinctrl_select_sleep_state(
  2384. rx_priv->rx_swr_gpio_p);
  2385. rx_macro_mclk_enable(rx_priv, 0, true);
  2386. }
  2387. }
  2388. dev_dbg(rx_priv->dev, "%s: swrm clock users %d\n",
  2389. __func__, rx_priv->swr_clk_users);
  2390. exit:
  2391. mutex_unlock(&rx_priv->swr_clk_lock);
  2392. return ret;
  2393. }
  2394. static void rx_macro_init_bcl_pmic_reg(struct snd_soc_codec *codec)
  2395. {
  2396. struct device *rx_dev = NULL;
  2397. struct rx_macro_priv *rx_priv = NULL;
  2398. if (!codec) {
  2399. pr_err("%s: NULL codec pointer!\n", __func__);
  2400. return;
  2401. }
  2402. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2403. return;
  2404. switch (rx_priv->bcl_pmic_params.id) {
  2405. case 0:
  2406. /* Enable ID0 to listen to respective PMIC group interrupts */
  2407. snd_soc_update_bits(codec,
  2408. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x02, 0x02);
  2409. /* Update MC_SID0 */
  2410. snd_soc_update_bits(codec,
  2411. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0x0F,
  2412. rx_priv->bcl_pmic_params.sid);
  2413. /* Update MC_PPID0 */
  2414. snd_soc_update_bits(codec,
  2415. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG2, 0xFF,
  2416. rx_priv->bcl_pmic_params.ppid);
  2417. break;
  2418. case 1:
  2419. /* Enable ID1 to listen to respective PMIC group interrupts */
  2420. snd_soc_update_bits(codec,
  2421. BOLERO_CDC_RX_BCL_VBAT_DECODE_CTL1, 0x01, 0x01);
  2422. /* Update MC_SID1 */
  2423. snd_soc_update_bits(codec,
  2424. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG3, 0x0F,
  2425. rx_priv->bcl_pmic_params.sid);
  2426. /* Update MC_PPID1 */
  2427. snd_soc_update_bits(codec,
  2428. BOLERO_CDC_RX_BCL_VBAT_DECODE_CFG1, 0xFF,
  2429. rx_priv->bcl_pmic_params.ppid);
  2430. break;
  2431. default:
  2432. dev_err(rx_dev, "%s: PMIC ID is invalid\n",
  2433. __func__, rx_priv->bcl_pmic_params.id);
  2434. break;
  2435. }
  2436. }
  2437. static int rx_macro_init(struct snd_soc_codec *codec)
  2438. {
  2439. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  2440. int ret = 0;
  2441. struct device *rx_dev = NULL;
  2442. struct rx_macro_priv *rx_priv = NULL;
  2443. rx_dev = bolero_get_device_ptr(codec->dev, RX_MACRO);
  2444. if (!rx_dev) {
  2445. dev_err(codec->dev,
  2446. "%s: null device for macro!\n", __func__);
  2447. return -EINVAL;
  2448. }
  2449. rx_priv = dev_get_drvdata(rx_dev);
  2450. if (!rx_priv) {
  2451. dev_err(codec->dev,
  2452. "%s: priv is null for macro!\n", __func__);
  2453. return -EINVAL;
  2454. }
  2455. ret = snd_soc_dapm_new_controls(dapm, rx_macro_dapm_widgets,
  2456. ARRAY_SIZE(rx_macro_dapm_widgets));
  2457. if (ret < 0) {
  2458. dev_err(rx_dev, "%s: failed to add controls\n", __func__);
  2459. return ret;
  2460. }
  2461. ret = snd_soc_dapm_add_routes(dapm, rx_audio_map,
  2462. ARRAY_SIZE(rx_audio_map));
  2463. if (ret < 0) {
  2464. dev_err(rx_dev, "%s: failed to add routes\n", __func__);
  2465. return ret;
  2466. }
  2467. ret = snd_soc_dapm_new_widgets(dapm->card);
  2468. if (ret < 0) {
  2469. dev_err(rx_dev, "%s: failed to add widgets\n", __func__);
  2470. return ret;
  2471. }
  2472. ret = snd_soc_add_codec_controls(codec, rx_macro_snd_controls,
  2473. ARRAY_SIZE(rx_macro_snd_controls));
  2474. if (ret < 0) {
  2475. dev_err(rx_dev, "%s: failed to add snd_ctls\n", __func__);
  2476. return ret;
  2477. }
  2478. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_DSM_CTL, 0x01, 0x01);
  2479. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_DSM_CTL, 0x01, 0x01);
  2480. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_DSM_CTL, 0x01, 0x01);
  2481. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_SEC7, 0x07, 0x02);
  2482. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_SEC7, 0x07, 0x02);
  2483. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_SEC7, 0x07, 0x02);
  2484. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX0_RX_PATH_CFG3, 0x03, 0x02);
  2485. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX1_RX_PATH_CFG3, 0x03, 0x02);
  2486. snd_soc_update_bits(codec, BOLERO_CDC_RX_RX2_RX_PATH_CFG3, 0x03, 0x02);
  2487. rx_macro_init_bcl_pmic_reg(codec);
  2488. rx_priv->codec = codec;
  2489. return 0;
  2490. }
  2491. static int rx_macro_deinit(struct snd_soc_codec *codec)
  2492. {
  2493. struct device *rx_dev = NULL;
  2494. struct rx_macro_priv *rx_priv = NULL;
  2495. if (!rx_macro_get_data(codec, &rx_dev, &rx_priv, __func__))
  2496. return -EINVAL;
  2497. rx_priv->codec = NULL;
  2498. return 0;
  2499. }
  2500. static void rx_macro_add_child_devices(struct work_struct *work)
  2501. {
  2502. struct rx_macro_priv *rx_priv = NULL;
  2503. struct platform_device *pdev = NULL;
  2504. struct device_node *node = NULL;
  2505. struct rx_swr_ctrl_data *swr_ctrl_data = NULL, *temp = NULL;
  2506. int ret = 0;
  2507. u16 count = 0, ctrl_num = 0;
  2508. struct rx_swr_ctrl_platform_data *platdata = NULL;
  2509. char plat_dev_name[RX_SWR_STRING_LEN] = "";
  2510. bool rx_swr_master_node = false;
  2511. rx_priv = container_of(work, struct rx_macro_priv,
  2512. rx_macro_add_child_devices_work);
  2513. if (!rx_priv) {
  2514. pr_err("%s: Memory for rx_priv does not exist\n",
  2515. __func__);
  2516. return;
  2517. }
  2518. if (!rx_priv->dev) {
  2519. pr_err("%s: RX device does not exist\n", __func__);
  2520. return;
  2521. }
  2522. if(!rx_priv->dev->of_node) {
  2523. dev_err(rx_priv->dev,
  2524. "%s: DT node for RX dev does not exist\n", __func__);
  2525. return;
  2526. }
  2527. platdata = &rx_priv->swr_plat_data;
  2528. rx_priv->child_count = 0;
  2529. for_each_available_child_of_node(rx_priv->dev->of_node, node) {
  2530. rx_swr_master_node = false;
  2531. if (strnstr(node->name, "rx_swr_master",
  2532. strlen("rx_swr_master")) != NULL)
  2533. rx_swr_master_node = true;
  2534. if(rx_swr_master_node)
  2535. strlcpy(plat_dev_name, "rx_swr_ctrl",
  2536. (RX_SWR_STRING_LEN - 1));
  2537. else
  2538. strlcpy(plat_dev_name, node->name,
  2539. (RX_SWR_STRING_LEN - 1));
  2540. pdev = platform_device_alloc(plat_dev_name, -1);
  2541. if (!pdev) {
  2542. dev_err(rx_priv->dev, "%s: pdev memory alloc failed\n",
  2543. __func__);
  2544. ret = -ENOMEM;
  2545. goto err;
  2546. }
  2547. pdev->dev.parent = rx_priv->dev;
  2548. pdev->dev.of_node = node;
  2549. if (rx_swr_master_node) {
  2550. ret = platform_device_add_data(pdev, platdata,
  2551. sizeof(*platdata));
  2552. if (ret) {
  2553. dev_err(&pdev->dev,
  2554. "%s: cannot add plat data ctrl:%d\n",
  2555. __func__, ctrl_num);
  2556. goto fail_pdev_add;
  2557. }
  2558. }
  2559. ret = platform_device_add(pdev);
  2560. if (ret) {
  2561. dev_err(&pdev->dev,
  2562. "%s: Cannot add platform device\n",
  2563. __func__);
  2564. goto fail_pdev_add;
  2565. }
  2566. if (rx_swr_master_node) {
  2567. temp = krealloc(swr_ctrl_data,
  2568. (ctrl_num + 1) * sizeof(
  2569. struct rx_swr_ctrl_data),
  2570. GFP_KERNEL);
  2571. if (!temp) {
  2572. ret = -ENOMEM;
  2573. goto fail_pdev_add;
  2574. }
  2575. swr_ctrl_data = temp;
  2576. swr_ctrl_data[ctrl_num].rx_swr_pdev = pdev;
  2577. ctrl_num++;
  2578. dev_dbg(&pdev->dev,
  2579. "%s: Added soundwire ctrl device(s)\n",
  2580. __func__);
  2581. rx_priv->swr_ctrl_data = swr_ctrl_data;
  2582. }
  2583. if (rx_priv->child_count < RX_MACRO_CHILD_DEVICES_MAX)
  2584. rx_priv->pdev_child_devices[
  2585. rx_priv->child_count++] = pdev;
  2586. else
  2587. goto err;
  2588. }
  2589. return;
  2590. fail_pdev_add:
  2591. for (count = 0; count < rx_priv->child_count; count++)
  2592. platform_device_put(rx_priv->pdev_child_devices[count]);
  2593. err:
  2594. return;
  2595. }
  2596. static void rx_macro_init_ops(struct macro_ops *ops, char __iomem *rx_io_base)
  2597. {
  2598. memset(ops, 0, sizeof(struct macro_ops));
  2599. ops->init = rx_macro_init;
  2600. ops->exit = rx_macro_deinit;
  2601. ops->io_base = rx_io_base;
  2602. ops->dai_ptr = rx_macro_dai;
  2603. ops->num_dais = ARRAY_SIZE(rx_macro_dai);
  2604. ops->mclk_fn = rx_macro_mclk_ctrl;
  2605. }
  2606. static int rx_macro_probe(struct platform_device *pdev)
  2607. {
  2608. struct macro_ops ops = {0};
  2609. struct rx_macro_priv *rx_priv = NULL;
  2610. u32 rx_base_addr = 0, muxsel = 0;
  2611. char __iomem *rx_io_base = NULL, *muxsel_io = NULL;
  2612. int ret = 0;
  2613. struct clk *rx_core_clk = NULL, *rx_npl_clk = NULL;
  2614. u8 bcl_pmic_params[3];
  2615. rx_priv = devm_kzalloc(&pdev->dev, sizeof(struct rx_macro_priv),
  2616. GFP_KERNEL);
  2617. if (!rx_priv)
  2618. return -ENOMEM;
  2619. rx_priv->dev = &pdev->dev;
  2620. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  2621. &rx_base_addr);
  2622. if (ret) {
  2623. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2624. __func__, "reg");
  2625. return ret;
  2626. }
  2627. ret = of_property_read_u32(pdev->dev.of_node, "qcom,rx_mclk_mode_muxsel",
  2628. &muxsel);
  2629. if (ret) {
  2630. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  2631. __func__, "reg");
  2632. return ret;
  2633. }
  2634. rx_priv->rx_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  2635. "qcom,rx-swr-gpios", 0);
  2636. if (!rx_priv->rx_swr_gpio_p) {
  2637. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  2638. __func__);
  2639. return -EINVAL;
  2640. }
  2641. rx_io_base = devm_ioremap(&pdev->dev, rx_base_addr,
  2642. RX_MACRO_MAX_OFFSET);
  2643. if (!rx_io_base) {
  2644. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  2645. return -ENOMEM;
  2646. }
  2647. rx_priv->rx_io_base = rx_io_base;
  2648. muxsel_io = devm_ioremap(&pdev->dev, muxsel, 0x4);
  2649. if (!muxsel_io) {
  2650. dev_err(&pdev->dev, "%s: ioremap failed for muxsel\n",
  2651. __func__);
  2652. return -ENOMEM;
  2653. }
  2654. rx_priv->rx_mclk_mode_muxsel = muxsel_io;
  2655. INIT_WORK(&rx_priv->rx_macro_add_child_devices_work,
  2656. rx_macro_add_child_devices);
  2657. rx_priv->swr_plat_data.handle = (void *) rx_priv;
  2658. rx_priv->swr_plat_data.read = NULL;
  2659. rx_priv->swr_plat_data.write = NULL;
  2660. rx_priv->swr_plat_data.bulk_write = NULL;
  2661. rx_priv->swr_plat_data.clk = rx_swrm_clock;
  2662. rx_priv->swr_plat_data.handle_irq = NULL;
  2663. /* Register MCLK for rx macro */
  2664. rx_core_clk = devm_clk_get(&pdev->dev, "rx_core_clk");
  2665. if (IS_ERR(rx_core_clk)) {
  2666. ret = PTR_ERR(rx_core_clk);
  2667. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2668. __func__, "rx_core_clk", ret);
  2669. return ret;
  2670. }
  2671. rx_priv->rx_core_clk = rx_core_clk;
  2672. /* Register npl clk for soundwire */
  2673. rx_npl_clk = devm_clk_get(&pdev->dev, "rx_npl_clk");
  2674. if (IS_ERR(rx_npl_clk)) {
  2675. ret = PTR_ERR(rx_npl_clk);
  2676. dev_err(&pdev->dev, "%s: clk get %s failed %d\n",
  2677. __func__, "rx_npl_clk", ret);
  2678. return ret;
  2679. }
  2680. rx_priv->rx_npl_clk = rx_npl_clk;
  2681. ret = of_property_read_u8_array(pdev->dev.of_node,
  2682. "qcom,rx-bcl-pmic-params", bcl_pmic_params,
  2683. sizeof(bcl_pmic_params));
  2684. if (ret) {
  2685. dev_dbg(&pdev->dev, "%s: could not find %s entry in dt\n",
  2686. __func__, "qcom,rx-bcl-pmic-params");
  2687. } else {
  2688. rx_priv->bcl_pmic_params.id = bcl_pmic_params[0];
  2689. rx_priv->bcl_pmic_params.sid = bcl_pmic_params[1];
  2690. rx_priv->bcl_pmic_params.ppid = bcl_pmic_params[2];
  2691. }
  2692. dev_set_drvdata(&pdev->dev, rx_priv);
  2693. mutex_init(&rx_priv->mclk_lock);
  2694. mutex_init(&rx_priv->swr_clk_lock);
  2695. rx_macro_init_ops(&ops, rx_io_base);
  2696. ret = bolero_register_macro(&pdev->dev, RX_MACRO, &ops);
  2697. if (ret) {
  2698. dev_err(&pdev->dev,
  2699. "%s: register macro failed\n", __func__);
  2700. goto err_reg_macro;
  2701. }
  2702. schedule_work(&rx_priv->rx_macro_add_child_devices_work);
  2703. return 0;
  2704. err_reg_macro:
  2705. mutex_destroy(&rx_priv->mclk_lock);
  2706. mutex_destroy(&rx_priv->swr_clk_lock);
  2707. return ret;
  2708. }
  2709. static int rx_macro_remove(struct platform_device *pdev)
  2710. {
  2711. struct rx_macro_priv *rx_priv = NULL;
  2712. u16 count = 0;
  2713. rx_priv = dev_get_drvdata(&pdev->dev);
  2714. if (!rx_priv)
  2715. return -EINVAL;
  2716. for (count = 0; count < rx_priv->child_count &&
  2717. count < RX_MACRO_CHILD_DEVICES_MAX; count++)
  2718. platform_device_unregister(rx_priv->pdev_child_devices[count]);
  2719. bolero_unregister_macro(&pdev->dev, RX_MACRO);
  2720. mutex_destroy(&rx_priv->mclk_lock);
  2721. mutex_destroy(&rx_priv->swr_clk_lock);
  2722. kfree(rx_priv->swr_ctrl_data);
  2723. return 0;
  2724. }
  2725. static const struct of_device_id rx_macro_dt_match[] = {
  2726. {.compatible = "qcom,rx-macro"},
  2727. {}
  2728. };
  2729. static struct platform_driver rx_macro_driver = {
  2730. .driver = {
  2731. .name = "rx_macro",
  2732. .owner = THIS_MODULE,
  2733. .of_match_table = rx_macro_dt_match,
  2734. },
  2735. .probe = rx_macro_probe,
  2736. .remove = rx_macro_remove,
  2737. };
  2738. module_platform_driver(rx_macro_driver);
  2739. MODULE_DESCRIPTION("RX macro driver");
  2740. MODULE_LICENSE("GPL v2");