rx-macro.c 83 KB

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