| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. 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 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/firmware.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
| 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/mfd/wcd9xxx/core.h> |
| 22 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 23 | #include <linux/mfd/wcd9xxx/wcd9304_registers.h> |
| 24 | #include <linux/mfd/wcd9xxx/pdata.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/jack.h> |
| 28 | #include <sound/soc.h> |
| 29 | #include <sound/soc-dapm.h> |
| 30 | #include <sound/tlv.h> |
| 31 | #include <linux/bitops.h> |
| 32 | #include <linux/delay.h> |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 34 | #include "wcd9304.h" |
| 35 | |
| 36 | #define WCD9304_RATES (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|\ |
| 37 | SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_48000) |
| 38 | |
| 39 | #define NUM_DECIMATORS 4 |
| 40 | #define NUM_INTERPOLATORS 3 |
| 41 | #define BITS_PER_REG 8 |
| 42 | #define AIF1_PB 1 |
| 43 | #define AIF1_CAP 2 |
| 44 | #define NUM_CODEC_DAIS 2 |
| 45 | |
| 46 | struct sitar_codec_dai_data { |
| 47 | u32 rate; |
| 48 | u32 *ch_num; |
| 49 | u32 ch_act; |
| 50 | u32 ch_tot; |
| 51 | }; |
| 52 | #define SITAR_CFILT_FAST_MODE 0x00 |
| 53 | #define SITAR_CFILT_SLOW_MODE 0x40 |
| 54 | |
| 55 | |
| 56 | #define SITAR_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR) |
| 57 | |
| 58 | #define SITAR_I2S_MASTER_MODE_MASK 0x08 |
| 59 | |
| 60 | #define SITAR_OCP_ATTEMPT 1 |
| 61 | |
| 62 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 63 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 64 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
| 65 | static struct snd_soc_dai_driver sitar_dai[]; |
| 66 | static int sitar_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 67 | struct snd_kcontrol *kcontrol, int event); |
| 68 | static int sitar_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 69 | struct snd_kcontrol *kcontrol, int event); |
| 70 | |
| 71 | enum sitar_bandgap_type { |
| 72 | SITAR_BANDGAP_OFF = 0, |
| 73 | SITAR_BANDGAP_AUDIO_MODE, |
| 74 | SITAR_BANDGAP_MBHC_MODE, |
| 75 | }; |
| 76 | |
| 77 | struct mbhc_micbias_regs { |
| 78 | u16 cfilt_val; |
| 79 | u16 cfilt_ctl; |
| 80 | u16 mbhc_reg; |
| 81 | u16 int_rbias; |
| 82 | u16 ctl_reg; |
| 83 | u8 cfilt_sel; |
| 84 | }; |
| 85 | |
| 86 | /* Codec supports 2 IIR filters */ |
| 87 | enum { |
| 88 | IIR1 = 0, |
| 89 | IIR2, |
| 90 | IIR_MAX, |
| 91 | }; |
| 92 | /* Codec supports 5 bands */ |
| 93 | enum { |
| 94 | BAND1 = 0, |
| 95 | BAND2, |
| 96 | BAND3, |
| 97 | BAND4, |
| 98 | BAND5, |
| 99 | BAND_MAX, |
| 100 | }; |
| 101 | |
| 102 | /* Flags to track of PA and DAC state. |
| 103 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 104 | * only PA to be turned on without DAC being on. */ |
| 105 | enum sitar_priv_ack_flags { |
| 106 | SITAR_HPHL_PA_OFF_ACK = 0, |
| 107 | SITAR_HPHR_PA_OFF_ACK, |
| 108 | SITAR_HPHL_DAC_OFF_ACK, |
| 109 | SITAR_HPHR_DAC_OFF_ACK |
| 110 | }; |
| 111 | |
| 112 | struct sitar_priv { |
| 113 | struct snd_soc_codec *codec; |
| 114 | u32 adc_count; |
| 115 | u32 cfilt1_cnt; |
| 116 | u32 cfilt2_cnt; |
| 117 | u32 cfilt3_cnt; |
| 118 | u32 rx_bias_count; |
| 119 | enum sitar_bandgap_type bandgap_type; |
| 120 | bool mclk_enabled; |
| 121 | bool clock_active; |
| 122 | bool config_mode_active; |
| 123 | bool mbhc_polling_active; |
| 124 | bool fake_insert_context; |
| 125 | int buttons_pressed; |
| 126 | |
| 127 | struct sitar_mbhc_calibration *calibration; |
| 128 | |
| 129 | struct snd_soc_jack *headset_jack; |
| 130 | struct snd_soc_jack *button_jack; |
| 131 | |
| 132 | struct wcd9xxx_pdata *pdata; |
| 133 | u32 anc_slot; |
| 134 | |
| 135 | bool no_mic_headset_override; |
| 136 | /* Delayed work to report long button press */ |
| 137 | struct delayed_work btn0_dwork; |
| 138 | |
| 139 | struct mbhc_micbias_regs mbhc_bias_regs; |
| 140 | u8 cfilt_k_value; |
| 141 | bool mbhc_micbias_switched; |
| 142 | |
| 143 | /* track PA/DAC state */ |
| 144 | unsigned long hph_pa_dac_state; |
| 145 | |
| 146 | /*track sitar interface type*/ |
| 147 | u8 intf_type; |
| 148 | |
| 149 | u32 hph_status; /* track headhpone status */ |
| 150 | /* define separate work for left and right headphone OCP to avoid |
| 151 | * additional checking on which OCP event to report so no locking |
| 152 | * to ensure synchronization is required |
| 153 | */ |
| 154 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 155 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
| 156 | |
| 157 | /* pm_cnt holds number of sleep lock holders + 1 |
| 158 | * so if pm_cnt is 1 system is sleep-able. */ |
| 159 | atomic_t pm_cnt; |
| 160 | wait_queue_head_t pm_wq; |
| 161 | |
| 162 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 163 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
| 164 | /* num of slim ports required */ |
| 165 | struct sitar_codec_dai_data dai[NUM_CODEC_DAIS]; |
| 166 | }; |
| 167 | |
| 168 | #ifdef CONFIG_DEBUG_FS |
| 169 | struct sitar_priv *debug_sitar_priv; |
| 170 | #endif |
| 171 | |
| 172 | |
| 173 | static int sitar_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 174 | struct snd_ctl_elem_value *ucontrol) |
| 175 | { |
| 176 | u8 ear_pa_gain; |
| 177 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 178 | |
| 179 | ear_pa_gain = snd_soc_read(codec, SITAR_A_RX_EAR_GAIN); |
| 180 | |
| 181 | ear_pa_gain = ear_pa_gain >> 5; |
| 182 | |
| 183 | if (ear_pa_gain == 0x00) { |
| 184 | ucontrol->value.integer.value[0] = 0; |
| 185 | } else if (ear_pa_gain == 0x04) { |
| 186 | ucontrol->value.integer.value[0] = 1; |
| 187 | } else { |
| 188 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 189 | __func__, ear_pa_gain); |
| 190 | return -EINVAL; |
| 191 | } |
| 192 | |
| 193 | pr_err("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int sitar_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 199 | struct snd_ctl_elem_value *ucontrol) |
| 200 | { |
| 201 | u8 ear_pa_gain; |
| 202 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 203 | |
| 204 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 205 | ucontrol->value.integer.value[0]); |
| 206 | |
| 207 | switch (ucontrol->value.integer.value[0]) { |
| 208 | case 0: |
| 209 | ear_pa_gain = 0x00; |
| 210 | break; |
| 211 | case 1: |
| 212 | ear_pa_gain = 0x80; |
| 213 | break; |
| 214 | default: |
| 215 | return -EINVAL; |
| 216 | } |
| 217 | |
| 218 | snd_soc_write(codec, SITAR_A_RX_EAR_GAIN, ear_pa_gain); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | static int sitar_get_iir_enable_audio_mixer( |
| 223 | struct snd_kcontrol *kcontrol, |
| 224 | struct snd_ctl_elem_value *ucontrol) |
| 225 | { |
| 226 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 227 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 228 | kcontrol->private_value)->reg; |
| 229 | int band_idx = ((struct soc_multi_mixer_control *) |
| 230 | kcontrol->private_value)->shift; |
| 231 | |
| 232 | ucontrol->value.integer.value[0] = |
| 233 | snd_soc_read(codec, (SITAR_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 234 | (1 << band_idx); |
| 235 | |
| 236 | pr_err("%s: IIR #%d band #%d enable %d\n", __func__, |
| 237 | iir_idx, band_idx, |
| 238 | (uint32_t)ucontrol->value.integer.value[0]); |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static int sitar_put_iir_enable_audio_mixer( |
| 243 | struct snd_kcontrol *kcontrol, |
| 244 | struct snd_ctl_elem_value *ucontrol) |
| 245 | { |
| 246 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 247 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 248 | kcontrol->private_value)->reg; |
| 249 | int band_idx = ((struct soc_multi_mixer_control *) |
| 250 | kcontrol->private_value)->shift; |
| 251 | int value = ucontrol->value.integer.value[0]; |
| 252 | |
| 253 | /* Mask first 5 bits, 6-8 are reserved */ |
| 254 | snd_soc_update_bits(codec, (SITAR_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 255 | (1 << band_idx), (value << band_idx)); |
| 256 | |
| 257 | pr_err("%s: IIR #%d band #%d enable %d\n", __func__, |
| 258 | iir_idx, band_idx, value); |
| 259 | return 0; |
| 260 | } |
| 261 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 262 | int iir_idx, int band_idx, |
| 263 | int coeff_idx) |
| 264 | { |
| 265 | /* Address does not automatically update if reading */ |
| 266 | snd_soc_update_bits(codec, |
| 267 | (SITAR_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 268 | 0x1F, band_idx * BAND_MAX + coeff_idx); |
| 269 | |
| 270 | /* Mask bits top 2 bits since they are reserved */ |
| 271 | return ((snd_soc_read(codec, |
| 272 | (SITAR_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 273 | (snd_soc_read(codec, |
| 274 | (SITAR_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 275 | (snd_soc_read(codec, |
| 276 | (SITAR_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 277 | (snd_soc_read(codec, |
| 278 | (SITAR_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 279 | 0x3FFFFFFF; |
| 280 | } |
| 281 | |
| 282 | static int sitar_get_iir_band_audio_mixer( |
| 283 | struct snd_kcontrol *kcontrol, |
| 284 | struct snd_ctl_elem_value *ucontrol) |
| 285 | { |
| 286 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 287 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 288 | kcontrol->private_value)->reg; |
| 289 | int band_idx = ((struct soc_multi_mixer_control *) |
| 290 | kcontrol->private_value)->shift; |
| 291 | |
| 292 | ucontrol->value.integer.value[0] = |
| 293 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 294 | ucontrol->value.integer.value[1] = |
| 295 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 296 | ucontrol->value.integer.value[2] = |
| 297 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 298 | ucontrol->value.integer.value[3] = |
| 299 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 300 | ucontrol->value.integer.value[4] = |
| 301 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 302 | |
| 303 | pr_err("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 304 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 305 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 306 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 307 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 308 | __func__, iir_idx, band_idx, |
| 309 | (uint32_t)ucontrol->value.integer.value[0], |
| 310 | __func__, iir_idx, band_idx, |
| 311 | (uint32_t)ucontrol->value.integer.value[1], |
| 312 | __func__, iir_idx, band_idx, |
| 313 | (uint32_t)ucontrol->value.integer.value[2], |
| 314 | __func__, iir_idx, band_idx, |
| 315 | (uint32_t)ucontrol->value.integer.value[3], |
| 316 | __func__, iir_idx, band_idx, |
| 317 | (uint32_t)ucontrol->value.integer.value[4]); |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 322 | int iir_idx, int band_idx, |
| 323 | int coeff_idx, uint32_t value) |
| 324 | { |
| 325 | /* Mask top 3 bits, 6-8 are reserved */ |
| 326 | /* Update address manually each time */ |
| 327 | snd_soc_update_bits(codec, |
| 328 | (SITAR_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
| 329 | 0x1F, band_idx * BAND_MAX + coeff_idx); |
| 330 | |
| 331 | /* Mask top 2 bits, 7-8 are reserved */ |
| 332 | snd_soc_update_bits(codec, |
| 333 | (SITAR_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
| 334 | 0x3F, (value >> 24) & 0x3F); |
| 335 | |
| 336 | /* Isolate 8bits at a time */ |
| 337 | snd_soc_update_bits(codec, |
| 338 | (SITAR_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
| 339 | 0xFF, (value >> 16) & 0xFF); |
| 340 | |
| 341 | snd_soc_update_bits(codec, |
| 342 | (SITAR_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
| 343 | 0xFF, (value >> 8) & 0xFF); |
| 344 | |
| 345 | snd_soc_update_bits(codec, |
| 346 | (SITAR_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
| 347 | 0xFF, value & 0xFF); |
| 348 | } |
| 349 | |
| 350 | static int sitar_put_iir_band_audio_mixer( |
| 351 | struct snd_kcontrol *kcontrol, |
| 352 | struct snd_ctl_elem_value *ucontrol) |
| 353 | { |
| 354 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 355 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 356 | kcontrol->private_value)->reg; |
| 357 | int band_idx = ((struct soc_multi_mixer_control *) |
| 358 | kcontrol->private_value)->shift; |
| 359 | |
| 360 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 361 | ucontrol->value.integer.value[0]); |
| 362 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 363 | ucontrol->value.integer.value[1]); |
| 364 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 365 | ucontrol->value.integer.value[2]); |
| 366 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 367 | ucontrol->value.integer.value[3]); |
| 368 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 369 | ucontrol->value.integer.value[4]); |
| 370 | |
| 371 | pr_err("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 372 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 373 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 374 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 375 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 376 | __func__, iir_idx, band_idx, |
| 377 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 378 | __func__, iir_idx, band_idx, |
| 379 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 380 | __func__, iir_idx, band_idx, |
| 381 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 382 | __func__, iir_idx, band_idx, |
| 383 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 384 | __func__, iir_idx, band_idx, |
| 385 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static const char *sitar_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 390 | static const struct soc_enum sitar_ear_pa_gain_enum[] = { |
| 391 | SOC_ENUM_SINGLE_EXT(2, sitar_ear_pa_gain_text), |
| 392 | }; |
| 393 | |
| 394 | /*cut of frequency for high pass filter*/ |
| 395 | static const char *cf_text[] = { |
| 396 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 397 | }; |
| 398 | |
| 399 | static const struct soc_enum cf_dec1_enum = |
| 400 | SOC_ENUM_SINGLE(SITAR_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 401 | |
| 402 | static const struct soc_enum cf_rxmix1_enum = |
| 403 | SOC_ENUM_SINGLE(SITAR_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 404 | |
| 405 | static const struct snd_kcontrol_new sitar_snd_controls[] = { |
| 406 | |
| 407 | SOC_ENUM_EXT("EAR PA Gain", sitar_ear_pa_gain_enum[0], |
| 408 | sitar_pa_gain_get, sitar_pa_gain_put), |
| 409 | |
| 410 | SOC_SINGLE_TLV("LINEOUT1 Volume", SITAR_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 411 | line_gain), |
| 412 | SOC_SINGLE_TLV("LINEOUT2 Volume", SITAR_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 413 | line_gain), |
| 414 | |
| 415 | SOC_SINGLE_TLV("HPHL Volume", SITAR_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 416 | line_gain), |
| 417 | SOC_SINGLE_TLV("HPHR Volume", SITAR_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 418 | line_gain), |
| 419 | |
| 420 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", SITAR_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 421 | -84, 40, digital_gain), |
| 422 | |
| 423 | SOC_SINGLE_S8_TLV("DEC1 Volume", SITAR_A_CDC_TX1_VOL_CTL_GAIN, -84, 40, |
| 424 | digital_gain), |
| 425 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", SITAR_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 426 | 40, digital_gain), |
| 427 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", SITAR_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 428 | 40, digital_gain), |
| 429 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", SITAR_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 430 | 40, digital_gain), |
| 431 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", SITAR_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 432 | 40, digital_gain), |
| 433 | SOC_SINGLE_TLV("ADC1 Volume", SITAR_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 434 | SOC_SINGLE_TLV("ADC2 Volume", SITAR_A_TX_1_2_EN, 1, 3, 0, analog_gain), |
| 435 | |
| 436 | SOC_SINGLE("MICBIAS1 CAPLESS Switch", SITAR_A_MICB_1_CTL, 4, 1, 1), |
| 437 | SOC_SINGLE("MICBIAS2 CAPLESS Switch", SITAR_A_MICB_2_CTL, 4, 1, 1), |
| 438 | |
| 439 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 440 | |
| 441 | SOC_SINGLE("TX1 HPF Switch", SITAR_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 442 | |
| 443 | SOC_SINGLE("RX1 HPF Switch", SITAR_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 444 | |
| 445 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 446 | |
| 447 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 448 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 449 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 450 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 451 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 452 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 453 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 454 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 455 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 456 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 457 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 458 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 459 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 460 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 461 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 462 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 463 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 464 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 465 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 466 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 467 | |
| 468 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 469 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 470 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 471 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 472 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 473 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 474 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 475 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 476 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 477 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 478 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 479 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 480 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 481 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 482 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 483 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 484 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 485 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 486 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 487 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 488 | }; |
| 489 | |
| 490 | static const char *rx_mix1_text[] = { |
| 491 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 492 | "RX5" |
| 493 | }; |
| 494 | |
| 495 | static const char *rx_dac1_text[] = { |
| 496 | "ZERO", "RX1", "RX2" |
| 497 | }; |
| 498 | |
| 499 | static const char *rx_dac2_text[] = { |
| 500 | "ZERO", "RX1", |
| 501 | }; |
| 502 | |
| 503 | static const char *rx_dac3_text[] = { |
| 504 | "ZERO", "RX1", "RX1_INV", "RX2" |
| 505 | }; |
| 506 | |
| 507 | static const char *rx_dac4_text[] = { |
| 508 | "ZERO", "ON" |
| 509 | }; |
| 510 | |
| 511 | static const char *sb_tx1_mux_text[] = { |
| 512 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 513 | "DEC1" |
| 514 | }; |
| 515 | |
| 516 | static const char *sb_tx2_mux_text[] = { |
| 517 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 518 | "DEC2" |
| 519 | }; |
| 520 | |
| 521 | static const char *sb_tx3_mux_text[] = { |
| 522 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 523 | "DEC3" |
| 524 | }; |
| 525 | |
| 526 | static const char *sb_tx5_mux_text[] = { |
| 527 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 528 | "DEC5" |
| 529 | }; |
| 530 | |
| 531 | static const char *dec1_mux_text[] = { |
| 532 | "ZERO", "DMIC1", "ADC1", "ADC2", "ADC3", "MBADC", "DMIC4", "ANCFB1", |
| 533 | }; |
| 534 | |
| 535 | static const char *dec2_mux_text[] = { |
| 536 | "ZERO", "DMIC2", "ADC1", "ADC2", "ADC3", "MBADC", "DMIC3", "ANCFB2", |
| 537 | }; |
| 538 | |
| 539 | static const char *dec3_mux_text[] = { |
| 540 | "ZERO", "DMIC2", "DMIC3", "DMIC4", "ADC1", "ADC2", "ADC3", "MBADC", |
| 541 | }; |
| 542 | |
| 543 | static const char *dec4_mux_text[] = { |
| 544 | "ZERO", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "ADC1", "ADC2", "ADC3", |
| 545 | }; |
| 546 | |
| 547 | static const char *iir1_inp1_text[] = { |
| 548 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "ZERO", "ZERO", "ZERO", |
| 549 | "ZERO", "ZERO", "ZERO", "RX1", "RX2", "RX3", "RX4", "RX5", |
| 550 | }; |
| 551 | |
| 552 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 553 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX1_B1_CTL, 0, 10, rx_mix1_text); |
| 554 | |
| 555 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 556 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX1_B1_CTL, 4, 10, rx_mix1_text); |
| 557 | |
| 558 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 559 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX2_B1_CTL, 0, 10, rx_mix1_text); |
| 560 | |
| 561 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 562 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX2_B1_CTL, 4, 10, rx_mix1_text); |
| 563 | |
| 564 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 565 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX3_B1_CTL, 0, 10, rx_mix1_text); |
| 566 | |
| 567 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 568 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX3_B1_CTL, 4, 10, rx_mix1_text); |
| 569 | |
| 570 | static const struct soc_enum rx_dac1_enum = |
| 571 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 6, 3, rx_dac1_text); |
| 572 | |
| 573 | static const struct soc_enum rx_dac2_enum = |
| 574 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 4, 2, rx_dac2_text); |
| 575 | |
| 576 | static const struct soc_enum rx_dac3_enum = |
| 577 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 2, 4, rx_dac3_text); |
| 578 | |
| 579 | static const struct soc_enum rx_dac4_enum = |
| 580 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 0, 2, rx_dac4_text); |
| 581 | |
| 582 | static const struct soc_enum sb_tx5_mux_enum = |
| 583 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 584 | |
| 585 | static const struct soc_enum sb_tx3_mux_enum = |
| 586 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 587 | |
| 588 | static const struct soc_enum sb_tx2_mux_enum = |
| 589 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 590 | |
| 591 | static const struct soc_enum sb_tx1_mux_enum = |
| 592 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 593 | |
| 594 | static const struct soc_enum dec1_mux_enum = |
| 595 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 0, 8, dec1_mux_text); |
| 596 | |
| 597 | static const struct soc_enum dec2_mux_enum = |
| 598 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 2, 8, dec2_mux_text); |
| 599 | |
| 600 | static const struct soc_enum dec3_mux_enum = |
| 601 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 4, 8, dec3_mux_text); |
| 602 | |
| 603 | static const struct soc_enum dec4_mux_enum = |
| 604 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 6, 8, dec4_mux_text); |
| 605 | |
| 606 | static const struct soc_enum iir1_inp1_mux_enum = |
| 607 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_EQ1_B1_CTL, 0, 16, iir1_inp1_text); |
| 608 | |
| 609 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 610 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 611 | |
| 612 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 613 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 614 | |
| 615 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 616 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 617 | |
| 618 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 619 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 620 | |
| 621 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 622 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 623 | |
| 624 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 625 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 626 | |
| 627 | static const struct snd_kcontrol_new rx_dac1_mux = |
| 628 | SOC_DAPM_ENUM("RX1 DAC Mux", rx_dac1_enum); |
| 629 | |
| 630 | static const struct snd_kcontrol_new rx_dac2_mux = |
| 631 | SOC_DAPM_ENUM("RX2 DAC Mux", rx_dac2_enum); |
| 632 | |
| 633 | static const struct snd_kcontrol_new rx_dac3_mux = |
| 634 | SOC_DAPM_ENUM("RX3 DAC Mux", rx_dac3_enum); |
| 635 | |
| 636 | static const struct snd_kcontrol_new rx_dac4_mux = |
| 637 | SOC_DAPM_ENUM("RX4 DAC Mux", rx_dac4_enum); |
| 638 | |
| 639 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 640 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 641 | |
| 642 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 643 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 644 | |
| 645 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 646 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 647 | |
| 648 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 649 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 650 | |
| 651 | static const struct snd_kcontrol_new dec1_mux = |
| 652 | SOC_DAPM_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
| 653 | |
| 654 | static const struct snd_kcontrol_new dec2_mux = |
| 655 | SOC_DAPM_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
| 656 | |
| 657 | static const struct snd_kcontrol_new dec3_mux = |
| 658 | SOC_DAPM_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
| 659 | |
| 660 | static const struct snd_kcontrol_new dec4_mux = |
| 661 | SOC_DAPM_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
| 662 | |
| 663 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 664 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 665 | |
| 666 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 667 | SOC_DAPM_SINGLE("Switch", SITAR_A_RX_EAR_EN, 5, 1, 0), |
| 668 | }; |
| 669 | |
| 670 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 671 | SOC_DAPM_SINGLE("Switch", SITAR_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 672 | }; |
| 673 | |
| 674 | static void sitar_codec_enable_adc_block(struct snd_soc_codec *codec, |
| 675 | int enable) |
| 676 | { |
| 677 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 678 | |
| 679 | pr_err("%s %d\n", __func__, enable); |
| 680 | |
| 681 | if (enable) { |
| 682 | sitar->adc_count++; |
| 683 | snd_soc_update_bits(codec, SITAR_A_TX_COM_BIAS, 0xE0, 0xE0); |
| 684 | |
| 685 | } else { |
| 686 | sitar->adc_count--; |
| 687 | if (!sitar->adc_count) { |
| 688 | if (!sitar->mbhc_polling_active) |
| 689 | snd_soc_update_bits(codec, SITAR_A_TX_COM_BIAS, |
| 690 | 0xE0, 0x0); |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | static int sitar_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 696 | struct snd_kcontrol *kcontrol, int event) |
| 697 | { |
| 698 | struct snd_soc_codec *codec = w->codec; |
| 699 | u16 adc_reg; |
| 700 | |
| 701 | pr_err("%s %d\n", __func__, event); |
| 702 | |
| 703 | if (w->reg == SITAR_A_TX_1_2_EN) |
| 704 | adc_reg = SITAR_A_TX_1_2_TEST_CTL; |
| 705 | else { |
| 706 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
| 710 | switch (event) { |
| 711 | case SND_SOC_DAPM_PRE_PMU: |
| 712 | sitar_codec_enable_adc_block(codec, 1); |
| 713 | break; |
| 714 | case SND_SOC_DAPM_POST_PMU: |
| 715 | snd_soc_update_bits(codec, adc_reg, 1 << w->shift, |
| 716 | 1 << w->shift); |
| 717 | usleep_range(1000, 1000); |
| 718 | snd_soc_update_bits(codec, adc_reg, 1 << w->shift, 0x00); |
| 719 | usleep_range(1000, 1000); |
| 720 | snd_soc_update_bits(codec, adc_reg, 0x08, 0x08); |
| 721 | break; |
| 722 | case SND_SOC_DAPM_POST_PMD: |
| 723 | sitar_codec_enable_adc_block(codec, 0); |
| 724 | break; |
| 725 | } |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | static int sitar_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 730 | struct snd_kcontrol *kcontrol, int event) |
| 731 | { |
| 732 | struct snd_soc_codec *codec = w->codec; |
| 733 | u16 lineout_gain_reg; |
| 734 | |
| 735 | pr_err("%s %d %s\n", __func__, event, w->name); |
| 736 | |
| 737 | switch (w->shift) { |
| 738 | case 0: |
| 739 | lineout_gain_reg = SITAR_A_RX_LINE_1_GAIN; |
| 740 | break; |
| 741 | case 1: |
| 742 | lineout_gain_reg = SITAR_A_RX_LINE_2_GAIN; |
| 743 | break; |
| 744 | default: |
| 745 | pr_err("%s: Error, incorrect lineout register value\n", |
| 746 | __func__); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | switch (event) { |
| 751 | case SND_SOC_DAPM_PRE_PMU: |
| 752 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 753 | break; |
| 754 | case SND_SOC_DAPM_POST_PMU: |
| 755 | pr_err("%s: sleeping 16 ms after %s PA turn on\n", |
| 756 | __func__, w->name); |
| 757 | usleep_range(16000, 16000); |
| 758 | break; |
| 759 | case SND_SOC_DAPM_POST_PMD: |
| 760 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 761 | break; |
| 762 | } |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static int sitar_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 767 | struct snd_kcontrol *kcontrol, int event) |
| 768 | { |
| 769 | struct snd_soc_codec *codec = w->codec; |
| 770 | u16 tx_mux_ctl_reg, tx_dmic_ctl_reg; |
| 771 | u8 dmic_clk_sel, dmic_clk_en; |
| 772 | unsigned int dmic; |
| 773 | int ret; |
| 774 | |
| 775 | ret = kstrtouint(strpbrk(w->name, "12"), 10, &dmic); |
| 776 | if (ret < 0) { |
| 777 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
| 778 | return -EINVAL; |
| 779 | } |
| 780 | |
| 781 | switch (dmic) { |
| 782 | case 1: |
| 783 | case 2: |
| 784 | dmic_clk_sel = 0x02; |
| 785 | dmic_clk_en = 0x01; |
| 786 | break; |
| 787 | case 3: |
| 788 | case 4: |
| 789 | dmic_clk_sel = 0x08; |
| 790 | dmic_clk_en = 0x04; |
| 791 | break; |
| 792 | |
| 793 | break; |
| 794 | |
| 795 | default: |
| 796 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | |
| 800 | tx_mux_ctl_reg = SITAR_A_CDC_TX1_MUX_CTL + 8 * (dmic - 1); |
| 801 | tx_dmic_ctl_reg = SITAR_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1); |
| 802 | |
| 803 | pr_err("%s %d\n", __func__, event); |
| 804 | |
| 805 | switch (event) { |
| 806 | case SND_SOC_DAPM_PRE_PMU: |
| 807 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, 0x1); |
| 808 | |
| 809 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 810 | dmic_clk_sel, dmic_clk_sel); |
| 811 | |
| 812 | snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1); |
| 813 | |
| 814 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 815 | dmic_clk_en, dmic_clk_en); |
| 816 | break; |
| 817 | case SND_SOC_DAPM_POST_PMD: |
| 818 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 819 | dmic_clk_en, 0); |
| 820 | break; |
| 821 | } |
| 822 | return 0; |
| 823 | } |
| 824 | |
| 825 | |
| 826 | static void sitar_codec_disable_button_presses(struct snd_soc_codec *codec) |
| 827 | { |
| 828 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B4_CTL, 0x80); |
| 829 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B3_CTL, 0x00); |
| 830 | } |
| 831 | |
| 832 | static void sitar_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 833 | { |
| 834 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 835 | |
| 836 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
| 837 | wcd9xxx_enable_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL); |
| 838 | if (!sitar->no_mic_headset_override) { |
| 839 | wcd9xxx_enable_irq(codec->control_data, |
| 840 | SITAR_IRQ_MBHC_POTENTIAL); |
| 841 | wcd9xxx_enable_irq(codec->control_data, |
| 842 | SITAR_IRQ_MBHC_RELEASE); |
| 843 | } else { |
| 844 | sitar_codec_disable_button_presses(codec); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | static void sitar_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 849 | { |
| 850 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 851 | |
| 852 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 853 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL); |
| 854 | if (!sitar->no_mic_headset_override) { |
| 855 | wcd9xxx_disable_irq(codec->control_data, |
| 856 | SITAR_IRQ_MBHC_POTENTIAL); |
| 857 | wcd9xxx_disable_irq(codec->control_data, |
| 858 | SITAR_IRQ_MBHC_RELEASE); |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | static void sitar_codec_switch_cfilt_mode(struct snd_soc_codec *codec, |
| 863 | int mode) |
| 864 | { |
| 865 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 866 | u8 reg_mode_val, cur_mode_val; |
| 867 | bool mbhc_was_polling = false; |
| 868 | |
| 869 | if (mode) |
| 870 | reg_mode_val = SITAR_CFILT_FAST_MODE; |
| 871 | else |
| 872 | reg_mode_val = SITAR_CFILT_SLOW_MODE; |
| 873 | |
| 874 | cur_mode_val = snd_soc_read(codec, |
| 875 | sitar->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 876 | |
| 877 | if (cur_mode_val != reg_mode_val) { |
| 878 | if (sitar->mbhc_polling_active) { |
| 879 | sitar_codec_pause_hs_polling(codec); |
| 880 | mbhc_was_polling = true; |
| 881 | } |
| 882 | snd_soc_update_bits(codec, |
| 883 | sitar->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 884 | if (mbhc_was_polling) |
| 885 | sitar_codec_start_hs_polling(codec); |
| 886 | pr_err("%s: CFILT mode change (%x to %x)\n", __func__, |
| 887 | cur_mode_val, reg_mode_val); |
| 888 | } else { |
| 889 | pr_err("%s: CFILT Value is already %x\n", |
| 890 | __func__, cur_mode_val); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | static void sitar_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 895 | u8 cfilt_sel, int inc) |
| 896 | { |
| 897 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 898 | u32 *cfilt_cnt_ptr = NULL; |
| 899 | u16 micb_cfilt_reg; |
| 900 | |
| 901 | switch (cfilt_sel) { |
| 902 | case SITAR_CFILT1_SEL: |
| 903 | cfilt_cnt_ptr = &sitar->cfilt1_cnt; |
| 904 | micb_cfilt_reg = SITAR_A_MICB_CFILT_1_CTL; |
| 905 | break; |
| 906 | case SITAR_CFILT2_SEL: |
| 907 | cfilt_cnt_ptr = &sitar->cfilt2_cnt; |
| 908 | micb_cfilt_reg = SITAR_A_MICB_CFILT_2_CTL; |
| 909 | break; |
| 910 | default: |
| 911 | return; /* should not happen */ |
| 912 | } |
| 913 | |
| 914 | if (inc) { |
| 915 | if (!(*cfilt_cnt_ptr)++) { |
| 916 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 917 | if (cfilt_sel == sitar->mbhc_bias_regs.cfilt_sel) |
| 918 | sitar_codec_switch_cfilt_mode(codec, 0); |
| 919 | |
| 920 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 921 | } |
| 922 | } else { |
| 923 | /* check if count not zero, decrement |
| 924 | * then check if zero, go ahead disable cfilter |
| 925 | */ |
| 926 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 927 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 928 | |
| 929 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 930 | if (cfilt_sel == sitar->mbhc_bias_regs.cfilt_sel) |
| 931 | sitar_codec_switch_cfilt_mode(codec, 1); |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | static int sitar_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 937 | { |
| 938 | int rc = -EINVAL; |
| 939 | unsigned min_mv, max_mv; |
| 940 | |
| 941 | switch (ldoh_v) { |
| 942 | case SITAR_LDOH_1P95_V: |
| 943 | min_mv = 160; |
| 944 | max_mv = 1800; |
| 945 | break; |
| 946 | case SITAR_LDOH_2P35_V: |
| 947 | min_mv = 200; |
| 948 | max_mv = 2200; |
| 949 | break; |
| 950 | case SITAR_LDOH_2P75_V: |
| 951 | min_mv = 240; |
| 952 | max_mv = 2600; |
| 953 | break; |
| 954 | case SITAR_LDOH_2P85_V: |
| 955 | min_mv = 250; |
| 956 | max_mv = 2700; |
| 957 | break; |
| 958 | default: |
| 959 | goto done; |
| 960 | } |
| 961 | |
| 962 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 963 | goto done; |
| 964 | |
| 965 | for (rc = 4; rc <= 44; rc++) { |
| 966 | min_mv = max_mv * (rc) / 44; |
| 967 | if (min_mv >= cfilt_mv) { |
| 968 | rc -= 4; |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | done: |
| 973 | return rc; |
| 974 | } |
| 975 | |
| 976 | static bool sitar_is_hph_pa_on(struct snd_soc_codec *codec) |
| 977 | { |
| 978 | u8 hph_reg_val = 0; |
| 979 | hph_reg_val = snd_soc_read(codec, SITAR_A_RX_HPH_CNP_EN); |
| 980 | |
| 981 | return (hph_reg_val & 0x30) ? true : false; |
| 982 | } |
| 983 | |
| 984 | static bool sitar_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 985 | { |
| 986 | u8 hph_reg_val = 0; |
| 987 | if (left) |
| 988 | hph_reg_val = snd_soc_read(codec, |
| 989 | SITAR_A_RX_HPH_L_DAC_CTL); |
| 990 | else |
| 991 | hph_reg_val = snd_soc_read(codec, |
| 992 | SITAR_A_RX_HPH_R_DAC_CTL); |
| 993 | |
| 994 | return (hph_reg_val & 0xC0) ? true : false; |
| 995 | } |
| 996 | |
| 997 | static void sitar_codec_switch_micbias(struct snd_soc_codec *codec, |
| 998 | int vddio_switch) |
| 999 | { |
| 1000 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1001 | int cfilt_k_val; |
| 1002 | bool mbhc_was_polling = false; |
| 1003 | |
| 1004 | switch (vddio_switch) { |
| 1005 | case 1: |
| 1006 | if (sitar->mbhc_polling_active) { |
| 1007 | |
| 1008 | sitar_codec_pause_hs_polling(codec); |
| 1009 | /* Enable Mic Bias switch to VDDIO */ |
| 1010 | sitar->cfilt_k_value = snd_soc_read(codec, |
| 1011 | sitar->mbhc_bias_regs.cfilt_val); |
| 1012 | cfilt_k_val = sitar_find_k_value( |
| 1013 | sitar->pdata->micbias.ldoh_v, 1800); |
| 1014 | snd_soc_update_bits(codec, |
| 1015 | sitar->mbhc_bias_regs.cfilt_val, |
| 1016 | 0xFC, (cfilt_k_val << 2)); |
| 1017 | |
| 1018 | snd_soc_update_bits(codec, |
| 1019 | sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x80); |
| 1020 | snd_soc_update_bits(codec, |
| 1021 | sitar->mbhc_bias_regs.mbhc_reg, 0x10, 0x00); |
| 1022 | sitar_codec_start_hs_polling(codec); |
| 1023 | |
| 1024 | sitar->mbhc_micbias_switched = true; |
| 1025 | pr_err("%s: Enabled MBHC Mic bias to VDDIO Switch\n", |
| 1026 | __func__); |
| 1027 | } |
| 1028 | break; |
| 1029 | |
| 1030 | case 0: |
| 1031 | if (sitar->mbhc_micbias_switched) { |
| 1032 | if (sitar->mbhc_polling_active) { |
| 1033 | sitar_codec_pause_hs_polling(codec); |
| 1034 | mbhc_was_polling = true; |
| 1035 | } |
| 1036 | /* Disable Mic Bias switch to VDDIO */ |
| 1037 | if (sitar->cfilt_k_value != 0) |
| 1038 | snd_soc_update_bits(codec, |
| 1039 | sitar->mbhc_bias_regs.cfilt_val, 0XFC, |
| 1040 | sitar->cfilt_k_value); |
| 1041 | snd_soc_update_bits(codec, |
| 1042 | sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 1043 | snd_soc_update_bits(codec, |
| 1044 | sitar->mbhc_bias_regs.mbhc_reg, 0x10, 0x00); |
| 1045 | |
| 1046 | if (mbhc_was_polling) |
| 1047 | sitar_codec_start_hs_polling(codec); |
| 1048 | |
| 1049 | sitar->mbhc_micbias_switched = false; |
| 1050 | pr_err("%s: Disabled MBHC Mic bias to VDDIO Switch\n", |
| 1051 | __func__); |
| 1052 | } |
| 1053 | break; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | static int sitar_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 1058 | struct snd_kcontrol *kcontrol, int event) |
| 1059 | { |
| 1060 | struct snd_soc_codec *codec = w->codec; |
| 1061 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1062 | u16 micb_int_reg; |
| 1063 | int micb_line; |
| 1064 | u8 cfilt_sel_val = 0; |
| 1065 | char *internal1_text = "Internal1"; |
| 1066 | char *internal2_text = "Internal2"; |
| 1067 | |
| 1068 | pr_err("%s %d\n", __func__, event); |
| 1069 | switch (w->reg) { |
| 1070 | case SITAR_A_MICB_1_CTL: |
| 1071 | micb_int_reg = SITAR_A_MICB_1_INT_RBIAS; |
| 1072 | cfilt_sel_val = sitar->pdata->micbias.bias1_cfilt_sel; |
| 1073 | micb_line = SITAR_MICBIAS1; |
| 1074 | break; |
| 1075 | case SITAR_A_MICB_2_CTL: |
| 1076 | micb_int_reg = SITAR_A_MICB_2_INT_RBIAS; |
| 1077 | cfilt_sel_val = sitar->pdata->micbias.bias2_cfilt_sel; |
| 1078 | micb_line = SITAR_MICBIAS2; |
| 1079 | break; |
| 1080 | default: |
| 1081 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 1082 | return -EINVAL; |
| 1083 | } |
| 1084 | |
| 1085 | switch (event) { |
| 1086 | case SND_SOC_DAPM_PRE_PMU: |
| 1087 | /* Decide whether to switch the micbias for MBHC */ |
| 1088 | if ((w->reg == sitar->mbhc_bias_regs.ctl_reg) |
| 1089 | && sitar->mbhc_micbias_switched) |
| 1090 | sitar_codec_switch_micbias(codec, 0); |
| 1091 | |
| 1092 | snd_soc_update_bits(codec, w->reg, 0x1E, 0x0A); |
| 1093 | sitar_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
| 1094 | |
| 1095 | if (strnstr(w->name, internal1_text, 30)) |
| 1096 | snd_soc_update_bits(codec, micb_int_reg, 0xFF, 0xA4); |
| 1097 | else if (strnstr(w->name, internal2_text, 30)) |
| 1098 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 1099 | break; |
| 1100 | case SND_SOC_DAPM_POST_PMU: |
| 1101 | if (sitar->mbhc_polling_active && |
| 1102 | (sitar->calibration->bias == micb_line)) { |
| 1103 | sitar_codec_pause_hs_polling(codec); |
| 1104 | sitar_codec_start_hs_polling(codec); |
| 1105 | } |
| 1106 | break; |
| 1107 | case SND_SOC_DAPM_POST_PMD: |
| 1108 | |
| 1109 | if ((w->reg == sitar->mbhc_bias_regs.ctl_reg) |
| 1110 | && sitar_is_hph_pa_on(codec)) |
| 1111 | sitar_codec_switch_micbias(codec, 1); |
| 1112 | |
| 1113 | if (strnstr(w->name, internal1_text, 30)) |
| 1114 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
| 1115 | else if (strnstr(w->name, internal2_text, 30)) |
| 1116 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 1117 | sitar_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
| 1118 | break; |
| 1119 | } |
| 1120 | |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
| 1124 | static int sitar_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 1125 | struct snd_kcontrol *kcontrol, int event) |
| 1126 | { |
| 1127 | struct snd_soc_codec *codec = w->codec; |
| 1128 | u16 dec_reset_reg; |
| 1129 | |
| 1130 | pr_err("%s %d\n", __func__, event); |
| 1131 | |
| 1132 | if (w->reg == SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL) |
| 1133 | dec_reset_reg = SITAR_A_CDC_CLK_TX_RESET_B1_CTL; |
| 1134 | else { |
| 1135 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 1136 | return -EINVAL; |
| 1137 | } |
| 1138 | |
| 1139 | switch (event) { |
| 1140 | case SND_SOC_DAPM_PRE_PMU: |
| 1141 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 1142 | 1 << w->shift); |
| 1143 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
| 1144 | break; |
| 1145 | } |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | static int sitar_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
| 1150 | struct snd_kcontrol *kcontrol, int event) |
| 1151 | { |
| 1152 | struct snd_soc_codec *codec = w->codec; |
| 1153 | |
| 1154 | pr_err("%s %d %s\n", __func__, event, w->name); |
| 1155 | |
| 1156 | switch (event) { |
| 1157 | case SND_SOC_DAPM_PRE_PMU: |
| 1158 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_RESET_CTL, |
| 1159 | 1 << w->shift, 1 << w->shift); |
| 1160 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_RESET_CTL, |
| 1161 | 1 << w->shift, 0x0); |
| 1162 | break; |
| 1163 | } |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static int sitar_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 1168 | struct snd_kcontrol *kcontrol, int event) |
| 1169 | { |
| 1170 | switch (event) { |
| 1171 | case SND_SOC_DAPM_POST_PMU: |
| 1172 | case SND_SOC_DAPM_POST_PMD: |
| 1173 | usleep_range(1000, 1000); |
| 1174 | pr_debug("LDO_H\n"); |
| 1175 | break; |
| 1176 | } |
| 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static void sitar_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 1181 | { |
| 1182 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1183 | |
| 1184 | if (enable) { |
| 1185 | sitar->rx_bias_count++; |
| 1186 | if (sitar->rx_bias_count == 1) |
| 1187 | snd_soc_update_bits(codec, SITAR_A_RX_COM_BIAS, |
| 1188 | 0x80, 0x80); |
| 1189 | } else { |
| 1190 | sitar->rx_bias_count--; |
| 1191 | if (!sitar->rx_bias_count) |
| 1192 | snd_soc_update_bits(codec, SITAR_A_RX_COM_BIAS, |
| 1193 | 0x80, 0x00); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | static int sitar_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 1198 | struct snd_kcontrol *kcontrol, int event) |
| 1199 | { |
| 1200 | struct snd_soc_codec *codec = w->codec; |
| 1201 | |
| 1202 | pr_err("%s %d\n", __func__, event); |
| 1203 | |
| 1204 | switch (event) { |
| 1205 | case SND_SOC_DAPM_PRE_PMU: |
| 1206 | sitar_enable_rx_bias(codec, 1); |
| 1207 | break; |
| 1208 | case SND_SOC_DAPM_POST_PMD: |
| 1209 | sitar_enable_rx_bias(codec, 0); |
| 1210 | break; |
| 1211 | } |
| 1212 | return 0; |
| 1213 | } |
| 1214 | static int sitar_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 1215 | struct snd_kcontrol *kcontrol, int event) |
| 1216 | { |
| 1217 | struct snd_soc_codec *codec = w->codec; |
| 1218 | |
| 1219 | pr_err("%s %s %d\n", __func__, w->name, event); |
| 1220 | |
| 1221 | switch (event) { |
| 1222 | case SND_SOC_DAPM_PRE_PMU: |
| 1223 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 1224 | break; |
| 1225 | case SND_SOC_DAPM_POST_PMD: |
| 1226 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 1227 | break; |
| 1228 | } |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | static void sitar_snd_soc_jack_report(struct sitar_priv *sitar, |
| 1233 | struct snd_soc_jack *jack, int status, |
| 1234 | int mask) |
| 1235 | { |
| 1236 | /* XXX: wake_lock_timeout()? */ |
| 1237 | snd_soc_jack_report(jack, status, mask); |
| 1238 | } |
| 1239 | |
| 1240 | static void hphocp_off_report(struct sitar_priv *sitar, |
| 1241 | u32 jack_status, int irq) |
| 1242 | { |
| 1243 | struct snd_soc_codec *codec; |
| 1244 | |
| 1245 | if (sitar) { |
| 1246 | pr_info("%s: clear ocp status %x\n", __func__, jack_status); |
| 1247 | codec = sitar->codec; |
| 1248 | sitar->hph_status &= ~jack_status; |
| 1249 | if (sitar->headset_jack) |
| 1250 | sitar_snd_soc_jack_report(sitar, sitar->headset_jack, |
| 1251 | sitar->hph_status, |
| 1252 | SITAR_JACK_MASK); |
| 1253 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 1254 | 0x00); |
| 1255 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 1256 | 0x10); |
| 1257 | /* reset retry counter as PA is turned off signifying |
| 1258 | * start of new OCP detection session |
| 1259 | */ |
| 1260 | if (SITAR_IRQ_HPH_PA_OCPL_FAULT) |
| 1261 | sitar->hphlocp_cnt = 0; |
| 1262 | else |
| 1263 | sitar->hphrocp_cnt = 0; |
| 1264 | wcd9xxx_enable_irq(codec->control_data, irq); |
| 1265 | } else { |
| 1266 | pr_err("%s: Bad sitar private data\n", __func__); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static void hphlocp_off_report(struct work_struct *work) |
| 1271 | { |
| 1272 | struct sitar_priv *sitar = container_of(work, struct sitar_priv, |
| 1273 | hphlocp_work); |
| 1274 | hphocp_off_report(sitar, SND_JACK_OC_HPHL, SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 1275 | } |
| 1276 | |
| 1277 | static void hphrocp_off_report(struct work_struct *work) |
| 1278 | { |
| 1279 | struct sitar_priv *sitar = container_of(work, struct sitar_priv, |
| 1280 | hphrocp_work); |
| 1281 | hphocp_off_report(sitar, SND_JACK_OC_HPHR, SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 1282 | } |
| 1283 | |
| 1284 | static int sitar_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 1285 | struct snd_kcontrol *kcontrol, int event) |
| 1286 | { |
| 1287 | struct snd_soc_codec *codec = w->codec; |
| 1288 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1289 | u8 mbhc_micb_ctl_val; |
| 1290 | pr_err("%s: event = %d\n", __func__, event); |
| 1291 | |
| 1292 | switch (event) { |
| 1293 | case SND_SOC_DAPM_PRE_PMU: |
| 1294 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 1295 | sitar->mbhc_bias_regs.ctl_reg); |
| 1296 | |
| 1297 | if (!(mbhc_micb_ctl_val & 0x80) |
| 1298 | && !sitar->mbhc_micbias_switched) |
| 1299 | sitar_codec_switch_micbias(codec, 1); |
| 1300 | |
| 1301 | break; |
| 1302 | |
| 1303 | case SND_SOC_DAPM_POST_PMD: |
| 1304 | /* schedule work is required because at the time HPH PA DAPM |
| 1305 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 1306 | * would have been locked while snd_soc_jack_report also |
| 1307 | * attempts to acquire same lock. |
| 1308 | */ |
| 1309 | if (w->shift == 5) { |
| 1310 | clear_bit(SITAR_HPHL_PA_OFF_ACK, |
| 1311 | &sitar->hph_pa_dac_state); |
| 1312 | clear_bit(SITAR_HPHL_DAC_OFF_ACK, |
| 1313 | &sitar->hph_pa_dac_state); |
| 1314 | if (sitar->hph_status & SND_JACK_OC_HPHL) |
| 1315 | schedule_work(&sitar->hphlocp_work); |
| 1316 | } else if (w->shift == 4) { |
| 1317 | clear_bit(SITAR_HPHR_PA_OFF_ACK, |
| 1318 | &sitar->hph_pa_dac_state); |
| 1319 | clear_bit(SITAR_HPHR_DAC_OFF_ACK, |
| 1320 | &sitar->hph_pa_dac_state); |
| 1321 | if (sitar->hph_status & SND_JACK_OC_HPHR) |
| 1322 | schedule_work(&sitar->hphrocp_work); |
| 1323 | } |
| 1324 | |
| 1325 | if (sitar->mbhc_micbias_switched) |
| 1326 | sitar_codec_switch_micbias(codec, 0); |
| 1327 | |
| 1328 | pr_err("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 1329 | w->name); |
| 1330 | usleep_range(10000, 10000); |
| 1331 | |
| 1332 | break; |
| 1333 | } |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
| 1337 | static void sitar_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
| 1338 | struct mbhc_micbias_regs *micbias_regs) |
| 1339 | { |
| 1340 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1341 | struct sitar_mbhc_calibration *calibration = sitar->calibration; |
| 1342 | unsigned int cfilt; |
| 1343 | |
| 1344 | switch (calibration->bias) { |
| 1345 | case SITAR_MICBIAS1: |
| 1346 | cfilt = sitar->pdata->micbias.bias1_cfilt_sel; |
| 1347 | micbias_regs->mbhc_reg = SITAR_A_MICB_1_MBHC; |
| 1348 | micbias_regs->int_rbias = SITAR_A_MICB_1_INT_RBIAS; |
| 1349 | micbias_regs->ctl_reg = SITAR_A_MICB_1_CTL; |
| 1350 | break; |
| 1351 | case SITAR_MICBIAS2: |
| 1352 | cfilt = sitar->pdata->micbias.bias2_cfilt_sel; |
| 1353 | micbias_regs->mbhc_reg = SITAR_A_MICB_2_MBHC; |
| 1354 | micbias_regs->int_rbias = SITAR_A_MICB_2_INT_RBIAS; |
| 1355 | micbias_regs->ctl_reg = SITAR_A_MICB_2_CTL; |
| 1356 | break; |
| 1357 | default: |
| 1358 | /* Should never reach here */ |
| 1359 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
| 1360 | return; |
| 1361 | } |
| 1362 | |
| 1363 | micbias_regs->cfilt_sel = cfilt; |
| 1364 | |
| 1365 | switch (cfilt) { |
| 1366 | case SITAR_CFILT1_SEL: |
| 1367 | micbias_regs->cfilt_val = SITAR_A_MICB_CFILT_1_VAL; |
| 1368 | micbias_regs->cfilt_ctl = SITAR_A_MICB_CFILT_1_CTL; |
| 1369 | break; |
| 1370 | case SITAR_CFILT2_SEL: |
| 1371 | micbias_regs->cfilt_val = SITAR_A_MICB_CFILT_2_VAL; |
| 1372 | micbias_regs->cfilt_ctl = SITAR_A_MICB_CFILT_2_CTL; |
| 1373 | break; |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | static int sitar_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 1378 | struct snd_kcontrol *kcontrol, int event) |
| 1379 | { |
| 1380 | struct snd_soc_codec *codec = w->codec; |
| 1381 | |
| 1382 | pr_err("%s %d\n", __func__, event); |
| 1383 | switch (event) { |
| 1384 | case SND_SOC_DAPM_POST_PMU: |
| 1385 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x01, |
| 1386 | 0x01); |
| 1387 | snd_soc_update_bits(codec, SITAR_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 1388 | usleep_range(200, 200); |
| 1389 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x10, 0x00); |
| 1390 | break; |
| 1391 | case SND_SOC_DAPM_PRE_PMD: |
| 1392 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 1393 | 0x10); |
| 1394 | usleep_range(20, 20); |
| 1395 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x08, 0x08); |
| 1396 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x10, 0x10); |
| 1397 | snd_soc_update_bits(codec, SITAR_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 1398 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x01, |
| 1399 | 0x00); |
| 1400 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x08, 0x00); |
| 1401 | break; |
| 1402 | } |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static const struct snd_soc_dapm_widget sitar_dapm_i2s_widgets[] = { |
| 1407 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 1408 | 4, 0, NULL, 0), |
| 1409 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", SITAR_A_CDC_CLK_TX_I2S_CTL, 4, |
| 1410 | 0, NULL, 0), |
| 1411 | }; |
| 1412 | |
| 1413 | static const struct snd_soc_dapm_widget sitar_dapm_widgets[] = { |
| 1414 | /*RX stuff */ |
| 1415 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 1416 | |
| 1417 | SND_SOC_DAPM_PGA("EAR PA", SITAR_A_RX_EAR_EN, 4, 0, NULL, 0), |
| 1418 | SND_SOC_DAPM_MIXER("DAC1", SITAR_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 1419 | ARRAY_SIZE(dac1_switch)), |
| 1420 | SND_SOC_DAPM_SUPPLY("EAR DRIVER", SITAR_A_RX_EAR_EN, 3, 0, NULL, 0), |
| 1421 | SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 1422 | 0, sitar_codec_enable_slimrx, |
| 1423 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1424 | SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 1425 | 0, sitar_codec_enable_slimrx, |
| 1426 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1427 | SND_SOC_DAPM_AIF_IN("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1428 | SND_SOC_DAPM_AIF_IN("SLIM RX4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1429 | SND_SOC_DAPM_AIF_IN("SLIM RX5", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1430 | |
| 1431 | /* Headphone */ |
| 1432 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 1433 | SND_SOC_DAPM_PGA_E("HPHL", SITAR_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 1434 | sitar_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 1435 | SND_SOC_DAPM_POST_PMD), |
| 1436 | SND_SOC_DAPM_MIXER("HPHL DAC", SITAR_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 1437 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 1438 | |
| 1439 | SND_SOC_DAPM_PGA_E("HPHR", SITAR_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 1440 | sitar_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 1441 | SND_SOC_DAPM_POST_PMD), |
| 1442 | |
| 1443 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, SITAR_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 1444 | sitar_hphr_dac_event, |
| 1445 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1446 | |
| 1447 | /* Speaker */ |
| 1448 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 1449 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 1450 | |
| 1451 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", SITAR_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 1452 | 0, sitar_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 1453 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1454 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", SITAR_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 1455 | 0, sitar_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 1456 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1457 | |
| 1458 | SND_SOC_DAPM_MIXER_E("RX1 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL, |
| 1459 | 0, sitar_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU), |
| 1460 | SND_SOC_DAPM_MIXER_E("RX2 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL, |
| 1461 | 0, sitar_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU), |
| 1462 | SND_SOC_DAPM_MIXER_E("RX3 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL, |
| 1463 | 0, sitar_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU), |
| 1464 | |
| 1465 | SND_SOC_DAPM_MUX("DAC1 MUX", SND_SOC_NOPM, 0, 0, |
| 1466 | &rx_dac1_mux), |
| 1467 | SND_SOC_DAPM_MUX("DAC2 MUX", SND_SOC_NOPM, 0, 0, |
| 1468 | &rx_dac2_mux), |
| 1469 | SND_SOC_DAPM_MUX("DAC3 MUX", SND_SOC_NOPM, 0, 0, |
| 1470 | &rx_dac3_mux), |
| 1471 | SND_SOC_DAPM_MUX("DAC4 MUX", SND_SOC_NOPM, 0, 0, |
| 1472 | &rx_dac4_mux), |
| 1473 | |
| 1474 | SND_SOC_DAPM_MIXER("RX1 CHAIN", SITAR_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0), |
| 1475 | SND_SOC_DAPM_MIXER("RX2 CHAIN", SITAR_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0), |
| 1476 | SND_SOC_DAPM_MIXER("RX3 CHAIN", SITAR_A_CDC_RX3_B6_CTL, 5, 0, NULL, 0), |
| 1477 | |
| 1478 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1479 | &rx_mix1_inp1_mux), |
| 1480 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1481 | &rx_mix1_inp2_mux), |
| 1482 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1483 | &rx2_mix1_inp1_mux), |
| 1484 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1485 | &rx2_mix1_inp2_mux), |
| 1486 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1487 | &rx3_mix1_inp1_mux), |
| 1488 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1489 | &rx3_mix1_inp2_mux), |
| 1490 | |
| 1491 | SND_SOC_DAPM_SUPPLY("CP", SITAR_A_CP_EN, 0, 0, |
| 1492 | sitar_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 1493 | SND_SOC_DAPM_PRE_PMD), |
| 1494 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 1495 | sitar_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 1496 | SND_SOC_DAPM_POST_PMD), |
| 1497 | |
| 1498 | SND_SOC_DAPM_SUPPLY("LDO_H", SITAR_A_LDO_H_MODE_1, 7, 0, |
| 1499 | sitar_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 1500 | /* TX */ |
| 1501 | SND_SOC_DAPM_SUPPLY("CDC_CONN", SITAR_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 1502 | 0), |
| 1503 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 1504 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SITAR_A_MICB_1_CTL, 7, 0, |
| 1505 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1506 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1507 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SITAR_A_MICB_1_CTL, 7, 0, |
| 1508 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1509 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1510 | |
| 1511 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 1512 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SITAR_A_MICB_2_CTL, 7, 0, |
| 1513 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1514 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1515 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SITAR_A_MICB_2_CTL, 7, 0, |
| 1516 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1517 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1518 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SITAR_A_MICB_2_CTL, 7, 0, |
| 1519 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1520 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1521 | |
| 1522 | SND_SOC_DAPM_ADC_E("ADC1", NULL, SITAR_A_TX_1_2_EN, 7, 0, |
| 1523 | sitar_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 1524 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1525 | SND_SOC_DAPM_ADC_E("ADC2", NULL, SITAR_A_TX_1_2_EN, 3, 0, |
| 1526 | sitar_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 1527 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1528 | |
| 1529 | SND_SOC_DAPM_MUX_E("DEC1 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0, |
| 1530 | &dec1_mux, sitar_codec_enable_dec, SND_SOC_DAPM_PRE_PMU), |
| 1531 | |
| 1532 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux), |
| 1533 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux), |
| 1534 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux), |
| 1535 | |
| 1536 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1537 | 0, sitar_codec_enable_slimtx, |
| 1538 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1539 | |
| 1540 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1541 | 0, sitar_codec_enable_slimtx, |
| 1542 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1543 | |
| 1544 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1545 | 0, sitar_codec_enable_slimtx, |
| 1546 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1547 | SND_SOC_DAPM_MUX_E("DEC2 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0, |
| 1548 | &dec2_mux, sitar_codec_enable_dec, SND_SOC_DAPM_PRE_PMU), |
| 1549 | SND_SOC_DAPM_MUX_E("DEC3 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0, |
| 1550 | &dec3_mux, sitar_codec_enable_dec, SND_SOC_DAPM_PRE_PMU), |
| 1551 | SND_SOC_DAPM_MUX_E("DEC4 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0, |
| 1552 | &dec4_mux, sitar_codec_enable_dec, SND_SOC_DAPM_PRE_PMU), |
| 1553 | |
| 1554 | /* Digital Mic Inputs */ |
| 1555 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 1556 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1557 | SND_SOC_DAPM_POST_PMD), |
| 1558 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 1559 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1560 | SND_SOC_DAPM_POST_PMD), |
| 1561 | |
| 1562 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 1563 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1564 | SND_SOC_DAPM_POST_PMD), |
| 1565 | |
| 1566 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 1567 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1568 | SND_SOC_DAPM_POST_PMD), |
| 1569 | |
| 1570 | /* Sidetone */ |
| 1571 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 1572 | SND_SOC_DAPM_PGA("IIR1", SITAR_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0), |
| 1573 | |
| 1574 | }; |
| 1575 | |
| 1576 | static const struct snd_soc_dapm_route audio_map[] = { |
| 1577 | /* Earpiece (RX MIX1) */ |
| 1578 | {"EAR", NULL, "EAR PA"}, |
| 1579 | {"EAR PA", "NULL", "DAC1"}, |
| 1580 | {"DAC1", "Switch", "DAC1 MUX"}, |
| 1581 | {"DAC1", NULL, "CP"}, |
| 1582 | {"DAC1", NULL, "EAR DRIVER"}, |
| 1583 | |
| 1584 | {"LINEOUT1", NULL, "CP"}, |
| 1585 | {"LINEOUT2", NULL, "CP"}, |
| 1586 | |
| 1587 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 1588 | {"LINEOUT2 PA", "NULL", "DAC3 MUX"}, |
| 1589 | |
| 1590 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 1591 | {"LINEOUT1 PA", "NULL", "DAC2 MUX"}, |
| 1592 | |
| 1593 | /* Headset (RX MIX1 and RX MIX2) */ |
| 1594 | {"HEADPHONE", NULL, "HPHL"}, |
| 1595 | {"HEADPHONE", NULL, "HPHR"}, |
| 1596 | |
| 1597 | {"HPHL", NULL, "HPHL DAC"}, |
| 1598 | {"HPHL DAC", NULL, "DAC4 MUX"}, |
| 1599 | {"HPHR", NULL, "HPHR DAC"}, |
| 1600 | {"HPHL DAC", NULL, "RX3 MIX1"}, |
| 1601 | |
| 1602 | {"DAC1 MUX", "RX1", "RX1 CHAIN"}, |
| 1603 | {"DAC2 MUX", "RX1", "RX1 CHAIN"}, |
| 1604 | {"DAC3 MUX", "RX1", "RX1 CHAIN"}, |
| 1605 | {"DAC3 MUX", "RX1_INV", "RX1 CHAIN"}, |
| 1606 | {"DAC3 MUX", "RX2", "RX2 MIX1"}, |
| 1607 | {"DAC4 MUX", "ON", "RX2 MIX1"}, |
| 1608 | |
| 1609 | {"RX1 CHAIN", NULL, "RX1 MIX1"}, |
| 1610 | |
| 1611 | {"CP", NULL, "RX_BIAS"}, |
| 1612 | |
| 1613 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 1614 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
| 1615 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 1616 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
| 1617 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 1618 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 1619 | |
| 1620 | /* SLIMBUS Connections */ |
| 1621 | |
| 1622 | /* Slimbus port 5 is non functional in Sitar 1.0 */ |
| 1623 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 1624 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 1625 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 1626 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 1627 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 1628 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 1629 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 1630 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 1631 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 1632 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
| 1633 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 1634 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 1635 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 1636 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 1637 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
| 1638 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 1639 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 1640 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 1641 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 1642 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
| 1643 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 1644 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 1645 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 1646 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 1647 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
| 1648 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 1649 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 1650 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 1651 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 1652 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
| 1653 | |
| 1654 | |
| 1655 | /* TX */ |
| 1656 | {"SLIM TX1", NULL, "SLIM TX1 MUX"}, |
| 1657 | {"MIC BIAS2 Internal1", NULL, "DEC1 MUX"}, |
| 1658 | |
| 1659 | {"SLIM TX2", NULL, "SLIM TX2 MUX"}, |
| 1660 | {"MIC BIAS2 Internal1", NULL, "DEC1 MUX"}, |
| 1661 | |
| 1662 | {"SLIM TX1", NULL, "SLIM TX1 MUX"}, |
| 1663 | {"SLIM TX2", NULL, "SLIM TX2 MUX"}, |
| 1664 | {"SLIM TX3", NULL, "SLIM TX3 MUX"}, |
| 1665 | |
| 1666 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
| 1667 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 1668 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
| 1669 | |
| 1670 | /* Decimator Inputs */ |
| 1671 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
| 1672 | {"DEC1 MUX", "DMIC4", "DMIC4"}, |
| 1673 | {"DEC1 MUX", "ADC1", "ADC1"}, |
| 1674 | {"DEC1 MUX", "ADC2", "ADC2"}, |
| 1675 | |
| 1676 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
| 1677 | {"DEC2 MUX", "DMIC3", "DMIC3"}, |
| 1678 | {"DEC2 MUX", "ADC1", "ADC1"}, |
| 1679 | {"DEC2 MUX", "ADC2", "ADC2"}, |
| 1680 | |
| 1681 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
| 1682 | {"DEC3 MUX", "ADC1", "ADC1"}, |
| 1683 | {"DEC3 MUX", "ADC2", "ADC2"}, |
| 1684 | {"DEC3 MUX", "DMIC2", "DMIC2"}, |
| 1685 | {"DEC3 MUX", "DMIC3", "DMIC4"}, |
| 1686 | |
| 1687 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
| 1688 | {"DEC4 MUX", "ADC1", "ADC1"}, |
| 1689 | {"DEC4 MUX", "ADC2", "ADC2"}, |
| 1690 | {"DEC4 MUX", "DMIC3", "DMIC3"}, |
| 1691 | {"DEC4 MUX", "DMIC2", "DMIC2"}, |
| 1692 | {"DEC4 MUX", "DMIC1", "DMIC1"}, |
| 1693 | |
| 1694 | /* ADC Connections */ |
| 1695 | {"ADC1", NULL, "AMIC1"}, |
| 1696 | {"ADC2", NULL, "AMIC2"}, |
| 1697 | |
| 1698 | /* IIR */ |
| 1699 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
| 1700 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 1701 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 1702 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 1703 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 1704 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 1705 | }; |
| 1706 | |
| 1707 | static int sitar_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 1708 | { |
| 1709 | return sitar_reg_readable[reg]; |
| 1710 | } |
| 1711 | |
| 1712 | static int sitar_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 1713 | { |
| 1714 | /* Registers lower than 0x100 are top level registers which can be |
| 1715 | * written by the Sitar core driver. |
| 1716 | */ |
| 1717 | |
| 1718 | if ((reg >= SITAR_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 1719 | return 1; |
| 1720 | |
| 1721 | /* IIR Coeff registers are not cacheable */ |
| 1722 | if ((reg >= SITAR_A_CDC_IIR1_COEF_B1_CTL) && |
| 1723 | (reg <= SITAR_A_CDC_IIR1_COEF_B5_CTL)) |
| 1724 | return 1; |
| 1725 | |
| 1726 | return 0; |
| 1727 | } |
| 1728 | |
| 1729 | #define SITAR_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 1730 | static int sitar_write(struct snd_soc_codec *codec, unsigned int reg, |
| 1731 | unsigned int value) |
| 1732 | { |
| 1733 | int ret; |
| 1734 | |
| 1735 | BUG_ON(reg > SITAR_MAX_REGISTER); |
| 1736 | |
| 1737 | if (!sitar_volatile(codec, reg)) { |
| 1738 | ret = snd_soc_cache_write(codec, reg, value); |
| 1739 | if (ret != 0) |
| 1740 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 1741 | reg, ret); |
| 1742 | } |
| 1743 | |
| 1744 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
| 1745 | } |
| 1746 | static unsigned int sitar_read(struct snd_soc_codec *codec, |
| 1747 | unsigned int reg) |
| 1748 | { |
| 1749 | unsigned int val; |
| 1750 | int ret; |
| 1751 | |
| 1752 | BUG_ON(reg > SITAR_MAX_REGISTER); |
| 1753 | |
| 1754 | if (!sitar_volatile(codec, reg) && sitar_readable(codec, reg) && |
| 1755 | reg < codec->driver->reg_cache_size) { |
| 1756 | ret = snd_soc_cache_read(codec, reg, &val); |
| 1757 | if (ret >= 0) { |
| 1758 | return val; |
| 1759 | } else |
| 1760 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 1761 | reg, ret); |
| 1762 | } |
| 1763 | |
| 1764 | val = wcd9xxx_reg_read(codec->control_data, reg); |
| 1765 | return val; |
| 1766 | } |
| 1767 | |
| 1768 | static void sitar_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 1769 | { |
| 1770 | |
| 1771 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x0C, 0x61); |
| 1772 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x80, 0x80); |
| 1773 | usleep_range(1000, 1000); |
| 1774 | snd_soc_write(codec, SITAR_A_BIAS_REF_CTL, 0x1C); |
| 1775 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1776 | 0x80); |
| 1777 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 1778 | 0x04); |
| 1779 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1780 | 0x01); |
| 1781 | usleep_range(1000, 1000); |
| 1782 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1783 | 0x00); |
| 1784 | } |
| 1785 | |
| 1786 | static void sitar_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 1787 | enum sitar_bandgap_type choice) |
| 1788 | { |
| 1789 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1790 | |
| 1791 | /* TODO lock resources accessed by audio streams and threaded |
| 1792 | * interrupt handlers |
| 1793 | */ |
| 1794 | |
| 1795 | pr_err("%s, choice is %d, current is %d\n", __func__, choice, |
| 1796 | sitar->bandgap_type); |
| 1797 | |
| 1798 | if (sitar->bandgap_type == choice) |
| 1799 | return; |
| 1800 | |
| 1801 | if ((sitar->bandgap_type == SITAR_BANDGAP_OFF) && |
| 1802 | (choice == SITAR_BANDGAP_AUDIO_MODE)) { |
| 1803 | sitar_codec_enable_audio_mode_bandgap(codec); |
| 1804 | } else if (choice == SITAR_BANDGAP_MBHC_MODE) { |
| 1805 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 1806 | 0x2); |
| 1807 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1808 | 0x80); |
| 1809 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 1810 | 0x4); |
| 1811 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1812 | 0x1); |
| 1813 | usleep_range(1000, 1000); |
| 1814 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1815 | 0x00); |
| 1816 | } else if ((sitar->bandgap_type == SITAR_BANDGAP_MBHC_MODE) && |
| 1817 | (choice == SITAR_BANDGAP_AUDIO_MODE)) { |
| 1818 | snd_soc_write(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x50); |
| 1819 | usleep_range(100, 100); |
| 1820 | sitar_codec_enable_audio_mode_bandgap(codec); |
| 1821 | } else if (choice == SITAR_BANDGAP_OFF) { |
| 1822 | snd_soc_write(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x50); |
| 1823 | } else { |
| 1824 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 1825 | } |
| 1826 | sitar->bandgap_type = choice; |
| 1827 | } |
| 1828 | |
| 1829 | |
| 1830 | static int sitar_codec_enable_clock_block(struct snd_soc_codec *codec, |
| 1831 | int config_mode) |
| 1832 | { |
| 1833 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1834 | |
| 1835 | pr_err("%s\n", __func__); |
| 1836 | |
| 1837 | if (config_mode) { |
| 1838 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN2, 0x00); |
| 1839 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN2, 0x02); |
| 1840 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN1, 0x0D); |
| 1841 | usleep_range(1000, 1000); |
| 1842 | } else |
| 1843 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 1844 | |
| 1845 | |
| 1846 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x05); |
| 1847 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x02, 0x00); |
| 1848 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 1849 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 1850 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x04, 0x04); |
| 1851 | usleep_range(50, 50); |
| 1852 | sitar->clock_active = true; |
| 1853 | return 0; |
| 1854 | } |
| 1855 | static void sitar_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 1856 | { |
| 1857 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1858 | pr_err("%s\n", __func__); |
| 1859 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x04, 0x04); |
| 1860 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x04, 0x00); |
| 1861 | ndelay(160); |
| 1862 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 1863 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x00); |
| 1864 | sitar->clock_active = false; |
| 1865 | } |
| 1866 | |
| 1867 | static void sitar_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 1868 | { |
| 1869 | /* TODO store register values in calibration */ |
| 1870 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B5_CTL, 0x20); |
| 1871 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B6_CTL, 0xFF); |
| 1872 | |
| 1873 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B10_CTL, 0xFF); |
| 1874 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B9_CTL, 0x20); |
| 1875 | |
| 1876 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B4_CTL, 0xF8); |
| 1877 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B3_CTL, 0xEE); |
| 1878 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B2_CTL, 0xFC); |
| 1879 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B1_CTL, 0xCE); |
| 1880 | |
| 1881 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B1_CTL, 3); |
| 1882 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B2_CTL, 9); |
| 1883 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B3_CTL, 30); |
| 1884 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B6_CTL, 120); |
| 1885 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_TIMER_B1_CTL, 0x78, 0x58); |
| 1886 | snd_soc_write(codec, SITAR_A_CDC_MBHC_B2_CTL, 11); |
| 1887 | } |
| 1888 | |
| 1889 | static int sitar_startup(struct snd_pcm_substream *substream, |
| 1890 | struct snd_soc_dai *dai) |
| 1891 | { |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 1892 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(dai->codec->dev->parent); |
| 1893 | if ((wcd9xxx != NULL) && (wcd9xxx->dev != NULL) && |
| 1894 | (wcd9xxx->dev->parent != NULL)) |
| 1895 | pm_runtime_get_sync(wcd9xxx->dev->parent); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1896 | pr_err("%s(): substream = %s stream = %d\n" , __func__, |
| 1897 | substream->name, substream->stream); |
| 1898 | |
| 1899 | return 0; |
| 1900 | } |
| 1901 | |
| 1902 | static void sitar_shutdown(struct snd_pcm_substream *substream, |
| 1903 | struct snd_soc_dai *dai) |
| 1904 | { |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 1905 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(dai->codec->dev->parent); |
| 1906 | if ((wcd9xxx != NULL) && (wcd9xxx->dev != NULL) && |
| 1907 | (wcd9xxx->dev->parent != NULL)) { |
| 1908 | pm_runtime_mark_last_busy(wcd9xxx->dev->parent); |
| 1909 | pm_runtime_put(wcd9xxx->dev->parent); |
| 1910 | } |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1911 | pr_err("%s(): substream = %s stream = %d\n" , __func__, |
| 1912 | substream->name, substream->stream); |
| 1913 | } |
| 1914 | |
| 1915 | int sitar_mclk_enable(struct snd_soc_codec *codec, int mclk_enable) |
| 1916 | { |
| 1917 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1918 | |
| 1919 | pr_err("%s() mclk_enable = %u\n", __func__, mclk_enable); |
| 1920 | |
| 1921 | if (mclk_enable) { |
| 1922 | sitar->mclk_enabled = true; |
| 1923 | |
| 1924 | if (sitar->mbhc_polling_active && (sitar->mclk_enabled)) { |
| 1925 | sitar_codec_pause_hs_polling(codec); |
| 1926 | sitar_codec_enable_bandgap(codec, |
| 1927 | SITAR_BANDGAP_AUDIO_MODE); |
| 1928 | sitar_codec_enable_clock_block(codec, 0); |
| 1929 | sitar_codec_calibrate_hs_polling(codec); |
| 1930 | sitar_codec_start_hs_polling(codec); |
| 1931 | } else { |
| 1932 | sitar_codec_enable_bandgap(codec, |
| 1933 | SITAR_BANDGAP_AUDIO_MODE); |
| 1934 | sitar_codec_enable_clock_block(codec, 0); |
| 1935 | } |
| 1936 | } else { |
| 1937 | |
| 1938 | if (!sitar->mclk_enabled) { |
| 1939 | pr_err("Error, MCLK already diabled\n"); |
| 1940 | return -EINVAL; |
| 1941 | } |
| 1942 | sitar->mclk_enabled = false; |
| 1943 | |
| 1944 | if (sitar->mbhc_polling_active) { |
| 1945 | if (!sitar->mclk_enabled) { |
| 1946 | sitar_codec_pause_hs_polling(codec); |
| 1947 | sitar_codec_enable_bandgap(codec, |
| 1948 | SITAR_BANDGAP_MBHC_MODE); |
| 1949 | sitar_enable_rx_bias(codec, 1); |
| 1950 | sitar_codec_enable_clock_block(codec, 1); |
| 1951 | sitar_codec_calibrate_hs_polling(codec); |
| 1952 | sitar_codec_start_hs_polling(codec); |
| 1953 | } |
| 1954 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, |
| 1955 | 0x05, 0x01); |
| 1956 | } else { |
| 1957 | sitar_codec_disable_clock_block(codec); |
| 1958 | sitar_codec_enable_bandgap(codec, |
| 1959 | SITAR_BANDGAP_OFF); |
| 1960 | } |
| 1961 | } |
| 1962 | return 0; |
| 1963 | } |
| 1964 | |
| 1965 | static int sitar_set_dai_sysclk(struct snd_soc_dai *dai, |
| 1966 | int clk_id, unsigned int freq, int dir) |
| 1967 | { |
| 1968 | pr_err("%s\n", __func__); |
| 1969 | return 0; |
| 1970 | } |
| 1971 | |
| 1972 | static int sitar_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 1973 | { |
| 1974 | u8 val = 0; |
| 1975 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 1976 | |
| 1977 | pr_err("%s\n", __func__); |
| 1978 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1979 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1980 | /* CPU is master */ |
| 1981 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 1982 | if (dai->id == AIF1_CAP) |
| 1983 | snd_soc_update_bits(dai->codec, |
| 1984 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 1985 | SITAR_I2S_MASTER_MODE_MASK, 0); |
| 1986 | else if (dai->id == AIF1_PB) |
| 1987 | snd_soc_update_bits(dai->codec, |
| 1988 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 1989 | SITAR_I2S_MASTER_MODE_MASK, 0); |
| 1990 | } |
| 1991 | break; |
| 1992 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1993 | /* CPU is slave */ |
| 1994 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 1995 | val = SITAR_I2S_MASTER_MODE_MASK; |
| 1996 | if (dai->id == AIF1_CAP) |
| 1997 | snd_soc_update_bits(dai->codec, |
| 1998 | SITAR_A_CDC_CLK_TX_I2S_CTL, val, val); |
| 1999 | else if (dai->id == AIF1_PB) |
| 2000 | snd_soc_update_bits(dai->codec, |
| 2001 | SITAR_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 2002 | } |
| 2003 | break; |
| 2004 | default: |
| 2005 | return -EINVAL; |
| 2006 | } |
| 2007 | return 0; |
| 2008 | } |
| 2009 | static int sitar_set_channel_map(struct snd_soc_dai *dai, |
| 2010 | unsigned int tx_num, unsigned int *tx_slot, |
| 2011 | unsigned int rx_num, unsigned int *rx_slot) |
| 2012 | |
| 2013 | { |
| 2014 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 2015 | u32 i = 0; |
| 2016 | if (!tx_slot && !rx_slot) { |
| 2017 | pr_err("%s: Invalid\n", __func__); |
| 2018 | return -EINVAL; |
| 2019 | } |
| 2020 | pr_debug("%s: DAI-ID %x %d %d\n", __func__, dai->id, tx_num, rx_num); |
| 2021 | |
| 2022 | if (dai->id == AIF1_PB) { |
| 2023 | for (i = 0; i < rx_num; i++) { |
| 2024 | sitar->dai[dai->id - 1].ch_num[i] = rx_slot[i]; |
| 2025 | sitar->dai[dai->id - 1].ch_act = 0; |
| 2026 | sitar->dai[dai->id - 1].ch_tot = rx_num; |
| 2027 | } |
| 2028 | } else if (dai->id == AIF1_CAP) { |
| 2029 | for (i = 0; i < tx_num; i++) { |
| 2030 | sitar->dai[dai->id - 1].ch_num[i] = tx_slot[i]; |
| 2031 | sitar->dai[dai->id - 1].ch_act = 0; |
| 2032 | sitar->dai[dai->id - 1].ch_tot = tx_num; |
| 2033 | } |
| 2034 | } |
| 2035 | return 0; |
| 2036 | } |
| 2037 | |
| 2038 | static int sitar_get_channel_map(struct snd_soc_dai *dai, |
| 2039 | unsigned int *tx_num, unsigned int *tx_slot, |
| 2040 | unsigned int *rx_num, unsigned int *rx_slot) |
| 2041 | |
| 2042 | { |
| 2043 | struct wcd9xxx *sitar = dev_get_drvdata(dai->codec->control_data); |
| 2044 | |
| 2045 | u32 cnt = 0; |
| 2046 | u32 tx_ch[SLIM_MAX_TX_PORTS]; |
| 2047 | u32 rx_ch[SLIM_MAX_RX_PORTS]; |
| 2048 | |
| 2049 | if (!rx_slot && !tx_slot) { |
| 2050 | pr_err("%s: Invalid\n", __func__); |
| 2051 | return -EINVAL; |
| 2052 | } |
| 2053 | pr_debug("%s: DAI-ID %x\n", __func__, dai->id); |
| 2054 | /* for virtual port, codec driver needs to do |
| 2055 | * housekeeping, for now should be ok |
| 2056 | */ |
| 2057 | wcd9xxx_get_channel(sitar, rx_ch, tx_ch); |
| 2058 | if (dai->id == AIF1_PB) { |
| 2059 | *rx_num = sitar_dai[dai->id - 1].playback.channels_max; |
| 2060 | while (cnt < *rx_num) { |
| 2061 | rx_slot[cnt] = rx_ch[cnt]; |
| 2062 | cnt++; |
| 2063 | } |
| 2064 | } else if (dai->id == AIF1_CAP) { |
| 2065 | *tx_num = sitar_dai[dai->id - 1].capture.channels_max; |
| 2066 | while (cnt < *tx_num) { |
| 2067 | tx_slot[cnt] = tx_ch[6 + cnt]; |
| 2068 | cnt++; |
| 2069 | } |
| 2070 | } |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
| 2074 | static int sitar_hw_params(struct snd_pcm_substream *substream, |
| 2075 | struct snd_pcm_hw_params *params, |
| 2076 | struct snd_soc_dai *dai) |
| 2077 | { |
| 2078 | struct snd_soc_codec *codec = dai->codec; |
| 2079 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 2080 | u8 path, shift; |
| 2081 | u16 tx_fs_reg, rx_fs_reg; |
| 2082 | u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state; |
| 2083 | |
| 2084 | pr_err("%s: DAI-ID %x\n", __func__, dai->id); |
| 2085 | |
| 2086 | switch (params_rate(params)) { |
| 2087 | case 8000: |
| 2088 | tx_fs_rate = 0x00; |
| 2089 | rx_fs_rate = 0x00; |
| 2090 | break; |
| 2091 | case 16000: |
| 2092 | tx_fs_rate = 0x01; |
| 2093 | rx_fs_rate = 0x20; |
| 2094 | break; |
| 2095 | case 32000: |
| 2096 | tx_fs_rate = 0x02; |
| 2097 | rx_fs_rate = 0x40; |
| 2098 | break; |
| 2099 | case 48000: |
| 2100 | tx_fs_rate = 0x03; |
| 2101 | rx_fs_rate = 0x60; |
| 2102 | break; |
| 2103 | default: |
| 2104 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 2105 | params_rate(params)); |
| 2106 | return -EINVAL; |
| 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | /** |
| 2111 | * If current dai is a tx dai, set sample rate to |
| 2112 | * all the txfe paths that are currently not active |
| 2113 | */ |
| 2114 | if (dai->id == AIF1_CAP) { |
| 2115 | |
| 2116 | tx_state = snd_soc_read(codec, |
| 2117 | SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL); |
| 2118 | |
| 2119 | for (path = 1, shift = 0; |
| 2120 | path <= NUM_DECIMATORS; path++, shift++) { |
| 2121 | |
| 2122 | if (!(tx_state & (1 << shift))) { |
| 2123 | tx_fs_reg = SITAR_A_CDC_TX1_CLK_FS_CTL |
| 2124 | + (BITS_PER_REG*(path-1)); |
| 2125 | snd_soc_update_bits(codec, tx_fs_reg, |
| 2126 | 0x03, tx_fs_rate); |
| 2127 | } |
| 2128 | } |
| 2129 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2130 | switch (params_format(params)) { |
| 2131 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2132 | snd_soc_update_bits(codec, |
| 2133 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2134 | 0x20, 0x20); |
| 2135 | break; |
| 2136 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2137 | snd_soc_update_bits(codec, |
| 2138 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2139 | 0x20, 0x00); |
| 2140 | break; |
| 2141 | default: |
| 2142 | pr_err("invalid format\n"); |
| 2143 | break; |
| 2144 | } |
| 2145 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2146 | 0x03, tx_fs_rate); |
| 2147 | } |
| 2148 | } else { |
| 2149 | sitar->dai[dai->id - 1].rate = params_rate(params); |
| 2150 | } |
| 2151 | |
| 2152 | /** |
| 2153 | * TODO: Need to handle case where same RX chain takes 2 or more inputs |
| 2154 | * with varying sample rates |
| 2155 | */ |
| 2156 | |
| 2157 | /** |
| 2158 | * If current dai is a rx dai, set sample rate to |
| 2159 | * all the rx paths that are currently not active |
| 2160 | */ |
| 2161 | if (dai->id == AIF1_PB) { |
| 2162 | |
| 2163 | rx_state = snd_soc_read(codec, |
| 2164 | SITAR_A_CDC_CLK_RX_B1_CTL); |
| 2165 | |
| 2166 | for (path = 1, shift = 0; |
| 2167 | path <= NUM_INTERPOLATORS; path++, shift++) { |
| 2168 | |
| 2169 | if (!(rx_state & (1 << shift))) { |
| 2170 | rx_fs_reg = SITAR_A_CDC_RX1_B5_CTL |
| 2171 | + (BITS_PER_REG*(path-1)); |
| 2172 | snd_soc_update_bits(codec, rx_fs_reg, |
| 2173 | 0xE0, rx_fs_rate); |
| 2174 | } |
| 2175 | } |
| 2176 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2177 | switch (params_format(params)) { |
| 2178 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2179 | snd_soc_update_bits(codec, |
| 2180 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2181 | 0x20, 0x20); |
| 2182 | break; |
| 2183 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2184 | snd_soc_update_bits(codec, |
| 2185 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2186 | 0x20, 0x00); |
| 2187 | break; |
| 2188 | default: |
| 2189 | pr_err("invalid format\n"); |
| 2190 | break; |
| 2191 | } |
| 2192 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2193 | 0x03, (rx_fs_rate >> 0x05)); |
| 2194 | } |
| 2195 | } else { |
| 2196 | sitar->dai[dai->id - 1].rate = params_rate(params); |
| 2197 | } |
| 2198 | |
| 2199 | return 0; |
| 2200 | } |
| 2201 | |
| 2202 | static struct snd_soc_dai_ops sitar_dai_ops = { |
| 2203 | .startup = sitar_startup, |
| 2204 | .shutdown = sitar_shutdown, |
| 2205 | .hw_params = sitar_hw_params, |
| 2206 | .set_sysclk = sitar_set_dai_sysclk, |
| 2207 | .set_fmt = sitar_set_dai_fmt, |
| 2208 | .set_channel_map = sitar_set_channel_map, |
| 2209 | .get_channel_map = sitar_get_channel_map, |
| 2210 | }; |
| 2211 | |
| 2212 | static struct snd_soc_dai_driver sitar_dai[] = { |
| 2213 | { |
| 2214 | .name = "sitar_rx1", |
| 2215 | .id = AIF1_PB, |
| 2216 | .playback = { |
| 2217 | .stream_name = "AIF1 Playback", |
| 2218 | .rates = WCD9304_RATES, |
| 2219 | .formats = SITAR_FORMATS, |
| 2220 | .rate_max = 48000, |
| 2221 | .rate_min = 8000, |
| 2222 | .channels_min = 1, |
| 2223 | .channels_max = 2, |
| 2224 | }, |
| 2225 | .ops = &sitar_dai_ops, |
| 2226 | }, |
| 2227 | { |
| 2228 | .name = "sitar_tx1", |
| 2229 | .id = AIF1_CAP, |
| 2230 | .capture = { |
| 2231 | .stream_name = "AIF1 Capture", |
| 2232 | .rates = WCD9304_RATES, |
| 2233 | .formats = SITAR_FORMATS, |
| 2234 | .rate_max = 48000, |
| 2235 | .rate_min = 8000, |
| 2236 | .channels_min = 1, |
| 2237 | .channels_max = 2, |
| 2238 | }, |
| 2239 | .ops = &sitar_dai_ops, |
| 2240 | }, |
| 2241 | }; |
| 2242 | |
| 2243 | static int sitar_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 2244 | struct snd_kcontrol *kcontrol, int event) |
| 2245 | { |
| 2246 | struct wcd9xxx *sitar; |
| 2247 | struct snd_soc_codec *codec = w->codec; |
| 2248 | struct sitar_priv *sitar_p = snd_soc_codec_get_drvdata(codec); |
| 2249 | u32 j = 0; |
| 2250 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 2251 | sitar = codec->control_data; |
| 2252 | /* Execute the callback only if interface type is slimbus */ |
| 2253 | if (sitar_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2254 | return 0; |
| 2255 | switch (event) { |
| 2256 | case SND_SOC_DAPM_POST_PMU: |
| 2257 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2258 | if (sitar_dai[j].id == AIF1_CAP) |
| 2259 | continue; |
| 2260 | if (!strncmp(w->sname, |
| 2261 | sitar_dai[j].playback.stream_name, 13)) { |
| 2262 | ++sitar_p->dai[j].ch_act; |
| 2263 | break; |
| 2264 | } |
| 2265 | } |
| 2266 | if (sitar_p->dai[j].ch_act == sitar_p->dai[j].ch_tot) |
| 2267 | wcd9xxx_cfg_slim_sch_rx(sitar, |
| 2268 | sitar_p->dai[j].ch_num, |
| 2269 | sitar_p->dai[j].ch_tot, |
| 2270 | sitar_p->dai[j].rate); |
| 2271 | break; |
| 2272 | case SND_SOC_DAPM_POST_PMD: |
| 2273 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2274 | if (sitar_dai[j].id == AIF1_CAP) |
| 2275 | continue; |
| 2276 | if (!strncmp(w->sname, |
| 2277 | sitar_dai[j].playback.stream_name, 13)) { |
| 2278 | --sitar_p->dai[j].ch_act; |
| 2279 | break; |
| 2280 | } |
| 2281 | } |
| 2282 | if (!sitar_p->dai[j].ch_act) { |
| 2283 | wcd9xxx_close_slim_sch_rx(sitar, |
| 2284 | sitar_p->dai[j].ch_num, |
| 2285 | sitar_p->dai[j].ch_tot); |
| 2286 | sitar_p->dai[j].rate = 0; |
| 2287 | memset(sitar_p->dai[j].ch_num, 0, (sizeof(u32)* |
| 2288 | sitar_p->dai[j].ch_tot)); |
| 2289 | sitar_p->dai[j].ch_tot = 0; |
| 2290 | } |
| 2291 | } |
| 2292 | return 0; |
| 2293 | } |
| 2294 | |
| 2295 | static int sitar_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 2296 | struct snd_kcontrol *kcontrol, int event) |
| 2297 | { |
| 2298 | struct wcd9xxx *sitar; |
| 2299 | struct snd_soc_codec *codec = w->codec; |
| 2300 | struct sitar_priv *sitar_p = snd_soc_codec_get_drvdata(codec); |
| 2301 | /* index to the DAI ID, for now hardcoding */ |
| 2302 | u32 j = 0; |
| 2303 | |
| 2304 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 2305 | sitar = codec->control_data; |
| 2306 | |
| 2307 | /* Execute the callback only if interface type is slimbus */ |
| 2308 | if (sitar_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2309 | return 0; |
| 2310 | switch (event) { |
| 2311 | case SND_SOC_DAPM_POST_PMU: |
| 2312 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2313 | if (sitar_dai[j].id == AIF1_PB) |
| 2314 | continue; |
| 2315 | if (!strncmp(w->sname, |
| 2316 | sitar_dai[j].capture.stream_name, 13)) { |
| 2317 | ++sitar_p->dai[j].ch_act; |
| 2318 | break; |
| 2319 | } |
| 2320 | } |
| 2321 | if (sitar_p->dai[j].ch_act == sitar_p->dai[j].ch_tot) |
| 2322 | wcd9xxx_cfg_slim_sch_tx(sitar, |
| 2323 | sitar_p->dai[j].ch_num, |
| 2324 | sitar_p->dai[j].ch_tot, |
| 2325 | sitar_p->dai[j].rate); |
| 2326 | break; |
| 2327 | case SND_SOC_DAPM_POST_PMD: |
| 2328 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2329 | if (sitar_dai[j].id == AIF1_PB) |
| 2330 | continue; |
| 2331 | if (!strncmp(w->sname, |
| 2332 | sitar_dai[j].capture.stream_name, 13)) { |
| 2333 | --sitar_p->dai[j].ch_act; |
| 2334 | break; |
| 2335 | } |
| 2336 | } |
| 2337 | if (!sitar_p->dai[j].ch_act) { |
| 2338 | wcd9xxx_close_slim_sch_tx(sitar, |
| 2339 | sitar_p->dai[j].ch_num, |
| 2340 | sitar_p->dai[j].ch_tot); |
| 2341 | sitar_p->dai[j].rate = 0; |
| 2342 | memset(sitar_p->dai[j].ch_num, 0, (sizeof(u32)* |
| 2343 | sitar_p->dai[j].ch_tot)); |
| 2344 | sitar_p->dai[j].ch_tot = 0; |
| 2345 | } |
| 2346 | } |
| 2347 | return 0; |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | static short sitar_codec_read_sta_result(struct snd_soc_codec *codec) |
| 2352 | { |
| 2353 | u8 bias_msb, bias_lsb; |
| 2354 | short bias_value; |
| 2355 | |
| 2356 | bias_msb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B3_STATUS); |
| 2357 | bias_lsb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B2_STATUS); |
| 2358 | bias_value = (bias_msb << 8) | bias_lsb; |
| 2359 | return bias_value; |
| 2360 | } |
| 2361 | |
| 2362 | static short sitar_codec_read_dce_result(struct snd_soc_codec *codec) |
| 2363 | { |
| 2364 | u8 bias_msb, bias_lsb; |
| 2365 | short bias_value; |
| 2366 | |
| 2367 | bias_msb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B5_STATUS); |
| 2368 | bias_lsb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B4_STATUS); |
| 2369 | bias_value = (bias_msb << 8) | bias_lsb; |
| 2370 | return bias_value; |
| 2371 | } |
| 2372 | |
| 2373 | static short sitar_codec_measure_micbias_voltage(struct snd_soc_codec *codec, |
| 2374 | int dce) |
| 2375 | { |
| 2376 | short bias_value; |
| 2377 | |
| 2378 | if (dce) { |
| 2379 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 2380 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x4); |
| 2381 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2382 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x4); |
| 2383 | usleep_range(60000, 60000); |
| 2384 | bias_value = sitar_codec_read_dce_result(codec); |
| 2385 | } else { |
| 2386 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 2387 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x2); |
| 2388 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2389 | usleep_range(5000, 5000); |
| 2390 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x2); |
| 2391 | usleep_range(50, 50); |
| 2392 | bias_value = sitar_codec_read_sta_result(codec); |
| 2393 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 2394 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x0); |
| 2395 | } |
| 2396 | |
| 2397 | pr_err("read microphone bias value %x\n", bias_value); |
| 2398 | return bias_value; |
| 2399 | } |
| 2400 | |
| 2401 | static short sitar_codec_setup_hs_polling(struct snd_soc_codec *codec) |
| 2402 | { |
| 2403 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2404 | struct sitar_mbhc_calibration *calibration = sitar->calibration; |
| 2405 | short bias_value; |
| 2406 | u8 cfilt_mode; |
| 2407 | |
| 2408 | if (!calibration) { |
| 2409 | pr_err("Error, no sitar calibration\n"); |
| 2410 | return -ENODEV; |
| 2411 | } |
| 2412 | |
| 2413 | sitar->mbhc_polling_active = true; |
| 2414 | |
| 2415 | if (!sitar->mclk_enabled) { |
| 2416 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_MBHC_MODE); |
| 2417 | sitar_enable_rx_bias(codec, 1); |
| 2418 | sitar_codec_enable_clock_block(codec, 1); |
| 2419 | } |
| 2420 | |
| 2421 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x01); |
| 2422 | |
| 2423 | snd_soc_update_bits(codec, SITAR_A_TX_COM_BIAS, 0xE0, 0xE0); |
| 2424 | |
| 2425 | /* Make sure CFILT is in fast mode, save current mode */ |
| 2426 | cfilt_mode = snd_soc_read(codec, |
| 2427 | sitar->mbhc_bias_regs.cfilt_ctl); |
| 2428 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, |
| 2429 | 0x70, 0x00); |
| 2430 | |
| 2431 | snd_soc_update_bits(codec, |
| 2432 | sitar->mbhc_bias_regs.ctl_reg, 0x1F, 0x16); |
| 2433 | |
| 2434 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2435 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
| 2436 | |
| 2437 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 2438 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x00); |
| 2439 | |
| 2440 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x6, 0x6); |
| 2441 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 2442 | |
| 2443 | sitar_codec_calibrate_hs_polling(codec); |
| 2444 | |
| 2445 | bias_value = sitar_codec_measure_micbias_voltage(codec, 0); |
| 2446 | snd_soc_update_bits(codec, |
| 2447 | sitar->mbhc_bias_regs.cfilt_ctl, 0x40, cfilt_mode); |
| 2448 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x13, 0x00); |
| 2449 | |
| 2450 | return bias_value; |
| 2451 | } |
| 2452 | |
| 2453 | static int sitar_codec_enable_hs_detect(struct snd_soc_codec *codec, |
| 2454 | int insertion) |
| 2455 | { |
| 2456 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2457 | struct sitar_mbhc_calibration *calibration = sitar->calibration; |
| 2458 | int central_bias_enabled = 0; |
| 2459 | u8 wg_time; |
| 2460 | |
| 2461 | if (!calibration) { |
| 2462 | pr_err("Error, no sitar calibration\n"); |
| 2463 | return -EINVAL; |
| 2464 | } |
| 2465 | |
| 2466 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 2467 | |
| 2468 | if (insertion) { |
| 2469 | /* Make sure mic bias and Mic line schmitt trigger |
| 2470 | * are turned OFF |
| 2471 | */ |
| 2472 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.ctl_reg, |
| 2473 | 0x81, 0x01); |
| 2474 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.mbhc_reg, |
| 2475 | 0x90, 0x00); |
| 2476 | wg_time = snd_soc_read(codec, SITAR_A_RX_HPH_CNP_WG_TIME) ; |
| 2477 | wg_time += 1; |
| 2478 | |
| 2479 | /* Enable HPH Schmitt Trigger */ |
| 2480 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x11, 0x11); |
| 2481 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x0C, |
| 2482 | calibration->hph_current << 2); |
| 2483 | |
| 2484 | /* Turn off HPH PAs and DAC's during insertion detection to |
| 2485 | * avoid false insertion interrupts |
| 2486 | */ |
| 2487 | if (sitar->mbhc_micbias_switched) |
| 2488 | sitar_codec_switch_micbias(codec, 0); |
| 2489 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 2490 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_L_DAC_CTL, |
| 2491 | 0xC0, 0x00); |
| 2492 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_R_DAC_CTL, |
| 2493 | 0xC0, 0x00); |
| 2494 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 2495 | |
| 2496 | /* setup for insetion detection */ |
| 2497 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x02, 0x02); |
| 2498 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x2, 0); |
| 2499 | } else { |
| 2500 | /* Make sure the HPH schmitt trigger is OFF */ |
| 2501 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x12, 0x00); |
| 2502 | |
| 2503 | /* enable the mic line schmitt trigger */ |
| 2504 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.mbhc_reg, 0x60, |
| 2505 | calibration->mic_current << 5); |
| 2506 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.mbhc_reg, |
| 2507 | 0x80, 0x80); |
| 2508 | usleep_range(calibration->mic_pid, calibration->mic_pid); |
| 2509 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.mbhc_reg, |
| 2510 | 0x10, 0x10); |
| 2511 | |
| 2512 | /* Setup for low power removal detection */ |
| 2513 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x2, 0x2); |
| 2514 | } |
| 2515 | |
| 2516 | if (snd_soc_read(codec, SITAR_A_CDC_MBHC_B1_CTL) & 0x4) { |
| 2517 | if (!(sitar->clock_active)) { |
| 2518 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, |
| 2519 | 0x06, 0); |
| 2520 | usleep_range(calibration->shutdown_plug_removal, |
| 2521 | calibration->shutdown_plug_removal); |
| 2522 | } else |
| 2523 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, |
| 2524 | 0x06, 0); |
| 2525 | } |
| 2526 | |
| 2527 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.int_rbias, 0x80, 0); |
| 2528 | |
| 2529 | /* If central bandgap disabled */ |
| 2530 | if (!(snd_soc_read(codec, SITAR_A_PIN_CTL_OE1) & 1)) { |
| 2531 | snd_soc_update_bits(codec, SITAR_A_PIN_CTL_OE1, 0x3, 0x3); |
| 2532 | usleep_range(calibration->bg_fast_settle, |
| 2533 | calibration->bg_fast_settle); |
| 2534 | central_bias_enabled = 1; |
| 2535 | } |
| 2536 | |
| 2537 | /* If LDO_H disabled */ |
| 2538 | if (snd_soc_read(codec, SITAR_A_PIN_CTL_OE0) & 0x80) { |
| 2539 | snd_soc_update_bits(codec, SITAR_A_PIN_CTL_OE0, 0x10, 0); |
| 2540 | snd_soc_update_bits(codec, SITAR_A_PIN_CTL_OE0, 0x80, 0x80); |
| 2541 | usleep_range(calibration->tldoh, calibration->tldoh); |
| 2542 | snd_soc_update_bits(codec, SITAR_A_PIN_CTL_OE0, 0x80, 0); |
| 2543 | |
| 2544 | if (central_bias_enabled) |
| 2545 | snd_soc_update_bits(codec, SITAR_A_PIN_CTL_OE1, 0x1, 0); |
| 2546 | } |
| 2547 | |
| 2548 | wcd9xxx_enable_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION); |
| 2549 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x1, 0x1); |
| 2550 | return 0; |
| 2551 | } |
| 2552 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2553 | static void btn0_lpress_fn(struct work_struct *work) |
| 2554 | { |
| 2555 | struct delayed_work *delayed_work; |
| 2556 | struct sitar_priv *sitar; |
| 2557 | |
| 2558 | pr_err("%s:\n", __func__); |
| 2559 | |
| 2560 | delayed_work = to_delayed_work(work); |
| 2561 | sitar = container_of(delayed_work, struct sitar_priv, btn0_dwork); |
| 2562 | |
| 2563 | if (sitar) { |
| 2564 | if (sitar->button_jack) { |
| 2565 | pr_err("%s: Reporting long button press event\n", |
| 2566 | __func__); |
| 2567 | sitar_snd_soc_jack_report(sitar, sitar->button_jack, |
| 2568 | SND_JACK_BTN_0, |
| 2569 | SND_JACK_BTN_0); |
| 2570 | } |
| 2571 | } else { |
| 2572 | pr_err("%s: Bad sitar private data\n", __func__); |
| 2573 | } |
| 2574 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | int sitar_hs_detect(struct snd_soc_codec *codec, |
| 2578 | struct snd_soc_jack *headset_jack, struct snd_soc_jack *button_jack, |
| 2579 | struct sitar_mbhc_calibration *calibration) |
| 2580 | { |
| 2581 | struct sitar_priv *sitar; |
| 2582 | int rc; |
| 2583 | |
| 2584 | if (!codec || !calibration) { |
| 2585 | pr_err("Error: no codec or calibration\n"); |
| 2586 | return -EINVAL; |
| 2587 | } |
| 2588 | sitar = snd_soc_codec_get_drvdata(codec); |
| 2589 | sitar->headset_jack = headset_jack; |
| 2590 | sitar->button_jack = button_jack; |
| 2591 | sitar->calibration = calibration; |
| 2592 | sitar_get_mbhc_micbias_regs(codec, &sitar->mbhc_bias_regs); |
| 2593 | |
| 2594 | /* Put CFILT in fast mode by default */ |
| 2595 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, |
| 2596 | 0x40, SITAR_CFILT_FAST_MODE); |
| 2597 | |
| 2598 | INIT_DELAYED_WORK(&sitar->btn0_dwork, btn0_lpress_fn); |
| 2599 | INIT_WORK(&sitar->hphlocp_work, hphlocp_off_report); |
| 2600 | INIT_WORK(&sitar->hphrocp_work, hphrocp_off_report); |
| 2601 | rc = sitar_codec_enable_hs_detect(codec, 1); |
| 2602 | |
| 2603 | if (!IS_ERR_VALUE(rc)) { |
| 2604 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 2605 | 0x10); |
| 2606 | wcd9xxx_enable_irq(codec->control_data, |
| 2607 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 2608 | wcd9xxx_enable_irq(codec->control_data, |
| 2609 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 2610 | } |
| 2611 | |
| 2612 | return rc; |
| 2613 | } |
| 2614 | EXPORT_SYMBOL_GPL(sitar_hs_detect); |
| 2615 | |
| 2616 | static irqreturn_t sitar_dce_handler(int irq, void *data) |
| 2617 | { |
| 2618 | struct sitar_priv *priv = data; |
| 2619 | struct snd_soc_codec *codec = priv->codec; |
| 2620 | short bias_value; |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2621 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2622 | |
| 2623 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL); |
| 2624 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2625 | |
| 2626 | bias_value = sitar_codec_read_dce_result(codec); |
| 2627 | pr_err("%s: button press interrupt, bias value(DCE Read)=%d\n", |
| 2628 | __func__, bias_value); |
| 2629 | |
| 2630 | bias_value = sitar_codec_read_sta_result(codec); |
| 2631 | pr_err("%s: button press interrupt, bias value(STA Read)=%d\n", |
| 2632 | __func__, bias_value); |
| 2633 | /* |
| 2634 | * TODO: If button pressed is not button 0, |
| 2635 | * report the button press event immediately. |
| 2636 | */ |
| 2637 | priv->buttons_pressed |= SND_JACK_BTN_0; |
| 2638 | |
| 2639 | msleep(100); |
| 2640 | |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2641 | wcd9xxx_lock_sleep(core); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2642 | if (schedule_delayed_work(&priv->btn0_dwork, |
| 2643 | msecs_to_jiffies(400)) == 0) { |
| 2644 | WARN(1, "Button pressed twice without release event\n"); |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2645 | wcd9xxx_unlock_sleep(core); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | return IRQ_HANDLED; |
| 2649 | } |
| 2650 | |
| 2651 | static irqreturn_t sitar_release_handler(int irq, void *data) |
| 2652 | { |
| 2653 | struct sitar_priv *priv = data; |
| 2654 | struct snd_soc_codec *codec = priv->codec; |
| 2655 | int ret, mic_voltage; |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2656 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2657 | |
| 2658 | pr_err("%s\n", __func__); |
| 2659 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2660 | |
| 2661 | mic_voltage = sitar_codec_read_dce_result(codec); |
| 2662 | pr_err("%s: Microphone Voltage on release(DCE Read) = %d\n", |
| 2663 | __func__, mic_voltage); |
| 2664 | |
| 2665 | if (priv->buttons_pressed & SND_JACK_BTN_0) { |
| 2666 | ret = cancel_delayed_work(&priv->btn0_dwork); |
| 2667 | |
| 2668 | if (ret == 0) { |
| 2669 | |
| 2670 | pr_err("%s: Reporting long button release event\n", |
| 2671 | __func__); |
| 2672 | if (priv->button_jack) { |
| 2673 | sitar_snd_soc_jack_report(priv, |
| 2674 | priv->button_jack, 0, |
| 2675 | SND_JACK_BTN_0); |
| 2676 | } |
| 2677 | |
| 2678 | } else { |
| 2679 | /* if scheduled btn0_dwork is canceled from here, |
| 2680 | * we have to unlock from here instead btn0_work */ |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2681 | wcd9xxx_unlock_sleep(core); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2682 | mic_voltage = |
| 2683 | sitar_codec_measure_micbias_voltage(codec, 0); |
| 2684 | pr_err("%s: Mic Voltage on release(new STA) = %d\n", |
| 2685 | __func__, mic_voltage); |
| 2686 | |
| 2687 | if (mic_voltage < -2000 || mic_voltage > -670) { |
| 2688 | pr_err("%s: Fake buttton press interrupt\n", |
| 2689 | __func__); |
| 2690 | } else { |
| 2691 | |
| 2692 | if (priv->button_jack) { |
| 2693 | pr_err("%s:reporting short button press and release\n", |
| 2694 | __func__); |
| 2695 | |
| 2696 | sitar_snd_soc_jack_report(priv, |
| 2697 | priv->button_jack, |
| 2698 | SND_JACK_BTN_0, SND_JACK_BTN_0); |
| 2699 | sitar_snd_soc_jack_report(priv, |
| 2700 | priv->button_jack, |
| 2701 | 0, SND_JACK_BTN_0); |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | priv->buttons_pressed &= ~SND_JACK_BTN_0; |
| 2707 | } |
| 2708 | |
| 2709 | sitar_codec_start_hs_polling(codec); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2710 | return IRQ_HANDLED; |
| 2711 | } |
| 2712 | |
| 2713 | static void sitar_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 2714 | { |
| 2715 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2716 | struct sitar_mbhc_calibration *calibration = sitar->calibration; |
| 2717 | |
| 2718 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2719 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x6, 0x0); |
| 2720 | |
| 2721 | snd_soc_update_bits(codec, |
| 2722 | sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 2723 | usleep_range(calibration->shutdown_plug_removal, |
| 2724 | calibration->shutdown_plug_removal); |
| 2725 | |
| 2726 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0xA, 0x8); |
| 2727 | |
| 2728 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x00); |
| 2729 | } |
| 2730 | |
| 2731 | static void sitar_codec_shutdown_hs_polling(struct snd_soc_codec *codec) |
| 2732 | { |
| 2733 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2734 | |
| 2735 | sitar_codec_shutdown_hs_removal_detect(codec); |
| 2736 | |
| 2737 | if (!sitar->mclk_enabled) { |
| 2738 | snd_soc_update_bits(codec, SITAR_A_TX_COM_BIAS, 0xE0, 0x00); |
| 2739 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_AUDIO_MODE); |
| 2740 | sitar_codec_enable_clock_block(codec, 0); |
| 2741 | } |
| 2742 | |
| 2743 | sitar->mbhc_polling_active = false; |
| 2744 | } |
| 2745 | |
| 2746 | static irqreturn_t sitar_hphl_ocp_irq(int irq, void *data) |
| 2747 | { |
| 2748 | struct sitar_priv *sitar = data; |
| 2749 | struct snd_soc_codec *codec; |
| 2750 | |
| 2751 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 2752 | |
| 2753 | if (sitar) { |
| 2754 | codec = sitar->codec; |
| 2755 | if (sitar->hphlocp_cnt++ < SITAR_OCP_ATTEMPT) { |
| 2756 | pr_info("%s: retry\n", __func__); |
| 2757 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 2758 | 0x00); |
| 2759 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 2760 | 0x10); |
| 2761 | } else { |
| 2762 | wcd9xxx_disable_irq(codec->control_data, |
| 2763 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 2764 | sitar->hphlocp_cnt = 0; |
| 2765 | sitar->hph_status |= SND_JACK_OC_HPHL; |
| 2766 | if (sitar->headset_jack) |
| 2767 | sitar_snd_soc_jack_report(sitar, |
| 2768 | sitar->headset_jack, |
| 2769 | sitar->hph_status, |
| 2770 | SITAR_JACK_MASK); |
| 2771 | } |
| 2772 | } else { |
| 2773 | pr_err("%s: Bad sitar private data\n", __func__); |
| 2774 | } |
| 2775 | |
| 2776 | return IRQ_HANDLED; |
| 2777 | } |
| 2778 | |
| 2779 | static irqreturn_t sitar_hphr_ocp_irq(int irq, void *data) |
| 2780 | { |
| 2781 | struct sitar_priv *sitar = data; |
| 2782 | struct snd_soc_codec *codec; |
| 2783 | |
| 2784 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 2785 | |
| 2786 | if (sitar) { |
| 2787 | codec = sitar->codec; |
| 2788 | if (sitar->hphrocp_cnt++ < SITAR_OCP_ATTEMPT) { |
| 2789 | pr_info("%s: retry\n", __func__); |
| 2790 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 2791 | 0x00); |
| 2792 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 2793 | 0x10); |
| 2794 | } else { |
| 2795 | wcd9xxx_disable_irq(codec->control_data, |
| 2796 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 2797 | sitar->hphrocp_cnt = 0; |
| 2798 | sitar->hph_status |= SND_JACK_OC_HPHR; |
| 2799 | if (sitar->headset_jack) |
| 2800 | sitar_snd_soc_jack_report(sitar, |
| 2801 | sitar->headset_jack, |
| 2802 | sitar->hph_status, |
| 2803 | SITAR_JACK_MASK); |
| 2804 | } |
| 2805 | } else { |
| 2806 | pr_err("%s: Bad sitar private data\n", __func__); |
| 2807 | } |
| 2808 | |
| 2809 | return IRQ_HANDLED; |
| 2810 | } |
| 2811 | |
| 2812 | static void sitar_sync_hph_state(struct sitar_priv *sitar) |
| 2813 | { |
| 2814 | if (test_and_clear_bit(SITAR_HPHR_PA_OFF_ACK, |
| 2815 | &sitar->hph_pa_dac_state)) { |
| 2816 | pr_err("%s: HPHR clear flag and enable PA\n", __func__); |
| 2817 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_CNP_EN, 0x10, |
| 2818 | 1 << 4); |
| 2819 | } |
| 2820 | if (test_and_clear_bit(SITAR_HPHL_PA_OFF_ACK, |
| 2821 | &sitar->hph_pa_dac_state)) { |
| 2822 | pr_err("%s: HPHL clear flag and enable PA\n", __func__); |
| 2823 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_CNP_EN, 0x20, |
| 2824 | 1 << 5); |
| 2825 | } |
| 2826 | |
| 2827 | if (test_and_clear_bit(SITAR_HPHR_DAC_OFF_ACK, |
| 2828 | &sitar->hph_pa_dac_state)) { |
| 2829 | pr_err("%s: HPHR clear flag and enable DAC\n", __func__); |
| 2830 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_R_DAC_CTL, |
| 2831 | 0xC0, 0xC0); |
| 2832 | } |
| 2833 | if (test_and_clear_bit(SITAR_HPHL_DAC_OFF_ACK, |
| 2834 | &sitar->hph_pa_dac_state)) { |
| 2835 | pr_err("%s: HPHL clear flag and enable DAC\n", __func__); |
| 2836 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_L_DAC_CTL, |
| 2837 | 0xC0, 0xC0); |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | static irqreturn_t sitar_hs_insert_irq(int irq, void *data) |
| 2842 | { |
| 2843 | struct sitar_priv *priv = data; |
| 2844 | struct snd_soc_codec *codec = priv->codec; |
| 2845 | int ldo_h_on, micb_cfilt_on; |
| 2846 | short mic_voltage; |
| 2847 | short threshold_no_mic = 0xF7F6; |
| 2848 | short threshold_fake_insert = 0xFD30; |
| 2849 | u8 is_removal; |
| 2850 | |
| 2851 | pr_err("%s\n", __func__); |
| 2852 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2853 | |
| 2854 | is_removal = snd_soc_read(codec, SITAR_A_CDC_MBHC_INT_CTL) & 0x02; |
| 2855 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 2856 | |
| 2857 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 2858 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, |
| 2859 | 0x90, 0x00); |
| 2860 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x13, 0x00); |
| 2861 | |
| 2862 | if (priv->fake_insert_context) { |
| 2863 | pr_err("%s: fake context interrupt, reset insertion\n", |
| 2864 | __func__); |
| 2865 | priv->fake_insert_context = false; |
| 2866 | sitar_codec_shutdown_hs_polling(codec); |
| 2867 | sitar_codec_enable_hs_detect(codec, 1); |
| 2868 | return IRQ_HANDLED; |
| 2869 | } |
| 2870 | |
| 2871 | |
| 2872 | ldo_h_on = snd_soc_read(codec, SITAR_A_LDO_H_MODE_1) & 0x80; |
| 2873 | micb_cfilt_on = snd_soc_read(codec, |
| 2874 | priv->mbhc_bias_regs.cfilt_ctl) & 0x80; |
| 2875 | |
| 2876 | if (!ldo_h_on) |
| 2877 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x80, 0x80); |
| 2878 | if (!micb_cfilt_on) |
| 2879 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl, |
| 2880 | 0x80, 0x80); |
| 2881 | |
| 2882 | usleep_range(priv->calibration->setup_plug_removal_delay, |
| 2883 | priv->calibration->setup_plug_removal_delay); |
| 2884 | |
| 2885 | if (!ldo_h_on) |
| 2886 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x80, 0x0); |
| 2887 | if (!micb_cfilt_on) |
| 2888 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.cfilt_ctl, |
| 2889 | 0x80, 0x0); |
| 2890 | |
| 2891 | if (is_removal) { |
| 2892 | /* |
| 2893 | * If headphone is removed while playback is in progress, |
| 2894 | * it is possible that micbias will be switched to VDDIO. |
| 2895 | */ |
| 2896 | if (priv->mbhc_micbias_switched) |
| 2897 | sitar_codec_switch_micbias(codec, 0); |
| 2898 | priv->hph_status &= ~SND_JACK_HEADPHONE; |
| 2899 | |
| 2900 | /* If headphone PA is on, check if userspace receives |
| 2901 | * removal event to sync-up PA's state */ |
| 2902 | if (sitar_is_hph_pa_on(codec)) { |
| 2903 | set_bit(SITAR_HPHL_PA_OFF_ACK, &priv->hph_pa_dac_state); |
| 2904 | set_bit(SITAR_HPHR_PA_OFF_ACK, &priv->hph_pa_dac_state); |
| 2905 | } |
| 2906 | |
| 2907 | if (sitar_is_hph_dac_on(codec, 1)) |
| 2908 | set_bit(SITAR_HPHL_DAC_OFF_ACK, |
| 2909 | &priv->hph_pa_dac_state); |
| 2910 | if (sitar_is_hph_dac_on(codec, 0)) |
| 2911 | set_bit(SITAR_HPHR_DAC_OFF_ACK, |
| 2912 | &priv->hph_pa_dac_state); |
| 2913 | |
| 2914 | if (priv->headset_jack) { |
| 2915 | pr_err("%s: Reporting removal\n", __func__); |
| 2916 | sitar_snd_soc_jack_report(priv, priv->headset_jack, |
| 2917 | priv->hph_status, |
| 2918 | SITAR_JACK_MASK); |
| 2919 | } |
| 2920 | sitar_codec_shutdown_hs_removal_detect(codec); |
| 2921 | sitar_codec_enable_hs_detect(codec, 1); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2922 | return IRQ_HANDLED; |
| 2923 | } |
| 2924 | |
| 2925 | mic_voltage = sitar_codec_setup_hs_polling(codec); |
| 2926 | |
| 2927 | if (mic_voltage > threshold_fake_insert) { |
| 2928 | pr_err("%s: Fake insertion interrupt, mic_voltage = %x\n", |
| 2929 | __func__, mic_voltage); |
| 2930 | |
| 2931 | /* Disable HPH trigger and enable MIC line trigger */ |
| 2932 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x12, 0x00); |
| 2933 | |
| 2934 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x60, |
| 2935 | priv->calibration->mic_current << 5); |
| 2936 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, |
| 2937 | 0x80, 0x80); |
| 2938 | usleep_range(priv->calibration->mic_pid, |
| 2939 | priv->calibration->mic_pid); |
| 2940 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, |
| 2941 | 0x10, 0x10); |
| 2942 | |
| 2943 | /* Setup for insertion detection */ |
| 2944 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x2, 0); |
| 2945 | priv->fake_insert_context = true; |
| 2946 | wcd9xxx_enable_irq(codec->control_data, |
| 2947 | SITAR_IRQ_MBHC_INSERTION); |
| 2948 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x1, 0x1); |
| 2949 | |
| 2950 | } else if (mic_voltage < threshold_no_mic) { |
| 2951 | pr_err("%s: Headphone Detected, mic_voltage = %x\n", |
| 2952 | __func__, mic_voltage); |
| 2953 | priv->hph_status |= SND_JACK_HEADPHONE; |
| 2954 | if (priv->headset_jack) { |
| 2955 | pr_err("%s: Reporting insertion %d\n", __func__, |
| 2956 | SND_JACK_HEADPHONE); |
| 2957 | sitar_snd_soc_jack_report(priv, priv->headset_jack, |
| 2958 | priv->hph_status, |
| 2959 | SITAR_JACK_MASK); |
| 2960 | } |
| 2961 | sitar_codec_shutdown_hs_polling(codec); |
| 2962 | sitar_codec_enable_hs_detect(codec, 0); |
| 2963 | sitar_sync_hph_state(priv); |
| 2964 | } else { |
| 2965 | pr_err("%s: Headset detected, mic_voltage = %x\n", |
| 2966 | __func__, mic_voltage); |
| 2967 | priv->hph_status |= SND_JACK_HEADSET; |
| 2968 | if (priv->headset_jack) { |
| 2969 | pr_err("%s: Reporting insertion %d\n", __func__, |
| 2970 | SND_JACK_HEADSET); |
| 2971 | sitar_snd_soc_jack_report(priv, priv->headset_jack, |
| 2972 | priv->hph_status, |
| 2973 | SITAR_JACK_MASK); |
| 2974 | } |
| 2975 | sitar_codec_start_hs_polling(codec); |
| 2976 | sitar_sync_hph_state(priv); |
| 2977 | } |
| 2978 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2979 | return IRQ_HANDLED; |
| 2980 | } |
| 2981 | |
| 2982 | static irqreturn_t sitar_hs_remove_irq(int irq, void *data) |
| 2983 | { |
| 2984 | struct sitar_priv *priv = data; |
| 2985 | struct snd_soc_codec *codec = priv->codec; |
| 2986 | short bias_value; |
| 2987 | |
| 2988 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL); |
| 2989 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| 2990 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE); |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2991 | |
| 2992 | usleep_range(priv->calibration->shutdown_plug_removal, |
| 2993 | priv->calibration->shutdown_plug_removal); |
| 2994 | |
| 2995 | bias_value = sitar_codec_measure_micbias_voltage(codec, 1); |
| 2996 | pr_err("removal interrupt, bias value is %d\n", bias_value); |
| 2997 | |
| 2998 | if (bias_value < -90) { |
| 2999 | pr_err("False alarm, headset not actually removed\n"); |
| 3000 | sitar_codec_start_hs_polling(codec); |
| 3001 | } else { |
| 3002 | /* |
| 3003 | * If this removal is not false, first check the micbias |
| 3004 | * switch status and switch it to LDOH if it is already |
| 3005 | * switched to VDDIO. |
| 3006 | */ |
| 3007 | if (priv->mbhc_micbias_switched) |
| 3008 | sitar_codec_switch_micbias(codec, 0); |
| 3009 | priv->hph_status &= ~SND_JACK_HEADSET; |
| 3010 | if (priv->headset_jack) { |
| 3011 | pr_err("%s: Reporting removal\n", __func__); |
| 3012 | sitar_snd_soc_jack_report(priv, priv->headset_jack, 0, |
| 3013 | SITAR_JACK_MASK); |
| 3014 | } |
| 3015 | sitar_codec_shutdown_hs_polling(codec); |
| 3016 | |
| 3017 | sitar_codec_enable_hs_detect(codec, 1); |
| 3018 | } |
| 3019 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3020 | return IRQ_HANDLED; |
| 3021 | } |
| 3022 | |
| 3023 | |
| 3024 | static unsigned long slimbus_value; |
| 3025 | |
| 3026 | static irqreturn_t sitar_slimbus_irq(int irq, void *data) |
| 3027 | { |
| 3028 | struct sitar_priv *priv = data; |
| 3029 | struct snd_soc_codec *codec = priv->codec; |
| 3030 | int i, j; |
| 3031 | u8 val; |
| 3032 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3033 | |
| 3034 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 3035 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
| 3036 | SITAR_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 3037 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
| 3038 | val = wcd9xxx_interface_reg_read(codec->control_data, |
| 3039 | SITAR_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 3040 | if (val & 0x1) |
| 3041 | pr_err_ratelimited("overflow error on port %x," |
| 3042 | " value %x\n", i*8 + j, val); |
| 3043 | if (val & 0x2) |
| 3044 | pr_err_ratelimited("underflow error on port %x," |
| 3045 | " value %x\n", i*8 + j, val); |
| 3046 | } |
| 3047 | wcd9xxx_interface_reg_write(codec->control_data, |
| 3048 | SITAR_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF); |
| 3049 | } |
| 3050 | |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3051 | return IRQ_HANDLED; |
| 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | static int sitar_handle_pdata(struct sitar_priv *sitar) |
| 3056 | { |
| 3057 | struct snd_soc_codec *codec = sitar->codec; |
| 3058 | struct wcd9xxx_pdata *pdata = sitar->pdata; |
| 3059 | int k1, k2, rc = 0; |
| 3060 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 3061 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 3062 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 3063 | u8 flag = pdata->amic_settings.use_pdata; |
| 3064 | u8 i = 0, j = 0; |
| 3065 | u8 val_txfe = 0, value = 0; |
| 3066 | |
| 3067 | if (!pdata) { |
| 3068 | rc = -ENODEV; |
| 3069 | goto done; |
| 3070 | } |
| 3071 | |
| 3072 | /* Make sure settings are correct */ |
| 3073 | if ((pdata->micbias.ldoh_v > SITAR_LDOH_2P85_V) || |
| 3074 | (pdata->micbias.bias1_cfilt_sel > SITAR_CFILT2_SEL) || |
| 3075 | (pdata->micbias.bias2_cfilt_sel > SITAR_CFILT2_SEL)) { |
| 3076 | rc = -EINVAL; |
| 3077 | goto done; |
| 3078 | } |
| 3079 | |
| 3080 | /* figure out k value */ |
| 3081 | k1 = sitar_find_k_value(pdata->micbias.ldoh_v, |
| 3082 | pdata->micbias.cfilt1_mv); |
| 3083 | k2 = sitar_find_k_value(pdata->micbias.ldoh_v, |
| 3084 | pdata->micbias.cfilt2_mv); |
| 3085 | |
| 3086 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2)) { |
| 3087 | rc = -EINVAL; |
| 3088 | goto done; |
| 3089 | } |
| 3090 | |
| 3091 | /* Set voltage level and always use LDO */ |
| 3092 | |
| 3093 | snd_soc_update_bits(codec, SITAR_A_MICB_CFILT_1_VAL, 0xFC, |
| 3094 | (k1 << 2)); |
| 3095 | snd_soc_update_bits(codec, SITAR_A_MICB_CFILT_2_VAL, 0xFC, |
| 3096 | (k2 << 2)); |
| 3097 | |
| 3098 | snd_soc_update_bits(codec, SITAR_A_MICB_1_CTL, 0x60, |
| 3099 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 3100 | snd_soc_update_bits(codec, SITAR_A_MICB_2_CTL, 0x60, |
| 3101 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 3102 | |
| 3103 | for (i = 0; i < 6; j++, i += 2) { |
| 3104 | if (flag & (0x01 << i)) { |
| 3105 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 3106 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 3107 | val_txfe = val_txfe | |
| 3108 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 3109 | snd_soc_update_bits(codec, SITAR_A_TX_1_2_EN + j * 10, |
| 3110 | 0x10, value); |
| 3111 | snd_soc_update_bits(codec, |
| 3112 | SITAR_A_TX_1_2_TEST_EN + j * 10, |
| 3113 | 0x30, val_txfe); |
| 3114 | } |
| 3115 | if (flag & (0x01 << (i + 1))) { |
| 3116 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 3117 | val_txfe = (txfe_bypass & |
| 3118 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 3119 | val_txfe |= (txfe_buff & |
| 3120 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 3121 | snd_soc_update_bits(codec, SITAR_A_TX_1_2_EN + j * 10, |
| 3122 | 0x01, value); |
| 3123 | snd_soc_update_bits(codec, |
| 3124 | SITAR_A_TX_1_2_TEST_EN + j * 10, |
| 3125 | 0x03, val_txfe); |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | if (pdata->ocp.use_pdata) { |
| 3130 | /* not defined in CODEC specification */ |
| 3131 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 3132 | pdata->ocp.hph_ocp_limit == 5) { |
| 3133 | rc = -EINVAL; |
| 3134 | goto done; |
| 3135 | } |
| 3136 | snd_soc_update_bits(codec, SITAR_A_RX_COM_OCP_CTL, |
| 3137 | 0x0F, pdata->ocp.num_attempts); |
| 3138 | snd_soc_write(codec, SITAR_A_RX_COM_OCP_COUNT, |
| 3139 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 3140 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, |
| 3141 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 3142 | } |
| 3143 | done: |
| 3144 | return rc; |
| 3145 | } |
| 3146 | |
| 3147 | static const struct sitar_reg_mask_val sitar_1_1_reg_defaults[] = { |
| 3148 | |
| 3149 | /* Sitar 1.1 MICBIAS changes */ |
| 3150 | SITAR_REG_VAL(SITAR_A_MICB_1_INT_RBIAS, 0x24), |
| 3151 | SITAR_REG_VAL(SITAR_A_MICB_2_INT_RBIAS, 0x24), |
| 3152 | |
| 3153 | /* Sitar 1.1 HPH changes */ |
| 3154 | SITAR_REG_VAL(SITAR_A_RX_HPH_BIAS_PA, 0x57), |
| 3155 | SITAR_REG_VAL(SITAR_A_RX_HPH_BIAS_LDO, 0x56), |
| 3156 | |
| 3157 | /* Sitar 1.1 EAR PA changes */ |
| 3158 | SITAR_REG_VAL(SITAR_A_RX_EAR_BIAS_PA, 0xA6), |
| 3159 | SITAR_REG_VAL(SITAR_A_RX_EAR_GAIN, 0x02), |
| 3160 | SITAR_REG_VAL(SITAR_A_RX_EAR_VCM, 0x03), |
| 3161 | |
| 3162 | /* Sitar 1.1 RX Changes */ |
| 3163 | SITAR_REG_VAL(SITAR_A_CDC_RX1_B5_CTL, 0x78), |
| 3164 | |
| 3165 | /* Sitar 1.1 RX1 and RX2 Changes */ |
| 3166 | SITAR_REG_VAL(SITAR_A_CDC_RX1_B6_CTL, 0x80), |
| 3167 | |
| 3168 | SITAR_REG_VAL(SITAR_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 3169 | |
| 3170 | }; |
| 3171 | |
| 3172 | static void sitar_update_reg_defaults(struct snd_soc_codec *codec) |
| 3173 | { |
| 3174 | u32 i; |
| 3175 | for (i = 0; i < ARRAY_SIZE(sitar_1_1_reg_defaults); i++) |
| 3176 | snd_soc_write(codec, sitar_1_1_reg_defaults[i].reg, |
| 3177 | sitar_1_1_reg_defaults[i].val); |
| 3178 | |
| 3179 | } |
| 3180 | static const struct sitar_reg_mask_val sitar_codec_reg_init_val[] = { |
| 3181 | /* Initialize current threshold to 350MA |
| 3182 | * number of wait and run cycles to 4096 |
| 3183 | */ |
| 3184 | {SITAR_A_RX_HPH_OCP_CTL, 0xF8, 0x60}, |
| 3185 | {SITAR_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
| 3186 | |
| 3187 | {SITAR_A_QFUSE_CTL, 0xFF, 0x03}, |
| 3188 | |
| 3189 | /* Initialize gain registers to use register gain */ |
| 3190 | {SITAR_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 3191 | {SITAR_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 3192 | {SITAR_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 3193 | {SITAR_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 3194 | |
| 3195 | /* Initialize mic biases to differential mode */ |
| 3196 | {SITAR_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 3197 | {SITAR_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 3198 | |
| 3199 | {SITAR_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 3200 | |
| 3201 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 3202 | {SITAR_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x28}, |
| 3203 | {SITAR_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 3204 | {SITAR_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 3205 | {SITAR_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 3206 | {SITAR_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 3207 | |
| 3208 | /* Use 16 bit sample size for RX */ |
| 3209 | {SITAR_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 3210 | {SITAR_A_CDC_CONN_RX_SB_B2_CTL, 0x02, 0x02}, |
| 3211 | |
| 3212 | /*enable HPF filter for TX paths */ |
| 3213 | {SITAR_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 3214 | }; |
| 3215 | |
| 3216 | static void sitar_codec_init_reg(struct snd_soc_codec *codec) |
| 3217 | { |
| 3218 | u32 i; |
| 3219 | |
| 3220 | for (i = 0; i < ARRAY_SIZE(sitar_codec_reg_init_val); i++) |
| 3221 | snd_soc_update_bits(codec, sitar_codec_reg_init_val[i].reg, |
| 3222 | sitar_codec_reg_init_val[i].mask, |
| 3223 | sitar_codec_reg_init_val[i].val); |
| 3224 | } |
| 3225 | |
| 3226 | static int sitar_codec_probe(struct snd_soc_codec *codec) |
| 3227 | { |
| 3228 | struct sitar *control; |
| 3229 | struct sitar_priv *sitar; |
| 3230 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 3231 | int ret = 0; |
| 3232 | int i; |
| 3233 | u8 sitar_version; |
| 3234 | int ch_cnt; |
| 3235 | |
| 3236 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 3237 | control = codec->control_data; |
| 3238 | |
| 3239 | sitar = kzalloc(sizeof(struct sitar_priv), GFP_KERNEL); |
| 3240 | if (!sitar) { |
| 3241 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 3242 | return -ENOMEM; |
| 3243 | } |
| 3244 | |
| 3245 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 3246 | memset(&sitar->mbhc_bias_regs, 0, |
| 3247 | sizeof(struct mbhc_micbias_regs)); |
| 3248 | sitar->cfilt_k_value = 0; |
| 3249 | sitar->mbhc_micbias_switched = false; |
| 3250 | |
| 3251 | snd_soc_codec_set_drvdata(codec, sitar); |
| 3252 | |
| 3253 | sitar->mclk_enabled = false; |
| 3254 | sitar->bandgap_type = SITAR_BANDGAP_OFF; |
| 3255 | sitar->clock_active = false; |
| 3256 | sitar->config_mode_active = false; |
| 3257 | sitar->mbhc_polling_active = false; |
| 3258 | sitar->fake_insert_context = false; |
| 3259 | sitar->no_mic_headset_override = false; |
| 3260 | sitar->codec = codec; |
| 3261 | sitar->pdata = dev_get_platdata(codec->dev->parent); |
| 3262 | atomic_set(&sitar->pm_cnt, 1); |
| 3263 | init_waitqueue_head(&sitar->pm_wq); |
| 3264 | |
| 3265 | sitar_update_reg_defaults(codec); |
| 3266 | sitar_codec_init_reg(codec); |
| 3267 | |
| 3268 | ret = sitar_handle_pdata(sitar); |
| 3269 | if (IS_ERR_VALUE(ret)) { |
| 3270 | pr_err("%s: bad pdata\n", __func__); |
| 3271 | goto err_pdata; |
| 3272 | } |
| 3273 | |
| 3274 | snd_soc_add_controls(codec, sitar_snd_controls, |
| 3275 | ARRAY_SIZE(sitar_snd_controls)); |
| 3276 | snd_soc_dapm_new_controls(dapm, sitar_dapm_widgets, |
| 3277 | ARRAY_SIZE(sitar_dapm_widgets)); |
| 3278 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
| 3279 | |
| 3280 | sitar_version = snd_soc_read(codec, WCD9XXX_A_CHIP_VERSION); |
| 3281 | pr_info("%s : Sitar version reg 0x%2x\n", __func__, (u32)sitar_version); |
| 3282 | |
| 3283 | sitar_version &= 0x1F; |
| 3284 | pr_info("%s : Sitar version %u\n", __func__, (u32)sitar_version); |
| 3285 | |
| 3286 | snd_soc_dapm_sync(dapm); |
| 3287 | |
| 3288 | |
| 3289 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION, |
| 3290 | sitar_hs_insert_irq, "Headset insert detect", sitar); |
| 3291 | if (ret) { |
| 3292 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3293 | SITAR_IRQ_MBHC_INSERTION); |
| 3294 | goto err_insert_irq; |
| 3295 | } |
| 3296 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION); |
| 3297 | |
| 3298 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL, |
| 3299 | sitar_hs_remove_irq, "Headset remove detect", sitar); |
| 3300 | if (ret) { |
| 3301 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3302 | SITAR_IRQ_MBHC_REMOVAL); |
| 3303 | goto err_remove_irq; |
| 3304 | } |
| 3305 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL); |
| 3306 | |
| 3307 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL, |
| 3308 | sitar_dce_handler, "DC Estimation detect", sitar); |
| 3309 | if (ret) { |
| 3310 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3311 | SITAR_IRQ_MBHC_POTENTIAL); |
| 3312 | goto err_potential_irq; |
| 3313 | } |
| 3314 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| 3315 | |
| 3316 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE, |
| 3317 | sitar_release_handler, "Button Release detect", sitar); |
| 3318 | if (ret) { |
| 3319 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3320 | SITAR_IRQ_MBHC_RELEASE); |
| 3321 | goto err_release_irq; |
| 3322 | } |
| 3323 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE); |
| 3324 | |
| 3325 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_SLIMBUS, |
| 3326 | sitar_slimbus_irq, "SLIMBUS Slave", sitar); |
| 3327 | if (ret) { |
| 3328 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3329 | SITAR_IRQ_SLIMBUS); |
| 3330 | goto err_slimbus_irq; |
| 3331 | } |
| 3332 | |
| 3333 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 3334 | wcd9xxx_interface_reg_write(codec->control_data, |
| 3335 | SITAR_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 3336 | |
| 3337 | |
| 3338 | ret = wcd9xxx_request_irq(codec->control_data, |
| 3339 | SITAR_IRQ_HPH_PA_OCPL_FAULT, sitar_hphl_ocp_irq, |
| 3340 | "HPH_L OCP detect", sitar); |
| 3341 | if (ret) { |
| 3342 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3343 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 3344 | goto err_hphl_ocp_irq; |
| 3345 | } |
| 3346 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 3347 | |
| 3348 | ret = wcd9xxx_request_irq(codec->control_data, |
| 3349 | SITAR_IRQ_HPH_PA_OCPR_FAULT, sitar_hphr_ocp_irq, |
| 3350 | "HPH_R OCP detect", sitar); |
| 3351 | if (ret) { |
| 3352 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 3353 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 3354 | goto err_hphr_ocp_irq; |
| 3355 | } |
| 3356 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 3357 | |
| 3358 | for (i = 0; i < ARRAY_SIZE(sitar_dai); i++) { |
| 3359 | switch (sitar_dai[i].id) { |
| 3360 | case AIF1_PB: |
| 3361 | ch_cnt = sitar_dai[i].playback.channels_max; |
| 3362 | break; |
| 3363 | case AIF1_CAP: |
| 3364 | ch_cnt = sitar_dai[i].capture.channels_max; |
| 3365 | break; |
| 3366 | default: |
| 3367 | continue; |
| 3368 | } |
| 3369 | sitar->dai[i].ch_num = kzalloc((sizeof(unsigned int)* |
| 3370 | ch_cnt), GFP_KERNEL); |
| 3371 | } |
| 3372 | |
| 3373 | #ifdef CONFIG_DEBUG_FS |
| 3374 | debug_sitar_priv = sitar; |
| 3375 | #endif |
| 3376 | |
| 3377 | return ret; |
| 3378 | |
| 3379 | err_hphr_ocp_irq: |
| 3380 | wcd9xxx_free_irq(codec->control_data, |
| 3381 | SITAR_IRQ_HPH_PA_OCPL_FAULT, sitar); |
| 3382 | err_hphl_ocp_irq: |
| 3383 | wcd9xxx_free_irq(codec->control_data, |
| 3384 | SITAR_IRQ_SLIMBUS, sitar); |
| 3385 | err_slimbus_irq: |
| 3386 | wcd9xxx_free_irq(codec->control_data, |
| 3387 | SITAR_IRQ_MBHC_RELEASE, sitar); |
| 3388 | err_release_irq: |
| 3389 | wcd9xxx_free_irq(codec->control_data, |
| 3390 | SITAR_IRQ_MBHC_POTENTIAL, sitar); |
| 3391 | err_potential_irq: |
| 3392 | wcd9xxx_free_irq(codec->control_data, |
| 3393 | SITAR_IRQ_MBHC_REMOVAL, sitar); |
| 3394 | err_remove_irq: |
| 3395 | wcd9xxx_free_irq(codec->control_data, |
| 3396 | SITAR_IRQ_MBHC_INSERTION, sitar); |
| 3397 | err_insert_irq: |
| 3398 | err_pdata: |
| 3399 | kfree(sitar); |
| 3400 | return ret; |
| 3401 | } |
| 3402 | static int sitar_codec_remove(struct snd_soc_codec *codec) |
| 3403 | { |
| 3404 | int i; |
| 3405 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3406 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_SLIMBUS, sitar); |
| 3407 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE, sitar); |
| 3408 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL, sitar); |
| 3409 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL, sitar); |
| 3410 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION, sitar); |
| 3411 | sitar_codec_disable_clock_block(codec); |
| 3412 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_OFF); |
| 3413 | for (i = 0; i < ARRAY_SIZE(sitar_dai); i++) |
| 3414 | kfree(sitar->dai[i].ch_num); |
| 3415 | kfree(sitar); |
| 3416 | return 0; |
| 3417 | } |
| 3418 | static struct snd_soc_codec_driver soc_codec_dev_sitar = { |
| 3419 | .probe = sitar_codec_probe, |
| 3420 | .remove = sitar_codec_remove, |
| 3421 | .read = sitar_read, |
| 3422 | .write = sitar_write, |
| 3423 | |
| 3424 | .readable_register = sitar_readable, |
| 3425 | .volatile_register = sitar_volatile, |
| 3426 | |
| 3427 | .reg_cache_size = SITAR_CACHE_SIZE, |
| 3428 | .reg_cache_default = sitar_reg_defaults, |
| 3429 | .reg_word_size = 1, |
| 3430 | }; |
| 3431 | |
| 3432 | #ifdef CONFIG_DEBUG_FS |
| 3433 | static struct dentry *debugfs_poke; |
| 3434 | |
| 3435 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 3436 | { |
| 3437 | file->private_data = inode->i_private; |
| 3438 | return 0; |
| 3439 | } |
| 3440 | |
| 3441 | static ssize_t codec_debug_write(struct file *filp, |
| 3442 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 3443 | { |
| 3444 | char lbuf[32]; |
| 3445 | char *buf; |
| 3446 | int rc; |
| 3447 | |
| 3448 | if (cnt > sizeof(lbuf) - 1) |
| 3449 | return -EINVAL; |
| 3450 | |
| 3451 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 3452 | if (rc) |
| 3453 | return -EFAULT; |
| 3454 | |
| 3455 | lbuf[cnt] = '\0'; |
| 3456 | buf = (char *)lbuf; |
| 3457 | debug_sitar_priv->no_mic_headset_override = (*strsep(&buf, " ") == '0') |
| 3458 | ? false : true; |
| 3459 | |
| 3460 | return rc; |
| 3461 | } |
| 3462 | |
| 3463 | static const struct file_operations codec_debug_ops = { |
| 3464 | .open = codec_debug_open, |
| 3465 | .write = codec_debug_write, |
| 3466 | }; |
| 3467 | #endif |
| 3468 | |
| 3469 | #ifdef CONFIG_PM |
| 3470 | static int sitar_suspend(struct device *dev) |
| 3471 | { |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 3472 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 3473 | return 0; |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | static int sitar_resume(struct device *dev) |
| 3477 | { |
| Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 3478 | dev_dbg(dev, "%s: system resume\n", __func__); |
| 3479 | return 0; |
| Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | static const struct dev_pm_ops sitar_pm_ops = { |
| 3483 | .suspend = sitar_suspend, |
| 3484 | .resume = sitar_resume, |
| 3485 | }; |
| 3486 | #endif |
| 3487 | |
| 3488 | static int __devinit sitar_probe(struct platform_device *pdev) |
| 3489 | { |
| 3490 | int ret = 0; |
| 3491 | pr_err("%s\n", __func__); |
| 3492 | #ifdef CONFIG_DEBUG_FS |
| 3493 | debugfs_poke = debugfs_create_file("TRRS", |
| 3494 | S_IFREG | S_IRUGO, NULL, (void *) "TRRS", &codec_debug_ops); |
| 3495 | |
| 3496 | #endif |
| 3497 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_sitar, |
| 3498 | sitar_dai, ARRAY_SIZE(sitar_dai)); |
| 3499 | return ret; |
| 3500 | } |
| 3501 | static int __devexit sitar_remove(struct platform_device *pdev) |
| 3502 | { |
| 3503 | snd_soc_unregister_codec(&pdev->dev); |
| 3504 | |
| 3505 | #ifdef CONFIG_DEBUG_FS |
| 3506 | debugfs_remove(debugfs_poke); |
| 3507 | #endif |
| 3508 | return 0; |
| 3509 | } |
| 3510 | static struct platform_driver sitar_codec_driver = { |
| 3511 | .probe = sitar_probe, |
| 3512 | .remove = sitar_remove, |
| 3513 | .driver = { |
| 3514 | .name = "sitar_codec", |
| 3515 | .owner = THIS_MODULE, |
| 3516 | #ifdef CONFIG_PM |
| 3517 | .pm = &sitar_pm_ops, |
| 3518 | #endif |
| 3519 | }, |
| 3520 | }; |
| 3521 | |
| 3522 | static int __init sitar_codec_init(void) |
| 3523 | { |
| 3524 | return platform_driver_register(&sitar_codec_driver); |
| 3525 | } |
| 3526 | |
| 3527 | static void __exit sitar_codec_exit(void) |
| 3528 | { |
| 3529 | platform_driver_unregister(&sitar_codec_driver); |
| 3530 | } |
| 3531 | |
| 3532 | module_init(sitar_codec_init); |
| 3533 | module_exit(sitar_codec_exit); |
| 3534 | |
| 3535 | MODULE_DESCRIPTION("Sitar codec driver"); |
| 3536 | MODULE_VERSION("1.0"); |
| 3537 | MODULE_LICENSE("GPL v2"); |