rx-macro.c 83 KB

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