wsa-macro.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  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/soc-dapm.h>
  19. #include <sound/tlv.h>
  20. #include <soc/swr-wcd.h>
  21. #include "bolero-cdc.h"
  22. #include "bolero-cdc-registers.h"
  23. #include "wsa-macro.h"
  24. #include "../msm-cdc-pinctrl.h"
  25. #define WSA_MACRO_MAX_OFFSET 0x1000
  26. #define WSA_MACRO_RX_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. #define WSA_MACRO_RX_MIX_RATES (SNDRV_PCM_RATE_48000 |\
  30. SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000)
  31. #define WSA_MACRO_RX_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  32. SNDRV_PCM_FMTBIT_S24_LE |\
  33. SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  34. #define WSA_MACRO_ECHO_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
  35. SNDRV_PCM_RATE_48000)
  36. #define WSA_MACRO_ECHO_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  37. SNDRV_PCM_FMTBIT_S24_LE |\
  38. SNDRV_PCM_FMTBIT_S24_3LE)
  39. #define NUM_INTERPOLATORS 2
  40. #define WSA_MACRO_MUX_INP_SHFT 0x3
  41. #define WSA_MACRO_MUX_INP_MASK1 0x38
  42. #define WSA_MACRO_MUX_INP_MASK2 0x38
  43. #define WSA_MACRO_MUX_CFG_OFFSET 0x8
  44. #define WSA_MACRO_MUX_CFG1_OFFSET 0x4
  45. #define WSA_MACRO_RX_COMP_OFFSET 0x40
  46. #define WSA_MACRO_RX_PATH_OFFSET 0x80
  47. #define WSA_MACRO_RX_PATH_CFG3_OFFSET 0x10
  48. #define WSA_MACRO_RX_PATH_DSMDEM_OFFSET 0x4C
  49. #define WSA_MACRO_FS_RATE_MASK 0x0F
  50. enum {
  51. WSA_MACRO_RX0 = 0,
  52. WSA_MACRO_RX1,
  53. WSA_MACRO_RX_MIX,
  54. WSA_MACRO_RX_MIX0 = WSA_MACRO_RX_MIX,
  55. WSA_MACRO_RX_MIX1,
  56. WSA_MACRO_RX_MAX,
  57. };
  58. enum {
  59. WSA_MACRO_TX0 = 0,
  60. WSA_MACRO_TX1,
  61. WSA_MACRO_TX_MAX,
  62. };
  63. enum {
  64. WSA_MACRO_EC0_MUX = 0,
  65. WSA_MACRO_EC1_MUX,
  66. WSA_MACRO_EC_MUX_MAX,
  67. };
  68. enum {
  69. WSA_MACRO_COMP1, /* SPK_L */
  70. WSA_MACRO_COMP2, /* SPK_R */
  71. WSA_MACRO_COMP_MAX
  72. };
  73. struct interp_sample_rate {
  74. int sample_rate;
  75. int rate_val;
  76. };
  77. /*
  78. * Structure used to update codec
  79. * register defaults after reset
  80. */
  81. struct wsa_macro_reg_mask_val {
  82. u16 reg;
  83. u8 mask;
  84. u8 val;
  85. };
  86. static struct interp_sample_rate int_prim_sample_rate_val[] = {
  87. {8000, 0x0}, /* 8K */
  88. {16000, 0x1}, /* 16K */
  89. {24000, -EINVAL},/* 24K */
  90. {32000, 0x3}, /* 32K */
  91. {48000, 0x4}, /* 48K */
  92. {96000, 0x5}, /* 96K */
  93. {192000, 0x6}, /* 192K */
  94. {384000, 0x7}, /* 384K */
  95. {44100, 0x8}, /* 44.1K */
  96. };
  97. static struct interp_sample_rate int_mix_sample_rate_val[] = {
  98. {48000, 0x4}, /* 48K */
  99. {96000, 0x5}, /* 96K */
  100. {192000, 0x6}, /* 192K */
  101. };
  102. #define WSA_MACRO_SWR_STRING_LEN 80
  103. static int wsa_macro_hw_params(struct snd_pcm_substream *substream,
  104. struct snd_pcm_hw_params *params,
  105. struct snd_soc_dai *dai);
  106. static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
  107. unsigned int *tx_num, unsigned int *tx_slot,
  108. unsigned int *rx_num, unsigned int *rx_slot);
  109. /* Hold instance to soundwire platform device */
  110. struct wsa_macro_swr_ctrl_data {
  111. struct platform_device *wsa_swr_pdev;
  112. };
  113. struct wsa_macro_swr_ctrl_platform_data {
  114. void *handle; /* holds codec private data */
  115. int (*read)(void *handle, int reg);
  116. int (*write)(void *handle, int reg, int val);
  117. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  118. int (*clk)(void *handle, bool enable);
  119. int (*handle_irq)(void *handle,
  120. irqreturn_t (*swrm_irq_handler)(int irq,
  121. void *data),
  122. void *swrm_handle,
  123. int action);
  124. };
  125. enum {
  126. WSA_MACRO_AIF_INVALID = 0,
  127. WSA_MACRO_AIF1_PB,
  128. WSA_MACRO_AIF_MIX1_PB,
  129. WSA_MACRO_AIF_VI,
  130. WSA_MACRO_AIF_ECHO,
  131. WSA_MACRO_MAX_DAIS,
  132. };
  133. #define WSA_MACRO_CHILD_DEVICES_MAX 3
  134. /*
  135. * @dev: wsa macro device pointer
  136. * @comp_enabled: compander enable mixer value set
  137. * @ec_hq: echo HQ enable mixer value set
  138. * @prim_int_users: Users of interpolator
  139. * @wsa_mclk_users: WSA MCLK users count
  140. * @swr_clk_users: SWR clk users count
  141. * @vi_feed_value: VI sense mask
  142. * @mclk_lock: to lock mclk operations
  143. * @swr_clk_lock: to lock swr master clock operations
  144. * @swr_ctrl_data: SoundWire data structure
  145. * @swr_plat_data: Soundwire platform data
  146. * @wsa_macro_add_child_devices_work: work for adding child devices
  147. * @wsa_swr_gpio_p: used by pinctrl API
  148. * @wsa_core_clk: MCLK for wsa macro
  149. * @wsa_npl_clk: NPL clock for WSA soundwire
  150. * @codec: codec handle
  151. * @rx_0_count: RX0 interpolation users
  152. * @rx_1_count: RX1 interpolation users
  153. * @active_ch_mask: channel mask for all AIF DAIs
  154. * @active_ch_cnt: channel count of all AIF DAIs
  155. * @rx_port_value: mixer ctl value of WSA RX MUXes
  156. * @wsa_io_base: Base address of WSA macro addr space
  157. */
  158. struct wsa_macro_priv {
  159. struct device *dev;
  160. int comp_enabled[WSA_MACRO_COMP_MAX];
  161. int ec_hq[WSA_MACRO_RX1 + 1];
  162. u16 prim_int_users[WSA_MACRO_RX1 + 1];
  163. u16 wsa_mclk_users;
  164. u16 swr_clk_users;
  165. unsigned int vi_feed_value;
  166. struct mutex mclk_lock;
  167. struct mutex swr_clk_lock;
  168. struct wsa_macro_swr_ctrl_data *swr_ctrl_data;
  169. struct wsa_macro_swr_ctrl_platform_data swr_plat_data;
  170. struct work_struct wsa_macro_add_child_devices_work;
  171. struct device_node *wsa_swr_gpio_p;
  172. struct clk *wsa_core_clk;
  173. struct clk *wsa_npl_clk;
  174. struct snd_soc_codec *codec;
  175. int rx_0_count;
  176. int rx_1_count;
  177. unsigned long active_ch_mask[WSA_MACRO_MAX_DAIS];
  178. unsigned long active_ch_cnt[WSA_MACRO_MAX_DAIS];
  179. int rx_port_value[WSA_MACRO_RX_MAX];
  180. char __iomem *wsa_io_base;
  181. struct platform_device *pdev_child_devices
  182. [WSA_MACRO_CHILD_DEVICES_MAX];
  183. int child_count;
  184. int ear_spkr_gain;
  185. int spkr_gain_offset;
  186. int spkr_mode;
  187. };
  188. static int wsa_macro_config_ear_spkr_gain(struct snd_soc_codec *codec,
  189. struct wsa_macro_priv *wsa_priv,
  190. int event, int gain_reg);
  191. static struct snd_soc_dai_driver wsa_macro_dai[];
  192. static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0);
  193. static const char *const rx_text[] = {
  194. "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1", "DEC0", "DEC1"
  195. };
  196. static const char *const rx_mix_text[] = {
  197. "ZERO", "RX0", "RX1", "RX_MIX0", "RX_MIX1"
  198. };
  199. static const char *const rx_mix_ec_text[] = {
  200. "ZERO", "RX_MIX_TX0", "RX_MIX_TX1"
  201. };
  202. static const char *const rx_mux_text[] = {
  203. "ZERO", "AIF1_PB", "AIF_MIX1_PB"
  204. };
  205. static const char * const wsa_macro_ear_spkr_pa_gain_text[] = {
  206. "G_DEFAULT", "G_0_DB", "G_1_DB", "G_2_DB", "G_3_DB",
  207. "G_4_DB", "G_5_DB", "G_6_DB"
  208. };
  209. static const char * const wsa_macro_speaker_boost_stage_text[] = {
  210. "NO_MAX_STATE", "MAX_STATE_1", "MAX_STATE_2"
  211. };
  212. static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_ear_spkr_pa_gain_enum,
  213. wsa_macro_ear_spkr_pa_gain_text);
  214. static SOC_ENUM_SINGLE_EXT_DECL(wsa_macro_spkr_boost_stage_enum,
  215. wsa_macro_speaker_boost_stage_text);
  216. /* RX INT0 */
  217. static const struct soc_enum rx0_prim_inp0_chain_enum =
  218. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
  219. 0, 7, rx_text);
  220. static const struct soc_enum rx0_prim_inp1_chain_enum =
  221. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0,
  222. 3, 7, rx_text);
  223. static const struct soc_enum rx0_prim_inp2_chain_enum =
  224. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
  225. 3, 7, rx_text);
  226. static const struct soc_enum rx0_mix_chain_enum =
  227. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1,
  228. 0, 5, rx_mix_text);
  229. static const struct snd_kcontrol_new rx0_prim_inp0_mux =
  230. SOC_DAPM_ENUM("WSA_RX0 INP0 Mux", rx0_prim_inp0_chain_enum);
  231. static const struct snd_kcontrol_new rx0_prim_inp1_mux =
  232. SOC_DAPM_ENUM("WSA_RX0 INP1 Mux", rx0_prim_inp1_chain_enum);
  233. static const struct snd_kcontrol_new rx0_prim_inp2_mux =
  234. SOC_DAPM_ENUM("WSA_RX0 INP2 Mux", rx0_prim_inp2_chain_enum);
  235. static const struct snd_kcontrol_new rx0_mix_mux =
  236. SOC_DAPM_ENUM("WSA_RX0 MIX Mux", rx0_mix_chain_enum);
  237. /* RX INT1 */
  238. static const struct soc_enum rx1_prim_inp0_chain_enum =
  239. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
  240. 0, 7, rx_text);
  241. static const struct soc_enum rx1_prim_inp1_chain_enum =
  242. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG0,
  243. 3, 7, rx_text);
  244. static const struct soc_enum rx1_prim_inp2_chain_enum =
  245. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
  246. 3, 7, rx_text);
  247. static const struct soc_enum rx1_mix_chain_enum =
  248. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_INT1_CFG1,
  249. 0, 5, rx_mix_text);
  250. static const struct snd_kcontrol_new rx1_prim_inp0_mux =
  251. SOC_DAPM_ENUM("WSA_RX1 INP0 Mux", rx1_prim_inp0_chain_enum);
  252. static const struct snd_kcontrol_new rx1_prim_inp1_mux =
  253. SOC_DAPM_ENUM("WSA_RX1 INP1 Mux", rx1_prim_inp1_chain_enum);
  254. static const struct snd_kcontrol_new rx1_prim_inp2_mux =
  255. SOC_DAPM_ENUM("WSA_RX1 INP2 Mux", rx1_prim_inp2_chain_enum);
  256. static const struct snd_kcontrol_new rx1_mix_mux =
  257. SOC_DAPM_ENUM("WSA_RX1 MIX Mux", rx1_mix_chain_enum);
  258. static const struct soc_enum rx_mix_ec0_enum =
  259. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  260. 0, 3, rx_mix_ec_text);
  261. static const struct soc_enum rx_mix_ec1_enum =
  262. SOC_ENUM_SINGLE(BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  263. 3, 3, rx_mix_ec_text);
  264. static const struct snd_kcontrol_new rx_mix_ec0_mux =
  265. SOC_DAPM_ENUM("WSA RX_MIX EC0_Mux", rx_mix_ec0_enum);
  266. static const struct snd_kcontrol_new rx_mix_ec1_mux =
  267. SOC_DAPM_ENUM("WSA RX_MIX EC1_Mux", rx_mix_ec1_enum);
  268. static struct snd_soc_dai_ops wsa_macro_dai_ops = {
  269. .hw_params = wsa_macro_hw_params,
  270. .get_channel_map = wsa_macro_get_channel_map,
  271. };
  272. static struct snd_soc_dai_driver wsa_macro_dai[] = {
  273. {
  274. .name = "wsa_macro_rx1",
  275. .id = WSA_MACRO_AIF1_PB,
  276. .playback = {
  277. .stream_name = "WSA_AIF1 Playback",
  278. .rates = WSA_MACRO_RX_RATES,
  279. .formats = WSA_MACRO_RX_FORMATS,
  280. .rate_max = 384000,
  281. .rate_min = 8000,
  282. .channels_min = 1,
  283. .channels_max = 2,
  284. },
  285. .ops = &wsa_macro_dai_ops,
  286. },
  287. {
  288. .name = "wsa_macro_rx_mix",
  289. .id = WSA_MACRO_AIF_MIX1_PB,
  290. .playback = {
  291. .stream_name = "WSA_AIF_MIX1 Playback",
  292. .rates = WSA_MACRO_RX_MIX_RATES,
  293. .formats = WSA_MACRO_RX_FORMATS,
  294. .rate_max = 192000,
  295. .rate_min = 48000,
  296. .channels_min = 1,
  297. .channels_max = 2,
  298. },
  299. .ops = &wsa_macro_dai_ops,
  300. },
  301. {
  302. .name = "wsa_macro_vifeedback",
  303. .id = WSA_MACRO_AIF_VI,
  304. .capture = {
  305. .stream_name = "WSA_AIF_VI Capture",
  306. .rates = SNDRV_PCM_RATE_8000,
  307. .formats = SNDRV_PCM_FMTBIT_S32_LE,
  308. .rate_max = 8000,
  309. .rate_min = 8000,
  310. .channels_min = 1,
  311. .channels_max = 2,
  312. },
  313. .ops = &wsa_macro_dai_ops,
  314. },
  315. {
  316. .name = "wsa_macro_echo",
  317. .id = WSA_MACRO_AIF_ECHO,
  318. .capture = {
  319. .stream_name = "WSA_AIF_ECHO Capture",
  320. .rates = WSA_MACRO_ECHO_RATES,
  321. .formats = WSA_MACRO_ECHO_FORMATS,
  322. .rate_max = 48000,
  323. .rate_min = 8000,
  324. .channels_min = 1,
  325. .channels_max = 2,
  326. },
  327. .ops = &wsa_macro_dai_ops,
  328. },
  329. };
  330. static const struct wsa_macro_reg_mask_val wsa_macro_spkr_default[] = {
  331. {BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x80},
  332. {BOLERO_CDC_WSA_COMPANDER1_CTL3, 0x80, 0x80},
  333. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
  334. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
  335. {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x58},
  336. {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x58},
  337. };
  338. static const struct wsa_macro_reg_mask_val wsa_macro_spkr_mode1[] = {
  339. {BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x00},
  340. {BOLERO_CDC_WSA_COMPANDER1_CTL3, 0x80, 0x00},
  341. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x00},
  342. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x00},
  343. {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x7C, 0x44},
  344. {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x7C, 0x44},
  345. };
  346. static bool wsa_macro_get_data(struct snd_soc_codec *codec,
  347. struct device **wsa_dev,
  348. struct wsa_macro_priv **wsa_priv,
  349. const char *func_name)
  350. {
  351. *wsa_dev = bolero_get_device_ptr(codec->dev, WSA_MACRO);
  352. if (!(*wsa_dev)) {
  353. dev_err(codec->dev,
  354. "%s: null device for macro!\n", func_name);
  355. return false;
  356. }
  357. *wsa_priv = dev_get_drvdata((*wsa_dev));
  358. if (!(*wsa_priv) || !(*wsa_priv)->codec) {
  359. dev_err(codec->dev,
  360. "%s: priv is null for macro!\n", func_name);
  361. return false;
  362. }
  363. return true;
  364. }
  365. /**
  366. * wsa_macro_set_spkr_gain_offset - offset the speaker path
  367. * gain with the given offset value.
  368. *
  369. * @codec: codec instance
  370. * @offset: Indicates speaker path gain offset value.
  371. *
  372. * Returns 0 on success or -EINVAL on error.
  373. */
  374. int wsa_macro_set_spkr_gain_offset(struct snd_soc_codec *codec, int offset)
  375. {
  376. struct device *wsa_dev = NULL;
  377. struct wsa_macro_priv *wsa_priv = NULL;
  378. if (!codec) {
  379. pr_err("%s: NULL codec pointer!\n", __func__);
  380. return -EINVAL;
  381. }
  382. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  383. return -EINVAL;
  384. wsa_priv->spkr_gain_offset = offset;
  385. return 0;
  386. }
  387. EXPORT_SYMBOL(wsa_macro_set_spkr_gain_offset);
  388. /**
  389. * wsa_macro_set_spkr_mode - Configures speaker compander and smartboost
  390. * settings based on speaker mode.
  391. *
  392. * @codec: codec instance
  393. * @mode: Indicates speaker configuration mode.
  394. *
  395. * Returns 0 on success or -EINVAL on error.
  396. */
  397. int wsa_macro_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  398. {
  399. int i;
  400. const struct wsa_macro_reg_mask_val *regs;
  401. int size;
  402. struct device *wsa_dev = NULL;
  403. struct wsa_macro_priv *wsa_priv = NULL;
  404. if (!codec) {
  405. pr_err("%s: NULL codec pointer!\n", __func__);
  406. return -EINVAL;
  407. }
  408. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  409. return -EINVAL;
  410. switch (mode) {
  411. case WSA_MACRO_SPKR_MODE_1:
  412. regs = wsa_macro_spkr_mode1;
  413. size = ARRAY_SIZE(wsa_macro_spkr_mode1);
  414. break;
  415. default:
  416. regs = wsa_macro_spkr_default;
  417. size = ARRAY_SIZE(wsa_macro_spkr_default);
  418. break;
  419. }
  420. wsa_priv->spkr_mode = mode;
  421. for (i = 0; i < size; i++)
  422. snd_soc_update_bits(codec, regs[i].reg,
  423. regs[i].mask, regs[i].val);
  424. return 0;
  425. }
  426. EXPORT_SYMBOL(wsa_macro_set_spkr_mode);
  427. static int wsa_macro_set_prim_interpolator_rate(struct snd_soc_dai *dai,
  428. u8 int_prim_fs_rate_reg_val,
  429. u32 sample_rate)
  430. {
  431. u8 int_1_mix1_inp;
  432. u32 j, port;
  433. u16 int_mux_cfg0, int_mux_cfg1;
  434. u16 int_fs_reg;
  435. u8 int_mux_cfg0_val, int_mux_cfg1_val;
  436. u8 inp0_sel, inp1_sel, inp2_sel;
  437. struct snd_soc_codec *codec = dai->codec;
  438. struct device *wsa_dev = NULL;
  439. struct wsa_macro_priv *wsa_priv = NULL;
  440. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  441. return -EINVAL;
  442. for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
  443. WSA_MACRO_RX_MAX) {
  444. int_1_mix1_inp = port;
  445. if ((int_1_mix1_inp < WSA_MACRO_RX0) ||
  446. (int_1_mix1_inp > WSA_MACRO_RX_MIX1)) {
  447. dev_err(wsa_dev,
  448. "%s: Invalid RX port, Dai ID is %d\n",
  449. __func__, dai->id);
  450. return -EINVAL;
  451. }
  452. int_mux_cfg0 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG0;
  453. /*
  454. * Loop through all interpolator MUX inputs and find out
  455. * to which interpolator input, the cdc_dma rx port
  456. * is connected
  457. */
  458. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  459. int_mux_cfg1 = int_mux_cfg0 + WSA_MACRO_MUX_CFG1_OFFSET;
  460. int_mux_cfg0_val = snd_soc_read(codec, int_mux_cfg0);
  461. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1);
  462. inp0_sel = int_mux_cfg0_val & WSA_MACRO_MUX_INP_MASK1;
  463. inp1_sel = (int_mux_cfg0_val >>
  464. WSA_MACRO_MUX_INP_SHFT) &
  465. WSA_MACRO_MUX_INP_MASK2;
  466. inp2_sel = (int_mux_cfg1_val >>
  467. WSA_MACRO_MUX_INP_SHFT) &
  468. WSA_MACRO_MUX_INP_MASK2;
  469. if ((inp0_sel == int_1_mix1_inp) ||
  470. (inp1_sel == int_1_mix1_inp) ||
  471. (inp2_sel == int_1_mix1_inp)) {
  472. int_fs_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL +
  473. WSA_MACRO_RX_PATH_OFFSET * j;
  474. dev_dbg(wsa_dev,
  475. "%s: AIF_PB DAI(%d) connected to INT%u_1\n",
  476. __func__, dai->id, j);
  477. dev_dbg(wsa_dev,
  478. "%s: set INT%u_1 sample rate to %u\n",
  479. __func__, j, sample_rate);
  480. /* sample_rate is in Hz */
  481. snd_soc_update_bits(codec, int_fs_reg,
  482. WSA_MACRO_FS_RATE_MASK,
  483. int_prim_fs_rate_reg_val);
  484. }
  485. int_mux_cfg0 += WSA_MACRO_MUX_CFG_OFFSET;
  486. }
  487. }
  488. return 0;
  489. }
  490. static int wsa_macro_set_mix_interpolator_rate(struct snd_soc_dai *dai,
  491. u8 int_mix_fs_rate_reg_val,
  492. u32 sample_rate)
  493. {
  494. u8 int_2_inp;
  495. u32 j, port;
  496. u16 int_mux_cfg1, int_fs_reg;
  497. u8 int_mux_cfg1_val;
  498. struct snd_soc_codec *codec = dai->codec;
  499. struct device *wsa_dev = NULL;
  500. struct wsa_macro_priv *wsa_priv = NULL;
  501. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  502. return -EINVAL;
  503. for_each_set_bit(port, &wsa_priv->active_ch_mask[dai->id],
  504. WSA_MACRO_RX_MAX) {
  505. int_2_inp = port;
  506. if ((int_2_inp < WSA_MACRO_RX0) ||
  507. (int_2_inp > WSA_MACRO_RX_MIX1)) {
  508. dev_err(wsa_dev,
  509. "%s: Invalid RX port, Dai ID is %d\n",
  510. __func__, dai->id);
  511. return -EINVAL;
  512. }
  513. int_mux_cfg1 = BOLERO_CDC_WSA_RX_INP_MUX_RX_INT0_CFG1;
  514. for (j = 0; j < NUM_INTERPOLATORS; j++) {
  515. int_mux_cfg1_val = snd_soc_read(codec, int_mux_cfg1) &
  516. WSA_MACRO_MUX_INP_MASK1;
  517. if (int_mux_cfg1_val == int_2_inp) {
  518. int_fs_reg =
  519. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL +
  520. WSA_MACRO_RX_PATH_OFFSET * j;
  521. dev_dbg(wsa_dev,
  522. "%s: AIF_PB DAI(%d) connected to INT%u_2\n",
  523. __func__, dai->id, j);
  524. dev_dbg(wsa_dev,
  525. "%s: set INT%u_2 sample rate to %u\n",
  526. __func__, j, sample_rate);
  527. snd_soc_update_bits(codec, int_fs_reg,
  528. WSA_MACRO_FS_RATE_MASK,
  529. int_mix_fs_rate_reg_val);
  530. }
  531. int_mux_cfg1 += WSA_MACRO_MUX_CFG_OFFSET;
  532. }
  533. }
  534. return 0;
  535. }
  536. static int wsa_macro_set_interpolator_rate(struct snd_soc_dai *dai,
  537. u32 sample_rate)
  538. {
  539. int rate_val = 0;
  540. int i, ret;
  541. /* set mixing path rate */
  542. for (i = 0; i < ARRAY_SIZE(int_mix_sample_rate_val); i++) {
  543. if (sample_rate ==
  544. int_mix_sample_rate_val[i].sample_rate) {
  545. rate_val =
  546. int_mix_sample_rate_val[i].rate_val;
  547. break;
  548. }
  549. }
  550. if ((i == ARRAY_SIZE(int_mix_sample_rate_val)) ||
  551. (rate_val < 0))
  552. goto prim_rate;
  553. ret = wsa_macro_set_mix_interpolator_rate(dai,
  554. (u8) rate_val, sample_rate);
  555. prim_rate:
  556. /* set primary path sample rate */
  557. for (i = 0; i < ARRAY_SIZE(int_prim_sample_rate_val); i++) {
  558. if (sample_rate ==
  559. int_prim_sample_rate_val[i].sample_rate) {
  560. rate_val =
  561. int_prim_sample_rate_val[i].rate_val;
  562. break;
  563. }
  564. }
  565. if ((i == ARRAY_SIZE(int_prim_sample_rate_val)) ||
  566. (rate_val < 0))
  567. return -EINVAL;
  568. ret = wsa_macro_set_prim_interpolator_rate(dai,
  569. (u8) rate_val, sample_rate);
  570. return ret;
  571. }
  572. static int wsa_macro_hw_params(struct snd_pcm_substream *substream,
  573. struct snd_pcm_hw_params *params,
  574. struct snd_soc_dai *dai)
  575. {
  576. struct snd_soc_codec *codec = dai->codec;
  577. int ret;
  578. dev_dbg(codec->dev,
  579. "%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__,
  580. dai->name, dai->id, params_rate(params),
  581. params_channels(params));
  582. switch (substream->stream) {
  583. case SNDRV_PCM_STREAM_PLAYBACK:
  584. ret = wsa_macro_set_interpolator_rate(dai, params_rate(params));
  585. if (ret) {
  586. dev_err(codec->dev,
  587. "%s: cannot set sample rate: %u\n",
  588. __func__, params_rate(params));
  589. return ret;
  590. }
  591. break;
  592. case SNDRV_PCM_STREAM_CAPTURE:
  593. default:
  594. break;
  595. }
  596. return 0;
  597. }
  598. static int wsa_macro_get_channel_map(struct snd_soc_dai *dai,
  599. unsigned int *tx_num, unsigned int *tx_slot,
  600. unsigned int *rx_num, unsigned int *rx_slot)
  601. {
  602. struct snd_soc_codec *codec = dai->codec;
  603. struct device *wsa_dev = NULL;
  604. struct wsa_macro_priv *wsa_priv = NULL;
  605. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  606. return -EINVAL;
  607. wsa_priv = dev_get_drvdata(wsa_dev);
  608. if (!wsa_priv)
  609. return -EINVAL;
  610. switch (dai->id) {
  611. case WSA_MACRO_AIF_VI:
  612. case WSA_MACRO_AIF_ECHO:
  613. *tx_slot = wsa_priv->active_ch_mask[dai->id];
  614. *tx_num = wsa_priv->active_ch_cnt[dai->id];
  615. break;
  616. case WSA_MACRO_AIF1_PB:
  617. case WSA_MACRO_AIF_MIX1_PB:
  618. *rx_slot = wsa_priv->active_ch_mask[dai->id];
  619. *rx_num = wsa_priv->active_ch_cnt[dai->id];
  620. break;
  621. default:
  622. dev_err(wsa_dev, "%s: Invalid AIF\n", __func__);
  623. break;
  624. }
  625. return 0;
  626. }
  627. static int wsa_macro_mclk_enable(struct wsa_macro_priv *wsa_priv,
  628. bool mclk_enable, bool dapm)
  629. {
  630. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  631. int ret = 0;
  632. dev_dbg(wsa_priv->dev, "%s: mclk_enable = %u, dapm = %d clk_users= %d\n",
  633. __func__, mclk_enable, dapm, wsa_priv->wsa_mclk_users);
  634. mutex_lock(&wsa_priv->mclk_lock);
  635. if (mclk_enable) {
  636. wsa_priv->wsa_mclk_users++;
  637. if (wsa_priv->wsa_mclk_users == 1) {
  638. ret = bolero_request_clock(wsa_priv->dev,
  639. WSA_MACRO, MCLK_MUX0, true);
  640. if (ret < 0) {
  641. dev_err(wsa_priv->dev,
  642. "%s: wsa request clock enable failed\n",
  643. __func__);
  644. goto exit;
  645. }
  646. regcache_mark_dirty(regmap);
  647. regcache_sync_region(regmap,
  648. WSA_START_OFFSET,
  649. WSA_MAX_OFFSET);
  650. /* 9.6MHz MCLK, set value 0x00 if other frequency */
  651. regmap_update_bits(regmap,
  652. BOLERO_CDC_WSA_TOP_FREQ_MCLK, 0x01, 0x01);
  653. regmap_update_bits(regmap,
  654. BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  655. 0x01, 0x01);
  656. regmap_update_bits(regmap,
  657. BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  658. 0x01, 0x01);
  659. }
  660. } else {
  661. wsa_priv->wsa_mclk_users--;
  662. if (wsa_priv->wsa_mclk_users == 0) {
  663. regmap_update_bits(regmap,
  664. BOLERO_CDC_WSA_CLK_RST_CTRL_FS_CNT_CONTROL,
  665. 0x01, 0x00);
  666. regmap_update_bits(regmap,
  667. BOLERO_CDC_WSA_CLK_RST_CTRL_MCLK_CONTROL,
  668. 0x01, 0x00);
  669. bolero_request_clock(wsa_priv->dev,
  670. WSA_MACRO, MCLK_MUX0, false);
  671. }
  672. }
  673. exit:
  674. mutex_unlock(&wsa_priv->mclk_lock);
  675. return ret;
  676. }
  677. static int wsa_macro_mclk_event(struct snd_soc_dapm_widget *w,
  678. struct snd_kcontrol *kcontrol, int event)
  679. {
  680. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  681. int ret = 0;
  682. struct device *wsa_dev = NULL;
  683. struct wsa_macro_priv *wsa_priv = NULL;
  684. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  685. return -EINVAL;
  686. dev_dbg(wsa_dev, "%s: event = %d\n", __func__, event);
  687. switch (event) {
  688. case SND_SOC_DAPM_PRE_PMU:
  689. ret = wsa_macro_mclk_enable(wsa_priv, 1, true);
  690. break;
  691. case SND_SOC_DAPM_POST_PMD:
  692. wsa_macro_mclk_enable(wsa_priv, 0, true);
  693. break;
  694. default:
  695. dev_err(wsa_priv->dev,
  696. "%s: invalid DAPM event %d\n", __func__, event);
  697. ret = -EINVAL;
  698. }
  699. return ret;
  700. }
  701. static int wsa_macro_mclk_ctrl(struct device *dev, bool enable)
  702. {
  703. struct wsa_macro_priv *wsa_priv = dev_get_drvdata(dev);
  704. int ret = 0;
  705. if (!wsa_priv)
  706. return -EINVAL;
  707. if (enable) {
  708. ret = clk_prepare_enable(wsa_priv->wsa_core_clk);
  709. if (ret < 0) {
  710. dev_err(dev, "%s:wsa mclk enable failed\n", __func__);
  711. goto exit;
  712. }
  713. ret = clk_prepare_enable(wsa_priv->wsa_npl_clk);
  714. if (ret < 0) {
  715. dev_err(dev, "%s:wsa npl_clk enable failed\n",
  716. __func__);
  717. clk_disable_unprepare(wsa_priv->wsa_core_clk);
  718. goto exit;
  719. }
  720. } else {
  721. clk_disable_unprepare(wsa_priv->wsa_npl_clk);
  722. clk_disable_unprepare(wsa_priv->wsa_core_clk);
  723. }
  724. exit:
  725. return ret;
  726. }
  727. static int wsa_macro_enable_vi_feedback(struct snd_soc_dapm_widget *w,
  728. struct snd_kcontrol *kcontrol,
  729. int event)
  730. {
  731. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  732. struct device *wsa_dev = NULL;
  733. struct wsa_macro_priv *wsa_priv = NULL;
  734. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  735. return -EINVAL;
  736. switch (event) {
  737. case SND_SOC_DAPM_POST_PMU:
  738. if (test_bit(WSA_MACRO_TX0,
  739. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  740. dev_dbg(wsa_dev, "%s: spkr1 enabled\n", __func__);
  741. /* Enable V&I sensing */
  742. snd_soc_update_bits(codec,
  743. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  744. 0x20, 0x20);
  745. snd_soc_update_bits(codec,
  746. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  747. 0x20, 0x20);
  748. snd_soc_update_bits(codec,
  749. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  750. 0x0F, 0x00);
  751. snd_soc_update_bits(codec,
  752. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  753. 0x0F, 0x00);
  754. snd_soc_update_bits(codec,
  755. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  756. 0x10, 0x10);
  757. snd_soc_update_bits(codec,
  758. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  759. 0x10, 0x10);
  760. snd_soc_update_bits(codec,
  761. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  762. 0x20, 0x00);
  763. snd_soc_update_bits(codec,
  764. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  765. 0x20, 0x00);
  766. }
  767. if (test_bit(WSA_MACRO_TX1,
  768. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  769. dev_dbg(wsa_dev, "%s: spkr2 enabled\n", __func__);
  770. /* Enable V&I sensing */
  771. snd_soc_update_bits(codec,
  772. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  773. 0x20, 0x20);
  774. snd_soc_update_bits(codec,
  775. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  776. 0x20, 0x20);
  777. snd_soc_update_bits(codec,
  778. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  779. 0x0F, 0x00);
  780. snd_soc_update_bits(codec,
  781. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  782. 0x0F, 0x00);
  783. snd_soc_update_bits(codec,
  784. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  785. 0x10, 0x10);
  786. snd_soc_update_bits(codec,
  787. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  788. 0x10, 0x10);
  789. snd_soc_update_bits(codec,
  790. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  791. 0x20, 0x00);
  792. snd_soc_update_bits(codec,
  793. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  794. 0x20, 0x00);
  795. }
  796. break;
  797. case SND_SOC_DAPM_POST_PMD:
  798. if (test_bit(WSA_MACRO_TX0,
  799. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  800. /* Disable V&I sensing */
  801. snd_soc_update_bits(codec,
  802. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  803. 0x20, 0x20);
  804. snd_soc_update_bits(codec,
  805. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  806. 0x20, 0x20);
  807. dev_dbg(wsa_dev, "%s: spkr1 disabled\n", __func__);
  808. snd_soc_update_bits(codec,
  809. BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CTL,
  810. 0x10, 0x00);
  811. snd_soc_update_bits(codec,
  812. BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CTL,
  813. 0x10, 0x00);
  814. }
  815. if (test_bit(WSA_MACRO_TX1,
  816. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  817. /* Disable V&I sensing */
  818. dev_dbg(wsa_dev, "%s: spkr2 disabled\n", __func__);
  819. snd_soc_update_bits(codec,
  820. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  821. 0x20, 0x20);
  822. snd_soc_update_bits(codec,
  823. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  824. 0x20, 0x20);
  825. snd_soc_update_bits(codec,
  826. BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CTL,
  827. 0x10, 0x00);
  828. snd_soc_update_bits(codec,
  829. BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CTL,
  830. 0x10, 0x00);
  831. }
  832. break;
  833. }
  834. return 0;
  835. }
  836. static int wsa_macro_enable_mix_path(struct snd_soc_dapm_widget *w,
  837. struct snd_kcontrol *kcontrol, int event)
  838. {
  839. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  840. u16 gain_reg;
  841. int offset_val = 0;
  842. int val = 0;
  843. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  844. switch (w->reg) {
  845. case BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL:
  846. gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_MIX_CTL;
  847. break;
  848. case BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL:
  849. gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_MIX_CTL;
  850. break;
  851. default:
  852. dev_err(codec->dev, "%s: No gain register avail for %s\n",
  853. __func__, w->name);
  854. return 0;
  855. }
  856. switch (event) {
  857. case SND_SOC_DAPM_POST_PMU:
  858. val = snd_soc_read(codec, gain_reg);
  859. val += offset_val;
  860. snd_soc_write(codec, gain_reg, val);
  861. break;
  862. case SND_SOC_DAPM_POST_PMD:
  863. break;
  864. }
  865. return 0;
  866. }
  867. static void wsa_macro_hd2_control(struct snd_soc_codec *codec,
  868. u16 reg, int event)
  869. {
  870. u16 hd2_scale_reg;
  871. u16 hd2_enable_reg = 0;
  872. if (reg == BOLERO_CDC_WSA_RX0_RX_PATH_CTL) {
  873. hd2_scale_reg = BOLERO_CDC_WSA_RX0_RX_PATH_SEC3;
  874. hd2_enable_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0;
  875. }
  876. if (reg == BOLERO_CDC_WSA_RX1_RX_PATH_CTL) {
  877. hd2_scale_reg = BOLERO_CDC_WSA_RX1_RX_PATH_SEC3;
  878. hd2_enable_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CFG0;
  879. }
  880. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_ON(event)) {
  881. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x10);
  882. snd_soc_update_bits(codec, hd2_scale_reg, 0x03, 0x01);
  883. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x04);
  884. }
  885. if (hd2_enable_reg && SND_SOC_DAPM_EVENT_OFF(event)) {
  886. snd_soc_update_bits(codec, hd2_enable_reg, 0x04, 0x00);
  887. snd_soc_update_bits(codec, hd2_scale_reg, 0x03, 0x00);
  888. snd_soc_update_bits(codec, hd2_scale_reg, 0x3C, 0x00);
  889. }
  890. }
  891. static int wsa_macro_enable_swr(struct snd_soc_dapm_widget *w,
  892. struct snd_kcontrol *kcontrol, int event)
  893. {
  894. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  895. int ch_cnt;
  896. struct device *wsa_dev = NULL;
  897. struct wsa_macro_priv *wsa_priv = NULL;
  898. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  899. return -EINVAL;
  900. switch (event) {
  901. case SND_SOC_DAPM_PRE_PMU:
  902. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  903. !wsa_priv->rx_0_count)
  904. wsa_priv->rx_0_count++;
  905. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  906. !wsa_priv->rx_1_count)
  907. wsa_priv->rx_1_count++;
  908. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  909. swrm_wcd_notify(
  910. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  911. SWR_DEVICE_UP, NULL);
  912. swrm_wcd_notify(
  913. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  914. SWR_SET_NUM_RX_CH, &ch_cnt);
  915. break;
  916. case SND_SOC_DAPM_POST_PMD:
  917. if (!(strnstr(w->name, "RX0", sizeof("WSA_RX0"))) &&
  918. wsa_priv->rx_0_count)
  919. wsa_priv->rx_0_count--;
  920. if (!(strnstr(w->name, "RX1", sizeof("WSA_RX1"))) &&
  921. wsa_priv->rx_1_count)
  922. wsa_priv->rx_1_count--;
  923. ch_cnt = wsa_priv->rx_0_count + wsa_priv->rx_1_count;
  924. swrm_wcd_notify(
  925. wsa_priv->swr_ctrl_data[0].wsa_swr_pdev,
  926. SWR_SET_NUM_RX_CH, &ch_cnt);
  927. break;
  928. }
  929. dev_dbg(wsa_priv->dev, "%s: current swr ch cnt: %d\n",
  930. __func__, wsa_priv->rx_0_count + wsa_priv->rx_1_count);
  931. return 0;
  932. }
  933. static int wsa_macro_config_compander(struct snd_soc_codec *codec,
  934. int comp, int event)
  935. {
  936. u16 comp_ctl0_reg, rx_path_cfg0_reg;
  937. struct device *wsa_dev = NULL;
  938. struct wsa_macro_priv *wsa_priv = NULL;
  939. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  940. return -EINVAL;
  941. dev_dbg(codec->dev, "%s: event %d compander %d, enabled %d\n",
  942. __func__, event, comp + 1, wsa_priv->comp_enabled[comp]);
  943. if (!wsa_priv->comp_enabled[comp])
  944. return 0;
  945. comp_ctl0_reg = BOLERO_CDC_WSA_COMPANDER0_CTL0 +
  946. (comp * WSA_MACRO_RX_COMP_OFFSET);
  947. rx_path_cfg0_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CFG0 +
  948. (comp * WSA_MACRO_RX_PATH_OFFSET);
  949. if (SND_SOC_DAPM_EVENT_ON(event)) {
  950. /* Enable Compander Clock */
  951. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x01);
  952. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  953. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  954. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x02);
  955. }
  956. if (SND_SOC_DAPM_EVENT_OFF(event)) {
  957. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x04);
  958. snd_soc_update_bits(codec, rx_path_cfg0_reg, 0x02, 0x00);
  959. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x02);
  960. snd_soc_update_bits(codec, comp_ctl0_reg, 0x02, 0x00);
  961. snd_soc_update_bits(codec, comp_ctl0_reg, 0x01, 0x00);
  962. snd_soc_update_bits(codec, comp_ctl0_reg, 0x04, 0x00);
  963. }
  964. return 0;
  965. }
  966. static int wsa_macro_interp_get_primary_reg(u16 reg, u16 *ind)
  967. {
  968. u16 prim_int_reg = 0;
  969. switch (reg) {
  970. case BOLERO_CDC_WSA_RX0_RX_PATH_CTL:
  971. case BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL:
  972. prim_int_reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  973. *ind = 0;
  974. break;
  975. case BOLERO_CDC_WSA_RX1_RX_PATH_CTL:
  976. case BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL:
  977. prim_int_reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  978. *ind = 1;
  979. break;
  980. }
  981. return prim_int_reg;
  982. }
  983. static int wsa_macro_enable_prim_interpolator(
  984. struct snd_soc_codec *codec,
  985. u16 reg, int event)
  986. {
  987. u16 prim_int_reg;
  988. u16 ind = 0;
  989. struct device *wsa_dev = NULL;
  990. struct wsa_macro_priv *wsa_priv = NULL;
  991. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  992. return -EINVAL;
  993. prim_int_reg = wsa_macro_interp_get_primary_reg(reg, &ind);
  994. switch (event) {
  995. case SND_SOC_DAPM_PRE_PMU:
  996. wsa_priv->prim_int_users[ind]++;
  997. if (wsa_priv->prim_int_users[ind] == 1) {
  998. snd_soc_update_bits(codec,
  999. prim_int_reg + WSA_MACRO_RX_PATH_CFG3_OFFSET,
  1000. 0x03, 0x03);
  1001. snd_soc_update_bits(codec, prim_int_reg,
  1002. 0x10, 0x10);
  1003. wsa_macro_hd2_control(codec, prim_int_reg, event);
  1004. snd_soc_update_bits(codec,
  1005. prim_int_reg + WSA_MACRO_RX_PATH_DSMDEM_OFFSET,
  1006. 0x1, 0x1);
  1007. snd_soc_update_bits(codec, prim_int_reg,
  1008. 1 << 0x5, 1 << 0x5);
  1009. }
  1010. if ((reg != prim_int_reg) &&
  1011. ((snd_soc_read(codec, prim_int_reg)) & 0x10))
  1012. snd_soc_update_bits(codec, reg, 0x10, 0x10);
  1013. break;
  1014. case SND_SOC_DAPM_POST_PMD:
  1015. wsa_priv->prim_int_users[ind]--;
  1016. if (wsa_priv->prim_int_users[ind] == 0) {
  1017. snd_soc_update_bits(codec, prim_int_reg,
  1018. 1 << 0x5, 0 << 0x5);
  1019. snd_soc_update_bits(codec, prim_int_reg,
  1020. 0x40, 0x40);
  1021. snd_soc_update_bits(codec, prim_int_reg,
  1022. 0x40, 0x00);
  1023. wsa_macro_hd2_control(codec, prim_int_reg, event);
  1024. }
  1025. break;
  1026. }
  1027. dev_dbg(codec->dev, "%s: primary interpolator: INT%d, users: %d\n",
  1028. __func__, ind, wsa_priv->prim_int_users[ind]);
  1029. return 0;
  1030. }
  1031. static int wsa_macro_enable_interpolator(struct snd_soc_dapm_widget *w,
  1032. struct snd_kcontrol *kcontrol,
  1033. int event)
  1034. {
  1035. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1036. u16 gain_reg;
  1037. u16 reg;
  1038. int val;
  1039. int offset_val = 0;
  1040. struct device *wsa_dev = NULL;
  1041. struct wsa_macro_priv *wsa_priv = NULL;
  1042. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1043. return -EINVAL;
  1044. dev_dbg(codec->dev, "%s %d %s\n", __func__, event, w->name);
  1045. if (!(strcmp(w->name, "WSA_RX INT0 INTERP"))) {
  1046. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  1047. gain_reg = BOLERO_CDC_WSA_RX0_RX_VOL_CTL;
  1048. } else if (!(strcmp(w->name, "WSA_RX INT1 INTERP"))) {
  1049. reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  1050. gain_reg = BOLERO_CDC_WSA_RX1_RX_VOL_CTL;
  1051. } else {
  1052. dev_err(codec->dev, "%s: Interpolator reg not found\n",
  1053. __func__);
  1054. return -EINVAL;
  1055. }
  1056. switch (event) {
  1057. case SND_SOC_DAPM_PRE_PMU:
  1058. /* Reset if needed */
  1059. wsa_macro_enable_prim_interpolator(codec, reg, event);
  1060. break;
  1061. case SND_SOC_DAPM_POST_PMU:
  1062. wsa_macro_config_compander(codec, w->shift, event);
  1063. /* apply gain after int clk is enabled */
  1064. if ((wsa_priv->spkr_gain_offset ==
  1065. WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
  1066. (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
  1067. wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
  1068. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
  1069. gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
  1070. snd_soc_update_bits(codec, BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
  1071. 0x01, 0x01);
  1072. snd_soc_update_bits(codec,
  1073. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
  1074. 0x01, 0x01);
  1075. snd_soc_update_bits(codec, BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
  1076. 0x01, 0x01);
  1077. snd_soc_update_bits(codec,
  1078. BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
  1079. 0x01, 0x01);
  1080. offset_val = -2;
  1081. }
  1082. val = snd_soc_read(codec, gain_reg);
  1083. val += offset_val;
  1084. snd_soc_write(codec, gain_reg, val);
  1085. wsa_macro_config_ear_spkr_gain(codec, wsa_priv,
  1086. event, gain_reg);
  1087. break;
  1088. case SND_SOC_DAPM_POST_PMD:
  1089. wsa_macro_config_compander(codec, w->shift, event);
  1090. wsa_macro_enable_prim_interpolator(codec, reg, event);
  1091. if ((wsa_priv->spkr_gain_offset ==
  1092. WSA_MACRO_GAIN_OFFSET_M1P5_DB) &&
  1093. (wsa_priv->comp_enabled[WSA_MACRO_COMP1] ||
  1094. wsa_priv->comp_enabled[WSA_MACRO_COMP2]) &&
  1095. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL ||
  1096. gain_reg == BOLERO_CDC_WSA_RX1_RX_VOL_CTL)) {
  1097. snd_soc_update_bits(codec, BOLERO_CDC_WSA_RX0_RX_PATH_SEC1,
  1098. 0x01, 0x00);
  1099. snd_soc_update_bits(codec,
  1100. BOLERO_CDC_WSA_RX0_RX_PATH_MIX_SEC0,
  1101. 0x01, 0x00);
  1102. snd_soc_update_bits(codec, BOLERO_CDC_WSA_RX1_RX_PATH_SEC1,
  1103. 0x01, 0x00);
  1104. snd_soc_update_bits(codec,
  1105. BOLERO_CDC_WSA_RX1_RX_PATH_MIX_SEC0,
  1106. 0x01, 0x00);
  1107. offset_val = 2;
  1108. val = snd_soc_read(codec, gain_reg);
  1109. val += offset_val;
  1110. snd_soc_write(codec, gain_reg, val);
  1111. }
  1112. wsa_macro_config_ear_spkr_gain(codec, wsa_priv,
  1113. event, gain_reg);
  1114. break;
  1115. }
  1116. return 0;
  1117. }
  1118. static int wsa_macro_config_ear_spkr_gain(struct snd_soc_codec *codec,
  1119. struct wsa_macro_priv *wsa_priv,
  1120. int event, int gain_reg)
  1121. {
  1122. int comp_gain_offset, val;
  1123. switch (wsa_priv->spkr_mode) {
  1124. /* Compander gain in WSA_MACRO_SPKR_MODE1 case is 12 dB */
  1125. case WSA_MACRO_SPKR_MODE_1:
  1126. comp_gain_offset = -12;
  1127. break;
  1128. /* Default case compander gain is 15 dB */
  1129. default:
  1130. comp_gain_offset = -15;
  1131. break;
  1132. }
  1133. switch (event) {
  1134. case SND_SOC_DAPM_POST_PMU:
  1135. /* Apply ear spkr gain only if compander is enabled */
  1136. if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
  1137. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
  1138. (wsa_priv->ear_spkr_gain != 0)) {
  1139. /* For example, val is -8(-12+5-1) for 4dB of gain */
  1140. val = comp_gain_offset + wsa_priv->ear_spkr_gain - 1;
  1141. snd_soc_write(codec, gain_reg, val);
  1142. dev_dbg(wsa_priv->dev, "%s: RX0 Volume %d dB\n",
  1143. __func__, val);
  1144. }
  1145. break;
  1146. case SND_SOC_DAPM_POST_PMD:
  1147. /*
  1148. * Reset RX0 volume to 0 dB if compander is enabled and
  1149. * ear_spkr_gain is non-zero.
  1150. */
  1151. if (wsa_priv->comp_enabled[WSA_MACRO_COMP1] &&
  1152. (gain_reg == BOLERO_CDC_WSA_RX0_RX_VOL_CTL) &&
  1153. (wsa_priv->ear_spkr_gain != 0)) {
  1154. snd_soc_write(codec, gain_reg, 0x0);
  1155. dev_dbg(wsa_priv->dev, "%s: Reset RX0 Volume to 0 dB\n",
  1156. __func__);
  1157. }
  1158. break;
  1159. }
  1160. return 0;
  1161. }
  1162. static int wsa_macro_spk_boost_event(struct snd_soc_dapm_widget *w,
  1163. struct snd_kcontrol *kcontrol,
  1164. int event)
  1165. {
  1166. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1167. u16 boost_path_ctl, boost_path_cfg1;
  1168. u16 reg, reg_mix;
  1169. dev_dbg(codec->dev, "%s %s %d\n", __func__, w->name, event);
  1170. if (!strcmp(w->name, "WSA_RX INT0 CHAIN")) {
  1171. boost_path_ctl = BOLERO_CDC_WSA_BOOST0_BOOST_PATH_CTL;
  1172. boost_path_cfg1 = BOLERO_CDC_WSA_RX0_RX_PATH_CFG1;
  1173. reg = BOLERO_CDC_WSA_RX0_RX_PATH_CTL;
  1174. reg_mix = BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CTL;
  1175. } else if (!strcmp(w->name, "WSA_RX INT1 CHAIN")) {
  1176. boost_path_ctl = BOLERO_CDC_WSA_BOOST1_BOOST_PATH_CTL;
  1177. boost_path_cfg1 = BOLERO_CDC_WSA_RX1_RX_PATH_CFG1;
  1178. reg = BOLERO_CDC_WSA_RX1_RX_PATH_CTL;
  1179. reg_mix = BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CTL;
  1180. } else {
  1181. dev_err(codec->dev, "%s: unknown widget: %s\n",
  1182. __func__, w->name);
  1183. return -EINVAL;
  1184. }
  1185. switch (event) {
  1186. case SND_SOC_DAPM_PRE_PMU:
  1187. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x01);
  1188. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x10);
  1189. if ((snd_soc_read(codec, reg_mix)) & 0x10)
  1190. snd_soc_update_bits(codec, reg_mix, 0x10, 0x00);
  1191. break;
  1192. case SND_SOC_DAPM_POST_PMU:
  1193. snd_soc_update_bits(codec, reg, 0x10, 0x00);
  1194. break;
  1195. case SND_SOC_DAPM_POST_PMD:
  1196. snd_soc_update_bits(codec, boost_path_ctl, 0x10, 0x00);
  1197. snd_soc_update_bits(codec, boost_path_cfg1, 0x01, 0x00);
  1198. break;
  1199. }
  1200. return 0;
  1201. }
  1202. static int wsa_macro_enable_echo(struct snd_soc_dapm_widget *w,
  1203. struct snd_kcontrol *kcontrol,
  1204. int event)
  1205. {
  1206. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
  1207. struct device *wsa_dev = NULL;
  1208. struct wsa_macro_priv *wsa_priv = NULL;
  1209. u16 val, ec_tx = 0, ec_hq_reg;
  1210. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1211. return -EINVAL;
  1212. dev_dbg(wsa_dev, "%s %d %s\n", __func__, event, w->name);
  1213. val = snd_soc_read(codec, BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0);
  1214. if (!(strcmp(w->name, "WSA RX_MIX EC0_MUX")))
  1215. ec_tx = (val & 0x07) - 1;
  1216. else
  1217. ec_tx = ((val & 0x38) >> 0x3) - 1;
  1218. if (ec_tx < 0 || ec_tx >= (WSA_MACRO_RX1 + 1)) {
  1219. dev_err(wsa_dev, "%s: EC mix control not set correctly\n",
  1220. __func__);
  1221. return -EINVAL;
  1222. }
  1223. if (wsa_priv->ec_hq[ec_tx]) {
  1224. snd_soc_update_bits(codec,
  1225. BOLERO_CDC_WSA_RX_INP_MUX_RX_MIX_CFG0,
  1226. 0x1 << ec_tx, 0x1 << ec_tx);
  1227. ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_PATH_CTL +
  1228. 0x20 * ec_tx;
  1229. snd_soc_update_bits(codec, ec_hq_reg, 0x01, 0x01);
  1230. ec_hq_reg = BOLERO_CDC_WSA_EC_HQ0_EC_REF_HQ_CFG0 +
  1231. 0x20 * ec_tx;
  1232. /* default set to 48k */
  1233. snd_soc_update_bits(codec, ec_hq_reg, 0x1E, 0x08);
  1234. }
  1235. return 0;
  1236. }
  1237. static int wsa_macro_get_ec_hq(struct snd_kcontrol *kcontrol,
  1238. struct snd_ctl_elem_value *ucontrol)
  1239. {
  1240. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1241. int ec_tx = ((struct soc_multi_mixer_control *)
  1242. kcontrol->private_value)->shift;
  1243. struct device *wsa_dev = NULL;
  1244. struct wsa_macro_priv *wsa_priv = NULL;
  1245. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1246. return -EINVAL;
  1247. ucontrol->value.integer.value[0] = wsa_priv->ec_hq[ec_tx];
  1248. return 0;
  1249. }
  1250. static int wsa_macro_set_ec_hq(struct snd_kcontrol *kcontrol,
  1251. struct snd_ctl_elem_value *ucontrol)
  1252. {
  1253. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1254. int ec_tx = ((struct soc_multi_mixer_control *)
  1255. kcontrol->private_value)->shift;
  1256. int value = ucontrol->value.integer.value[0];
  1257. struct device *wsa_dev = NULL;
  1258. struct wsa_macro_priv *wsa_priv = NULL;
  1259. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1260. return -EINVAL;
  1261. dev_dbg(wsa_dev, "%s: enable current %d, new %d\n",
  1262. __func__, wsa_priv->ec_hq[ec_tx], value);
  1263. wsa_priv->ec_hq[ec_tx] = value;
  1264. return 0;
  1265. }
  1266. static int wsa_macro_get_compander(struct snd_kcontrol *kcontrol,
  1267. struct snd_ctl_elem_value *ucontrol)
  1268. {
  1269. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1270. int comp = ((struct soc_multi_mixer_control *)
  1271. kcontrol->private_value)->shift;
  1272. struct device *wsa_dev = NULL;
  1273. struct wsa_macro_priv *wsa_priv = NULL;
  1274. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1275. return -EINVAL;
  1276. ucontrol->value.integer.value[0] = wsa_priv->comp_enabled[comp];
  1277. return 0;
  1278. }
  1279. static int wsa_macro_set_compander(struct snd_kcontrol *kcontrol,
  1280. struct snd_ctl_elem_value *ucontrol)
  1281. {
  1282. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1283. int comp = ((struct soc_multi_mixer_control *)
  1284. kcontrol->private_value)->shift;
  1285. int value = ucontrol->value.integer.value[0];
  1286. struct device *wsa_dev = NULL;
  1287. struct wsa_macro_priv *wsa_priv = NULL;
  1288. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1289. return -EINVAL;
  1290. dev_dbg(codec->dev, "%s: Compander %d enable current %d, new %d\n",
  1291. __func__, comp + 1, wsa_priv->comp_enabled[comp], value);
  1292. wsa_priv->comp_enabled[comp] = value;
  1293. return 0;
  1294. }
  1295. static int wsa_macro_ear_spkr_pa_gain_get(struct snd_kcontrol *kcontrol,
  1296. struct snd_ctl_elem_value *ucontrol)
  1297. {
  1298. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1299. struct device *wsa_dev = NULL;
  1300. struct wsa_macro_priv *wsa_priv = NULL;
  1301. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1302. return -EINVAL;
  1303. ucontrol->value.integer.value[0] = wsa_priv->ear_spkr_gain;
  1304. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1305. __func__, ucontrol->value.integer.value[0]);
  1306. return 0;
  1307. }
  1308. static int wsa_macro_ear_spkr_pa_gain_put(struct snd_kcontrol *kcontrol,
  1309. struct snd_ctl_elem_value *ucontrol)
  1310. {
  1311. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1312. struct device *wsa_dev = NULL;
  1313. struct wsa_macro_priv *wsa_priv = NULL;
  1314. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1315. return -EINVAL;
  1316. wsa_priv->ear_spkr_gain = ucontrol->value.integer.value[0];
  1317. dev_dbg(codec->dev, "%s: gain = %d\n", __func__,
  1318. wsa_priv->ear_spkr_gain);
  1319. return 0;
  1320. }
  1321. static int wsa_macro_spkr_left_boost_stage_get(struct snd_kcontrol *kcontrol,
  1322. struct snd_ctl_elem_value *ucontrol)
  1323. {
  1324. u8 bst_state_max = 0;
  1325. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1326. bst_state_max = snd_soc_read(codec, BOLERO_CDC_WSA_BOOST0_BOOST_CTL);
  1327. bst_state_max = (bst_state_max & 0x0c) >> 2;
  1328. ucontrol->value.integer.value[0] = bst_state_max;
  1329. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1330. __func__, ucontrol->value.integer.value[0]);
  1331. return 0;
  1332. }
  1333. static int wsa_macro_spkr_left_boost_stage_put(struct snd_kcontrol *kcontrol,
  1334. struct snd_ctl_elem_value *ucontrol)
  1335. {
  1336. u8 bst_state_max;
  1337. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1338. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1339. __func__, ucontrol->value.integer.value[0]);
  1340. bst_state_max = ucontrol->value.integer.value[0] << 2;
  1341. snd_soc_update_bits(codec, BOLERO_CDC_WSA_BOOST0_BOOST_CTL,
  1342. 0x0c, bst_state_max);
  1343. return 0;
  1344. }
  1345. static int wsa_macro_spkr_right_boost_stage_get(struct snd_kcontrol *kcontrol,
  1346. struct snd_ctl_elem_value *ucontrol)
  1347. {
  1348. u8 bst_state_max = 0;
  1349. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1350. bst_state_max = snd_soc_read(codec, BOLERO_CDC_WSA_BOOST1_BOOST_CTL);
  1351. bst_state_max = (bst_state_max & 0x0c) >> 2;
  1352. ucontrol->value.integer.value[0] = bst_state_max;
  1353. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1354. __func__, ucontrol->value.integer.value[0]);
  1355. return 0;
  1356. }
  1357. static int wsa_macro_spkr_right_boost_stage_put(struct snd_kcontrol *kcontrol,
  1358. struct snd_ctl_elem_value *ucontrol)
  1359. {
  1360. u8 bst_state_max;
  1361. struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
  1362. dev_dbg(codec->dev, "%s: ucontrol->value.integer.value[0] = %ld\n",
  1363. __func__, ucontrol->value.integer.value[0]);
  1364. bst_state_max = ucontrol->value.integer.value[0] << 2;
  1365. snd_soc_update_bits(codec, BOLERO_CDC_WSA_BOOST1_BOOST_CTL,
  1366. 0x0c, bst_state_max);
  1367. return 0;
  1368. }
  1369. static int wsa_macro_rx_mux_get(struct snd_kcontrol *kcontrol,
  1370. struct snd_ctl_elem_value *ucontrol)
  1371. {
  1372. struct snd_soc_dapm_widget *widget =
  1373. snd_soc_dapm_kcontrol_widget(kcontrol);
  1374. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1375. struct device *wsa_dev = NULL;
  1376. struct wsa_macro_priv *wsa_priv = NULL;
  1377. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1378. return -EINVAL;
  1379. ucontrol->value.integer.value[0] =
  1380. wsa_priv->rx_port_value[widget->shift];
  1381. return 0;
  1382. }
  1383. static int wsa_macro_rx_mux_put(struct snd_kcontrol *kcontrol,
  1384. struct snd_ctl_elem_value *ucontrol)
  1385. {
  1386. struct snd_soc_dapm_widget *widget =
  1387. snd_soc_dapm_kcontrol_widget(kcontrol);
  1388. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1389. struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
  1390. struct snd_soc_dapm_update *update = NULL;
  1391. u32 rx_port_value = ucontrol->value.integer.value[0];
  1392. u32 bit_input = 0;
  1393. u32 aif_rst;
  1394. struct device *wsa_dev = NULL;
  1395. struct wsa_macro_priv *wsa_priv = NULL;
  1396. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1397. return -EINVAL;
  1398. aif_rst = wsa_priv->rx_port_value[widget->shift];
  1399. if (!rx_port_value) {
  1400. if (aif_rst == 0) {
  1401. dev_err(wsa_dev, "%s: AIF reset already\n", __func__);
  1402. return 0;
  1403. }
  1404. }
  1405. wsa_priv->rx_port_value[widget->shift] = rx_port_value;
  1406. bit_input = widget->shift;
  1407. if (widget->shift >= WSA_MACRO_RX_MIX)
  1408. bit_input %= WSA_MACRO_RX_MIX;
  1409. switch (rx_port_value) {
  1410. case 0:
  1411. clear_bit(bit_input,
  1412. &wsa_priv->active_ch_mask[aif_rst]);
  1413. wsa_priv->active_ch_cnt[aif_rst]--;
  1414. break;
  1415. case 1:
  1416. case 2:
  1417. set_bit(bit_input,
  1418. &wsa_priv->active_ch_mask[rx_port_value]);
  1419. wsa_priv->active_ch_cnt[rx_port_value]++;
  1420. break;
  1421. default:
  1422. dev_err(wsa_dev,
  1423. "%s: Invalid AIF_ID for WSA RX MUX\n", __func__);
  1424. return -EINVAL;
  1425. }
  1426. snd_soc_dapm_mux_update_power(widget->dapm, kcontrol,
  1427. rx_port_value, e, update);
  1428. return 0;
  1429. }
  1430. static const struct snd_kcontrol_new wsa_macro_snd_controls[] = {
  1431. SOC_ENUM_EXT("EAR SPKR PA Gain", wsa_macro_ear_spkr_pa_gain_enum,
  1432. wsa_macro_ear_spkr_pa_gain_get,
  1433. wsa_macro_ear_spkr_pa_gain_put),
  1434. SOC_ENUM_EXT("SPKR Left Boost Max State",
  1435. wsa_macro_spkr_boost_stage_enum,
  1436. wsa_macro_spkr_left_boost_stage_get,
  1437. wsa_macro_spkr_left_boost_stage_put),
  1438. SOC_ENUM_EXT("SPKR Right Boost Max State",
  1439. wsa_macro_spkr_boost_stage_enum,
  1440. wsa_macro_spkr_right_boost_stage_get,
  1441. wsa_macro_spkr_right_boost_stage_put),
  1442. SOC_SINGLE_SX_TLV("WSA_RX0 Digital Volume",
  1443. BOLERO_CDC_WSA_RX0_RX_VOL_CTL,
  1444. 0, -84, 40, digital_gain),
  1445. SOC_SINGLE_SX_TLV("WSA_RX1 Digital Volume",
  1446. BOLERO_CDC_WSA_RX1_RX_VOL_CTL,
  1447. 0, -84, 40, digital_gain),
  1448. SOC_SINGLE_EXT("WSA_COMP1 Switch", SND_SOC_NOPM, WSA_MACRO_COMP1, 1, 0,
  1449. wsa_macro_get_compander, wsa_macro_set_compander),
  1450. SOC_SINGLE_EXT("WSA_COMP2 Switch", SND_SOC_NOPM, WSA_MACRO_COMP2, 1, 0,
  1451. wsa_macro_get_compander, wsa_macro_set_compander),
  1452. SOC_SINGLE_EXT("WSA_RX0 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX0,
  1453. 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
  1454. SOC_SINGLE_EXT("WSA_RX1 EC_HQ Switch", SND_SOC_NOPM, WSA_MACRO_RX1,
  1455. 1, 0, wsa_macro_get_ec_hq, wsa_macro_set_ec_hq),
  1456. };
  1457. static const struct soc_enum rx_mux_enum =
  1458. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(rx_mux_text), rx_mux_text);
  1459. static const struct snd_kcontrol_new rx_mux[WSA_MACRO_RX_MAX] = {
  1460. SOC_DAPM_ENUM_EXT("WSA RX0 Mux", rx_mux_enum,
  1461. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  1462. SOC_DAPM_ENUM_EXT("WSA RX1 Mux", rx_mux_enum,
  1463. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  1464. SOC_DAPM_ENUM_EXT("WSA RX_MIX0 Mux", rx_mux_enum,
  1465. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  1466. SOC_DAPM_ENUM_EXT("WSA RX_MIX1 Mux", rx_mux_enum,
  1467. wsa_macro_rx_mux_get, wsa_macro_rx_mux_put),
  1468. };
  1469. static int wsa_macro_vi_feed_mixer_get(struct snd_kcontrol *kcontrol,
  1470. struct snd_ctl_elem_value *ucontrol)
  1471. {
  1472. struct snd_soc_dapm_widget *widget =
  1473. snd_soc_dapm_kcontrol_widget(kcontrol);
  1474. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1475. struct soc_multi_mixer_control *mixer =
  1476. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1477. u32 dai_id = widget->shift;
  1478. u32 spk_tx_id = mixer->shift;
  1479. struct device *wsa_dev = NULL;
  1480. struct wsa_macro_priv *wsa_priv = NULL;
  1481. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1482. return -EINVAL;
  1483. if (test_bit(spk_tx_id, &wsa_priv->active_ch_mask[dai_id]))
  1484. ucontrol->value.integer.value[0] = 1;
  1485. else
  1486. ucontrol->value.integer.value[0] = 0;
  1487. return 0;
  1488. }
  1489. static int wsa_macro_vi_feed_mixer_put(struct snd_kcontrol *kcontrol,
  1490. struct snd_ctl_elem_value *ucontrol)
  1491. {
  1492. struct snd_soc_dapm_widget *widget =
  1493. snd_soc_dapm_kcontrol_widget(kcontrol);
  1494. struct snd_soc_codec *codec = snd_soc_dapm_to_codec(widget->dapm);
  1495. struct soc_multi_mixer_control *mixer =
  1496. ((struct soc_multi_mixer_control *)kcontrol->private_value);
  1497. u32 spk_tx_id = mixer->shift;
  1498. u32 enable = ucontrol->value.integer.value[0];
  1499. struct device *wsa_dev = NULL;
  1500. struct wsa_macro_priv *wsa_priv = NULL;
  1501. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1502. return -EINVAL;
  1503. wsa_priv->vi_feed_value = ucontrol->value.integer.value[0];
  1504. if (enable) {
  1505. if (spk_tx_id == WSA_MACRO_TX0 &&
  1506. !test_bit(WSA_MACRO_TX0,
  1507. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1508. set_bit(WSA_MACRO_TX0,
  1509. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  1510. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
  1511. }
  1512. if (spk_tx_id == WSA_MACRO_TX1 &&
  1513. !test_bit(WSA_MACRO_TX1,
  1514. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1515. set_bit(WSA_MACRO_TX1,
  1516. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  1517. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]++;
  1518. }
  1519. } else {
  1520. if (spk_tx_id == WSA_MACRO_TX0 &&
  1521. test_bit(WSA_MACRO_TX0,
  1522. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1523. clear_bit(WSA_MACRO_TX0,
  1524. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  1525. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
  1526. }
  1527. if (spk_tx_id == WSA_MACRO_TX1 &&
  1528. test_bit(WSA_MACRO_TX1,
  1529. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI])) {
  1530. clear_bit(WSA_MACRO_TX1,
  1531. &wsa_priv->active_ch_mask[WSA_MACRO_AIF_VI]);
  1532. wsa_priv->active_ch_cnt[WSA_MACRO_AIF_VI]--;
  1533. }
  1534. }
  1535. snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol, enable, NULL);
  1536. return 0;
  1537. }
  1538. static const struct snd_kcontrol_new aif_vi_mixer[] = {
  1539. SOC_SINGLE_EXT("WSA_SPKR_VI_1", SND_SOC_NOPM, WSA_MACRO_TX0, 1, 0,
  1540. wsa_macro_vi_feed_mixer_get,
  1541. wsa_macro_vi_feed_mixer_put),
  1542. SOC_SINGLE_EXT("WSA_SPKR_VI_2", SND_SOC_NOPM, WSA_MACRO_TX1, 1, 0,
  1543. wsa_macro_vi_feed_mixer_get,
  1544. wsa_macro_vi_feed_mixer_put),
  1545. };
  1546. static const struct snd_soc_dapm_widget wsa_macro_dapm_widgets[] = {
  1547. SND_SOC_DAPM_AIF_IN("WSA AIF1 PB", "WSA_AIF1 Playback", 0,
  1548. SND_SOC_NOPM, 0, 0),
  1549. SND_SOC_DAPM_AIF_IN("WSA AIF_MIX1 PB", "WSA_AIF_MIX1 Playback", 0,
  1550. SND_SOC_NOPM, 0, 0),
  1551. SND_SOC_DAPM_AIF_OUT_E("WSA AIF_VI", "WSA_AIF_VI Capture", 0,
  1552. SND_SOC_NOPM, WSA_MACRO_AIF_VI, 0,
  1553. wsa_macro_enable_vi_feedback,
  1554. SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
  1555. SND_SOC_DAPM_AIF_OUT("WSA AIF_ECHO", "WSA_AIF_ECHO Capture", 0,
  1556. SND_SOC_NOPM, 0, 0),
  1557. SND_SOC_DAPM_MIXER("WSA_AIF_VI Mixer", SND_SOC_NOPM, WSA_MACRO_AIF_VI,
  1558. 0, aif_vi_mixer, ARRAY_SIZE(aif_vi_mixer)),
  1559. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC0_MUX", SND_SOC_NOPM,
  1560. WSA_MACRO_EC0_MUX, 0,
  1561. &rx_mix_ec0_mux, wsa_macro_enable_echo,
  1562. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1563. SND_SOC_DAPM_MUX_E("WSA RX_MIX EC1_MUX", SND_SOC_NOPM,
  1564. WSA_MACRO_EC1_MUX, 0,
  1565. &rx_mix_ec1_mux, wsa_macro_enable_echo,
  1566. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1567. SND_SOC_DAPM_MUX("WSA RX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX0, 0,
  1568. &rx_mux[WSA_MACRO_RX0]),
  1569. SND_SOC_DAPM_MUX("WSA RX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX1, 0,
  1570. &rx_mux[WSA_MACRO_RX1]),
  1571. SND_SOC_DAPM_MUX("WSA RX_MIX0 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX0, 0,
  1572. &rx_mux[WSA_MACRO_RX_MIX0]),
  1573. SND_SOC_DAPM_MUX("WSA RX_MIX1 MUX", SND_SOC_NOPM, WSA_MACRO_RX_MIX1, 0,
  1574. &rx_mux[WSA_MACRO_RX_MIX1]),
  1575. SND_SOC_DAPM_MIXER("WSA RX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  1576. SND_SOC_DAPM_MIXER("WSA RX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1577. SND_SOC_DAPM_MIXER("WSA RX_MIX0", SND_SOC_NOPM, 0, 0, NULL, 0),
  1578. SND_SOC_DAPM_MIXER("WSA RX_MIX1", SND_SOC_NOPM, 0, 0, NULL, 0),
  1579. SND_SOC_DAPM_MUX_E("WSA_RX0 INP0", SND_SOC_NOPM, 0, 0,
  1580. &rx0_prim_inp0_mux, wsa_macro_enable_swr,
  1581. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1582. SND_SOC_DAPM_MUX_E("WSA_RX0 INP1", SND_SOC_NOPM, 0, 0,
  1583. &rx0_prim_inp1_mux, wsa_macro_enable_swr,
  1584. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1585. SND_SOC_DAPM_MUX_E("WSA_RX0 INP2", SND_SOC_NOPM, 0, 0,
  1586. &rx0_prim_inp2_mux, wsa_macro_enable_swr,
  1587. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1588. SND_SOC_DAPM_MUX_E("WSA_RX0 MIX INP", SND_SOC_NOPM, 0, 0,
  1589. &rx0_mix_mux, wsa_macro_enable_mix_path,
  1590. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1591. SND_SOC_DAPM_MUX_E("WSA_RX1 INP0", SND_SOC_NOPM, 0, 0,
  1592. &rx1_prim_inp0_mux, wsa_macro_enable_swr,
  1593. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1594. SND_SOC_DAPM_MUX_E("WSA_RX1 INP1", SND_SOC_NOPM, 0, 0,
  1595. &rx1_prim_inp1_mux, wsa_macro_enable_swr,
  1596. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1597. SND_SOC_DAPM_MUX_E("WSA_RX1 INP2", SND_SOC_NOPM, 0, 0,
  1598. &rx1_prim_inp2_mux, wsa_macro_enable_swr,
  1599. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1600. SND_SOC_DAPM_MUX_E("WSA_RX1 MIX INP", SND_SOC_NOPM, 0, 0,
  1601. &rx1_mix_mux, wsa_macro_enable_mix_path,
  1602. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1603. SND_SOC_DAPM_MIXER("WSA_RX INT0 MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1604. SND_SOC_DAPM_MIXER("WSA_RX INT1 MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1605. SND_SOC_DAPM_MIXER("WSA_RX INT0 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1606. SND_SOC_DAPM_MIXER("WSA_RX INT1 SEC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
  1607. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 INTERP", SND_SOC_NOPM,
  1608. WSA_MACRO_COMP1, 0, NULL, 0, wsa_macro_enable_interpolator,
  1609. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1610. SND_SOC_DAPM_POST_PMD),
  1611. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 INTERP", SND_SOC_NOPM,
  1612. WSA_MACRO_COMP2, 0, NULL, 0, wsa_macro_enable_interpolator,
  1613. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1614. SND_SOC_DAPM_POST_PMD),
  1615. SND_SOC_DAPM_MIXER_E("WSA_RX INT0 CHAIN", SND_SOC_NOPM, 0, 0,
  1616. NULL, 0, wsa_macro_spk_boost_event,
  1617. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1618. SND_SOC_DAPM_POST_PMD),
  1619. SND_SOC_DAPM_MIXER_E("WSA_RX INT1 CHAIN", SND_SOC_NOPM, 0, 0,
  1620. NULL, 0, wsa_macro_spk_boost_event,
  1621. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
  1622. SND_SOC_DAPM_POST_PMD),
  1623. SND_SOC_DAPM_INPUT("VIINPUT_WSA"),
  1624. SND_SOC_DAPM_OUTPUT("WSA_SPK1 OUT"),
  1625. SND_SOC_DAPM_OUTPUT("WSA_SPK2 OUT"),
  1626. SND_SOC_DAPM_SUPPLY_S("WSA_MCLK", 0, SND_SOC_NOPM, 0, 0,
  1627. wsa_macro_mclk_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  1628. };
  1629. static const struct snd_soc_dapm_route wsa_audio_map[] = {
  1630. /* VI Feedback */
  1631. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_1", "VIINPUT_WSA"},
  1632. {"WSA_AIF_VI Mixer", "WSA_SPKR_VI_2", "VIINPUT_WSA"},
  1633. {"WSA AIF_VI", NULL, "WSA_AIF_VI Mixer"},
  1634. {"WSA AIF_VI", NULL, "WSA_MCLK"},
  1635. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  1636. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX0", "WSA_RX INT0 SEC MIX"},
  1637. {"WSA RX_MIX EC0_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  1638. {"WSA RX_MIX EC1_MUX", "RX_MIX_TX1", "WSA_RX INT1 SEC MIX"},
  1639. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC0_MUX"},
  1640. {"WSA AIF_ECHO", NULL, "WSA RX_MIX EC1_MUX"},
  1641. {"WSA AIF_ECHO", NULL, "WSA_MCLK"},
  1642. {"WSA AIF1 PB", NULL, "WSA_MCLK"},
  1643. {"WSA AIF_MIX1 PB", NULL, "WSA_MCLK"},
  1644. {"WSA RX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  1645. {"WSA RX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  1646. {"WSA RX_MIX0 MUX", "AIF1_PB", "WSA AIF1 PB"},
  1647. {"WSA RX_MIX1 MUX", "AIF1_PB", "WSA AIF1 PB"},
  1648. {"WSA RX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  1649. {"WSA RX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  1650. {"WSA RX_MIX0 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  1651. {"WSA RX_MIX1 MUX", "AIF_MIX1_PB", "WSA AIF_MIX1 PB"},
  1652. {"WSA RX0", NULL, "WSA RX0 MUX"},
  1653. {"WSA RX1", NULL, "WSA RX1 MUX"},
  1654. {"WSA RX_MIX0", NULL, "WSA RX_MIX0 MUX"},
  1655. {"WSA RX_MIX1", NULL, "WSA RX_MIX1 MUX"},
  1656. {"WSA_RX0 INP0", "RX0", "WSA RX0"},
  1657. {"WSA_RX0 INP0", "RX1", "WSA RX1"},
  1658. {"WSA_RX0 INP0", "RX_MIX0", "WSA RX_MIX0"},
  1659. {"WSA_RX0 INP0", "RX_MIX1", "WSA RX_MIX1"},
  1660. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP0"},
  1661. {"WSA_RX0 INP1", "RX0", "WSA RX0"},
  1662. {"WSA_RX0 INP1", "RX1", "WSA RX1"},
  1663. {"WSA_RX0 INP1", "RX_MIX0", "WSA RX_MIX0"},
  1664. {"WSA_RX0 INP1", "RX_MIX1", "WSA RX_MIX1"},
  1665. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP1"},
  1666. {"WSA_RX0 INP2", "RX0", "WSA RX0"},
  1667. {"WSA_RX0 INP2", "RX1", "WSA RX1"},
  1668. {"WSA_RX0 INP2", "RX_MIX0", "WSA RX_MIX0"},
  1669. {"WSA_RX0 INP2", "RX_MIX1", "WSA RX_MIX1"},
  1670. {"WSA_RX INT0 MIX", NULL, "WSA_RX0 INP2"},
  1671. {"WSA_RX0 MIX INP", "RX0", "WSA RX0"},
  1672. {"WSA_RX0 MIX INP", "RX1", "WSA RX1"},
  1673. {"WSA_RX0 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  1674. {"WSA_RX0 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  1675. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX0 MIX INP"},
  1676. {"WSA_RX INT0 SEC MIX", NULL, "WSA_RX INT0 MIX"},
  1677. {"WSA_RX INT0 INTERP", NULL, "WSA_RX INT0 SEC MIX"},
  1678. {"WSA_RX INT0 CHAIN", NULL, "WSA_RX INT0 INTERP"},
  1679. {"WSA_SPK1 OUT", NULL, "WSA_RX INT0 CHAIN"},
  1680. {"WSA_SPK1 OUT", NULL, "WSA_MCLK"},
  1681. {"WSA_RX1 INP0", "RX0", "WSA RX0"},
  1682. {"WSA_RX1 INP0", "RX1", "WSA RX1"},
  1683. {"WSA_RX1 INP0", "RX_MIX0", "WSA RX_MIX0"},
  1684. {"WSA_RX1 INP0", "RX_MIX1", "WSA RX_MIX1"},
  1685. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP0"},
  1686. {"WSA_RX1 INP1", "RX0", "WSA RX0"},
  1687. {"WSA_RX1 INP1", "RX1", "WSA RX1"},
  1688. {"WSA_RX1 INP1", "RX_MIX0", "WSA RX_MIX0"},
  1689. {"WSA_RX1 INP1", "RX_MIX1", "WSA RX_MIX1"},
  1690. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP1"},
  1691. {"WSA_RX1 INP2", "RX0", "WSA RX0"},
  1692. {"WSA_RX1 INP2", "RX1", "WSA RX1"},
  1693. {"WSA_RX1 INP2", "RX_MIX0", "WSA RX_MIX0"},
  1694. {"WSA_RX1 INP2", "RX_MIX1", "WSA RX_MIX1"},
  1695. {"WSA_RX INT1 MIX", NULL, "WSA_RX1 INP2"},
  1696. {"WSA_RX1 MIX INP", "RX0", "WSA RX0"},
  1697. {"WSA_RX1 MIX INP", "RX1", "WSA RX1"},
  1698. {"WSA_RX1 MIX INP", "RX_MIX0", "WSA RX_MIX0"},
  1699. {"WSA_RX1 MIX INP", "RX_MIX1", "WSA RX_MIX1"},
  1700. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX1 MIX INP"},
  1701. {"WSA_RX INT1 SEC MIX", NULL, "WSA_RX INT1 MIX"},
  1702. {"WSA_RX INT1 INTERP", NULL, "WSA_RX INT1 SEC MIX"},
  1703. {"WSA_RX INT1 CHAIN", NULL, "WSA_RX INT1 INTERP"},
  1704. {"WSA_SPK2 OUT", NULL, "WSA_RX INT1 CHAIN"},
  1705. {"WSA_SPK2 OUT", NULL, "WSA_MCLK"},
  1706. };
  1707. static const struct wsa_macro_reg_mask_val wsa_macro_reg_init[] = {
  1708. {BOLERO_CDC_WSA_BOOST0_BOOST_CFG1, 0x3F, 0x12},
  1709. {BOLERO_CDC_WSA_BOOST0_BOOST_CFG2, 0x1C, 0x08},
  1710. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x1E, 0x18},
  1711. {BOLERO_CDC_WSA_BOOST1_BOOST_CFG1, 0x3F, 0x12},
  1712. {BOLERO_CDC_WSA_BOOST1_BOOST_CFG2, 0x1C, 0x08},
  1713. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x1E, 0x18},
  1714. {BOLERO_CDC_WSA_BOOST0_BOOST_CTL, 0x70, 0x58},
  1715. {BOLERO_CDC_WSA_BOOST1_BOOST_CTL, 0x70, 0x58},
  1716. {BOLERO_CDC_WSA_RX0_RX_PATH_CFG1, 0x08, 0x08},
  1717. {BOLERO_CDC_WSA_RX1_RX_PATH_CFG1, 0x08, 0x08},
  1718. {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x02, 0x02},
  1719. {BOLERO_CDC_WSA_TOP_TOP_CFG1, 0x01, 0x01},
  1720. {BOLERO_CDC_WSA_TX0_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1721. {BOLERO_CDC_WSA_TX1_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1722. {BOLERO_CDC_WSA_TX2_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1723. {BOLERO_CDC_WSA_TX3_SPKR_PROT_PATH_CFG0, 0x01, 0x01},
  1724. {BOLERO_CDC_WSA_COMPANDER0_CTL3, 0x80, 0x80},
  1725. {BOLERO_CDC_WSA_COMPANDER1_CTL3, 0x80, 0x80},
  1726. {BOLERO_CDC_WSA_COMPANDER0_CTL7, 0x01, 0x01},
  1727. {BOLERO_CDC_WSA_COMPANDER1_CTL7, 0x01, 0x01},
  1728. {BOLERO_CDC_WSA_RX0_RX_PATH_CFG0, 0x01, 0x01},
  1729. {BOLERO_CDC_WSA_RX1_RX_PATH_CFG0, 0x01, 0x01},
  1730. {BOLERO_CDC_WSA_RX0_RX_PATH_MIX_CFG, 0x01, 0x01},
  1731. {BOLERO_CDC_WSA_RX1_RX_PATH_MIX_CFG, 0x01, 0x01},
  1732. };
  1733. static void wsa_macro_init_reg(struct snd_soc_codec *codec)
  1734. {
  1735. int i;
  1736. for (i = 0; i < ARRAY_SIZE(wsa_macro_reg_init); i++)
  1737. snd_soc_update_bits(codec,
  1738. wsa_macro_reg_init[i].reg,
  1739. wsa_macro_reg_init[i].mask,
  1740. wsa_macro_reg_init[i].val);
  1741. }
  1742. static int wsa_swrm_clock(void *handle, bool enable)
  1743. {
  1744. struct wsa_macro_priv *wsa_priv = (struct wsa_macro_priv *) handle;
  1745. struct regmap *regmap = dev_get_regmap(wsa_priv->dev->parent, NULL);
  1746. mutex_lock(&wsa_priv->swr_clk_lock);
  1747. dev_dbg(wsa_priv->dev, "%s: swrm clock %s\n",
  1748. __func__, (enable ? "enable" : "disable"));
  1749. if (enable) {
  1750. wsa_priv->swr_clk_users++;
  1751. if (wsa_priv->swr_clk_users == 1) {
  1752. wsa_macro_mclk_enable(wsa_priv, 1, true);
  1753. regmap_update_bits(regmap,
  1754. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  1755. 0x01, 0x01);
  1756. regmap_update_bits(regmap,
  1757. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  1758. 0x1C, 0x0C);
  1759. msm_cdc_pinctrl_select_active_state(
  1760. wsa_priv->wsa_swr_gpio_p);
  1761. }
  1762. } else {
  1763. wsa_priv->swr_clk_users--;
  1764. if (wsa_priv->swr_clk_users == 0) {
  1765. regmap_update_bits(regmap,
  1766. BOLERO_CDC_WSA_CLK_RST_CTRL_SWR_CONTROL,
  1767. 0x01, 0x00);
  1768. msm_cdc_pinctrl_select_sleep_state(
  1769. wsa_priv->wsa_swr_gpio_p);
  1770. wsa_macro_mclk_enable(wsa_priv, 0, true);
  1771. }
  1772. }
  1773. dev_dbg(wsa_priv->dev, "%s: swrm clock users %d\n",
  1774. __func__, wsa_priv->swr_clk_users);
  1775. mutex_unlock(&wsa_priv->swr_clk_lock);
  1776. return 0;
  1777. }
  1778. static int wsa_macro_init(struct snd_soc_codec *codec)
  1779. {
  1780. struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
  1781. int ret;
  1782. struct device *wsa_dev = NULL;
  1783. struct wsa_macro_priv *wsa_priv = NULL;
  1784. wsa_dev = bolero_get_device_ptr(codec->dev, WSA_MACRO);
  1785. if (!wsa_dev) {
  1786. dev_err(codec->dev,
  1787. "%s: null device for macro!\n", __func__);
  1788. return -EINVAL;
  1789. }
  1790. wsa_priv = dev_get_drvdata(wsa_dev);
  1791. if (!wsa_priv) {
  1792. dev_err(codec->dev,
  1793. "%s: priv is null for macro!\n", __func__);
  1794. return -EINVAL;
  1795. }
  1796. ret = snd_soc_dapm_new_controls(dapm, wsa_macro_dapm_widgets,
  1797. ARRAY_SIZE(wsa_macro_dapm_widgets));
  1798. if (ret < 0) {
  1799. dev_err(wsa_dev, "%s: Failed to add controls\n", __func__);
  1800. return ret;
  1801. }
  1802. ret = snd_soc_dapm_add_routes(dapm, wsa_audio_map,
  1803. ARRAY_SIZE(wsa_audio_map));
  1804. if (ret < 0) {
  1805. dev_err(wsa_dev, "%s: Failed to add routes\n", __func__);
  1806. return ret;
  1807. }
  1808. ret = snd_soc_dapm_new_widgets(dapm->card);
  1809. if (ret < 0) {
  1810. dev_err(wsa_dev, "%s: Failed to add widgets\n", __func__);
  1811. return ret;
  1812. }
  1813. ret = snd_soc_add_codec_controls(codec, wsa_macro_snd_controls,
  1814. ARRAY_SIZE(wsa_macro_snd_controls));
  1815. if (ret < 0) {
  1816. dev_err(wsa_dev, "%s: Failed to add snd_ctls\n", __func__);
  1817. return ret;
  1818. }
  1819. wsa_priv->codec = codec;
  1820. wsa_priv->spkr_gain_offset = WSA_MACRO_GAIN_OFFSET_0_DB;
  1821. wsa_macro_init_reg(codec);
  1822. return 0;
  1823. }
  1824. static int wsa_macro_deinit(struct snd_soc_codec *codec)
  1825. {
  1826. struct device *wsa_dev = NULL;
  1827. struct wsa_macro_priv *wsa_priv = NULL;
  1828. if (!wsa_macro_get_data(codec, &wsa_dev, &wsa_priv, __func__))
  1829. return -EINVAL;
  1830. wsa_priv->codec = NULL;
  1831. return 0;
  1832. }
  1833. static void wsa_macro_add_child_devices(struct work_struct *work)
  1834. {
  1835. struct wsa_macro_priv *wsa_priv;
  1836. struct platform_device *pdev;
  1837. struct device_node *node;
  1838. struct wsa_macro_swr_ctrl_data *swr_ctrl_data = NULL, *temp;
  1839. int ret;
  1840. u16 count = 0, ctrl_num = 0;
  1841. struct wsa_macro_swr_ctrl_platform_data *platdata;
  1842. char plat_dev_name[WSA_MACRO_SWR_STRING_LEN];
  1843. wsa_priv = container_of(work, struct wsa_macro_priv,
  1844. wsa_macro_add_child_devices_work);
  1845. if (!wsa_priv) {
  1846. pr_err("%s: Memory for wsa_priv does not exist\n",
  1847. __func__);
  1848. return;
  1849. }
  1850. if (!wsa_priv->dev || !wsa_priv->dev->of_node) {
  1851. dev_err(wsa_priv->dev,
  1852. "%s: DT node for wsa_priv does not exist\n", __func__);
  1853. return;
  1854. }
  1855. platdata = &wsa_priv->swr_plat_data;
  1856. wsa_priv->child_count = 0;
  1857. for_each_available_child_of_node(wsa_priv->dev->of_node, node) {
  1858. if (strnstr(node->name, "wsa_swr_master",
  1859. strlen("wsa_swr_master")) != NULL)
  1860. strlcpy(plat_dev_name, "wsa_swr_ctrl",
  1861. (WSA_MACRO_SWR_STRING_LEN - 1));
  1862. else if (strnstr(node->name, "msm_cdc_pinctrl",
  1863. strlen("msm_cdc_pinctrl")) != NULL)
  1864. strlcpy(plat_dev_name, node->name,
  1865. (WSA_MACRO_SWR_STRING_LEN - 1));
  1866. else
  1867. continue;
  1868. pdev = platform_device_alloc(plat_dev_name, -1);
  1869. if (!pdev) {
  1870. dev_err(wsa_priv->dev, "%s: pdev memory alloc failed\n",
  1871. __func__);
  1872. ret = -ENOMEM;
  1873. goto err;
  1874. }
  1875. pdev->dev.parent = wsa_priv->dev;
  1876. pdev->dev.of_node = node;
  1877. if (strnstr(node->name, "wsa_swr_master",
  1878. strlen("wsa_swr_master")) != NULL) {
  1879. ret = platform_device_add_data(pdev, platdata,
  1880. sizeof(*platdata));
  1881. if (ret) {
  1882. dev_err(&pdev->dev,
  1883. "%s: cannot add plat data ctrl:%d\n",
  1884. __func__, ctrl_num);
  1885. goto fail_pdev_add;
  1886. }
  1887. }
  1888. ret = platform_device_add(pdev);
  1889. if (ret) {
  1890. dev_err(&pdev->dev,
  1891. "%s: Cannot add platform device\n",
  1892. __func__);
  1893. goto fail_pdev_add;
  1894. }
  1895. if (!strcmp(node->name, "wsa_swr_master")) {
  1896. temp = krealloc(swr_ctrl_data,
  1897. (ctrl_num + 1) * sizeof(
  1898. struct wsa_macro_swr_ctrl_data),
  1899. GFP_KERNEL);
  1900. if (!temp) {
  1901. dev_err(&pdev->dev, "out of memory\n");
  1902. ret = -ENOMEM;
  1903. goto err;
  1904. }
  1905. swr_ctrl_data = temp;
  1906. swr_ctrl_data[ctrl_num].wsa_swr_pdev = pdev;
  1907. ctrl_num++;
  1908. dev_dbg(&pdev->dev,
  1909. "%s: Added soundwire ctrl device(s)\n",
  1910. __func__);
  1911. wsa_priv->swr_ctrl_data = swr_ctrl_data;
  1912. }
  1913. if (wsa_priv->child_count < WSA_MACRO_CHILD_DEVICES_MAX)
  1914. wsa_priv->pdev_child_devices[
  1915. wsa_priv->child_count++] = pdev;
  1916. else
  1917. goto err;
  1918. }
  1919. return;
  1920. fail_pdev_add:
  1921. for (count = 0; count < wsa_priv->child_count; count++)
  1922. platform_device_put(wsa_priv->pdev_child_devices[count]);
  1923. err:
  1924. return;
  1925. }
  1926. static void wsa_macro_init_ops(struct macro_ops *ops,
  1927. char __iomem *wsa_io_base)
  1928. {
  1929. memset(ops, 0, sizeof(struct macro_ops));
  1930. ops->init = wsa_macro_init;
  1931. ops->exit = wsa_macro_deinit;
  1932. ops->io_base = wsa_io_base;
  1933. ops->dai_ptr = wsa_macro_dai;
  1934. ops->num_dais = ARRAY_SIZE(wsa_macro_dai);
  1935. ops->mclk_fn = wsa_macro_mclk_ctrl;
  1936. }
  1937. static int wsa_macro_probe(struct platform_device *pdev)
  1938. {
  1939. struct macro_ops ops;
  1940. struct wsa_macro_priv *wsa_priv;
  1941. u32 wsa_base_addr;
  1942. char __iomem *wsa_io_base;
  1943. int ret = 0;
  1944. struct clk *wsa_core_clk, *wsa_npl_clk;
  1945. wsa_priv = devm_kzalloc(&pdev->dev, sizeof(struct wsa_macro_priv),
  1946. GFP_KERNEL);
  1947. if (!wsa_priv)
  1948. return -ENOMEM;
  1949. wsa_priv->dev = &pdev->dev;
  1950. ret = of_property_read_u32(pdev->dev.of_node, "reg",
  1951. &wsa_base_addr);
  1952. if (ret) {
  1953. dev_err(&pdev->dev, "%s: could not find %s entry in dt\n",
  1954. __func__, "reg");
  1955. return ret;
  1956. }
  1957. wsa_priv->wsa_swr_gpio_p = of_parse_phandle(pdev->dev.of_node,
  1958. "qcom,wsa-swr-gpios", 0);
  1959. if (!wsa_priv->wsa_swr_gpio_p) {
  1960. dev_err(&pdev->dev, "%s: swr_gpios handle not provided!\n",
  1961. __func__);
  1962. return -EINVAL;
  1963. }
  1964. wsa_io_base = devm_ioremap(&pdev->dev,
  1965. wsa_base_addr, WSA_MACRO_MAX_OFFSET);
  1966. if (!wsa_io_base) {
  1967. dev_err(&pdev->dev, "%s: ioremap failed\n", __func__);
  1968. return -EINVAL;
  1969. }
  1970. wsa_priv->wsa_io_base = wsa_io_base;
  1971. INIT_WORK(&wsa_priv->wsa_macro_add_child_devices_work,
  1972. wsa_macro_add_child_devices);
  1973. wsa_priv->swr_plat_data.handle = (void *) wsa_priv;
  1974. wsa_priv->swr_plat_data.read = NULL;
  1975. wsa_priv->swr_plat_data.write = NULL;
  1976. wsa_priv->swr_plat_data.bulk_write = NULL;
  1977. wsa_priv->swr_plat_data.clk = wsa_swrm_clock;
  1978. wsa_priv->swr_plat_data.handle_irq = NULL;
  1979. /* Register MCLK for wsa macro */
  1980. wsa_core_clk = devm_clk_get(&pdev->dev, "wsa_core_clk");
  1981. if (IS_ERR(wsa_core_clk)) {
  1982. ret = PTR_ERR(wsa_core_clk);
  1983. dev_err(&pdev->dev, "%s: clk get %s failed\n",
  1984. __func__, "wsa_core_clk");
  1985. return ret;
  1986. }
  1987. wsa_priv->wsa_core_clk = wsa_core_clk;
  1988. /* Register npl clk for soundwire */
  1989. wsa_npl_clk = devm_clk_get(&pdev->dev, "wsa_npl_clk");
  1990. if (IS_ERR(wsa_npl_clk)) {
  1991. ret = PTR_ERR(wsa_npl_clk);
  1992. dev_err(&pdev->dev, "%s: clk get %s failed\n",
  1993. __func__, "wsa_npl_clk");
  1994. return ret;
  1995. }
  1996. wsa_priv->wsa_npl_clk = wsa_npl_clk;
  1997. dev_set_drvdata(&pdev->dev, wsa_priv);
  1998. mutex_init(&wsa_priv->mclk_lock);
  1999. mutex_init(&wsa_priv->swr_clk_lock);
  2000. wsa_macro_init_ops(&ops, wsa_io_base);
  2001. ret = bolero_register_macro(&pdev->dev, WSA_MACRO, &ops);
  2002. if (ret < 0) {
  2003. dev_err(&pdev->dev, "%s: register macro failed\n", __func__);
  2004. goto reg_macro_fail;
  2005. }
  2006. schedule_work(&wsa_priv->wsa_macro_add_child_devices_work);
  2007. return ret;
  2008. reg_macro_fail:
  2009. mutex_destroy(&wsa_priv->mclk_lock);
  2010. mutex_destroy(&wsa_priv->swr_clk_lock);
  2011. return ret;
  2012. }
  2013. static int wsa_macro_remove(struct platform_device *pdev)
  2014. {
  2015. struct wsa_macro_priv *wsa_priv;
  2016. u16 count = 0;
  2017. wsa_priv = dev_get_drvdata(&pdev->dev);
  2018. if (!wsa_priv)
  2019. return -EINVAL;
  2020. for (count = 0; count < wsa_priv->child_count &&
  2021. count < WSA_MACRO_CHILD_DEVICES_MAX; count++)
  2022. platform_device_unregister(wsa_priv->pdev_child_devices[count]);
  2023. bolero_unregister_macro(&pdev->dev, WSA_MACRO);
  2024. mutex_destroy(&wsa_priv->mclk_lock);
  2025. mutex_destroy(&wsa_priv->swr_clk_lock);
  2026. return 0;
  2027. }
  2028. static const struct of_device_id wsa_macro_dt_match[] = {
  2029. {.compatible = "qcom,wsa-macro"},
  2030. {}
  2031. };
  2032. static struct platform_driver wsa_macro_driver = {
  2033. .driver = {
  2034. .name = "wsa_macro",
  2035. .owner = THIS_MODULE,
  2036. .of_match_table = wsa_macro_dt_match,
  2037. },
  2038. .probe = wsa_macro_probe,
  2039. .remove = wsa_macro_remove,
  2040. };
  2041. module_platform_driver(wsa_macro_driver);
  2042. MODULE_DESCRIPTION("WSA macro driver");
  2043. MODULE_LICENSE("GPL v2");