wcd9xxx-resmgr-v2.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __WCD9XXX_COMMON_V2_H__
  14. #define __WCD9XXX_COMMON_V2_H__
  15. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  16. #include "core.h"
  17. enum wcd_clock_type {
  18. WCD_CLK_OFF,
  19. WCD_CLK_RCO,
  20. WCD_CLK_MCLK,
  21. };
  22. enum {
  23. SIDO_SOURCE_INTERNAL,
  24. SIDO_SOURCE_RCO_BG,
  25. };
  26. struct wcd_resmgr_cb {
  27. int (*cdc_rco_ctrl)(struct snd_soc_codec *, bool);
  28. };
  29. struct wcd9xxx_resmgr_v2 {
  30. struct snd_soc_codec *codec;
  31. struct wcd9xxx_core_resource *core_res;
  32. int master_bias_users;
  33. int clk_mclk_users;
  34. int clk_rco_users;
  35. struct mutex codec_bg_clk_lock;
  36. struct mutex master_bias_lock;
  37. enum codec_variant codec_type;
  38. enum wcd_clock_type clk_type;
  39. const struct wcd_resmgr_cb *resmgr_cb;
  40. int sido_input_src;
  41. };
  42. #define WCD9XXX_V2_BG_CLK_LOCK(resmgr) \
  43. { \
  44. struct wcd9xxx_resmgr_v2 *__resmgr = resmgr; \
  45. pr_debug("%s: Acquiring BG_CLK\n", __func__); \
  46. mutex_lock(&__resmgr->codec_bg_clk_lock); \
  47. pr_debug("%s: Acquiring BG_CLK done\n", __func__); \
  48. }
  49. #define WCD9XXX_V2_BG_CLK_UNLOCK(resmgr) \
  50. { \
  51. struct wcd9xxx_resmgr_v2 *__resmgr = resmgr; \
  52. pr_debug("%s: Releasing BG_CLK\n", __func__); \
  53. mutex_unlock(&__resmgr->codec_bg_clk_lock); \
  54. }
  55. #define WCD9XXX_V2_BG_CLK_ASSERT_LOCKED(resmgr) \
  56. { \
  57. WARN_ONCE(!mutex_is_locked(&resmgr->codec_bg_clk_lock), \
  58. "%s: BG_CLK lock should have acquired\n", __func__); \
  59. }
  60. int wcd_resmgr_enable_master_bias(struct wcd9xxx_resmgr_v2 *resmgr);
  61. int wcd_resmgr_disable_master_bias(struct wcd9xxx_resmgr_v2 *resmgr);
  62. struct wcd9xxx_resmgr_v2 *wcd_resmgr_init(
  63. struct wcd9xxx_core_resource *core_res,
  64. struct snd_soc_codec *codec);
  65. void wcd_resmgr_remove(struct wcd9xxx_resmgr_v2 *resmgr);
  66. int wcd_resmgr_post_init(struct wcd9xxx_resmgr_v2 *resmgr,
  67. const struct wcd_resmgr_cb *resmgr_cb,
  68. struct snd_soc_codec *codec);
  69. int wcd_resmgr_enable_clk_block(struct wcd9xxx_resmgr_v2 *resmgr,
  70. enum wcd_clock_type type);
  71. int wcd_resmgr_disable_clk_block(struct wcd9xxx_resmgr_v2 *resmgr,
  72. enum wcd_clock_type type);
  73. int wcd_resmgr_get_clk_type(struct wcd9xxx_resmgr_v2 *resmgr);
  74. void wcd_resmgr_post_ssr_v2(struct wcd9xxx_resmgr_v2 *resmgr);
  75. void wcd_resmgr_set_sido_input_src_locked(struct wcd9xxx_resmgr_v2 *resmgr,
  76. int sido_src);
  77. void wcd_resmgr_set_sido_input_src(struct wcd9xxx_resmgr_v2 *resmgr,
  78. int sido_src);
  79. #endif