rx-macro.c 84 KB

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