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> |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/gpio.h> |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 36 | #include <linux/wait.h> |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 37 | #include "wcd9304.h" |
| 38 | |
| 39 | #define WCD9304_RATES (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|\ |
| 40 | SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_48000) |
| 41 | |
| 42 | #define NUM_DECIMATORS 4 |
| 43 | #define NUM_INTERPOLATORS 3 |
| 44 | #define BITS_PER_REG 8 |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 45 | #define SITAR_CFILT_FAST_MODE 0x00 |
| 46 | #define SITAR_CFILT_SLOW_MODE 0x40 |
| 47 | #define MBHC_FW_READ_ATTEMPTS 15 |
| 48 | #define MBHC_FW_READ_TIMEOUT 2000000 |
| 49 | |
| 50 | #define SITAR_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR) |
| 51 | |
| 52 | #define SITAR_I2S_MASTER_MODE_MASK 0x08 |
| 53 | |
| 54 | #define SITAR_OCP_ATTEMPT 1 |
| 55 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 56 | #define AIF1_PB 1 |
| 57 | #define AIF1_CAP 2 |
| 58 | #define NUM_CODEC_DAIS 2 |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 59 | #define SLIM_CLOSE_TIMEOUT 1000 |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 60 | |
| 61 | struct sitar_codec_dai_data { |
| 62 | u32 rate; |
| 63 | u32 *ch_num; |
| 64 | u32 ch_act; |
| 65 | u32 ch_tot; |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 66 | u32 ch_mask; |
| 67 | wait_queue_head_t dai_wait; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 68 | }; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 69 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 70 | #define SITAR_MCLK_RATE_12288KHZ 12288000 |
| 71 | #define SITAR_MCLK_RATE_9600KHZ 9600000 |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 72 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 73 | #define SITAR_FAKE_INS_THRESHOLD_MS 2500 |
| 74 | #define SITAR_FAKE_REMOVAL_MIN_PERIOD_MS 50 |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 75 | #define SITAR_MBHC_BUTTON_MIN 0x8000 |
| 76 | #define SITAR_GPIO_IRQ_DEBOUNCE_TIME_US 5000 |
| 77 | |
| 78 | #define SITAR_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0) |
| 79 | #define SITAR_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0) |
| 80 | |
| 81 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
| 82 | #define SITAR_MBHC_FAKE_INSERT_LOW 10 |
| 83 | #define SITAR_MBHC_FAKE_INSERT_HIGH 80 |
| 84 | #define SITAR_MBHC_FAKE_INSERT_VOLT_DELTA_MV 500 |
| 85 | #define SITAR_HS_DETECT_PLUG_TIME_MS (5 * 1000) |
| 86 | #define SITAR_HS_DETECT_PLUG_INERVAL_MS 100 |
| 87 | #define NUM_ATTEMPTS_TO_REPORT 5 |
| 88 | #define SITAR_MBHC_STATUS_REL_DETECTION 0x0C |
| 89 | #define SITAR_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 200 |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 90 | |
| 91 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 92 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 93 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
| 94 | static struct snd_soc_dai_driver sitar_dai[]; |
| 95 | static int sitar_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 96 | struct snd_kcontrol *kcontrol, int event); |
| 97 | static int sitar_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 98 | struct snd_kcontrol *kcontrol, int event); |
| 99 | |
| 100 | enum sitar_bandgap_type { |
| 101 | SITAR_BANDGAP_OFF = 0, |
| 102 | SITAR_BANDGAP_AUDIO_MODE, |
| 103 | SITAR_BANDGAP_MBHC_MODE, |
| 104 | }; |
| 105 | |
| 106 | struct mbhc_micbias_regs { |
| 107 | u16 cfilt_val; |
| 108 | u16 cfilt_ctl; |
| 109 | u16 mbhc_reg; |
| 110 | u16 int_rbias; |
| 111 | u16 ctl_reg; |
| 112 | u8 cfilt_sel; |
| 113 | }; |
| 114 | |
| 115 | /* Codec supports 2 IIR filters */ |
| 116 | enum { |
| 117 | IIR1 = 0, |
| 118 | IIR2, |
| 119 | IIR_MAX, |
| 120 | }; |
| 121 | /* Codec supports 5 bands */ |
| 122 | enum { |
| 123 | BAND1 = 0, |
| 124 | BAND2, |
| 125 | BAND3, |
| 126 | BAND4, |
| 127 | BAND5, |
| 128 | BAND_MAX, |
| 129 | }; |
| 130 | |
| 131 | /* Flags to track of PA and DAC state. |
| 132 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 133 | * only PA to be turned on without DAC being on. */ |
| 134 | enum sitar_priv_ack_flags { |
| 135 | SITAR_HPHL_PA_OFF_ACK = 0, |
| 136 | SITAR_HPHR_PA_OFF_ACK, |
| 137 | SITAR_HPHL_DAC_OFF_ACK, |
| 138 | SITAR_HPHR_DAC_OFF_ACK |
| 139 | }; |
| 140 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 141 | /* Data used by MBHC */ |
| 142 | struct mbhc_internal_cal_data { |
| 143 | u16 dce_z; |
| 144 | u16 dce_mb; |
| 145 | u16 sta_z; |
| 146 | u16 sta_mb; |
| 147 | u32 t_sta_dce; |
| 148 | u32 t_dce; |
| 149 | u32 t_sta; |
| 150 | u32 micb_mv; |
| 151 | u16 v_ins_hu; |
| 152 | u16 v_ins_h; |
| 153 | u16 v_b1_hu; |
| 154 | u16 v_b1_h; |
| 155 | u16 v_b1_huc; |
| 156 | u16 v_brh; |
| 157 | u16 v_brl; |
| 158 | u16 v_no_mic; |
| 159 | u8 npoll; |
| 160 | u8 nbounce_wait; |
| 161 | }; |
| 162 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 163 | enum sitar_mbhc_plug_type { |
| 164 | PLUG_TYPE_INVALID = -1, |
| 165 | PLUG_TYPE_NONE, |
| 166 | PLUG_TYPE_HEADSET, |
| 167 | PLUG_TYPE_HEADPHONE, |
| 168 | PLUG_TYPE_HIGH_HPH, |
| 169 | }; |
| 170 | |
| 171 | enum sitar_mbhc_state { |
| 172 | MBHC_STATE_NONE = -1, |
| 173 | MBHC_STATE_POTENTIAL, |
| 174 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 175 | MBHC_STATE_RELEASE, |
| 176 | }; |
| 177 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 178 | struct sitar_priv { |
| 179 | struct snd_soc_codec *codec; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 180 | u32 mclk_freq; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 181 | u32 adc_count; |
| 182 | u32 cfilt1_cnt; |
| 183 | u32 cfilt2_cnt; |
| 184 | u32 cfilt3_cnt; |
| 185 | u32 rx_bias_count; |
| 186 | enum sitar_bandgap_type bandgap_type; |
| 187 | bool mclk_enabled; |
| 188 | bool clock_active; |
| 189 | bool config_mode_active; |
| 190 | bool mbhc_polling_active; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 191 | unsigned long mbhc_fake_ins_start; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 192 | int buttons_pressed; |
| 193 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 194 | enum sitar_micbias_num micbias; |
| 195 | /* void* calibration contains: |
| 196 | * struct sitar_mbhc_general_cfg generic; |
| 197 | * struct sitar_mbhc_plug_detect_cfg plug_det; |
| 198 | * struct sitar_mbhc_plug_type_cfg plug_type; |
| 199 | * struct sitar_mbhc_btn_detect_cfg btn_det; |
| 200 | * struct sitar_mbhc_imped_detect_cfg imped_det; |
| 201 | * Note: various size depends on btn_det->num_btn |
| 202 | */ |
| 203 | void *calibration; |
| 204 | struct mbhc_internal_cal_data mbhc_data; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 205 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 206 | struct wcd9xxx_pdata *pdata; |
| 207 | u32 anc_slot; |
| 208 | |
| 209 | bool no_mic_headset_override; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 210 | |
| 211 | struct mbhc_micbias_regs mbhc_bias_regs; |
| 212 | u8 cfilt_k_value; |
| 213 | bool mbhc_micbias_switched; |
| 214 | |
| 215 | /* track PA/DAC state */ |
| 216 | unsigned long hph_pa_dac_state; |
| 217 | |
| 218 | /*track sitar interface type*/ |
| 219 | u8 intf_type; |
| 220 | |
| 221 | u32 hph_status; /* track headhpone status */ |
| 222 | /* define separate work for left and right headphone OCP to avoid |
| 223 | * additional checking on which OCP event to report so no locking |
| 224 | * to ensure synchronization is required |
| 225 | */ |
| 226 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 227 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
| 228 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 229 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 230 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 231 | |
| 232 | /* Callback function to enable MCLK */ |
| 233 | int (*mclk_cb) (struct snd_soc_codec*, int); |
| 234 | |
| 235 | /* Work to perform MBHC Firmware Read */ |
| 236 | struct delayed_work mbhc_firmware_dwork; |
| 237 | const struct firmware *mbhc_fw; |
| 238 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 239 | /* num of slim ports required */ |
| 240 | struct sitar_codec_dai_data dai[NUM_CODEC_DAIS]; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 241 | |
| 242 | /* Currently, only used for mbhc purpose, to protect |
| 243 | * concurrent execution of mbhc threaded irq handlers and |
| 244 | * kill race between DAPM and MBHC.But can serve as a |
| 245 | * general lock to protect codec resource |
| 246 | */ |
| 247 | struct mutex codec_resource_lock; |
| 248 | |
| 249 | struct sitar_mbhc_config mbhc_cfg; |
| 250 | bool in_gpio_handler; |
| 251 | u8 current_plug; |
| 252 | bool lpi_enabled; |
| 253 | enum sitar_mbhc_state mbhc_state; |
| 254 | struct work_struct hs_correct_plug_work; |
| 255 | bool hs_detect_work_stop; |
| 256 | struct delayed_work mbhc_btn_dwork; |
| 257 | unsigned long mbhc_last_resume; /* in jiffies */ |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | #ifdef CONFIG_DEBUG_FS |
| 261 | struct sitar_priv *debug_sitar_priv; |
| 262 | #endif |
| 263 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 264 | static int sitar_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 265 | struct snd_ctl_elem_value *ucontrol) |
| 266 | { |
| 267 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 268 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 269 | ucontrol->value.integer.value[0] = sitar->anc_slot; |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int sitar_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 274 | struct snd_ctl_elem_value *ucontrol) |
| 275 | { |
| 276 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 277 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 278 | sitar->anc_slot = ucontrol->value.integer.value[0]; |
| 279 | return 0; |
| 280 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 281 | |
| 282 | static int sitar_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 283 | struct snd_ctl_elem_value *ucontrol) |
| 284 | { |
| 285 | u8 ear_pa_gain; |
| 286 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 287 | |
| 288 | ear_pa_gain = snd_soc_read(codec, SITAR_A_RX_EAR_GAIN); |
| 289 | |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 290 | ear_pa_gain &= 0xE0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 291 | |
| 292 | if (ear_pa_gain == 0x00) { |
| 293 | ucontrol->value.integer.value[0] = 0; |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 294 | } else if (ear_pa_gain == 0x80) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 295 | ucontrol->value.integer.value[0] = 1; |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 296 | } else if (ear_pa_gain == 0xA0) { |
| 297 | ucontrol->value.integer.value[0] = 2; |
| 298 | } else if (ear_pa_gain == 0xE0) { |
| 299 | ucontrol->value.integer.value[0] = 3; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 300 | } else { |
| 301 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 302 | __func__, ear_pa_gain); |
| 303 | return -EINVAL; |
| 304 | } |
| 305 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 306 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 307 | |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int sitar_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 312 | struct snd_ctl_elem_value *ucontrol) |
| 313 | { |
| 314 | u8 ear_pa_gain; |
| 315 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 316 | |
| 317 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 318 | ucontrol->value.integer.value[0]); |
| 319 | |
| 320 | switch (ucontrol->value.integer.value[0]) { |
| 321 | case 0: |
| 322 | ear_pa_gain = 0x00; |
| 323 | break; |
| 324 | case 1: |
| 325 | ear_pa_gain = 0x80; |
| 326 | break; |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 327 | case 2: |
| 328 | ear_pa_gain = 0xA0; |
| 329 | break; |
| 330 | case 3: |
| 331 | ear_pa_gain = 0xE0; |
| 332 | break; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 333 | default: |
| 334 | return -EINVAL; |
| 335 | } |
| 336 | |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 337 | snd_soc_update_bits(codec, SITAR_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | static int sitar_get_iir_enable_audio_mixer( |
| 342 | struct snd_kcontrol *kcontrol, |
| 343 | struct snd_ctl_elem_value *ucontrol) |
| 344 | { |
| 345 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 346 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 347 | kcontrol->private_value)->reg; |
| 348 | int band_idx = ((struct soc_multi_mixer_control *) |
| 349 | kcontrol->private_value)->shift; |
| 350 | |
| 351 | ucontrol->value.integer.value[0] = |
| 352 | snd_soc_read(codec, (SITAR_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 353 | (1 << band_idx); |
| 354 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 355 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 356 | iir_idx, band_idx, |
| 357 | (uint32_t)ucontrol->value.integer.value[0]); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static int sitar_put_iir_enable_audio_mixer( |
| 362 | struct snd_kcontrol *kcontrol, |
| 363 | struct snd_ctl_elem_value *ucontrol) |
| 364 | { |
| 365 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 366 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 367 | kcontrol->private_value)->reg; |
| 368 | int band_idx = ((struct soc_multi_mixer_control *) |
| 369 | kcontrol->private_value)->shift; |
| 370 | int value = ucontrol->value.integer.value[0]; |
| 371 | |
| 372 | /* Mask first 5 bits, 6-8 are reserved */ |
| 373 | snd_soc_update_bits(codec, (SITAR_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 374 | (1 << band_idx), (value << band_idx)); |
| 375 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 376 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 377 | iir_idx, band_idx, value); |
| 378 | return 0; |
| 379 | } |
| 380 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 381 | int iir_idx, int band_idx, |
| 382 | int coeff_idx) |
| 383 | { |
| 384 | /* Address does not automatically update if reading */ |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 385 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 386 | (SITAR_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 387 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 388 | |
| 389 | /* Mask bits top 2 bits since they are reserved */ |
| 390 | return ((snd_soc_read(codec, |
| 391 | (SITAR_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 392 | (snd_soc_read(codec, |
| 393 | (SITAR_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 394 | (snd_soc_read(codec, |
| 395 | (SITAR_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 396 | (snd_soc_read(codec, |
| 397 | (SITAR_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 398 | 0x3FFFFFFF; |
| 399 | } |
| 400 | |
| 401 | static int sitar_get_iir_band_audio_mixer( |
| 402 | struct snd_kcontrol *kcontrol, |
| 403 | struct snd_ctl_elem_value *ucontrol) |
| 404 | { |
| 405 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 406 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 407 | kcontrol->private_value)->reg; |
| 408 | int band_idx = ((struct soc_multi_mixer_control *) |
| 409 | kcontrol->private_value)->shift; |
| 410 | |
| 411 | ucontrol->value.integer.value[0] = |
| 412 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 413 | ucontrol->value.integer.value[1] = |
| 414 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 415 | ucontrol->value.integer.value[2] = |
| 416 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 417 | ucontrol->value.integer.value[3] = |
| 418 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 419 | ucontrol->value.integer.value[4] = |
| 420 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 421 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 422 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 423 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 424 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 425 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 426 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 427 | __func__, iir_idx, band_idx, |
| 428 | (uint32_t)ucontrol->value.integer.value[0], |
| 429 | __func__, iir_idx, band_idx, |
| 430 | (uint32_t)ucontrol->value.integer.value[1], |
| 431 | __func__, iir_idx, band_idx, |
| 432 | (uint32_t)ucontrol->value.integer.value[2], |
| 433 | __func__, iir_idx, band_idx, |
| 434 | (uint32_t)ucontrol->value.integer.value[3], |
| 435 | __func__, iir_idx, band_idx, |
| 436 | (uint32_t)ucontrol->value.integer.value[4]); |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 441 | int iir_idx, int band_idx, |
| 442 | int coeff_idx, uint32_t value) |
| 443 | { |
| 444 | /* Mask top 3 bits, 6-8 are reserved */ |
| 445 | /* Update address manually each time */ |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 446 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 447 | (SITAR_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 448 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 449 | |
| 450 | /* Mask top 2 bits, 7-8 are reserved */ |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 451 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 452 | (SITAR_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 453 | (value >> 24) & 0x3F); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 454 | |
| 455 | /* Isolate 8bits at a time */ |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 456 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 457 | (SITAR_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 458 | (value >> 16) & 0xFF); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 459 | |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 460 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 461 | (SITAR_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 462 | (value >> 8) & 0xFF); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 463 | |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 464 | snd_soc_write(codec, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 465 | (SITAR_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 466 | value & 0xFF); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static int sitar_put_iir_band_audio_mixer( |
| 470 | struct snd_kcontrol *kcontrol, |
| 471 | struct snd_ctl_elem_value *ucontrol) |
| 472 | { |
| 473 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 474 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 475 | kcontrol->private_value)->reg; |
| 476 | int band_idx = ((struct soc_multi_mixer_control *) |
| 477 | kcontrol->private_value)->shift; |
| 478 | |
| 479 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 480 | ucontrol->value.integer.value[0]); |
| 481 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 482 | ucontrol->value.integer.value[1]); |
| 483 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 484 | ucontrol->value.integer.value[2]); |
| 485 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 486 | ucontrol->value.integer.value[3]); |
| 487 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 488 | ucontrol->value.integer.value[4]); |
| 489 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 490 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 491 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 492 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 493 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 494 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 495 | __func__, iir_idx, band_idx, |
| 496 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 497 | __func__, iir_idx, band_idx, |
| 498 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 499 | __func__, iir_idx, band_idx, |
| 500 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 501 | __func__, iir_idx, band_idx, |
| 502 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 503 | __func__, iir_idx, band_idx, |
| 504 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 505 | return 0; |
| 506 | } |
| 507 | |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 508 | static const char * const sitar_ear_pa_gain_text[] = {"POS_6_DB", |
| 509 | "POS_2_DB", "NEG_2P5_DB", "NEG_12_DB"}; |
| 510 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 511 | static const struct soc_enum sitar_ear_pa_gain_enum[] = { |
Bhalchandra Gajare | 36d82a4 | 2012-06-11 16:09:06 -0700 | [diff] [blame] | 512 | SOC_ENUM_SINGLE_EXT(4, sitar_ear_pa_gain_text), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 513 | }; |
| 514 | |
| 515 | /*cut of frequency for high pass filter*/ |
| 516 | static const char *cf_text[] = { |
| 517 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 518 | }; |
| 519 | |
| 520 | static const struct soc_enum cf_dec1_enum = |
| 521 | SOC_ENUM_SINGLE(SITAR_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 522 | |
| 523 | static const struct soc_enum cf_rxmix1_enum = |
| 524 | SOC_ENUM_SINGLE(SITAR_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 525 | |
| 526 | static const struct snd_kcontrol_new sitar_snd_controls[] = { |
| 527 | |
| 528 | SOC_ENUM_EXT("EAR PA Gain", sitar_ear_pa_gain_enum[0], |
| 529 | sitar_pa_gain_get, sitar_pa_gain_put), |
| 530 | |
| 531 | SOC_SINGLE_TLV("LINEOUT1 Volume", SITAR_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 532 | line_gain), |
| 533 | SOC_SINGLE_TLV("LINEOUT2 Volume", SITAR_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 534 | line_gain), |
| 535 | |
| 536 | SOC_SINGLE_TLV("HPHL Volume", SITAR_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 537 | line_gain), |
| 538 | SOC_SINGLE_TLV("HPHR Volume", SITAR_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 539 | line_gain), |
| 540 | |
| 541 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", SITAR_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 542 | -84, 40, digital_gain), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 543 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", SITAR_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 544 | -84, 40, digital_gain), |
| 545 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", SITAR_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 546 | -84, 40, digital_gain), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 547 | |
| 548 | SOC_SINGLE_S8_TLV("DEC1 Volume", SITAR_A_CDC_TX1_VOL_CTL_GAIN, -84, 40, |
| 549 | digital_gain), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 550 | SOC_SINGLE_S8_TLV("DEC2 Volume", SITAR_A_CDC_TX2_VOL_CTL_GAIN, -84, 40, |
| 551 | digital_gain), |
| 552 | SOC_SINGLE_S8_TLV("DEC3 Volume", SITAR_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 553 | digital_gain), |
| 554 | SOC_SINGLE_S8_TLV("DEC4 Volume", SITAR_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 555 | digital_gain), |
| 556 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 557 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", SITAR_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 558 | 40, digital_gain), |
| 559 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", SITAR_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 560 | 40, digital_gain), |
| 561 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", SITAR_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 562 | 40, digital_gain), |
| 563 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", SITAR_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 564 | 40, digital_gain), |
| 565 | SOC_SINGLE_TLV("ADC1 Volume", SITAR_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 566 | SOC_SINGLE_TLV("ADC2 Volume", SITAR_A_TX_1_2_EN, 1, 3, 0, analog_gain), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 567 | SOC_SINGLE_TLV("ADC3 Volume", SITAR_A_TX_3_EN, 5, 3, 0, analog_gain), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 568 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 569 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, sitar_get_anc_slot, |
| 570 | sitar_put_anc_slot), |
| 571 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 572 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 573 | |
| 574 | SOC_SINGLE("TX1 HPF Switch", SITAR_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 575 | |
| 576 | SOC_SINGLE("RX1 HPF Switch", SITAR_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 577 | |
| 578 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 579 | |
| 580 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 581 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 582 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 583 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 584 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 585 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 586 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 587 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 588 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 589 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 590 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 591 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 592 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 593 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 594 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 595 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 596 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 597 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 598 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 599 | sitar_get_iir_enable_audio_mixer, sitar_put_iir_enable_audio_mixer), |
| 600 | |
| 601 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 602 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 603 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 604 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 605 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 606 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 607 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 608 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 609 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 610 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 611 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 612 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 613 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 614 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 615 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 616 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 617 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 618 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 619 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 620 | sitar_get_iir_band_audio_mixer, sitar_put_iir_band_audio_mixer), |
| 621 | }; |
| 622 | |
| 623 | static const char *rx_mix1_text[] = { |
| 624 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 625 | "RX5" |
| 626 | }; |
| 627 | |
| 628 | static const char *rx_dac1_text[] = { |
| 629 | "ZERO", "RX1", "RX2" |
| 630 | }; |
| 631 | |
| 632 | static const char *rx_dac2_text[] = { |
| 633 | "ZERO", "RX1", |
| 634 | }; |
| 635 | |
| 636 | static const char *rx_dac3_text[] = { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 637 | "ZERO", "RX1", "INV_RX1", "RX2" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 638 | }; |
| 639 | |
| 640 | static const char *rx_dac4_text[] = { |
| 641 | "ZERO", "ON" |
| 642 | }; |
| 643 | |
| 644 | static const char *sb_tx1_mux_text[] = { |
| 645 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 646 | "DEC1" |
| 647 | }; |
| 648 | |
| 649 | static const char *sb_tx2_mux_text[] = { |
| 650 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 651 | "DEC2" |
| 652 | }; |
| 653 | |
| 654 | static const char *sb_tx3_mux_text[] = { |
| 655 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 656 | "DEC3" |
| 657 | }; |
| 658 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 659 | static const char *sb_tx4_mux_text[] = { |
| 660 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 661 | "DEC4" |
| 662 | }; |
| 663 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 664 | static const char *sb_tx5_mux_text[] = { |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 665 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "DEC1", "DEC2", "DEC3", "DEC4" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | static const char *dec1_mux_text[] = { |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 669 | "ZERO", "DMIC1", "ADC1", "ADC2", "ADC3", "MBADC", "DMIC4", "ANC1_FB", |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 670 | }; |
| 671 | |
| 672 | static const char *dec2_mux_text[] = { |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 673 | "ZERO", "DMIC2", "ADC1", "ADC2", "ADC3", "MBADC", "DMIC3", "ANC2_FB", |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 674 | }; |
| 675 | |
| 676 | static const char *dec3_mux_text[] = { |
Bhalchandra Gajare | 9e5a477 | 2012-05-31 12:22:33 -0700 | [diff] [blame] | 677 | "ZERO", "DMIC3", "ADC1", "ADC2", "ADC3", "MBADC", "DMIC2", "DMIC4" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | static const char *dec4_mux_text[] = { |
Bhalchandra Gajare | 9e5a477 | 2012-05-31 12:22:33 -0700 | [diff] [blame] | 681 | "ZERO", "DMIC4", "ADC1", "ADC2", "ADC3", "DMIC3", "DMIC2", "DMIC1" |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 682 | }; |
| 683 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 684 | static const char const *anc_mux_text[] = { |
| 685 | "ZERO", "ADC1", "ADC2", "ADC3", "RSVD1", "RSVD2", "RSVD3", |
| 686 | "MBADC", "RSVD4", "DMIC1", "DMIC2", "DMIC3", "DMIC4" |
| 687 | }; |
| 688 | |
| 689 | static const char const *anc1_fb_mux_text[] = { |
| 690 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 691 | }; |
| 692 | |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 693 | static const char const *iir_inp1_text[] = { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 694 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "ZERO", "ZERO", "ZERO", |
| 695 | "ZERO", "ZERO", "ZERO", "RX1", "RX2", "RX3", "RX4", "RX5", |
| 696 | }; |
| 697 | |
| 698 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 699 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX1_B1_CTL, 0, 10, rx_mix1_text); |
| 700 | |
| 701 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 702 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX1_B1_CTL, 4, 10, rx_mix1_text); |
| 703 | |
| 704 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 705 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX2_B1_CTL, 0, 10, rx_mix1_text); |
| 706 | |
| 707 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 708 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX2_B1_CTL, 4, 10, rx_mix1_text); |
| 709 | |
| 710 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 711 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX3_B1_CTL, 0, 10, rx_mix1_text); |
| 712 | |
| 713 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 714 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_RX3_B1_CTL, 4, 10, rx_mix1_text); |
| 715 | |
| 716 | static const struct soc_enum rx_dac1_enum = |
| 717 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 6, 3, rx_dac1_text); |
| 718 | |
| 719 | static const struct soc_enum rx_dac2_enum = |
| 720 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 4, 2, rx_dac2_text); |
| 721 | |
| 722 | static const struct soc_enum rx_dac3_enum = |
| 723 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 2, 4, rx_dac3_text); |
| 724 | |
| 725 | static const struct soc_enum rx_dac4_enum = |
| 726 | SOC_ENUM_SINGLE(SITAR_A_CDC_TOP_RDAC_DOUT_CTL, 0, 2, rx_dac4_text); |
| 727 | |
| 728 | static const struct soc_enum sb_tx5_mux_enum = |
| 729 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 730 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 731 | static const struct soc_enum sb_tx4_mux_enum = |
| 732 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 733 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 734 | static const struct soc_enum sb_tx3_mux_enum = |
| 735 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 736 | |
| 737 | static const struct soc_enum sb_tx2_mux_enum = |
| 738 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 739 | |
| 740 | static const struct soc_enum sb_tx1_mux_enum = |
| 741 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 742 | |
| 743 | static const struct soc_enum dec1_mux_enum = |
| 744 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 0, 8, dec1_mux_text); |
| 745 | |
| 746 | static const struct soc_enum dec2_mux_enum = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 747 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B1_CTL, 3, 8, dec2_mux_text); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 748 | |
| 749 | static const struct soc_enum dec3_mux_enum = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 750 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B2_CTL, 0, 8, dec3_mux_text); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 751 | |
| 752 | static const struct soc_enum dec4_mux_enum = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 753 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_TX_B2_CTL, 3, 8, dec4_mux_text); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 754 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 755 | static const struct soc_enum anc1_mux_enum = |
| 756 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_ANC_B1_CTL, 0, 13, anc_mux_text); |
| 757 | |
| 758 | static const struct soc_enum anc2_mux_enum = |
| 759 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_ANC_B1_CTL, 4, 13, anc_mux_text); |
| 760 | |
| 761 | static const struct soc_enum anc1_fb_mux_enum = |
| 762 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 763 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 764 | static const struct soc_enum iir1_inp1_mux_enum = |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 765 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_EQ1_B1_CTL, 0, 16, iir_inp1_text); |
| 766 | |
| 767 | static const struct soc_enum iir2_inp1_mux_enum = |
| 768 | SOC_ENUM_SINGLE(SITAR_A_CDC_CONN_EQ2_B1_CTL, 0, 16, iir_inp1_text); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 769 | |
| 770 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 771 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 772 | |
| 773 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 774 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 775 | |
| 776 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 777 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 778 | |
| 779 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 780 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 781 | |
| 782 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 783 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 784 | |
| 785 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 786 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 787 | |
| 788 | static const struct snd_kcontrol_new rx_dac1_mux = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 789 | SOC_DAPM_ENUM("RX DAC1 Mux", rx_dac1_enum); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 790 | |
| 791 | static const struct snd_kcontrol_new rx_dac2_mux = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 792 | SOC_DAPM_ENUM("RX DAC2 Mux", rx_dac2_enum); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 793 | |
| 794 | static const struct snd_kcontrol_new rx_dac3_mux = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 795 | SOC_DAPM_ENUM("RX DAC3 Mux", rx_dac3_enum); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 796 | |
| 797 | static const struct snd_kcontrol_new rx_dac4_mux = |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 798 | SOC_DAPM_ENUM("RX DAC4 Mux", rx_dac4_enum); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 799 | |
| 800 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 801 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 802 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 803 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 804 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 805 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 806 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 807 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 808 | |
| 809 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 810 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 811 | |
| 812 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 813 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 814 | |
| 815 | static const struct snd_kcontrol_new dec1_mux = |
| 816 | SOC_DAPM_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
| 817 | |
| 818 | static const struct snd_kcontrol_new dec2_mux = |
| 819 | SOC_DAPM_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
| 820 | |
| 821 | static const struct snd_kcontrol_new dec3_mux = |
| 822 | SOC_DAPM_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
| 823 | |
| 824 | static const struct snd_kcontrol_new dec4_mux = |
| 825 | SOC_DAPM_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
| 826 | |
| 827 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 828 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 829 | |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 830 | static const struct snd_kcontrol_new iir2_inp1_mux = |
| 831 | SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum); |
| 832 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 833 | static const struct snd_kcontrol_new anc1_mux = |
| 834 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 835 | |
| 836 | static const struct snd_kcontrol_new anc2_mux = |
| 837 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
| 838 | |
| 839 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 840 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
| 841 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 842 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 843 | SOC_DAPM_SINGLE("Switch", SITAR_A_RX_EAR_EN, 5, 1, 0), |
| 844 | }; |
| 845 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 846 | static void sitar_codec_enable_adc_block(struct snd_soc_codec *codec, |
| 847 | int enable) |
| 848 | { |
| 849 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 850 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 851 | pr_debug("%s %d\n", __func__, enable); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 852 | |
| 853 | if (enable) { |
| 854 | sitar->adc_count++; |
Bhalchandra Gajare | 5d260e3 | 2012-07-18 16:30:29 -0700 | [diff] [blame] | 855 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, |
| 856 | 0x02, 0x02); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 857 | } else { |
| 858 | sitar->adc_count--; |
| 859 | if (!sitar->adc_count) { |
| 860 | if (!sitar->mbhc_polling_active) |
Bhalchandra Gajare | 5d260e3 | 2012-07-18 16:30:29 -0700 | [diff] [blame] | 861 | snd_soc_update_bits(codec, |
| 862 | SITAR_A_CDC_CLK_OTHR_CTL, 0xE0, 0x0); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | static int sitar_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 868 | struct snd_kcontrol *kcontrol, int event) |
| 869 | { |
| 870 | struct snd_soc_codec *codec = w->codec; |
| 871 | u16 adc_reg; |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 872 | u8 init_bit_shift; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 873 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 874 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 875 | |
| 876 | if (w->reg == SITAR_A_TX_1_2_EN) |
| 877 | adc_reg = SITAR_A_TX_1_2_TEST_CTL; |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 878 | else if (w->reg == SITAR_A_TX_3_EN) |
| 879 | adc_reg = SITAR_A_TX_3_TEST_CTL; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 880 | else { |
| 881 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 885 | if (w->shift == 3) |
| 886 | init_bit_shift = 6; |
| 887 | else if (w->shift == 7) |
| 888 | init_bit_shift = 7; |
| 889 | else { |
| 890 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 891 | __func__); |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 895 | switch (event) { |
| 896 | case SND_SOC_DAPM_PRE_PMU: |
| 897 | sitar_codec_enable_adc_block(codec, 1); |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 898 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 899 | 1 << init_bit_shift); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 900 | break; |
| 901 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 902 | |
| 903 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 904 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 905 | break; |
| 906 | case SND_SOC_DAPM_POST_PMD: |
| 907 | sitar_codec_enable_adc_block(codec, 0); |
| 908 | break; |
| 909 | } |
| 910 | return 0; |
| 911 | } |
| 912 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 913 | static int sitar_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 914 | struct snd_kcontrol *kcontrol, int event) |
| 915 | { |
| 916 | struct snd_soc_codec *codec = w->codec; |
| 917 | |
| 918 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 919 | |
| 920 | switch (event) { |
| 921 | case SND_SOC_DAPM_PRE_PMU: |
| 922 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 923 | break; |
| 924 | |
| 925 | case SND_SOC_DAPM_POST_PMD: |
| 926 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 927 | break; |
| 928 | } |
| 929 | return 0; |
| 930 | } |
| 931 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 932 | static int sitar_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 933 | struct snd_kcontrol *kcontrol, int event) |
| 934 | { |
| 935 | struct snd_soc_codec *codec = w->codec; |
| 936 | u16 lineout_gain_reg; |
| 937 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 938 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 939 | |
| 940 | switch (w->shift) { |
| 941 | case 0: |
| 942 | lineout_gain_reg = SITAR_A_RX_LINE_1_GAIN; |
| 943 | break; |
| 944 | case 1: |
| 945 | lineout_gain_reg = SITAR_A_RX_LINE_2_GAIN; |
| 946 | break; |
| 947 | default: |
| 948 | pr_err("%s: Error, incorrect lineout register value\n", |
| 949 | __func__); |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | |
| 953 | switch (event) { |
| 954 | case SND_SOC_DAPM_PRE_PMU: |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 955 | snd_soc_update_bits(codec, lineout_gain_reg, 0x10, 0x10); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 956 | break; |
| 957 | case SND_SOC_DAPM_POST_PMU: |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 958 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 959 | __func__, w->name); |
| 960 | usleep_range(16000, 16000); |
| 961 | break; |
| 962 | case SND_SOC_DAPM_POST_PMD: |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 963 | snd_soc_update_bits(codec, lineout_gain_reg, 0x10, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static int sitar_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
| 970 | struct snd_kcontrol *kcontrol, int event) |
| 971 | { |
| 972 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | 37f4ab7 | 2012-04-10 18:52:37 -0700 | [diff] [blame] | 973 | u16 tx_dmic_ctl_reg, tx_mux_ctl_reg; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 974 | u8 dmic_clk_sel, dmic_clk_en; |
| 975 | unsigned int dmic; |
| 976 | int ret; |
| 977 | |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 978 | ret = kstrtouint(strpbrk(w->name, "1234"), 10, &dmic); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 979 | if (ret < 0) { |
| 980 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
| 981 | return -EINVAL; |
| 982 | } |
| 983 | |
| 984 | switch (dmic) { |
| 985 | case 1: |
| 986 | case 2: |
| 987 | dmic_clk_sel = 0x02; |
| 988 | dmic_clk_en = 0x01; |
| 989 | break; |
| 990 | case 3: |
| 991 | case 4: |
| 992 | dmic_clk_sel = 0x08; |
| 993 | dmic_clk_en = 0x04; |
| 994 | break; |
| 995 | |
| 996 | break; |
| 997 | |
| 998 | default: |
| 999 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 1000 | return -EINVAL; |
| 1001 | } |
| 1002 | |
Bhalchandra Gajare | 37f4ab7 | 2012-04-10 18:52:37 -0700 | [diff] [blame] | 1003 | tx_mux_ctl_reg = SITAR_A_CDC_TX1_MUX_CTL + 8 * (dmic - 1); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1004 | tx_dmic_ctl_reg = SITAR_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1); |
| 1005 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1006 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1007 | |
| 1008 | switch (event) { |
| 1009 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | 37f4ab7 | 2012-04-10 18:52:37 -0700 | [diff] [blame] | 1010 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x01, 0x01); |
| 1011 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1012 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 1013 | dmic_clk_sel, dmic_clk_sel); |
| 1014 | |
| 1015 | snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1); |
| 1016 | |
| 1017 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 1018 | dmic_clk_en, dmic_clk_en); |
| 1019 | break; |
| 1020 | case SND_SOC_DAPM_POST_PMD: |
| 1021 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_DMIC_CTL, |
| 1022 | dmic_clk_en, 0); |
Bhalchandra Gajare | 37f4ab7 | 2012-04-10 18:52:37 -0700 | [diff] [blame] | 1023 | |
| 1024 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x01, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 1030 | static int sitar_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 1031 | struct snd_kcontrol *kcontrol, int event) |
| 1032 | { |
| 1033 | struct snd_soc_codec *codec = w->codec; |
| 1034 | const char *filename; |
| 1035 | const struct firmware *fw; |
| 1036 | int i; |
| 1037 | int ret; |
| 1038 | int num_anc_slots; |
| 1039 | struct anc_header *anc_head; |
| 1040 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1041 | u32 anc_writes_size = 0; |
| 1042 | int anc_size_remaining; |
| 1043 | u32 *anc_ptr; |
| 1044 | u16 reg; |
| 1045 | u8 mask, val, old_val; |
| 1046 | |
| 1047 | pr_debug("%s %d\n", __func__, event); |
| 1048 | switch (event) { |
| 1049 | case SND_SOC_DAPM_PRE_PMU: |
| 1050 | |
| 1051 | /* Use the same firmware file as that of WCD9310, |
| 1052 | * since the register sequences are same for |
| 1053 | * WCD9310 and WCD9304 |
| 1054 | */ |
| 1055 | filename = "wcd9310/wcd9310_anc.bin"; |
| 1056 | |
| 1057 | ret = request_firmware(&fw, filename, codec->dev); |
| 1058 | if (ret != 0) { |
| 1059 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 1060 | ret); |
| 1061 | return -ENODEV; |
| 1062 | } |
| 1063 | |
| 1064 | if (fw->size < sizeof(struct anc_header)) { |
| 1065 | dev_err(codec->dev, "Not enough data\n"); |
| 1066 | release_firmware(fw); |
| 1067 | return -ENOMEM; |
| 1068 | } |
| 1069 | |
| 1070 | /* First number is the number of register writes */ |
| 1071 | anc_head = (struct anc_header *)(fw->data); |
| 1072 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 1073 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 1074 | num_anc_slots = anc_head->num_anc_slots; |
| 1075 | |
| 1076 | if (sitar->anc_slot >= num_anc_slots) { |
| 1077 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 1078 | release_firmware(fw); |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | |
| 1082 | for (i = 0; i < num_anc_slots; i++) { |
| 1083 | |
| 1084 | if (anc_size_remaining < SITAR_PACKED_REG_SIZE) { |
| 1085 | dev_err(codec->dev, "Invalid register format\n"); |
| 1086 | release_firmware(fw); |
| 1087 | return -EINVAL; |
| 1088 | } |
| 1089 | anc_writes_size = (u32)(*anc_ptr); |
| 1090 | anc_size_remaining -= sizeof(u32); |
| 1091 | anc_ptr += 1; |
| 1092 | |
| 1093 | if (anc_writes_size * SITAR_PACKED_REG_SIZE |
| 1094 | > anc_size_remaining) { |
| 1095 | dev_err(codec->dev, "Invalid register format\n"); |
| 1096 | release_firmware(fw); |
| 1097 | return -ENOMEM; |
| 1098 | } |
| 1099 | |
| 1100 | if (sitar->anc_slot == i) |
| 1101 | break; |
| 1102 | |
| 1103 | anc_size_remaining -= (anc_writes_size * |
| 1104 | SITAR_PACKED_REG_SIZE); |
| 1105 | anc_ptr += anc_writes_size; |
| 1106 | } |
| 1107 | if (i == num_anc_slots) { |
| 1108 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
| 1109 | release_firmware(fw); |
| 1110 | return -ENOMEM; |
| 1111 | } |
| 1112 | |
| 1113 | for (i = 0; i < anc_writes_size; i++) { |
| 1114 | SITAR_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
| 1115 | mask, val); |
| 1116 | old_val = snd_soc_read(codec, reg); |
| 1117 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 1118 | (val & mask)); |
| 1119 | } |
| 1120 | |
| 1121 | release_firmware(fw); |
| 1122 | |
| 1123 | /* For Sitar, it is required to enable both Feed-forward |
| 1124 | * and Feed back clocks to enable ANC |
| 1125 | */ |
| 1126 | snd_soc_write(codec, SITAR_A_CDC_CLK_ANC_CLK_EN_CTL, 0x0F); |
| 1127 | |
| 1128 | break; |
| 1129 | |
| 1130 | case SND_SOC_DAPM_POST_PMD: |
| 1131 | snd_soc_write(codec, SITAR_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 1132 | snd_soc_write(codec, SITAR_A_CDC_CLK_ANC_CLK_EN_CTL, 0x00); |
| 1133 | break; |
| 1134 | } |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
| 1138 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1139 | static void sitar_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 1140 | { |
| 1141 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1142 | int mbhc_state = sitar->mbhc_state; |
| 1143 | |
| 1144 | pr_debug("%s: enter\n", __func__); |
| 1145 | if (!sitar->mbhc_polling_active) { |
| 1146 | pr_debug("Polling is not active, do not start polling\n"); |
| 1147 | return; |
| 1148 | } |
| 1149 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
| 1150 | |
| 1151 | |
| 1152 | if (!sitar->no_mic_headset_override) { |
| 1153 | if (mbhc_state == MBHC_STATE_POTENTIAL) { |
| 1154 | pr_debug("%s recovering MBHC state macine\n", __func__); |
| 1155 | sitar->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
| 1156 | /* set to max button press threshold */ |
| 1157 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B2_CTL, |
| 1158 | 0x7F); |
| 1159 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B1_CTL, |
| 1160 | 0xFF); |
| 1161 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B4_CTL, |
| 1162 | 0x7F); |
| 1163 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B3_CTL, |
| 1164 | 0xFF); |
| 1165 | /* set to max */ |
| 1166 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B6_CTL, |
| 1167 | 0x7F); |
| 1168 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B5_CTL, |
| 1169 | 0xFF); |
| 1170 | } |
| 1171 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1172 | |
| 1173 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1174 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x1); |
| 1175 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 1176 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x1); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | static void sitar_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 1180 | { |
| 1181 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1182 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1183 | pr_debug("%s: enter\n", __func__); |
| 1184 | if (!sitar->mbhc_polling_active) { |
| 1185 | pr_debug("polling not active, nothing to pause\n"); |
| 1186 | return; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1187 | } |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1188 | |
| 1189 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 1190 | pr_debug("%s: leave\n", __func__); |
| 1191 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | static void sitar_codec_switch_cfilt_mode(struct snd_soc_codec *codec, |
| 1195 | int mode) |
| 1196 | { |
| 1197 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1198 | u8 reg_mode_val, cur_mode_val; |
| 1199 | bool mbhc_was_polling = false; |
| 1200 | |
| 1201 | if (mode) |
| 1202 | reg_mode_val = SITAR_CFILT_FAST_MODE; |
| 1203 | else |
| 1204 | reg_mode_val = SITAR_CFILT_SLOW_MODE; |
| 1205 | |
| 1206 | cur_mode_val = snd_soc_read(codec, |
| 1207 | sitar->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 1208 | |
| 1209 | if (cur_mode_val != reg_mode_val) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1210 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1211 | if (sitar->mbhc_polling_active) { |
| 1212 | sitar_codec_pause_hs_polling(codec); |
| 1213 | mbhc_was_polling = true; |
| 1214 | } |
| 1215 | snd_soc_update_bits(codec, |
| 1216 | sitar->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 1217 | if (mbhc_was_polling) |
| 1218 | sitar_codec_start_hs_polling(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1219 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1220 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1221 | cur_mode_val, reg_mode_val); |
| 1222 | } else { |
| 1223 | pr_err("%s: CFILT Value is already %x\n", |
| 1224 | __func__, cur_mode_val); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | static void sitar_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 1229 | u8 cfilt_sel, int inc) |
| 1230 | { |
| 1231 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1232 | u32 *cfilt_cnt_ptr = NULL; |
| 1233 | u16 micb_cfilt_reg; |
| 1234 | |
| 1235 | switch (cfilt_sel) { |
| 1236 | case SITAR_CFILT1_SEL: |
| 1237 | cfilt_cnt_ptr = &sitar->cfilt1_cnt; |
| 1238 | micb_cfilt_reg = SITAR_A_MICB_CFILT_1_CTL; |
| 1239 | break; |
| 1240 | case SITAR_CFILT2_SEL: |
| 1241 | cfilt_cnt_ptr = &sitar->cfilt2_cnt; |
| 1242 | micb_cfilt_reg = SITAR_A_MICB_CFILT_2_CTL; |
| 1243 | break; |
| 1244 | default: |
| 1245 | return; /* should not happen */ |
| 1246 | } |
| 1247 | |
| 1248 | if (inc) { |
| 1249 | if (!(*cfilt_cnt_ptr)++) { |
| 1250 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 1251 | if (cfilt_sel == sitar->mbhc_bias_regs.cfilt_sel) |
| 1252 | sitar_codec_switch_cfilt_mode(codec, 0); |
| 1253 | |
| 1254 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 1255 | } |
| 1256 | } else { |
| 1257 | /* check if count not zero, decrement |
| 1258 | * then check if zero, go ahead disable cfilter |
| 1259 | */ |
| 1260 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 1261 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 1262 | |
| 1263 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 1264 | if (cfilt_sel == sitar->mbhc_bias_regs.cfilt_sel) |
| 1265 | sitar_codec_switch_cfilt_mode(codec, 1); |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static int sitar_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 1271 | { |
| 1272 | int rc = -EINVAL; |
| 1273 | unsigned min_mv, max_mv; |
| 1274 | |
| 1275 | switch (ldoh_v) { |
| 1276 | case SITAR_LDOH_1P95_V: |
| 1277 | min_mv = 160; |
| 1278 | max_mv = 1800; |
| 1279 | break; |
| 1280 | case SITAR_LDOH_2P35_V: |
| 1281 | min_mv = 200; |
| 1282 | max_mv = 2200; |
| 1283 | break; |
| 1284 | case SITAR_LDOH_2P75_V: |
| 1285 | min_mv = 240; |
| 1286 | max_mv = 2600; |
| 1287 | break; |
| 1288 | case SITAR_LDOH_2P85_V: |
| 1289 | min_mv = 250; |
| 1290 | max_mv = 2700; |
| 1291 | break; |
| 1292 | default: |
| 1293 | goto done; |
| 1294 | } |
| 1295 | |
| 1296 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 1297 | goto done; |
| 1298 | |
| 1299 | for (rc = 4; rc <= 44; rc++) { |
| 1300 | min_mv = max_mv * (rc) / 44; |
| 1301 | if (min_mv >= cfilt_mv) { |
| 1302 | rc -= 4; |
| 1303 | break; |
| 1304 | } |
| 1305 | } |
| 1306 | done: |
| 1307 | return rc; |
| 1308 | } |
| 1309 | |
| 1310 | static bool sitar_is_hph_pa_on(struct snd_soc_codec *codec) |
| 1311 | { |
| 1312 | u8 hph_reg_val = 0; |
| 1313 | hph_reg_val = snd_soc_read(codec, SITAR_A_RX_HPH_CNP_EN); |
| 1314 | |
| 1315 | return (hph_reg_val & 0x30) ? true : false; |
| 1316 | } |
| 1317 | |
| 1318 | static bool sitar_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 1319 | { |
| 1320 | u8 hph_reg_val = 0; |
| 1321 | if (left) |
| 1322 | hph_reg_val = snd_soc_read(codec, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1323 | SITAR_A_RX_HPH_L_DAC_CTL); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1324 | else |
| 1325 | hph_reg_val = snd_soc_read(codec, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1326 | SITAR_A_RX_HPH_R_DAC_CTL); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1327 | |
| 1328 | return (hph_reg_val & 0xC0) ? true : false; |
| 1329 | } |
| 1330 | |
| 1331 | static void sitar_codec_switch_micbias(struct snd_soc_codec *codec, |
| 1332 | int vddio_switch) |
| 1333 | { |
| 1334 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1335 | int cfilt_k_val; |
| 1336 | bool mbhc_was_polling = false; |
| 1337 | |
| 1338 | switch (vddio_switch) { |
| 1339 | case 1: |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1340 | if (sitar->mbhc_micbias_switched == 0 && |
| 1341 | sitar->mbhc_polling_active) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1342 | |
| 1343 | sitar_codec_pause_hs_polling(codec); |
| 1344 | /* Enable Mic Bias switch to VDDIO */ |
| 1345 | sitar->cfilt_k_value = snd_soc_read(codec, |
| 1346 | sitar->mbhc_bias_regs.cfilt_val); |
| 1347 | cfilt_k_val = sitar_find_k_value( |
| 1348 | sitar->pdata->micbias.ldoh_v, 1800); |
| 1349 | snd_soc_update_bits(codec, |
| 1350 | sitar->mbhc_bias_regs.cfilt_val, |
| 1351 | 0xFC, (cfilt_k_val << 2)); |
| 1352 | |
| 1353 | snd_soc_update_bits(codec, |
| 1354 | sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x80); |
| 1355 | snd_soc_update_bits(codec, |
| 1356 | sitar->mbhc_bias_regs.mbhc_reg, 0x10, 0x00); |
| 1357 | sitar_codec_start_hs_polling(codec); |
| 1358 | |
| 1359 | sitar->mbhc_micbias_switched = true; |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1360 | pr_debug("%s: Enabled MBHC Mic bias to VDDIO Switch\n", |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1361 | __func__); |
| 1362 | } |
| 1363 | break; |
| 1364 | |
| 1365 | case 0: |
| 1366 | if (sitar->mbhc_micbias_switched) { |
| 1367 | if (sitar->mbhc_polling_active) { |
| 1368 | sitar_codec_pause_hs_polling(codec); |
| 1369 | mbhc_was_polling = true; |
| 1370 | } |
| 1371 | /* Disable Mic Bias switch to VDDIO */ |
| 1372 | if (sitar->cfilt_k_value != 0) |
| 1373 | snd_soc_update_bits(codec, |
| 1374 | sitar->mbhc_bias_regs.cfilt_val, 0XFC, |
| 1375 | sitar->cfilt_k_value); |
| 1376 | snd_soc_update_bits(codec, |
| 1377 | sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 1378 | snd_soc_update_bits(codec, |
| 1379 | sitar->mbhc_bias_regs.mbhc_reg, 0x10, 0x00); |
| 1380 | |
| 1381 | if (mbhc_was_polling) |
| 1382 | sitar_codec_start_hs_polling(codec); |
| 1383 | |
| 1384 | sitar->mbhc_micbias_switched = false; |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1385 | pr_debug("%s: Disabled MBHC Mic bias to VDDIO Switch\n", |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1386 | __func__); |
| 1387 | } |
| 1388 | break; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | static int sitar_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 1393 | struct snd_kcontrol *kcontrol, int event) |
| 1394 | { |
| 1395 | struct snd_soc_codec *codec = w->codec; |
| 1396 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1397 | u16 micb_int_reg; |
| 1398 | int micb_line; |
| 1399 | u8 cfilt_sel_val = 0; |
| 1400 | char *internal1_text = "Internal1"; |
| 1401 | char *internal2_text = "Internal2"; |
| 1402 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1403 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1404 | switch (w->reg) { |
| 1405 | case SITAR_A_MICB_1_CTL: |
| 1406 | micb_int_reg = SITAR_A_MICB_1_INT_RBIAS; |
| 1407 | cfilt_sel_val = sitar->pdata->micbias.bias1_cfilt_sel; |
| 1408 | micb_line = SITAR_MICBIAS1; |
| 1409 | break; |
| 1410 | case SITAR_A_MICB_2_CTL: |
| 1411 | micb_int_reg = SITAR_A_MICB_2_INT_RBIAS; |
| 1412 | cfilt_sel_val = sitar->pdata->micbias.bias2_cfilt_sel; |
| 1413 | micb_line = SITAR_MICBIAS2; |
| 1414 | break; |
| 1415 | default: |
| 1416 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 1417 | return -EINVAL; |
| 1418 | } |
| 1419 | |
| 1420 | switch (event) { |
| 1421 | case SND_SOC_DAPM_PRE_PMU: |
| 1422 | /* Decide whether to switch the micbias for MBHC */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1423 | if (w->reg == sitar->mbhc_bias_regs.ctl_reg) { |
| 1424 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1425 | sitar_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1426 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
| 1427 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1428 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1429 | snd_soc_update_bits(codec, w->reg, 0x1E, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1430 | sitar_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
| 1431 | |
| 1432 | if (strnstr(w->name, internal1_text, 30)) |
| 1433 | snd_soc_update_bits(codec, micb_int_reg, 0xFF, 0xA4); |
| 1434 | else if (strnstr(w->name, internal2_text, 30)) |
| 1435 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 1436 | break; |
| 1437 | case SND_SOC_DAPM_POST_PMU: |
| 1438 | if (sitar->mbhc_polling_active && |
Bhalchandra Gajare | 9e5a477 | 2012-05-31 12:22:33 -0700 | [diff] [blame] | 1439 | sitar->mbhc_cfg.micbias == micb_line) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1440 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1441 | sitar_codec_pause_hs_polling(codec); |
| 1442 | sitar_codec_start_hs_polling(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1443 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1444 | } |
| 1445 | break; |
| 1446 | case SND_SOC_DAPM_POST_PMD: |
| 1447 | |
| 1448 | if ((w->reg == sitar->mbhc_bias_regs.ctl_reg) |
| 1449 | && sitar_is_hph_pa_on(codec)) |
| 1450 | sitar_codec_switch_micbias(codec, 1); |
| 1451 | |
| 1452 | if (strnstr(w->name, internal1_text, 30)) |
| 1453 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
| 1454 | else if (strnstr(w->name, internal2_text, 30)) |
| 1455 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 1456 | sitar_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
| 1463 | static int sitar_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 1464 | struct snd_kcontrol *kcontrol, int event) |
| 1465 | { |
| 1466 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1467 | u16 dec_reset_reg, gain_reg; |
| 1468 | u8 current_gain; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1469 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1470 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1471 | |
| 1472 | if (w->reg == SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL) |
| 1473 | dec_reset_reg = SITAR_A_CDC_CLK_TX_RESET_B1_CTL; |
| 1474 | else { |
| 1475 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 1476 | return -EINVAL; |
| 1477 | } |
| 1478 | |
| 1479 | switch (event) { |
| 1480 | case SND_SOC_DAPM_PRE_PMU: |
| 1481 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 1482 | 1 << w->shift); |
| 1483 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
| 1484 | break; |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1485 | case SND_SOC_DAPM_POST_PMU: |
| 1486 | /* Reprogram the digital gain after power up of Decimator */ |
| 1487 | gain_reg = SITAR_A_CDC_TX1_VOL_CTL_GAIN + (8 * w->shift); |
| 1488 | current_gain = snd_soc_read(codec, gain_reg); |
| 1489 | snd_soc_write(codec, gain_reg, current_gain); |
| 1490 | break; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1491 | } |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | static int sitar_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
| 1496 | struct snd_kcontrol *kcontrol, int event) |
| 1497 | { |
| 1498 | struct snd_soc_codec *codec = w->codec; |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1499 | u16 gain_reg; |
| 1500 | u8 current_gain; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1501 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1502 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1503 | |
| 1504 | switch (event) { |
| 1505 | case SND_SOC_DAPM_PRE_PMU: |
| 1506 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_RESET_CTL, |
| 1507 | 1 << w->shift, 1 << w->shift); |
| 1508 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_RESET_CTL, |
| 1509 | 1 << w->shift, 0x0); |
| 1510 | break; |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1511 | case SND_SOC_DAPM_POST_PMU: |
| 1512 | /* Reprogram gain after power up interpolator */ |
| 1513 | gain_reg = SITAR_A_CDC_RX1_VOL_CTL_B2_CTL + (8 * w->shift); |
| 1514 | current_gain = snd_soc_read(codec, gain_reg); |
| 1515 | snd_soc_write(codec, gain_reg, current_gain); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1516 | } |
| 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | static int sitar_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 1521 | struct snd_kcontrol *kcontrol, int event) |
| 1522 | { |
| 1523 | switch (event) { |
| 1524 | case SND_SOC_DAPM_POST_PMU: |
| 1525 | case SND_SOC_DAPM_POST_PMD: |
| 1526 | usleep_range(1000, 1000); |
| 1527 | pr_debug("LDO_H\n"); |
| 1528 | break; |
| 1529 | } |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static void sitar_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 1534 | { |
| 1535 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1536 | |
| 1537 | if (enable) { |
| 1538 | sitar->rx_bias_count++; |
| 1539 | if (sitar->rx_bias_count == 1) |
| 1540 | snd_soc_update_bits(codec, SITAR_A_RX_COM_BIAS, |
| 1541 | 0x80, 0x80); |
| 1542 | } else { |
| 1543 | sitar->rx_bias_count--; |
| 1544 | if (!sitar->rx_bias_count) |
| 1545 | snd_soc_update_bits(codec, SITAR_A_RX_COM_BIAS, |
| 1546 | 0x80, 0x00); |
| 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | static int sitar_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 1551 | struct snd_kcontrol *kcontrol, int event) |
| 1552 | { |
| 1553 | struct snd_soc_codec *codec = w->codec; |
| 1554 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1555 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1556 | |
| 1557 | switch (event) { |
| 1558 | case SND_SOC_DAPM_PRE_PMU: |
| 1559 | sitar_enable_rx_bias(codec, 1); |
| 1560 | break; |
| 1561 | case SND_SOC_DAPM_POST_PMD: |
| 1562 | sitar_enable_rx_bias(codec, 0); |
| 1563 | break; |
| 1564 | } |
| 1565 | return 0; |
| 1566 | } |
Bhalchandra Gajare | 6613171 | 2012-05-07 14:12:26 -0700 | [diff] [blame] | 1567 | static int sitar_hph_dac_event(struct snd_soc_dapm_widget *w, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1568 | struct snd_kcontrol *kcontrol, int event) |
| 1569 | { |
| 1570 | struct snd_soc_codec *codec = w->codec; |
| 1571 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1572 | pr_debug("%s %s %d\n", __func__, w->name, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1573 | |
| 1574 | switch (event) { |
| 1575 | case SND_SOC_DAPM_PRE_PMU: |
| 1576 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 1577 | break; |
| 1578 | case SND_SOC_DAPM_POST_PMD: |
| 1579 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 1580 | break; |
| 1581 | } |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | static void sitar_snd_soc_jack_report(struct sitar_priv *sitar, |
| 1586 | struct snd_soc_jack *jack, int status, |
| 1587 | int mask) |
| 1588 | { |
| 1589 | /* XXX: wake_lock_timeout()? */ |
| 1590 | snd_soc_jack_report(jack, status, mask); |
| 1591 | } |
| 1592 | |
| 1593 | static void hphocp_off_report(struct sitar_priv *sitar, |
| 1594 | u32 jack_status, int irq) |
| 1595 | { |
| 1596 | struct snd_soc_codec *codec; |
| 1597 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1598 | if (!sitar) { |
| 1599 | pr_err("%s: Bad sitar private data\n", __func__); |
| 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | pr_info("%s: clear ocp status %x\n", __func__, jack_status); |
| 1604 | codec = sitar->codec; |
| 1605 | if (sitar->hph_status & jack_status) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1606 | sitar->hph_status &= ~jack_status; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1607 | if (sitar->mbhc_cfg.headset_jack) |
| 1608 | sitar_snd_soc_jack_report(sitar, |
| 1609 | sitar->mbhc_cfg.headset_jack, |
| 1610 | sitar->hph_status, |
| 1611 | SITAR_JACK_MASK); |
| 1612 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 1613 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1614 | /* reset retry counter as PA is turned off signifying |
| 1615 | * start of new OCP detection session |
| 1616 | */ |
| 1617 | if (SITAR_IRQ_HPH_PA_OCPL_FAULT) |
| 1618 | sitar->hphlocp_cnt = 0; |
| 1619 | else |
| 1620 | sitar->hphrocp_cnt = 0; |
| 1621 | wcd9xxx_enable_irq(codec->control_data, irq); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | static void hphlocp_off_report(struct work_struct *work) |
| 1626 | { |
| 1627 | struct sitar_priv *sitar = container_of(work, struct sitar_priv, |
| 1628 | hphlocp_work); |
| 1629 | hphocp_off_report(sitar, SND_JACK_OC_HPHL, SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 1630 | } |
| 1631 | |
| 1632 | static void hphrocp_off_report(struct work_struct *work) |
| 1633 | { |
| 1634 | struct sitar_priv *sitar = container_of(work, struct sitar_priv, |
| 1635 | hphrocp_work); |
| 1636 | hphocp_off_report(sitar, SND_JACK_OC_HPHR, SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 1637 | } |
| 1638 | |
| 1639 | static int sitar_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 1640 | struct snd_kcontrol *kcontrol, int event) |
| 1641 | { |
| 1642 | struct snd_soc_codec *codec = w->codec; |
| 1643 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 1644 | u8 mbhc_micb_ctl_val; |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1645 | pr_debug("%s: event = %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1646 | |
| 1647 | switch (event) { |
| 1648 | case SND_SOC_DAPM_PRE_PMU: |
| 1649 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 1650 | sitar->mbhc_bias_regs.ctl_reg); |
| 1651 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1652 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 1653 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1654 | sitar_codec_switch_micbias(codec, 1); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1655 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
| 1656 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1657 | |
| 1658 | break; |
| 1659 | |
| 1660 | case SND_SOC_DAPM_POST_PMD: |
| 1661 | /* schedule work is required because at the time HPH PA DAPM |
| 1662 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 1663 | * would have been locked while snd_soc_jack_report also |
| 1664 | * attempts to acquire same lock. |
| 1665 | */ |
| 1666 | if (w->shift == 5) { |
| 1667 | clear_bit(SITAR_HPHL_PA_OFF_ACK, |
| 1668 | &sitar->hph_pa_dac_state); |
| 1669 | clear_bit(SITAR_HPHL_DAC_OFF_ACK, |
| 1670 | &sitar->hph_pa_dac_state); |
| 1671 | if (sitar->hph_status & SND_JACK_OC_HPHL) |
| 1672 | schedule_work(&sitar->hphlocp_work); |
| 1673 | } else if (w->shift == 4) { |
| 1674 | clear_bit(SITAR_HPHR_PA_OFF_ACK, |
| 1675 | &sitar->hph_pa_dac_state); |
| 1676 | clear_bit(SITAR_HPHR_DAC_OFF_ACK, |
| 1677 | &sitar->hph_pa_dac_state); |
| 1678 | if (sitar->hph_status & SND_JACK_OC_HPHR) |
| 1679 | schedule_work(&sitar->hphrocp_work); |
| 1680 | } |
| 1681 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 1682 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
| 1683 | sitar_codec_switch_micbias(codec, 0); |
| 1684 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1685 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1686 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1687 | w->name); |
| 1688 | usleep_range(10000, 10000); |
| 1689 | |
| 1690 | break; |
| 1691 | } |
| 1692 | return 0; |
| 1693 | } |
| 1694 | |
| 1695 | static void sitar_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
| 1696 | struct mbhc_micbias_regs *micbias_regs) |
| 1697 | { |
| 1698 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1699 | unsigned int cfilt; |
| 1700 | |
Patrick Lai | a5062da | 2012-05-11 17:55:09 -0700 | [diff] [blame] | 1701 | switch (sitar->mbhc_cfg.micbias) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1702 | case SITAR_MICBIAS1: |
| 1703 | cfilt = sitar->pdata->micbias.bias1_cfilt_sel; |
| 1704 | micbias_regs->mbhc_reg = SITAR_A_MICB_1_MBHC; |
| 1705 | micbias_regs->int_rbias = SITAR_A_MICB_1_INT_RBIAS; |
| 1706 | micbias_regs->ctl_reg = SITAR_A_MICB_1_CTL; |
| 1707 | break; |
| 1708 | case SITAR_MICBIAS2: |
| 1709 | cfilt = sitar->pdata->micbias.bias2_cfilt_sel; |
| 1710 | micbias_regs->mbhc_reg = SITAR_A_MICB_2_MBHC; |
| 1711 | micbias_regs->int_rbias = SITAR_A_MICB_2_INT_RBIAS; |
| 1712 | micbias_regs->ctl_reg = SITAR_A_MICB_2_CTL; |
| 1713 | break; |
| 1714 | default: |
| 1715 | /* Should never reach here */ |
| 1716 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | micbias_regs->cfilt_sel = cfilt; |
| 1721 | |
| 1722 | switch (cfilt) { |
| 1723 | case SITAR_CFILT1_SEL: |
| 1724 | micbias_regs->cfilt_val = SITAR_A_MICB_CFILT_1_VAL; |
| 1725 | micbias_regs->cfilt_ctl = SITAR_A_MICB_CFILT_1_CTL; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1726 | sitar->mbhc_data.micb_mv = sitar->pdata->micbias.cfilt1_mv; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1727 | break; |
| 1728 | case SITAR_CFILT2_SEL: |
| 1729 | micbias_regs->cfilt_val = SITAR_A_MICB_CFILT_2_VAL; |
| 1730 | micbias_regs->cfilt_ctl = SITAR_A_MICB_CFILT_2_CTL; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1731 | sitar->mbhc_data.micb_mv = sitar->pdata->micbias.cfilt2_mv; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1732 | break; |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | static int sitar_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 1737 | struct snd_kcontrol *kcontrol, int event) |
| 1738 | { |
| 1739 | struct snd_soc_codec *codec = w->codec; |
| 1740 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 1741 | pr_debug("%s %d\n", __func__, event); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1742 | switch (event) { |
| 1743 | case SND_SOC_DAPM_POST_PMU: |
Bhalchandra Gajare | 2776af1 | 2012-04-27 16:59:39 -0700 | [diff] [blame] | 1744 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 1745 | 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1746 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x01, |
| 1747 | 0x01); |
| 1748 | snd_soc_update_bits(codec, SITAR_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 1749 | usleep_range(200, 200); |
| 1750 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x10, 0x00); |
| 1751 | break; |
| 1752 | case SND_SOC_DAPM_PRE_PMD: |
| 1753 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 1754 | 0x10); |
| 1755 | usleep_range(20, 20); |
| 1756 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x08, 0x08); |
| 1757 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x10, 0x10); |
| 1758 | snd_soc_update_bits(codec, SITAR_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 1759 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_OTHR_CTL, 0x01, |
| 1760 | 0x00); |
| 1761 | snd_soc_update_bits(codec, SITAR_A_CP_STATIC, 0x08, 0x00); |
| 1762 | break; |
| 1763 | } |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
| 1767 | static const struct snd_soc_dapm_widget sitar_dapm_i2s_widgets[] = { |
| 1768 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 1769 | 4, 0, NULL, 0), |
| 1770 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", SITAR_A_CDC_CLK_TX_I2S_CTL, 4, |
| 1771 | 0, NULL, 0), |
| 1772 | }; |
| 1773 | |
| 1774 | static const struct snd_soc_dapm_widget sitar_dapm_widgets[] = { |
| 1775 | /*RX stuff */ |
| 1776 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 1777 | |
| 1778 | SND_SOC_DAPM_PGA("EAR PA", SITAR_A_RX_EAR_EN, 4, 0, NULL, 0), |
| 1779 | SND_SOC_DAPM_MIXER("DAC1", SITAR_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 1780 | ARRAY_SIZE(dac1_switch)), |
| 1781 | SND_SOC_DAPM_SUPPLY("EAR DRIVER", SITAR_A_RX_EAR_EN, 3, 0, NULL, 0), |
| 1782 | SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 1783 | 0, sitar_codec_enable_slimrx, |
| 1784 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1785 | SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 1786 | 0, sitar_codec_enable_slimrx, |
| 1787 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1788 | SND_SOC_DAPM_AIF_IN("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1789 | SND_SOC_DAPM_AIF_IN("SLIM RX4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1790 | SND_SOC_DAPM_AIF_IN("SLIM RX5", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1791 | |
| 1792 | /* Headphone */ |
| 1793 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 1794 | SND_SOC_DAPM_PGA_E("HPHL", SITAR_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 1795 | sitar_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 1796 | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1797 | |
| 1798 | SND_SOC_DAPM_PGA_E("HPHR", SITAR_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 1799 | sitar_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 1800 | SND_SOC_DAPM_POST_PMD), |
| 1801 | |
Bhalchandra Gajare | 6613171 | 2012-05-07 14:12:26 -0700 | [diff] [blame] | 1802 | SND_SOC_DAPM_DAC_E("HPHL DAC", NULL, SITAR_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 1803 | sitar_hph_dac_event, |
| 1804 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1805 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, SITAR_A_RX_HPH_R_DAC_CTL, 7, 0, |
Bhalchandra Gajare | 6613171 | 2012-05-07 14:12:26 -0700 | [diff] [blame] | 1806 | sitar_hph_dac_event, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1807 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1808 | |
| 1809 | /* Speaker */ |
| 1810 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 1811 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 1812 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1813 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, SITAR_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 1814 | , sitar_lineout_dac_event, |
| 1815 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1816 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, SITAR_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 1817 | , sitar_lineout_dac_event, |
| 1818 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1819 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1820 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", SITAR_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 1821 | 0, sitar_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 1822 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1823 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", SITAR_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 1824 | 0, sitar_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 1825 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1826 | |
| 1827 | SND_SOC_DAPM_MIXER_E("RX1 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1828 | 0, sitar_codec_reset_interpolator, |
| 1829 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1830 | SND_SOC_DAPM_MIXER_E("RX2 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1831 | 0, sitar_codec_reset_interpolator, |
| 1832 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1833 | SND_SOC_DAPM_MIXER_E("RX3 MIX1", SITAR_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1834 | 0, sitar_codec_reset_interpolator, |
| 1835 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1836 | |
| 1837 | SND_SOC_DAPM_MUX("DAC1 MUX", SND_SOC_NOPM, 0, 0, |
| 1838 | &rx_dac1_mux), |
| 1839 | SND_SOC_DAPM_MUX("DAC2 MUX", SND_SOC_NOPM, 0, 0, |
| 1840 | &rx_dac2_mux), |
| 1841 | SND_SOC_DAPM_MUX("DAC3 MUX", SND_SOC_NOPM, 0, 0, |
| 1842 | &rx_dac3_mux), |
| 1843 | SND_SOC_DAPM_MUX("DAC4 MUX", SND_SOC_NOPM, 0, 0, |
| 1844 | &rx_dac4_mux), |
| 1845 | |
| 1846 | SND_SOC_DAPM_MIXER("RX1 CHAIN", SITAR_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0), |
| 1847 | SND_SOC_DAPM_MIXER("RX2 CHAIN", SITAR_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0), |
| 1848 | SND_SOC_DAPM_MIXER("RX3 CHAIN", SITAR_A_CDC_RX3_B6_CTL, 5, 0, NULL, 0), |
| 1849 | |
| 1850 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1851 | &rx_mix1_inp1_mux), |
| 1852 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1853 | &rx_mix1_inp2_mux), |
| 1854 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1855 | &rx2_mix1_inp1_mux), |
| 1856 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1857 | &rx2_mix1_inp2_mux), |
| 1858 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 1859 | &rx3_mix1_inp1_mux), |
| 1860 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 1861 | &rx3_mix1_inp2_mux), |
| 1862 | |
| 1863 | SND_SOC_DAPM_SUPPLY("CP", SITAR_A_CP_EN, 0, 0, |
| 1864 | sitar_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 1865 | SND_SOC_DAPM_PRE_PMD), |
| 1866 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 1867 | sitar_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 1868 | SND_SOC_DAPM_POST_PMD), |
| 1869 | |
| 1870 | SND_SOC_DAPM_SUPPLY("LDO_H", SITAR_A_LDO_H_MODE_1, 7, 0, |
| 1871 | sitar_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 1872 | /* TX */ |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1873 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1874 | SND_SOC_DAPM_SUPPLY("CDC_CONN", SITAR_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 1875 | 0), |
| 1876 | SND_SOC_DAPM_INPUT("AMIC1"), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1877 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 1878 | SND_SOC_DAPM_INPUT("AMIC3"), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1879 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SITAR_A_MICB_1_CTL, 7, 0, |
| 1880 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1881 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1882 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SITAR_A_MICB_1_CTL, 7, 0, |
| 1883 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1884 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1885 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1886 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SITAR_A_MICB_2_CTL, 7, 0, |
| 1887 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1888 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1889 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SITAR_A_MICB_2_CTL, 7, 0, |
| 1890 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1891 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1892 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SITAR_A_MICB_2_CTL, 7, 0, |
| 1893 | sitar_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 1894 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1895 | |
| 1896 | SND_SOC_DAPM_ADC_E("ADC1", NULL, SITAR_A_TX_1_2_EN, 7, 0, |
| 1897 | sitar_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 1898 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1899 | SND_SOC_DAPM_ADC_E("ADC2", NULL, SITAR_A_TX_1_2_EN, 3, 0, |
| 1900 | sitar_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 1901 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1902 | SND_SOC_DAPM_ADC_E("ADC3", NULL, SITAR_A_TX_3_EN, 7, 0, |
| 1903 | sitar_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 1904 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1905 | |
| 1906 | SND_SOC_DAPM_MUX_E("DEC1 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1907 | &dec1_mux, sitar_codec_enable_dec, |
| 1908 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1909 | SND_SOC_DAPM_MUX_E("DEC2 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1910 | &dec2_mux, sitar_codec_enable_dec, |
| 1911 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1912 | SND_SOC_DAPM_MUX_E("DEC3 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1913 | &dec3_mux, sitar_codec_enable_dec, |
| 1914 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1915 | SND_SOC_DAPM_MUX_E("DEC4 MUX", SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0, |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 1916 | &dec4_mux, sitar_codec_enable_dec, |
| 1917 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1918 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 1919 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 1920 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 1921 | |
| 1922 | SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1923 | sitar_codec_enable_anc, SND_SOC_DAPM_PRE_PMU | |
| 1924 | SND_SOC_DAPM_POST_PMD), |
| 1925 | |
| 1926 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 1927 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1928 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux), |
| 1929 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux), |
| 1930 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1931 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, 0, 0, &sb_tx4_mux), |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 1932 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1933 | |
| 1934 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1935 | 0, sitar_codec_enable_slimtx, |
| 1936 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1937 | |
| 1938 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1939 | 0, sitar_codec_enable_slimtx, |
| 1940 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1941 | |
| 1942 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1943 | 0, sitar_codec_enable_slimtx, |
| 1944 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1945 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX4", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1946 | 0, sitar_codec_enable_slimtx, |
| 1947 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1948 | |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 1949 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX5", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 1950 | 0, sitar_codec_enable_slimtx, |
| 1951 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1952 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1953 | /* Digital Mic Inputs */ |
| 1954 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 1955 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1956 | SND_SOC_DAPM_POST_PMD), |
| 1957 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 1958 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1959 | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1960 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 1961 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1962 | SND_SOC_DAPM_POST_PMD), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1963 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 1964 | sitar_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 1965 | SND_SOC_DAPM_POST_PMD), |
| 1966 | |
| 1967 | /* Sidetone */ |
| 1968 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 1969 | SND_SOC_DAPM_PGA("IIR1", SITAR_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0), |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 1970 | SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux), |
| 1971 | SND_SOC_DAPM_PGA("IIR2", SITAR_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1972 | |
| 1973 | }; |
| 1974 | |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 1975 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 1976 | {"RX_I2S_CLK", NULL, "CP"}, |
| 1977 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 1978 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 1979 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 1980 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 1981 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 1982 | |
| 1983 | {"SLIM TX1", NULL, "TX_I2S_CLK"}, |
| 1984 | {"SLIM TX2", NULL, "TX_I2S_CLK"}, |
| 1985 | {"SLIM TX3", NULL, "TX_I2S_CLK"}, |
| 1986 | {"SLIM TX4", NULL, "TX_I2S_CLK"}, |
| 1987 | }; |
| 1988 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 1989 | static const struct snd_soc_dapm_route audio_map[] = { |
| 1990 | /* Earpiece (RX MIX1) */ |
| 1991 | {"EAR", NULL, "EAR PA"}, |
| 1992 | {"EAR PA", "NULL", "DAC1"}, |
| 1993 | {"DAC1", "Switch", "DAC1 MUX"}, |
| 1994 | {"DAC1", NULL, "CP"}, |
| 1995 | {"DAC1", NULL, "EAR DRIVER"}, |
| 1996 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 1997 | {"CP", NULL, "RX_BIAS"}, |
| 1998 | |
| 1999 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 2000 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2001 | |
| 2002 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
Bhalchandra Gajare | aca4f5b | 2012-06-13 15:05:15 -0700 | [diff] [blame] | 2003 | {"LINEOUT2 PA", NULL, "CP"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2004 | {"LINEOUT2 PA", NULL, "LINEOUT2 DAC"}, |
| 2005 | {"LINEOUT2 DAC", NULL, "DAC3 MUX"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2006 | |
| 2007 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
Bhalchandra Gajare | aca4f5b | 2012-06-13 15:05:15 -0700 | [diff] [blame] | 2008 | {"LINEOUT2 PA", NULL, "CP"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2009 | {"LINEOUT1 PA", NULL, "LINEOUT1 DAC"}, |
| 2010 | {"LINEOUT1 DAC", NULL, "DAC2 MUX"}, |
| 2011 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 2012 | {"ANC1 FB MUX", "EAR_HPH_L", "RX2 MIX1"}, |
| 2013 | {"ANC1 FB MUX", "EAR_LINE_1", "RX3 MIX1"}, |
| 2014 | {"ANC", NULL, "ANC1 FB MUX"}, |
| 2015 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2016 | |
| 2017 | /* Headset (RX MIX1 and RX MIX2) */ |
| 2018 | {"HEADPHONE", NULL, "HPHL"}, |
| 2019 | {"HEADPHONE", NULL, "HPHR"}, |
| 2020 | |
Patrick Lai | 9b250b7 | 2012-05-24 14:45:57 -0700 | [diff] [blame] | 2021 | {"HPHL DAC", NULL, "CP"}, |
| 2022 | {"HPHR DAC", NULL, "CP"}, |
| 2023 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2024 | {"HPHL", NULL, "HPHL DAC"}, |
Bhalchandra Gajare | 6613171 | 2012-05-07 14:12:26 -0700 | [diff] [blame] | 2025 | {"HPHL DAC", "NULL", "DAC4 MUX"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2026 | {"HPHR", NULL, "HPHR DAC"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2027 | {"HPHR DAC", NULL, "RX3 MIX1"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2028 | |
| 2029 | {"DAC1 MUX", "RX1", "RX1 CHAIN"}, |
| 2030 | {"DAC2 MUX", "RX1", "RX1 CHAIN"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2031 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2032 | {"DAC3 MUX", "RX1", "RX1 CHAIN"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2033 | {"DAC3 MUX", "INV_RX1", "RX1 CHAIN"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2034 | {"DAC3 MUX", "RX2", "RX2 MIX1"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2035 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2036 | {"DAC4 MUX", "ON", "RX2 MIX1"}, |
| 2037 | |
| 2038 | {"RX1 CHAIN", NULL, "RX1 MIX1"}, |
| 2039 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2040 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 2041 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
| 2042 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 2043 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
| 2044 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 2045 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 2046 | |
Bhalchandra Gajare | 160c64a | 2012-06-06 18:31:50 -0700 | [diff] [blame] | 2047 | /* ANC */ |
| 2048 | {"ANC", NULL, "ANC1 MUX"}, |
| 2049 | {"ANC", NULL, "ANC2 MUX"}, |
| 2050 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 2051 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 2052 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 2053 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 2054 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 2055 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 2056 | |
| 2057 | {"ANC", NULL, "CDC_CONN"}, |
| 2058 | |
| 2059 | {"RX2 MIX1", NULL, "ANC"}, |
| 2060 | {"RX3 MIX1", NULL, "ANC"}, |
| 2061 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2062 | /* SLIMBUS Connections */ |
| 2063 | |
| 2064 | /* Slimbus port 5 is non functional in Sitar 1.0 */ |
| 2065 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2066 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2067 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2068 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2069 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2070 | {"RX1 MIX1 INP1", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2071 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2072 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2073 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2074 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2075 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2076 | {"RX1 MIX1 INP2", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2077 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2078 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2079 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2080 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2081 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2082 | {"RX2 MIX1 INP1", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2083 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2084 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2085 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2086 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2087 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2088 | {"RX2 MIX1 INP2", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2089 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 2090 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
| 2091 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 2092 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
| 2093 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2094 | {"RX3 MIX1 INP1", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2095 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 2096 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
| 2097 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 2098 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
| 2099 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2100 | {"RX3 MIX1 INP2", "IIR2", "IIR2"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2101 | |
| 2102 | |
| 2103 | /* TX */ |
| 2104 | {"SLIM TX1", NULL, "SLIM TX1 MUX"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2105 | {"SLIM TX2", NULL, "SLIM TX2 MUX"}, |
| 2106 | {"SLIM TX3", NULL, "SLIM TX3 MUX"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2107 | {"SLIM TX4", NULL, "SLIM TX4 MUX"}, |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 2108 | {"SLIM TX5", NULL, "SLIM TX5 MUX"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2109 | |
| 2110 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
| 2111 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 2112 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2113 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 2114 | {"SLIM TX5 MUX", "DEC1", "DEC1 MUX"}, |
| 2115 | {"SLIM TX5 MUX", "DEC2", "DEC2 MUX"}, |
| 2116 | {"SLIM TX5 MUX", "DEC3", "DEC3 MUX"}, |
| 2117 | {"SLIM TX5 MUX", "DEC4", "DEC4 MUX"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2118 | |
| 2119 | /* Decimator Inputs */ |
| 2120 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
| 2121 | {"DEC1 MUX", "DMIC4", "DMIC4"}, |
| 2122 | {"DEC1 MUX", "ADC1", "ADC1"}, |
| 2123 | {"DEC1 MUX", "ADC2", "ADC2"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2124 | {"DEC1 MUX", "ADC3", "ADC3"}, |
| 2125 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2126 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
| 2127 | {"DEC2 MUX", "DMIC3", "DMIC3"}, |
| 2128 | {"DEC2 MUX", "ADC1", "ADC1"}, |
| 2129 | {"DEC2 MUX", "ADC2", "ADC2"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2130 | {"DEC2 MUX", "ADC3", "ADC3"}, |
| 2131 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2132 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
| 2133 | {"DEC3 MUX", "ADC1", "ADC1"}, |
| 2134 | {"DEC3 MUX", "ADC2", "ADC2"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2135 | {"DEC3 MUX", "ADC3", "ADC3"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2136 | {"DEC3 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | 9e5a477 | 2012-05-31 12:22:33 -0700 | [diff] [blame] | 2137 | {"DEC3 MUX", "DMIC4", "DMIC4"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2138 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2139 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
| 2140 | {"DEC4 MUX", "ADC1", "ADC1"}, |
| 2141 | {"DEC4 MUX", "ADC2", "ADC2"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2142 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2143 | {"DEC4 MUX", "DMIC3", "DMIC3"}, |
| 2144 | {"DEC4 MUX", "DMIC2", "DMIC2"}, |
| 2145 | {"DEC4 MUX", "DMIC1", "DMIC1"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2146 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2147 | |
| 2148 | /* ADC Connections */ |
| 2149 | {"ADC1", NULL, "AMIC1"}, |
| 2150 | {"ADC2", NULL, "AMIC2"}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2151 | {"ADC3", NULL, "AMIC3"}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2152 | |
| 2153 | /* IIR */ |
| 2154 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
| 2155 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
Asish Bhattacharya | a735489 | 2012-05-28 12:49:01 +0530 | [diff] [blame] | 2156 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 2157 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 2158 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 2159 | {"IIR1 INP1 MUX", "RX1", "SLIM RX1"}, |
| 2160 | {"IIR1 INP1 MUX", "RX2", "SLIM RX2"}, |
| 2161 | {"IIR1 INP1 MUX", "RX3", "SLIM RX3"}, |
| 2162 | {"IIR1 INP1 MUX", "RX4", "SLIM RX4"}, |
| 2163 | {"IIR1 INP1 MUX", "RX5", "SLIM RX5"}, |
| 2164 | |
| 2165 | {"IIR2", NULL, "IIR2 INP1 MUX"}, |
| 2166 | {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 2167 | {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 2168 | {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 2169 | {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 2170 | {"IIR2 INP1 MUX", "RX1", "SLIM RX1"}, |
| 2171 | {"IIR2 INP1 MUX", "RX2", "SLIM RX2"}, |
| 2172 | {"IIR2 INP1 MUX", "RX3", "SLIM RX3"}, |
| 2173 | {"IIR2 INP1 MUX", "RX4", "SLIM RX4"}, |
| 2174 | {"IIR2 INP1 MUX", "RX5", "SLIM RX5"}, |
| 2175 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2176 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 2177 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 2178 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 2179 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 2180 | }; |
| 2181 | |
| 2182 | static int sitar_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 2183 | { |
| 2184 | return sitar_reg_readable[reg]; |
| 2185 | } |
| 2186 | |
| 2187 | static int sitar_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 2188 | { |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 2189 | int i; |
| 2190 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2191 | /* Registers lower than 0x100 are top level registers which can be |
| 2192 | * written by the Sitar core driver. |
| 2193 | */ |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2194 | if ((reg >= SITAR_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 2195 | return 1; |
| 2196 | |
| 2197 | /* IIR Coeff registers are not cacheable */ |
| 2198 | if ((reg >= SITAR_A_CDC_IIR1_COEF_B1_CTL) && |
| 2199 | (reg <= SITAR_A_CDC_IIR1_COEF_B5_CTL)) |
| 2200 | return 1; |
| 2201 | |
Bhalchandra Gajare | ddd4510 | 2012-06-13 17:12:34 -0700 | [diff] [blame] | 2202 | for (i = 0; i < NUM_DECIMATORS; i++) { |
| 2203 | if (reg == SITAR_A_CDC_TX1_VOL_CTL_GAIN + (8 * i)) |
| 2204 | return 1; |
| 2205 | } |
| 2206 | |
| 2207 | for (i = 0; i < NUM_INTERPOLATORS; i++) { |
| 2208 | if (reg == SITAR_A_CDC_RX1_VOL_CTL_B2_CTL + (8 * i)) |
| 2209 | return 1; |
| 2210 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2211 | return 0; |
| 2212 | } |
| 2213 | |
| 2214 | #define SITAR_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 2215 | static int sitar_write(struct snd_soc_codec *codec, unsigned int reg, |
| 2216 | unsigned int value) |
| 2217 | { |
| 2218 | int ret; |
| 2219 | |
| 2220 | BUG_ON(reg > SITAR_MAX_REGISTER); |
| 2221 | |
| 2222 | if (!sitar_volatile(codec, reg)) { |
| 2223 | ret = snd_soc_cache_write(codec, reg, value); |
| 2224 | if (ret != 0) |
| 2225 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 2226 | reg, ret); |
| 2227 | } |
| 2228 | |
| 2229 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
| 2230 | } |
| 2231 | static unsigned int sitar_read(struct snd_soc_codec *codec, |
| 2232 | unsigned int reg) |
| 2233 | { |
| 2234 | unsigned int val; |
| 2235 | int ret; |
| 2236 | |
| 2237 | BUG_ON(reg > SITAR_MAX_REGISTER); |
| 2238 | |
| 2239 | if (!sitar_volatile(codec, reg) && sitar_readable(codec, reg) && |
| 2240 | reg < codec->driver->reg_cache_size) { |
| 2241 | ret = snd_soc_cache_read(codec, reg, &val); |
| 2242 | if (ret >= 0) { |
| 2243 | return val; |
| 2244 | } else |
| 2245 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 2246 | reg, ret); |
| 2247 | } |
| 2248 | |
| 2249 | val = wcd9xxx_reg_read(codec->control_data, reg); |
| 2250 | return val; |
| 2251 | } |
| 2252 | |
| 2253 | static void sitar_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 2254 | { |
Bhalchandra Gajare | 03d28d0 | 2012-05-18 17:39:32 -0700 | [diff] [blame] | 2255 | struct wcd9xxx *sitar_core = dev_get_drvdata(codec->dev->parent); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2256 | |
Bhalchandra Gajare | 03d28d0 | 2012-05-18 17:39:32 -0700 | [diff] [blame] | 2257 | if (SITAR_IS_1P0(sitar_core->version)) |
| 2258 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x80, 0x80); |
| 2259 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2260 | snd_soc_update_bits(codec, SITAR_A_BIAS_CURR_CTL_2, 0x0C, 0x08); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2261 | usleep_range(1000, 1000); |
| 2262 | snd_soc_write(codec, SITAR_A_BIAS_REF_CTL, 0x1C); |
| 2263 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2264 | 0x80); |
| 2265 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 2266 | 0x04); |
| 2267 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2268 | 0x01); |
| 2269 | usleep_range(1000, 1000); |
| 2270 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2271 | 0x00); |
| 2272 | } |
| 2273 | |
| 2274 | static void sitar_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 2275 | enum sitar_bandgap_type choice) |
| 2276 | { |
| 2277 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 03d28d0 | 2012-05-18 17:39:32 -0700 | [diff] [blame] | 2278 | struct wcd9xxx *sitar_core = dev_get_drvdata(codec->dev->parent); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2279 | |
| 2280 | /* TODO lock resources accessed by audio streams and threaded |
| 2281 | * interrupt handlers |
| 2282 | */ |
| 2283 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2284 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2285 | sitar->bandgap_type); |
| 2286 | |
| 2287 | if (sitar->bandgap_type == choice) |
| 2288 | return; |
| 2289 | |
| 2290 | if ((sitar->bandgap_type == SITAR_BANDGAP_OFF) && |
| 2291 | (choice == SITAR_BANDGAP_AUDIO_MODE)) { |
| 2292 | sitar_codec_enable_audio_mode_bandgap(codec); |
| 2293 | } else if (choice == SITAR_BANDGAP_MBHC_MODE) { |
Bhalchandra Gajare | 7708ee3 | 2012-05-24 17:37:37 -0700 | [diff] [blame] | 2294 | snd_soc_update_bits(codec, SITAR_A_BIAS_CURR_CTL_2, 0x0C, 0x08); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2295 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 2296 | 0x2); |
| 2297 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2298 | 0x80); |
| 2299 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 2300 | 0x4); |
| 2301 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2302 | 0x1); |
| 2303 | usleep_range(1000, 1000); |
| 2304 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2305 | 0x00); |
| 2306 | } else if ((sitar->bandgap_type == SITAR_BANDGAP_MBHC_MODE) && |
| 2307 | (choice == SITAR_BANDGAP_AUDIO_MODE)) { |
| 2308 | snd_soc_write(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x50); |
| 2309 | usleep_range(100, 100); |
| 2310 | sitar_codec_enable_audio_mode_bandgap(codec); |
| 2311 | } else if (choice == SITAR_BANDGAP_OFF) { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2312 | snd_soc_update_bits(codec, SITAR_A_BIAS_CURR_CTL_2, 0x0C, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2313 | snd_soc_write(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | 03d28d0 | 2012-05-18 17:39:32 -0700 | [diff] [blame] | 2314 | if (SITAR_IS_1P0(sitar_core->version)) |
| 2315 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, |
| 2316 | 0xFF, 0x65); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2317 | usleep_range(1000, 1000); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2318 | } else { |
| 2319 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 2320 | } |
| 2321 | sitar->bandgap_type = choice; |
| 2322 | } |
| 2323 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2324 | static int sitar_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 2325 | int enable) |
| 2326 | { |
| 2327 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2328 | |
| 2329 | if (enable) { |
| 2330 | snd_soc_update_bits(codec, SITAR_A_RC_OSC_FREQ, 0x10, 0); |
| 2331 | snd_soc_write(codec, SITAR_A_BIAS_OSC_BG_CTL, 0x17); |
| 2332 | usleep_range(5, 5); |
| 2333 | snd_soc_update_bits(codec, SITAR_A_RC_OSC_FREQ, 0x80, |
| 2334 | 0x80); |
| 2335 | snd_soc_update_bits(codec, SITAR_A_RC_OSC_TEST, 0x80, |
| 2336 | 0x80); |
| 2337 | usleep_range(10, 10); |
| 2338 | snd_soc_update_bits(codec, SITAR_A_RC_OSC_TEST, 0x80, 0); |
| 2339 | usleep_range(20, 20); |
| 2340 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 2341 | } else { |
| 2342 | snd_soc_update_bits(codec, SITAR_A_BIAS_OSC_BG_CTL, 0x1, |
| 2343 | 0); |
| 2344 | snd_soc_update_bits(codec, SITAR_A_RC_OSC_FREQ, 0x80, 0); |
| 2345 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 2346 | } |
| 2347 | sitar->config_mode_active = enable ? true : false; |
| 2348 | |
| 2349 | return 0; |
| 2350 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2351 | |
| 2352 | static int sitar_codec_enable_clock_block(struct snd_soc_codec *codec, |
| 2353 | int config_mode) |
| 2354 | { |
| 2355 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2356 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2357 | pr_debug("%s\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2358 | |
| 2359 | if (config_mode) { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2360 | sitar_codec_enable_config_mode(codec, 1); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2361 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN2, 0x00); |
| 2362 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN2, 0x02); |
| 2363 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN1, 0x0D); |
| 2364 | usleep_range(1000, 1000); |
| 2365 | } else |
| 2366 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 2367 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2368 | if (!config_mode && sitar->mbhc_polling_active) { |
| 2369 | snd_soc_write(codec, SITAR_A_CLK_BUFF_EN2, 0x02); |
| 2370 | sitar_codec_enable_config_mode(codec, 0); |
| 2371 | |
| 2372 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2373 | |
| 2374 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x05); |
| 2375 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x02, 0x00); |
| 2376 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x04, 0x04); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2377 | usleep_range(50, 50); |
| 2378 | sitar->clock_active = true; |
| 2379 | return 0; |
| 2380 | } |
| 2381 | static void sitar_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 2382 | { |
| 2383 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2384 | pr_debug("%s\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2385 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x04, 0x00); |
| 2386 | ndelay(160); |
| 2387 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 2388 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x00); |
| 2389 | sitar->clock_active = false; |
| 2390 | } |
| 2391 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2392 | static int sitar_codec_mclk_index(const struct sitar_priv *sitar) |
| 2393 | { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2394 | if (sitar->mbhc_cfg.mclk_rate == SITAR_MCLK_RATE_12288KHZ) |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2395 | return 0; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2396 | else if (sitar->mbhc_cfg.mclk_rate == SITAR_MCLK_RATE_9600KHZ) |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2397 | return 1; |
| 2398 | else { |
| 2399 | BUG_ON(1); |
| 2400 | return -EINVAL; |
| 2401 | } |
| 2402 | } |
| 2403 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2404 | static void sitar_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 2405 | { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2406 | u8 *n_ready, *n_cic; |
| 2407 | struct sitar_mbhc_btn_detect_cfg *btn_det; |
| 2408 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2409 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2410 | btn_det = SITAR_MBHC_CAL_BTN_DET_PTR(sitar->mbhc_cfg.calibration); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2411 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2412 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B1_CTL, |
| 2413 | sitar->mbhc_data.v_ins_hu & 0xFF); |
| 2414 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B2_CTL, |
| 2415 | (sitar->mbhc_data.v_ins_hu >> 8) & 0xFF); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2416 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 2417 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B3_CTL, |
| 2418 | sitar->mbhc_data.v_b1_hu & 0xFF); |
| 2419 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B4_CTL, |
| 2420 | (sitar->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 2421 | |
| 2422 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B5_CTL, |
| 2423 | sitar->mbhc_data.v_b1_h & 0xFF); |
| 2424 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B6_CTL, |
| 2425 | (sitar->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 2426 | |
| 2427 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B9_CTL, |
| 2428 | sitar->mbhc_data.v_brh & 0xFF); |
| 2429 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B10_CTL, |
| 2430 | (sitar->mbhc_data.v_brh >> 8) & 0xFF); |
| 2431 | |
| 2432 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B11_CTL, |
| 2433 | sitar->mbhc_data.v_brl & 0xFF); |
| 2434 | snd_soc_write(codec, SITAR_A_CDC_MBHC_VOLT_B12_CTL, |
| 2435 | (sitar->mbhc_data.v_brl >> 8) & 0xFF); |
| 2436 | |
| 2437 | n_ready = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_N_READY); |
| 2438 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B1_CTL, |
| 2439 | n_ready[sitar_codec_mclk_index(sitar)]); |
| 2440 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B2_CTL, |
| 2441 | sitar->mbhc_data.npoll); |
| 2442 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B3_CTL, |
| 2443 | sitar->mbhc_data.nbounce_wait); |
| 2444 | n_cic = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_N_CIC); |
| 2445 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B6_CTL, |
| 2446 | n_cic[sitar_codec_mclk_index(sitar)]); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | static int sitar_startup(struct snd_pcm_substream *substream, |
| 2450 | struct snd_soc_dai *dai) |
| 2451 | { |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2452 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(dai->codec->dev->parent); |
| 2453 | if ((wcd9xxx != NULL) && (wcd9xxx->dev != NULL) && |
| 2454 | (wcd9xxx->dev->parent != NULL)) |
| 2455 | pm_runtime_get_sync(wcd9xxx->dev->parent); |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2456 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2457 | substream->name, substream->stream); |
| 2458 | |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | static void sitar_shutdown(struct snd_pcm_substream *substream, |
| 2463 | struct snd_soc_dai *dai) |
| 2464 | { |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 2465 | struct wcd9xxx *wcd9xxx = dev_get_drvdata(dai->codec->dev->parent); |
| 2466 | if ((wcd9xxx != NULL) && (wcd9xxx->dev != NULL) && |
| 2467 | (wcd9xxx->dev->parent != NULL)) { |
| 2468 | pm_runtime_mark_last_busy(wcd9xxx->dev->parent); |
| 2469 | pm_runtime_put(wcd9xxx->dev->parent); |
| 2470 | } |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2471 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2472 | substream->name, substream->stream); |
| 2473 | } |
| 2474 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2475 | int sitar_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2476 | { |
| 2477 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 2478 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2479 | pr_debug("%s() mclk_enable = %u\n", __func__, mclk_enable); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2480 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2481 | if (dapm) |
| 2482 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2483 | if (mclk_enable) { |
| 2484 | sitar->mclk_enabled = true; |
| 2485 | |
| 2486 | if (sitar->mbhc_polling_active && (sitar->mclk_enabled)) { |
| 2487 | sitar_codec_pause_hs_polling(codec); |
| 2488 | sitar_codec_enable_bandgap(codec, |
| 2489 | SITAR_BANDGAP_AUDIO_MODE); |
| 2490 | sitar_codec_enable_clock_block(codec, 0); |
| 2491 | sitar_codec_calibrate_hs_polling(codec); |
| 2492 | sitar_codec_start_hs_polling(codec); |
| 2493 | } else { |
| 2494 | sitar_codec_enable_bandgap(codec, |
| 2495 | SITAR_BANDGAP_AUDIO_MODE); |
| 2496 | sitar_codec_enable_clock_block(codec, 0); |
| 2497 | } |
| 2498 | } else { |
| 2499 | |
| 2500 | if (!sitar->mclk_enabled) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2501 | if (dapm) |
| 2502 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2503 | pr_err("Error, MCLK already diabled\n"); |
| 2504 | return -EINVAL; |
| 2505 | } |
| 2506 | sitar->mclk_enabled = false; |
| 2507 | |
| 2508 | if (sitar->mbhc_polling_active) { |
| 2509 | if (!sitar->mclk_enabled) { |
| 2510 | sitar_codec_pause_hs_polling(codec); |
| 2511 | sitar_codec_enable_bandgap(codec, |
| 2512 | SITAR_BANDGAP_MBHC_MODE); |
| 2513 | sitar_enable_rx_bias(codec, 1); |
| 2514 | sitar_codec_enable_clock_block(codec, 1); |
| 2515 | sitar_codec_calibrate_hs_polling(codec); |
| 2516 | sitar_codec_start_hs_polling(codec); |
| 2517 | } |
| 2518 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, |
| 2519 | 0x05, 0x01); |
| 2520 | } else { |
| 2521 | sitar_codec_disable_clock_block(codec); |
| 2522 | sitar_codec_enable_bandgap(codec, |
| 2523 | SITAR_BANDGAP_OFF); |
| 2524 | } |
| 2525 | } |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 2526 | if (dapm) |
| 2527 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2528 | return 0; |
| 2529 | } |
| 2530 | |
| 2531 | static int sitar_set_dai_sysclk(struct snd_soc_dai *dai, |
| 2532 | int clk_id, unsigned int freq, int dir) |
| 2533 | { |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2534 | pr_debug("%s\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2535 | return 0; |
| 2536 | } |
| 2537 | |
| 2538 | static int sitar_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2539 | { |
| 2540 | u8 val = 0; |
| 2541 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 2542 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2543 | pr_debug("%s\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2544 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 2545 | case SND_SOC_DAIFMT_CBS_CFS: |
| 2546 | /* CPU is master */ |
| 2547 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2548 | if (dai->id == AIF1_CAP) |
| 2549 | snd_soc_update_bits(dai->codec, |
| 2550 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2551 | SITAR_I2S_MASTER_MODE_MASK, 0); |
| 2552 | else if (dai->id == AIF1_PB) |
| 2553 | snd_soc_update_bits(dai->codec, |
| 2554 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2555 | SITAR_I2S_MASTER_MODE_MASK, 0); |
| 2556 | } |
| 2557 | break; |
| 2558 | case SND_SOC_DAIFMT_CBM_CFM: |
| 2559 | /* CPU is slave */ |
| 2560 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2561 | val = SITAR_I2S_MASTER_MODE_MASK; |
| 2562 | if (dai->id == AIF1_CAP) |
| 2563 | snd_soc_update_bits(dai->codec, |
| 2564 | SITAR_A_CDC_CLK_TX_I2S_CTL, val, val); |
| 2565 | else if (dai->id == AIF1_PB) |
| 2566 | snd_soc_update_bits(dai->codec, |
| 2567 | SITAR_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 2568 | } |
| 2569 | break; |
| 2570 | default: |
| 2571 | return -EINVAL; |
| 2572 | } |
| 2573 | return 0; |
| 2574 | } |
| 2575 | static int sitar_set_channel_map(struct snd_soc_dai *dai, |
| 2576 | unsigned int tx_num, unsigned int *tx_slot, |
| 2577 | unsigned int rx_num, unsigned int *rx_slot) |
| 2578 | |
| 2579 | { |
| 2580 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 2581 | u32 i = 0; |
| 2582 | if (!tx_slot && !rx_slot) { |
| 2583 | pr_err("%s: Invalid\n", __func__); |
| 2584 | return -EINVAL; |
| 2585 | } |
| 2586 | pr_debug("%s: DAI-ID %x %d %d\n", __func__, dai->id, tx_num, rx_num); |
| 2587 | |
| 2588 | if (dai->id == AIF1_PB) { |
| 2589 | for (i = 0; i < rx_num; i++) { |
| 2590 | sitar->dai[dai->id - 1].ch_num[i] = rx_slot[i]; |
| 2591 | sitar->dai[dai->id - 1].ch_act = 0; |
| 2592 | sitar->dai[dai->id - 1].ch_tot = rx_num; |
| 2593 | } |
| 2594 | } else if (dai->id == AIF1_CAP) { |
| 2595 | for (i = 0; i < tx_num; i++) { |
| 2596 | sitar->dai[dai->id - 1].ch_num[i] = tx_slot[i]; |
| 2597 | sitar->dai[dai->id - 1].ch_act = 0; |
| 2598 | sitar->dai[dai->id - 1].ch_tot = tx_num; |
| 2599 | } |
| 2600 | } |
| 2601 | return 0; |
| 2602 | } |
| 2603 | |
| 2604 | static int sitar_get_channel_map(struct snd_soc_dai *dai, |
| 2605 | unsigned int *tx_num, unsigned int *tx_slot, |
| 2606 | unsigned int *rx_num, unsigned int *rx_slot) |
| 2607 | |
| 2608 | { |
| 2609 | struct wcd9xxx *sitar = dev_get_drvdata(dai->codec->control_data); |
| 2610 | |
| 2611 | u32 cnt = 0; |
| 2612 | u32 tx_ch[SLIM_MAX_TX_PORTS]; |
| 2613 | u32 rx_ch[SLIM_MAX_RX_PORTS]; |
| 2614 | |
| 2615 | if (!rx_slot && !tx_slot) { |
| 2616 | pr_err("%s: Invalid\n", __func__); |
| 2617 | return -EINVAL; |
| 2618 | } |
| 2619 | pr_debug("%s: DAI-ID %x\n", __func__, dai->id); |
| 2620 | /* for virtual port, codec driver needs to do |
| 2621 | * housekeeping, for now should be ok |
| 2622 | */ |
| 2623 | wcd9xxx_get_channel(sitar, rx_ch, tx_ch); |
| 2624 | if (dai->id == AIF1_PB) { |
| 2625 | *rx_num = sitar_dai[dai->id - 1].playback.channels_max; |
| 2626 | while (cnt < *rx_num) { |
| 2627 | rx_slot[cnt] = rx_ch[cnt]; |
| 2628 | cnt++; |
| 2629 | } |
| 2630 | } else if (dai->id == AIF1_CAP) { |
| 2631 | *tx_num = sitar_dai[dai->id - 1].capture.channels_max; |
Bhalchandra Gajare | e6a30f7 | 2012-05-23 19:46:21 -0700 | [diff] [blame] | 2632 | tx_slot[0] = tx_ch[cnt]; |
| 2633 | tx_slot[1] = tx_ch[4 + cnt]; |
Bhalchandra Gajare | 9e5a477 | 2012-05-31 12:22:33 -0700 | [diff] [blame] | 2634 | tx_slot[2] = tx_ch[2 + cnt]; |
| 2635 | tx_slot[3] = tx_ch[3 + cnt]; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2636 | } |
| 2637 | return 0; |
| 2638 | } |
| 2639 | |
| 2640 | static int sitar_hw_params(struct snd_pcm_substream *substream, |
| 2641 | struct snd_pcm_hw_params *params, |
| 2642 | struct snd_soc_dai *dai) |
| 2643 | { |
| 2644 | struct snd_soc_codec *codec = dai->codec; |
| 2645 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(dai->codec); |
| 2646 | u8 path, shift; |
| 2647 | u16 tx_fs_reg, rx_fs_reg; |
| 2648 | u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state; |
| 2649 | |
Asish Bhattacharya | 7147f8e | 2012-04-30 10:34:39 +0530 | [diff] [blame] | 2650 | pr_debug("%s: DAI-ID %x\n", __func__, dai->id); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2651 | |
| 2652 | switch (params_rate(params)) { |
| 2653 | case 8000: |
| 2654 | tx_fs_rate = 0x00; |
| 2655 | rx_fs_rate = 0x00; |
| 2656 | break; |
| 2657 | case 16000: |
| 2658 | tx_fs_rate = 0x01; |
| 2659 | rx_fs_rate = 0x20; |
| 2660 | break; |
| 2661 | case 32000: |
| 2662 | tx_fs_rate = 0x02; |
| 2663 | rx_fs_rate = 0x40; |
| 2664 | break; |
| 2665 | case 48000: |
| 2666 | tx_fs_rate = 0x03; |
| 2667 | rx_fs_rate = 0x60; |
| 2668 | break; |
| 2669 | default: |
| 2670 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 2671 | params_rate(params)); |
| 2672 | return -EINVAL; |
| 2673 | } |
| 2674 | |
| 2675 | |
| 2676 | /** |
| 2677 | * If current dai is a tx dai, set sample rate to |
| 2678 | * all the txfe paths that are currently not active |
| 2679 | */ |
| 2680 | if (dai->id == AIF1_CAP) { |
| 2681 | |
| 2682 | tx_state = snd_soc_read(codec, |
| 2683 | SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL); |
| 2684 | |
| 2685 | for (path = 1, shift = 0; |
| 2686 | path <= NUM_DECIMATORS; path++, shift++) { |
| 2687 | |
| 2688 | if (!(tx_state & (1 << shift))) { |
| 2689 | tx_fs_reg = SITAR_A_CDC_TX1_CLK_FS_CTL |
| 2690 | + (BITS_PER_REG*(path-1)); |
| 2691 | snd_soc_update_bits(codec, tx_fs_reg, |
| 2692 | 0x03, tx_fs_rate); |
| 2693 | } |
| 2694 | } |
| 2695 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2696 | switch (params_format(params)) { |
| 2697 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2698 | snd_soc_update_bits(codec, |
| 2699 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2700 | 0x20, 0x20); |
| 2701 | break; |
| 2702 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2703 | snd_soc_update_bits(codec, |
| 2704 | SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2705 | 0x20, 0x00); |
| 2706 | break; |
| 2707 | default: |
| 2708 | pr_err("invalid format\n"); |
| 2709 | break; |
| 2710 | } |
| 2711 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_TX_I2S_CTL, |
| 2712 | 0x03, tx_fs_rate); |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 2713 | } else { |
| 2714 | sitar->dai[dai->id - 1].rate = params_rate(params); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2715 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | /** |
| 2719 | * TODO: Need to handle case where same RX chain takes 2 or more inputs |
| 2720 | * with varying sample rates |
| 2721 | */ |
| 2722 | |
| 2723 | /** |
| 2724 | * If current dai is a rx dai, set sample rate to |
| 2725 | * all the rx paths that are currently not active |
| 2726 | */ |
| 2727 | if (dai->id == AIF1_PB) { |
| 2728 | |
| 2729 | rx_state = snd_soc_read(codec, |
| 2730 | SITAR_A_CDC_CLK_RX_B1_CTL); |
| 2731 | |
| 2732 | for (path = 1, shift = 0; |
| 2733 | path <= NUM_INTERPOLATORS; path++, shift++) { |
| 2734 | |
| 2735 | if (!(rx_state & (1 << shift))) { |
| 2736 | rx_fs_reg = SITAR_A_CDC_RX1_B5_CTL |
| 2737 | + (BITS_PER_REG*(path-1)); |
| 2738 | snd_soc_update_bits(codec, rx_fs_reg, |
| 2739 | 0xE0, rx_fs_rate); |
| 2740 | } |
| 2741 | } |
| 2742 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 2743 | switch (params_format(params)) { |
| 2744 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2745 | snd_soc_update_bits(codec, |
| 2746 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2747 | 0x20, 0x20); |
| 2748 | break; |
| 2749 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2750 | snd_soc_update_bits(codec, |
| 2751 | SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2752 | 0x20, 0x00); |
| 2753 | break; |
| 2754 | default: |
| 2755 | pr_err("invalid format\n"); |
| 2756 | break; |
| 2757 | } |
| 2758 | snd_soc_update_bits(codec, SITAR_A_CDC_CLK_RX_I2S_CTL, |
| 2759 | 0x03, (rx_fs_rate >> 0x05)); |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 2760 | } else { |
| 2761 | sitar->dai[dai->id - 1].rate = params_rate(params); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2762 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | return 0; |
| 2766 | } |
| 2767 | |
| 2768 | static struct snd_soc_dai_ops sitar_dai_ops = { |
| 2769 | .startup = sitar_startup, |
| 2770 | .shutdown = sitar_shutdown, |
| 2771 | .hw_params = sitar_hw_params, |
| 2772 | .set_sysclk = sitar_set_dai_sysclk, |
| 2773 | .set_fmt = sitar_set_dai_fmt, |
| 2774 | .set_channel_map = sitar_set_channel_map, |
| 2775 | .get_channel_map = sitar_get_channel_map, |
| 2776 | }; |
| 2777 | |
| 2778 | static struct snd_soc_dai_driver sitar_dai[] = { |
| 2779 | { |
| 2780 | .name = "sitar_rx1", |
| 2781 | .id = AIF1_PB, |
| 2782 | .playback = { |
| 2783 | .stream_name = "AIF1 Playback", |
| 2784 | .rates = WCD9304_RATES, |
| 2785 | .formats = SITAR_FORMATS, |
| 2786 | .rate_max = 48000, |
| 2787 | .rate_min = 8000, |
| 2788 | .channels_min = 1, |
| 2789 | .channels_max = 2, |
| 2790 | }, |
| 2791 | .ops = &sitar_dai_ops, |
| 2792 | }, |
| 2793 | { |
| 2794 | .name = "sitar_tx1", |
| 2795 | .id = AIF1_CAP, |
| 2796 | .capture = { |
| 2797 | .stream_name = "AIF1 Capture", |
| 2798 | .rates = WCD9304_RATES, |
| 2799 | .formats = SITAR_FORMATS, |
| 2800 | .rate_max = 48000, |
| 2801 | .rate_min = 8000, |
| 2802 | .channels_min = 1, |
| 2803 | .channels_max = 2, |
| 2804 | }, |
| 2805 | .ops = &sitar_dai_ops, |
| 2806 | }, |
| 2807 | }; |
| 2808 | |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 2809 | static struct snd_soc_dai_driver sitar_i2s_dai[] = { |
| 2810 | { |
| 2811 | .name = "sitar_i2s_rx1", |
| 2812 | .id = AIF1_PB, |
| 2813 | .playback = { |
| 2814 | .stream_name = "AIF1 Playback", |
| 2815 | .rates = WCD9304_RATES, |
| 2816 | .formats = SITAR_FORMATS, |
| 2817 | .rate_max = 192000, |
| 2818 | .rate_min = 8000, |
| 2819 | .channels_min = 1, |
| 2820 | .channels_max = 4, |
| 2821 | }, |
| 2822 | .ops = &sitar_dai_ops, |
| 2823 | }, |
| 2824 | { |
| 2825 | .name = "sitar_i2s_tx1", |
| 2826 | .id = AIF1_CAP, |
| 2827 | .capture = { |
| 2828 | .stream_name = "AIF1 Capture", |
| 2829 | .rates = WCD9304_RATES, |
| 2830 | .formats = SITAR_FORMATS, |
| 2831 | .rate_max = 192000, |
| 2832 | .rate_min = 8000, |
| 2833 | .channels_min = 1, |
| 2834 | .channels_max = 4, |
| 2835 | }, |
| 2836 | .ops = &sitar_dai_ops, |
| 2837 | }, |
| 2838 | }; |
| 2839 | |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2840 | static int sitar_codec_enable_chmask(struct sitar_priv *sitar, |
| 2841 | int event, int index) |
| 2842 | { |
| 2843 | int ret = 0; |
| 2844 | u32 k = 0; |
| 2845 | switch (event) { |
| 2846 | case SND_SOC_DAPM_POST_PMU: |
| 2847 | for (k = 0; k < sitar->dai[index].ch_tot; k++) { |
| 2848 | ret = wcd9xxx_get_slave_port( |
| 2849 | sitar->dai[index].ch_num[k]); |
| 2850 | if (ret < 0) { |
| 2851 | pr_err("%s: Invalid Slave port ID: %d\n", |
| 2852 | __func__, ret); |
| 2853 | ret = -EINVAL; |
| 2854 | break; |
| 2855 | } |
| 2856 | sitar->dai[index].ch_mask |= 1 << ret; |
| 2857 | } |
| 2858 | ret = 0; |
| 2859 | break; |
| 2860 | case SND_SOC_DAPM_POST_PMD: |
| 2861 | ret = wait_event_timeout(sitar->dai[index].dai_wait, |
| 2862 | (sitar->dai[index].ch_mask == 0), |
| 2863 | msecs_to_jiffies(SLIM_CLOSE_TIMEOUT)); |
| 2864 | if (!ret) { |
| 2865 | pr_err("%s: slim close tx/rx timeout\n", |
| 2866 | __func__); |
| 2867 | ret = -EINVAL; |
| 2868 | } |
| 2869 | ret = 0; |
| 2870 | break; |
| 2871 | } |
| 2872 | return ret; |
| 2873 | } |
| 2874 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2875 | static int sitar_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 2876 | struct snd_kcontrol *kcontrol, int event) |
| 2877 | { |
| 2878 | struct wcd9xxx *sitar; |
| 2879 | struct snd_soc_codec *codec = w->codec; |
| 2880 | struct sitar_priv *sitar_p = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2881 | u32 j = 0, ret = 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2882 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 2883 | sitar = codec->control_data; |
| 2884 | /* Execute the callback only if interface type is slimbus */ |
| 2885 | if (sitar_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2886 | return 0; |
| 2887 | switch (event) { |
| 2888 | case SND_SOC_DAPM_POST_PMU: |
| 2889 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2890 | if (sitar_dai[j].id == AIF1_CAP) |
| 2891 | continue; |
| 2892 | if (!strncmp(w->sname, |
| 2893 | sitar_dai[j].playback.stream_name, 13)) { |
| 2894 | ++sitar_p->dai[j].ch_act; |
| 2895 | break; |
| 2896 | } |
| 2897 | } |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2898 | if (sitar_p->dai[j].ch_act == sitar_p->dai[j].ch_tot) { |
| 2899 | ret = sitar_codec_enable_chmask(sitar_p, event, j); |
| 2900 | ret = wcd9xxx_cfg_slim_sch_rx(sitar, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2901 | sitar_p->dai[j].ch_num, |
| 2902 | sitar_p->dai[j].ch_tot, |
| 2903 | sitar_p->dai[j].rate); |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2904 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2905 | break; |
| 2906 | case SND_SOC_DAPM_POST_PMD: |
| 2907 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2908 | if (sitar_dai[j].id == AIF1_CAP) |
| 2909 | continue; |
| 2910 | if (!strncmp(w->sname, |
| 2911 | sitar_dai[j].playback.stream_name, 13)) { |
| 2912 | --sitar_p->dai[j].ch_act; |
| 2913 | break; |
| 2914 | } |
| 2915 | } |
| 2916 | if (!sitar_p->dai[j].ch_act) { |
| 2917 | wcd9xxx_close_slim_sch_rx(sitar, |
| 2918 | sitar_p->dai[j].ch_num, |
| 2919 | sitar_p->dai[j].ch_tot); |
| 2920 | sitar_p->dai[j].rate = 0; |
| 2921 | memset(sitar_p->dai[j].ch_num, 0, (sizeof(u32)* |
| 2922 | sitar_p->dai[j].ch_tot)); |
| 2923 | sitar_p->dai[j].ch_tot = 0; |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2924 | ret = sitar_codec_enable_chmask(sitar_p, event, j); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2925 | } |
| 2926 | } |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2927 | return ret; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | static int sitar_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 2931 | struct snd_kcontrol *kcontrol, int event) |
| 2932 | { |
| 2933 | struct wcd9xxx *sitar; |
| 2934 | struct snd_soc_codec *codec = w->codec; |
| 2935 | struct sitar_priv *sitar_p = snd_soc_codec_get_drvdata(codec); |
| 2936 | /* index to the DAI ID, for now hardcoding */ |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2937 | u32 j = 0, ret = 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2938 | |
| 2939 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 2940 | sitar = codec->control_data; |
| 2941 | |
| 2942 | /* Execute the callback only if interface type is slimbus */ |
| 2943 | if (sitar_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2944 | return 0; |
| 2945 | switch (event) { |
| 2946 | case SND_SOC_DAPM_POST_PMU: |
| 2947 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2948 | if (sitar_dai[j].id == AIF1_PB) |
| 2949 | continue; |
| 2950 | if (!strncmp(w->sname, |
| 2951 | sitar_dai[j].capture.stream_name, 13)) { |
| 2952 | ++sitar_p->dai[j].ch_act; |
| 2953 | break; |
| 2954 | } |
| 2955 | } |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2956 | if (sitar_p->dai[j].ch_act == sitar_p->dai[j].ch_tot) { |
| 2957 | ret = sitar_codec_enable_chmask(sitar_p, event, j); |
| 2958 | ret = wcd9xxx_cfg_slim_sch_tx(sitar, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2959 | sitar_p->dai[j].ch_num, |
| 2960 | sitar_p->dai[j].ch_tot, |
| 2961 | sitar_p->dai[j].rate); |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2962 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2963 | break; |
| 2964 | case SND_SOC_DAPM_POST_PMD: |
| 2965 | for (j = 0; j < ARRAY_SIZE(sitar_dai); j++) { |
| 2966 | if (sitar_dai[j].id == AIF1_PB) |
| 2967 | continue; |
| 2968 | if (!strncmp(w->sname, |
| 2969 | sitar_dai[j].capture.stream_name, 13)) { |
| 2970 | --sitar_p->dai[j].ch_act; |
| 2971 | break; |
| 2972 | } |
| 2973 | } |
| 2974 | if (!sitar_p->dai[j].ch_act) { |
| 2975 | wcd9xxx_close_slim_sch_tx(sitar, |
| 2976 | sitar_p->dai[j].ch_num, |
| 2977 | sitar_p->dai[j].ch_tot); |
| 2978 | sitar_p->dai[j].rate = 0; |
| 2979 | memset(sitar_p->dai[j].ch_num, 0, (sizeof(u32)* |
| 2980 | sitar_p->dai[j].ch_tot)); |
| 2981 | sitar_p->dai[j].ch_tot = 0; |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2982 | ret = sitar_codec_enable_chmask(sitar_p, event, j); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2983 | } |
| 2984 | } |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 2985 | return ret; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | |
| 2989 | static short sitar_codec_read_sta_result(struct snd_soc_codec *codec) |
| 2990 | { |
| 2991 | u8 bias_msb, bias_lsb; |
| 2992 | short bias_value; |
| 2993 | |
| 2994 | bias_msb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B3_STATUS); |
| 2995 | bias_lsb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B2_STATUS); |
| 2996 | bias_value = (bias_msb << 8) | bias_lsb; |
| 2997 | return bias_value; |
| 2998 | } |
| 2999 | |
| 3000 | static short sitar_codec_read_dce_result(struct snd_soc_codec *codec) |
| 3001 | { |
| 3002 | u8 bias_msb, bias_lsb; |
| 3003 | short bias_value; |
| 3004 | |
| 3005 | bias_msb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B5_STATUS); |
| 3006 | bias_lsb = snd_soc_read(codec, SITAR_A_CDC_MBHC_B4_STATUS); |
| 3007 | bias_value = (bias_msb << 8) | bias_lsb; |
| 3008 | return bias_value; |
| 3009 | } |
| 3010 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3011 | static void sitar_turn_onoff_rel_detection(struct snd_soc_codec *codec, |
| 3012 | bool on) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3013 | { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3014 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 3015 | } |
| 3016 | |
| 3017 | static short __sitar_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 3018 | bool override_bypass, bool noreldetection) |
| 3019 | { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3020 | short bias_value; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3021 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3022 | |
| 3023 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| 3024 | if (noreldetection) |
| 3025 | sitar_turn_onoff_rel_detection(codec, false); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3026 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3027 | /* Turn on the override */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3028 | if (!override_bypass) |
| 3029 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x4, 0x4); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3030 | if (dce) { |
| 3031 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 3032 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x4); |
| 3033 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3034 | usleep_range(sitar->mbhc_data.t_sta_dce, |
| 3035 | sitar->mbhc_data.t_sta_dce); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3036 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x4); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3037 | usleep_range(sitar->mbhc_data.t_dce, |
| 3038 | sitar->mbhc_data.t_dce); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3039 | bias_value = sitar_codec_read_dce_result(codec); |
| 3040 | } else { |
| 3041 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 3042 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x2); |
| 3043 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3044 | usleep_range(sitar->mbhc_data.t_sta_dce, |
| 3045 | sitar->mbhc_data.t_sta_dce); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3046 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x2); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3047 | usleep_range(sitar->mbhc_data.t_sta, |
| 3048 | sitar->mbhc_data.t_sta); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3049 | bias_value = sitar_codec_read_sta_result(codec); |
| 3050 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 3051 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x0); |
| 3052 | } |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3053 | /* Turn off the override after measuring mic voltage */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3054 | if (!override_bypass) |
| 3055 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 3056 | |
| 3057 | if (noreldetection) |
| 3058 | sitar_turn_onoff_rel_detection(codec, true); |
| 3059 | wcd9xxx_enable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3060 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3061 | return bias_value; |
| 3062 | } |
| 3063 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3064 | static short sitar_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 3065 | bool norel) |
| 3066 | { |
| 3067 | return __sitar_codec_sta_dce(codec, dce, false, norel); |
| 3068 | } |
| 3069 | |
| 3070 | static void sitar_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 3071 | { |
| 3072 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3073 | const struct sitar_mbhc_general_cfg *generic = |
| 3074 | SITAR_MBHC_CAL_GENERAL_PTR(sitar->mbhc_cfg.calibration); |
| 3075 | |
| 3076 | if (!sitar->mclk_enabled && !sitar->mbhc_polling_active) |
| 3077 | sitar_codec_enable_config_mode(codec, 1); |
| 3078 | |
| 3079 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 3080 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x6, 0x0); |
| 3081 | |
| 3082 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 3083 | |
| 3084 | usleep_range(generic->t_shutdown_plug_rem, |
| 3085 | generic->t_shutdown_plug_rem); |
| 3086 | |
| 3087 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0xA, 0x8); |
| 3088 | if (!sitar->mclk_enabled && !sitar->mbhc_polling_active) |
| 3089 | sitar_codec_enable_config_mode(codec, 0); |
| 3090 | |
| 3091 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x00); |
| 3092 | } |
| 3093 | |
| 3094 | static void sitar_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
| 3095 | { |
| 3096 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3097 | |
| 3098 | sitar_codec_shutdown_hs_removal_detect(codec); |
| 3099 | |
| 3100 | if (!sitar->mclk_enabled) { |
| 3101 | sitar_codec_disable_clock_block(codec); |
| 3102 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_OFF); |
| 3103 | } |
| 3104 | |
| 3105 | sitar->mbhc_polling_active = false; |
| 3106 | sitar->mbhc_state = MBHC_STATE_NONE; |
| 3107 | } |
| 3108 | |
| 3109 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3110 | static short sitar_codec_setup_hs_polling(struct snd_soc_codec *codec) |
| 3111 | { |
| 3112 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3113 | short bias_value; |
| 3114 | u8 cfilt_mode; |
| 3115 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3116 | if (!sitar->mbhc_cfg.calibration) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3117 | pr_err("Error, no sitar calibration\n"); |
| 3118 | return -ENODEV; |
| 3119 | } |
| 3120 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3121 | if (!sitar->mclk_enabled) { |
| 3122 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_MBHC_MODE); |
| 3123 | sitar_enable_rx_bias(codec, 1); |
| 3124 | sitar_codec_enable_clock_block(codec, 1); |
| 3125 | } |
| 3126 | |
| 3127 | snd_soc_update_bits(codec, SITAR_A_CLK_BUFF_EN1, 0x05, 0x01); |
| 3128 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3129 | /* Make sure CFILT is in fast mode, save current mode */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3130 | cfilt_mode = snd_soc_read(codec, sitar->mbhc_bias_regs.cfilt_ctl); |
| 3131 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00); |
| 3132 | |
| 3133 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.ctl_reg, 0x1F, 0x16); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3134 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3135 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 3136 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
| 3137 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3138 | snd_soc_update_bits(codec, SITAR_A_TX_4_MBHC_EN, 0x80, 0x80); |
| 3139 | snd_soc_update_bits(codec, SITAR_A_TX_4_MBHC_EN, 0x1F, 0x1C); |
| 3140 | snd_soc_update_bits(codec, SITAR_A_TX_4_MBHC_TEST_CTL, 0x40, 0x40); |
| 3141 | |
| 3142 | snd_soc_update_bits(codec, SITAR_A_TX_4_MBHC_EN, 0x80, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3143 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 3144 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x00); |
| 3145 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3146 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x2, 0x2); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3147 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 3148 | |
| 3149 | sitar_codec_calibrate_hs_polling(codec); |
| 3150 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3151 | /* don't flip override */ |
| 3152 | bias_value = __sitar_codec_sta_dce(codec, 1, true, true); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3153 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 3154 | cfilt_mode); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3155 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x13, 0x00); |
| 3156 | |
| 3157 | return bias_value; |
| 3158 | } |
| 3159 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3160 | static int sitar_cancel_btn_work(struct sitar_priv *sitar) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3161 | { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3162 | int r = 0; |
| 3163 | struct wcd9xxx *core = dev_get_drvdata(sitar->codec->dev->parent); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3164 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3165 | if (cancel_delayed_work_sync(&sitar->mbhc_btn_dwork)) { |
| 3166 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 3167 | * we have to unlock from here instead btn_work */ |
| 3168 | wcd9xxx_unlock_sleep(core); |
| 3169 | r = 1; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3170 | } |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3171 | return r; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3172 | } |
| 3173 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3174 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3175 | static u16 sitar_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 3176 | s16 vin_mv) |
| 3177 | { |
| 3178 | short diff, zero; |
| 3179 | struct sitar_priv *sitar; |
| 3180 | u32 mb_mv, in; |
| 3181 | |
| 3182 | sitar = snd_soc_codec_get_drvdata(codec); |
| 3183 | mb_mv = sitar->mbhc_data.micb_mv; |
| 3184 | |
| 3185 | if (mb_mv == 0) { |
| 3186 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 3187 | return -EINVAL; |
| 3188 | } |
| 3189 | |
| 3190 | if (dce) { |
| 3191 | diff = sitar->mbhc_data.dce_mb - sitar->mbhc_data.dce_z; |
| 3192 | zero = sitar->mbhc_data.dce_z; |
| 3193 | } else { |
| 3194 | diff = sitar->mbhc_data.sta_mb - sitar->mbhc_data.sta_z; |
| 3195 | zero = sitar->mbhc_data.sta_z; |
| 3196 | } |
| 3197 | in = (u32) diff * vin_mv; |
| 3198 | |
| 3199 | return (u16) (in / mb_mv) + zero; |
| 3200 | } |
| 3201 | |
| 3202 | static s32 sitar_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 3203 | u16 bias_value) |
| 3204 | { |
| 3205 | struct sitar_priv *sitar; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3206 | s16 value, z, mb; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3207 | s32 mv; |
| 3208 | |
| 3209 | sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3210 | value = bias_value; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3211 | |
| 3212 | if (dce) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3213 | z = (sitar->mbhc_data.dce_z); |
| 3214 | mb = (sitar->mbhc_data.dce_mb); |
| 3215 | mv = (value - z) * (s32)sitar->mbhc_data.micb_mv / (mb - z); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3216 | } else { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3217 | z = (sitar->mbhc_data.sta_z); |
| 3218 | mb = (sitar->mbhc_data.sta_mb); |
| 3219 | mv = (value - z) * (s32)sitar->mbhc_data.micb_mv / (mb - z); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | return mv; |
| 3223 | } |
| 3224 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3225 | static void btn_lpress_fn(struct work_struct *work) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3226 | { |
| 3227 | struct delayed_work *delayed_work; |
| 3228 | struct sitar_priv *sitar; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3229 | short bias_value; |
| 3230 | int dce_mv, sta_mv; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3231 | struct wcd9xxx *core; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3232 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3233 | pr_debug("%s:\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3234 | |
| 3235 | delayed_work = to_delayed_work(work); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3236 | sitar = container_of(delayed_work, struct sitar_priv, mbhc_btn_dwork); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3237 | core = dev_get_drvdata(sitar->codec->dev->parent); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3238 | |
| 3239 | if (sitar) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3240 | if (sitar->mbhc_cfg.button_jack) { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3241 | bias_value = sitar_codec_read_sta_result(sitar->codec); |
| 3242 | sta_mv = sitar_codec_sta_dce_v(sitar->codec, 0, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3243 | bias_value); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3244 | bias_value = sitar_codec_read_dce_result(sitar->codec); |
| 3245 | dce_mv = sitar_codec_sta_dce_v(sitar->codec, 1, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3246 | bias_value); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3247 | pr_debug("%s: Reporting long button press event" |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3248 | " STA: %d, DCE: %d\n", __func__, sta_mv, dce_mv); |
| 3249 | sitar_snd_soc_jack_report(sitar, |
| 3250 | sitar->mbhc_cfg.button_jack, |
| 3251 | sitar->buttons_pressed, |
| 3252 | sitar->buttons_pressed); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3253 | } |
| 3254 | } else { |
| 3255 | pr_err("%s: Bad sitar private data\n", __func__); |
| 3256 | } |
| 3257 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3258 | pr_debug("%s: leave\n", __func__); |
| 3259 | wcd9xxx_unlock_sleep(core); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3260 | } |
| 3261 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3262 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3263 | void sitar_mbhc_cal(struct snd_soc_codec *codec) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 3264 | { |
| 3265 | struct sitar_priv *sitar; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3266 | struct sitar_mbhc_btn_detect_cfg *btn_det; |
| 3267 | u8 cfilt_mode, bg_mode; |
| 3268 | u8 ncic, nmeas, navg; |
| 3269 | u32 mclk_rate; |
| 3270 | u32 dce_wait, sta_wait; |
| 3271 | u8 *n_cic; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3272 | void *calibration; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3273 | |
| 3274 | sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3275 | calibration = sitar->mbhc_cfg.calibration; |
| 3276 | |
| 3277 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| 3278 | sitar_turn_onoff_rel_detection(codec, false); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3279 | |
| 3280 | /* First compute the DCE / STA wait times |
| 3281 | * depending on tunable parameters. |
| 3282 | * The value is computed in microseconds |
| 3283 | */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3284 | btn_det = SITAR_MBHC_CAL_BTN_DET_PTR(calibration); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3285 | n_cic = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_N_CIC); |
| 3286 | ncic = n_cic[sitar_codec_mclk_index(sitar)]; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3287 | nmeas = SITAR_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 3288 | navg = SITAR_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 3289 | mclk_rate = sitar->mbhc_cfg.mclk_rate; |
| 3290 | dce_wait = (1000 * 512 * 60 * (nmeas + 1)) / (mclk_rate / 1000); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3291 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
| 3292 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3293 | sitar->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 3294 | sitar->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3295 | |
| 3296 | /* LDOH and CFILT are already configured during pdata handling. |
| 3297 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 3298 | * Need to restore defaults once calculation is done. |
| 3299 | */ |
| 3300 | cfilt_mode = snd_soc_read(codec, sitar->mbhc_bias_regs.cfilt_ctl); |
| 3301 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, 0x40, 0x00); |
| 3302 | bg_mode = snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 3303 | 0x02); |
| 3304 | |
| 3305 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 3306 | * to perform ADC calibration |
| 3307 | */ |
| 3308 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.ctl_reg, 0x60, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3309 | sitar->mbhc_cfg.micbias << 5); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3310 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 3311 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x60, 0x60); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3312 | snd_soc_write(codec, SITAR_A_TX_4_MBHC_TEST_CTL, 0x78); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3313 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 3314 | |
| 3315 | /* DCE measurement for 0 volts */ |
| 3316 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 3317 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x04); |
| 3318 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x02); |
| 3319 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x81); |
| 3320 | usleep_range(100, 100); |
| 3321 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x04); |
| 3322 | usleep_range(sitar->mbhc_data.t_dce, sitar->mbhc_data.t_dce); |
| 3323 | sitar->mbhc_data.dce_z = sitar_codec_read_dce_result(codec); |
| 3324 | |
| 3325 | /* DCE measurment for MB voltage */ |
| 3326 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 3327 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x02); |
| 3328 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x82); |
| 3329 | usleep_range(100, 100); |
| 3330 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x04); |
| 3331 | usleep_range(sitar->mbhc_data.t_dce, sitar->mbhc_data.t_dce); |
| 3332 | sitar->mbhc_data.dce_mb = sitar_codec_read_dce_result(codec); |
| 3333 | |
| 3334 | /* Sta measuremnt for 0 volts */ |
| 3335 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 3336 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x02); |
| 3337 | snd_soc_write(codec, SITAR_A_CDC_MBHC_CLK_CTL, 0x02); |
| 3338 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x81); |
| 3339 | usleep_range(100, 100); |
| 3340 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x02); |
| 3341 | usleep_range(sitar->mbhc_data.t_sta, sitar->mbhc_data.t_sta); |
| 3342 | sitar->mbhc_data.sta_z = sitar_codec_read_sta_result(codec); |
| 3343 | |
| 3344 | /* STA Measurement for MB Voltage */ |
| 3345 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x82); |
| 3346 | usleep_range(100, 100); |
| 3347 | snd_soc_write(codec, SITAR_A_CDC_MBHC_EN_CTL, 0x02); |
| 3348 | usleep_range(sitar->mbhc_data.t_sta, sitar->mbhc_data.t_sta); |
| 3349 | sitar->mbhc_data.sta_mb = sitar_codec_read_sta_result(codec); |
| 3350 | |
| 3351 | /* Restore default settings. */ |
| 3352 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 3353 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 3354 | cfilt_mode); |
| 3355 | snd_soc_update_bits(codec, SITAR_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 3356 | |
| 3357 | snd_soc_write(codec, SITAR_A_MBHC_SCALING_MUX_1, 0x84); |
| 3358 | usleep_range(100, 100); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3359 | |
| 3360 | wcd9xxx_enable_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL); |
| 3361 | sitar_turn_onoff_rel_detection(codec, true); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | void *sitar_mbhc_cal_btn_det_mp(const struct sitar_mbhc_btn_detect_cfg* btn_det, |
| 3365 | const enum sitar_mbhc_btn_det_mem mem) |
| 3366 | { |
| 3367 | void *ret = &btn_det->_v_btn_low; |
| 3368 | |
| 3369 | switch (mem) { |
| 3370 | case SITAR_BTN_DET_GAIN: |
| 3371 | ret += sizeof(btn_det->_n_cic); |
| 3372 | case SITAR_BTN_DET_N_CIC: |
| 3373 | ret += sizeof(btn_det->_n_ready); |
| 3374 | case SITAR_BTN_DET_N_READY: |
| 3375 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 3376 | case SITAR_BTN_DET_V_BTN_HIGH: |
| 3377 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 3378 | case SITAR_BTN_DET_V_BTN_LOW: |
| 3379 | /* do nothing */ |
| 3380 | break; |
| 3381 | default: |
| 3382 | ret = NULL; |
| 3383 | } |
| 3384 | |
| 3385 | return ret; |
| 3386 | } |
| 3387 | |
| 3388 | static void sitar_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 3389 | { |
| 3390 | struct sitar_priv *sitar; |
| 3391 | s16 btn_mv = 0, btn_delta_mv; |
| 3392 | struct sitar_mbhc_btn_detect_cfg *btn_det; |
| 3393 | struct sitar_mbhc_plug_type_cfg *plug_type; |
| 3394 | u16 *btn_high; |
| 3395 | u8 *n_ready; |
| 3396 | int i; |
| 3397 | |
| 3398 | sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3399 | btn_det = SITAR_MBHC_CAL_BTN_DET_PTR(sitar->mbhc_cfg.calibration); |
| 3400 | plug_type = SITAR_MBHC_CAL_PLUG_TYPE_PTR(sitar->mbhc_cfg.calibration); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3401 | |
| 3402 | n_ready = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_N_READY); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3403 | if (sitar->mbhc_cfg.mclk_rate == SITAR_MCLK_RATE_12288KHZ) { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3404 | sitar->mbhc_data.npoll = 9; |
| 3405 | sitar->mbhc_data.nbounce_wait = 30; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3406 | } else if (sitar->mbhc_cfg.mclk_rate == SITAR_MCLK_RATE_9600KHZ) { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3407 | sitar->mbhc_data.npoll = 7; |
| 3408 | sitar->mbhc_data.nbounce_wait = 23; |
| 3409 | } |
| 3410 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3411 | sitar->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 3412 | (sitar->mbhc_cfg.mclk_rate / 1000) * |
| 3413 | n_ready[sitar_codec_mclk_index(sitar)]) + |
| 3414 | 10; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3415 | sitar->mbhc_data.v_ins_hu = |
| 3416 | sitar_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 3417 | sitar->mbhc_data.v_ins_h = |
| 3418 | sitar_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 3419 | |
| 3420 | btn_high = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_V_BTN_HIGH); |
| 3421 | for (i = 0; i < btn_det->num_btn; i++) |
| 3422 | btn_mv = btn_high[i] > btn_mv ? btn_high[i] : btn_mv; |
| 3423 | |
| 3424 | sitar->mbhc_data.v_b1_h = sitar_codec_v_sta_dce(codec, DCE, btn_mv); |
| 3425 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_sta; |
| 3426 | |
| 3427 | sitar->mbhc_data.v_b1_hu = |
| 3428 | sitar_codec_v_sta_dce(codec, STA, btn_delta_mv); |
| 3429 | |
| 3430 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_cic; |
| 3431 | |
| 3432 | sitar->mbhc_data.v_b1_huc = |
| 3433 | sitar_codec_v_sta_dce(codec, DCE, btn_delta_mv); |
| 3434 | |
| 3435 | sitar->mbhc_data.v_brh = sitar->mbhc_data.v_b1_h; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3436 | sitar->mbhc_data.v_brl = SITAR_MBHC_BUTTON_MIN; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3437 | |
| 3438 | sitar->mbhc_data.v_no_mic = |
| 3439 | sitar_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 3440 | } |
| 3441 | |
| 3442 | void sitar_mbhc_init(struct snd_soc_codec *codec) |
| 3443 | { |
| 3444 | struct sitar_priv *sitar; |
| 3445 | struct sitar_mbhc_general_cfg *generic; |
| 3446 | struct sitar_mbhc_btn_detect_cfg *btn_det; |
| 3447 | int n; |
| 3448 | u8 *n_cic, *gain; |
| 3449 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3450 | pr_err("%s(): ENTER\n", __func__); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3451 | sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3452 | generic = SITAR_MBHC_CAL_GENERAL_PTR(sitar->mbhc_cfg.calibration); |
| 3453 | btn_det = SITAR_MBHC_CAL_BTN_DET_PTR(sitar->mbhc_cfg.calibration); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3454 | |
| 3455 | for (n = 0; n < 8; n++) { |
| 3456 | if (n != 7) { |
| 3457 | snd_soc_update_bits(codec, |
| 3458 | SITAR_A_CDC_MBHC_FIR_B1_CFG, |
| 3459 | 0x07, n); |
| 3460 | snd_soc_write(codec, SITAR_A_CDC_MBHC_FIR_B2_CFG, |
| 3461 | btn_det->c[n]); |
| 3462 | } |
| 3463 | } |
| 3464 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B2_CTL, 0x07, |
| 3465 | btn_det->nc); |
| 3466 | |
| 3467 | n_cic = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_N_CIC); |
| 3468 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_TIMER_B6_CTL, 0xFF, |
| 3469 | n_cic[sitar_codec_mclk_index(sitar)]); |
| 3470 | |
| 3471 | gain = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_GAIN); |
| 3472 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B2_CTL, 0x78, |
| 3473 | gain[sitar_codec_mclk_index(sitar)] << 3); |
| 3474 | |
| 3475 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 3476 | generic->mbhc_nsa << 4); |
| 3477 | |
| 3478 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 3479 | btn_det->n_meas); |
| 3480 | |
| 3481 | snd_soc_write(codec, SITAR_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 3482 | |
| 3483 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 3484 | |
| 3485 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x78, |
| 3486 | btn_det->mbhc_nsc << 3); |
| 3487 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3488 | snd_soc_update_bits(codec, SITAR_A_MICB_1_MBHC, 0x03, |
| 3489 | sitar->mbhc_cfg.micbias); |
| 3490 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3491 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x02, 0x02); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3492 | |
| 3493 | snd_soc_update_bits(codec, SITAR_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0); |
| 3494 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | static bool sitar_mbhc_fw_validate(const struct firmware *fw) |
| 3498 | { |
| 3499 | u32 cfg_offset; |
| 3500 | struct sitar_mbhc_imped_detect_cfg *imped_cfg; |
| 3501 | struct sitar_mbhc_btn_detect_cfg *btn_cfg; |
| 3502 | |
| 3503 | if (fw->size < SITAR_MBHC_CAL_MIN_SIZE) |
| 3504 | return false; |
| 3505 | |
| 3506 | /* previous check guarantees that there is enough fw data up |
| 3507 | * to num_btn |
| 3508 | */ |
| 3509 | btn_cfg = SITAR_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 3510 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 3511 | if (fw->size < (cfg_offset + SITAR_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 3512 | return false; |
| 3513 | |
| 3514 | /* previous check guarantees that there is enough fw data up |
| 3515 | * to start of impedance detection configuration |
| 3516 | */ |
| 3517 | imped_cfg = SITAR_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 3518 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 3519 | |
| 3520 | if (fw->size < (cfg_offset + SITAR_MBHC_CAL_IMPED_MIN_SZ)) |
| 3521 | return false; |
| 3522 | |
| 3523 | if (fw->size < (cfg_offset + SITAR_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 3524 | return false; |
| 3525 | |
| 3526 | return true; |
| 3527 | } |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 3528 | |
| 3529 | |
| 3530 | static void sitar_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 3531 | { |
| 3532 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 3533 | } |
| 3534 | |
| 3535 | /* called under codec_resource_lock acquisition */ |
| 3536 | void sitar_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
| 3537 | { |
| 3538 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3539 | u8 wg_time; |
| 3540 | |
| 3541 | wg_time = snd_soc_read(codec, SITAR_A_RX_HPH_CNP_WG_TIME) ; |
| 3542 | wg_time += 1; |
| 3543 | |
| 3544 | /* If headphone PA is on, check if userspace receives |
| 3545 | * removal event to sync-up PA's state */ |
| 3546 | if (sitar_is_hph_pa_on(codec)) { |
| 3547 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 3548 | set_bit(SITAR_HPHL_PA_OFF_ACK, &sitar->hph_pa_dac_state); |
| 3549 | set_bit(SITAR_HPHR_PA_OFF_ACK, &sitar->hph_pa_dac_state); |
| 3550 | } else { |
| 3551 | pr_debug("%s PA is off\n", __func__); |
| 3552 | } |
| 3553 | |
| 3554 | if (sitar_is_hph_dac_on(codec, 1)) |
| 3555 | set_bit(SITAR_HPHL_DAC_OFF_ACK, &sitar->hph_pa_dac_state); |
| 3556 | if (sitar_is_hph_dac_on(codec, 0)) |
| 3557 | set_bit(SITAR_HPHR_DAC_OFF_ACK, &sitar->hph_pa_dac_state); |
| 3558 | |
| 3559 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 3560 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_L_DAC_CTL, |
| 3561 | 0xC0, 0x00); |
| 3562 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_R_DAC_CTL, |
| 3563 | 0xC0, 0x00); |
| 3564 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 3565 | } |
| 3566 | |
| 3567 | static void sitar_clr_and_turnon_hph_padac(struct sitar_priv *sitar) |
| 3568 | { |
| 3569 | bool pa_turned_on = false; |
| 3570 | struct snd_soc_codec *codec = sitar->codec; |
| 3571 | u8 wg_time; |
| 3572 | |
| 3573 | wg_time = snd_soc_read(codec, SITAR_A_RX_HPH_CNP_WG_TIME) ; |
| 3574 | wg_time += 1; |
| 3575 | |
| 3576 | if (test_and_clear_bit(SITAR_HPHR_DAC_OFF_ACK, |
| 3577 | &sitar->hph_pa_dac_state)) { |
| 3578 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 3579 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_R_DAC_CTL, |
| 3580 | 0xC0, 0xC0); |
| 3581 | } |
| 3582 | if (test_and_clear_bit(SITAR_HPHL_DAC_OFF_ACK, |
| 3583 | &sitar->hph_pa_dac_state)) { |
| 3584 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 3585 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_L_DAC_CTL, |
| 3586 | 0xC0, 0xC0); |
| 3587 | } |
| 3588 | |
| 3589 | if (test_and_clear_bit(SITAR_HPHR_PA_OFF_ACK, |
| 3590 | &sitar->hph_pa_dac_state)) { |
| 3591 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 3592 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_CNP_EN, 0x10, |
| 3593 | 1 << 4); |
| 3594 | pa_turned_on = true; |
| 3595 | } |
| 3596 | if (test_and_clear_bit(SITAR_HPHL_PA_OFF_ACK, |
| 3597 | &sitar->hph_pa_dac_state)) { |
| 3598 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 3599 | snd_soc_update_bits(sitar->codec, SITAR_A_RX_HPH_CNP_EN, 0x20, |
| 3600 | 1 << 5); |
| 3601 | pa_turned_on = true; |
| 3602 | } |
| 3603 | |
| 3604 | if (pa_turned_on) { |
| 3605 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 3606 | __func__); |
| 3607 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 3608 | } |
| 3609 | } |
| 3610 | |
| 3611 | static void sitar_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 3612 | enum snd_jack_types jack_type) |
| 3613 | { |
| 3614 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3615 | |
| 3616 | if (!insertion) { |
| 3617 | /* Report removal */ |
| 3618 | sitar->hph_status &= ~jack_type; |
| 3619 | if (sitar->mbhc_cfg.headset_jack) { |
| 3620 | /* cancel possibly scheduled btn work and |
| 3621 | * report release if we reported button press */ |
| 3622 | if (sitar_cancel_btn_work(sitar)) { |
| 3623 | pr_debug("%s: button press is canceled\n", |
| 3624 | __func__); |
| 3625 | } else if (sitar->buttons_pressed) { |
| 3626 | pr_debug("%s: Reporting release for reported " |
| 3627 | "button press %d\n", __func__, |
| 3628 | jack_type); |
| 3629 | sitar_snd_soc_jack_report(sitar, |
| 3630 | sitar->mbhc_cfg.button_jack, 0, |
| 3631 | sitar->buttons_pressed); |
| 3632 | sitar->buttons_pressed &= |
| 3633 | ~SITAR_JACK_BUTTON_MASK; |
| 3634 | } |
| 3635 | pr_debug("%s: Reporting removal %d\n", __func__, |
| 3636 | jack_type); |
| 3637 | sitar_snd_soc_jack_report(sitar, |
| 3638 | sitar->mbhc_cfg.headset_jack, |
| 3639 | sitar->hph_status, |
| 3640 | SITAR_JACK_MASK); |
| 3641 | } |
| 3642 | sitar_set_and_turnoff_hph_padac(codec); |
| 3643 | hphocp_off_report(sitar, SND_JACK_OC_HPHR, |
| 3644 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 3645 | hphocp_off_report(sitar, SND_JACK_OC_HPHL, |
| 3646 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 3647 | sitar->current_plug = PLUG_TYPE_NONE; |
| 3648 | sitar->mbhc_polling_active = false; |
| 3649 | } else { |
| 3650 | /* Report insertion */ |
| 3651 | sitar->hph_status |= jack_type; |
| 3652 | |
| 3653 | if (jack_type == SND_JACK_HEADPHONE) |
| 3654 | sitar->current_plug = PLUG_TYPE_HEADPHONE; |
| 3655 | else if (jack_type == SND_JACK_HEADSET) { |
| 3656 | sitar->mbhc_polling_active = true; |
| 3657 | sitar->current_plug = PLUG_TYPE_HEADSET; |
| 3658 | } |
| 3659 | if (sitar->mbhc_cfg.headset_jack) { |
| 3660 | pr_debug("%s: Reporting insertion %d\n", __func__, |
| 3661 | jack_type); |
| 3662 | sitar_snd_soc_jack_report(sitar, |
| 3663 | sitar->mbhc_cfg.headset_jack, |
| 3664 | sitar->hph_status, |
| 3665 | SITAR_JACK_MASK); |
| 3666 | } |
| 3667 | sitar_clr_and_turnon_hph_padac(sitar); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | |
| 3672 | static bool sitar_hs_gpio_level_remove(struct sitar_priv *sitar) |
| 3673 | { |
| 3674 | return (gpio_get_value_cansleep(sitar->mbhc_cfg.gpio) != |
| 3675 | sitar->mbhc_cfg.gpio_level_insert); |
| 3676 | } |
| 3677 | |
| 3678 | static bool sitar_is_invalid_insert_delta(struct snd_soc_codec *codec, |
| 3679 | int mic_volt, int mic_volt_prev) |
| 3680 | { |
| 3681 | int delta = abs(mic_volt - mic_volt_prev); |
| 3682 | if (delta > SITAR_MBHC_FAKE_INSERT_VOLT_DELTA_MV) { |
| 3683 | pr_debug("%s: volt delta %dmv\n", __func__, delta); |
| 3684 | return true; |
| 3685 | } |
| 3686 | return false; |
| 3687 | } |
| 3688 | |
| 3689 | static bool sitar_is_invalid_insertion_range(struct snd_soc_codec *codec, |
| 3690 | s32 mic_volt) |
| 3691 | { |
| 3692 | bool invalid = false; |
| 3693 | |
| 3694 | if (mic_volt < SITAR_MBHC_FAKE_INSERT_HIGH |
| 3695 | && (mic_volt > SITAR_MBHC_FAKE_INSERT_LOW)) { |
| 3696 | invalid = true; |
| 3697 | } |
| 3698 | |
| 3699 | return invalid; |
| 3700 | } |
| 3701 | |
| 3702 | static bool sitar_codec_is_invalid_plug(struct snd_soc_codec *codec, |
| 3703 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT], |
| 3704 | enum sitar_mbhc_plug_type plug_type[MBHC_NUM_DCE_PLUG_DETECT]) |
| 3705 | { |
| 3706 | int i; |
| 3707 | bool r = false; |
| 3708 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3709 | struct sitar_mbhc_plug_type_cfg *plug_type_ptr = |
| 3710 | SITAR_MBHC_CAL_PLUG_TYPE_PTR(sitar->mbhc_cfg.calibration); |
| 3711 | |
| 3712 | for (i = 0 ; i < MBHC_NUM_DCE_PLUG_DETECT && !r; i++) { |
| 3713 | if (mic_mv[i] < plug_type_ptr->v_no_mic) |
| 3714 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 3715 | else if (mic_mv[i] < plug_type_ptr->v_hs_max) |
| 3716 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 3717 | else if (mic_mv[i] > plug_type_ptr->v_hs_max) |
| 3718 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 3719 | |
| 3720 | r = sitar_is_invalid_insertion_range(codec, mic_mv[i]); |
| 3721 | if (!r && i > 0) { |
| 3722 | if (plug_type[i-1] != plug_type[i]) |
| 3723 | r = true; |
| 3724 | else |
| 3725 | r = sitar_is_invalid_insert_delta(codec, |
| 3726 | mic_mv[i], |
| 3727 | mic_mv[i - 1]); |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | return r; |
| 3732 | } |
| 3733 | |
| 3734 | /* called under codec_resource_lock acquisition */ |
| 3735 | void sitar_find_plug_and_report(struct snd_soc_codec *codec, |
| 3736 | enum sitar_mbhc_plug_type plug_type) |
| 3737 | { |
| 3738 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3739 | |
| 3740 | if (plug_type == PLUG_TYPE_HEADPHONE |
| 3741 | && sitar->current_plug == PLUG_TYPE_NONE) { |
| 3742 | /* Nothing was reported previously |
| 3743 | * reporte a headphone |
| 3744 | */ |
| 3745 | sitar_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 3746 | sitar_codec_cleanup_hs_polling(codec); |
| 3747 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 3748 | /* If Headphone was reported previously, this will |
| 3749 | * only report the mic line |
| 3750 | */ |
| 3751 | sitar_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 3752 | msleep(100); |
| 3753 | sitar_codec_start_hs_polling(codec); |
| 3754 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
| 3755 | if (sitar->current_plug == PLUG_TYPE_NONE) |
| 3756 | sitar_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 3757 | sitar_codec_cleanup_hs_polling(codec); |
| 3758 | pr_debug("setup mic trigger for further detection\n"); |
| 3759 | sitar->lpi_enabled = true; |
| 3760 | /* TODO ::: sitar_codec_enable_hs_detect */ |
| 3761 | pr_err("%s(): High impedence hph not supported\n", __func__); |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | /* should be called under interrupt context that hold suspend */ |
| 3766 | static void sitar_schedule_hs_detect_plug(struct sitar_priv *sitar) |
| 3767 | { |
| 3768 | pr_debug("%s: scheduling sitar_hs_correct_gpio_plug\n", __func__); |
| 3769 | sitar->hs_detect_work_stop = false; |
| 3770 | wcd9xxx_lock_sleep(sitar->codec->control_data); |
| 3771 | schedule_work(&sitar->hs_correct_plug_work); |
| 3772 | } |
| 3773 | |
| 3774 | /* called under codec_resource_lock acquisition */ |
| 3775 | static void sitar_cancel_hs_detect_plug(struct sitar_priv *sitar) |
| 3776 | { |
| 3777 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 3778 | sitar->hs_detect_work_stop = true; |
| 3779 | wmb(); |
| 3780 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
| 3781 | if (cancel_work_sync(&sitar->hs_correct_plug_work)) { |
| 3782 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 3783 | wcd9xxx_unlock_sleep(sitar->codec->control_data); |
| 3784 | } |
| 3785 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
| 3786 | } |
| 3787 | |
| 3788 | static void sitar_hs_correct_gpio_plug(struct work_struct *work) |
| 3789 | { |
| 3790 | struct sitar_priv *sitar; |
| 3791 | struct snd_soc_codec *codec; |
| 3792 | int retry = 0, i; |
| 3793 | bool correction = false; |
| 3794 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3795 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3796 | enum sitar_mbhc_plug_type plug_type[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3797 | unsigned long timeout; |
| 3798 | |
| 3799 | sitar = container_of(work, struct sitar_priv, hs_correct_plug_work); |
| 3800 | codec = sitar->codec; |
| 3801 | |
| 3802 | pr_debug("%s: enter\n", __func__); |
| 3803 | sitar->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 3804 | |
| 3805 | /* Keep override on during entire plug type correction work. |
| 3806 | * |
| 3807 | * This is okay under the assumption that any GPIO irqs which use |
| 3808 | * MBHC block cancel and sync this work so override is off again |
| 3809 | * prior to GPIO interrupt handler's MBHC block usage. |
| 3810 | * Also while this correction work is running, we can guarantee |
| 3811 | * DAPM doesn't use any MBHC block as this work only runs with |
| 3812 | * headphone detection. |
| 3813 | */ |
| 3814 | sitar_turn_onoff_override(codec, true); |
| 3815 | |
| 3816 | timeout = jiffies + msecs_to_jiffies(SITAR_HS_DETECT_PLUG_TIME_MS); |
| 3817 | while (!time_after(jiffies, timeout)) { |
| 3818 | ++retry; |
| 3819 | rmb(); |
| 3820 | if (sitar->hs_detect_work_stop) { |
| 3821 | pr_debug("%s: stop requested\n", __func__); |
| 3822 | break; |
| 3823 | } |
| 3824 | |
| 3825 | msleep(SITAR_HS_DETECT_PLUG_INERVAL_MS); |
| 3826 | if (sitar_hs_gpio_level_remove(sitar)) { |
| 3827 | pr_debug("%s: GPIO value is low\n", __func__); |
| 3828 | break; |
| 3829 | } |
| 3830 | |
| 3831 | /* can race with removal interrupt */ |
| 3832 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
| 3833 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 3834 | mb_v[i] = __sitar_codec_sta_dce(codec, 1, true, true); |
| 3835 | mic_mv[i] = sitar_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 3836 | pr_debug("%s : DCE run %d, mic_mv = %d(%x)\n", |
| 3837 | __func__, retry, mic_mv[i], mb_v[i]); |
| 3838 | } |
| 3839 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
| 3840 | |
| 3841 | if (sitar_codec_is_invalid_plug(codec, mic_mv, plug_type)) { |
| 3842 | pr_debug("Invalid plug in attempt # %d\n", retry); |
| 3843 | if (retry == NUM_ATTEMPTS_TO_REPORT && |
| 3844 | sitar->current_plug == PLUG_TYPE_NONE) { |
| 3845 | sitar_codec_report_plug(codec, 1, |
| 3846 | SND_JACK_HEADPHONE); |
| 3847 | } |
| 3848 | } else if (!sitar_codec_is_invalid_plug(codec, mic_mv, |
| 3849 | plug_type) && |
| 3850 | plug_type[0] == PLUG_TYPE_HEADPHONE) { |
| 3851 | pr_debug("Good headphone detected, continue polling mic\n"); |
| 3852 | if (sitar->current_plug == PLUG_TYPE_NONE) { |
| 3853 | sitar_codec_report_plug(codec, 1, |
| 3854 | SND_JACK_HEADPHONE); |
| 3855 | } |
| 3856 | } else { |
| 3857 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
| 3858 | /* Turn off override */ |
| 3859 | sitar_turn_onoff_override(codec, false); |
| 3860 | sitar_find_plug_and_report(codec, plug_type[0]); |
| 3861 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
| 3862 | pr_debug("Attempt %d found correct plug %d\n", retry, |
| 3863 | plug_type[0]); |
| 3864 | correction = true; |
| 3865 | break; |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | /* Turn off override */ |
| 3870 | if (!correction) |
| 3871 | sitar_turn_onoff_override(codec, false); |
| 3872 | |
| 3873 | sitar->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 3874 | pr_debug("%s: leave\n", __func__); |
| 3875 | /* unlock sleep */ |
| 3876 | wcd9xxx_unlock_sleep(sitar->codec->control_data); |
| 3877 | } |
| 3878 | |
| 3879 | /* called under codec_resource_lock acquisition */ |
| 3880 | static void sitar_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 3881 | { |
| 3882 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3883 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3884 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3885 | enum sitar_mbhc_plug_type plug_type[MBHC_NUM_DCE_PLUG_DETECT]; |
| 3886 | int i; |
| 3887 | |
| 3888 | pr_debug("%s: enter\n", __func__); |
| 3889 | |
| 3890 | sitar_turn_onoff_override(codec, true); |
| 3891 | mb_v[0] = sitar_codec_setup_hs_polling(codec); |
| 3892 | mic_mv[0] = sitar_codec_sta_dce_v(codec, 1, mb_v[0]); |
| 3893 | pr_debug("%s: DCE run 1, mic_mv = %d\n", __func__, mic_mv[0]); |
| 3894 | |
| 3895 | for (i = 1; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 3896 | mb_v[i] = __sitar_codec_sta_dce(codec, 1, true, true); |
| 3897 | mic_mv[i] = sitar_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 3898 | pr_debug("%s: DCE run %d, mic_mv = %d\n", __func__, i + 1, |
| 3899 | mic_mv[i]); |
| 3900 | } |
| 3901 | sitar_turn_onoff_override(codec, false); |
| 3902 | |
| 3903 | if (sitar_hs_gpio_level_remove(sitar)) { |
| 3904 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 3905 | __func__); |
| 3906 | return; |
| 3907 | } |
| 3908 | |
| 3909 | if (sitar_codec_is_invalid_plug(codec, mic_mv, plug_type)) { |
| 3910 | sitar_schedule_hs_detect_plug(sitar); |
| 3911 | } else if (plug_type[0] == PLUG_TYPE_HEADPHONE) { |
| 3912 | sitar_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 3913 | sitar_schedule_hs_detect_plug(sitar); |
| 3914 | } else if (plug_type[0] == PLUG_TYPE_HEADSET) { |
| 3915 | pr_debug("%s: Valid plug found, determine plug type\n", |
| 3916 | __func__); |
| 3917 | sitar_find_plug_and_report(codec, plug_type[0]); |
| 3918 | } |
| 3919 | |
| 3920 | } |
| 3921 | |
| 3922 | /* called under codec_resource_lock acquisition */ |
| 3923 | static void sitar_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 3924 | { |
| 3925 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 3926 | const struct sitar_mbhc_plug_detect_cfg *plug_det = |
| 3927 | SITAR_MBHC_CAL_PLUG_DET_PTR(sitar->mbhc_cfg.calibration); |
| 3928 | |
| 3929 | if (plug_det->t_ins_complete > 20) |
| 3930 | msleep(plug_det->t_ins_complete); |
| 3931 | else |
| 3932 | usleep_range(plug_det->t_ins_complete * 1000, |
| 3933 | plug_det->t_ins_complete * 1000); |
| 3934 | |
| 3935 | if (sitar_hs_gpio_level_remove(sitar)) |
| 3936 | pr_debug("%s: GPIO value is low when determining " |
| 3937 | "plug\n", __func__); |
| 3938 | else |
| 3939 | sitar_codec_decide_gpio_plug(codec); |
| 3940 | |
| 3941 | return; |
| 3942 | } |
| 3943 | |
| 3944 | static void sitar_hs_gpio_handler(struct snd_soc_codec *codec) |
| 3945 | { |
| 3946 | bool insert; |
| 3947 | struct sitar_priv *priv = snd_soc_codec_get_drvdata(codec); |
| 3948 | bool is_removed = false; |
| 3949 | |
| 3950 | pr_debug("%s: enter\n", __func__); |
| 3951 | |
| 3952 | priv->in_gpio_handler = true; |
| 3953 | /* Wait here for debounce time */ |
| 3954 | usleep_range(SITAR_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 3955 | SITAR_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 3956 | |
| 3957 | SITAR_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 3958 | |
| 3959 | /* cancel pending button press */ |
| 3960 | if (sitar_cancel_btn_work(priv)) |
| 3961 | pr_debug("%s: button press is canceled\n", __func__); |
| 3962 | |
| 3963 | insert = (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 3964 | priv->mbhc_cfg.gpio_level_insert); |
| 3965 | if ((priv->current_plug == PLUG_TYPE_NONE) && insert) { |
| 3966 | priv->lpi_enabled = false; |
| 3967 | wmb(); |
| 3968 | |
| 3969 | /* cancel detect plug */ |
| 3970 | sitar_cancel_hs_detect_plug(priv); |
| 3971 | |
| 3972 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 3973 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, |
| 3974 | 0x00); |
| 3975 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x01, 0x00); |
| 3976 | sitar_codec_detect_plug_type(codec); |
| 3977 | } else if ((priv->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 3978 | priv->lpi_enabled = false; |
| 3979 | wmb(); |
| 3980 | |
| 3981 | /* cancel detect plug */ |
| 3982 | sitar_cancel_hs_detect_plug(priv); |
| 3983 | |
| 3984 | if (priv->current_plug == PLUG_TYPE_HEADPHONE) { |
| 3985 | sitar_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 3986 | is_removed = true; |
| 3987 | } else if (priv->current_plug == PLUG_TYPE_HEADSET) { |
| 3988 | sitar_codec_pause_hs_polling(codec); |
| 3989 | sitar_codec_cleanup_hs_polling(codec); |
| 3990 | sitar_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 3991 | is_removed = true; |
| 3992 | } |
| 3993 | |
| 3994 | if (is_removed) { |
| 3995 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 3996 | snd_soc_update_bits(codec, |
| 3997 | priv->mbhc_bias_regs.ctl_reg, 0x01, |
| 3998 | 0x01); |
| 3999 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x01, |
| 4000 | 0x01); |
| 4001 | /* Make sure mic trigger is turned off */ |
| 4002 | snd_soc_update_bits(codec, |
| 4003 | priv->mbhc_bias_regs.ctl_reg, |
| 4004 | 0x01, 0x01); |
| 4005 | snd_soc_update_bits(codec, |
| 4006 | priv->mbhc_bias_regs.mbhc_reg, |
| 4007 | 0x90, 0x00); |
| 4008 | /* Reset MBHC State Machine */ |
| 4009 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, |
| 4010 | 0x08, 0x08); |
| 4011 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_CLK_CTL, |
| 4012 | 0x08, 0x00); |
| 4013 | /* Turn off override */ |
| 4014 | sitar_turn_onoff_override(codec, false); |
| 4015 | } |
| 4016 | } |
| 4017 | |
| 4018 | priv->in_gpio_handler = false; |
| 4019 | SITAR_RELEASE_LOCK(priv->codec_resource_lock); |
| 4020 | pr_debug("%s: leave\n", __func__); |
| 4021 | } |
| 4022 | |
| 4023 | static irqreturn_t sitar_mechanical_plug_detect_irq(int irq, void *data) |
| 4024 | { |
| 4025 | int r = IRQ_HANDLED; |
| 4026 | struct snd_soc_codec *codec = data; |
| 4027 | |
| 4028 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 4029 | pr_warn("%s(): Failed to hold suspend\n", __func__); |
| 4030 | r = IRQ_NONE; |
| 4031 | } else { |
| 4032 | sitar_hs_gpio_handler(codec); |
| 4033 | wcd9xxx_unlock_sleep(codec->control_data); |
| 4034 | } |
| 4035 | return r; |
| 4036 | } |
| 4037 | |
| 4038 | static int sitar_mbhc_init_and_calibrate(struct snd_soc_codec *codec) |
| 4039 | { |
| 4040 | int rc = 0; |
| 4041 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 4042 | |
| 4043 | sitar->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 4044 | sitar_mbhc_init(codec); |
| 4045 | sitar_mbhc_cal(codec); |
| 4046 | sitar_mbhc_calc_thres(codec); |
| 4047 | sitar->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 4048 | sitar_codec_calibrate_hs_polling(codec); |
| 4049 | |
| 4050 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 4051 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.ctl_reg, |
| 4052 | 0x01, 0x01); |
| 4053 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, |
| 4054 | 0x01, 0x01); |
| 4055 | |
| 4056 | rc = request_threaded_irq(sitar->mbhc_cfg.gpio_irq, |
| 4057 | NULL, |
| 4058 | sitar_mechanical_plug_detect_irq, |
| 4059 | (IRQF_TRIGGER_RISING | |
| 4060 | IRQF_TRIGGER_FALLING), |
| 4061 | "sitar-hs-gpio", codec); |
| 4062 | |
| 4063 | if (!IS_ERR_VALUE(rc)) { |
| 4064 | rc = enable_irq_wake(sitar->mbhc_cfg.gpio_irq); |
| 4065 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, |
| 4066 | 0x10, 0x10); |
| 4067 | wcd9xxx_enable_irq(codec->control_data, |
| 4068 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 4069 | wcd9xxx_enable_irq(codec->control_data, |
| 4070 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 4071 | /* Bootup time detection */ |
| 4072 | sitar_hs_gpio_handler(codec); |
| 4073 | } |
| 4074 | |
| 4075 | return rc; |
| 4076 | } |
| 4077 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4078 | static void mbhc_fw_read(struct work_struct *work) |
| 4079 | { |
| 4080 | struct delayed_work *dwork; |
| 4081 | struct sitar_priv *sitar; |
| 4082 | struct snd_soc_codec *codec; |
| 4083 | const struct firmware *fw; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4084 | int ret = -1, retry = 0; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4085 | |
| 4086 | dwork = to_delayed_work(work); |
| 4087 | sitar = container_of(dwork, struct sitar_priv, |
| 4088 | mbhc_firmware_dwork); |
| 4089 | codec = sitar->codec; |
| 4090 | |
| 4091 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 4092 | retry++; |
| 4093 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 4094 | __func__, retry); |
| 4095 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 4096 | codec->dev); |
| 4097 | |
| 4098 | if (ret != 0) { |
| 4099 | usleep_range(MBHC_FW_READ_TIMEOUT, |
| 4100 | MBHC_FW_READ_TIMEOUT); |
| 4101 | } else { |
| 4102 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 4103 | break; |
| 4104 | } |
| 4105 | } |
| 4106 | |
| 4107 | if (ret != 0) { |
| 4108 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 4109 | __func__); |
| 4110 | } else if (sitar_mbhc_fw_validate(fw) == false) { |
| 4111 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 4112 | __func__); |
| 4113 | release_firmware(fw); |
| 4114 | } else { |
| 4115 | sitar->calibration = (void *)fw->data; |
| 4116 | sitar->mbhc_fw = fw; |
| 4117 | } |
| 4118 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4119 | sitar_mbhc_init_and_calibrate(codec); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | int sitar_hs_detect(struct snd_soc_codec *codec, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4123 | const struct sitar_mbhc_config *cfg) |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4124 | { |
| 4125 | struct sitar_priv *sitar; |
| 4126 | int rc = 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4127 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4128 | if (!codec || !cfg->calibration) { |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4129 | pr_err("Error: no codec or calibration\n"); |
| 4130 | return -EINVAL; |
| 4131 | } |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4132 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4133 | if (cfg->mclk_rate != SITAR_MCLK_RATE_12288KHZ) { |
| 4134 | if (cfg->mclk_rate == SITAR_MCLK_RATE_9600KHZ) |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4135 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4136 | cfg->mclk_rate); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4137 | else |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4138 | pr_err("Error: unsupported clock rate %d\n", |
| 4139 | cfg->mclk_rate); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4140 | return -EINVAL; |
| 4141 | } |
| 4142 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4143 | sitar = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4144 | sitar->mbhc_cfg = *cfg; |
| 4145 | sitar->in_gpio_handler = false; |
| 4146 | sitar->current_plug = PLUG_TYPE_NONE; |
| 4147 | sitar->lpi_enabled = false; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4148 | sitar_get_mbhc_micbias_regs(codec, &sitar->mbhc_bias_regs); |
| 4149 | |
| 4150 | /* Put CFILT in fast mode by default */ |
| 4151 | snd_soc_update_bits(codec, sitar->mbhc_bias_regs.cfilt_ctl, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4152 | 0x40, SITAR_CFILT_FAST_MODE); |
| 4153 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4154 | INIT_DELAYED_WORK(&sitar->mbhc_firmware_dwork, mbhc_fw_read); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4155 | INIT_DELAYED_WORK(&sitar->mbhc_btn_dwork, btn_lpress_fn); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4156 | INIT_WORK(&sitar->hphlocp_work, hphlocp_off_report); |
| 4157 | INIT_WORK(&sitar->hphrocp_work, hphrocp_off_report); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4158 | INIT_WORK(&sitar->hs_correct_plug_work, |
| 4159 | sitar_hs_correct_gpio_plug); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4160 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4161 | if (!sitar->mbhc_cfg.read_fw_bin) { |
| 4162 | rc = sitar_mbhc_init_and_calibrate(codec); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4163 | } else { |
| 4164 | schedule_delayed_work(&sitar->mbhc_firmware_dwork, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4165 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | return rc; |
| 4169 | } |
| 4170 | EXPORT_SYMBOL_GPL(sitar_hs_detect); |
| 4171 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4172 | static int sitar_determine_button(const struct sitar_priv *priv, |
| 4173 | const s32 bias_mv) |
| 4174 | { |
| 4175 | s16 *v_btn_low, *v_btn_high; |
| 4176 | struct sitar_mbhc_btn_detect_cfg *btn_det; |
| 4177 | int i, btn = -1; |
| 4178 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4179 | btn_det = SITAR_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4180 | v_btn_low = sitar_mbhc_cal_btn_det_mp(btn_det, SITAR_BTN_DET_V_BTN_LOW); |
| 4181 | v_btn_high = sitar_mbhc_cal_btn_det_mp(btn_det, |
| 4182 | SITAR_BTN_DET_V_BTN_HIGH); |
| 4183 | for (i = 0; i < btn_det->num_btn; i++) { |
| 4184 | if ((v_btn_low[i] <= bias_mv) && (v_btn_high[i] >= bias_mv)) { |
| 4185 | btn = i; |
| 4186 | break; |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | if (btn == -1) |
| 4191 | pr_debug("%s: couldn't find button number for mic mv %d\n", |
| 4192 | __func__, bias_mv); |
| 4193 | |
| 4194 | return btn; |
| 4195 | } |
| 4196 | |
| 4197 | static int sitar_get_button_mask(const int btn) |
| 4198 | { |
| 4199 | int mask = 0; |
| 4200 | switch (btn) { |
| 4201 | case 0: |
| 4202 | mask = SND_JACK_BTN_0; |
| 4203 | break; |
| 4204 | case 1: |
| 4205 | mask = SND_JACK_BTN_1; |
| 4206 | break; |
| 4207 | case 2: |
| 4208 | mask = SND_JACK_BTN_2; |
| 4209 | break; |
| 4210 | case 3: |
| 4211 | mask = SND_JACK_BTN_3; |
| 4212 | break; |
| 4213 | case 4: |
| 4214 | mask = SND_JACK_BTN_4; |
| 4215 | break; |
| 4216 | case 5: |
| 4217 | mask = SND_JACK_BTN_5; |
| 4218 | break; |
| 4219 | case 6: |
| 4220 | mask = SND_JACK_BTN_6; |
| 4221 | break; |
| 4222 | case 7: |
| 4223 | mask = SND_JACK_BTN_7; |
| 4224 | break; |
| 4225 | } |
| 4226 | return mask; |
| 4227 | } |
| 4228 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4229 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4230 | static irqreturn_t sitar_dce_handler(int irq, void *data) |
| 4231 | { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4232 | int i, mask; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4233 | short dce, sta, bias_value_dce; |
| 4234 | s32 mv, stamv, bias_mv_dce; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4235 | int btn = -1, meas = 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4236 | struct sitar_priv *priv = data; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4237 | const struct sitar_mbhc_btn_detect_cfg *d = |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4238 | SITAR_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4239 | short btnmeas[d->n_btn_meas + 1]; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4240 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 4241 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4242 | int n_btn_meas = d->n_btn_meas; |
| 4243 | u8 mbhc_status = snd_soc_read(codec, SITAR_A_CDC_MBHC_B1_STATUS) & 0x3E; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4244 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4245 | pr_debug("%s: enter\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4246 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4247 | SITAR_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 4248 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 4249 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 4250 | __func__); |
| 4251 | goto done; |
| 4252 | } |
| 4253 | |
| 4254 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 4255 | |
| 4256 | if (!priv->mbhc_polling_active) { |
| 4257 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 4258 | __func__); |
| 4259 | goto done; |
| 4260 | } |
| 4261 | |
| 4262 | dce = sitar_codec_read_dce_result(codec); |
| 4263 | mv = sitar_codec_sta_dce_v(codec, 1, dce); |
| 4264 | |
| 4265 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 4266 | if (priv->in_gpio_handler) { |
| 4267 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 4268 | __func__); |
| 4269 | btn = -1; |
| 4270 | goto done; |
| 4271 | } |
| 4272 | |
| 4273 | if (mbhc_status != SITAR_MBHC_STATUS_REL_DETECTION) { |
| 4274 | if (priv->mbhc_last_resume && |
| 4275 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 4276 | pr_debug("%s: Button is already released shortly after " |
| 4277 | "resume\n", __func__); |
| 4278 | n_btn_meas = 0; |
| 4279 | } else { |
| 4280 | pr_debug("%s: Button is already released without " |
| 4281 | "resume", __func__); |
| 4282 | sta = sitar_codec_read_sta_result(codec); |
| 4283 | stamv = sitar_codec_sta_dce_v(codec, 0, sta); |
| 4284 | btn = sitar_determine_button(priv, mv); |
| 4285 | if (btn != sitar_determine_button(priv, stamv)) |
| 4286 | btn = -1; |
| 4287 | goto done; |
| 4288 | } |
| 4289 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4290 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4291 | /* determine pressed button */ |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4292 | btnmeas[meas++] = sitar_determine_button(priv, mv); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4293 | pr_debug("%s: meas %d - DCE %d,%d, button %d\n", __func__, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4294 | meas - 1, dce, mv, btnmeas[meas - 1]); |
| 4295 | if (n_btn_meas == 0) |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4296 | btn = btnmeas[0]; |
| 4297 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4298 | bias_value_dce = sitar_codec_sta_dce(codec, 1, false); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4299 | bias_mv_dce = sitar_codec_sta_dce_v(codec, 1, bias_value_dce); |
| 4300 | btnmeas[meas] = sitar_determine_button(priv, bias_mv_dce); |
| 4301 | pr_debug("%s: meas %d - DCE %d,%d, button %d\n", |
| 4302 | __func__, meas, bias_value_dce, bias_mv_dce, |
| 4303 | btnmeas[meas]); |
| 4304 | /* if large enough measurements are collected, |
| 4305 | * start to check if last all n_btn_con measurements were |
| 4306 | * in same button low/high range */ |
| 4307 | if (meas + 1 >= d->n_btn_con) { |
| 4308 | for (i = 0; i < d->n_btn_con; i++) |
| 4309 | if ((btnmeas[meas] < 0) || |
| 4310 | (btnmeas[meas] != btnmeas[meas - i])) |
| 4311 | break; |
| 4312 | if (i == d->n_btn_con) { |
| 4313 | /* button pressed */ |
| 4314 | btn = btnmeas[meas]; |
| 4315 | break; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4316 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 4317 | /* if left measurements are less than n_btn_con, |
| 4318 | * it's impossible to find button number */ |
| 4319 | break; |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4320 | } |
| 4321 | } |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4322 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4323 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4324 | if (btn >= 0) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4325 | if (priv->in_gpio_handler) { |
| 4326 | pr_debug("%s: GPIO already triggered, ignore button " |
| 4327 | "press\n", __func__); |
| 4328 | goto done; |
| 4329 | } |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4330 | mask = sitar_get_button_mask(btn); |
| 4331 | priv->buttons_pressed |= mask; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4332 | wcd9xxx_lock_sleep(core); |
| 4333 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 4334 | msecs_to_jiffies(400)) == 0) { |
| 4335 | WARN(1, "Button pressed twice without release" |
| 4336 | "event\n"); |
| 4337 | wcd9xxx_unlock_sleep(core); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4338 | } |
| 4339 | } else { |
| 4340 | pr_debug("%s: bogus button press, too short press?\n", |
| 4341 | __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4342 | } |
| 4343 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4344 | done: |
| 4345 | pr_debug("%s: leave\n", __func__); |
| 4346 | SITAR_RELEASE_LOCK(priv->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4347 | return IRQ_HANDLED; |
| 4348 | } |
| 4349 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4350 | static int sitar_is_fake_press(struct sitar_priv *priv) |
| 4351 | { |
| 4352 | int i; |
| 4353 | int r = 0; |
| 4354 | struct snd_soc_codec *codec = priv->codec; |
| 4355 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
| 4356 | short mb_v; |
| 4357 | |
| 4358 | for (i = 0; i < dces; i++) { |
| 4359 | usleep_range(10000, 10000); |
| 4360 | if (i == 0) { |
| 4361 | mb_v = sitar_codec_sta_dce(codec, 0, true); |
| 4362 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 4363 | sitar_codec_sta_dce_v(codec, 0, mb_v)); |
| 4364 | if (mb_v < (short)priv->mbhc_data.v_b1_hu || |
| 4365 | mb_v > (short)priv->mbhc_data.v_ins_hu) { |
| 4366 | r = 1; |
| 4367 | break; |
| 4368 | } |
| 4369 | } else { |
| 4370 | mb_v = sitar_codec_sta_dce(codec, 1, true); |
| 4371 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 4372 | sitar_codec_sta_dce_v(codec, 1, mb_v)); |
| 4373 | if (mb_v < (short)priv->mbhc_data.v_b1_h || |
| 4374 | mb_v > (short)priv->mbhc_data.v_ins_h) { |
| 4375 | r = 1; |
| 4376 | break; |
| 4377 | } |
| 4378 | } |
| 4379 | } |
| 4380 | |
| 4381 | return r; |
| 4382 | } |
| 4383 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4384 | static irqreturn_t sitar_release_handler(int irq, void *data) |
| 4385 | { |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4386 | int ret; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4387 | struct sitar_priv *priv = data; |
| 4388 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4389 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4390 | pr_debug("%s: enter\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4391 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4392 | SITAR_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 4393 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4394 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4395 | if (priv->buttons_pressed & SITAR_JACK_BUTTON_MASK) { |
| 4396 | ret = sitar_cancel_btn_work(priv); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4397 | if (ret == 0) { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4398 | pr_debug("%s: Reporting long button release event\n", |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4399 | __func__); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4400 | if (priv->mbhc_cfg.button_jack) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4401 | sitar_snd_soc_jack_report(priv, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4402 | priv->mbhc_cfg.button_jack, 0, |
| 4403 | priv->buttons_pressed); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4404 | } else { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4405 | if (sitar_is_fake_press(priv)) { |
| 4406 | pr_debug("%s: Fake button press interrupt\n", |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4407 | __func__); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4408 | } else if (priv->mbhc_cfg.button_jack) { |
| 4409 | if (priv->in_gpio_handler) { |
| 4410 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 4411 | __func__); |
| 4412 | } else { |
| 4413 | pr_debug("%s: Reporting short button 0 " |
| 4414 | "press and release\n", |
| 4415 | __func__); |
| 4416 | sitar_snd_soc_jack_report(priv, |
| 4417 | priv->mbhc_cfg.button_jack, |
| 4418 | priv->buttons_pressed, |
| 4419 | priv->buttons_pressed); |
| 4420 | sitar_snd_soc_jack_report(priv, |
| 4421 | priv->mbhc_cfg.button_jack, 0, |
| 4422 | priv->buttons_pressed); |
| 4423 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4424 | } |
| 4425 | } |
| 4426 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4427 | priv->buttons_pressed &= ~SITAR_JACK_BUTTON_MASK; |
| 4428 | } |
| 4429 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4430 | sitar_codec_calibrate_hs_polling(codec); |
| 4431 | |
| 4432 | if (priv->mbhc_cfg.gpio) |
| 4433 | msleep(SITAR_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
| 4434 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4435 | sitar_codec_start_hs_polling(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4436 | |
| 4437 | pr_debug("%s: leave\n", __func__); |
| 4438 | SITAR_RELEASE_LOCK(priv->codec_resource_lock); |
| 4439 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4440 | return IRQ_HANDLED; |
| 4441 | } |
| 4442 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4443 | static irqreturn_t sitar_hphl_ocp_irq(int irq, void *data) |
| 4444 | { |
| 4445 | struct sitar_priv *sitar = data; |
| 4446 | struct snd_soc_codec *codec; |
| 4447 | |
| 4448 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 4449 | |
| 4450 | if (sitar) { |
| 4451 | codec = sitar->codec; |
| 4452 | if (sitar->hphlocp_cnt++ < SITAR_OCP_ATTEMPT) { |
| 4453 | pr_info("%s: retry\n", __func__); |
| 4454 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4455 | 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4456 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4457 | 0x10); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4458 | } else { |
| 4459 | wcd9xxx_disable_irq(codec->control_data, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4460 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4461 | sitar->hphlocp_cnt = 0; |
| 4462 | sitar->hph_status |= SND_JACK_OC_HPHL; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4463 | if (sitar->mbhc_cfg.headset_jack) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4464 | sitar_snd_soc_jack_report(sitar, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4465 | sitar->mbhc_cfg.headset_jack, |
| 4466 | sitar->hph_status, |
| 4467 | SITAR_JACK_MASK); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4468 | } |
| 4469 | } else { |
| 4470 | pr_err("%s: Bad sitar private data\n", __func__); |
| 4471 | } |
| 4472 | |
| 4473 | return IRQ_HANDLED; |
| 4474 | } |
| 4475 | |
| 4476 | static irqreturn_t sitar_hphr_ocp_irq(int irq, void *data) |
| 4477 | { |
| 4478 | struct sitar_priv *sitar = data; |
| 4479 | struct snd_soc_codec *codec; |
| 4480 | |
| 4481 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 4482 | |
| 4483 | if (sitar) { |
| 4484 | codec = sitar->codec; |
| 4485 | if (sitar->hphrocp_cnt++ < SITAR_OCP_ATTEMPT) { |
| 4486 | pr_info("%s: retry\n", __func__); |
| 4487 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 4488 | 0x00); |
| 4489 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, 0x10, |
| 4490 | 0x10); |
| 4491 | } else { |
| 4492 | wcd9xxx_disable_irq(codec->control_data, |
| 4493 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 4494 | sitar->hphrocp_cnt = 0; |
| 4495 | sitar->hph_status |= SND_JACK_OC_HPHR; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4496 | if (sitar->mbhc_cfg.headset_jack) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4497 | sitar_snd_soc_jack_report(sitar, |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4498 | sitar->mbhc_cfg.headset_jack, |
| 4499 | sitar->hph_status, |
| 4500 | SITAR_JACK_MASK); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4501 | } |
| 4502 | } else { |
| 4503 | pr_err("%s: Bad sitar private data\n", __func__); |
| 4504 | } |
| 4505 | |
| 4506 | return IRQ_HANDLED; |
| 4507 | } |
| 4508 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4509 | static irqreturn_t sitar_hs_insert_irq(int irq, void *data) |
| 4510 | { |
| 4511 | struct sitar_priv *priv = data; |
| 4512 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4513 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4514 | pr_debug("%s: enter\n", __func__); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4515 | SITAR_ACQUIRE_LOCK(priv->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4516 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4517 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4518 | snd_soc_update_bits(codec, SITAR_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 4519 | |
| 4520 | /* Turn off both HPH and MIC line schmitt triggers */ |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4521 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4522 | snd_soc_update_bits(codec, SITAR_A_MBHC_HPH, 0x13, 0x00); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4523 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4524 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4525 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4526 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4527 | rmb(); |
| 4528 | if (priv->lpi_enabled) |
| 4529 | msleep(100); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4530 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4531 | rmb(); |
| 4532 | if (!priv->lpi_enabled) { |
| 4533 | pr_debug("%s: lpi is disabled\n", __func__); |
| 4534 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 4535 | priv->mbhc_cfg.gpio_level_insert) { |
| 4536 | pr_debug("%s: Valid insertion, " |
| 4537 | "detect plug type\n", __func__); |
| 4538 | sitar_codec_decide_gpio_plug(codec); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4539 | } else { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4540 | pr_debug("%s: Invalid insertion, " |
| 4541 | "stop plug detection\n", __func__); |
| 4542 | } |
| 4543 | SITAR_RELEASE_LOCK(priv->codec_resource_lock); |
| 4544 | return IRQ_HANDLED; |
| 4545 | } |
| 4546 | |
| 4547 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 4548 | { |
| 4549 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 4550 | struct sitar_mbhc_plug_type_cfg *plug_type = |
| 4551 | SITAR_MBHC_CAL_PLUG_TYPE_PTR(sitar->mbhc_cfg.calibration); |
| 4552 | |
| 4553 | return (!(mic_mv > SITAR_MBHC_FAKE_INSERT_LOW |
| 4554 | && mic_mv < SITAR_MBHC_FAKE_INSERT_HIGH) |
| 4555 | && (mic_mv > plug_type->v_no_mic) |
| 4556 | && (mic_mv < plug_type->v_hs_max)) ? true : false; |
| 4557 | } |
| 4558 | |
| 4559 | /* called under codec_resource_lock acquisition |
| 4560 | * returns true if mic voltage range is back to normal insertion |
| 4561 | * returns false either if timedout or removed */ |
| 4562 | static bool sitar_hs_remove_settle(struct snd_soc_codec *codec) |
| 4563 | { |
| 4564 | int i; |
| 4565 | bool timedout, settled = false; |
| 4566 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 4567 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 4568 | unsigned long retry = 0, timeout; |
| 4569 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 4570 | |
| 4571 | timeout = jiffies + msecs_to_jiffies(SITAR_HS_DETECT_PLUG_TIME_MS); |
| 4572 | while (!(timedout = time_after(jiffies, timeout))) { |
| 4573 | retry++; |
| 4574 | if (sitar_hs_gpio_level_remove(sitar)) { |
| 4575 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 4576 | break; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4577 | } |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4578 | |
| 4579 | if (retry > 1) |
| 4580 | msleep(250); |
| 4581 | else |
| 4582 | msleep(50); |
| 4583 | |
| 4584 | if (sitar_hs_gpio_level_remove(sitar)) { |
| 4585 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 4586 | break; |
| 4587 | } |
| 4588 | |
| 4589 | sitar_turn_onoff_override(codec, true); |
| 4590 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 4591 | mb_v[i] = __sitar_codec_sta_dce(codec, 1, true, true); |
| 4592 | mic_mv[i] = sitar_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 4593 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 4594 | __func__, retry, mic_mv[i], mb_v[i]); |
| 4595 | } |
| 4596 | sitar_turn_onoff_override(codec, false); |
| 4597 | |
| 4598 | if (sitar_hs_gpio_level_remove(sitar)) { |
| 4599 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 4600 | break; |
| 4601 | } |
| 4602 | |
| 4603 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 4604 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 4605 | break; |
| 4606 | |
| 4607 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 4608 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 4609 | settled = true; |
| 4610 | msleep(200); |
| 4611 | break; |
| 4612 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4613 | } |
| 4614 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4615 | if (timedout) |
| 4616 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 4617 | __func__, SITAR_HS_DETECT_PLUG_TIME_MS); |
| 4618 | return settled; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4619 | } |
| 4620 | |
| 4621 | static irqreturn_t sitar_hs_remove_irq(int irq, void *data) |
| 4622 | { |
| 4623 | struct sitar_priv *priv = data; |
| 4624 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4625 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4626 | pr_debug("%s: enter, removal interrupt\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4627 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4628 | SITAR_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 4629 | if (sitar_hs_remove_settle(codec)) |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4630 | sitar_codec_start_hs_polling(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4631 | pr_debug("%s: remove settle done\n", __func__); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4632 | |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4633 | SITAR_RELEASE_LOCK(priv->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4634 | return IRQ_HANDLED; |
| 4635 | } |
| 4636 | |
| 4637 | |
| 4638 | static unsigned long slimbus_value; |
| 4639 | |
| 4640 | static irqreturn_t sitar_slimbus_irq(int irq, void *data) |
| 4641 | { |
| 4642 | struct sitar_priv *priv = data; |
| 4643 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 4644 | int i, j, k, port_id, ch_mask_temp; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4645 | u8 val; |
| 4646 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4647 | |
| 4648 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 4649 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
| 4650 | SITAR_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 4651 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 4652 | port_id = i*8 + j; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4653 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 4654 | SITAR_SLIM_PGD_PORT_INT_SOURCE0 + port_id); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4655 | if (val & 0x1) |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 4656 | pr_err_ratelimited("overflow error on port %x, value %x\n", |
| 4657 | port_id, val); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4658 | if (val & 0x2) |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 4659 | pr_err_ratelimited("underflow error on port %x,value %x\n", |
| 4660 | port_id, val); |
| 4661 | if (val & 0x4) { |
| 4662 | pr_debug("%s: port %x disconnect value %x\n", |
| 4663 | __func__, port_id, val); |
| 4664 | for (k = 0; k < ARRAY_SIZE(sitar_dai); k++) { |
| 4665 | ch_mask_temp = 1 << port_id; |
| 4666 | if (ch_mask_temp & |
| 4667 | priv->dai[k].ch_mask) { |
| 4668 | priv->dai[k].ch_mask &= |
| 4669 | ~ch_mask_temp; |
| 4670 | if (!priv->dai[k].ch_mask) |
| 4671 | wake_up( |
| 4672 | &priv->dai[k].dai_wait); |
| 4673 | } |
| 4674 | } |
| 4675 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4676 | } |
| 4677 | wcd9xxx_interface_reg_write(codec->control_data, |
| 4678 | SITAR_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF); |
| 4679 | } |
| 4680 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4681 | return IRQ_HANDLED; |
| 4682 | } |
| 4683 | |
| 4684 | |
| 4685 | static int sitar_handle_pdata(struct sitar_priv *sitar) |
| 4686 | { |
| 4687 | struct snd_soc_codec *codec = sitar->codec; |
| 4688 | struct wcd9xxx_pdata *pdata = sitar->pdata; |
| 4689 | int k1, k2, rc = 0; |
| 4690 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 4691 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 4692 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 4693 | u8 flag = pdata->amic_settings.use_pdata; |
| 4694 | u8 i = 0, j = 0; |
| 4695 | u8 val_txfe = 0, value = 0; |
| 4696 | |
| 4697 | if (!pdata) { |
| 4698 | rc = -ENODEV; |
| 4699 | goto done; |
| 4700 | } |
| 4701 | |
| 4702 | /* Make sure settings are correct */ |
| 4703 | if ((pdata->micbias.ldoh_v > SITAR_LDOH_2P85_V) || |
| 4704 | (pdata->micbias.bias1_cfilt_sel > SITAR_CFILT2_SEL) || |
| 4705 | (pdata->micbias.bias2_cfilt_sel > SITAR_CFILT2_SEL)) { |
| 4706 | rc = -EINVAL; |
| 4707 | goto done; |
| 4708 | } |
| 4709 | |
| 4710 | /* figure out k value */ |
| 4711 | k1 = sitar_find_k_value(pdata->micbias.ldoh_v, |
| 4712 | pdata->micbias.cfilt1_mv); |
| 4713 | k2 = sitar_find_k_value(pdata->micbias.ldoh_v, |
| 4714 | pdata->micbias.cfilt2_mv); |
| 4715 | |
| 4716 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2)) { |
| 4717 | rc = -EINVAL; |
| 4718 | goto done; |
| 4719 | } |
| 4720 | |
| 4721 | /* Set voltage level and always use LDO */ |
Bhalchandra Gajare | 03d28d0 | 2012-05-18 17:39:32 -0700 | [diff] [blame] | 4722 | snd_soc_update_bits(codec, SITAR_A_LDO_H_MODE_1, 0x0C, |
| 4723 | (pdata->micbias.ldoh_v << 2)); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4724 | |
| 4725 | snd_soc_update_bits(codec, SITAR_A_MICB_CFILT_1_VAL, 0xFC, |
| 4726 | (k1 << 2)); |
| 4727 | snd_soc_update_bits(codec, SITAR_A_MICB_CFILT_2_VAL, 0xFC, |
| 4728 | (k2 << 2)); |
| 4729 | |
| 4730 | snd_soc_update_bits(codec, SITAR_A_MICB_1_CTL, 0x60, |
| 4731 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 4732 | snd_soc_update_bits(codec, SITAR_A_MICB_2_CTL, 0x60, |
| 4733 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 4734 | |
Bhalchandra Gajare | 15dbeaa | 2012-06-26 12:53:07 -0700 | [diff] [blame] | 4735 | /* Set micbias capless mode */ |
| 4736 | snd_soc_update_bits(codec, SITAR_A_MICB_1_CTL, 0x10, |
| 4737 | (pdata->micbias.bias1_cap_mode << 4)); |
| 4738 | snd_soc_update_bits(codec, SITAR_A_MICB_2_CTL, 0x10, |
| 4739 | (pdata->micbias.bias2_cap_mode << 4)); |
| 4740 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4741 | for (i = 0; i < 6; j++, i += 2) { |
| 4742 | if (flag & (0x01 << i)) { |
| 4743 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 4744 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 4745 | val_txfe = val_txfe | |
| 4746 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 4747 | snd_soc_update_bits(codec, SITAR_A_TX_1_2_EN + j * 10, |
| 4748 | 0x10, value); |
| 4749 | snd_soc_update_bits(codec, |
| 4750 | SITAR_A_TX_1_2_TEST_EN + j * 10, |
| 4751 | 0x30, val_txfe); |
| 4752 | } |
| 4753 | if (flag & (0x01 << (i + 1))) { |
| 4754 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 4755 | val_txfe = (txfe_bypass & |
| 4756 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 4757 | val_txfe |= (txfe_buff & |
| 4758 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 4759 | snd_soc_update_bits(codec, SITAR_A_TX_1_2_EN + j * 10, |
| 4760 | 0x01, value); |
| 4761 | snd_soc_update_bits(codec, |
| 4762 | SITAR_A_TX_1_2_TEST_EN + j * 10, |
| 4763 | 0x03, val_txfe); |
| 4764 | } |
| 4765 | } |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4766 | if (flag & 0x40) { |
| 4767 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 4768 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 4769 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 4770 | snd_soc_update_bits(codec, SITAR_A_TX_4_MBHC_EN, |
| 4771 | 0x13, value); |
| 4772 | } |
| 4773 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4774 | |
| 4775 | if (pdata->ocp.use_pdata) { |
| 4776 | /* not defined in CODEC specification */ |
| 4777 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 4778 | pdata->ocp.hph_ocp_limit == 5) { |
| 4779 | rc = -EINVAL; |
| 4780 | goto done; |
| 4781 | } |
| 4782 | snd_soc_update_bits(codec, SITAR_A_RX_COM_OCP_CTL, |
| 4783 | 0x0F, pdata->ocp.num_attempts); |
| 4784 | snd_soc_write(codec, SITAR_A_RX_COM_OCP_COUNT, |
| 4785 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 4786 | snd_soc_update_bits(codec, SITAR_A_RX_HPH_OCP_CTL, |
| 4787 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 4788 | } |
| 4789 | done: |
| 4790 | return rc; |
| 4791 | } |
| 4792 | |
| 4793 | static const struct sitar_reg_mask_val sitar_1_1_reg_defaults[] = { |
| 4794 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4795 | SITAR_REG_VAL(SITAR_A_MICB_1_INT_RBIAS, 0x24), |
| 4796 | SITAR_REG_VAL(SITAR_A_MICB_2_INT_RBIAS, 0x24), |
| 4797 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4798 | SITAR_REG_VAL(SITAR_A_RX_HPH_BIAS_PA, 0x57), |
| 4799 | SITAR_REG_VAL(SITAR_A_RX_HPH_BIAS_LDO, 0x56), |
| 4800 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4801 | SITAR_REG_VAL(SITAR_A_RX_EAR_BIAS_PA, 0xA6), |
| 4802 | SITAR_REG_VAL(SITAR_A_RX_EAR_GAIN, 0x02), |
| 4803 | SITAR_REG_VAL(SITAR_A_RX_EAR_VCM, 0x03), |
| 4804 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4805 | SITAR_REG_VAL(SITAR_A_CDC_RX1_B5_CTL, 0x78), |
Asish Bhattacharya | 2e1d752 | 2012-05-25 15:08:40 +0530 | [diff] [blame] | 4806 | SITAR_REG_VAL(SITAR_A_CDC_RX2_B5_CTL, 0x78), |
| 4807 | SITAR_REG_VAL(SITAR_A_CDC_RX3_B5_CTL, 0x78), |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4808 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4809 | SITAR_REG_VAL(SITAR_A_CDC_RX1_B6_CTL, 0x80), |
| 4810 | |
| 4811 | SITAR_REG_VAL(SITAR_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 4812 | |
| 4813 | }; |
| 4814 | |
| 4815 | static void sitar_update_reg_defaults(struct snd_soc_codec *codec) |
| 4816 | { |
| 4817 | u32 i; |
| 4818 | for (i = 0; i < ARRAY_SIZE(sitar_1_1_reg_defaults); i++) |
| 4819 | snd_soc_write(codec, sitar_1_1_reg_defaults[i].reg, |
| 4820 | sitar_1_1_reg_defaults[i].val); |
| 4821 | |
| 4822 | } |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4823 | |
| 4824 | static const struct sitar_reg_mask_val sitar_i2c_codec_reg_init_val[] = { |
| 4825 | {WCD9XXX_A_CHIP_CTL, 0x1, 0x1}, |
| 4826 | }; |
| 4827 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4828 | static const struct sitar_reg_mask_val sitar_codec_reg_init_val[] = { |
| 4829 | /* Initialize current threshold to 350MA |
| 4830 | * number of wait and run cycles to 4096 |
| 4831 | */ |
Bhalchandra Gajare | 33f7430 | 2012-06-14 15:12:51 -0700 | [diff] [blame] | 4832 | {SITAR_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4833 | {SITAR_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
| 4834 | |
| 4835 | {SITAR_A_QFUSE_CTL, 0xFF, 0x03}, |
| 4836 | |
| 4837 | /* Initialize gain registers to use register gain */ |
| 4838 | {SITAR_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 4839 | {SITAR_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 4840 | {SITAR_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 4841 | {SITAR_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 4842 | |
| 4843 | /* Initialize mic biases to differential mode */ |
| 4844 | {SITAR_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 4845 | {SITAR_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 4846 | |
| 4847 | {SITAR_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 4848 | |
| 4849 | /* Use 16 bit sample size for TX1 to TX6 */ |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4850 | {SITAR_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4851 | {SITAR_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 4852 | {SITAR_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 4853 | {SITAR_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 4854 | {SITAR_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4855 | {SITAR_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0x1, 0x1}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4856 | |
| 4857 | /* Use 16 bit sample size for RX */ |
| 4858 | {SITAR_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 4859 | {SITAR_A_CDC_CONN_RX_SB_B2_CTL, 0x02, 0x02}, |
| 4860 | |
| 4861 | /*enable HPF filter for TX paths */ |
| 4862 | {SITAR_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4863 | {SITAR_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
Bhalchandra Gajare | 2776af1 | 2012-04-27 16:59:39 -0700 | [diff] [blame] | 4864 | |
| 4865 | /*enable External clock select*/ |
| 4866 | {SITAR_A_CDC_CLK_MCLK_CTL, 0x01, 0x01}, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4867 | }; |
| 4868 | |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4869 | static void sitar_i2c_codec_init_reg(struct snd_soc_codec *codec) |
| 4870 | { |
| 4871 | u32 i; |
| 4872 | for (i = 0; i < ARRAY_SIZE(sitar_i2c_codec_reg_init_val); i++) |
| 4873 | snd_soc_update_bits(codec, sitar_i2c_codec_reg_init_val[i].reg, |
| 4874 | sitar_i2c_codec_reg_init_val[i].mask, |
| 4875 | sitar_i2c_codec_reg_init_val[i].val); |
| 4876 | } |
| 4877 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4878 | static void sitar_codec_init_reg(struct snd_soc_codec *codec) |
| 4879 | { |
| 4880 | u32 i; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4881 | for (i = 0; i < ARRAY_SIZE(sitar_codec_reg_init_val); i++) |
| 4882 | snd_soc_update_bits(codec, sitar_codec_reg_init_val[i].reg, |
| 4883 | sitar_codec_reg_init_val[i].mask, |
| 4884 | sitar_codec_reg_init_val[i].val); |
| 4885 | } |
| 4886 | |
| 4887 | static int sitar_codec_probe(struct snd_soc_codec *codec) |
| 4888 | { |
| 4889 | struct sitar *control; |
| 4890 | struct sitar_priv *sitar; |
| 4891 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 4892 | int ret = 0; |
| 4893 | int i; |
| 4894 | u8 sitar_version; |
| 4895 | int ch_cnt; |
| 4896 | |
| 4897 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4898 | control = codec->control_data; |
| 4899 | |
| 4900 | sitar = kzalloc(sizeof(struct sitar_priv), GFP_KERNEL); |
| 4901 | if (!sitar) { |
| 4902 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 4903 | return -ENOMEM; |
| 4904 | } |
| 4905 | |
| 4906 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 4907 | memset(&sitar->mbhc_bias_regs, 0, |
| 4908 | sizeof(struct mbhc_micbias_regs)); |
| 4909 | sitar->cfilt_k_value = 0; |
| 4910 | sitar->mbhc_micbias_switched = false; |
| 4911 | |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 4912 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 4913 | memset(&sitar->mbhc_data, 0, |
| 4914 | sizeof(struct mbhc_internal_cal_data)); |
| 4915 | sitar->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
| 4916 | sitar->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 4917 | sitar->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4918 | snd_soc_codec_set_drvdata(codec, sitar); |
| 4919 | |
| 4920 | sitar->mclk_enabled = false; |
| 4921 | sitar->bandgap_type = SITAR_BANDGAP_OFF; |
| 4922 | sitar->clock_active = false; |
| 4923 | sitar->config_mode_active = false; |
| 4924 | sitar->mbhc_polling_active = false; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4925 | sitar->no_mic_headset_override = false; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4926 | mutex_init(&sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4927 | sitar->codec = codec; |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 4928 | sitar->mbhc_state = MBHC_STATE_NONE; |
| 4929 | sitar->mbhc_last_resume = 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4930 | sitar->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4931 | sitar_update_reg_defaults(codec); |
| 4932 | sitar_codec_init_reg(codec); |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4933 | sitar->intf_type = wcd9xxx_get_intf_type(); |
| 4934 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) |
| 4935 | sitar_i2c_codec_init_reg(codec); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4936 | |
| 4937 | ret = sitar_handle_pdata(sitar); |
| 4938 | if (IS_ERR_VALUE(ret)) { |
| 4939 | pr_err("%s: bad pdata\n", __func__); |
| 4940 | goto err_pdata; |
| 4941 | } |
| 4942 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4943 | snd_soc_add_codec_controls(codec, sitar_snd_controls, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4944 | ARRAY_SIZE(sitar_snd_controls)); |
| 4945 | snd_soc_dapm_new_controls(dapm, sitar_dapm_widgets, |
| 4946 | ARRAY_SIZE(sitar_dapm_widgets)); |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4947 | if (sitar->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
| 4948 | snd_soc_dapm_new_controls(dapm, sitar_dapm_i2s_widgets, |
| 4949 | ARRAY_SIZE(sitar_dapm_i2s_widgets)); |
| 4950 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 4951 | ARRAY_SIZE(audio_i2s_map)); |
| 4952 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4953 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
| 4954 | |
| 4955 | sitar_version = snd_soc_read(codec, WCD9XXX_A_CHIP_VERSION); |
| 4956 | pr_info("%s : Sitar version reg 0x%2x\n", __func__, (u32)sitar_version); |
| 4957 | |
| 4958 | sitar_version &= 0x1F; |
| 4959 | pr_info("%s : Sitar version %u\n", __func__, (u32)sitar_version); |
| 4960 | |
| 4961 | snd_soc_dapm_sync(dapm); |
| 4962 | |
| 4963 | |
| 4964 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION, |
| 4965 | sitar_hs_insert_irq, "Headset insert detect", sitar); |
| 4966 | if (ret) { |
| 4967 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 4968 | SITAR_IRQ_MBHC_INSERTION); |
| 4969 | goto err_insert_irq; |
| 4970 | } |
| 4971 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION); |
| 4972 | |
| 4973 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL, |
| 4974 | sitar_hs_remove_irq, "Headset remove detect", sitar); |
| 4975 | if (ret) { |
| 4976 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 4977 | SITAR_IRQ_MBHC_REMOVAL); |
| 4978 | goto err_remove_irq; |
| 4979 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4980 | |
| 4981 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL, |
| 4982 | sitar_dce_handler, "DC Estimation detect", sitar); |
| 4983 | if (ret) { |
| 4984 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 4985 | SITAR_IRQ_MBHC_POTENTIAL); |
| 4986 | goto err_potential_irq; |
| 4987 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4988 | |
| 4989 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE, |
| 4990 | sitar_release_handler, "Button Release detect", sitar); |
| 4991 | if (ret) { |
| 4992 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 4993 | SITAR_IRQ_MBHC_RELEASE); |
| 4994 | goto err_release_irq; |
| 4995 | } |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 4996 | |
| 4997 | ret = wcd9xxx_request_irq(codec->control_data, SITAR_IRQ_SLIMBUS, |
| 4998 | sitar_slimbus_irq, "SLIMBUS Slave", sitar); |
| 4999 | if (ret) { |
| 5000 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 5001 | SITAR_IRQ_SLIMBUS); |
| 5002 | goto err_slimbus_irq; |
| 5003 | } |
| 5004 | |
| 5005 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 5006 | wcd9xxx_interface_reg_write(codec->control_data, |
| 5007 | SITAR_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 5008 | |
| 5009 | |
| 5010 | ret = wcd9xxx_request_irq(codec->control_data, |
| 5011 | SITAR_IRQ_HPH_PA_OCPL_FAULT, sitar_hphl_ocp_irq, |
| 5012 | "HPH_L OCP detect", sitar); |
| 5013 | if (ret) { |
| 5014 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 5015 | SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 5016 | goto err_hphl_ocp_irq; |
| 5017 | } |
| 5018 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_HPH_PA_OCPL_FAULT); |
| 5019 | |
| 5020 | ret = wcd9xxx_request_irq(codec->control_data, |
| 5021 | SITAR_IRQ_HPH_PA_OCPR_FAULT, sitar_hphr_ocp_irq, |
| 5022 | "HPH_R OCP detect", sitar); |
| 5023 | if (ret) { |
| 5024 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 5025 | SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 5026 | goto err_hphr_ocp_irq; |
| 5027 | } |
| 5028 | wcd9xxx_disable_irq(codec->control_data, SITAR_IRQ_HPH_PA_OCPR_FAULT); |
| 5029 | |
| 5030 | for (i = 0; i < ARRAY_SIZE(sitar_dai); i++) { |
| 5031 | switch (sitar_dai[i].id) { |
| 5032 | case AIF1_PB: |
| 5033 | ch_cnt = sitar_dai[i].playback.channels_max; |
| 5034 | break; |
| 5035 | case AIF1_CAP: |
| 5036 | ch_cnt = sitar_dai[i].capture.channels_max; |
| 5037 | break; |
| 5038 | default: |
| 5039 | continue; |
| 5040 | } |
| 5041 | sitar->dai[i].ch_num = kzalloc((sizeof(unsigned int)* |
| 5042 | ch_cnt), GFP_KERNEL); |
Bhalchandra Gajare | e66e4bb | 2012-07-10 15:17:50 -0700 | [diff] [blame^] | 5043 | init_waitqueue_head(&sitar->dai[i].dai_wait); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5044 | } |
| 5045 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 5046 | codec->ignore_pmdown_time = 1; |
| 5047 | |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5048 | #ifdef CONFIG_DEBUG_FS |
| 5049 | debug_sitar_priv = sitar; |
| 5050 | #endif |
| 5051 | |
| 5052 | return ret; |
| 5053 | |
| 5054 | err_hphr_ocp_irq: |
| 5055 | wcd9xxx_free_irq(codec->control_data, |
| 5056 | SITAR_IRQ_HPH_PA_OCPL_FAULT, sitar); |
| 5057 | err_hphl_ocp_irq: |
| 5058 | wcd9xxx_free_irq(codec->control_data, |
| 5059 | SITAR_IRQ_SLIMBUS, sitar); |
| 5060 | err_slimbus_irq: |
| 5061 | wcd9xxx_free_irq(codec->control_data, |
| 5062 | SITAR_IRQ_MBHC_RELEASE, sitar); |
| 5063 | err_release_irq: |
| 5064 | wcd9xxx_free_irq(codec->control_data, |
| 5065 | SITAR_IRQ_MBHC_POTENTIAL, sitar); |
| 5066 | err_potential_irq: |
| 5067 | wcd9xxx_free_irq(codec->control_data, |
| 5068 | SITAR_IRQ_MBHC_REMOVAL, sitar); |
| 5069 | err_remove_irq: |
| 5070 | wcd9xxx_free_irq(codec->control_data, |
| 5071 | SITAR_IRQ_MBHC_INSERTION, sitar); |
| 5072 | err_insert_irq: |
| 5073 | err_pdata: |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5074 | mutex_destroy(&sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5075 | kfree(sitar); |
| 5076 | return ret; |
| 5077 | } |
| 5078 | static int sitar_codec_remove(struct snd_soc_codec *codec) |
| 5079 | { |
| 5080 | int i; |
| 5081 | struct sitar_priv *sitar = snd_soc_codec_get_drvdata(codec); |
| 5082 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_SLIMBUS, sitar); |
| 5083 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_RELEASE, sitar); |
| 5084 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_POTENTIAL, sitar); |
| 5085 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_REMOVAL, sitar); |
| 5086 | wcd9xxx_free_irq(codec->control_data, SITAR_IRQ_MBHC_INSERTION, sitar); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5087 | SITAR_ACQUIRE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5088 | sitar_codec_disable_clock_block(codec); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5089 | SITAR_RELEASE_LOCK(sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5090 | sitar_codec_enable_bandgap(codec, SITAR_BANDGAP_OFF); |
Asish Bhattacharya | f868a1f | 2012-03-05 10:07:44 -0800 | [diff] [blame] | 5091 | if (sitar->mbhc_fw) |
| 5092 | release_firmware(sitar->mbhc_fw); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5093 | for (i = 0; i < ARRAY_SIZE(sitar_dai); i++) |
| 5094 | kfree(sitar->dai[i].ch_num); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5095 | mutex_destroy(&sitar->codec_resource_lock); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5096 | kfree(sitar); |
| 5097 | return 0; |
| 5098 | } |
| 5099 | static struct snd_soc_codec_driver soc_codec_dev_sitar = { |
| 5100 | .probe = sitar_codec_probe, |
| 5101 | .remove = sitar_codec_remove, |
| 5102 | .read = sitar_read, |
| 5103 | .write = sitar_write, |
| 5104 | |
| 5105 | .readable_register = sitar_readable, |
| 5106 | .volatile_register = sitar_volatile, |
| 5107 | |
| 5108 | .reg_cache_size = SITAR_CACHE_SIZE, |
| 5109 | .reg_cache_default = sitar_reg_defaults, |
| 5110 | .reg_word_size = 1, |
| 5111 | }; |
| 5112 | |
| 5113 | #ifdef CONFIG_DEBUG_FS |
| 5114 | static struct dentry *debugfs_poke; |
| 5115 | |
| 5116 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 5117 | { |
| 5118 | file->private_data = inode->i_private; |
| 5119 | return 0; |
| 5120 | } |
| 5121 | |
| 5122 | static ssize_t codec_debug_write(struct file *filp, |
| 5123 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 5124 | { |
| 5125 | char lbuf[32]; |
| 5126 | char *buf; |
| 5127 | int rc; |
| 5128 | |
| 5129 | if (cnt > sizeof(lbuf) - 1) |
| 5130 | return -EINVAL; |
| 5131 | |
| 5132 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 5133 | if (rc) |
| 5134 | return -EFAULT; |
| 5135 | |
| 5136 | lbuf[cnt] = '\0'; |
| 5137 | buf = (char *)lbuf; |
| 5138 | debug_sitar_priv->no_mic_headset_override = (*strsep(&buf, " ") == '0') |
| 5139 | ? false : true; |
| 5140 | |
| 5141 | return rc; |
| 5142 | } |
| 5143 | |
| 5144 | static const struct file_operations codec_debug_ops = { |
| 5145 | .open = codec_debug_open, |
| 5146 | .write = codec_debug_write, |
| 5147 | }; |
| 5148 | #endif |
| 5149 | |
| 5150 | #ifdef CONFIG_PM |
| 5151 | static int sitar_suspend(struct device *dev) |
| 5152 | { |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 5153 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 5154 | return 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | static int sitar_resume(struct device *dev) |
| 5158 | { |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5159 | struct platform_device *pdev = to_platform_device(dev); |
| 5160 | struct sitar_priv *sitar = platform_get_drvdata(pdev); |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 5161 | dev_dbg(dev, "%s: system resume\n", __func__); |
Bhalchandra Gajare | 466aafe | 2012-05-02 17:55:26 -0700 | [diff] [blame] | 5162 | sitar->mbhc_last_resume = jiffies; |
Asish Bhattacharya | 1d06953 | 2012-03-07 13:25:24 -0800 | [diff] [blame] | 5163 | return 0; |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | static const struct dev_pm_ops sitar_pm_ops = { |
| 5167 | .suspend = sitar_suspend, |
| 5168 | .resume = sitar_resume, |
| 5169 | }; |
| 5170 | #endif |
| 5171 | |
| 5172 | static int __devinit sitar_probe(struct platform_device *pdev) |
| 5173 | { |
| 5174 | int ret = 0; |
| 5175 | pr_err("%s\n", __func__); |
| 5176 | #ifdef CONFIG_DEBUG_FS |
| 5177 | debugfs_poke = debugfs_create_file("TRRS", |
| 5178 | S_IFREG | S_IRUGO, NULL, (void *) "TRRS", &codec_debug_ops); |
| 5179 | |
| 5180 | #endif |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5181 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 5182 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_sitar, |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5183 | sitar_dai, ARRAY_SIZE(sitar_dai)); |
Asish Bhattacharya | 2b709d4 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5184 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
| 5185 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_sitar, |
| 5186 | sitar_i2s_dai, ARRAY_SIZE(sitar_i2s_dai)); |
Asish Bhattacharya | b86c347 | 2012-02-15 08:31:52 +0530 | [diff] [blame] | 5187 | return ret; |
| 5188 | } |
| 5189 | static int __devexit sitar_remove(struct platform_device *pdev) |
| 5190 | { |
| 5191 | snd_soc_unregister_codec(&pdev->dev); |
| 5192 | |
| 5193 | #ifdef CONFIG_DEBUG_FS |
| 5194 | debugfs_remove(debugfs_poke); |
| 5195 | #endif |
| 5196 | return 0; |
| 5197 | } |
| 5198 | static struct platform_driver sitar_codec_driver = { |
| 5199 | .probe = sitar_probe, |
| 5200 | .remove = sitar_remove, |
| 5201 | .driver = { |
| 5202 | .name = "sitar_codec", |
| 5203 | .owner = THIS_MODULE, |
| 5204 | #ifdef CONFIG_PM |
| 5205 | .pm = &sitar_pm_ops, |
| 5206 | #endif |
| 5207 | }, |
| 5208 | }; |
| 5209 | |
| 5210 | static int __init sitar_codec_init(void) |
| 5211 | { |
| 5212 | return platform_driver_register(&sitar_codec_driver); |
| 5213 | } |
| 5214 | |
| 5215 | static void __exit sitar_codec_exit(void) |
| 5216 | { |
| 5217 | platform_driver_unregister(&sitar_codec_driver); |
| 5218 | } |
| 5219 | |
| 5220 | module_init(sitar_codec_init); |
| 5221 | module_exit(sitar_codec_exit); |
| 5222 | |
| 5223 | MODULE_DESCRIPTION("Sitar codec driver"); |
| 5224 | MODULE_VERSION("1.0"); |
| 5225 | MODULE_LICENSE("GPL v2"); |