wcd9xxx-common.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Copyright (c) 2013-2014, 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. #ifndef WCD9XXX_CODEC_COMMON
  13. #define WCD9XXX_CODEC_COMMON
  14. #include "wcd9xxx-resmgr.h"
  15. #define WCD9XXX_CLSH_REQ_ENABLE true
  16. #define WCD9XXX_CLSH_REQ_DISABLE false
  17. #define WCD9XXX_CLSH_EVENT_PRE_DAC 0x01
  18. #define WCD9XXX_CLSH_EVENT_POST_PA 0x02
  19. /* Basic states for Class H state machine.
  20. * represented as a bit mask within a u8 data type
  21. * bit 0: EAR mode
  22. * bit 1: HPH Left mode
  23. * bit 2: HPH Right mode
  24. * bit 3: Lineout mode
  25. * bit 4: Ultrasound mode
  26. */
  27. #define WCD9XXX_CLSH_STATE_IDLE 0x00
  28. #define WCD9XXX_CLSH_STATE_EAR (0x01 << 0)
  29. #define WCD9XXX_CLSH_STATE_HPHL (0x01 << 1)
  30. #define WCD9XXX_CLSH_STATE_HPHR (0x01 << 2)
  31. #define WCD9XXX_CLSH_STATE_LO (0x01 << 3)
  32. #define NUM_CLSH_STATES (0x01 << 4)
  33. #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_2 0x0
  34. #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_3 0x1
  35. #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_4 0x2
  36. #define WCD9XXX_DMIC_B1_CTL_DIV_2 0x00
  37. #define WCD9XXX_DMIC_B1_CTL_DIV_3 0x22
  38. #define WCD9XXX_DMIC_B1_CTL_DIV_4 0x44
  39. #define WCD9XXX_DMIC_B2_CTL_DIV_2 0x00
  40. #define WCD9XXX_DMIC_B2_CTL_DIV_3 0x02
  41. #define WCD9XXX_DMIC_B2_CTL_DIV_4 0x04
  42. #define WCD9XXX_ANC_DMIC_X2_ON 0x1
  43. #define WCD9XXX_ANC_DMIC_X2_OFF 0x0
  44. /* Derived State: Bits 1 and 2 should be set for Headphone stereo */
  45. #define WCD9XXX_CLSH_STATE_HPH_ST (WCD9XXX_CLSH_STATE_HPHL | \
  46. WCD9XXX_CLSH_STATE_HPHR)
  47. #define WCD9XXX_CLSH_STATE_HPHL_EAR (WCD9XXX_CLSH_STATE_HPHL | \
  48. WCD9XXX_CLSH_STATE_EAR)
  49. #define WCD9XXX_CLSH_STATE_HPHR_EAR (WCD9XXX_CLSH_STATE_HPHR | \
  50. WCD9XXX_CLSH_STATE_EAR)
  51. #define WCD9XXX_CLSH_STATE_HPH_ST_EAR (WCD9XXX_CLSH_STATE_HPH_ST | \
  52. WCD9XXX_CLSH_STATE_EAR)
  53. #define WCD9XXX_CLSH_STATE_HPHL_LO (WCD9XXX_CLSH_STATE_HPHL | \
  54. WCD9XXX_CLSH_STATE_LO)
  55. #define WCD9XXX_CLSH_STATE_HPHR_LO (WCD9XXX_CLSH_STATE_HPHR | \
  56. WCD9XXX_CLSH_STATE_LO)
  57. #define WCD9XXX_CLSH_STATE_HPH_ST_LO (WCD9XXX_CLSH_STATE_HPH_ST | \
  58. WCD9XXX_CLSH_STATE_LO)
  59. #define WCD9XXX_CLSH_STATE_EAR_LO (WCD9XXX_CLSH_STATE_EAR | \
  60. WCD9XXX_CLSH_STATE_LO)
  61. #define WCD9XXX_CLSH_STATE_HPHL_EAR_LO (WCD9XXX_CLSH_STATE_HPHL | \
  62. WCD9XXX_CLSH_STATE_EAR | \
  63. WCD9XXX_CLSH_STATE_LO)
  64. #define WCD9XXX_CLSH_STATE_HPHR_EAR_LO (WCD9XXX_CLSH_STATE_HPHR | \
  65. WCD9XXX_CLSH_STATE_EAR | \
  66. WCD9XXX_CLSH_STATE_LO)
  67. #define WCD9XXX_CLSH_STATE_HPH_ST_EAR_LO (WCD9XXX_CLSH_STATE_HPH_ST | \
  68. WCD9XXX_CLSH_STATE_EAR | \
  69. WCD9XXX_CLSH_STATE_LO)
  70. struct wcd9xxx_reg_mask_val {
  71. u16 reg;
  72. u8 mask;
  73. u8 val;
  74. };
  75. enum ncp_fclk_level {
  76. NCP_FCLK_LEVEL_8,
  77. NCP_FCLK_LEVEL_5,
  78. NCP_FCLK_LEVEL_MAX,
  79. };
  80. /* Class H data that the codec driver will maintain */
  81. struct wcd9xxx_clsh_cdc_data {
  82. u8 state;
  83. int buck_mv;
  84. bool is_dynamic_vdd_cp;
  85. int clsh_users;
  86. int buck_users;
  87. int ncp_users[NCP_FCLK_LEVEL_MAX];
  88. struct wcd9xxx_resmgr *resmgr;
  89. bool hs_perf_mode_enabled;
  90. };
  91. struct wcd9xxx_anc_header {
  92. u32 reserved[3];
  93. u32 num_anc_slots;
  94. };
  95. enum wcd9xxx_buck_volt {
  96. WCD9XXX_CDC_BUCK_UNSUPPORTED = 0,
  97. WCD9XXX_CDC_BUCK_MV_1P8 = 1800000,
  98. WCD9XXX_CDC_BUCK_MV_2P15 = 2150000,
  99. };
  100. extern void wcd9xxx_clsh_fsm(struct snd_soc_codec *codec,
  101. struct wcd9xxx_clsh_cdc_data *cdc_clsh_d,
  102. u8 req_state, bool req_type, u8 clsh_event);
  103. extern void wcd9xxx_clsh_init(struct wcd9xxx_clsh_cdc_data *clsh,
  104. struct wcd9xxx_resmgr *resmgr);
  105. extern void wcd9xxx_clsh_imped_config(struct snd_soc_codec *codec,
  106. int imped);
  107. enum wcd9xxx_codec_event {
  108. WCD9XXX_CODEC_EVENT_CODEC_UP = 0,
  109. };
  110. struct wcd9xxx_register_save_node {
  111. struct list_head lh;
  112. u16 reg;
  113. u16 value;
  114. };
  115. extern int wcd9xxx_soc_update_bits_push(struct snd_soc_codec *codec,
  116. struct list_head *lh,
  117. uint16_t reg, uint8_t mask,
  118. uint8_t value, int delay);
  119. extern void wcd9xxx_restore_registers(struct snd_soc_codec *codec,
  120. struct list_head *lh);
  121. enum {
  122. RESERVED = 0,
  123. AANC_LPF_FF_FB = 1,
  124. AANC_LPF_COEFF_MSB,
  125. AANC_LPF_COEFF_LSB,
  126. HW_MAD_AUDIO_ENABLE,
  127. HW_MAD_ULTR_ENABLE,
  128. HW_MAD_BEACON_ENABLE,
  129. HW_MAD_AUDIO_SLEEP_TIME,
  130. HW_MAD_ULTR_SLEEP_TIME,
  131. HW_MAD_BEACON_SLEEP_TIME,
  132. HW_MAD_TX_AUDIO_SWITCH_OFF,
  133. HW_MAD_TX_ULTR_SWITCH_OFF,
  134. HW_MAD_TX_BEACON_SWITCH_OFF,
  135. MAD_AUDIO_INT_DEST_SELECT_REG,
  136. MAD_ULT_INT_DEST_SELECT_REG,
  137. MAD_BEACON_INT_DEST_SELECT_REG,
  138. MAD_CLIP_INT_DEST_SELECT_REG,
  139. MAD_VBAT_INT_DEST_SELECT_REG,
  140. MAD_AUDIO_INT_MASK_REG,
  141. MAD_ULT_INT_MASK_REG,
  142. MAD_BEACON_INT_MASK_REG,
  143. MAD_CLIP_INT_MASK_REG,
  144. MAD_VBAT_INT_MASK_REG,
  145. MAD_AUDIO_INT_STATUS_REG,
  146. MAD_ULT_INT_STATUS_REG,
  147. MAD_BEACON_INT_STATUS_REG,
  148. MAD_CLIP_INT_STATUS_REG,
  149. MAD_VBAT_INT_STATUS_REG,
  150. MAD_AUDIO_INT_CLEAR_REG,
  151. MAD_ULT_INT_CLEAR_REG,
  152. MAD_BEACON_INT_CLEAR_REG,
  153. MAD_CLIP_INT_CLEAR_REG,
  154. MAD_VBAT_INT_CLEAR_REG,
  155. SB_PGD_PORT_TX_WATERMARK_N,
  156. SB_PGD_PORT_TX_ENABLE_N,
  157. SB_PGD_PORT_RX_WATERMARK_N,
  158. SB_PGD_PORT_RX_ENABLE_N,
  159. SB_PGD_TX_PORTn_MULTI_CHNL_0,
  160. SB_PGD_TX_PORTn_MULTI_CHNL_1,
  161. SB_PGD_RX_PORTn_MULTI_CHNL_0,
  162. SB_PGD_RX_PORTn_MULTI_CHNL_1,
  163. AANC_FF_GAIN_ADAPTIVE,
  164. AANC_FFGAIN_ADAPTIVE_EN,
  165. AANC_GAIN_CONTROL,
  166. SPKR_CLIP_PIPE_BANK_SEL,
  167. SPKR_CLIPDET_VAL0,
  168. SPKR_CLIPDET_VAL1,
  169. SPKR_CLIPDET_VAL2,
  170. SPKR_CLIPDET_VAL3,
  171. SPKR_CLIPDET_VAL4,
  172. SPKR_CLIPDET_VAL5,
  173. SPKR_CLIPDET_VAL6,
  174. SPKR_CLIPDET_VAL7,
  175. MAX_CFG_REGISTERS,
  176. };
  177. #endif