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