msm-analog-cdc.h 6.8 KB

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