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