msm-analog-cdc.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* Copyright (c) 2015-2017, 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 MSM_ANALOG_CDC_H
  13. #define MSM_ANALOG_CDC_H
  14. #include <sound/soc.h>
  15. #include <sound/jack.h>
  16. #include <dsp/q6afe-v2.h>
  17. #include "../wcd-mbhc-v2.h"
  18. #include "../wcdcal-hwdep.h"
  19. #include "sdm660-cdc-registers.h"
  20. #define MICBIAS_EXT_BYP_CAP 0x00
  21. #define MICBIAS_NO_EXT_BYP_CAP 0x01
  22. #define MSM89XX_NUM_IRQ_REGS 2
  23. #define MAX_REGULATOR 7
  24. #define MSM89XX_REG_VAL(reg, val) {reg, 0, val}
  25. #define MSM89XX_VDD_SPKDRV_NAME "cdc-vdd-spkdrv"
  26. #define DEFAULT_MULTIPLIER 800
  27. #define DEFAULT_GAIN 9
  28. #define DEFAULT_OFFSET 100
  29. extern const u8 msm89xx_pmic_cdc_reg_readable[MSM89XX_PMIC_CDC_CACHE_SIZE];
  30. extern const u8 msm89xx_cdc_core_reg_readable[MSM89XX_CDC_CORE_CACHE_SIZE];
  31. extern struct regmap_config msm89xx_cdc_core_regmap_config;
  32. extern struct regmap_config msm89xx_pmic_cdc_regmap_config;
  33. enum wcd_curr_ref {
  34. I_h4_UA = 0,
  35. I_pt5_UA,
  36. I_14_UA,
  37. I_l4_UA,
  38. I_1_UA,
  39. };
  40. enum wcd_mbhc_imp_det_pin {
  41. WCD_MBHC_DET_NONE = 0,
  42. WCD_MBHC_DET_HPHL,
  43. WCD_MBHC_DET_HPHR,
  44. WCD_MBHC_DET_BOTH,
  45. };
  46. /* Each micbias can be assigned to one of three cfilters
  47. * Vbatt_min >= .15V + ldoh_v
  48. * ldoh_v >= .15v + cfiltx_mv
  49. * If ldoh_v = 1.95 160 mv < cfiltx_mv < 1800 mv
  50. * If ldoh_v = 2.35 200 mv < cfiltx_mv < 2200 mv
  51. * If ldoh_v = 2.75 240 mv < cfiltx_mv < 2600 mv
  52. * If ldoh_v = 2.85 250 mv < cfiltx_mv < 2700 mv
  53. */
  54. struct wcd_micbias_setting {
  55. u8 ldoh_v;
  56. u32 cfilt1_mv; /* in mv */
  57. u32 cfilt2_mv; /* in mv */
  58. u32 cfilt3_mv; /* in mv */
  59. /* Different WCD9xxx series codecs may not
  60. * have 4 mic biases. If a codec has fewer
  61. * mic biases, some of these properties will
  62. * not be used.
  63. */
  64. u8 bias1_cfilt_sel;
  65. u8 bias2_cfilt_sel;
  66. u8 bias3_cfilt_sel;
  67. u8 bias4_cfilt_sel;
  68. u8 bias1_cap_mode;
  69. u8 bias2_cap_mode;
  70. u8 bias3_cap_mode;
  71. u8 bias4_cap_mode;
  72. bool bias2_is_headset_only;
  73. };
  74. enum sdm660_cdc_pid_current {
  75. MSM89XX_PID_MIC_2P5_UA,
  76. MSM89XX_PID_MIC_5_UA,
  77. MSM89XX_PID_MIC_10_UA,
  78. MSM89XX_PID_MIC_20_UA,
  79. };
  80. struct sdm660_cdc_reg_mask_val {
  81. u16 reg;
  82. u8 mask;
  83. u8 val;
  84. };
  85. enum {
  86. /* INTR_REG 0 - Digital Periph */
  87. MSM89XX_IRQ_SPKR_CNP = 0,
  88. MSM89XX_IRQ_SPKR_CLIP,
  89. MSM89XX_IRQ_SPKR_OCP,
  90. MSM89XX_IRQ_MBHC_INSREM_DET1,
  91. MSM89XX_IRQ_MBHC_RELEASE,
  92. MSM89XX_IRQ_MBHC_PRESS,
  93. MSM89XX_IRQ_MBHC_INSREM_DET,
  94. MSM89XX_IRQ_MBHC_HS_DET,
  95. /* INTR_REG 1 - Analog Periph */
  96. MSM89XX_IRQ_EAR_OCP,
  97. MSM89XX_IRQ_HPHR_OCP,
  98. MSM89XX_IRQ_HPHL_OCP,
  99. MSM89XX_IRQ_EAR_CNP,
  100. MSM89XX_IRQ_HPHR_CNP,
  101. MSM89XX_IRQ_HPHL_CNP,
  102. MSM89XX_NUM_IRQS,
  103. };
  104. enum {
  105. ON_DEMAND_MICBIAS = 0,
  106. ON_DEMAND_SPKDRV,
  107. ON_DEMAND_SUPPLIES_MAX,
  108. };
  109. /*
  110. * The delay list is per codec HW specification.
  111. * Please add delay in the list in the future instead
  112. * of magic number
  113. */
  114. enum {
  115. CODEC_DELAY_1_MS = 1000,
  116. CODEC_DELAY_1_1_MS = 1100,
  117. };
  118. struct sdm660_cdc_regulator {
  119. const char *name;
  120. int min_uv;
  121. int max_uv;
  122. int optimum_ua;
  123. bool ondemand;
  124. struct regulator *regulator;
  125. };
  126. struct on_demand_supply {
  127. struct regulator *supply;
  128. atomic_t ref;
  129. int min_uv;
  130. int max_uv;
  131. int optimum_ua;
  132. };
  133. struct wcd_imped_i_ref {
  134. enum wcd_curr_ref curr_ref;
  135. int min_val;
  136. int multiplier;
  137. int gain_adj;
  138. int offset;
  139. };
  140. enum sdm660_cdc_micbias_num {
  141. MSM89XX_MICBIAS1 = 0,
  142. };
  143. /* Hold instance to digital codec platform device */
  144. struct msm_dig_ctrl_data {
  145. struct platform_device *dig_pdev;
  146. };
  147. struct msm_dig_ctrl_platform_data {
  148. void *handle;
  149. void (*update_clkdiv)(void *handle, int val);
  150. int (*get_cdc_version)(void *handle);
  151. int (*register_notifier)(void *handle,
  152. struct notifier_block *nblock,
  153. bool enable);
  154. };
  155. struct sdm660_cdc_priv {
  156. struct device *dev;
  157. u32 num_of_supplies;
  158. struct regulator_bulk_data *supplies;
  159. struct snd_soc_codec *codec;
  160. struct work_struct msm_anlg_add_child_devices_work;
  161. struct msm_dig_ctrl_platform_data dig_plat_data;
  162. /* digital codec data structure */
  163. struct msm_dig_ctrl_data *dig_ctrl_data;
  164. struct blocking_notifier_head notifier;
  165. u16 pmic_rev;
  166. u16 codec_version;
  167. u16 analog_major_rev;
  168. u32 boost_voltage;
  169. u32 adc_count;
  170. u32 rx_bias_count;
  171. bool int_mclk0_enabled;
  172. u16 boost_option;
  173. /* mode to select hd2 */
  174. u32 hph_mode;
  175. /* compander used for each rx chain */
  176. bool spk_boost_set;
  177. bool ear_pa_boost_set;
  178. bool ext_spk_boost_set;
  179. struct on_demand_supply on_demand_list[ON_DEMAND_SUPPLIES_MAX];
  180. struct regulator *spkdrv_reg;
  181. struct blocking_notifier_head notifier_mbhc;
  182. /* mbhc module */
  183. struct wcd_mbhc mbhc;
  184. /* cal info for codec */
  185. struct fw_info *fw_data;
  186. struct notifier_block audio_ssr_nb;
  187. int (*codec_spk_ext_pa_cb)(struct snd_soc_codec *codec, int enable);
  188. unsigned long status_mask;
  189. struct wcd_imped_i_ref imped_i_ref;
  190. enum wcd_mbhc_imp_det_pin imped_det_pin;
  191. /* Entry for version info */
  192. struct snd_info_entry *entry;
  193. struct snd_info_entry *version_entry;
  194. };
  195. struct sdm660_cdc_pdata {
  196. struct wcd_micbias_setting micbias;
  197. struct sdm660_cdc_regulator regulator[MAX_REGULATOR];
  198. };
  199. extern int msm_anlg_cdc_mclk_enable(struct snd_soc_codec *codec,
  200. int mclk_enable, bool dapm);
  201. extern int msm_anlg_cdc_hs_detect(struct snd_soc_codec *codec,
  202. struct wcd_mbhc_config *mbhc_cfg);
  203. extern void msm_anlg_cdc_hs_detect_exit(struct snd_soc_codec *codec);
  204. extern void sdm660_cdc_update_int_spk_boost(bool enable);
  205. extern void msm_anlg_cdc_spk_ext_pa_cb(
  206. int (*codec_spk_ext_pa)(struct snd_soc_codec *codec,
  207. int enable), struct snd_soc_codec *codec);
  208. int msm_anlg_codec_info_create_codec_entry(struct snd_info_entry *codec_root,
  209. struct snd_soc_codec *codec);
  210. #endif