rx-macro.c 84 KB

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