rx-macro.c 79 KB

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