Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 14 | #include <linux/firmware.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 17 | #include <linux/device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 20 | #include <linux/debugfs.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 21 | #include <linux/mfd/wcd9xxx/core.h> |
| 22 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 23 | #include <linux/mfd/wcd9xxx/wcd9310_registers.h> |
| 24 | #include <linux/mfd/wcd9xxx/pdata.h> |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | #include <sound/soc.h> |
| 28 | #include <sound/soc-dapm.h> |
| 29 | #include <sound/tlv.h> |
| 30 | #include <linux/bitops.h> |
| 31 | #include <linux/delay.h> |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 33 | #include <linux/kernel.h> |
| 34 | #include <linux/gpio.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #include "wcd9310.h" |
| 36 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 37 | #define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 38 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 39 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 40 | |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 41 | |
| 42 | #define NUM_DECIMATORS 10 |
| 43 | #define NUM_INTERPOLATORS 7 |
| 44 | #define BITS_PER_REG 8 |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 45 | #define TABLA_CFILT_FAST_MODE 0x00 |
| 46 | #define TABLA_CFILT_SLOW_MODE 0x40 |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 47 | #define MBHC_FW_READ_ATTEMPTS 15 |
| 48 | #define MBHC_FW_READ_TIMEOUT 2000000 |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 49 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 50 | enum { |
| 51 | MBHC_USE_HPHL_TRIGGER = 1, |
| 52 | MBHC_USE_MB_TRIGGER = 2 |
| 53 | }; |
| 54 | |
| 55 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 56 | #define NUM_ATTEMPTS_INSERT_DETECT 25 |
| 57 | #define NUM_ATTEMPTS_TO_REPORT 5 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 58 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 59 | #define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | SND_JACK_OC_HPHR) |
| 60 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 61 | #define TABLA_I2S_MASTER_MODE_MASK 0x08 |
| 62 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 63 | #define TABLA_OCP_ATTEMPT 1 |
| 64 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 65 | #define AIF1_PB 1 |
| 66 | #define AIF1_CAP 2 |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 67 | #define AIF2_PB 3 |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 68 | #define AIF2_CAP 4 |
| 69 | |
| 70 | #define NUM_CODEC_DAIS 4 |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 71 | #define TABLA_COMP_DIGITAL_GAIN_OFFSET 3 |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 72 | |
| 73 | struct tabla_codec_dai_data { |
| 74 | u32 rate; |
| 75 | u32 *ch_num; |
| 76 | u32 ch_act; |
| 77 | u32 ch_tot; |
| 78 | }; |
| 79 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 80 | #define TABLA_MCLK_RATE_12288KHZ 12288000 |
| 81 | #define TABLA_MCLK_RATE_9600KHZ 9600000 |
| 82 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 83 | #define TABLA_FAKE_INS_THRESHOLD_MS 2500 |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 84 | #define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50 |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 85 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 86 | #define TABLA_MBHC_BUTTON_MIN 0x8000 |
| 87 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 88 | #define TABLA_MBHC_FAKE_INSERT_LOW 10 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 89 | #define TABLA_MBHC_FAKE_INSERT_HIGH 80 |
| 90 | #define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 91 | |
| 92 | #define TABLA_MBHC_STATUS_REL_DETECTION 0x0C |
| 93 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 94 | #define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 200 |
| 95 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 96 | #define TABLA_MBHC_FAKE_INS_DELTA_MV 200 |
| 97 | #define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 98 | |
| 99 | #define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000) |
| 100 | #define TABLA_HS_DETECT_PLUG_INERVAL_MS 100 |
| 101 | |
| 102 | #define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000 |
| 103 | |
| 104 | #define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0) |
| 105 | #define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0) |
| 106 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 108 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 109 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 110 | static struct snd_soc_dai_driver tabla_dai[]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 111 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 112 | |
| 113 | enum tabla_bandgap_type { |
| 114 | TABLA_BANDGAP_OFF = 0, |
| 115 | TABLA_BANDGAP_AUDIO_MODE, |
| 116 | TABLA_BANDGAP_MBHC_MODE, |
| 117 | }; |
| 118 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 119 | struct mbhc_micbias_regs { |
| 120 | u16 cfilt_val; |
| 121 | u16 cfilt_ctl; |
| 122 | u16 mbhc_reg; |
| 123 | u16 int_rbias; |
| 124 | u16 ctl_reg; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 125 | u8 cfilt_sel; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 128 | /* Codec supports 2 IIR filters */ |
| 129 | enum { |
| 130 | IIR1 = 0, |
| 131 | IIR2, |
| 132 | IIR_MAX, |
| 133 | }; |
| 134 | /* Codec supports 5 bands */ |
| 135 | enum { |
| 136 | BAND1 = 0, |
| 137 | BAND2, |
| 138 | BAND3, |
| 139 | BAND4, |
| 140 | BAND5, |
| 141 | BAND_MAX, |
| 142 | }; |
| 143 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 144 | enum { |
| 145 | COMPANDER_1 = 0, |
| 146 | COMPANDER_2, |
| 147 | COMPANDER_MAX, |
| 148 | }; |
| 149 | |
| 150 | enum { |
| 151 | COMPANDER_FS_8KHZ = 0, |
| 152 | COMPANDER_FS_16KHZ, |
| 153 | COMPANDER_FS_32KHZ, |
| 154 | COMPANDER_FS_48KHZ, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 155 | COMPANDER_FS_96KHZ, |
| 156 | COMPANDER_FS_192KHZ, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 157 | COMPANDER_FS_MAX, |
| 158 | }; |
| 159 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 160 | /* Flags to track of PA and DAC state. |
| 161 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 162 | * only PA to be turned on without DAC being on. */ |
| 163 | enum tabla_priv_ack_flags { |
| 164 | TABLA_HPHL_PA_OFF_ACK = 0, |
| 165 | TABLA_HPHR_PA_OFF_ACK, |
| 166 | TABLA_HPHL_DAC_OFF_ACK, |
| 167 | TABLA_HPHR_DAC_OFF_ACK |
| 168 | }; |
| 169 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 170 | |
| 171 | struct comp_sample_dependent_params { |
| 172 | u32 peak_det_timeout; |
| 173 | u32 rms_meter_div_fact; |
| 174 | u32 rms_meter_resamp_fact; |
| 175 | }; |
| 176 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 177 | /* Data used by MBHC */ |
| 178 | struct mbhc_internal_cal_data { |
| 179 | u16 dce_z; |
| 180 | u16 dce_mb; |
| 181 | u16 sta_z; |
| 182 | u16 sta_mb; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 183 | u32 t_sta_dce; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 184 | u32 t_dce; |
| 185 | u32 t_sta; |
| 186 | u32 micb_mv; |
| 187 | u16 v_ins_hu; |
| 188 | u16 v_ins_h; |
| 189 | u16 v_b1_hu; |
| 190 | u16 v_b1_h; |
| 191 | u16 v_b1_huc; |
| 192 | u16 v_brh; |
| 193 | u16 v_brl; |
| 194 | u16 v_no_mic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 195 | u8 npoll; |
| 196 | u8 nbounce_wait; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 197 | s16 adj_v_hs_max; |
| 198 | u16 adj_v_ins_hu; |
| 199 | u16 adj_v_ins_h; |
| 200 | s16 v_inval_ins_low; |
| 201 | s16 v_inval_ins_high; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 204 | struct tabla_reg_address { |
| 205 | u16 micb_4_ctl; |
| 206 | u16 micb_4_int_rbias; |
| 207 | u16 micb_4_mbhc; |
| 208 | }; |
| 209 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 210 | enum tabla_mbhc_plug_type { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 211 | PLUG_TYPE_INVALID = -1, |
| 212 | PLUG_TYPE_NONE, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 213 | PLUG_TYPE_HEADSET, |
| 214 | PLUG_TYPE_HEADPHONE, |
| 215 | PLUG_TYPE_HIGH_HPH, |
| 216 | }; |
| 217 | |
| 218 | enum tabla_mbhc_state { |
| 219 | MBHC_STATE_NONE = -1, |
| 220 | MBHC_STATE_POTENTIAL, |
| 221 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 222 | MBHC_STATE_RELEASE, |
| 223 | }; |
| 224 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 225 | struct hpf_work { |
| 226 | struct tabla_priv *tabla; |
| 227 | u32 decimator; |
| 228 | u8 tx_hpf_cut_of_freq; |
| 229 | struct delayed_work dwork; |
| 230 | }; |
| 231 | |
| 232 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 233 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 234 | struct tabla_priv { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 235 | struct snd_soc_codec *codec; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 236 | struct tabla_reg_address reg_addr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 237 | u32 adc_count; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 238 | u32 cfilt1_cnt; |
| 239 | u32 cfilt2_cnt; |
| 240 | u32 cfilt3_cnt; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 241 | u32 rx_bias_count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 242 | enum tabla_bandgap_type bandgap_type; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 243 | bool mclk_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | bool clock_active; |
| 245 | bool config_mode_active; |
| 246 | bool mbhc_polling_active; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 247 | unsigned long mbhc_fake_ins_start; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 248 | int buttons_pressed; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 249 | enum tabla_mbhc_state mbhc_state; |
| 250 | struct tabla_mbhc_config mbhc_cfg; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 251 | struct mbhc_internal_cal_data mbhc_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 252 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 253 | struct wcd9xxx_pdata *pdata; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 254 | u32 anc_slot; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 255 | |
| 256 | bool no_mic_headset_override; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 257 | /* Delayed work to report long button press */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 258 | struct delayed_work mbhc_btn_dwork; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 259 | |
| 260 | struct mbhc_micbias_regs mbhc_bias_regs; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 261 | bool mbhc_micbias_switched; |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 262 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 263 | /* track PA/DAC state */ |
| 264 | unsigned long hph_pa_dac_state; |
| 265 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 266 | /*track tabla interface type*/ |
| 267 | u8 intf_type; |
| 268 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 269 | u32 hph_status; /* track headhpone status */ |
| 270 | /* define separate work for left and right headphone OCP to avoid |
| 271 | * additional checking on which OCP event to report so no locking |
| 272 | * to ensure synchronization is required |
| 273 | */ |
| 274 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 275 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 276 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 277 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 278 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 279 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 280 | /* Work to perform MBHC Firmware Read */ |
| 281 | struct delayed_work mbhc_firmware_dwork; |
| 282 | const struct firmware *mbhc_fw; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 283 | |
| 284 | /* num of slim ports required */ |
| 285 | struct tabla_codec_dai_data dai[NUM_CODEC_DAIS]; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 286 | |
| 287 | /*compander*/ |
| 288 | int comp_enabled[COMPANDER_MAX]; |
| 289 | u32 comp_fs[COMPANDER_MAX]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 290 | |
| 291 | /* Maintain the status of AUX PGA */ |
| 292 | int aux_pga_cnt; |
| 293 | u8 aux_l_gain; |
| 294 | u8 aux_r_gain; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 295 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 296 | struct delayed_work mbhc_insert_dwork; |
| 297 | unsigned long mbhc_last_resume; /* in jiffies */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 298 | |
| 299 | u8 current_plug; |
| 300 | struct work_struct hs_correct_plug_work; |
| 301 | bool hs_detect_work_stop; |
| 302 | bool hs_polling_irq_prepared; |
| 303 | bool lpi_enabled; /* low power insertion detection */ |
| 304 | bool in_gpio_handler; |
| 305 | /* Currently, only used for mbhc purpose, to protect |
| 306 | * concurrent execution of mbhc threaded irq handlers and |
| 307 | * kill race between DAPM and MBHC.But can serve as a |
| 308 | * general lock to protect codec resource |
| 309 | */ |
| 310 | struct mutex codec_resource_lock; |
| 311 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 312 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 313 | struct dentry *debugfs_poke; |
| 314 | struct dentry *debugfs_mbhc; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 315 | #endif |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 318 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 319 | static const u32 comp_shift[] = { |
| 320 | 0, |
| 321 | 2, |
| 322 | }; |
| 323 | |
| 324 | static const int comp_rx_path[] = { |
| 325 | COMPANDER_1, |
| 326 | COMPANDER_1, |
| 327 | COMPANDER_2, |
| 328 | COMPANDER_2, |
| 329 | COMPANDER_2, |
| 330 | COMPANDER_2, |
| 331 | COMPANDER_MAX, |
| 332 | }; |
| 333 | |
| 334 | static const struct comp_sample_dependent_params comp_samp_params[] = { |
| 335 | { |
| 336 | .peak_det_timeout = 0x2, |
| 337 | .rms_meter_div_fact = 0x8 << 4, |
| 338 | .rms_meter_resamp_fact = 0x21, |
| 339 | }, |
| 340 | { |
| 341 | .peak_det_timeout = 0x3, |
| 342 | .rms_meter_div_fact = 0x9 << 4, |
| 343 | .rms_meter_resamp_fact = 0x28, |
| 344 | }, |
| 345 | |
| 346 | { |
| 347 | .peak_det_timeout = 0x5, |
| 348 | .rms_meter_div_fact = 0xB << 4, |
| 349 | .rms_meter_resamp_fact = 0x28, |
| 350 | }, |
| 351 | |
| 352 | { |
| 353 | .peak_det_timeout = 0x5, |
| 354 | .rms_meter_div_fact = 0xB << 4, |
| 355 | .rms_meter_resamp_fact = 0x28, |
| 356 | }, |
| 357 | }; |
| 358 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 359 | static unsigned short rx_digital_gain_reg[] = { |
| 360 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 361 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 362 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 363 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 364 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 365 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 366 | TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 367 | }; |
| 368 | |
| 369 | |
| 370 | static unsigned short tx_digital_gain_reg[] = { |
| 371 | TABLA_A_CDC_TX1_VOL_CTL_GAIN, |
| 372 | TABLA_A_CDC_TX2_VOL_CTL_GAIN, |
| 373 | TABLA_A_CDC_TX3_VOL_CTL_GAIN, |
| 374 | TABLA_A_CDC_TX4_VOL_CTL_GAIN, |
| 375 | TABLA_A_CDC_TX5_VOL_CTL_GAIN, |
| 376 | TABLA_A_CDC_TX6_VOL_CTL_GAIN, |
| 377 | TABLA_A_CDC_TX7_VOL_CTL_GAIN, |
| 378 | TABLA_A_CDC_TX8_VOL_CTL_GAIN, |
| 379 | TABLA_A_CDC_TX9_VOL_CTL_GAIN, |
| 380 | TABLA_A_CDC_TX10_VOL_CTL_GAIN, |
| 381 | }; |
| 382 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 383 | static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 384 | struct snd_kcontrol *kcontrol, int event) |
| 385 | { |
| 386 | struct snd_soc_codec *codec = w->codec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 387 | |
| 388 | pr_debug("%s %d\n", __func__, event); |
| 389 | switch (event) { |
| 390 | case SND_SOC_DAPM_POST_PMU: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 392 | 0x01); |
| 393 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 394 | usleep_range(200, 200); |
| 395 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00); |
| 396 | break; |
| 397 | case SND_SOC_DAPM_PRE_PMD: |
| 398 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 399 | 0x10); |
| 400 | usleep_range(20, 20); |
| 401 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08); |
| 402 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10); |
| 403 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 404 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 405 | 0x00); |
| 406 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | return 0; |
| 410 | } |
| 411 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 412 | static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 413 | struct snd_ctl_elem_value *ucontrol) |
| 414 | { |
| 415 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 416 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 417 | ucontrol->value.integer.value[0] = tabla->anc_slot; |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 422 | struct snd_ctl_elem_value *ucontrol) |
| 423 | { |
| 424 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 425 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 426 | tabla->anc_slot = ucontrol->value.integer.value[0]; |
| 427 | return 0; |
| 428 | } |
| 429 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 430 | static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 431 | struct snd_ctl_elem_value *ucontrol) |
| 432 | { |
| 433 | u8 ear_pa_gain; |
| 434 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 435 | |
| 436 | ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN); |
| 437 | |
| 438 | ear_pa_gain = ear_pa_gain >> 5; |
| 439 | |
| 440 | if (ear_pa_gain == 0x00) { |
| 441 | ucontrol->value.integer.value[0] = 0; |
| 442 | } else if (ear_pa_gain == 0x04) { |
| 443 | ucontrol->value.integer.value[0] = 1; |
| 444 | } else { |
| 445 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 446 | __func__, ear_pa_gain); |
| 447 | return -EINVAL; |
| 448 | } |
| 449 | |
| 450 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 456 | struct snd_ctl_elem_value *ucontrol) |
| 457 | { |
| 458 | u8 ear_pa_gain; |
| 459 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 460 | |
| 461 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 462 | ucontrol->value.integer.value[0]); |
| 463 | |
| 464 | switch (ucontrol->value.integer.value[0]) { |
| 465 | case 0: |
| 466 | ear_pa_gain = 0x00; |
| 467 | break; |
| 468 | case 1: |
| 469 | ear_pa_gain = 0x80; |
| 470 | break; |
| 471 | default: |
| 472 | return -EINVAL; |
| 473 | } |
| 474 | |
| 475 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 476 | return 0; |
| 477 | } |
| 478 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 479 | static int tabla_get_iir_enable_audio_mixer( |
| 480 | struct snd_kcontrol *kcontrol, |
| 481 | struct snd_ctl_elem_value *ucontrol) |
| 482 | { |
| 483 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 484 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 485 | kcontrol->private_value)->reg; |
| 486 | int band_idx = ((struct soc_multi_mixer_control *) |
| 487 | kcontrol->private_value)->shift; |
| 488 | |
| 489 | ucontrol->value.integer.value[0] = |
| 490 | snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 491 | (1 << band_idx); |
| 492 | |
| 493 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 494 | iir_idx, band_idx, |
| 495 | (uint32_t)ucontrol->value.integer.value[0]); |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | static int tabla_put_iir_enable_audio_mixer( |
| 500 | struct snd_kcontrol *kcontrol, |
| 501 | struct snd_ctl_elem_value *ucontrol) |
| 502 | { |
| 503 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 504 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 505 | kcontrol->private_value)->reg; |
| 506 | int band_idx = ((struct soc_multi_mixer_control *) |
| 507 | kcontrol->private_value)->shift; |
| 508 | int value = ucontrol->value.integer.value[0]; |
| 509 | |
| 510 | /* Mask first 5 bits, 6-8 are reserved */ |
| 511 | snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 512 | (1 << band_idx), (value << band_idx)); |
| 513 | |
| 514 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 515 | iir_idx, band_idx, value); |
| 516 | return 0; |
| 517 | } |
| 518 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 519 | int iir_idx, int band_idx, |
| 520 | int coeff_idx) |
| 521 | { |
| 522 | /* Address does not automatically update if reading */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 523 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 524 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 525 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 526 | |
| 527 | /* Mask bits top 2 bits since they are reserved */ |
| 528 | return ((snd_soc_read(codec, |
| 529 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 530 | (snd_soc_read(codec, |
| 531 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 532 | (snd_soc_read(codec, |
| 533 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 534 | (snd_soc_read(codec, |
| 535 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 536 | 0x3FFFFFFF; |
| 537 | } |
| 538 | |
| 539 | static int tabla_get_iir_band_audio_mixer( |
| 540 | struct snd_kcontrol *kcontrol, |
| 541 | struct snd_ctl_elem_value *ucontrol) |
| 542 | { |
| 543 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 544 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 545 | kcontrol->private_value)->reg; |
| 546 | int band_idx = ((struct soc_multi_mixer_control *) |
| 547 | kcontrol->private_value)->shift; |
| 548 | |
| 549 | ucontrol->value.integer.value[0] = |
| 550 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 551 | ucontrol->value.integer.value[1] = |
| 552 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 553 | ucontrol->value.integer.value[2] = |
| 554 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 555 | ucontrol->value.integer.value[3] = |
| 556 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 557 | ucontrol->value.integer.value[4] = |
| 558 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 559 | |
| 560 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 561 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 562 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 563 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 564 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 565 | __func__, iir_idx, band_idx, |
| 566 | (uint32_t)ucontrol->value.integer.value[0], |
| 567 | __func__, iir_idx, band_idx, |
| 568 | (uint32_t)ucontrol->value.integer.value[1], |
| 569 | __func__, iir_idx, band_idx, |
| 570 | (uint32_t)ucontrol->value.integer.value[2], |
| 571 | __func__, iir_idx, band_idx, |
| 572 | (uint32_t)ucontrol->value.integer.value[3], |
| 573 | __func__, iir_idx, band_idx, |
| 574 | (uint32_t)ucontrol->value.integer.value[4]); |
| 575 | return 0; |
| 576 | } |
| 577 | |
| 578 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 579 | int iir_idx, int band_idx, |
| 580 | int coeff_idx, uint32_t value) |
| 581 | { |
| 582 | /* Mask top 3 bits, 6-8 are reserved */ |
| 583 | /* Update address manually each time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 584 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 585 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 586 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 587 | |
| 588 | /* Mask top 2 bits, 7-8 are reserved */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 589 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 590 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 591 | (value >> 24) & 0x3F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 592 | |
| 593 | /* Isolate 8bits at a time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 594 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 595 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 596 | (value >> 16) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 597 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 598 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 599 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 600 | (value >> 8) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 601 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 602 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 603 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 604 | value & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static int tabla_put_iir_band_audio_mixer( |
| 608 | struct snd_kcontrol *kcontrol, |
| 609 | struct snd_ctl_elem_value *ucontrol) |
| 610 | { |
| 611 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 612 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 613 | kcontrol->private_value)->reg; |
| 614 | int band_idx = ((struct soc_multi_mixer_control *) |
| 615 | kcontrol->private_value)->shift; |
| 616 | |
| 617 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 618 | ucontrol->value.integer.value[0]); |
| 619 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 620 | ucontrol->value.integer.value[1]); |
| 621 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 622 | ucontrol->value.integer.value[2]); |
| 623 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 624 | ucontrol->value.integer.value[3]); |
| 625 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 626 | ucontrol->value.integer.value[4]); |
| 627 | |
| 628 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 629 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 630 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 631 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 632 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 633 | __func__, iir_idx, band_idx, |
| 634 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 635 | __func__, iir_idx, band_idx, |
| 636 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 637 | __func__, iir_idx, band_idx, |
| 638 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 639 | __func__, iir_idx, band_idx, |
| 640 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 641 | __func__, iir_idx, band_idx, |
| 642 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 643 | return 0; |
| 644 | } |
| 645 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 646 | static int tabla_compander_gain_offset( |
| 647 | struct snd_soc_codec *codec, u32 enable, |
| 648 | unsigned int reg, int mask, int event) |
| 649 | { |
| 650 | int pa_mode = snd_soc_read(codec, reg) & mask; |
| 651 | int gain_offset = 0; |
| 652 | /* if PMU && enable is 1-> offset is 3 |
| 653 | * if PMU && enable is 0-> offset is 0 |
| 654 | * if PMD && pa_mode is PA -> offset is 0: PMU compander is off |
| 655 | * if PMD && pa_mode is comp -> offset is -3: PMU compander is on. |
| 656 | */ |
| 657 | |
| 658 | if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) |
| 659 | gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 660 | if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) |
| 661 | gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 662 | return gain_offset; |
| 663 | } |
| 664 | |
| 665 | |
| 666 | static int tabla_config_gain_compander( |
| 667 | struct snd_soc_codec *codec, |
| 668 | u32 compander, u32 enable, int event) |
| 669 | { |
| 670 | int value = 0; |
| 671 | int mask = 1 << 4; |
| 672 | int gain = 0; |
| 673 | int gain_offset; |
| 674 | if (compander >= COMPANDER_MAX) { |
| 675 | pr_err("%s: Error, invalid compander channel\n", __func__); |
| 676 | return -EINVAL; |
| 677 | } |
| 678 | |
| 679 | if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event)) |
| 680 | value = 1 << 4; |
| 681 | |
| 682 | if (compander == COMPANDER_1) { |
| 683 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 684 | TABLA_A_RX_HPH_L_GAIN, mask, event); |
| 685 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value); |
| 686 | gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL); |
| 687 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 688 | 0xFF, gain - gain_offset); |
| 689 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 690 | TABLA_A_RX_HPH_R_GAIN, mask, event); |
| 691 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value); |
| 692 | gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL); |
| 693 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 694 | 0xFF, gain - gain_offset); |
| 695 | } else if (compander == COMPANDER_2) { |
| 696 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 697 | TABLA_A_RX_LINE_1_GAIN, mask, event); |
| 698 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value); |
| 699 | gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL); |
| 700 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 701 | 0xFF, gain - gain_offset); |
| 702 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 703 | TABLA_A_RX_LINE_3_GAIN, mask, event); |
| 704 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value); |
| 705 | gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL); |
| 706 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 707 | 0xFF, gain - gain_offset); |
| 708 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 709 | TABLA_A_RX_LINE_2_GAIN, mask, event); |
| 710 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value); |
| 711 | gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL); |
| 712 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 713 | 0xFF, gain - gain_offset); |
| 714 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 715 | TABLA_A_RX_LINE_4_GAIN, mask, event); |
| 716 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value); |
| 717 | gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL); |
| 718 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 719 | 0xFF, gain - gain_offset); |
| 720 | } |
| 721 | return 0; |
| 722 | } |
| 723 | static int tabla_get_compander(struct snd_kcontrol *kcontrol, |
| 724 | struct snd_ctl_elem_value *ucontrol) |
| 725 | { |
| 726 | |
| 727 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 728 | int comp = ((struct soc_multi_mixer_control *) |
| 729 | kcontrol->private_value)->max; |
| 730 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 731 | |
| 732 | ucontrol->value.integer.value[0] = tabla->comp_enabled[comp]; |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | static int tabla_set_compander(struct snd_kcontrol *kcontrol, |
| 738 | struct snd_ctl_elem_value *ucontrol) |
| 739 | { |
| 740 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 741 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 742 | int comp = ((struct soc_multi_mixer_control *) |
| 743 | kcontrol->private_value)->max; |
| 744 | int value = ucontrol->value.integer.value[0]; |
| 745 | |
| 746 | if (value == tabla->comp_enabled[comp]) { |
| 747 | pr_debug("%s: compander #%d enable %d no change\n", |
| 748 | __func__, comp, value); |
| 749 | return 0; |
| 750 | } |
| 751 | tabla->comp_enabled[comp] = value; |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | static int tabla_config_compander(struct snd_soc_dapm_widget *w, |
| 757 | struct snd_kcontrol *kcontrol, |
| 758 | int event) |
| 759 | { |
| 760 | struct snd_soc_codec *codec = w->codec; |
| 761 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 762 | u32 rate = tabla->comp_fs[w->shift]; |
| 763 | |
| 764 | switch (event) { |
| 765 | case SND_SOC_DAPM_PRE_PMU: |
| 766 | if (tabla->comp_enabled[w->shift] != 0) { |
| 767 | /* Enable both L/R compander clocks */ |
| 768 | snd_soc_update_bits(codec, |
| 769 | TABLA_A_CDC_CLK_RX_B2_CTL, |
| 770 | 0x03 << comp_shift[w->shift], |
| 771 | 0x03 << comp_shift[w->shift]); |
| 772 | /* Clar the HALT for the compander*/ |
| 773 | snd_soc_update_bits(codec, |
| 774 | TABLA_A_CDC_COMP1_B1_CTL + |
| 775 | w->shift * 8, 1 << 2, 0); |
| 776 | /* Toggle compander reset bits*/ |
| 777 | snd_soc_update_bits(codec, |
| 778 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 779 | 0x03 << comp_shift[w->shift], |
| 780 | 0x03 << comp_shift[w->shift]); |
| 781 | snd_soc_update_bits(codec, |
| 782 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 783 | 0x03 << comp_shift[w->shift], 0); |
| 784 | tabla_config_gain_compander(codec, w->shift, 1, event); |
| 785 | /* Update the RMS meter resampling*/ |
| 786 | snd_soc_update_bits(codec, |
| 787 | TABLA_A_CDC_COMP1_B3_CTL + |
| 788 | w->shift * 8, 0xFF, 0x01); |
| 789 | /* Wait for 1ms*/ |
| 790 | usleep_range(1000, 1000); |
| 791 | } |
| 792 | break; |
| 793 | case SND_SOC_DAPM_POST_PMU: |
| 794 | /* Set sample rate dependent paramater*/ |
| 795 | if (tabla->comp_enabled[w->shift] != 0) { |
| 796 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG + |
| 797 | w->shift * 8, 0x03, rate); |
| 798 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 799 | w->shift * 8, 0x0F, |
| 800 | comp_samp_params[rate].peak_det_timeout); |
| 801 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 802 | w->shift * 8, 0xF0, |
| 803 | comp_samp_params[rate].rms_meter_div_fact); |
| 804 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL + |
| 805 | w->shift * 8, 0xFF, |
| 806 | comp_samp_params[rate].rms_meter_resamp_fact); |
| 807 | /* Compander enable -> 0x370/0x378*/ |
| 808 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 809 | w->shift * 8, 0x03, 0x03); |
| 810 | } |
| 811 | break; |
| 812 | case SND_SOC_DAPM_PRE_PMD: |
| 813 | /* Halt the compander*/ |
| 814 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 815 | w->shift * 8, 1 << 2, 1 << 2); |
| 816 | break; |
| 817 | case SND_SOC_DAPM_POST_PMD: |
| 818 | /* Restore the gain */ |
| 819 | tabla_config_gain_compander(codec, w->shift, |
| 820 | tabla->comp_enabled[w->shift], event); |
| 821 | /* Disable the compander*/ |
| 822 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 823 | w->shift * 8, 0x03, 0x00); |
| 824 | /* Turn off the clock for compander in pair*/ |
| 825 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL, |
| 826 | 0x03 << comp_shift[w->shift], 0); |
| 827 | break; |
| 828 | } |
| 829 | return 0; |
| 830 | } |
| 831 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 832 | static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 833 | static const struct soc_enum tabla_ear_pa_gain_enum[] = { |
| 834 | SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text), |
| 835 | }; |
| 836 | |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 837 | /*cut of frequency for high pass filter*/ |
| 838 | static const char *cf_text[] = { |
| 839 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 840 | }; |
| 841 | |
| 842 | static const struct soc_enum cf_dec1_enum = |
| 843 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 844 | |
| 845 | static const struct soc_enum cf_dec2_enum = |
| 846 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 847 | |
| 848 | static const struct soc_enum cf_dec3_enum = |
| 849 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 850 | |
| 851 | static const struct soc_enum cf_dec4_enum = |
| 852 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 853 | |
| 854 | static const struct soc_enum cf_dec5_enum = |
| 855 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text); |
| 856 | |
| 857 | static const struct soc_enum cf_dec6_enum = |
| 858 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text); |
| 859 | |
| 860 | static const struct soc_enum cf_dec7_enum = |
| 861 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text); |
| 862 | |
| 863 | static const struct soc_enum cf_dec8_enum = |
| 864 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text); |
| 865 | |
| 866 | static const struct soc_enum cf_dec9_enum = |
| 867 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text); |
| 868 | |
| 869 | static const struct soc_enum cf_dec10_enum = |
| 870 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text); |
| 871 | |
| 872 | static const struct soc_enum cf_rxmix1_enum = |
| 873 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 874 | |
| 875 | static const struct soc_enum cf_rxmix2_enum = |
| 876 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text); |
| 877 | |
| 878 | static const struct soc_enum cf_rxmix3_enum = |
| 879 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text); |
| 880 | |
| 881 | static const struct soc_enum cf_rxmix4_enum = |
| 882 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text); |
| 883 | |
| 884 | static const struct soc_enum cf_rxmix5_enum = |
| 885 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text) |
| 886 | ; |
| 887 | static const struct soc_enum cf_rxmix6_enum = |
| 888 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text); |
| 889 | |
| 890 | static const struct soc_enum cf_rxmix7_enum = |
| 891 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text); |
| 892 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 893 | static const struct snd_kcontrol_new tabla_snd_controls[] = { |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 894 | |
| 895 | SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0], |
| 896 | tabla_pa_gain_get, tabla_pa_gain_put), |
| 897 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 898 | SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 899 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 900 | SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 901 | line_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 902 | SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1, |
| 903 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 904 | SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1, |
| 905 | line_gain), |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 906 | SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1, |
| 907 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 908 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 909 | SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 910 | line_gain), |
| 911 | SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 912 | line_gain), |
| 913 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 914 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 915 | -84, 40, digital_gain), |
| 916 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 917 | -84, 40, digital_gain), |
| 918 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 919 | -84, 40, digital_gain), |
| 920 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 921 | -84, 40, digital_gain), |
| 922 | SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 923 | -84, 40, digital_gain), |
| 924 | SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 925 | -84, 40, digital_gain), |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 926 | SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 927 | -84, 40, digital_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 928 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 929 | SOC_SINGLE_S8_TLV("DEC1 Volume", TABLA_A_CDC_TX1_VOL_CTL_GAIN, -84, 40, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 930 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 931 | SOC_SINGLE_S8_TLV("DEC2 Volume", TABLA_A_CDC_TX2_VOL_CTL_GAIN, -84, 40, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 932 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 933 | SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 934 | digital_gain), |
| 935 | SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 936 | digital_gain), |
| 937 | SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40, |
| 938 | digital_gain), |
| 939 | SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40, |
| 940 | digital_gain), |
| 941 | SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40, |
| 942 | digital_gain), |
| 943 | SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40, |
| 944 | digital_gain), |
| 945 | SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40, |
| 946 | digital_gain), |
| 947 | SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84, |
| 948 | 40, digital_gain), |
Patrick Lai | 2900637 | 2011-09-28 17:57:42 -0700 | [diff] [blame] | 949 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 950 | 40, digital_gain), |
| 951 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 952 | 40, digital_gain), |
| 953 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 954 | 40, digital_gain), |
| 955 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 956 | 40, digital_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 957 | SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 958 | SOC_SINGLE_TLV("ADC2 Volume", TABLA_A_TX_1_2_EN, 1, 3, 0, analog_gain), |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 959 | SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain), |
| 960 | SOC_SINGLE_TLV("ADC4 Volume", TABLA_A_TX_3_4_EN, 1, 3, 0, analog_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 961 | SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain), |
| 962 | SOC_SINGLE_TLV("ADC6 Volume", TABLA_A_TX_5_6_EN, 1, 3, 0, analog_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 963 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 964 | SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0, |
| 965 | aux_pga_gain), |
| 966 | SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0, |
| 967 | aux_pga_gain), |
| 968 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 969 | SOC_SINGLE("MICBIAS1 CAPLESS Switch", TABLA_A_MICB_1_CTL, 4, 1, 1), |
Santosh Mardi | 680b41e | 2011-11-22 16:51:16 -0800 | [diff] [blame] | 970 | SOC_SINGLE("MICBIAS2 CAPLESS Switch", TABLA_A_MICB_2_CTL, 4, 1, 1), |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 971 | SOC_SINGLE("MICBIAS3 CAPLESS Switch", TABLA_A_MICB_3_CTL, 4, 1, 1), |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 972 | |
| 973 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot, |
| 974 | tabla_put_anc_slot), |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 975 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 976 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 977 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 978 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 979 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 980 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 981 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 982 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 983 | SOC_ENUM("TX9 HPF cut off", cf_dec9_enum), |
| 984 | SOC_ENUM("TX10 HPF cut off", cf_dec10_enum), |
| 985 | |
| 986 | SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 987 | SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 988 | SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 989 | SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 990 | SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0), |
| 991 | SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0), |
| 992 | SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0), |
| 993 | SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0), |
| 994 | SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0), |
| 995 | SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0), |
| 996 | |
| 997 | SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 998 | SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 999 | SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 1000 | SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1001 | SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0), |
| 1002 | SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0), |
| 1003 | SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0), |
| 1004 | |
| 1005 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1006 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1007 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 1008 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 1009 | SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum), |
| 1010 | SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum), |
| 1011 | SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum), |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 1012 | |
| 1013 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1014 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1015 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1016 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1017 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1018 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1019 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1020 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1021 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1022 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1023 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1024 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1025 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1026 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1027 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1028 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1029 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1030 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1031 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1032 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1033 | |
| 1034 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1035 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1036 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1037 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1038 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1039 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1040 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1041 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1042 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1043 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1044 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1045 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1046 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1047 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1048 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1049 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1050 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1051 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1052 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1053 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1054 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0, |
| 1055 | tabla_get_compander, tabla_set_compander), |
| 1056 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0, |
| 1057 | tabla_get_compander, tabla_set_compander), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1058 | }; |
| 1059 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 1060 | static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = { |
| 1061 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1), |
| 1062 | }; |
| 1063 | |
| 1064 | static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = { |
| 1065 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1), |
| 1066 | }; |
| 1067 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1068 | static const char *rx_mix1_text[] = { |
| 1069 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1070 | "RX5", "RX6", "RX7" |
| 1071 | }; |
| 1072 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1073 | static const char *rx_mix2_text[] = { |
| 1074 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1075 | }; |
| 1076 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1077 | static const char *rx_dsm_text[] = { |
| 1078 | "CIC_OUT", "DSM_INV" |
| 1079 | }; |
| 1080 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1081 | static const char *sb_tx1_mux_text[] = { |
| 1082 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1083 | "DEC1" |
| 1084 | }; |
| 1085 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1086 | static const char *sb_tx2_mux_text[] = { |
| 1087 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1088 | "DEC2" |
| 1089 | }; |
| 1090 | |
| 1091 | static const char *sb_tx3_mux_text[] = { |
| 1092 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1093 | "DEC3" |
| 1094 | }; |
| 1095 | |
| 1096 | static const char *sb_tx4_mux_text[] = { |
| 1097 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1098 | "DEC4" |
| 1099 | }; |
| 1100 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1101 | static const char *sb_tx5_mux_text[] = { |
| 1102 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1103 | "DEC5" |
| 1104 | }; |
| 1105 | |
| 1106 | static const char *sb_tx6_mux_text[] = { |
| 1107 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1108 | "DEC6" |
| 1109 | }; |
| 1110 | |
| 1111 | static const char const *sb_tx7_to_tx10_mux_text[] = { |
| 1112 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1113 | "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1114 | "DEC9", "DEC10" |
| 1115 | }; |
| 1116 | |
| 1117 | static const char *dec1_mux_text[] = { |
| 1118 | "ZERO", "DMIC1", "ADC6", |
| 1119 | }; |
| 1120 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1121 | static const char *dec2_mux_text[] = { |
| 1122 | "ZERO", "DMIC2", "ADC5", |
| 1123 | }; |
| 1124 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1125 | static const char *dec3_mux_text[] = { |
| 1126 | "ZERO", "DMIC3", "ADC4", |
| 1127 | }; |
| 1128 | |
| 1129 | static const char *dec4_mux_text[] = { |
| 1130 | "ZERO", "DMIC4", "ADC3", |
| 1131 | }; |
| 1132 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1133 | static const char *dec5_mux_text[] = { |
| 1134 | "ZERO", "DMIC5", "ADC2", |
| 1135 | }; |
| 1136 | |
| 1137 | static const char *dec6_mux_text[] = { |
| 1138 | "ZERO", "DMIC6", "ADC1", |
| 1139 | }; |
| 1140 | |
| 1141 | static const char const *dec7_mux_text[] = { |
| 1142 | "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB", |
| 1143 | }; |
| 1144 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1145 | static const char *dec8_mux_text[] = { |
| 1146 | "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5", |
| 1147 | }; |
| 1148 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1149 | static const char *dec9_mux_text[] = { |
| 1150 | "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1151 | }; |
| 1152 | |
| 1153 | static const char *dec10_mux_text[] = { |
| 1154 | "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1155 | }; |
| 1156 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1157 | static const char const *anc_mux_text[] = { |
| 1158 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB", |
| 1159 | "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6" |
| 1160 | }; |
| 1161 | |
| 1162 | static const char const *anc1_fb_mux_text[] = { |
| 1163 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1164 | }; |
| 1165 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1166 | static const char *iir1_inp1_text[] = { |
| 1167 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1168 | "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 1169 | }; |
| 1170 | |
| 1171 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 1172 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text); |
| 1173 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1174 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 1175 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text); |
| 1176 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1177 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 1178 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text); |
| 1179 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1180 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 1181 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text); |
| 1182 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1183 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 1184 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text); |
| 1185 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1186 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 1187 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text); |
| 1188 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1189 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
| 1190 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text); |
| 1191 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1192 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
| 1193 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text); |
| 1194 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1195 | static const struct soc_enum rx5_mix1_inp1_chain_enum = |
| 1196 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text); |
| 1197 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1198 | static const struct soc_enum rx5_mix1_inp2_chain_enum = |
| 1199 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text); |
| 1200 | |
| 1201 | static const struct soc_enum rx6_mix1_inp1_chain_enum = |
| 1202 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text); |
| 1203 | |
| 1204 | static const struct soc_enum rx6_mix1_inp2_chain_enum = |
| 1205 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text); |
| 1206 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1207 | static const struct soc_enum rx7_mix1_inp1_chain_enum = |
| 1208 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text); |
| 1209 | |
| 1210 | static const struct soc_enum rx7_mix1_inp2_chain_enum = |
| 1211 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text); |
| 1212 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1213 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1214 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1215 | |
| 1216 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1217 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1218 | |
| 1219 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1220 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1221 | |
| 1222 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1223 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1224 | |
| 1225 | static const struct soc_enum rx3_mix2_inp1_chain_enum = |
| 1226 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text); |
| 1227 | |
| 1228 | static const struct soc_enum rx3_mix2_inp2_chain_enum = |
| 1229 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text); |
| 1230 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1231 | static const struct soc_enum rx4_dsm_enum = |
| 1232 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text); |
| 1233 | |
| 1234 | static const struct soc_enum rx6_dsm_enum = |
| 1235 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text); |
| 1236 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1237 | static const struct soc_enum sb_tx1_mux_enum = |
| 1238 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 1239 | |
| 1240 | static const struct soc_enum sb_tx2_mux_enum = |
| 1241 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 1242 | |
| 1243 | static const struct soc_enum sb_tx3_mux_enum = |
| 1244 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 1245 | |
| 1246 | static const struct soc_enum sb_tx4_mux_enum = |
| 1247 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 1248 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1249 | static const struct soc_enum sb_tx5_mux_enum = |
| 1250 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 1251 | |
| 1252 | static const struct soc_enum sb_tx6_mux_enum = |
| 1253 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text); |
| 1254 | |
| 1255 | static const struct soc_enum sb_tx7_mux_enum = |
| 1256 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18, |
| 1257 | sb_tx7_to_tx10_mux_text); |
| 1258 | |
| 1259 | static const struct soc_enum sb_tx8_mux_enum = |
| 1260 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18, |
| 1261 | sb_tx7_to_tx10_mux_text); |
| 1262 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1263 | static const struct soc_enum sb_tx9_mux_enum = |
| 1264 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18, |
| 1265 | sb_tx7_to_tx10_mux_text); |
| 1266 | |
| 1267 | static const struct soc_enum sb_tx10_mux_enum = |
| 1268 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18, |
| 1269 | sb_tx7_to_tx10_mux_text); |
| 1270 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1271 | static const struct soc_enum dec1_mux_enum = |
| 1272 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text); |
| 1273 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1274 | static const struct soc_enum dec2_mux_enum = |
| 1275 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text); |
| 1276 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1277 | static const struct soc_enum dec3_mux_enum = |
| 1278 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text); |
| 1279 | |
| 1280 | static const struct soc_enum dec4_mux_enum = |
| 1281 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text); |
| 1282 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1283 | static const struct soc_enum dec5_mux_enum = |
| 1284 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text); |
| 1285 | |
| 1286 | static const struct soc_enum dec6_mux_enum = |
| 1287 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text); |
| 1288 | |
| 1289 | static const struct soc_enum dec7_mux_enum = |
| 1290 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text); |
| 1291 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1292 | static const struct soc_enum dec8_mux_enum = |
| 1293 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text); |
| 1294 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1295 | static const struct soc_enum dec9_mux_enum = |
| 1296 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text); |
| 1297 | |
| 1298 | static const struct soc_enum dec10_mux_enum = |
| 1299 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text); |
| 1300 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1301 | static const struct soc_enum anc1_mux_enum = |
| 1302 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text); |
| 1303 | |
| 1304 | static const struct soc_enum anc2_mux_enum = |
| 1305 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text); |
| 1306 | |
| 1307 | static const struct soc_enum anc1_fb_mux_enum = |
| 1308 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1309 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1310 | static const struct soc_enum iir1_inp1_mux_enum = |
| 1311 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text); |
| 1312 | |
| 1313 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1314 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1315 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1316 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1317 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1318 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1319 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1320 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1321 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1322 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1323 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1324 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1325 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1326 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1327 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1328 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1329 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1330 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1331 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1332 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1333 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1334 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1335 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1336 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1337 | static const struct snd_kcontrol_new rx5_mix1_inp1_mux = |
| 1338 | SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum); |
| 1339 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1340 | static const struct snd_kcontrol_new rx5_mix1_inp2_mux = |
| 1341 | SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum); |
| 1342 | |
| 1343 | static const struct snd_kcontrol_new rx6_mix1_inp1_mux = |
| 1344 | SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum); |
| 1345 | |
| 1346 | static const struct snd_kcontrol_new rx6_mix1_inp2_mux = |
| 1347 | SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum); |
| 1348 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1349 | static const struct snd_kcontrol_new rx7_mix1_inp1_mux = |
| 1350 | SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum); |
| 1351 | |
| 1352 | static const struct snd_kcontrol_new rx7_mix1_inp2_mux = |
| 1353 | SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum); |
| 1354 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1355 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1356 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1357 | |
| 1358 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1359 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1360 | |
| 1361 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1362 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1363 | |
| 1364 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1365 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1366 | |
| 1367 | static const struct snd_kcontrol_new rx3_mix2_inp1_mux = |
| 1368 | SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum); |
| 1369 | |
| 1370 | static const struct snd_kcontrol_new rx3_mix2_inp2_mux = |
| 1371 | SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum); |
| 1372 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1373 | static const struct snd_kcontrol_new rx4_dsm_mux = |
| 1374 | SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum); |
| 1375 | |
| 1376 | static const struct snd_kcontrol_new rx6_dsm_mux = |
| 1377 | SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum); |
| 1378 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1379 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1380 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1381 | |
| 1382 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1383 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1384 | |
| 1385 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1386 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1387 | |
| 1388 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1389 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1390 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1391 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 1392 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 1393 | |
| 1394 | static const struct snd_kcontrol_new sb_tx6_mux = |
| 1395 | SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); |
| 1396 | |
| 1397 | static const struct snd_kcontrol_new sb_tx7_mux = |
| 1398 | SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); |
| 1399 | |
| 1400 | static const struct snd_kcontrol_new sb_tx8_mux = |
| 1401 | SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); |
| 1402 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1403 | static const struct snd_kcontrol_new sb_tx9_mux = |
| 1404 | SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum); |
| 1405 | |
| 1406 | static const struct snd_kcontrol_new sb_tx10_mux = |
| 1407 | SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum); |
| 1408 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1409 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1410 | static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1411 | struct snd_ctl_elem_value *ucontrol) |
| 1412 | { |
| 1413 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1414 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1415 | struct snd_soc_codec *codec = w->codec; |
| 1416 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1417 | unsigned int dec_mux, decimator; |
| 1418 | char *dec_name = NULL; |
| 1419 | char *widget_name = NULL; |
| 1420 | char *temp; |
| 1421 | u16 tx_mux_ctl_reg; |
| 1422 | u8 adc_dmic_sel = 0x0; |
| 1423 | int ret = 0; |
| 1424 | |
| 1425 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1426 | return -EINVAL; |
| 1427 | |
| 1428 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1429 | |
| 1430 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1431 | if (!widget_name) |
| 1432 | return -ENOMEM; |
| 1433 | temp = widget_name; |
| 1434 | |
| 1435 | dec_name = strsep(&widget_name, " "); |
| 1436 | widget_name = temp; |
| 1437 | if (!dec_name) { |
| 1438 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1439 | ret = -EINVAL; |
| 1440 | goto out; |
| 1441 | } |
| 1442 | |
| 1443 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 1444 | if (ret < 0) { |
| 1445 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1446 | ret = -EINVAL; |
| 1447 | goto out; |
| 1448 | } |
| 1449 | |
| 1450 | dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u" |
| 1451 | " dec_mux = %u\n", __func__, w->name, dec_name, decimator, |
| 1452 | dec_mux); |
| 1453 | |
| 1454 | |
| 1455 | switch (decimator) { |
| 1456 | case 1: |
| 1457 | case 2: |
| 1458 | case 3: |
| 1459 | case 4: |
| 1460 | case 5: |
| 1461 | case 6: |
| 1462 | if (dec_mux == 1) |
| 1463 | adc_dmic_sel = 0x1; |
| 1464 | else |
| 1465 | adc_dmic_sel = 0x0; |
| 1466 | break; |
| 1467 | case 7: |
| 1468 | case 8: |
| 1469 | case 9: |
| 1470 | case 10: |
| 1471 | if ((dec_mux == 1) || (dec_mux == 2)) |
| 1472 | adc_dmic_sel = 0x1; |
| 1473 | else |
| 1474 | adc_dmic_sel = 0x0; |
| 1475 | break; |
| 1476 | default: |
| 1477 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1478 | ret = -EINVAL; |
| 1479 | goto out; |
| 1480 | } |
| 1481 | |
| 1482 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1483 | |
| 1484 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1485 | |
| 1486 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1487 | |
| 1488 | out: |
| 1489 | kfree(widget_name); |
| 1490 | return ret; |
| 1491 | } |
| 1492 | |
| 1493 | #define WCD9310_DEC_ENUM(xname, xenum) \ |
| 1494 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1495 | .info = snd_soc_info_enum_double, \ |
| 1496 | .get = snd_soc_dapm_get_enum_double, \ |
| 1497 | .put = wcd9310_put_dec_enum, \ |
| 1498 | .private_value = (unsigned long)&xenum } |
| 1499 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1500 | static const struct snd_kcontrol_new dec1_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1501 | WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1502 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1503 | static const struct snd_kcontrol_new dec2_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1504 | WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1505 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1506 | static const struct snd_kcontrol_new dec3_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1507 | WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1508 | |
| 1509 | static const struct snd_kcontrol_new dec4_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1510 | WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1511 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1512 | static const struct snd_kcontrol_new dec5_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1513 | WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1514 | |
| 1515 | static const struct snd_kcontrol_new dec6_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1516 | WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1517 | |
| 1518 | static const struct snd_kcontrol_new dec7_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1519 | WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1520 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1521 | static const struct snd_kcontrol_new dec8_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1522 | WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1523 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1524 | static const struct snd_kcontrol_new dec9_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1525 | WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1526 | |
| 1527 | static const struct snd_kcontrol_new dec10_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1528 | WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1529 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1530 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1531 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1532 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1533 | static const struct snd_kcontrol_new anc1_mux = |
| 1534 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1535 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1536 | static const struct snd_kcontrol_new anc2_mux = |
| 1537 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1538 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1539 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1540 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1541 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1542 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1543 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0) |
| 1544 | }; |
| 1545 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1546 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1547 | }; |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1548 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1549 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1550 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1551 | 7, 1, 0), |
| 1552 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1553 | 7, 1, 0), |
| 1554 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1555 | TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0), |
| 1556 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1557 | TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0), |
| 1558 | }; |
| 1559 | |
| 1560 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1561 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1562 | 6, 1, 0), |
| 1563 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1564 | 6, 1, 0), |
| 1565 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1566 | TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0), |
| 1567 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1568 | TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0), |
| 1569 | }; |
| 1570 | |
| 1571 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1572 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1573 | 5, 1, 0), |
| 1574 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1575 | 5, 1, 0), |
| 1576 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1577 | TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0), |
| 1578 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1579 | TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0), |
| 1580 | }; |
| 1581 | |
| 1582 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1583 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1584 | 4, 1, 0), |
| 1585 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1586 | 4, 1, 0), |
| 1587 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1588 | TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0), |
| 1589 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1590 | TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0), |
| 1591 | }; |
| 1592 | |
| 1593 | static const struct snd_kcontrol_new lineout3_pa_mix[] = { |
| 1594 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1595 | 3, 1, 0), |
| 1596 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1597 | 3, 1, 0), |
| 1598 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1599 | TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0), |
| 1600 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1601 | TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0), |
| 1602 | }; |
| 1603 | |
| 1604 | static const struct snd_kcontrol_new lineout4_pa_mix[] = { |
| 1605 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1606 | 2, 1, 0), |
| 1607 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1608 | 2, 1, 0), |
| 1609 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1610 | TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0), |
| 1611 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1612 | TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0), |
| 1613 | }; |
| 1614 | |
| 1615 | static const struct snd_kcontrol_new lineout5_pa_mix[] = { |
| 1616 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1617 | 1, 1, 0), |
| 1618 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1619 | 1, 1, 0), |
| 1620 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1621 | TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0), |
| 1622 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1623 | TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0), |
| 1624 | }; |
| 1625 | |
| 1626 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1627 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1628 | 0, 1, 0), |
| 1629 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1630 | 0, 1, 0), |
| 1631 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1632 | TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0), |
| 1633 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1634 | TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0), |
| 1635 | }; |
| 1636 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1637 | static const struct snd_kcontrol_new lineout3_ground_switch = |
| 1638 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0); |
| 1639 | |
| 1640 | static const struct snd_kcontrol_new lineout4_ground_switch = |
| 1641 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_4_DAC_CTL, 6, 1, 0); |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1642 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1643 | static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1644 | int enable) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1645 | { |
| 1646 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1647 | |
| 1648 | pr_debug("%s %d\n", __func__, enable); |
| 1649 | |
| 1650 | if (enable) { |
| 1651 | tabla->adc_count++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1652 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2); |
| 1653 | } else { |
| 1654 | tabla->adc_count--; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1655 | if (!tabla->adc_count) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1656 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 1657 | 0x2, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 1662 | struct snd_kcontrol *kcontrol, int event) |
| 1663 | { |
| 1664 | struct snd_soc_codec *codec = w->codec; |
| 1665 | u16 adc_reg; |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1666 | u8 init_bit_shift; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1667 | |
| 1668 | pr_debug("%s %d\n", __func__, event); |
| 1669 | |
| 1670 | if (w->reg == TABLA_A_TX_1_2_EN) |
| 1671 | adc_reg = TABLA_A_TX_1_2_TEST_CTL; |
| 1672 | else if (w->reg == TABLA_A_TX_3_4_EN) |
| 1673 | adc_reg = TABLA_A_TX_3_4_TEST_CTL; |
| 1674 | else if (w->reg == TABLA_A_TX_5_6_EN) |
| 1675 | adc_reg = TABLA_A_TX_5_6_TEST_CTL; |
| 1676 | else { |
| 1677 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 1678 | return -EINVAL; |
| 1679 | } |
| 1680 | |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1681 | if (w->shift == 3) |
| 1682 | init_bit_shift = 6; |
| 1683 | else if (w->shift == 7) |
| 1684 | init_bit_shift = 7; |
| 1685 | else { |
| 1686 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 1687 | __func__); |
| 1688 | return -EINVAL; |
| 1689 | } |
| 1690 | |
| 1691 | |
| 1692 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1693 | switch (event) { |
| 1694 | case SND_SOC_DAPM_PRE_PMU: |
| 1695 | tabla_codec_enable_adc_block(codec, 1); |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1696 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 1697 | 1 << init_bit_shift); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1698 | break; |
| 1699 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1700 | |
| 1701 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 1702 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1703 | break; |
| 1704 | case SND_SOC_DAPM_POST_PMD: |
| 1705 | tabla_codec_enable_adc_block(codec, 0); |
| 1706 | break; |
| 1707 | } |
| 1708 | return 0; |
| 1709 | } |
| 1710 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1711 | static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 1712 | { |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1713 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1714 | 0x80); |
| 1715 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 1716 | 0x04); |
| 1717 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1718 | 0x01); |
| 1719 | usleep_range(1000, 1000); |
| 1720 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1721 | 0x00); |
| 1722 | } |
| 1723 | |
| 1724 | static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 1725 | enum tabla_bandgap_type choice) |
| 1726 | { |
| 1727 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1728 | |
| 1729 | /* TODO lock resources accessed by audio streams and threaded |
| 1730 | * interrupt handlers |
| 1731 | */ |
| 1732 | |
| 1733 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
| 1734 | tabla->bandgap_type); |
| 1735 | |
| 1736 | if (tabla->bandgap_type == choice) |
| 1737 | return; |
| 1738 | |
| 1739 | if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) && |
| 1740 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 1741 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 1742 | } else if (choice == TABLA_BANDGAP_MBHC_MODE) { |
| 1743 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 1744 | 0x2); |
| 1745 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1746 | 0x80); |
| 1747 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 1748 | 0x4); |
| 1749 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 1750 | 0x01); |
| 1751 | usleep_range(1000, 1000); |
| 1752 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 1753 | 0x00); |
| 1754 | } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) && |
| 1755 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 1756 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00); |
| 1757 | usleep_range(100, 100); |
| 1758 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 1759 | } else if (choice == TABLA_BANDGAP_OFF) { |
| 1760 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x00); |
| 1761 | } else { |
| 1762 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 1763 | } |
| 1764 | tabla->bandgap_type = choice; |
| 1765 | } |
| 1766 | |
| 1767 | static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 1768 | { |
| 1769 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1770 | pr_debug("%s\n", __func__); |
| 1771 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00); |
| 1772 | ndelay(160); |
| 1773 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 1774 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00); |
| 1775 | tabla->clock_active = false; |
| 1776 | } |
| 1777 | |
| 1778 | static int tabla_codec_mclk_index(const struct tabla_priv *tabla) |
| 1779 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1780 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1781 | return 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1782 | else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1783 | return 1; |
| 1784 | else { |
| 1785 | BUG_ON(1); |
| 1786 | return -EINVAL; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 1791 | { |
| 1792 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1793 | |
| 1794 | if (enable) { |
| 1795 | tabla->rx_bias_count++; |
| 1796 | if (tabla->rx_bias_count == 1) |
| 1797 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 1798 | 0x80, 0x80); |
| 1799 | } else { |
| 1800 | tabla->rx_bias_count--; |
| 1801 | if (!tabla->rx_bias_count) |
| 1802 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 1803 | 0x80, 0x00); |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 1808 | int enable) |
| 1809 | { |
| 1810 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1811 | |
| 1812 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 1813 | if (enable) { |
| 1814 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0); |
| 1815 | snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17); |
| 1816 | usleep_range(5, 5); |
| 1817 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, |
| 1818 | 0x80); |
| 1819 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, |
| 1820 | 0x80); |
| 1821 | usleep_range(10, 10); |
| 1822 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0); |
| 1823 | usleep_range(20, 20); |
| 1824 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 1825 | } else { |
| 1826 | snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1, |
| 1827 | 0); |
| 1828 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0); |
| 1829 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 1830 | } |
| 1831 | tabla->config_mode_active = enable ? true : false; |
| 1832 | |
| 1833 | return 0; |
| 1834 | } |
| 1835 | |
| 1836 | static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec, |
| 1837 | int config_mode) |
| 1838 | { |
| 1839 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1840 | |
| 1841 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 1842 | |
| 1843 | if (config_mode) { |
| 1844 | tabla_codec_enable_config_mode(codec, 1); |
| 1845 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x00); |
| 1846 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 1847 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN1, 0x0D); |
| 1848 | usleep_range(1000, 1000); |
| 1849 | } else |
| 1850 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 1851 | |
| 1852 | if (!config_mode && tabla->mbhc_polling_active) { |
| 1853 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 1854 | tabla_codec_enable_config_mode(codec, 0); |
| 1855 | |
| 1856 | } |
| 1857 | |
| 1858 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x05); |
| 1859 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00); |
| 1860 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 1861 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 1862 | usleep_range(50, 50); |
| 1863 | tabla->clock_active = true; |
| 1864 | return 0; |
| 1865 | } |
| 1866 | |
| 1867 | static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 1868 | struct snd_kcontrol *kcontrol, int event) |
| 1869 | { |
| 1870 | struct snd_soc_codec *codec = w->codec; |
| 1871 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1872 | |
| 1873 | pr_debug("%s: %d\n", __func__, event); |
| 1874 | |
| 1875 | switch (event) { |
| 1876 | case SND_SOC_DAPM_PRE_PMU: |
| 1877 | tabla_codec_enable_bandgap(codec, |
| 1878 | TABLA_BANDGAP_AUDIO_MODE); |
| 1879 | tabla_enable_rx_bias(codec, 1); |
| 1880 | |
| 1881 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 1882 | 0x08, 0x08); |
| 1883 | /* Enable Zero Cross detect for AUX PGA channel |
| 1884 | * and set the initial AUX PGA gain to NEG_0P0_DB |
| 1885 | * to avoid glitches. |
| 1886 | */ |
| 1887 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1888 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 1889 | 0x20, 0x20); |
| 1890 | tabla->aux_l_gain = snd_soc_read(codec, |
| 1891 | TABLA_A_AUX_L_GAIN); |
| 1892 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 1893 | } else { |
| 1894 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 1895 | 0x20, 0x20); |
| 1896 | tabla->aux_r_gain = snd_soc_read(codec, |
| 1897 | TABLA_A_AUX_R_GAIN); |
| 1898 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 1899 | } |
| 1900 | if (tabla->aux_pga_cnt++ == 1 |
| 1901 | && !tabla->mclk_enabled) { |
| 1902 | tabla_codec_enable_clock_block(codec, 1); |
| 1903 | pr_debug("AUX PGA enabled RC osc\n"); |
| 1904 | } |
| 1905 | break; |
| 1906 | |
| 1907 | case SND_SOC_DAPM_POST_PMU: |
| 1908 | if (w->reg == TABLA_A_AUX_L_EN) |
| 1909 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 1910 | tabla->aux_l_gain); |
| 1911 | else |
| 1912 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 1913 | tabla->aux_r_gain); |
| 1914 | break; |
| 1915 | |
| 1916 | case SND_SOC_DAPM_PRE_PMD: |
| 1917 | /* Mute AUX PGA channel in use before disabling AUX PGA */ |
| 1918 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1919 | tabla->aux_l_gain = snd_soc_read(codec, |
| 1920 | TABLA_A_AUX_L_GAIN); |
| 1921 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 1922 | } else { |
| 1923 | tabla->aux_r_gain = snd_soc_read(codec, |
| 1924 | TABLA_A_AUX_R_GAIN); |
| 1925 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 1926 | } |
| 1927 | break; |
| 1928 | |
| 1929 | case SND_SOC_DAPM_POST_PMD: |
| 1930 | tabla_enable_rx_bias(codec, 0); |
| 1931 | |
| 1932 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 1933 | 0x08, 0x00); |
| 1934 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 1935 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 1936 | tabla->aux_l_gain); |
| 1937 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 1938 | 0x20, 0x00); |
| 1939 | } else { |
| 1940 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 1941 | tabla->aux_r_gain); |
| 1942 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 1943 | 0x20, 0x00); |
| 1944 | } |
| 1945 | |
| 1946 | if (tabla->aux_pga_cnt-- == 0) { |
| 1947 | if (tabla->mbhc_polling_active) |
| 1948 | tabla_codec_enable_bandgap(codec, |
| 1949 | TABLA_BANDGAP_MBHC_MODE); |
| 1950 | else |
| 1951 | tabla_codec_enable_bandgap(codec, |
| 1952 | TABLA_BANDGAP_OFF); |
| 1953 | |
| 1954 | if (!tabla->mclk_enabled && |
| 1955 | !tabla->mbhc_polling_active) { |
| 1956 | tabla_codec_enable_clock_block(codec, 0); |
| 1957 | } |
| 1958 | } |
| 1959 | break; |
| 1960 | } |
| 1961 | return 0; |
| 1962 | } |
| 1963 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1964 | static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 1965 | struct snd_kcontrol *kcontrol, int event) |
| 1966 | { |
| 1967 | struct snd_soc_codec *codec = w->codec; |
| 1968 | u16 lineout_gain_reg; |
| 1969 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 1970 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1971 | |
| 1972 | switch (w->shift) { |
| 1973 | case 0: |
| 1974 | lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN; |
| 1975 | break; |
| 1976 | case 1: |
| 1977 | lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN; |
| 1978 | break; |
| 1979 | case 2: |
| 1980 | lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN; |
| 1981 | break; |
| 1982 | case 3: |
| 1983 | lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN; |
| 1984 | break; |
| 1985 | case 4: |
| 1986 | lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN; |
| 1987 | break; |
| 1988 | default: |
| 1989 | pr_err("%s: Error, incorrect lineout register value\n", |
| 1990 | __func__); |
| 1991 | return -EINVAL; |
| 1992 | } |
| 1993 | |
| 1994 | switch (event) { |
| 1995 | case SND_SOC_DAPM_PRE_PMU: |
| 1996 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 1997 | break; |
| 1998 | case SND_SOC_DAPM_POST_PMU: |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 1999 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2000 | __func__, w->name); |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2001 | usleep_range(16000, 16000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2002 | break; |
| 2003 | case SND_SOC_DAPM_POST_PMD: |
| 2004 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 2005 | break; |
| 2006 | } |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2010 | |
| 2011 | static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2012 | struct snd_kcontrol *kcontrol, int event) |
| 2013 | { |
| 2014 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 2015 | u16 tx_dmic_ctl_reg; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2016 | u8 dmic_clk_sel, dmic_clk_en; |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2017 | unsigned int dmic; |
| 2018 | int ret; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2019 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2020 | ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic); |
| 2021 | if (ret < 0) { |
| 2022 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2023 | return -EINVAL; |
| 2024 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2025 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2026 | switch (dmic) { |
| 2027 | case 1: |
| 2028 | case 2: |
| 2029 | dmic_clk_sel = 0x02; |
| 2030 | dmic_clk_en = 0x01; |
| 2031 | break; |
| 2032 | |
| 2033 | case 3: |
| 2034 | case 4: |
| 2035 | dmic_clk_sel = 0x08; |
| 2036 | dmic_clk_en = 0x04; |
| 2037 | break; |
| 2038 | |
| 2039 | case 5: |
| 2040 | case 6: |
| 2041 | dmic_clk_sel = 0x20; |
| 2042 | dmic_clk_en = 0x10; |
| 2043 | break; |
| 2044 | |
| 2045 | default: |
| 2046 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2047 | return -EINVAL; |
| 2048 | } |
| 2049 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2050 | tx_dmic_ctl_reg = TABLA_A_CDC_TX1_DMIC_CTL + 8 * (dmic - 1); |
| 2051 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2052 | pr_debug("%s %d\n", __func__, event); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2053 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2054 | switch (event) { |
| 2055 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2056 | |
| 2057 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2058 | dmic_clk_sel, dmic_clk_sel); |
| 2059 | |
| 2060 | snd_soc_update_bits(codec, tx_dmic_ctl_reg, 0x1, 0x1); |
| 2061 | |
| 2062 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2063 | dmic_clk_en, dmic_clk_en); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2064 | break; |
| 2065 | case SND_SOC_DAPM_POST_PMD: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2066 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2067 | dmic_clk_en, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2068 | break; |
| 2069 | } |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2073 | static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 2074 | struct snd_kcontrol *kcontrol, int event) |
| 2075 | { |
| 2076 | struct snd_soc_codec *codec = w->codec; |
| 2077 | const char *filename; |
| 2078 | const struct firmware *fw; |
| 2079 | int i; |
| 2080 | int ret; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2081 | int num_anc_slots; |
| 2082 | struct anc_header *anc_head; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2083 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2084 | u32 anc_writes_size = 0; |
| 2085 | int anc_size_remaining; |
| 2086 | u32 *anc_ptr; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2087 | u16 reg; |
| 2088 | u8 mask, val, old_val; |
| 2089 | |
| 2090 | pr_debug("%s %d\n", __func__, event); |
| 2091 | switch (event) { |
| 2092 | case SND_SOC_DAPM_PRE_PMU: |
| 2093 | |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2094 | filename = "wcd9310/wcd9310_anc.bin"; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2095 | |
| 2096 | ret = request_firmware(&fw, filename, codec->dev); |
| 2097 | if (ret != 0) { |
| 2098 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 2099 | ret); |
| 2100 | return -ENODEV; |
| 2101 | } |
| 2102 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2103 | if (fw->size < sizeof(struct anc_header)) { |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2104 | dev_err(codec->dev, "Not enough data\n"); |
| 2105 | release_firmware(fw); |
| 2106 | return -ENOMEM; |
| 2107 | } |
| 2108 | |
| 2109 | /* First number is the number of register writes */ |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2110 | anc_head = (struct anc_header *)(fw->data); |
| 2111 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 2112 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 2113 | num_anc_slots = anc_head->num_anc_slots; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2114 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2115 | if (tabla->anc_slot >= num_anc_slots) { |
| 2116 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 2117 | release_firmware(fw); |
| 2118 | return -EINVAL; |
| 2119 | } |
| 2120 | |
| 2121 | for (i = 0; i < num_anc_slots; i++) { |
| 2122 | |
| 2123 | if (anc_size_remaining < TABLA_PACKED_REG_SIZE) { |
| 2124 | dev_err(codec->dev, "Invalid register format\n"); |
| 2125 | release_firmware(fw); |
| 2126 | return -EINVAL; |
| 2127 | } |
| 2128 | anc_writes_size = (u32)(*anc_ptr); |
| 2129 | anc_size_remaining -= sizeof(u32); |
| 2130 | anc_ptr += 1; |
| 2131 | |
| 2132 | if (anc_writes_size * TABLA_PACKED_REG_SIZE |
| 2133 | > anc_size_remaining) { |
| 2134 | dev_err(codec->dev, "Invalid register format\n"); |
| 2135 | release_firmware(fw); |
| 2136 | return -ENOMEM; |
| 2137 | } |
| 2138 | |
| 2139 | if (tabla->anc_slot == i) |
| 2140 | break; |
| 2141 | |
| 2142 | anc_size_remaining -= (anc_writes_size * |
| 2143 | TABLA_PACKED_REG_SIZE); |
Bradley Rubin | 939ff3f | 2011-08-26 17:19:34 -0700 | [diff] [blame] | 2144 | anc_ptr += anc_writes_size; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2145 | } |
| 2146 | if (i == num_anc_slots) { |
| 2147 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2148 | release_firmware(fw); |
| 2149 | return -ENOMEM; |
| 2150 | } |
| 2151 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2152 | for (i = 0; i < anc_writes_size; i++) { |
| 2153 | TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2154 | mask, val); |
| 2155 | old_val = snd_soc_read(codec, reg); |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2156 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 2157 | (val & mask)); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2158 | } |
| 2159 | release_firmware(fw); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2160 | |
| 2161 | break; |
| 2162 | case SND_SOC_DAPM_POST_PMD: |
| 2163 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 2164 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
| 2165 | break; |
| 2166 | } |
| 2167 | return 0; |
| 2168 | } |
| 2169 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2170 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2171 | static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 2172 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2173 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2174 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
| 2175 | int mbhc_state = tabla->mbhc_state; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2176 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2177 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2178 | if (!tabla->mbhc_polling_active) { |
| 2179 | pr_debug("Polling is not active, do not start polling\n"); |
| 2180 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2181 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2182 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2183 | |
| 2184 | if (!tabla->no_mic_headset_override) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2185 | if (mbhc_state == MBHC_STATE_POTENTIAL) { |
| 2186 | pr_debug("%s recovering MBHC state macine\n", __func__); |
| 2187 | tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2188 | /* set to max button press threshold */ |
| 2189 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2190 | 0x7F); |
| 2191 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2192 | 0xFF); |
| 2193 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 2194 | (TABLA_IS_1_X(tabla_core->version) ? |
| 2195 | 0x07 : 0x7F)); |
| 2196 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 2197 | 0xFF); |
| 2198 | /* set to max */ |
| 2199 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 2200 | 0x7F); |
| 2201 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 2202 | 0xFF); |
| 2203 | } |
| 2204 | } |
| 2205 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2206 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
| 2207 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2208 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2209 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2212 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2213 | static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 2214 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2215 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2216 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2217 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2218 | if (!tabla->mbhc_polling_active) { |
| 2219 | pr_debug("polling not active, nothing to pause\n"); |
| 2220 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2221 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2222 | |
| 2223 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2224 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2227 | static void tabla_codec_switch_cfilt_mode(struct snd_soc_codec *codec, int mode) |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2228 | { |
| 2229 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2230 | u8 reg_mode_val, cur_mode_val; |
| 2231 | bool mbhc_was_polling = false; |
| 2232 | |
| 2233 | if (mode) |
| 2234 | reg_mode_val = TABLA_CFILT_FAST_MODE; |
| 2235 | else |
| 2236 | reg_mode_val = TABLA_CFILT_SLOW_MODE; |
| 2237 | |
| 2238 | cur_mode_val = snd_soc_read(codec, |
| 2239 | tabla->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 2240 | |
| 2241 | if (cur_mode_val != reg_mode_val) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2242 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2243 | if (tabla->mbhc_polling_active) { |
| 2244 | tabla_codec_pause_hs_polling(codec); |
| 2245 | mbhc_was_polling = true; |
| 2246 | } |
| 2247 | snd_soc_update_bits(codec, |
| 2248 | tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 2249 | if (mbhc_was_polling) |
| 2250 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2251 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2252 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
| 2253 | cur_mode_val, reg_mode_val); |
| 2254 | } else { |
| 2255 | pr_debug("%s: CFILT Value is already %x\n", |
| 2256 | __func__, cur_mode_val); |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 2261 | u8 cfilt_sel, int inc) |
| 2262 | { |
| 2263 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2264 | u32 *cfilt_cnt_ptr = NULL; |
| 2265 | u16 micb_cfilt_reg; |
| 2266 | |
| 2267 | switch (cfilt_sel) { |
| 2268 | case TABLA_CFILT1_SEL: |
| 2269 | cfilt_cnt_ptr = &tabla->cfilt1_cnt; |
| 2270 | micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL; |
| 2271 | break; |
| 2272 | case TABLA_CFILT2_SEL: |
| 2273 | cfilt_cnt_ptr = &tabla->cfilt2_cnt; |
| 2274 | micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL; |
| 2275 | break; |
| 2276 | case TABLA_CFILT3_SEL: |
| 2277 | cfilt_cnt_ptr = &tabla->cfilt3_cnt; |
| 2278 | micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL; |
| 2279 | break; |
| 2280 | default: |
| 2281 | return; /* should not happen */ |
| 2282 | } |
| 2283 | |
| 2284 | if (inc) { |
| 2285 | if (!(*cfilt_cnt_ptr)++) { |
| 2286 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 2287 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2288 | tabla_codec_switch_cfilt_mode(codec, 0); |
| 2289 | |
| 2290 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 2291 | } |
| 2292 | } else { |
| 2293 | /* check if count not zero, decrement |
| 2294 | * then check if zero, go ahead disable cfilter |
| 2295 | */ |
| 2296 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 2297 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 2298 | |
| 2299 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 2300 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2301 | tabla_codec_switch_cfilt_mode(codec, 1); |
| 2302 | } |
| 2303 | } |
| 2304 | } |
| 2305 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2306 | static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 2307 | { |
| 2308 | int rc = -EINVAL; |
| 2309 | unsigned min_mv, max_mv; |
| 2310 | |
| 2311 | switch (ldoh_v) { |
| 2312 | case TABLA_LDOH_1P95_V: |
| 2313 | min_mv = 160; |
| 2314 | max_mv = 1800; |
| 2315 | break; |
| 2316 | case TABLA_LDOH_2P35_V: |
| 2317 | min_mv = 200; |
| 2318 | max_mv = 2200; |
| 2319 | break; |
| 2320 | case TABLA_LDOH_2P75_V: |
| 2321 | min_mv = 240; |
| 2322 | max_mv = 2600; |
| 2323 | break; |
| 2324 | case TABLA_LDOH_2P85_V: |
| 2325 | min_mv = 250; |
| 2326 | max_mv = 2700; |
| 2327 | break; |
| 2328 | default: |
| 2329 | goto done; |
| 2330 | } |
| 2331 | |
| 2332 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 2333 | goto done; |
| 2334 | |
| 2335 | for (rc = 4; rc <= 44; rc++) { |
| 2336 | min_mv = max_mv * (rc) / 44; |
| 2337 | if (min_mv >= cfilt_mv) { |
| 2338 | rc -= 4; |
| 2339 | break; |
| 2340 | } |
| 2341 | } |
| 2342 | done: |
| 2343 | return rc; |
| 2344 | } |
| 2345 | |
| 2346 | static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec) |
| 2347 | { |
| 2348 | u8 hph_reg_val = 0; |
| 2349 | hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN); |
| 2350 | |
| 2351 | return (hph_reg_val & 0x30) ? true : false; |
| 2352 | } |
| 2353 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2354 | static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 2355 | { |
| 2356 | u8 hph_reg_val = 0; |
| 2357 | if (left) |
| 2358 | hph_reg_val = snd_soc_read(codec, |
| 2359 | TABLA_A_RX_HPH_L_DAC_CTL); |
| 2360 | else |
| 2361 | hph_reg_val = snd_soc_read(codec, |
| 2362 | TABLA_A_RX_HPH_R_DAC_CTL); |
| 2363 | |
| 2364 | return (hph_reg_val & 0xC0) ? true : false; |
| 2365 | } |
| 2366 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2367 | static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 2368 | { |
| 2369 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 2370 | } |
| 2371 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2372 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2373 | static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec, |
| 2374 | int usec) |
| 2375 | { |
| 2376 | int cfilt_k_val; |
| 2377 | bool set = true; |
| 2378 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2379 | |
| 2380 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 2381 | tabla->mbhc_micbias_switched) { |
| 2382 | pr_debug("%s: set mic V to micbias V\n", __func__); |
| 2383 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2384 | tabla_turn_onoff_override(codec, true); |
| 2385 | while (1) { |
| 2386 | cfilt_k_val = tabla_find_k_value( |
| 2387 | tabla->pdata->micbias.ldoh_v, |
| 2388 | set ? tabla->mbhc_data.micb_mv : |
| 2389 | VDDIO_MICBIAS_MV); |
| 2390 | snd_soc_update_bits(codec, |
| 2391 | tabla->mbhc_bias_regs.cfilt_val, |
| 2392 | 0xFC, (cfilt_k_val << 2)); |
| 2393 | if (!set) |
| 2394 | break; |
| 2395 | usleep_range(usec, usec); |
| 2396 | set = false; |
| 2397 | } |
| 2398 | tabla_turn_onoff_override(codec, false); |
| 2399 | } |
| 2400 | } |
| 2401 | |
| 2402 | /* called under codec_resource_lock acquisition */ |
| 2403 | static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2404 | int vddio_switch, bool restartpolling, |
| 2405 | bool checkpolling) |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2406 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2407 | int cfilt_k_val; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 2408 | bool override; |
| 2409 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2410 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2411 | if (vddio_switch && !tabla->mbhc_micbias_switched && |
| 2412 | (!checkpolling || tabla->mbhc_polling_active)) { |
| 2413 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2414 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 2415 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 2416 | if (!override) |
| 2417 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2418 | /* Adjust threshold if Mic Bias voltage changes */ |
| 2419 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2420 | cfilt_k_val = tabla_find_k_value( |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2421 | tabla->pdata->micbias.ldoh_v, |
| 2422 | VDDIO_MICBIAS_MV); |
| 2423 | usleep_range(10000, 10000); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2424 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2425 | tabla->mbhc_bias_regs.cfilt_val, |
| 2426 | 0xFC, (cfilt_k_val << 2)); |
| 2427 | usleep_range(10000, 10000); |
| 2428 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2429 | tabla->mbhc_data.adj_v_ins_hu & 0xFF); |
| 2430 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2431 | (tabla->mbhc_data.adj_v_ins_hu >> 8) & |
| 2432 | 0xFF); |
| 2433 | pr_debug("%s: Programmed MBHC thresholds to VDDIO\n", |
| 2434 | __func__); |
| 2435 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2436 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2437 | /* enable MIC BIAS Switch to VDDIO */ |
| 2438 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2439 | 0x80, 0x80); |
| 2440 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2441 | 0x10, 0x00); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 2442 | if (!override) |
| 2443 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2444 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2445 | tabla_codec_start_hs_polling(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2446 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2447 | tabla->mbhc_micbias_switched = true; |
| 2448 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2449 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2450 | } else if (!vddio_switch && tabla->mbhc_micbias_switched) { |
| 2451 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2452 | restartpolling) |
| 2453 | tabla_codec_pause_hs_polling(codec); |
| 2454 | /* Reprogram thresholds */ |
| 2455 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 2456 | cfilt_k_val = tabla_find_k_value( |
| 2457 | tabla->pdata->micbias.ldoh_v, |
| 2458 | tabla->mbhc_data.micb_mv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2459 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2460 | tabla->mbhc_bias_regs.cfilt_val, |
| 2461 | 0xFC, (cfilt_k_val << 2)); |
| 2462 | usleep_range(10000, 10000); |
| 2463 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2464 | tabla->mbhc_data.v_ins_hu & 0xFF); |
| 2465 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2466 | (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF); |
| 2467 | pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n", |
| 2468 | __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2469 | } |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2470 | |
| 2471 | /* Disable MIC BIAS Switch to VDDIO */ |
| 2472 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2473 | 0x80, 0x00); |
| 2474 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2475 | 0x10, 0x00); |
| 2476 | |
| 2477 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2478 | restartpolling) |
| 2479 | tabla_codec_start_hs_polling(codec); |
| 2480 | |
| 2481 | tabla->mbhc_micbias_switched = false; |
| 2482 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2486 | static void tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2487 | int vddio_switch) |
| 2488 | { |
| 2489 | return __tabla_codec_switch_micbias(codec, vddio_switch, true, true); |
| 2490 | } |
| 2491 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2492 | static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2493 | struct snd_kcontrol *kcontrol, int event) |
| 2494 | { |
| 2495 | struct snd_soc_codec *codec = w->codec; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2496 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2497 | u16 micb_int_reg; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2498 | int micb_line; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2499 | u8 cfilt_sel_val = 0; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2500 | char *internal1_text = "Internal1"; |
| 2501 | char *internal2_text = "Internal2"; |
| 2502 | char *internal3_text = "Internal3"; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2503 | |
| 2504 | pr_debug("%s %d\n", __func__, event); |
| 2505 | switch (w->reg) { |
| 2506 | case TABLA_A_MICB_1_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2507 | micb_int_reg = TABLA_A_MICB_1_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2508 | cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2509 | micb_line = TABLA_MICBIAS1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2510 | break; |
| 2511 | case TABLA_A_MICB_2_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2512 | micb_int_reg = TABLA_A_MICB_2_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2513 | cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2514 | micb_line = TABLA_MICBIAS2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2515 | break; |
| 2516 | case TABLA_A_MICB_3_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2517 | micb_int_reg = TABLA_A_MICB_3_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2518 | cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2519 | micb_line = TABLA_MICBIAS3; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2520 | break; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2521 | case TABLA_1_A_MICB_4_CTL: |
| 2522 | case TABLA_2_A_MICB_4_CTL: |
| 2523 | micb_int_reg = tabla->reg_addr.micb_4_int_rbias; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2524 | cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2525 | micb_line = TABLA_MICBIAS4; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2526 | break; |
| 2527 | default: |
| 2528 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 2529 | return -EINVAL; |
| 2530 | } |
| 2531 | |
| 2532 | switch (event) { |
| 2533 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2534 | /* Decide whether to switch the micbias for MBHC */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2535 | if (w->reg == tabla->mbhc_bias_regs.ctl_reg) { |
| 2536 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2537 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2538 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2539 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2540 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2541 | snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2542 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2543 | |
| 2544 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2545 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2546 | else if (strnstr(w->name, internal2_text, 30)) |
| 2547 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 2548 | else if (strnstr(w->name, internal3_text, 30)) |
| 2549 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 2550 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2551 | break; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2552 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2553 | |
| 2554 | usleep_range(20000, 20000); |
| 2555 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2556 | if (tabla->mbhc_polling_active && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2557 | tabla->mbhc_cfg.micbias == micb_line) { |
| 2558 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2559 | tabla_codec_pause_hs_polling(codec); |
| 2560 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2561 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2562 | } |
| 2563 | break; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2564 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2565 | case SND_SOC_DAPM_POST_PMD: |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2566 | if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2567 | tabla_is_hph_pa_on(codec)) { |
| 2568 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2569 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2570 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2571 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2572 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2573 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2574 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2575 | else if (strnstr(w->name, internal2_text, 30)) |
| 2576 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 2577 | else if (strnstr(w->name, internal3_text, 30)) |
| 2578 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 2579 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2580 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2581 | break; |
| 2582 | } |
| 2583 | |
| 2584 | return 0; |
| 2585 | } |
| 2586 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2587 | |
| 2588 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 2589 | { |
| 2590 | struct delayed_work *hpf_delayed_work; |
| 2591 | struct hpf_work *hpf_work; |
| 2592 | struct tabla_priv *tabla; |
| 2593 | struct snd_soc_codec *codec; |
| 2594 | u16 tx_mux_ctl_reg; |
| 2595 | u8 hpf_cut_of_freq; |
| 2596 | |
| 2597 | hpf_delayed_work = to_delayed_work(work); |
| 2598 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 2599 | tabla = hpf_work->tabla; |
| 2600 | codec = hpf_work->tabla->codec; |
| 2601 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 2602 | |
| 2603 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + |
| 2604 | (hpf_work->decimator - 1) * 8; |
| 2605 | |
| 2606 | pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__, |
| 2607 | hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 2608 | |
| 2609 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 2610 | } |
| 2611 | |
| 2612 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 2613 | #define CF_MIN_3DB_4HZ 0x0 |
| 2614 | #define CF_MIN_3DB_75HZ 0x1 |
| 2615 | #define CF_MIN_3DB_150HZ 0x2 |
| 2616 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2617 | static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 2618 | struct snd_kcontrol *kcontrol, int event) |
| 2619 | { |
| 2620 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2621 | unsigned int decimator; |
| 2622 | char *dec_name = NULL; |
| 2623 | char *widget_name = NULL; |
| 2624 | char *temp; |
| 2625 | int ret = 0; |
| 2626 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 2627 | u8 dec_hpf_cut_of_freq; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2628 | int offset; |
| 2629 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2630 | |
| 2631 | pr_debug("%s %d\n", __func__, event); |
| 2632 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2633 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 2634 | if (!widget_name) |
| 2635 | return -ENOMEM; |
| 2636 | temp = widget_name; |
| 2637 | |
| 2638 | dec_name = strsep(&widget_name, " "); |
| 2639 | widget_name = temp; |
| 2640 | if (!dec_name) { |
| 2641 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 2642 | ret = -EINVAL; |
| 2643 | goto out; |
| 2644 | } |
| 2645 | |
| 2646 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 2647 | if (ret < 0) { |
| 2648 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 2649 | ret = -EINVAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
| 2653 | pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__, |
| 2654 | w->name, dec_name, decimator); |
| 2655 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2656 | if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2657 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2658 | offset = 0; |
| 2659 | } else if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2660 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2661 | offset = 8; |
| 2662 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2663 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 2664 | return -EINVAL; |
| 2665 | } |
| 2666 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2667 | tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1); |
| 2668 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 2669 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2670 | switch (event) { |
| 2671 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2672 | |
| 2673 | // Enableable TX digital mute */ |
| 2674 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2675 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2676 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 2677 | 1 << w->shift); |
| 2678 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2679 | |
| 2680 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 2681 | |
| 2682 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 2683 | |
| 2684 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 2685 | dec_hpf_cut_of_freq; |
| 2686 | |
| 2687 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 2688 | |
| 2689 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 2690 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2691 | CF_MIN_3DB_150HZ << 4); |
| 2692 | } |
| 2693 | |
| 2694 | /* enable HPF */ |
| 2695 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 2696 | |
| 2697 | break; |
| 2698 | |
| 2699 | case SND_SOC_DAPM_POST_PMU: |
| 2700 | |
| 2701 | /* Disable TX digital mute */ |
| 2702 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 2703 | |
| 2704 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 2705 | CF_MIN_3DB_150HZ) { |
| 2706 | |
| 2707 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 2708 | msecs_to_jiffies(300)); |
| 2709 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2710 | /* apply the digital gain after the decimator is enabled*/ |
| 2711 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2712 | snd_soc_write(codec, |
| 2713 | tx_digital_gain_reg[w->shift + offset], |
| 2714 | snd_soc_read(codec, |
| 2715 | tx_digital_gain_reg[w->shift + offset]) |
| 2716 | ); |
| 2717 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2718 | break; |
| 2719 | |
| 2720 | case SND_SOC_DAPM_PRE_PMD: |
| 2721 | |
| 2722 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 2723 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 2724 | break; |
| 2725 | |
| 2726 | case SND_SOC_DAPM_POST_PMD: |
| 2727 | |
| 2728 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 2729 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 2730 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 2731 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2732 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2733 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2734 | out: |
| 2735 | kfree(widget_name); |
| 2736 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 2739 | static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2740 | struct snd_kcontrol *kcontrol, int event) |
| 2741 | { |
| 2742 | struct snd_soc_codec *codec = w->codec; |
| 2743 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 2744 | pr_debug("%s %d %s\n", __func__, event, w->name); |
| 2745 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2746 | switch (event) { |
| 2747 | case SND_SOC_DAPM_PRE_PMU: |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 2748 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 2749 | 1 << w->shift, 1 << w->shift); |
| 2750 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 2751 | 1 << w->shift, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2752 | break; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2753 | case SND_SOC_DAPM_POST_PMU: |
| 2754 | /* apply the digital gain after the interpolator is enabled*/ |
| 2755 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 2756 | snd_soc_write(codec, |
| 2757 | rx_digital_gain_reg[w->shift], |
| 2758 | snd_soc_read(codec, |
| 2759 | rx_digital_gain_reg[w->shift]) |
| 2760 | ); |
| 2761 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2762 | } |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2766 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 2767 | struct snd_kcontrol *kcontrol, int event) |
| 2768 | { |
| 2769 | switch (event) { |
| 2770 | case SND_SOC_DAPM_POST_PMU: |
| 2771 | case SND_SOC_DAPM_POST_PMD: |
| 2772 | usleep_range(1000, 1000); |
| 2773 | break; |
| 2774 | } |
| 2775 | return 0; |
| 2776 | } |
| 2777 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 2778 | static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 2779 | struct snd_kcontrol *kcontrol, int event) |
| 2780 | { |
| 2781 | struct snd_soc_codec *codec = w->codec; |
| 2782 | |
| 2783 | pr_debug("%s %d\n", __func__, event); |
| 2784 | |
| 2785 | switch (event) { |
| 2786 | case SND_SOC_DAPM_PRE_PMU: |
| 2787 | tabla_enable_rx_bias(codec, 1); |
| 2788 | break; |
| 2789 | case SND_SOC_DAPM_POST_PMD: |
| 2790 | tabla_enable_rx_bias(codec, 0); |
| 2791 | break; |
| 2792 | } |
| 2793 | return 0; |
| 2794 | } |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 2795 | static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 2796 | struct snd_kcontrol *kcontrol, int event) |
| 2797 | { |
| 2798 | struct snd_soc_codec *codec = w->codec; |
| 2799 | |
| 2800 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 2801 | |
| 2802 | switch (event) { |
| 2803 | case SND_SOC_DAPM_PRE_PMU: |
| 2804 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2805 | break; |
| 2806 | case SND_SOC_DAPM_POST_PMD: |
| 2807 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2808 | break; |
| 2809 | } |
| 2810 | return 0; |
| 2811 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 2812 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2813 | static void tabla_snd_soc_jack_report(struct tabla_priv *tabla, |
| 2814 | struct snd_soc_jack *jack, int status, |
| 2815 | int mask) |
| 2816 | { |
| 2817 | /* XXX: wake_lock_timeout()? */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2818 | snd_soc_jack_report_no_dapm(jack, status, mask); |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2819 | } |
| 2820 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2821 | static void hphocp_off_report(struct tabla_priv *tabla, |
| 2822 | u32 jack_status, int irq) |
| 2823 | { |
| 2824 | struct snd_soc_codec *codec; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2825 | if (!tabla) { |
| 2826 | pr_err("%s: Bad tabla private data\n", __func__); |
| 2827 | return; |
| 2828 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2829 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2830 | pr_debug("%s: clear ocp status %x\n", __func__, jack_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2831 | codec = tabla->codec; |
| 2832 | if (tabla->hph_status & jack_status) { |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2833 | tabla->hph_status &= ~jack_status; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2834 | if (tabla->mbhc_cfg.headset_jack) |
| 2835 | tabla_snd_soc_jack_report(tabla, |
| 2836 | tabla->mbhc_cfg.headset_jack, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 2837 | tabla->hph_status, |
| 2838 | TABLA_JACK_MASK); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 2839 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 2840 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 2841 | /* reset retry counter as PA is turned off signifying |
| 2842 | * start of new OCP detection session |
| 2843 | */ |
| 2844 | if (TABLA_IRQ_HPH_PA_OCPL_FAULT) |
| 2845 | tabla->hphlocp_cnt = 0; |
| 2846 | else |
| 2847 | tabla->hphrocp_cnt = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 2848 | wcd9xxx_enable_irq(codec->control_data, irq); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | static void hphlocp_off_report(struct work_struct *work) |
| 2853 | { |
| 2854 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 2855 | hphlocp_work); |
| 2856 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 2857 | } |
| 2858 | |
| 2859 | static void hphrocp_off_report(struct work_struct *work) |
| 2860 | { |
| 2861 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 2862 | hphrocp_work); |
| 2863 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 2864 | } |
| 2865 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2866 | static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 2867 | struct snd_kcontrol *kcontrol, int event) |
| 2868 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2869 | struct snd_soc_codec *codec = w->codec; |
| 2870 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2871 | u8 mbhc_micb_ctl_val; |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2872 | pr_debug("%s: event = %d\n", __func__, event); |
| 2873 | |
| 2874 | switch (event) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2875 | case SND_SOC_DAPM_PRE_PMU: |
| 2876 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 2877 | tabla->mbhc_bias_regs.ctl_reg); |
| 2878 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2879 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 2880 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2881 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2882 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2883 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2884 | break; |
| 2885 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2886 | case SND_SOC_DAPM_POST_PMD: |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 2887 | /* schedule work is required because at the time HPH PA DAPM |
| 2888 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 2889 | * would have been locked while snd_soc_jack_report also |
| 2890 | * attempts to acquire same lock. |
| 2891 | */ |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2892 | if (w->shift == 5) { |
| 2893 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 2894 | &tabla->hph_pa_dac_state); |
| 2895 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 2896 | &tabla->hph_pa_dac_state); |
| 2897 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 2898 | schedule_work(&tabla->hphlocp_work); |
| 2899 | } else if (w->shift == 4) { |
| 2900 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 2901 | &tabla->hph_pa_dac_state); |
| 2902 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 2903 | &tabla->hph_pa_dac_state); |
| 2904 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 2905 | schedule_work(&tabla->hphrocp_work); |
| 2906 | } |
| 2907 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2908 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2909 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2910 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2911 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2912 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 2913 | w->name); |
| 2914 | usleep_range(10000, 10000); |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 2915 | break; |
| 2916 | } |
| 2917 | return 0; |
| 2918 | } |
| 2919 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2920 | static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2921 | struct mbhc_micbias_regs *micbias_regs) |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2922 | { |
| 2923 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2924 | unsigned int cfilt; |
| 2925 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2926 | switch (tabla->mbhc_cfg.micbias) { |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2927 | case TABLA_MICBIAS1: |
| 2928 | cfilt = tabla->pdata->micbias.bias1_cfilt_sel; |
| 2929 | micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC; |
| 2930 | micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS; |
| 2931 | micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL; |
| 2932 | break; |
| 2933 | case TABLA_MICBIAS2: |
| 2934 | cfilt = tabla->pdata->micbias.bias2_cfilt_sel; |
| 2935 | micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC; |
| 2936 | micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS; |
| 2937 | micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL; |
| 2938 | break; |
| 2939 | case TABLA_MICBIAS3: |
| 2940 | cfilt = tabla->pdata->micbias.bias3_cfilt_sel; |
| 2941 | micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC; |
| 2942 | micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS; |
| 2943 | micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL; |
| 2944 | break; |
| 2945 | case TABLA_MICBIAS4: |
| 2946 | cfilt = tabla->pdata->micbias.bias4_cfilt_sel; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2947 | micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc; |
| 2948 | micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias; |
| 2949 | micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2950 | break; |
| 2951 | default: |
| 2952 | /* Should never reach here */ |
| 2953 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
Jordan Crouse | 239d841 | 2011-11-23 11:47:02 -0700 | [diff] [blame] | 2954 | return; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2957 | micbias_regs->cfilt_sel = cfilt; |
| 2958 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2959 | switch (cfilt) { |
| 2960 | case TABLA_CFILT1_SEL: |
| 2961 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL; |
| 2962 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 2963 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2964 | break; |
| 2965 | case TABLA_CFILT2_SEL: |
| 2966 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL; |
| 2967 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 2968 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2969 | break; |
| 2970 | case TABLA_CFILT3_SEL: |
| 2971 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL; |
| 2972 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 2973 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2974 | break; |
| 2975 | } |
| 2976 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 2977 | static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = { |
| 2978 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 2979 | 4, 0, NULL, 0), |
| 2980 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4, |
| 2981 | 0, NULL, 0), |
| 2982 | }; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 2983 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 2984 | static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 2985 | struct snd_kcontrol *kcontrol, int event) |
| 2986 | { |
| 2987 | struct snd_soc_codec *codec = w->codec; |
| 2988 | |
| 2989 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 2990 | |
| 2991 | switch (event) { |
| 2992 | case SND_SOC_DAPM_PRE_PMU: |
| 2993 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 2994 | break; |
| 2995 | |
| 2996 | case SND_SOC_DAPM_POST_PMD: |
| 2997 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 2998 | break; |
| 2999 | } |
| 3000 | return 0; |
| 3001 | } |
| 3002 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3003 | static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = { |
| 3004 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_1_A_MICB_4_CTL, 7, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3005 | 0, tabla_codec_enable_micbias, |
| 3006 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3007 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3008 | }; |
| 3009 | |
| 3010 | static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = { |
| 3011 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_2_A_MICB_4_CTL, 7, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3012 | 0, tabla_codec_enable_micbias, |
| 3013 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3014 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3015 | }; |
| 3016 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3017 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 3018 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 3019 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 3020 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 3021 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 3022 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 3023 | |
| 3024 | {"SLIM TX7", NULL, "TX_I2S_CLK"}, |
| 3025 | {"SLIM TX8", NULL, "TX_I2S_CLK"}, |
| 3026 | {"SLIM TX9", NULL, "TX_I2S_CLK"}, |
| 3027 | {"SLIM TX10", NULL, "TX_I2S_CLK"}, |
| 3028 | }; |
| 3029 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3030 | static const struct snd_soc_dapm_route audio_map[] = { |
| 3031 | /* SLIMBUS Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3032 | |
| 3033 | {"SLIM TX1", NULL, "SLIM TX1 MUX"}, |
| 3034 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
| 3035 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3036 | {"SLIM TX2", NULL, "SLIM TX2 MUX"}, |
| 3037 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 3038 | |
| 3039 | {"SLIM TX3", NULL, "SLIM TX3 MUX"}, |
| 3040 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
| 3041 | |
| 3042 | {"SLIM TX4", NULL, "SLIM TX4 MUX"}, |
| 3043 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
| 3044 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3045 | {"SLIM TX5", NULL, "SLIM TX5 MUX"}, |
| 3046 | {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"}, |
| 3047 | |
| 3048 | {"SLIM TX6", NULL, "SLIM TX6 MUX"}, |
| 3049 | {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"}, |
| 3050 | |
| 3051 | {"SLIM TX7", NULL, "SLIM TX7 MUX"}, |
| 3052 | {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3053 | {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3054 | {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"}, |
| 3055 | {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3056 | {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"}, |
| 3057 | {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3058 | {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"}, |
| 3059 | {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3060 | {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"}, |
| 3061 | {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3062 | |
| 3063 | {"SLIM TX8", NULL, "SLIM TX8 MUX"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3064 | {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"}, |
| 3065 | {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"}, |
| 3066 | {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | 9ec83cd | 2011-09-23 17:25:07 -0700 | [diff] [blame] | 3067 | {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3068 | {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"}, |
| 3069 | {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3070 | {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"}, |
| 3071 | {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"}, |
| 3072 | {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"}, |
| 3073 | {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3074 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3075 | {"SLIM TX9", NULL, "SLIM TX9 MUX"}, |
| 3076 | {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"}, |
| 3077 | {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"}, |
| 3078 | {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"}, |
| 3079 | {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"}, |
| 3080 | {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"}, |
| 3081 | {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"}, |
| 3082 | {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"}, |
| 3083 | {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"}, |
| 3084 | {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"}, |
| 3085 | {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"}, |
| 3086 | |
| 3087 | {"SLIM TX10", NULL, "SLIM TX10 MUX"}, |
| 3088 | {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"}, |
| 3089 | {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"}, |
| 3090 | {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"}, |
| 3091 | {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"}, |
| 3092 | {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"}, |
| 3093 | {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"}, |
| 3094 | {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"}, |
| 3095 | {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"}, |
| 3096 | {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"}, |
| 3097 | {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"}, |
| 3098 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3099 | /* Earpiece (RX MIX1) */ |
| 3100 | {"EAR", NULL, "EAR PA"}, |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3101 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 3102 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3103 | {"DAC1", NULL, "CP"}, |
| 3104 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3105 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 3106 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3107 | {"ANC", NULL, "ANC1 FB MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3108 | |
| 3109 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3110 | {"HEADPHONE", NULL, "HPHL"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3111 | {"HEADPHONE", NULL, "HPHR"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3112 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3113 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3114 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3115 | |
| 3116 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3117 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3118 | |
| 3119 | {"HPHL DAC", NULL, "CP"}, |
| 3120 | {"HPHR DAC", NULL, "CP"}, |
| 3121 | |
| 3122 | {"ANC", NULL, "ANC1 MUX"}, |
| 3123 | {"ANC", NULL, "ANC2 MUX"}, |
| 3124 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 3125 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 3126 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 3127 | {"ANC1 MUX", "ADC4", "ADC4"}, |
| 3128 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 3129 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 3130 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 3131 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 3132 | |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3133 | {"ANC", NULL, "CDC_CONN"}, |
| 3134 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3135 | {"DAC1", "Switch", "RX1 CHAIN"}, |
| 3136 | {"HPHL DAC", "Switch", "RX1 CHAIN"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3137 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3138 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 3139 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3140 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 3141 | {"LINEOUT3", NULL, "LINEOUT3 PA"}, |
| 3142 | {"LINEOUT4", NULL, "LINEOUT4 PA"}, |
| 3143 | {"LINEOUT5", NULL, "LINEOUT5 PA"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3144 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3145 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3146 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 3147 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3148 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3149 | {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"}, |
| 3150 | {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"}, |
| 3151 | {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"}, |
| 3152 | {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"}, |
| 3153 | {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"}, |
| 3154 | {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3155 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3156 | {"LINEOUT1 DAC", NULL, "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3157 | {"LINEOUT5 DAC", NULL, "RX7 MIX1"}, |
| 3158 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3159 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3160 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3161 | {"RX1 CHAIN", NULL, "ANC"}, |
| 3162 | {"RX2 CHAIN", NULL, "ANC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3163 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3164 | {"CP", NULL, "RX_BIAS"}, |
| 3165 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3166 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
| 3167 | {"LINEOUT3 DAC", NULL, "RX_BIAS"}, |
| 3168 | {"LINEOUT4 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3169 | {"LINEOUT5 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3170 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3171 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 3172 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 3173 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 3174 | {"RX5 MIX1", NULL, "COMP2_CLK"}, |
| 3175 | |
| 3176 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3177 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3178 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
| 3179 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3180 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3181 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3182 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 3183 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 3184 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 3185 | {"RX5 MIX1", NULL, "RX5 MIX1 INP1"}, |
| 3186 | {"RX5 MIX1", NULL, "RX5 MIX1 INP2"}, |
| 3187 | {"RX6 MIX1", NULL, "RX6 MIX1 INP1"}, |
| 3188 | {"RX6 MIX1", NULL, "RX6 MIX1 INP2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3189 | {"RX7 MIX1", NULL, "RX7 MIX1 INP1"}, |
| 3190 | {"RX7 MIX1", NULL, "RX7 MIX1 INP2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3191 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3192 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3193 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3194 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3195 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3196 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
| 3197 | {"RX3 MIX2", NULL, "RX3 MIX1"}, |
| 3198 | {"RX3 MIX2", NULL, "RX3 MIX2 INP1"}, |
| 3199 | {"RX3 MIX2", NULL, "RX3 MIX2 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3200 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3201 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3202 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3203 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3204 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3205 | {"RX1 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3206 | {"RX1 MIX1 INP1", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3207 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 3208 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3209 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3210 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3211 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3212 | {"RX1 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3213 | {"RX1 MIX1 INP2", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3214 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
| 3215 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3216 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3217 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3218 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3219 | {"RX2 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3220 | {"RX2 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3221 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3222 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3223 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3224 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3225 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3226 | {"RX2 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3227 | {"RX2 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3228 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3229 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3230 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3231 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3232 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3233 | {"RX3 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3234 | {"RX3 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3235 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3236 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3237 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3238 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3239 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3240 | {"RX3 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3241 | {"RX3 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3242 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3243 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3244 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3245 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3246 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3247 | {"RX4 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3248 | {"RX4 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3249 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3250 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3251 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3252 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3253 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3254 | {"RX4 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3255 | {"RX4 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3256 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3257 | {"RX5 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3258 | {"RX5 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3259 | {"RX5 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3260 | {"RX5 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3261 | {"RX5 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3262 | {"RX5 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3263 | {"RX5 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3264 | {"RX5 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3265 | {"RX5 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3266 | {"RX5 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3267 | {"RX5 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3268 | {"RX5 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3269 | {"RX5 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3270 | {"RX5 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3271 | {"RX6 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3272 | {"RX6 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3273 | {"RX6 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3274 | {"RX6 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3275 | {"RX6 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3276 | {"RX6 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3277 | {"RX6 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3278 | {"RX6 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3279 | {"RX6 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3280 | {"RX6 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3281 | {"RX6 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3282 | {"RX6 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3283 | {"RX6 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3284 | {"RX6 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3285 | {"RX7 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3286 | {"RX7 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3287 | {"RX7 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3288 | {"RX7 MIX1 INP1", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3289 | {"RX7 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3290 | {"RX7 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3291 | {"RX7 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3292 | {"RX7 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3293 | {"RX7 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3294 | {"RX7 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3295 | {"RX7 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3296 | {"RX7 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3297 | {"RX7 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3298 | {"RX7 MIX1 INP2", "IIR1", "IIR1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3299 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
| 3300 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
| 3301 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
| 3302 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
| 3303 | {"RX3 MIX2 INP1", "IIR1", "IIR1"}, |
| 3304 | {"RX3 MIX2 INP2", "IIR1", "IIR1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3305 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3306 | /* Decimator Inputs */ |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3307 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3308 | {"DEC1 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3309 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3310 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3311 | {"DEC2 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3312 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3313 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3314 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3315 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3316 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3317 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3318 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3319 | {"DEC5 MUX", "DMIC5", "DMIC5"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3320 | {"DEC5 MUX", "ADC2", "ADC2"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3321 | {"DEC5 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3322 | {"DEC6 MUX", "DMIC6", "DMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3323 | {"DEC6 MUX", "ADC1", "ADC1"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3324 | {"DEC6 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3325 | {"DEC7 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3326 | {"DEC7 MUX", "DMIC6", "DMIC6"}, |
| 3327 | {"DEC7 MUX", "ADC1", "ADC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3328 | {"DEC7 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3329 | {"DEC7 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3330 | {"DEC8 MUX", "DMIC2", "DMIC2"}, |
| 3331 | {"DEC8 MUX", "DMIC5", "DMIC5"}, |
| 3332 | {"DEC8 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3333 | {"DEC8 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3334 | {"DEC8 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3335 | {"DEC9 MUX", "DMIC4", "DMIC4"}, |
| 3336 | {"DEC9 MUX", "DMIC5", "DMIC5"}, |
| 3337 | {"DEC9 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3338 | {"DEC9 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3339 | {"DEC9 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3340 | {"DEC10 MUX", "DMIC3", "DMIC3"}, |
| 3341 | {"DEC10 MUX", "DMIC6", "DMIC6"}, |
| 3342 | {"DEC10 MUX", "ADC1", "ADC1"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3343 | {"DEC10 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3344 | {"DEC10 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3345 | |
| 3346 | /* ADC Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3347 | {"ADC1", NULL, "AMIC1"}, |
| 3348 | {"ADC2", NULL, "AMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3349 | {"ADC3", NULL, "AMIC3"}, |
| 3350 | {"ADC4", NULL, "AMIC4"}, |
| 3351 | {"ADC5", NULL, "AMIC5"}, |
| 3352 | {"ADC6", NULL, "AMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3353 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3354 | /* AUX PGA Connections */ |
| 3355 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3356 | {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3357 | {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3358 | {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3359 | {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3360 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3361 | {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3362 | {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3363 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3364 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3365 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3366 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3367 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3368 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3369 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3370 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3371 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3372 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3373 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3374 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3375 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3376 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3377 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3378 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3379 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3380 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3381 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3382 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3383 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3384 | {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3385 | {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3386 | {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3387 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 3388 | {"AUX_PGA_Right", NULL, "AMIC6"}, |
| 3389 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3390 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3391 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 3392 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 3393 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 3394 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 3395 | {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3396 | {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3397 | {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 3398 | {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 3399 | {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 3400 | {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3401 | |
| 3402 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 3403 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 3404 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 3405 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 3406 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 3407 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 3408 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 3409 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 3410 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 3411 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 3412 | {"MIC BIAS4 External", NULL, "LDO_H"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3413 | }; |
| 3414 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3415 | static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = { |
| 3416 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3417 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3418 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3419 | |
| 3420 | {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"}, |
| 3421 | |
| 3422 | {"LINEOUT3 DAC", NULL, "RX5 MIX1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3423 | {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3424 | {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"}, |
| 3425 | |
| 3426 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3427 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3428 | |
| 3429 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3430 | {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"}, |
| 3431 | {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"}, |
| 3432 | }; |
| 3433 | |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3434 | |
| 3435 | static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = { |
| 3436 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3437 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3438 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3439 | |
| 3440 | {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"}, |
| 3441 | |
| 3442 | {"LINEOUT2 DAC", NULL, "RX5 MIX1"}, |
| 3443 | |
| 3444 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3445 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3446 | |
| 3447 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3448 | }; |
| 3449 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3450 | static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 3451 | { |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3452 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3453 | struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3454 | |
| 3455 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 3456 | for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) { |
| 3457 | if (tabla_1_reg_readable[i] == reg) |
| 3458 | return 1; |
| 3459 | } |
| 3460 | } else { |
| 3461 | for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) { |
| 3462 | if (tabla_2_reg_readable[i] == reg) |
| 3463 | return 1; |
| 3464 | } |
| 3465 | } |
| 3466 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3467 | return tabla_reg_readable[reg]; |
| 3468 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3469 | static bool tabla_is_digital_gain_register(unsigned int reg) |
| 3470 | { |
| 3471 | bool rtn = false; |
| 3472 | switch (reg) { |
| 3473 | case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 3474 | case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 3475 | case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 3476 | case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 3477 | case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL: |
| 3478 | case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL: |
| 3479 | case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL: |
| 3480 | case TABLA_A_CDC_TX1_VOL_CTL_GAIN: |
| 3481 | case TABLA_A_CDC_TX2_VOL_CTL_GAIN: |
| 3482 | case TABLA_A_CDC_TX3_VOL_CTL_GAIN: |
| 3483 | case TABLA_A_CDC_TX4_VOL_CTL_GAIN: |
| 3484 | case TABLA_A_CDC_TX5_VOL_CTL_GAIN: |
| 3485 | case TABLA_A_CDC_TX6_VOL_CTL_GAIN: |
| 3486 | case TABLA_A_CDC_TX7_VOL_CTL_GAIN: |
| 3487 | case TABLA_A_CDC_TX8_VOL_CTL_GAIN: |
| 3488 | case TABLA_A_CDC_TX9_VOL_CTL_GAIN: |
| 3489 | case TABLA_A_CDC_TX10_VOL_CTL_GAIN: |
| 3490 | rtn = true; |
| 3491 | break; |
| 3492 | default: |
| 3493 | break; |
| 3494 | } |
| 3495 | return rtn; |
| 3496 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3497 | static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 3498 | { |
| 3499 | /* Registers lower than 0x100 are top level registers which can be |
| 3500 | * written by the Tabla core driver. |
| 3501 | */ |
| 3502 | |
| 3503 | if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 3504 | return 1; |
| 3505 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 3506 | /* IIR Coeff registers are not cacheable */ |
| 3507 | if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) && |
| 3508 | (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL)) |
| 3509 | return 1; |
| 3510 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3511 | /* Digital gain register is not cacheable so we have to write |
| 3512 | * the setting even it is the same |
| 3513 | */ |
| 3514 | if (tabla_is_digital_gain_register(reg)) |
| 3515 | return 1; |
| 3516 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3517 | return 0; |
| 3518 | } |
| 3519 | |
| 3520 | #define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 3521 | static int tabla_write(struct snd_soc_codec *codec, unsigned int reg, |
| 3522 | unsigned int value) |
| 3523 | { |
| 3524 | int ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3525 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 3526 | |
| 3527 | if (!tabla_volatile(codec, reg)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3528 | ret = snd_soc_cache_write(codec, reg, value); |
| 3529 | if (ret != 0) |
| 3530 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 3531 | reg, ret); |
| 3532 | } |
| 3533 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3534 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3535 | } |
| 3536 | static unsigned int tabla_read(struct snd_soc_codec *codec, |
| 3537 | unsigned int reg) |
| 3538 | { |
| 3539 | unsigned int val; |
| 3540 | int ret; |
| 3541 | |
| 3542 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 3543 | |
| 3544 | if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) && |
| 3545 | reg < codec->driver->reg_cache_size) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3546 | ret = snd_soc_cache_read(codec, reg, &val); |
| 3547 | if (ret >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3548 | return val; |
| 3549 | } else |
| 3550 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 3551 | reg, ret); |
| 3552 | } |
| 3553 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3554 | val = wcd9xxx_reg_read(codec->control_data, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3555 | return val; |
| 3556 | } |
| 3557 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3558 | static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu) |
| 3559 | { |
| 3560 | s16 v_ins; |
| 3561 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 3562 | tabla->mbhc_micbias_switched) |
| 3563 | v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu : |
| 3564 | (s16)tabla->mbhc_data.adj_v_ins_h; |
| 3565 | else |
| 3566 | v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu : |
| 3567 | (s16)tabla->mbhc_data.v_ins_h; |
| 3568 | return v_ins; |
| 3569 | } |
| 3570 | |
| 3571 | static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla) |
| 3572 | { |
| 3573 | s16 v_hs_max; |
| 3574 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 3575 | |
| 3576 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 3577 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 3578 | tabla->mbhc_micbias_switched) |
| 3579 | v_hs_max = tabla->mbhc_data.adj_v_hs_max; |
| 3580 | else |
| 3581 | v_hs_max = plug_type->v_hs_max; |
| 3582 | return v_hs_max; |
| 3583 | } |
| 3584 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3585 | static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 3586 | { |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3587 | u8 *n_ready, *n_cic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3588 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 3589 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3590 | const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true); |
| 3591 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3592 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3593 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3594 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3595 | v_ins_hu & 0xFF); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3596 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3597 | (v_ins_hu >> 8) & 0xFF); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3598 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3599 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 3600 | tabla->mbhc_data.v_b1_hu & 0xFF); |
| 3601 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 3602 | (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 3603 | |
| 3604 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 3605 | tabla->mbhc_data.v_b1_h & 0xFF); |
| 3606 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 3607 | (tabla->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 3608 | |
| 3609 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, |
| 3610 | tabla->mbhc_data.v_brh & 0xFF); |
| 3611 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, |
| 3612 | (tabla->mbhc_data.v_brh >> 8) & 0xFF); |
| 3613 | |
| 3614 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL, |
| 3615 | tabla->mbhc_data.v_brl & 0xFF); |
| 3616 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL, |
| 3617 | (tabla->mbhc_data.v_brl >> 8) & 0xFF); |
| 3618 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3619 | n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3620 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 3621 | n_ready[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3622 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, |
| 3623 | tabla->mbhc_data.npoll); |
| 3624 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, |
| 3625 | tabla->mbhc_data.nbounce_wait); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3626 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
Joonwoo Park | 107edf0 | 2012-01-11 11:42:24 -0800 | [diff] [blame] | 3627 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, |
| 3628 | n_cic[tabla_codec_mclk_index(tabla)]); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3631 | static int tabla_startup(struct snd_pcm_substream *substream, |
| 3632 | struct snd_soc_dai *dai) |
| 3633 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3634 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3635 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 3636 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3637 | if ((tabla_core != NULL) && |
| 3638 | (tabla_core->dev != NULL) && |
| 3639 | (tabla_core->dev->parent != NULL)) |
| 3640 | pm_runtime_get_sync(tabla_core->dev->parent); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3641 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3642 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | static void tabla_shutdown(struct snd_pcm_substream *substream, |
| 3646 | struct snd_soc_dai *dai) |
| 3647 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3648 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3649 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 3650 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 3651 | if ((tabla_core != NULL) && |
| 3652 | (tabla_core->dev != NULL) && |
| 3653 | (tabla_core->dev->parent != NULL)) { |
| 3654 | pm_runtime_mark_last_busy(tabla_core->dev->parent); |
| 3655 | pm_runtime_put(tabla_core->dev->parent); |
| 3656 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3659 | int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, bool dapm) |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3660 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3661 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3662 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 3663 | pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable, |
| 3664 | dapm); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3665 | if (dapm) |
| 3666 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3667 | if (mclk_enable) { |
| 3668 | tabla->mclk_enabled = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3669 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3670 | if (tabla->mbhc_polling_active && (tabla->mclk_enabled)) { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3671 | tabla_codec_pause_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3672 | tabla_codec_enable_bandgap(codec, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3673 | TABLA_BANDGAP_AUDIO_MODE); |
| 3674 | tabla_codec_enable_clock_block(codec, 0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 3675 | tabla_codec_calibrate_hs_polling(codec); |
| 3676 | tabla_codec_start_hs_polling(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3677 | } else { |
| 3678 | tabla_codec_enable_bandgap(codec, |
| 3679 | TABLA_BANDGAP_AUDIO_MODE); |
| 3680 | tabla_codec_enable_clock_block(codec, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3681 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3682 | } else { |
| 3683 | |
| 3684 | if (!tabla->mclk_enabled) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3685 | if (dapm) |
| 3686 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3687 | pr_err("Error, MCLK already diabled\n"); |
| 3688 | return -EINVAL; |
| 3689 | } |
| 3690 | tabla->mclk_enabled = false; |
| 3691 | |
| 3692 | if (tabla->mbhc_polling_active) { |
| 3693 | if (!tabla->mclk_enabled) { |
| 3694 | tabla_codec_pause_hs_polling(codec); |
| 3695 | tabla_codec_enable_bandgap(codec, |
| 3696 | TABLA_BANDGAP_MBHC_MODE); |
| 3697 | tabla_enable_rx_bias(codec, 1); |
| 3698 | tabla_codec_enable_clock_block(codec, 1); |
| 3699 | tabla_codec_calibrate_hs_polling(codec); |
| 3700 | tabla_codec_start_hs_polling(codec); |
| 3701 | } |
| 3702 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, |
| 3703 | 0x05, 0x01); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 3704 | } else { |
| 3705 | tabla_codec_disable_clock_block(codec); |
| 3706 | tabla_codec_enable_bandgap(codec, |
| 3707 | TABLA_BANDGAP_OFF); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3708 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3709 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3710 | if (dapm) |
| 3711 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3712 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3715 | static int tabla_set_dai_sysclk(struct snd_soc_dai *dai, |
| 3716 | int clk_id, unsigned int freq, int dir) |
| 3717 | { |
| 3718 | pr_debug("%s\n", __func__); |
| 3719 | return 0; |
| 3720 | } |
| 3721 | |
| 3722 | static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 3723 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3724 | u8 val = 0; |
| 3725 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 3726 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3727 | pr_debug("%s\n", __func__); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3728 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 3729 | case SND_SOC_DAIFMT_CBS_CFS: |
| 3730 | /* CPU is master */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3731 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3732 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3733 | snd_soc_update_bits(dai->codec, |
| 3734 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 3735 | TABLA_I2S_MASTER_MODE_MASK, 0); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3736 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3737 | snd_soc_update_bits(dai->codec, |
| 3738 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3739 | TABLA_I2S_MASTER_MODE_MASK, 0); |
| 3740 | } |
| 3741 | break; |
| 3742 | case SND_SOC_DAIFMT_CBM_CFM: |
| 3743 | /* CPU is slave */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3744 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3745 | val = TABLA_I2S_MASTER_MODE_MASK; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3746 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3747 | snd_soc_update_bits(dai->codec, |
| 3748 | TABLA_A_CDC_CLK_TX_I2S_CTL, val, val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3749 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3750 | snd_soc_update_bits(dai->codec, |
| 3751 | TABLA_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 3752 | } |
| 3753 | break; |
| 3754 | default: |
| 3755 | return -EINVAL; |
| 3756 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3757 | return 0; |
| 3758 | } |
| 3759 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3760 | static int tabla_set_channel_map(struct snd_soc_dai *dai, |
| 3761 | unsigned int tx_num, unsigned int *tx_slot, |
| 3762 | unsigned int rx_num, unsigned int *rx_slot) |
| 3763 | |
| 3764 | { |
| 3765 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 3766 | u32 i = 0; |
| 3767 | if (!tx_slot && !rx_slot) { |
| 3768 | pr_err("%s: Invalid\n", __func__); |
| 3769 | return -EINVAL; |
| 3770 | } |
| 3771 | pr_debug("%s: DAI-ID %x %d %d\n", __func__, dai->id, tx_num, rx_num); |
| 3772 | |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3773 | if (dai->id == AIF1_PB || dai->id == AIF2_PB) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3774 | for (i = 0; i < rx_num; i++) { |
| 3775 | tabla->dai[dai->id - 1].ch_num[i] = rx_slot[i]; |
| 3776 | tabla->dai[dai->id - 1].ch_act = 0; |
| 3777 | tabla->dai[dai->id - 1].ch_tot = rx_num; |
| 3778 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3779 | } else if (dai->id == AIF1_CAP || dai->id == AIF2_CAP) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3780 | for (i = 0; i < tx_num; i++) { |
| 3781 | tabla->dai[dai->id - 1].ch_num[i] = tx_slot[i]; |
| 3782 | tabla->dai[dai->id - 1].ch_act = 0; |
| 3783 | tabla->dai[dai->id - 1].ch_tot = tx_num; |
| 3784 | } |
| 3785 | } |
| 3786 | return 0; |
| 3787 | } |
| 3788 | |
| 3789 | static int tabla_get_channel_map(struct snd_soc_dai *dai, |
| 3790 | unsigned int *tx_num, unsigned int *tx_slot, |
| 3791 | unsigned int *rx_num, unsigned int *rx_slot) |
| 3792 | |
| 3793 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3794 | struct wcd9xxx *tabla = dev_get_drvdata(dai->codec->control_data); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3795 | |
| 3796 | u32 cnt = 0; |
| 3797 | u32 tx_ch[SLIM_MAX_TX_PORTS]; |
| 3798 | u32 rx_ch[SLIM_MAX_RX_PORTS]; |
| 3799 | |
| 3800 | if (!rx_slot && !tx_slot) { |
| 3801 | pr_err("%s: Invalid\n", __func__); |
| 3802 | return -EINVAL; |
| 3803 | } |
| 3804 | pr_debug("%s: DAI-ID %x\n", __func__, dai->id); |
| 3805 | /* for virtual port, codec driver needs to do |
| 3806 | * housekeeping, for now should be ok |
| 3807 | */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3808 | wcd9xxx_get_channel(tabla, rx_ch, tx_ch); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3809 | if (dai->id == AIF1_PB) { |
| 3810 | *rx_num = tabla_dai[dai->id - 1].playback.channels_max; |
| 3811 | while (cnt < *rx_num) { |
| 3812 | rx_slot[cnt] = rx_ch[cnt]; |
| 3813 | cnt++; |
| 3814 | } |
| 3815 | } else if (dai->id == AIF1_CAP) { |
| 3816 | *tx_num = tabla_dai[dai->id - 1].capture.channels_max; |
| 3817 | while (cnt < *tx_num) { |
| 3818 | tx_slot[cnt] = tx_ch[6 + cnt]; |
| 3819 | cnt++; |
| 3820 | } |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3821 | } else if (dai->id == AIF2_PB) { |
| 3822 | *rx_num = tabla_dai[dai->id - 1].playback.channels_max; |
| 3823 | while (cnt < *rx_num) { |
| 3824 | rx_slot[cnt] = rx_ch[5 + cnt]; |
| 3825 | cnt++; |
| 3826 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3827 | } else if (dai->id == AIF2_CAP) { |
| 3828 | *tx_num = tabla_dai[dai->id - 1].capture.channels_max; |
| 3829 | tx_slot[0] = tx_ch[cnt]; |
| 3830 | tx_slot[1] = tx_ch[1 + cnt]; |
| 3831 | tx_slot[2] = tx_ch[3 + cnt]; |
| 3832 | tx_slot[3] = tx_ch[5 + cnt]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3833 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3834 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3835 | return 0; |
| 3836 | } |
| 3837 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3838 | static int tabla_hw_params(struct snd_pcm_substream *substream, |
| 3839 | struct snd_pcm_hw_params *params, |
| 3840 | struct snd_soc_dai *dai) |
| 3841 | { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3842 | struct snd_soc_codec *codec = dai->codec; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3843 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Bhalchandra Gajare | 038bf3a | 2011-09-02 15:32:30 -0700 | [diff] [blame] | 3844 | u8 path, shift; |
| 3845 | u16 tx_fs_reg, rx_fs_reg; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3846 | u8 tx_fs_rate, rx_fs_rate, rx_state, tx_state; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3847 | u32 compander_fs; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3848 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3849 | pr_debug("%s: DAI-ID %x rate %d\n", __func__, dai->id, |
| 3850 | params_rate(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3851 | |
| 3852 | switch (params_rate(params)) { |
| 3853 | case 8000: |
| 3854 | tx_fs_rate = 0x00; |
| 3855 | rx_fs_rate = 0x00; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3856 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3857 | break; |
| 3858 | case 16000: |
| 3859 | tx_fs_rate = 0x01; |
| 3860 | rx_fs_rate = 0x20; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3861 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3862 | break; |
| 3863 | case 32000: |
| 3864 | tx_fs_rate = 0x02; |
| 3865 | rx_fs_rate = 0x40; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3866 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3867 | break; |
| 3868 | case 48000: |
| 3869 | tx_fs_rate = 0x03; |
| 3870 | rx_fs_rate = 0x60; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3871 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3872 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3873 | case 96000: |
| 3874 | tx_fs_rate = 0x04; |
| 3875 | rx_fs_rate = 0x80; |
| 3876 | compander_fs = COMPANDER_FS_96KHZ; |
| 3877 | break; |
| 3878 | case 192000: |
| 3879 | tx_fs_rate = 0x05; |
| 3880 | rx_fs_rate = 0xA0; |
| 3881 | compander_fs = COMPANDER_FS_192KHZ; |
| 3882 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3883 | default: |
| 3884 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
| 3885 | params_rate(params)); |
| 3886 | return -EINVAL; |
| 3887 | } |
| 3888 | |
| 3889 | |
| 3890 | /** |
| 3891 | * If current dai is a tx dai, set sample rate to |
| 3892 | * all the txfe paths that are currently not active |
| 3893 | */ |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3894 | if ((dai->id == AIF1_CAP) || (dai->id == AIF2_CAP)) { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3895 | |
| 3896 | tx_state = snd_soc_read(codec, |
| 3897 | TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL); |
| 3898 | |
| 3899 | for (path = 1, shift = 0; |
| 3900 | path <= NUM_DECIMATORS; path++, shift++) { |
| 3901 | |
| 3902 | if (path == BITS_PER_REG + 1) { |
| 3903 | shift = 0; |
| 3904 | tx_state = snd_soc_read(codec, |
| 3905 | TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL); |
| 3906 | } |
| 3907 | |
| 3908 | if (!(tx_state & (1 << shift))) { |
| 3909 | tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL |
| 3910 | + (BITS_PER_REG*(path-1)); |
| 3911 | snd_soc_update_bits(codec, tx_fs_reg, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3912 | 0x07, tx_fs_rate); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3913 | } |
| 3914 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3915 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3916 | switch (params_format(params)) { |
| 3917 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3918 | snd_soc_update_bits(codec, |
| 3919 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 3920 | 0x20, 0x20); |
| 3921 | break; |
| 3922 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3923 | snd_soc_update_bits(codec, |
| 3924 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 3925 | 0x20, 0x00); |
| 3926 | break; |
| 3927 | default: |
| 3928 | pr_err("invalid format\n"); |
| 3929 | break; |
| 3930 | } |
| 3931 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3932 | 0x07, tx_fs_rate); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3933 | } else { |
| 3934 | tabla->dai[dai->id - 1].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3935 | } |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3936 | } |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3937 | /** |
| 3938 | * TODO: Need to handle case where same RX chain takes 2 or more inputs |
| 3939 | * with varying sample rates |
| 3940 | */ |
| 3941 | |
| 3942 | /** |
| 3943 | * If current dai is a rx dai, set sample rate to |
| 3944 | * all the rx paths that are currently not active |
| 3945 | */ |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3946 | if (dai->id == AIF1_PB || dai->id == AIF2_PB) { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3947 | |
| 3948 | rx_state = snd_soc_read(codec, |
| 3949 | TABLA_A_CDC_CLK_RX_B1_CTL); |
| 3950 | |
| 3951 | for (path = 1, shift = 0; |
| 3952 | path <= NUM_INTERPOLATORS; path++, shift++) { |
| 3953 | |
| 3954 | if (!(rx_state & (1 << shift))) { |
| 3955 | rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL |
| 3956 | + (BITS_PER_REG*(path-1)); |
| 3957 | snd_soc_update_bits(codec, rx_fs_reg, |
| 3958 | 0xE0, rx_fs_rate); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3959 | if (comp_rx_path[shift] < COMPANDER_MAX) |
| 3960 | tabla->comp_fs[comp_rx_path[shift]] |
| 3961 | = compander_fs; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3962 | } |
| 3963 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3964 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3965 | switch (params_format(params)) { |
| 3966 | case SNDRV_PCM_FORMAT_S16_LE: |
| 3967 | snd_soc_update_bits(codec, |
| 3968 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3969 | 0x20, 0x20); |
| 3970 | break; |
| 3971 | case SNDRV_PCM_FORMAT_S32_LE: |
| 3972 | snd_soc_update_bits(codec, |
| 3973 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3974 | 0x20, 0x00); |
| 3975 | break; |
| 3976 | default: |
| 3977 | pr_err("invalid format\n"); |
| 3978 | break; |
| 3979 | } |
| 3980 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3981 | 0x03, (rx_fs_rate >> 0x05)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3982 | } else { |
| 3983 | tabla->dai[dai->id - 1].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3984 | } |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3987 | return 0; |
| 3988 | } |
| 3989 | |
| 3990 | static struct snd_soc_dai_ops tabla_dai_ops = { |
| 3991 | .startup = tabla_startup, |
| 3992 | .shutdown = tabla_shutdown, |
| 3993 | .hw_params = tabla_hw_params, |
| 3994 | .set_sysclk = tabla_set_dai_sysclk, |
| 3995 | .set_fmt = tabla_set_dai_fmt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 3996 | .set_channel_map = tabla_set_channel_map, |
| 3997 | .get_channel_map = tabla_get_channel_map, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3998 | }; |
| 3999 | |
| 4000 | static struct snd_soc_dai_driver tabla_dai[] = { |
| 4001 | { |
| 4002 | .name = "tabla_rx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4003 | .id = AIF1_PB, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4004 | .playback = { |
| 4005 | .stream_name = "AIF1 Playback", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4006 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4007 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4008 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4009 | .rate_min = 8000, |
| 4010 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4011 | .channels_max = 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4012 | }, |
| 4013 | .ops = &tabla_dai_ops, |
| 4014 | }, |
| 4015 | { |
| 4016 | .name = "tabla_tx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4017 | .id = AIF1_CAP, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4018 | .capture = { |
| 4019 | .stream_name = "AIF1 Capture", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4020 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4021 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4022 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4023 | .rate_min = 8000, |
| 4024 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4025 | .channels_max = 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4026 | }, |
| 4027 | .ops = &tabla_dai_ops, |
| 4028 | }, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4029 | { |
| 4030 | .name = "tabla_rx2", |
| 4031 | .id = AIF2_PB, |
| 4032 | .playback = { |
| 4033 | .stream_name = "AIF2 Playback", |
| 4034 | .rates = WCD9310_RATES, |
| 4035 | .formats = TABLA_FORMATS, |
| 4036 | .rate_min = 8000, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4037 | .rate_max = 192000, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4038 | .channels_min = 1, |
| 4039 | .channels_max = 2, |
| 4040 | }, |
| 4041 | .ops = &tabla_dai_ops, |
| 4042 | }, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4043 | { |
| 4044 | .name = "tabla_tx2", |
| 4045 | .id = AIF2_CAP, |
| 4046 | .capture = { |
| 4047 | .stream_name = "AIF2 Capture", |
| 4048 | .rates = WCD9310_RATES, |
| 4049 | .formats = TABLA_FORMATS, |
| 4050 | .rate_max = 192000, |
| 4051 | .rate_min = 8000, |
| 4052 | .channels_min = 1, |
| 4053 | .channels_max = 4, |
| 4054 | }, |
| 4055 | .ops = &tabla_dai_ops, |
| 4056 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4057 | }; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4058 | |
| 4059 | static struct snd_soc_dai_driver tabla_i2s_dai[] = { |
| 4060 | { |
| 4061 | .name = "tabla_i2s_rx1", |
| 4062 | .id = 1, |
| 4063 | .playback = { |
| 4064 | .stream_name = "AIF1 Playback", |
| 4065 | .rates = WCD9310_RATES, |
| 4066 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4067 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4068 | .rate_min = 8000, |
| 4069 | .channels_min = 1, |
| 4070 | .channels_max = 4, |
| 4071 | }, |
| 4072 | .ops = &tabla_dai_ops, |
| 4073 | }, |
| 4074 | { |
| 4075 | .name = "tabla_i2s_tx1", |
| 4076 | .id = 2, |
| 4077 | .capture = { |
| 4078 | .stream_name = "AIF1 Capture", |
| 4079 | .rates = WCD9310_RATES, |
| 4080 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4081 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4082 | .rate_min = 8000, |
| 4083 | .channels_min = 1, |
| 4084 | .channels_max = 4, |
| 4085 | }, |
| 4086 | .ops = &tabla_dai_ops, |
| 4087 | }, |
| 4088 | }; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4089 | |
| 4090 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 4091 | struct snd_kcontrol *kcontrol, int event) |
| 4092 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4093 | struct wcd9xxx *tabla; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4094 | struct snd_soc_codec *codec = w->codec; |
| 4095 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 4096 | u32 j = 0; |
| 4097 | u32 ret = 0; |
| 4098 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4099 | tabla = codec->control_data; |
| 4100 | /* Execute the callback only if interface type is slimbus */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4101 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4102 | return 0; |
| 4103 | switch (event) { |
| 4104 | case SND_SOC_DAPM_POST_PMU: |
| 4105 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4106 | if ((tabla_dai[j].id == AIF1_CAP) || |
| 4107 | (tabla_dai[j].id == AIF2_CAP)) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4108 | continue; |
| 4109 | if (!strncmp(w->sname, |
| 4110 | tabla_dai[j].playback.stream_name, 13)) { |
| 4111 | ++tabla_p->dai[j].ch_act; |
| 4112 | break; |
| 4113 | } |
| 4114 | } |
| 4115 | if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4116 | ret = wcd9xxx_cfg_slim_sch_rx(tabla, |
| 4117 | tabla_p->dai[j].ch_num, |
| 4118 | tabla_p->dai[j].ch_tot, |
| 4119 | tabla_p->dai[j].rate); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4120 | break; |
| 4121 | case SND_SOC_DAPM_POST_PMD: |
| 4122 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4123 | if ((tabla_dai[j].id == AIF1_CAP) || |
| 4124 | (tabla_dai[j].id == AIF2_CAP)) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4125 | continue; |
| 4126 | if (!strncmp(w->sname, |
| 4127 | tabla_dai[j].playback.stream_name, 13)) { |
| 4128 | --tabla_p->dai[j].ch_act; |
| 4129 | break; |
| 4130 | } |
| 4131 | } |
| 4132 | if (!tabla_p->dai[j].ch_act) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4133 | ret = wcd9xxx_close_slim_sch_rx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4134 | tabla_p->dai[j].ch_num, |
| 4135 | tabla_p->dai[j].ch_tot); |
Bharath Ramachandramurthy | da6fa7a | 2012-03-30 14:35:32 -0700 | [diff] [blame] | 4136 | usleep_range(5000, 5000); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4137 | tabla_p->dai[j].rate = 0; |
| 4138 | memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)* |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4139 | tabla_p->dai[j].ch_tot)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4140 | tabla_p->dai[j].ch_tot = 0; |
| 4141 | } |
| 4142 | } |
| 4143 | return ret; |
| 4144 | } |
| 4145 | |
| 4146 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 4147 | struct snd_kcontrol *kcontrol, int event) |
| 4148 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4149 | struct wcd9xxx *tabla; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4150 | struct snd_soc_codec *codec = w->codec; |
| 4151 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 4152 | /* index to the DAI ID, for now hardcoding */ |
| 4153 | u32 j = 0; |
| 4154 | u32 ret = 0; |
| 4155 | |
| 4156 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 4157 | tabla = codec->control_data; |
| 4158 | |
| 4159 | /* Execute the callback only if interface type is slimbus */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4160 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4161 | return 0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4162 | |
| 4163 | pr_debug("%s(): %s %d\n", __func__, w->name, event); |
| 4164 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4165 | switch (event) { |
| 4166 | case SND_SOC_DAPM_POST_PMU: |
| 4167 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4168 | if (tabla_dai[j].id == AIF1_PB || |
| 4169 | tabla_dai[j].id == AIF2_PB) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4170 | continue; |
| 4171 | if (!strncmp(w->sname, |
| 4172 | tabla_dai[j].capture.stream_name, 13)) { |
| 4173 | ++tabla_p->dai[j].ch_act; |
| 4174 | break; |
| 4175 | } |
| 4176 | } |
| 4177 | if (tabla_p->dai[j].ch_act == tabla_p->dai[j].ch_tot) |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4178 | ret = wcd9xxx_cfg_slim_sch_tx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4179 | tabla_p->dai[j].ch_num, |
| 4180 | tabla_p->dai[j].ch_tot, |
| 4181 | tabla_p->dai[j].rate); |
| 4182 | break; |
| 4183 | case SND_SOC_DAPM_POST_PMD: |
| 4184 | for (j = 0; j < ARRAY_SIZE(tabla_dai); j++) { |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4185 | if (tabla_dai[j].id == AIF1_PB || |
| 4186 | tabla_dai[j].id == AIF2_PB) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4187 | continue; |
| 4188 | if (!strncmp(w->sname, |
| 4189 | tabla_dai[j].capture.stream_name, 13)) { |
| 4190 | --tabla_p->dai[j].ch_act; |
| 4191 | break; |
| 4192 | } |
| 4193 | } |
| 4194 | if (!tabla_p->dai[j].ch_act) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4195 | ret = wcd9xxx_close_slim_sch_tx(tabla, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4196 | tabla_p->dai[j].ch_num, |
| 4197 | tabla_p->dai[j].ch_tot); |
| 4198 | tabla_p->dai[j].rate = 0; |
| 4199 | memset(tabla_p->dai[j].ch_num, 0, (sizeof(u32)* |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4200 | tabla_p->dai[j].ch_tot)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4201 | tabla_p->dai[j].ch_tot = 0; |
| 4202 | } |
| 4203 | } |
| 4204 | return ret; |
| 4205 | } |
| 4206 | |
| 4207 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 4208 | * Might Need to have callbacks registered only for slimbus |
| 4209 | */ |
| 4210 | static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = { |
| 4211 | /*RX stuff */ |
| 4212 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 4213 | |
| 4214 | SND_SOC_DAPM_PGA("EAR PA", TABLA_A_RX_EAR_EN, 4, 0, NULL, 0), |
| 4215 | |
| 4216 | SND_SOC_DAPM_MIXER("DAC1", TABLA_A_RX_EAR_EN, 6, 0, dac1_switch, |
| 4217 | ARRAY_SIZE(dac1_switch)), |
| 4218 | |
| 4219 | SND_SOC_DAPM_AIF_IN_E("SLIM RX1", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 4220 | 0, tabla_codec_enable_slimrx, |
| 4221 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4222 | SND_SOC_DAPM_AIF_IN_E("SLIM RX2", "AIF1 Playback", 0, SND_SOC_NOPM, 0, |
| 4223 | 0, tabla_codec_enable_slimrx, |
| 4224 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4225 | |
| 4226 | SND_SOC_DAPM_AIF_IN("SLIM RX3", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 4227 | SND_SOC_DAPM_AIF_IN("SLIM RX4", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 4228 | |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4229 | SND_SOC_DAPM_AIF_IN_E("SLIM RX6", "AIF2 Playback", 0, SND_SOC_NOPM, 0, |
| 4230 | 0, tabla_codec_enable_slimrx, |
| 4231 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4232 | SND_SOC_DAPM_AIF_IN_E("SLIM RX7", "AIF2 Playback", 0, SND_SOC_NOPM, 0, |
| 4233 | 0, tabla_codec_enable_slimrx, |
| 4234 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4235 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4236 | /* Headphone */ |
| 4237 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 4238 | SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 4239 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4240 | SND_SOC_DAPM_POST_PMD), |
| 4241 | SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 4242 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 4243 | |
| 4244 | SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 4245 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4246 | SND_SOC_DAPM_POST_PMD), |
| 4247 | |
| 4248 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 4249 | tabla_hphr_dac_event, |
| 4250 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4251 | |
| 4252 | /* Speaker */ |
| 4253 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 4254 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 4255 | SND_SOC_DAPM_OUTPUT("LINEOUT3"), |
| 4256 | SND_SOC_DAPM_OUTPUT("LINEOUT4"), |
| 4257 | SND_SOC_DAPM_OUTPUT("LINEOUT5"), |
| 4258 | |
| 4259 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 4260 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4261 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4262 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 4263 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4264 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4265 | SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL, |
| 4266 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4267 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4268 | SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL, |
| 4269 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4270 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4271 | SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0, |
| 4272 | tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4273 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4274 | |
| 4275 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 4276 | , tabla_lineout_dac_event, |
| 4277 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4278 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 4279 | , tabla_lineout_dac_event, |
| 4280 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4281 | SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0 |
| 4282 | , tabla_lineout_dac_event, |
| 4283 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4284 | SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4285 | &lineout3_ground_switch), |
| 4286 | SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0 |
| 4287 | , tabla_lineout_dac_event, |
| 4288 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4289 | SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4290 | &lineout4_ground_switch), |
| 4291 | SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0 |
| 4292 | , tabla_lineout_dac_event, |
| 4293 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4294 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4295 | SND_SOC_DAPM_MIXER_E("RX1 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 0, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4296 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4297 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4298 | SND_SOC_DAPM_MIXER_E("RX2 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 1, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4299 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4300 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4301 | SND_SOC_DAPM_MIXER_E("RX3 MIX2", TABLA_A_CDC_CLK_RX_B1_CTL, 2, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4302 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4303 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4304 | SND_SOC_DAPM_MIXER_E("RX4 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4305 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4306 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4307 | SND_SOC_DAPM_MIXER_E("RX5 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 4, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4308 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4309 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4310 | SND_SOC_DAPM_MIXER_E("RX6 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4311 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4312 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4313 | SND_SOC_DAPM_MIXER_E("RX7 MIX1", TABLA_A_CDC_CLK_RX_B1_CTL, 6, 0, NULL, |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4314 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 4315 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4316 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4317 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4318 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4319 | SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4320 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4321 | SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, |
| 4322 | &rx4_dsm_mux, tabla_codec_reset_interpolator, |
| 4323 | SND_SOC_DAPM_PRE_PMU), |
| 4324 | |
| 4325 | SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, |
| 4326 | &rx6_dsm_mux, tabla_codec_reset_interpolator, |
| 4327 | SND_SOC_DAPM_PRE_PMU), |
| 4328 | |
| 4329 | SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0), |
| 4330 | SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0), |
| 4331 | |
| 4332 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4333 | &rx_mix1_inp1_mux), |
| 4334 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4335 | &rx_mix1_inp2_mux), |
| 4336 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4337 | &rx2_mix1_inp1_mux), |
| 4338 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4339 | &rx2_mix1_inp2_mux), |
| 4340 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4341 | &rx3_mix1_inp1_mux), |
| 4342 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4343 | &rx3_mix1_inp2_mux), |
| 4344 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4345 | &rx4_mix1_inp1_mux), |
| 4346 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4347 | &rx4_mix1_inp2_mux), |
| 4348 | SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4349 | &rx5_mix1_inp1_mux), |
| 4350 | SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4351 | &rx5_mix1_inp2_mux), |
| 4352 | SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4353 | &rx6_mix1_inp1_mux), |
| 4354 | SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4355 | &rx6_mix1_inp2_mux), |
| 4356 | SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 4357 | &rx7_mix1_inp1_mux), |
| 4358 | SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 4359 | &rx7_mix1_inp2_mux), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4360 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4361 | &rx1_mix2_inp1_mux), |
| 4362 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4363 | &rx1_mix2_inp2_mux), |
| 4364 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4365 | &rx2_mix2_inp1_mux), |
| 4366 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4367 | &rx2_mix2_inp2_mux), |
| 4368 | SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 4369 | &rx3_mix2_inp1_mux), |
| 4370 | SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 4371 | &rx3_mix2_inp2_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4372 | |
| 4373 | SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0, |
| 4374 | tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 4375 | SND_SOC_DAPM_PRE_PMD), |
| 4376 | |
| 4377 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 4378 | tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 4379 | SND_SOC_DAPM_POST_PMD), |
| 4380 | |
| 4381 | /* TX */ |
| 4382 | |
| 4383 | SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 4384 | 0), |
| 4385 | |
| 4386 | SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0, |
| 4387 | tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 4388 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4389 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0, |
| 4390 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4391 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 4392 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0, |
| 4393 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 4394 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 4395 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4396 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 4397 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0, |
| 4398 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4399 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4400 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0, |
| 4401 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4402 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4403 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0, |
| 4404 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4405 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4406 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0, |
| 4407 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4408 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4409 | |
| 4410 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 4411 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0, |
| 4412 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4413 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4414 | |
| 4415 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 4416 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0, |
| 4417 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4418 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4419 | |
| 4420 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 4421 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0, |
| 4422 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 4423 | |
| 4424 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 4425 | SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0, |
| 4426 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 4427 | |
| 4428 | SND_SOC_DAPM_MUX_E("DEC1 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 0, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4429 | &dec1_mux, tabla_codec_enable_dec, |
| 4430 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4431 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4432 | |
| 4433 | SND_SOC_DAPM_MUX_E("DEC2 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 1, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4434 | &dec2_mux, tabla_codec_enable_dec, |
| 4435 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4436 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4437 | |
| 4438 | SND_SOC_DAPM_MUX_E("DEC3 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 2, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4439 | &dec3_mux, tabla_codec_enable_dec, |
| 4440 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4441 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4442 | |
| 4443 | SND_SOC_DAPM_MUX_E("DEC4 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 3, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4444 | &dec4_mux, tabla_codec_enable_dec, |
| 4445 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4446 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4447 | |
| 4448 | SND_SOC_DAPM_MUX_E("DEC5 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 4, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4449 | &dec5_mux, tabla_codec_enable_dec, |
| 4450 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4451 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4452 | |
| 4453 | SND_SOC_DAPM_MUX_E("DEC6 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 5, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4454 | &dec6_mux, tabla_codec_enable_dec, |
| 4455 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4456 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4457 | |
| 4458 | SND_SOC_DAPM_MUX_E("DEC7 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 6, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4459 | &dec7_mux, tabla_codec_enable_dec, |
| 4460 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4461 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4462 | |
| 4463 | SND_SOC_DAPM_MUX_E("DEC8 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL, 7, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4464 | &dec8_mux, tabla_codec_enable_dec, |
| 4465 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4466 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4467 | |
| 4468 | SND_SOC_DAPM_MUX_E("DEC9 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 0, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4469 | &dec9_mux, tabla_codec_enable_dec, |
| 4470 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4471 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4472 | |
| 4473 | SND_SOC_DAPM_MUX_E("DEC10 MUX", TABLA_A_CDC_CLK_TX_CLK_EN_B2_CTL, 1, 0, |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 4474 | &dec10_mux, tabla_codec_enable_dec, |
| 4475 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 4476 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4477 | |
| 4478 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 4479 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 4480 | |
| 4481 | SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 4482 | tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU | |
| 4483 | SND_SOC_DAPM_POST_PMD), |
| 4484 | |
| 4485 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 4486 | |
| 4487 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 4488 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0, |
| 4489 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4490 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4491 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0, |
| 4492 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4493 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4494 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0, |
| 4495 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4496 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4497 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0, |
| 4498 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4499 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4500 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0, |
| 4501 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4502 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4503 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0, |
| 4504 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4505 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4506 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0, |
| 4507 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 4508 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4509 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0, |
| 4510 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 4511 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4512 | |
| 4513 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, 0, 0, &sb_tx1_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4514 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX1", "AIF2 Capture", 0, SND_SOC_NOPM, 0, |
| 4515 | 0, tabla_codec_enable_slimtx, |
| 4516 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4517 | |
| 4518 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, 0, 0, &sb_tx2_mux), |
| 4519 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX2", "AIF2 Capture", 0, SND_SOC_NOPM, 0, |
| 4520 | 0, tabla_codec_enable_slimtx, |
| 4521 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4522 | |
| 4523 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, 0, 0, &sb_tx3_mux), |
| 4524 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX3", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 4525 | 0, tabla_codec_enable_slimtx, |
| 4526 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4527 | |
| 4528 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, 0, 0, &sb_tx4_mux), |
| 4529 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX4", "AIF2 Capture", 0, SND_SOC_NOPM, 0, |
| 4530 | 0, tabla_codec_enable_slimtx, |
| 4531 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4532 | |
| 4533 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, 0, 0, &sb_tx5_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4534 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX5", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 4535 | 0, tabla_codec_enable_slimtx, |
| 4536 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4537 | |
| 4538 | SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, 0, 0, &sb_tx6_mux), |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4539 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX6", "AIF2 Capture", 0, SND_SOC_NOPM, 0, |
| 4540 | 0, tabla_codec_enable_slimtx, |
| 4541 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4542 | |
| 4543 | SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, 0, 0, &sb_tx7_mux), |
| 4544 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX7", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 4545 | 0, tabla_codec_enable_slimtx, |
| 4546 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4547 | |
| 4548 | SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, 0, 0, &sb_tx8_mux), |
| 4549 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX8", "AIF1 Capture", 0, SND_SOC_NOPM, 0, |
| 4550 | 0, tabla_codec_enable_slimtx, |
| 4551 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4552 | |
| 4553 | SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, 0, 0, &sb_tx9_mux), |
| 4554 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX9", "AIF1 Capture", NULL, SND_SOC_NOPM, |
| 4555 | 0, 0, tabla_codec_enable_slimtx, |
| 4556 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4557 | |
| 4558 | SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, 0, 0, &sb_tx10_mux), |
| 4559 | SND_SOC_DAPM_AIF_OUT_E("SLIM TX10", "AIF1 Capture", NULL, SND_SOC_NOPM, |
| 4560 | 0, 0, tabla_codec_enable_slimtx, |
| 4561 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4562 | |
| 4563 | /* Digital Mic Inputs */ |
| 4564 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 4565 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4566 | SND_SOC_DAPM_POST_PMD), |
| 4567 | |
| 4568 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 4569 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4570 | SND_SOC_DAPM_POST_PMD), |
| 4571 | |
| 4572 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 4573 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4574 | SND_SOC_DAPM_POST_PMD), |
| 4575 | |
| 4576 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 4577 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4578 | SND_SOC_DAPM_POST_PMD), |
| 4579 | |
| 4580 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 4581 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4582 | SND_SOC_DAPM_POST_PMD), |
| 4583 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 4584 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 4585 | SND_SOC_DAPM_POST_PMD), |
| 4586 | |
| 4587 | /* Sidetone */ |
| 4588 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 4589 | SND_SOC_DAPM_PGA("IIR1", TABLA_A_CDC_CLK_SD_CTL, 0, 0, NULL, 0), |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 4590 | |
| 4591 | /* AUX PGA */ |
| 4592 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0, |
| 4593 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4594 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4595 | SND_SOC_DAPM_POST_PMD), |
| 4596 | |
| 4597 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0, |
| 4598 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 4599 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 4600 | SND_SOC_DAPM_POST_PMD), |
| 4601 | |
| 4602 | /* Lineout, ear and HPH PA Mixers */ |
| 4603 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4604 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 4605 | |
| 4606 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4607 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 4608 | |
| 4609 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4610 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 4611 | |
| 4612 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4613 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
| 4614 | |
| 4615 | SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4616 | lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)), |
| 4617 | |
| 4618 | SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4619 | lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)), |
| 4620 | |
| 4621 | SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4622 | lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)), |
| 4623 | |
| 4624 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 4625 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4626 | }; |
| 4627 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4628 | static short tabla_codec_read_sta_result(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4629 | { |
| 4630 | u8 bias_msb, bias_lsb; |
| 4631 | short bias_value; |
| 4632 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4633 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS); |
| 4634 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS); |
| 4635 | bias_value = (bias_msb << 8) | bias_lsb; |
| 4636 | return bias_value; |
| 4637 | } |
| 4638 | |
| 4639 | static short tabla_codec_read_dce_result(struct snd_soc_codec *codec) |
| 4640 | { |
| 4641 | u8 bias_msb, bias_lsb; |
| 4642 | short bias_value; |
| 4643 | |
| 4644 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS); |
| 4645 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS); |
| 4646 | bias_value = (bias_msb << 8) | bias_lsb; |
| 4647 | return bias_value; |
| 4648 | } |
| 4649 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4650 | static void tabla_turn_onoff_rel_detection(struct snd_soc_codec *codec, bool on) |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4651 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4652 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 4653 | } |
| 4654 | |
| 4655 | static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 4656 | bool override_bypass, bool noreldetection) |
| 4657 | { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4658 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4659 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4660 | |
| 4661 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 4662 | if (noreldetection) |
| 4663 | tabla_turn_onoff_rel_detection(codec, false); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4664 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 4665 | /* Turn on the override */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4666 | if (!override_bypass) |
| 4667 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x4, 0x4); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4668 | if (dce) { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4669 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 4670 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
| 4671 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 4672 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 4673 | tabla->mbhc_data.t_sta_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4674 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4675 | usleep_range(tabla->mbhc_data.t_dce, |
| 4676 | tabla->mbhc_data.t_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4677 | bias_value = tabla_codec_read_dce_result(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4678 | } else { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4679 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4680 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 4681 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 4682 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 4683 | tabla->mbhc_data.t_sta_dce); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4684 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 4685 | usleep_range(tabla->mbhc_data.t_sta, |
| 4686 | tabla->mbhc_data.t_sta); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4687 | bias_value = tabla_codec_read_sta_result(codec); |
| 4688 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 4689 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4690 | } |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 4691 | /* Turn off the override after measuring mic voltage */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4692 | if (!override_bypass) |
| 4693 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 4694 | |
| 4695 | if (noreldetection) |
| 4696 | tabla_turn_onoff_rel_detection(codec, true); |
| 4697 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4698 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4699 | return bias_value; |
| 4700 | } |
| 4701 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4702 | static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 4703 | bool norel) |
| 4704 | { |
| 4705 | return __tabla_codec_sta_dce(codec, dce, false, norel); |
| 4706 | } |
| 4707 | |
| 4708 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 4709 | static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4710 | { |
| 4711 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 4712 | short bias_value; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 4713 | u8 cfilt_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4714 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4715 | pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4716 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4717 | pr_err("Error, no tabla calibration\n"); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4718 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4721 | if (!tabla->mclk_enabled) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4722 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4723 | tabla_enable_rx_bias(codec, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4724 | tabla_codec_enable_clock_block(codec, 1); |
| 4725 | } |
| 4726 | |
| 4727 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01); |
| 4728 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 4729 | /* Make sure CFILT is in fast mode, save current mode */ |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 4730 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
| 4731 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 4732 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 4733 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x1F, 0x16); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4734 | |
| 4735 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4736 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4737 | |
| 4738 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80); |
| 4739 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C); |
| 4740 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40); |
| 4741 | |
| 4742 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4743 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 4744 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4745 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 4746 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x2, 0x2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4747 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 4748 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4749 | tabla_codec_calibrate_hs_polling(codec); |
| 4750 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4751 | /* don't flip override */ |
| 4752 | bias_value = __tabla_codec_sta_dce(codec, 1, true, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4753 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 4754 | cfilt_mode); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 4755 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4756 | |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 4757 | return bias_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4760 | static int tabla_cancel_btn_work(struct tabla_priv *tabla) |
| 4761 | { |
| 4762 | int r = 0; |
| 4763 | struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent); |
| 4764 | |
| 4765 | if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) { |
| 4766 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 4767 | * we have to unlock from here instead btn_work */ |
| 4768 | wcd9xxx_unlock_sleep(core); |
| 4769 | r = 1; |
| 4770 | } |
| 4771 | return r; |
| 4772 | } |
| 4773 | |
| 4774 | /* called under codec_resource_lock acquisition */ |
| 4775 | void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4776 | { |
| 4777 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4778 | u8 wg_time; |
| 4779 | |
| 4780 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 4781 | wg_time += 1; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4782 | |
| 4783 | /* If headphone PA is on, check if userspace receives |
| 4784 | * removal event to sync-up PA's state */ |
| 4785 | if (tabla_is_hph_pa_on(codec)) { |
| 4786 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 4787 | set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 4788 | set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 4789 | } else { |
| 4790 | pr_debug("%s PA is off\n", __func__); |
| 4791 | } |
| 4792 | |
| 4793 | if (tabla_is_hph_dac_on(codec, 1)) |
| 4794 | set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
| 4795 | if (tabla_is_hph_dac_on(codec, 0)) |
| 4796 | set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4797 | |
| 4798 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 4799 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 4800 | 0xC0, 0x00); |
| 4801 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 4802 | 0xC0, 0x00); |
| 4803 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 4804 | } |
| 4805 | |
| 4806 | static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla) |
| 4807 | { |
| 4808 | bool pa_turned_on = false; |
| 4809 | struct snd_soc_codec *codec = tabla->codec; |
| 4810 | u8 wg_time; |
| 4811 | |
| 4812 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 4813 | wg_time += 1; |
| 4814 | |
| 4815 | if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 4816 | &tabla->hph_pa_dac_state)) { |
| 4817 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 4818 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 4819 | 0xC0, 0xC0); |
| 4820 | } |
| 4821 | if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 4822 | &tabla->hph_pa_dac_state)) { |
| 4823 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 4824 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 4825 | 0xC0, 0xC0); |
| 4826 | } |
| 4827 | |
| 4828 | if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 4829 | &tabla->hph_pa_dac_state)) { |
| 4830 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 4831 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10, |
| 4832 | 1 << 4); |
| 4833 | pa_turned_on = true; |
| 4834 | } |
| 4835 | if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 4836 | &tabla->hph_pa_dac_state)) { |
| 4837 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 4838 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20, |
| 4839 | 1 << 5); |
| 4840 | pa_turned_on = true; |
| 4841 | } |
| 4842 | |
| 4843 | if (pa_turned_on) { |
| 4844 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 4845 | __func__); |
| 4846 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | /* called under codec_resource_lock acquisition */ |
| 4851 | static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 4852 | enum snd_jack_types jack_type) |
| 4853 | { |
| 4854 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4855 | |
| 4856 | if (!insertion) { |
| 4857 | /* Report removal */ |
| 4858 | tabla->hph_status &= ~jack_type; |
| 4859 | if (tabla->mbhc_cfg.headset_jack) { |
| 4860 | /* cancel possibly scheduled btn work and |
| 4861 | * report release if we reported button press */ |
| 4862 | if (tabla_cancel_btn_work(tabla)) { |
| 4863 | pr_debug("%s: button press is canceled\n", |
| 4864 | __func__); |
| 4865 | } else if (tabla->buttons_pressed) { |
| 4866 | pr_debug("%s: Reporting release for reported " |
| 4867 | "button press %d\n", __func__, |
| 4868 | jack_type); |
| 4869 | tabla_snd_soc_jack_report(tabla, |
| 4870 | tabla->mbhc_cfg.button_jack, 0, |
| 4871 | tabla->buttons_pressed); |
| 4872 | tabla->buttons_pressed &= |
| 4873 | ~TABLA_JACK_BUTTON_MASK; |
| 4874 | } |
| 4875 | pr_debug("%s: Reporting removal %d\n", __func__, |
| 4876 | jack_type); |
| 4877 | tabla_snd_soc_jack_report(tabla, |
| 4878 | tabla->mbhc_cfg.headset_jack, |
| 4879 | tabla->hph_status, |
| 4880 | TABLA_JACK_MASK); |
| 4881 | } |
| 4882 | tabla_set_and_turnoff_hph_padac(codec); |
| 4883 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
| 4884 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 4885 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
| 4886 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 4887 | tabla->current_plug = PLUG_TYPE_NONE; |
| 4888 | tabla->mbhc_polling_active = false; |
| 4889 | } else { |
| 4890 | /* Report insertion */ |
| 4891 | tabla->hph_status |= jack_type; |
| 4892 | |
| 4893 | if (jack_type == SND_JACK_HEADPHONE) |
| 4894 | tabla->current_plug = PLUG_TYPE_HEADPHONE; |
| 4895 | else if (jack_type == SND_JACK_HEADSET) { |
| 4896 | tabla->mbhc_polling_active = true; |
| 4897 | tabla->current_plug = PLUG_TYPE_HEADSET; |
| 4898 | } |
| 4899 | if (tabla->mbhc_cfg.headset_jack) { |
| 4900 | pr_debug("%s: Reporting insertion %d\n", __func__, |
| 4901 | jack_type); |
| 4902 | tabla_snd_soc_jack_report(tabla, |
| 4903 | tabla->mbhc_cfg.headset_jack, |
| 4904 | tabla->hph_status, |
| 4905 | TABLA_JACK_MASK); |
| 4906 | } |
| 4907 | tabla_clr_and_turnon_hph_padac(tabla); |
| 4908 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4909 | } |
| 4910 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4911 | static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4912 | int insertion, int trigger, |
| 4913 | bool padac_off) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4914 | { |
| 4915 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4916 | int central_bias_enabled = 0; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4917 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4918 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4919 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4920 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4921 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4922 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4923 | pr_err("Error, no tabla calibration\n"); |
| 4924 | return -EINVAL; |
| 4925 | } |
| 4926 | |
| 4927 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 4928 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4929 | /* Make sure mic bias and Mic line schmitt trigger |
| 4930 | * are turned OFF |
| 4931 | */ |
| 4932 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 4933 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 4934 | |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4935 | if (insertion) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4936 | tabla_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4937 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4938 | /* DAPM can manipulate PA/DAC bits concurrently */ |
| 4939 | if (padac_off == true) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4940 | tabla_set_and_turnoff_hph_padac(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4941 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4942 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4943 | if (trigger & MBHC_USE_HPHL_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4944 | /* Enable HPH Schmitt Trigger */ |
| 4945 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11, |
| 4946 | 0x11); |
| 4947 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C, |
| 4948 | plug_det->hph_current << 2); |
| 4949 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02, |
| 4950 | 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4951 | } |
| 4952 | if (trigger & MBHC_USE_MB_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4953 | /* enable the mic line schmitt trigger */ |
| 4954 | snd_soc_update_bits(codec, |
| 4955 | tabla->mbhc_bias_regs.mbhc_reg, |
| 4956 | 0x60, plug_det->mic_current << 5); |
| 4957 | snd_soc_update_bits(codec, |
| 4958 | tabla->mbhc_bias_regs.mbhc_reg, |
| 4959 | 0x80, 0x80); |
| 4960 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
| 4961 | snd_soc_update_bits(codec, |
| 4962 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 4963 | 0x00); |
| 4964 | snd_soc_update_bits(codec, |
| 4965 | tabla->mbhc_bias_regs.mbhc_reg, |
| 4966 | 0x10, 0x10); |
| 4967 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4968 | |
| 4969 | /* setup for insetion detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4970 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4971 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4972 | pr_debug("setup for removal detection\n"); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4973 | /* Make sure the HPH schmitt trigger is OFF */ |
| 4974 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00); |
| 4975 | |
| 4976 | /* enable the mic line schmitt trigger */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 4977 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 4978 | 0x01, 0x00); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4979 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4980 | plug_det->mic_current << 5); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4981 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 4982 | 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4983 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4984 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 4985 | 0x10, 0x10); |
| 4986 | |
| 4987 | /* Setup for low power removal detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4988 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x2, 0x2); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 4989 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4990 | |
| 4991 | if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4992 | /* called called by interrupt */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4993 | if (!(tabla->clock_active)) { |
| 4994 | tabla_codec_enable_config_mode(codec, 1); |
| 4995 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4996 | 0x06, 0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4997 | usleep_range(generic->t_shutdown_plug_rem, |
| 4998 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4999 | tabla_codec_enable_config_mode(codec, 0); |
| 5000 | } else |
| 5001 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5002 | 0x06, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5003 | } |
| 5004 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 5005 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.int_rbias, 0x80, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5006 | |
| 5007 | /* If central bandgap disabled */ |
| 5008 | if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) { |
| 5009 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5010 | usleep_range(generic->t_bg_fast_settle, |
| 5011 | generic->t_bg_fast_settle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5012 | central_bias_enabled = 1; |
| 5013 | } |
| 5014 | |
| 5015 | /* If LDO_H disabled */ |
| 5016 | if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) { |
| 5017 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0); |
| 5018 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5019 | usleep_range(generic->t_ldoh, generic->t_ldoh); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5020 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0); |
| 5021 | |
| 5022 | if (central_bias_enabled) |
| 5023 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0); |
| 5024 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5025 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 5026 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5027 | tabla->mbhc_cfg.micbias); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5028 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5029 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5030 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1); |
| 5031 | return 0; |
| 5032 | } |
| 5033 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5034 | static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 5035 | s16 vin_mv) |
| 5036 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5037 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5038 | s16 diff, zero; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5039 | u32 mb_mv, in; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5040 | u16 value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5041 | |
| 5042 | tabla = snd_soc_codec_get_drvdata(codec); |
| 5043 | mb_mv = tabla->mbhc_data.micb_mv; |
| 5044 | |
| 5045 | if (mb_mv == 0) { |
| 5046 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 5047 | return -EINVAL; |
| 5048 | } |
| 5049 | |
| 5050 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5051 | diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z); |
| 5052 | zero = (tabla->mbhc_data.dce_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5053 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5054 | diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z); |
| 5055 | zero = (tabla->mbhc_data.sta_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5056 | } |
| 5057 | in = (u32) diff * vin_mv; |
| 5058 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5059 | value = (u16) (in / mb_mv) + zero; |
| 5060 | return value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 5064 | u16 bias_value) |
| 5065 | { |
| 5066 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5067 | s16 value, z, mb; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5068 | s32 mv; |
| 5069 | |
| 5070 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5071 | value = bias_value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5072 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5073 | z = (tabla->mbhc_data.dce_z); |
| 5074 | mb = (tabla->mbhc_data.dce_mb); |
| 5075 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5076 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5077 | z = (tabla->mbhc_data.sta_z); |
| 5078 | mb = (tabla->mbhc_data.sta_mb); |
| 5079 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | return mv; |
| 5083 | } |
| 5084 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5085 | static void btn_lpress_fn(struct work_struct *work) |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5086 | { |
| 5087 | struct delayed_work *delayed_work; |
| 5088 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5089 | short bias_value; |
| 5090 | int dce_mv, sta_mv; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5091 | struct wcd9xxx *core; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5092 | |
| 5093 | pr_debug("%s:\n", __func__); |
| 5094 | |
| 5095 | delayed_work = to_delayed_work(work); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5096 | tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5097 | core = dev_get_drvdata(tabla->codec->dev->parent); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5098 | |
| 5099 | if (tabla) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5100 | if (tabla->mbhc_cfg.button_jack) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5101 | bias_value = tabla_codec_read_sta_result(tabla->codec); |
| 5102 | sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5103 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5104 | bias_value = tabla_codec_read_dce_result(tabla->codec); |
| 5105 | dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5106 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5107 | pr_debug("%s: Reporting long button press event" |
| 5108 | " STA: %d, DCE: %d\n", __func__, |
| 5109 | sta_mv, dce_mv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5110 | tabla_snd_soc_jack_report(tabla, |
| 5111 | tabla->mbhc_cfg.button_jack, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5112 | tabla->buttons_pressed, |
| 5113 | tabla->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5114 | } |
| 5115 | } else { |
| 5116 | pr_err("%s: Bad tabla private data\n", __func__); |
| 5117 | } |
| 5118 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5119 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5120 | wcd9xxx_unlock_sleep(core); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5121 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 5122 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5123 | void tabla_mbhc_cal(struct snd_soc_codec *codec) |
| 5124 | { |
| 5125 | struct tabla_priv *tabla; |
| 5126 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5127 | u8 cfilt_mode, bg_mode; |
| 5128 | u8 ncic, nmeas, navg; |
| 5129 | u32 mclk_rate; |
| 5130 | u32 dce_wait, sta_wait; |
| 5131 | u8 *n_cic; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5132 | void *calibration; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5133 | |
| 5134 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5135 | calibration = tabla->mbhc_cfg.calibration; |
| 5136 | |
| 5137 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 5138 | tabla_turn_onoff_rel_detection(codec, false); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5139 | |
| 5140 | /* First compute the DCE / STA wait times |
| 5141 | * depending on tunable parameters. |
| 5142 | * The value is computed in microseconds |
| 5143 | */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5144 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5145 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
Joonwoo Park | 107edf0 | 2012-01-11 11:42:24 -0800 | [diff] [blame] | 5146 | ncic = n_cic[tabla_codec_mclk_index(tabla)]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5147 | nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 5148 | navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 5149 | mclk_rate = tabla->mbhc_cfg.mclk_rate; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 5150 | dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000); |
| 5151 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5152 | |
| 5153 | tabla->mbhc_data.t_dce = dce_wait; |
| 5154 | tabla->mbhc_data.t_sta = sta_wait; |
| 5155 | |
| 5156 | /* LDOH and CFILT are already configured during pdata handling. |
| 5157 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 5158 | * Need to restore defaults once calculation is done. |
| 5159 | */ |
| 5160 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
| 5161 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, 0x00); |
| 5162 | bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 5163 | 0x02); |
| 5164 | |
| 5165 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 5166 | * to perform ADC calibration |
| 5167 | */ |
| 5168 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5169 | tabla->mbhc_cfg.micbias << 5); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5170 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 5171 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60); |
| 5172 | snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78); |
| 5173 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 5174 | |
| 5175 | /* DCE measurement for 0 volts */ |
| 5176 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5177 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5178 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5179 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5180 | usleep_range(100, 100); |
| 5181 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5182 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5183 | tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec); |
| 5184 | |
| 5185 | /* DCE measurment for MB voltage */ |
| 5186 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5187 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
| 5188 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5189 | usleep_range(100, 100); |
| 5190 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5191 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5192 | tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec); |
| 5193 | |
| 5194 | /* Sta measuremnt for 0 volts */ |
| 5195 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5196 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5197 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5198 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5199 | usleep_range(100, 100); |
| 5200 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5201 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5202 | tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec); |
| 5203 | |
| 5204 | /* STA Measurement for MB Voltage */ |
| 5205 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5206 | usleep_range(100, 100); |
| 5207 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5208 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5209 | tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec); |
| 5210 | |
| 5211 | /* Restore default settings. */ |
| 5212 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 5213 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5214 | cfilt_mode); |
| 5215 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 5216 | |
| 5217 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 5218 | usleep_range(100, 100); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5219 | |
| 5220 | wcd9xxx_enable_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL); |
| 5221 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det, |
| 5225 | const enum tabla_mbhc_btn_det_mem mem) |
| 5226 | { |
| 5227 | void *ret = &btn_det->_v_btn_low; |
| 5228 | |
| 5229 | switch (mem) { |
| 5230 | case TABLA_BTN_DET_GAIN: |
| 5231 | ret += sizeof(btn_det->_n_cic); |
| 5232 | case TABLA_BTN_DET_N_CIC: |
| 5233 | ret += sizeof(btn_det->_n_ready); |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5234 | case TABLA_BTN_DET_N_READY: |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5235 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 5236 | case TABLA_BTN_DET_V_BTN_HIGH: |
| 5237 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 5238 | case TABLA_BTN_DET_V_BTN_LOW: |
| 5239 | /* do nothing */ |
| 5240 | break; |
| 5241 | default: |
| 5242 | ret = NULL; |
| 5243 | } |
| 5244 | |
| 5245 | return ret; |
| 5246 | } |
| 5247 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5248 | static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v, |
| 5249 | bool tovddio) |
| 5250 | { |
| 5251 | int r; |
| 5252 | int vddio_k, mb_k; |
| 5253 | vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 5254 | VDDIO_MICBIAS_MV); |
| 5255 | mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 5256 | tabla->mbhc_data.micb_mv); |
| 5257 | if (tovddio) |
| 5258 | r = v * vddio_k / mb_k; |
| 5259 | else |
| 5260 | r = v * mb_k / vddio_k; |
| 5261 | return r; |
| 5262 | } |
| 5263 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5264 | static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 5265 | { |
| 5266 | struct tabla_priv *tabla; |
| 5267 | s16 btn_mv = 0, btn_delta_mv; |
| 5268 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5269 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 5270 | u16 *btn_high; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5271 | u8 *n_ready; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5272 | int i; |
| 5273 | |
| 5274 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5275 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 5276 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5277 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5278 | n_ready = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_READY); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5279 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5280 | tabla->mbhc_data.npoll = 4; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5281 | tabla->mbhc_data.nbounce_wait = 30; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5282 | } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5283 | tabla->mbhc_data.npoll = 7; |
| 5284 | tabla->mbhc_data.nbounce_wait = 23; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5285 | } |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5286 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5287 | tabla->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 5288 | (tabla->mbhc_cfg.mclk_rate / 1000) * |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 5289 | n_ready[tabla_codec_mclk_index(tabla)]) + |
| 5290 | 10; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5291 | tabla->mbhc_data.v_ins_hu = |
| 5292 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 5293 | tabla->mbhc_data.v_ins_h = |
| 5294 | tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 5295 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5296 | tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW; |
| 5297 | if (tabla->mbhc_cfg.gpio) |
| 5298 | tabla->mbhc_data.v_inval_ins_high = |
| 5299 | TABLA_MBHC_FAKE_INSERT_HIGH; |
| 5300 | else |
| 5301 | tabla->mbhc_data.v_inval_ins_high = |
| 5302 | TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO; |
| 5303 | |
| 5304 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 5305 | tabla->mbhc_data.adj_v_hs_max = |
| 5306 | tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true); |
| 5307 | tabla->mbhc_data.adj_v_ins_hu = |
| 5308 | tabla_codec_v_sta_dce(codec, STA, |
| 5309 | tabla->mbhc_data.adj_v_hs_max); |
| 5310 | tabla->mbhc_data.adj_v_ins_h = |
| 5311 | tabla_codec_v_sta_dce(codec, DCE, |
| 5312 | tabla->mbhc_data.adj_v_hs_max); |
| 5313 | tabla->mbhc_data.v_inval_ins_low = |
| 5314 | tabla_scale_v_micb_vddio(tabla, |
| 5315 | tabla->mbhc_data.v_inval_ins_low, |
| 5316 | false); |
| 5317 | tabla->mbhc_data.v_inval_ins_high = |
| 5318 | tabla_scale_v_micb_vddio(tabla, |
| 5319 | tabla->mbhc_data.v_inval_ins_high, |
| 5320 | false); |
| 5321 | } |
| 5322 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5323 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH); |
| 5324 | for (i = 0; i < btn_det->num_btn; i++) |
| 5325 | btn_mv = btn_high[i] > btn_mv ? btn_high[i] : btn_mv; |
| 5326 | |
| 5327 | tabla->mbhc_data.v_b1_h = tabla_codec_v_sta_dce(codec, DCE, btn_mv); |
| 5328 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_sta; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5329 | tabla->mbhc_data.v_b1_hu = |
| 5330 | tabla_codec_v_sta_dce(codec, STA, btn_delta_mv); |
| 5331 | |
| 5332 | btn_delta_mv = btn_mv + btn_det->v_btn_press_delta_cic; |
| 5333 | |
| 5334 | tabla->mbhc_data.v_b1_huc = |
| 5335 | tabla_codec_v_sta_dce(codec, DCE, btn_delta_mv); |
| 5336 | |
| 5337 | tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5338 | tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5339 | |
| 5340 | tabla->mbhc_data.v_no_mic = |
| 5341 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 5342 | } |
| 5343 | |
| 5344 | void tabla_mbhc_init(struct snd_soc_codec *codec) |
| 5345 | { |
| 5346 | struct tabla_priv *tabla; |
| 5347 | struct tabla_mbhc_general_cfg *generic; |
| 5348 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5349 | int n; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5350 | u8 *n_cic, *gain; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5351 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5352 | |
| 5353 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5354 | generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
| 5355 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5356 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5357 | for (n = 0; n < 8; n++) { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 5358 | if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5359 | snd_soc_update_bits(codec, |
| 5360 | TABLA_A_CDC_MBHC_FEATURE_B1_CFG, |
| 5361 | 0x07, n); |
| 5362 | snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG, |
| 5363 | btn_det->c[n]); |
| 5364 | } |
| 5365 | } |
| 5366 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07, |
| 5367 | btn_det->nc); |
| 5368 | |
| 5369 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
| 5370 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, 0xFF, |
Joonwoo Park | 107edf0 | 2012-01-11 11:42:24 -0800 | [diff] [blame] | 5371 | n_cic[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5372 | |
| 5373 | gain = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_GAIN); |
Joonwoo Park | 107edf0 | 2012-01-11 11:42:24 -0800 | [diff] [blame] | 5374 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78, |
| 5375 | gain[tabla_codec_mclk_index(tabla)] << 3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5376 | |
| 5377 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 5378 | generic->mbhc_nsa << 4); |
| 5379 | |
| 5380 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 5381 | btn_det->n_meas); |
| 5382 | |
| 5383 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 5384 | |
| 5385 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 5386 | |
| 5387 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78, |
| 5388 | btn_det->mbhc_nsc << 3); |
| 5389 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 5390 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03, |
| 5391 | TABLA_MICBIAS2); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5392 | |
| 5393 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5394 | |
| 5395 | snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5396 | } |
| 5397 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 5398 | static bool tabla_mbhc_fw_validate(const struct firmware *fw) |
| 5399 | { |
| 5400 | u32 cfg_offset; |
| 5401 | struct tabla_mbhc_imped_detect_cfg *imped_cfg; |
| 5402 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 5403 | |
| 5404 | if (fw->size < TABLA_MBHC_CAL_MIN_SIZE) |
| 5405 | return false; |
| 5406 | |
| 5407 | /* previous check guarantees that there is enough fw data up |
| 5408 | * to num_btn |
| 5409 | */ |
| 5410 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 5411 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 5412 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 5413 | return false; |
| 5414 | |
| 5415 | /* previous check guarantees that there is enough fw data up |
| 5416 | * to start of impedance detection configuration |
| 5417 | */ |
| 5418 | imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 5419 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 5420 | |
| 5421 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ)) |
| 5422 | return false; |
| 5423 | |
| 5424 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 5425 | return false; |
| 5426 | |
| 5427 | return true; |
| 5428 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5429 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5430 | static int tabla_determine_button(const struct tabla_priv *priv, |
| 5431 | const s32 bias_mv) |
| 5432 | { |
| 5433 | s16 *v_btn_low, *v_btn_high; |
| 5434 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 5435 | int i, btn = -1; |
| 5436 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5437 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5438 | v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW); |
| 5439 | v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5440 | TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5441 | for (i = 0; i < btn_det->num_btn; i++) { |
| 5442 | if ((v_btn_low[i] <= bias_mv) && (v_btn_high[i] >= bias_mv)) { |
| 5443 | btn = i; |
| 5444 | break; |
| 5445 | } |
| 5446 | } |
| 5447 | |
| 5448 | if (btn == -1) |
| 5449 | pr_debug("%s: couldn't find button number for mic mv %d\n", |
| 5450 | __func__, bias_mv); |
| 5451 | |
| 5452 | return btn; |
| 5453 | } |
| 5454 | |
| 5455 | static int tabla_get_button_mask(const int btn) |
| 5456 | { |
| 5457 | int mask = 0; |
| 5458 | switch (btn) { |
| 5459 | case 0: |
| 5460 | mask = SND_JACK_BTN_0; |
| 5461 | break; |
| 5462 | case 1: |
| 5463 | mask = SND_JACK_BTN_1; |
| 5464 | break; |
| 5465 | case 2: |
| 5466 | mask = SND_JACK_BTN_2; |
| 5467 | break; |
| 5468 | case 3: |
| 5469 | mask = SND_JACK_BTN_3; |
| 5470 | break; |
| 5471 | case 4: |
| 5472 | mask = SND_JACK_BTN_4; |
| 5473 | break; |
| 5474 | case 5: |
| 5475 | mask = SND_JACK_BTN_5; |
| 5476 | break; |
| 5477 | case 6: |
| 5478 | mask = SND_JACK_BTN_6; |
| 5479 | break; |
| 5480 | case 7: |
| 5481 | mask = SND_JACK_BTN_7; |
| 5482 | break; |
| 5483 | } |
| 5484 | return mask; |
| 5485 | } |
| 5486 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5487 | static irqreturn_t tabla_dce_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5488 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5489 | int i, mask; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5490 | short dce, sta, bias_value_dce; |
| 5491 | s32 mv, stamv, bias_mv_dce; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5492 | int btn = -1, meas = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5493 | struct tabla_priv *priv = data; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5494 | const struct tabla_mbhc_btn_detect_cfg *d = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5495 | TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5496 | short btnmeas[d->n_btn_meas + 1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5497 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5498 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5499 | int n_btn_meas = d->n_btn_meas; |
| 5500 | u8 mbhc_status = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_STATUS) & 0x3E; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5501 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5502 | pr_debug("%s: enter\n", __func__); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5503 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5504 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 5505 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 5506 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 5507 | __func__); |
| 5508 | goto done; |
| 5509 | } |
| 5510 | |
| 5511 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 5512 | |
| 5513 | if (!priv->mbhc_polling_active) { |
| 5514 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 5515 | __func__); |
| 5516 | goto done; |
| 5517 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5518 | |
| 5519 | dce = tabla_codec_read_dce_result(codec); |
| 5520 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 5521 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5522 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 5523 | if (priv->in_gpio_handler) { |
| 5524 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 5525 | __func__); |
| 5526 | btn = -1; |
| 5527 | goto done; |
| 5528 | } |
| 5529 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5530 | if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) { |
| 5531 | if (priv->mbhc_last_resume && |
| 5532 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 5533 | pr_debug("%s: Button is already released shortly after " |
| 5534 | "resume\n", __func__); |
| 5535 | n_btn_meas = 0; |
| 5536 | } else { |
| 5537 | pr_debug("%s: Button is already released without " |
| 5538 | "resume", __func__); |
| 5539 | sta = tabla_codec_read_sta_result(codec); |
| 5540 | stamv = tabla_codec_sta_dce_v(codec, 0, sta); |
| 5541 | btn = tabla_determine_button(priv, mv); |
| 5542 | if (btn != tabla_determine_button(priv, stamv)) |
| 5543 | btn = -1; |
| 5544 | goto done; |
| 5545 | } |
| 5546 | } |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5547 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5548 | /* determine pressed button */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5549 | btnmeas[meas++] = tabla_determine_button(priv, mv); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5550 | pr_debug("%s: meas %d - DCE %d,%d, button %d\n", __func__, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5551 | meas - 1, dce, mv, btnmeas[meas - 1]); |
| 5552 | if (n_btn_meas == 0) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5553 | btn = btnmeas[0]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5554 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
| 5555 | bias_value_dce = tabla_codec_sta_dce(codec, 1, false); |
| 5556 | bias_mv_dce = tabla_codec_sta_dce_v(codec, 1, bias_value_dce); |
| 5557 | btnmeas[meas] = tabla_determine_button(priv, bias_mv_dce); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5558 | pr_debug("%s: meas %d - DCE %d,%d, button %d\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5559 | __func__, meas, bias_value_dce, bias_mv_dce, |
| 5560 | btnmeas[meas]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5561 | /* if large enough measurements are collected, |
| 5562 | * start to check if last all n_btn_con measurements were |
| 5563 | * in same button low/high range */ |
| 5564 | if (meas + 1 >= d->n_btn_con) { |
| 5565 | for (i = 0; i < d->n_btn_con; i++) |
| 5566 | if ((btnmeas[meas] < 0) || |
| 5567 | (btnmeas[meas] != btnmeas[meas - i])) |
| 5568 | break; |
| 5569 | if (i == d->n_btn_con) { |
| 5570 | /* button pressed */ |
| 5571 | btn = btnmeas[meas]; |
| 5572 | break; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5573 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 5574 | /* if left measurements are less than n_btn_con, |
| 5575 | * it's impossible to find button number */ |
| 5576 | break; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5577 | } |
| 5578 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 5579 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5580 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5581 | if (btn >= 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5582 | if (priv->in_gpio_handler) { |
| 5583 | pr_debug("%s: GPIO already triggered, ignore button " |
| 5584 | "press\n", __func__); |
| 5585 | goto done; |
| 5586 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5587 | mask = tabla_get_button_mask(btn); |
| 5588 | priv->buttons_pressed |= mask; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5589 | wcd9xxx_lock_sleep(core); |
| 5590 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 5591 | msecs_to_jiffies(400)) == 0) { |
| 5592 | WARN(1, "Button pressed twice without release" |
| 5593 | "event\n"); |
| 5594 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5595 | } |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5596 | } else { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5597 | pr_debug("%s: bogus button press, too short press?\n", |
| 5598 | __func__); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5599 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5600 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5601 | done: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5602 | pr_debug("%s: leave\n", __func__); |
| 5603 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5604 | return IRQ_HANDLED; |
| 5605 | } |
| 5606 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5607 | static int tabla_is_fake_press(struct tabla_priv *priv) |
| 5608 | { |
| 5609 | int i; |
| 5610 | int r = 0; |
| 5611 | struct snd_soc_codec *codec = priv->codec; |
| 5612 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5613 | s16 mb_v, v_ins_hu, v_ins_h; |
| 5614 | |
| 5615 | v_ins_hu = tabla_get_current_v_ins(priv, true); |
| 5616 | v_ins_h = tabla_get_current_v_ins(priv, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5617 | |
| 5618 | for (i = 0; i < dces; i++) { |
| 5619 | usleep_range(10000, 10000); |
| 5620 | if (i == 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5621 | mb_v = tabla_codec_sta_dce(codec, 0, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5622 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 5623 | tabla_codec_sta_dce_v(codec, 0, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5624 | if (mb_v < (s16)priv->mbhc_data.v_b1_hu || |
| 5625 | mb_v > v_ins_hu) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5626 | r = 1; |
| 5627 | break; |
| 5628 | } |
| 5629 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5630 | mb_v = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5631 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 5632 | tabla_codec_sta_dce_v(codec, 1, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5633 | if (mb_v < (s16)priv->mbhc_data.v_b1_h || |
| 5634 | mb_v > v_ins_h) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5635 | r = 1; |
| 5636 | break; |
| 5637 | } |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | return r; |
| 5642 | } |
| 5643 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5644 | static irqreturn_t tabla_release_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5645 | { |
Joonwoo Park | e5d3aa9 | 2012-01-11 14:47:15 -0800 | [diff] [blame] | 5646 | int ret; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5647 | struct tabla_priv *priv = data; |
| 5648 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5649 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5650 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5651 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5652 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 5653 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5654 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5655 | tabla_codec_drive_v_to_micbias(codec, 10000); |
| 5656 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5657 | if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5658 | ret = tabla_cancel_btn_work(priv); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5659 | if (ret == 0) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5660 | pr_debug("%s: Reporting long button release event\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5661 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5662 | if (priv->mbhc_cfg.button_jack) |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 5663 | tabla_snd_soc_jack_report(priv, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5664 | priv->mbhc_cfg.button_jack, 0, |
| 5665 | priv->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5666 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5667 | if (tabla_is_fake_press(priv)) { |
| 5668 | pr_debug("%s: Fake button press interrupt\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5669 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5670 | } else if (priv->mbhc_cfg.button_jack) { |
| 5671 | if (priv->in_gpio_handler) { |
| 5672 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 5673 | __func__); |
| 5674 | } else { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5675 | pr_debug("%s: Reporting short button " |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5676 | "press and release\n", |
| 5677 | __func__); |
| 5678 | tabla_snd_soc_jack_report(priv, |
| 5679 | priv->mbhc_cfg.button_jack, |
| 5680 | priv->buttons_pressed, |
| 5681 | priv->buttons_pressed); |
| 5682 | tabla_snd_soc_jack_report(priv, |
| 5683 | priv->mbhc_cfg.button_jack, 0, |
| 5684 | priv->buttons_pressed); |
| 5685 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5686 | } |
| 5687 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5688 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 5689 | priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK; |
| 5690 | } |
| 5691 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5692 | tabla_codec_calibrate_hs_polling(codec); |
| 5693 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5694 | if (priv->mbhc_cfg.gpio) |
| 5695 | msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5696 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5697 | tabla_codec_start_hs_polling(codec); |
| 5698 | |
| 5699 | pr_debug("%s: leave\n", __func__); |
| 5700 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5701 | return IRQ_HANDLED; |
| 5702 | } |
| 5703 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5704 | static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 5705 | { |
| 5706 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5707 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5708 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5709 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5710 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5711 | tabla_codec_enable_config_mode(codec, 1); |
| 5712 | |
| 5713 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 5714 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x6, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5715 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5716 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 5717 | |
| 5718 | usleep_range(generic->t_shutdown_plug_rem, |
| 5719 | generic->t_shutdown_plug_rem); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5720 | |
| 5721 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0xA, 0x8); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5722 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5723 | tabla_codec_enable_config_mode(codec, 0); |
| 5724 | |
| 5725 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00); |
| 5726 | } |
| 5727 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5728 | static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5729 | { |
| 5730 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5731 | |
| 5732 | tabla_codec_shutdown_hs_removal_detect(codec); |
| 5733 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5734 | if (!tabla->mclk_enabled) { |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 5735 | tabla_codec_disable_clock_block(codec); |
| 5736 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5737 | } |
| 5738 | |
| 5739 | tabla->mbhc_polling_active = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5740 | tabla->mbhc_state = MBHC_STATE_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5741 | } |
| 5742 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 5743 | static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data) |
| 5744 | { |
| 5745 | struct tabla_priv *tabla = data; |
| 5746 | struct snd_soc_codec *codec; |
| 5747 | |
| 5748 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 5749 | |
| 5750 | if (tabla) { |
| 5751 | codec = tabla->codec; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5752 | if (tabla->hphlocp_cnt++ < TABLA_OCP_ATTEMPT) { |
| 5753 | pr_info("%s: retry\n", __func__); |
| 5754 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 5755 | 0x00); |
| 5756 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 5757 | 0x10); |
| 5758 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5759 | wcd9xxx_disable_irq(codec->control_data, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5760 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 5761 | tabla->hphlocp_cnt = 0; |
| 5762 | tabla->hph_status |= SND_JACK_OC_HPHL; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5763 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5764 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5765 | tabla->mbhc_cfg.headset_jack, |
| 5766 | tabla->hph_status, |
| 5767 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 5768 | } |
| 5769 | } else { |
| 5770 | pr_err("%s: Bad tabla private data\n", __func__); |
| 5771 | } |
| 5772 | |
| 5773 | return IRQ_HANDLED; |
| 5774 | } |
| 5775 | |
| 5776 | static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data) |
| 5777 | { |
| 5778 | struct tabla_priv *tabla = data; |
| 5779 | struct snd_soc_codec *codec; |
| 5780 | |
| 5781 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 5782 | |
| 5783 | if (tabla) { |
| 5784 | codec = tabla->codec; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5785 | if (tabla->hphrocp_cnt++ < TABLA_OCP_ATTEMPT) { |
| 5786 | pr_info("%s: retry\n", __func__); |
| 5787 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 5788 | 0x00); |
| 5789 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 5790 | 0x10); |
| 5791 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5792 | wcd9xxx_disable_irq(codec->control_data, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5793 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 5794 | tabla->hphrocp_cnt = 0; |
| 5795 | tabla->hph_status |= SND_JACK_OC_HPHR; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5796 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 5797 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5798 | tabla->mbhc_cfg.headset_jack, |
| 5799 | tabla->hph_status, |
| 5800 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 5801 | } |
| 5802 | } else { |
| 5803 | pr_err("%s: Bad tabla private data\n", __func__); |
| 5804 | } |
| 5805 | |
| 5806 | return IRQ_HANDLED; |
| 5807 | } |
| 5808 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5809 | static bool tabla_is_invalid_insertion_range(struct snd_soc_codec *codec, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 5810 | s32 mic_volt, bool highhph) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5811 | { |
| 5812 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5813 | bool invalid = false; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5814 | s16 v_hs_max; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5815 | |
| 5816 | /* Perform this check only when the high voltage headphone |
| 5817 | * needs to be considered as invalid |
| 5818 | */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5819 | v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 5820 | if (!highhph && (mic_volt > v_hs_max)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5821 | invalid = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5822 | else if (mic_volt < tabla->mbhc_data.v_inval_ins_high && |
| 5823 | (mic_volt > tabla->mbhc_data.v_inval_ins_low)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5824 | invalid = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5825 | |
| 5826 | return invalid; |
| 5827 | } |
| 5828 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5829 | static bool tabla_is_inval_insert_delta(struct snd_soc_codec *codec, |
| 5830 | int mic_volt, int mic_volt_prev, |
| 5831 | int threshold) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5832 | { |
| 5833 | int delta = abs(mic_volt - mic_volt_prev); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5834 | if (delta > threshold) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5835 | pr_debug("%s: volt delta %dmv\n", __func__, delta); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5836 | return true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5837 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5838 | return false; |
| 5839 | } |
| 5840 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5841 | /* called under codec_resource_lock acquisition */ |
| 5842 | void tabla_find_plug_and_report(struct snd_soc_codec *codec, |
| 5843 | enum tabla_mbhc_plug_type plug_type) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5844 | { |
| 5845 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5846 | |
| 5847 | if (plug_type == PLUG_TYPE_HEADPHONE |
| 5848 | && tabla->current_plug == PLUG_TYPE_NONE) { |
| 5849 | /* Nothing was reported previously |
| 5850 | * reporte a headphone |
| 5851 | */ |
| 5852 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 5853 | tabla_codec_cleanup_hs_polling(codec); |
| 5854 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 5855 | /* If Headphone was reported previously, this will |
| 5856 | * only report the mic line |
| 5857 | */ |
| 5858 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 5859 | msleep(100); |
| 5860 | tabla_codec_start_hs_polling(codec); |
| 5861 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
| 5862 | if (tabla->current_plug == PLUG_TYPE_NONE) |
| 5863 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 5864 | tabla_codec_cleanup_hs_polling(codec); |
| 5865 | pr_debug("setup mic trigger for further detection\n"); |
| 5866 | tabla->lpi_enabled = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5867 | tabla_codec_enable_hs_detect(codec, 1, |
| 5868 | MBHC_USE_MB_TRIGGER | |
| 5869 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5870 | false); |
| 5871 | } |
| 5872 | } |
| 5873 | |
| 5874 | /* should be called under interrupt context that hold suspend */ |
| 5875 | static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla) |
| 5876 | { |
| 5877 | pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__); |
| 5878 | tabla->hs_detect_work_stop = false; |
| 5879 | wcd9xxx_lock_sleep(tabla->codec->control_data); |
| 5880 | schedule_work(&tabla->hs_correct_plug_work); |
| 5881 | } |
| 5882 | |
| 5883 | /* called under codec_resource_lock acquisition */ |
| 5884 | static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla) |
| 5885 | { |
| 5886 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 5887 | tabla->hs_detect_work_stop = true; |
| 5888 | wmb(); |
| 5889 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 5890 | if (cancel_work_sync(&tabla->hs_correct_plug_work)) { |
| 5891 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 5892 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 5893 | } |
| 5894 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 5895 | } |
| 5896 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5897 | static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla) |
| 5898 | { |
| 5899 | return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) != |
| 5900 | tabla->mbhc_cfg.gpio_level_insert); |
| 5901 | } |
| 5902 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 5903 | /* called under codec_resource_lock acquisition */ |
| 5904 | static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on) |
| 5905 | { |
| 5906 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on); |
| 5907 | if (on) |
| 5908 | usleep_range(5000, 5000); |
| 5909 | } |
| 5910 | |
| 5911 | /* called under codec_resource_lock acquisition and mbhc override = 1 */ |
| 5912 | static enum tabla_mbhc_plug_type |
| 5913 | tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph) |
| 5914 | { |
| 5915 | int i; |
| 5916 | bool gndswitch, vddioswitch; |
| 5917 | int scaled; |
| 5918 | struct tabla_mbhc_plug_type_cfg *plug_type_ptr; |
| 5919 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5920 | const bool vddio = (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV); |
| 5921 | int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio); |
| 5922 | enum tabla_mbhc_plug_type plug_type[num_det]; |
| 5923 | s16 mb_v[num_det]; |
| 5924 | s32 mic_mv[num_det]; |
| 5925 | bool inval = false; |
| 5926 | |
| 5927 | /* make sure override is on */ |
| 5928 | WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04)); |
| 5929 | |
| 5930 | /* performs DCEs for N times |
| 5931 | * 1st: check if voltage is in invalid range |
| 5932 | * 2nd - N-2nd: check voltage range and delta |
| 5933 | * N-1st: check voltage range, delta with HPHR GND switch |
| 5934 | * Nth: check voltage range with VDDIO switch if micbias V != vddio V*/ |
| 5935 | for (i = 0; i < num_det && !inval; i++) { |
| 5936 | gndswitch = (i == (num_det - 1 - vddio)); |
| 5937 | vddioswitch = (vddio && (i == num_det - 1)); |
| 5938 | if (i == 0) { |
| 5939 | mb_v[i] = tabla_codec_setup_hs_polling(codec); |
| 5940 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 5941 | inval = tabla_is_invalid_insertion_range(codec, |
| 5942 | mic_mv[i], |
| 5943 | highhph); |
| 5944 | scaled = mic_mv[i]; |
| 5945 | } else if (vddioswitch) { |
| 5946 | __tabla_codec_switch_micbias(tabla->codec, 1, false, |
| 5947 | false); |
| 5948 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 5949 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 5950 | scaled = tabla_scale_v_micb_vddio(tabla, mic_mv[i], |
| 5951 | false); |
| 5952 | inval = (tabla_is_invalid_insertion_range(codec, |
| 5953 | mic_mv[i], |
| 5954 | highhph) || |
| 5955 | tabla_is_inval_insert_delta(codec, scaled, |
| 5956 | mic_mv[i - 1], |
| 5957 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV)); |
| 5958 | __tabla_codec_switch_micbias(tabla->codec, 0, false, |
| 5959 | false); |
| 5960 | } else { |
| 5961 | if (gndswitch) |
| 5962 | tabla_codec_hphr_gnd_switch(codec, true); |
| 5963 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 5964 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 5965 | inval = (tabla_is_invalid_insertion_range(codec, |
| 5966 | mic_mv[i], |
| 5967 | highhph) || |
| 5968 | tabla_is_inval_insert_delta(codec, mic_mv[i], |
| 5969 | mic_mv[i - 1], |
| 5970 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV)); |
| 5971 | if (gndswitch) |
| 5972 | tabla_codec_hphr_gnd_switch(codec, false); |
| 5973 | scaled = mic_mv[i]; |
| 5974 | } |
| 5975 | pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, " |
| 5976 | "invalid %d\n", __func__, |
| 5977 | i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch, |
| 5978 | inval); |
| 5979 | } |
| 5980 | |
| 5981 | plug_type_ptr = |
| 5982 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 5983 | plug_type[0] = PLUG_TYPE_INVALID; |
| 5984 | for (i = 0; !inval && i < num_det; i++) { |
| 5985 | /* |
| 5986 | * If we are here, means none of the all |
| 5987 | * measurements are fake, continue plug type detection. |
| 5988 | * If all three measurements do not produce same |
| 5989 | * plug type, restart insertion detection |
| 5990 | */ |
| 5991 | if (mic_mv[i] < plug_type_ptr->v_no_mic) { |
| 5992 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 5993 | pr_debug("%s: Detect attempt %d, detected Headphone\n", |
| 5994 | __func__, i); |
| 5995 | } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) { |
| 5996 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 5997 | pr_debug("%s: Detect attempt %d, detected High " |
| 5998 | "Headphone\n", __func__, i); |
| 5999 | } else { |
| 6000 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 6001 | pr_debug("%s: Detect attempt %d, detected Headset\n", |
| 6002 | __func__, i); |
| 6003 | } |
| 6004 | |
| 6005 | if (i > 0 && (plug_type[i - 1] != plug_type[i])) { |
| 6006 | pr_err("%s: Detect attempt %d and %d are not same", |
| 6007 | __func__, i - 1, i); |
| 6008 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6009 | inval = true; |
| 6010 | break; |
| 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | return plug_type[0]; |
| 6015 | } |
| 6016 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6017 | static void tabla_hs_correct_gpio_plug(struct work_struct *work) |
| 6018 | { |
| 6019 | struct tabla_priv *tabla; |
| 6020 | struct snd_soc_codec *codec; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6021 | int retry = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6022 | bool correction = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6023 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6024 | unsigned long timeout; |
| 6025 | |
| 6026 | tabla = container_of(work, struct tabla_priv, hs_correct_plug_work); |
| 6027 | codec = tabla->codec; |
| 6028 | |
| 6029 | pr_debug("%s: enter\n", __func__); |
| 6030 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 6031 | |
| 6032 | /* Keep override on during entire plug type correction work. |
| 6033 | * |
| 6034 | * This is okay under the assumption that any GPIO irqs which use |
| 6035 | * MBHC block cancel and sync this work so override is off again |
| 6036 | * prior to GPIO interrupt handler's MBHC block usage. |
| 6037 | * Also while this correction work is running, we can guarantee |
| 6038 | * DAPM doesn't use any MBHC block as this work only runs with |
| 6039 | * headphone detection. |
| 6040 | */ |
| 6041 | tabla_turn_onoff_override(codec, true); |
| 6042 | |
| 6043 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6044 | while (!time_after(jiffies, timeout)) { |
| 6045 | ++retry; |
| 6046 | rmb(); |
| 6047 | if (tabla->hs_detect_work_stop) { |
| 6048 | pr_debug("%s: stop requested\n", __func__); |
| 6049 | break; |
| 6050 | } |
| 6051 | |
| 6052 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 6053 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 6054 | pr_debug("%s: GPIO value is low\n", __func__); |
| 6055 | break; |
| 6056 | } |
| 6057 | |
| 6058 | /* can race with removal interrupt */ |
| 6059 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6060 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6061 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6062 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6063 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6064 | pr_debug("Invalid plug in attempt # %d\n", retry); |
| 6065 | if (retry == NUM_ATTEMPTS_TO_REPORT && |
| 6066 | tabla->current_plug == PLUG_TYPE_NONE) { |
| 6067 | tabla_codec_report_plug(codec, 1, |
| 6068 | SND_JACK_HEADPHONE); |
| 6069 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6070 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6071 | pr_debug("Good headphone detected, continue polling mic\n"); |
| 6072 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 6073 | tabla_codec_report_plug(codec, 1, |
| 6074 | SND_JACK_HEADPHONE); |
| 6075 | } |
| 6076 | } else { |
| 6077 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6078 | /* Turn off override */ |
| 6079 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6080 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6081 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6082 | pr_debug("Attempt %d found correct plug %d\n", retry, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6083 | plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6084 | correction = true; |
| 6085 | break; |
| 6086 | } |
| 6087 | } |
| 6088 | |
| 6089 | /* Turn off override */ |
| 6090 | if (!correction) |
| 6091 | tabla_turn_onoff_override(codec, false); |
| 6092 | |
| 6093 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 6094 | pr_debug("%s: leave\n", __func__); |
| 6095 | /* unlock sleep */ |
| 6096 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 6097 | } |
| 6098 | |
| 6099 | /* called under codec_resource_lock acquisition */ |
| 6100 | static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 6101 | { |
| 6102 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6103 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6104 | |
| 6105 | pr_debug("%s: enter\n", __func__); |
| 6106 | |
| 6107 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6108 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6109 | tabla_turn_onoff_override(codec, false); |
| 6110 | |
| 6111 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 6112 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 6113 | __func__); |
| 6114 | return; |
| 6115 | } |
| 6116 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6117 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6118 | tabla_schedule_hs_detect_plug(tabla); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6119 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6120 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6121 | |
| 6122 | tabla_schedule_hs_detect_plug(tabla); |
| 6123 | } else { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6124 | pr_debug("%s: Valid plug found, determine plug type %d\n", |
| 6125 | __func__, plug_type); |
| 6126 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6131 | static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 6132 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6133 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6134 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 6135 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
| 6136 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6137 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6138 | /* Turn on the override, |
| 6139 | * tabla_codec_setup_hs_polling requires override on */ |
| 6140 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6141 | |
| 6142 | if (plug_det->t_ins_complete > 20) |
| 6143 | msleep(plug_det->t_ins_complete); |
| 6144 | else |
| 6145 | usleep_range(plug_det->t_ins_complete * 1000, |
| 6146 | plug_det->t_ins_complete * 1000); |
| 6147 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6148 | if (tabla->mbhc_cfg.gpio) { |
| 6149 | /* Turn off the override */ |
| 6150 | tabla_turn_onoff_override(codec, false); |
| 6151 | if (tabla_hs_gpio_level_remove(tabla)) |
| 6152 | pr_debug("%s: GPIO value is low when determining " |
| 6153 | "plug\n", __func__); |
| 6154 | else |
| 6155 | tabla_codec_decide_gpio_plug(codec); |
| 6156 | return; |
| 6157 | } |
| 6158 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6159 | plug_type = tabla_codec_get_plug_type(codec, tabla->mbhc_cfg.gpio ? |
| 6160 | true : false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6161 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6162 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6163 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6164 | pr_debug("%s: Invalid plug type detected\n", __func__); |
| 6165 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
| 6166 | 0x02, 0x02); |
| 6167 | tabla_codec_cleanup_hs_polling(codec); |
| 6168 | tabla_codec_enable_hs_detect(codec, 1, |
| 6169 | MBHC_USE_MB_TRIGGER | |
| 6170 | MBHC_USE_HPHL_TRIGGER, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6171 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6172 | pr_debug("%s: Headphone Detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6173 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6174 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6175 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame^] | 6176 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6177 | pr_debug("%s: Headset detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6178 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 6179 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6180 | /* avoid false button press detect */ |
| 6181 | msleep(50); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6182 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6183 | } |
| 6184 | } |
| 6185 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6186 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6187 | static void tabla_hs_insert_irq_gpio(struct tabla_priv *priv, bool is_removal) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6188 | { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6189 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6190 | |
| 6191 | if (!is_removal) { |
| 6192 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
| 6193 | |
| 6194 | rmb(); |
| 6195 | if (priv->lpi_enabled) |
| 6196 | msleep(100); |
| 6197 | |
| 6198 | rmb(); |
| 6199 | if (!priv->lpi_enabled) { |
| 6200 | pr_debug("%s: lpi is disabled\n", __func__); |
| 6201 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 6202 | priv->mbhc_cfg.gpio_level_insert) { |
| 6203 | pr_debug("%s: Valid insertion, " |
| 6204 | "detect plug type\n", __func__); |
| 6205 | tabla_codec_decide_gpio_plug(codec); |
| 6206 | } else { |
| 6207 | pr_debug("%s: Invalid insertion, " |
| 6208 | "stop plug detection\n", __func__); |
| 6209 | } |
| 6210 | } else { |
| 6211 | pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__); |
| 6212 | } |
| 6213 | } |
| 6214 | |
| 6215 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6216 | static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal, |
| 6217 | bool is_mb_trigger) |
| 6218 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6219 | int ret; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6220 | struct snd_soc_codec *codec = priv->codec; |
| 6221 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6222 | |
| 6223 | if (is_removal) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6224 | /* cancel possiblely running hs detect work */ |
| 6225 | tabla_cancel_hs_detect_plug(priv); |
| 6226 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6227 | /* |
| 6228 | * If headphone is removed while playback is in progress, |
| 6229 | * it is possible that micbias will be switched to VDDIO. |
| 6230 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6231 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6232 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6233 | tabla_codec_shutdown_hs_removal_detect(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6234 | tabla_codec_enable_hs_detect(codec, 1, |
| 6235 | MBHC_USE_MB_TRIGGER | |
| 6236 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6237 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6238 | } else if (is_mb_trigger && !is_removal) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6239 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 6240 | __func__); |
| 6241 | wcd9xxx_lock_sleep(core); |
| 6242 | if (schedule_delayed_work(&priv->mbhc_insert_dwork, |
| 6243 | usecs_to_jiffies(1000000)) == 0) { |
| 6244 | pr_err("%s: mbhc_insert_dwork is already scheduled\n", |
| 6245 | __func__); |
| 6246 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 6247 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6248 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 6249 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6250 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6251 | ret = cancel_delayed_work(&priv->mbhc_insert_dwork); |
| 6252 | if (ret != 0) { |
| 6253 | pr_debug("%s: Complete plug insertion, Detecting plug " |
| 6254 | "type\n", __func__); |
| 6255 | tabla_codec_detect_plug_type(codec); |
| 6256 | wcd9xxx_unlock_sleep(core); |
| 6257 | } else { |
| 6258 | wcd9xxx_enable_irq(codec->control_data, |
| 6259 | TABLA_IRQ_MBHC_INSERTION); |
| 6260 | pr_err("%s: Error detecting plug insertion\n", |
| 6261 | __func__); |
| 6262 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6263 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6264 | } |
Bhalchandra Gajare | 9494fa26 | 2011-11-10 19:25:59 -0800 | [diff] [blame] | 6265 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6266 | static irqreturn_t tabla_hs_insert_irq(int irq, void *data) |
| 6267 | { |
| 6268 | bool is_mb_trigger, is_removal; |
| 6269 | struct tabla_priv *priv = data; |
| 6270 | struct snd_soc_codec *codec = priv->codec; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6271 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6272 | pr_debug("%s: enter\n", __func__); |
| 6273 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6274 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
| 6275 | |
| 6276 | is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) & |
| 6277 | 0x10); |
| 6278 | is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02); |
| 6279 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 6280 | |
| 6281 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 6282 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6283 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 6284 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6285 | |
| 6286 | if (priv->mbhc_cfg.gpio) |
| 6287 | tabla_hs_insert_irq_gpio(priv, is_removal); |
| 6288 | else |
| 6289 | tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger); |
| 6290 | |
| 6291 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6292 | return IRQ_HANDLED; |
| 6293 | } |
| 6294 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6295 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 6296 | { |
| 6297 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6298 | const struct tabla_mbhc_plug_type_cfg *plug_type = |
| 6299 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 6300 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6301 | |
| 6302 | return (!(mic_mv > 10 && mic_mv < 80) && (mic_mv > plug_type->v_no_mic) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6303 | && (mic_mv < v_hs_max)) ? true : false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
| 6306 | /* called under codec_resource_lock acquisition |
| 6307 | * returns true if mic voltage range is back to normal insertion |
| 6308 | * returns false either if timedout or removed */ |
| 6309 | static bool tabla_hs_remove_settle(struct snd_soc_codec *codec) |
| 6310 | { |
| 6311 | int i; |
| 6312 | bool timedout, settled = false; |
| 6313 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 6314 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 6315 | unsigned long retry = 0, timeout; |
| 6316 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6317 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6318 | |
| 6319 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6320 | while (!(timedout = time_after(jiffies, timeout))) { |
| 6321 | retry++; |
| 6322 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6323 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6324 | break; |
| 6325 | } |
| 6326 | |
| 6327 | if (tabla->mbhc_cfg.gpio) { |
| 6328 | if (retry > 1) |
| 6329 | msleep(250); |
| 6330 | else |
| 6331 | msleep(50); |
| 6332 | } |
| 6333 | |
| 6334 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6335 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6336 | break; |
| 6337 | } |
| 6338 | |
| 6339 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 6340 | mb_v[i] = tabla_codec_sta_dce(codec, 1, true); |
| 6341 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 6342 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 6343 | __func__, retry, mic_mv[i], mb_v[i]); |
| 6344 | } |
| 6345 | |
| 6346 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 6347 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 6348 | break; |
| 6349 | } |
| 6350 | |
| 6351 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 6352 | pr_debug("%s : headset/headphone is removed\n", |
| 6353 | __func__); |
| 6354 | break; |
| 6355 | } |
| 6356 | |
| 6357 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 6358 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 6359 | break; |
| 6360 | |
| 6361 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 6362 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 6363 | settled = true; |
| 6364 | msleep(200); |
| 6365 | break; |
| 6366 | } |
| 6367 | |
| 6368 | /* only for non-GPIO remove irq */ |
| 6369 | if (!tabla->mbhc_cfg.gpio) { |
| 6370 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6371 | if (mic_mv[i] < v_hs_max) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6372 | break; |
| 6373 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 6374 | pr_debug("%s: Headset is removed\n", __func__); |
| 6375 | break; |
| 6376 | } |
| 6377 | } |
| 6378 | } |
| 6379 | |
| 6380 | if (timedout) |
| 6381 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 6382 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6383 | return settled; |
| 6384 | } |
| 6385 | |
| 6386 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6387 | static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv) |
| 6388 | { |
| 6389 | struct snd_soc_codec *codec = priv->codec; |
| 6390 | |
| 6391 | if (tabla_hs_remove_settle(codec)) |
| 6392 | tabla_codec_start_hs_polling(codec); |
| 6393 | pr_debug("%s: remove settle done\n", __func__); |
| 6394 | } |
| 6395 | |
| 6396 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 6397 | static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6398 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6399 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6400 | bool removed = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6401 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6402 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6403 | TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6404 | int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6405 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6406 | if (priv->current_plug != PLUG_TYPE_HEADSET) { |
| 6407 | pr_debug("%s(): Headset is not inserted, ignore removal\n", |
| 6408 | __func__); |
| 6409 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 6410 | 0x08, 0x08); |
| 6411 | return; |
| 6412 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6413 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6414 | usleep_range(generic->t_shutdown_plug_rem, |
| 6415 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6416 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6417 | do { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6418 | bias_value = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6419 | pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value, |
| 6420 | tabla_codec_sta_dce_v(codec, 1, bias_value), min_us); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6421 | if (bias_value < tabla_get_current_v_ins(priv, false)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6422 | pr_debug("%s: checking false removal\n", __func__); |
| 6423 | msleep(500); |
| 6424 | removed = !tabla_hs_remove_settle(codec); |
| 6425 | pr_debug("%s: headset %sactually removed\n", __func__, |
| 6426 | removed ? "" : "not "); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6427 | break; |
| 6428 | } |
| 6429 | min_us -= priv->mbhc_data.t_dce; |
| 6430 | } while (min_us > 0); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 6431 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6432 | if (removed) { |
| 6433 | /* cancel possiblely running hs detect work */ |
| 6434 | tabla_cancel_hs_detect_plug(priv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6435 | /* |
| 6436 | * If this removal is not false, first check the micbias |
| 6437 | * switch status and switch it to LDOH if it is already |
| 6438 | * switched to VDDIO. |
| 6439 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6440 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6441 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6442 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 6443 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6444 | tabla_codec_enable_hs_detect(codec, 1, |
| 6445 | MBHC_USE_MB_TRIGGER | |
| 6446 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6447 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6448 | } else { |
| 6449 | tabla_codec_start_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6450 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6451 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6452 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6453 | static irqreturn_t tabla_hs_remove_irq(int irq, void *data) |
| 6454 | { |
| 6455 | struct tabla_priv *priv = data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6456 | bool vddio; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6457 | pr_debug("%s: enter, removal interrupt\n", __func__); |
| 6458 | |
| 6459 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6460 | vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 6461 | priv->mbhc_micbias_switched); |
| 6462 | if (vddio) |
| 6463 | __tabla_codec_switch_micbias(priv->codec, 0, false, true); |
| 6464 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6465 | if (priv->mbhc_cfg.gpio) |
| 6466 | tabla_hs_remove_irq_gpio(priv); |
| 6467 | else |
| 6468 | tabla_hs_remove_irq_nogpio(priv); |
| 6469 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6470 | /* if driver turned off vddio switch and headset is not removed, |
| 6471 | * turn on the vddio switch back, if headset is removed then vddio |
| 6472 | * switch is off by time now and shouldn't be turn on again from here */ |
| 6473 | if (vddio && priv->current_plug == PLUG_TYPE_HEADSET) |
| 6474 | __tabla_codec_switch_micbias(priv->codec, 1, true, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6475 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6476 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6477 | return IRQ_HANDLED; |
| 6478 | } |
| 6479 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6480 | void mbhc_insert_work(struct work_struct *work) |
| 6481 | { |
| 6482 | struct delayed_work *dwork; |
| 6483 | struct tabla_priv *tabla; |
| 6484 | struct snd_soc_codec *codec; |
| 6485 | struct wcd9xxx *tabla_core; |
| 6486 | |
| 6487 | dwork = to_delayed_work(work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6488 | tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6489 | codec = tabla->codec; |
| 6490 | tabla_core = dev_get_drvdata(codec->dev->parent); |
| 6491 | |
| 6492 | pr_debug("%s:\n", __func__); |
| 6493 | |
| 6494 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 6495 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6496 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 6497 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6498 | wcd9xxx_disable_irq_sync(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
| 6499 | tabla_codec_detect_plug_type(codec); |
| 6500 | wcd9xxx_unlock_sleep(tabla_core); |
| 6501 | } |
| 6502 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6503 | static void tabla_hs_gpio_handler(struct snd_soc_codec *codec) |
| 6504 | { |
| 6505 | bool insert; |
| 6506 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 6507 | bool is_removed = false; |
| 6508 | |
| 6509 | pr_debug("%s: enter\n", __func__); |
| 6510 | |
| 6511 | tabla->in_gpio_handler = true; |
| 6512 | /* Wait here for debounce time */ |
| 6513 | usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 6514 | TABLA_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 6515 | |
| 6516 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6517 | |
| 6518 | /* cancel pending button press */ |
| 6519 | if (tabla_cancel_btn_work(tabla)) |
| 6520 | pr_debug("%s: button press is canceled\n", __func__); |
| 6521 | |
| 6522 | insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) == |
| 6523 | tabla->mbhc_cfg.gpio_level_insert); |
| 6524 | if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) { |
| 6525 | tabla->lpi_enabled = false; |
| 6526 | wmb(); |
| 6527 | |
| 6528 | /* cancel detect plug */ |
| 6529 | tabla_cancel_hs_detect_plug(tabla); |
| 6530 | |
| 6531 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 6532 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6533 | 0x00); |
| 6534 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00); |
| 6535 | tabla_codec_detect_plug_type(codec); |
| 6536 | } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 6537 | tabla->lpi_enabled = false; |
| 6538 | wmb(); |
| 6539 | |
| 6540 | /* cancel detect plug */ |
| 6541 | tabla_cancel_hs_detect_plug(tabla); |
| 6542 | |
| 6543 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE) { |
| 6544 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 6545 | is_removed = true; |
| 6546 | } else if (tabla->current_plug == PLUG_TYPE_HEADSET) { |
| 6547 | tabla_codec_pause_hs_polling(codec); |
| 6548 | tabla_codec_cleanup_hs_polling(codec); |
| 6549 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 6550 | is_removed = true; |
| 6551 | } |
| 6552 | |
| 6553 | if (is_removed) { |
| 6554 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 6555 | snd_soc_update_bits(codec, |
| 6556 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6557 | 0x01); |
| 6558 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 6559 | 0x01); |
| 6560 | /* Make sure mic trigger is turned off */ |
| 6561 | snd_soc_update_bits(codec, |
| 6562 | tabla->mbhc_bias_regs.ctl_reg, |
| 6563 | 0x01, 0x01); |
| 6564 | snd_soc_update_bits(codec, |
| 6565 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6566 | 0x90, 0x00); |
| 6567 | /* Reset MBHC State Machine */ |
| 6568 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 6569 | 0x08, 0x08); |
| 6570 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 6571 | 0x08, 0x00); |
| 6572 | /* Turn off override */ |
| 6573 | tabla_turn_onoff_override(codec, false); |
| 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | tabla->in_gpio_handler = false; |
| 6578 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6579 | pr_debug("%s: leave\n", __func__); |
| 6580 | } |
| 6581 | |
| 6582 | static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data) |
| 6583 | { |
| 6584 | int r = IRQ_HANDLED; |
| 6585 | struct snd_soc_codec *codec = data; |
| 6586 | |
| 6587 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 6588 | pr_warn("%s: failed to hold suspend\n", __func__); |
| 6589 | r = IRQ_NONE; |
| 6590 | } else { |
| 6591 | tabla_hs_gpio_handler(codec); |
| 6592 | wcd9xxx_unlock_sleep(codec->control_data); |
| 6593 | } |
| 6594 | |
| 6595 | return r; |
| 6596 | } |
| 6597 | |
| 6598 | static void mbhc_fw_read(struct work_struct *work) |
| 6599 | { |
| 6600 | struct delayed_work *dwork; |
| 6601 | struct tabla_priv *tabla; |
| 6602 | struct snd_soc_codec *codec; |
| 6603 | const struct firmware *fw; |
| 6604 | int ret = -1, retry = 0, rc; |
| 6605 | |
| 6606 | dwork = to_delayed_work(work); |
| 6607 | tabla = container_of(dwork, struct tabla_priv, |
| 6608 | mbhc_firmware_dwork); |
| 6609 | codec = tabla->codec; |
| 6610 | |
| 6611 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 6612 | retry++; |
| 6613 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 6614 | __func__, retry); |
| 6615 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 6616 | codec->dev); |
| 6617 | |
| 6618 | if (ret != 0) { |
| 6619 | usleep_range(MBHC_FW_READ_TIMEOUT, |
| 6620 | MBHC_FW_READ_TIMEOUT); |
| 6621 | } else { |
| 6622 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 6623 | break; |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | if (ret != 0) { |
| 6628 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 6629 | __func__); |
| 6630 | } else if (tabla_mbhc_fw_validate(fw) == false) { |
| 6631 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 6632 | __func__); |
| 6633 | release_firmware(fw); |
| 6634 | } else { |
| 6635 | tabla->mbhc_cfg.calibration = (void *)fw->data; |
| 6636 | tabla->mbhc_fw = fw; |
| 6637 | } |
| 6638 | |
| 6639 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 6640 | tabla_mbhc_init(codec); |
| 6641 | tabla_mbhc_cal(codec); |
| 6642 | tabla_mbhc_calc_thres(codec); |
| 6643 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 6644 | tabla_codec_calibrate_hs_polling(codec); |
| 6645 | if (!tabla->mbhc_cfg.gpio) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6646 | rc = tabla_codec_enable_hs_detect(codec, 1, |
| 6647 | MBHC_USE_MB_TRIGGER | |
| 6648 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6649 | false); |
| 6650 | |
| 6651 | if (IS_ERR_VALUE(rc)) |
| 6652 | pr_err("%s: Failed to setup MBHC detection\n", |
| 6653 | __func__); |
| 6654 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6655 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 6656 | snd_soc_update_bits(codec, |
| 6657 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6658 | 0x01); |
| 6659 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 6660 | 0x01); |
| 6661 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 6662 | tabla_hs_correct_gpio_plug); |
| 6663 | } |
| 6664 | |
| 6665 | } |
| 6666 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6667 | int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6668 | const struct tabla_mbhc_config *cfg) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6669 | { |
| 6670 | struct tabla_priv *tabla; |
| 6671 | int rc = 0; |
| 6672 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6673 | if (!codec || !cfg->calibration) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6674 | pr_err("Error: no codec or calibration\n"); |
| 6675 | return -EINVAL; |
| 6676 | } |
| 6677 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6678 | if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) { |
| 6679 | if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6680 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6681 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6682 | else |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6683 | pr_err("Error: unsupported clock rate %d\n", |
| 6684 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6685 | return -EINVAL; |
| 6686 | } |
| 6687 | |
| 6688 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6689 | tabla->mbhc_cfg = *cfg; |
| 6690 | tabla->in_gpio_handler = false; |
| 6691 | tabla->current_plug = PLUG_TYPE_NONE; |
| 6692 | tabla->lpi_enabled = false; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6693 | tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs); |
| 6694 | |
| 6695 | /* Put CFILT in fast mode by default */ |
| 6696 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 6697 | 0x40, TABLA_CFILT_FAST_MODE); |
| 6698 | INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read); |
| 6699 | INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn); |
| 6700 | INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report); |
| 6701 | INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report); |
| 6702 | INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work); |
| 6703 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6704 | if (!tabla->mbhc_cfg.read_fw_bin) { |
| 6705 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6706 | tabla_mbhc_init(codec); |
| 6707 | tabla_mbhc_cal(codec); |
| 6708 | tabla_mbhc_calc_thres(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6709 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6710 | tabla_codec_calibrate_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6711 | if (!tabla->mbhc_cfg.gpio) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6712 | rc = tabla_codec_enable_hs_detect(codec, 1, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6713 | MBHC_USE_MB_TRIGGER | |
| 6714 | MBHC_USE_HPHL_TRIGGER, |
| 6715 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6716 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6717 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 6718 | snd_soc_update_bits(codec, |
| 6719 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6720 | 0x01); |
| 6721 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 6722 | 0x01); |
| 6723 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 6724 | tabla_hs_correct_gpio_plug); |
| 6725 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6726 | } else { |
| 6727 | schedule_delayed_work(&tabla->mbhc_firmware_dwork, |
| 6728 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
| 6729 | } |
| 6730 | |
| 6731 | if (!IS_ERR_VALUE(rc)) { |
| 6732 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
| 6733 | wcd9xxx_enable_irq(codec->control_data, |
| 6734 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 6735 | wcd9xxx_enable_irq(codec->control_data, |
| 6736 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 6737 | } |
| 6738 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6739 | if (!IS_ERR_VALUE(rc) && tabla->mbhc_cfg.gpio) { |
| 6740 | rc = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, NULL, |
| 6741 | tabla_mechanical_plug_detect_irq, |
| 6742 | (IRQF_TRIGGER_RISING | |
| 6743 | IRQF_TRIGGER_FALLING), |
| 6744 | "tabla-gpio", codec); |
| 6745 | if (!IS_ERR_VALUE(rc)) { |
| 6746 | rc = enable_irq_wake(tabla->mbhc_cfg.gpio_irq); |
| 6747 | /* Bootup time detection */ |
| 6748 | tabla_hs_gpio_handler(codec); |
| 6749 | } |
| 6750 | } |
| 6751 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6752 | return rc; |
| 6753 | } |
| 6754 | EXPORT_SYMBOL_GPL(tabla_hs_detect); |
| 6755 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6756 | static unsigned long slimbus_value; |
| 6757 | |
| 6758 | static irqreturn_t tabla_slimbus_irq(int irq, void *data) |
| 6759 | { |
| 6760 | struct tabla_priv *priv = data; |
| 6761 | struct snd_soc_codec *codec = priv->codec; |
| 6762 | int i, j; |
| 6763 | u8 val; |
| 6764 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6765 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 6766 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6767 | TABLA_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 6768 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6769 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6770 | TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 6771 | if (val & 0x1) |
| 6772 | pr_err_ratelimited("overflow error on port %x," |
| 6773 | " value %x\n", i*8 + j, val); |
| 6774 | if (val & 0x2) |
| 6775 | pr_err_ratelimited("underflow error on port %x," |
| 6776 | " value %x\n", i*8 + j, val); |
| 6777 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6778 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6779 | TABLA_SLIM_PGD_PORT_INT_CLR0 + i, 0xFF); |
| 6780 | } |
| 6781 | |
| 6782 | return IRQ_HANDLED; |
| 6783 | } |
| 6784 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 6785 | |
| 6786 | static int tabla_handle_pdata(struct tabla_priv *tabla) |
| 6787 | { |
| 6788 | struct snd_soc_codec *codec = tabla->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6789 | struct wcd9xxx_pdata *pdata = tabla->pdata; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 6790 | int k1, k2, k3, rc = 0; |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 6791 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 6792 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 6793 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 6794 | u8 flag = pdata->amic_settings.use_pdata; |
| 6795 | u8 i = 0, j = 0; |
| 6796 | u8 val_txfe = 0, value = 0; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 6797 | |
| 6798 | if (!pdata) { |
| 6799 | rc = -ENODEV; |
| 6800 | goto done; |
| 6801 | } |
| 6802 | |
| 6803 | /* Make sure settings are correct */ |
| 6804 | if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) || |
| 6805 | (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) || |
| 6806 | (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) || |
| 6807 | (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) || |
| 6808 | (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) { |
| 6809 | rc = -EINVAL; |
| 6810 | goto done; |
| 6811 | } |
| 6812 | |
| 6813 | /* figure out k value */ |
| 6814 | k1 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 6815 | pdata->micbias.cfilt1_mv); |
| 6816 | k2 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 6817 | pdata->micbias.cfilt2_mv); |
| 6818 | k3 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 6819 | pdata->micbias.cfilt3_mv); |
| 6820 | |
| 6821 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
| 6822 | rc = -EINVAL; |
| 6823 | goto done; |
| 6824 | } |
| 6825 | |
| 6826 | /* Set voltage level and always use LDO */ |
| 6827 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C, |
| 6828 | (pdata->micbias.ldoh_v << 2)); |
| 6829 | |
| 6830 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC, |
| 6831 | (k1 << 2)); |
| 6832 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC, |
| 6833 | (k2 << 2)); |
| 6834 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC, |
| 6835 | (k3 << 2)); |
| 6836 | |
| 6837 | snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60, |
| 6838 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 6839 | snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60, |
| 6840 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 6841 | snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60, |
| 6842 | (pdata->micbias.bias3_cfilt_sel << 5)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6843 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60, |
| 6844 | (pdata->micbias.bias4_cfilt_sel << 5)); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 6845 | |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 6846 | for (i = 0; i < 6; j++, i += 2) { |
| 6847 | if (flag & (0x01 << i)) { |
| 6848 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 6849 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 6850 | val_txfe = val_txfe | |
| 6851 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 6852 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 6853 | 0x10, value); |
| 6854 | snd_soc_update_bits(codec, |
| 6855 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 6856 | 0x30, val_txfe); |
| 6857 | } |
| 6858 | if (flag & (0x01 << (i + 1))) { |
| 6859 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 6860 | val_txfe = (txfe_bypass & |
| 6861 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 6862 | val_txfe |= (txfe_buff & |
| 6863 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 6864 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 6865 | 0x01, value); |
| 6866 | snd_soc_update_bits(codec, |
| 6867 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 6868 | 0x03, val_txfe); |
| 6869 | } |
| 6870 | } |
| 6871 | if (flag & 0x40) { |
| 6872 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 6873 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 6874 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 6875 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, |
| 6876 | 0x13, value); |
| 6877 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6878 | |
| 6879 | if (pdata->ocp.use_pdata) { |
| 6880 | /* not defined in CODEC specification */ |
| 6881 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 6882 | pdata->ocp.hph_ocp_limit == 5) { |
| 6883 | rc = -EINVAL; |
| 6884 | goto done; |
| 6885 | } |
| 6886 | snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL, |
| 6887 | 0x0F, pdata->ocp.num_attempts); |
| 6888 | snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT, |
| 6889 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 6890 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, |
| 6891 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 6892 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6893 | |
| 6894 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 6895 | if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) { |
| 6896 | if (pdata->regulator[i].min_uV == 1800000 && |
| 6897 | pdata->regulator[i].max_uV == 1800000) { |
| 6898 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 6899 | 0x1C); |
| 6900 | } else if (pdata->regulator[i].min_uV == 2200000 && |
| 6901 | pdata->regulator[i].max_uV == 2200000) { |
| 6902 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 6903 | 0x1E); |
| 6904 | } else { |
| 6905 | pr_err("%s: unsupported CDC_VDDA_RX voltage " |
| 6906 | "min %d, max %d\n", __func__, |
| 6907 | pdata->regulator[i].min_uV, |
| 6908 | pdata->regulator[i].max_uV); |
| 6909 | rc = -EINVAL; |
| 6910 | } |
| 6911 | break; |
| 6912 | } |
| 6913 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 6914 | done: |
| 6915 | return rc; |
| 6916 | } |
| 6917 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6918 | static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = { |
| 6919 | |
| 6920 | /* Tabla 1.1 MICBIAS changes */ |
| 6921 | TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24), |
| 6922 | TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24), |
| 6923 | TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24), |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6924 | |
| 6925 | /* Tabla 1.1 HPH changes */ |
| 6926 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57), |
| 6927 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56), |
| 6928 | |
| 6929 | /* Tabla 1.1 EAR PA changes */ |
| 6930 | TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6), |
| 6931 | TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02), |
| 6932 | TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03), |
| 6933 | |
| 6934 | /* Tabla 1.1 Lineout_5 Changes */ |
| 6935 | TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10), |
| 6936 | |
| 6937 | /* Tabla 1.1 RX Changes */ |
| 6938 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78), |
| 6939 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78), |
| 6940 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78), |
| 6941 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78), |
| 6942 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78), |
| 6943 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78), |
| 6944 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78), |
| 6945 | |
| 6946 | /* Tabla 1.1 RX1 and RX2 Changes */ |
| 6947 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0), |
| 6948 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0), |
| 6949 | |
| 6950 | /* Tabla 1.1 RX3 to RX7 Changes */ |
| 6951 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80), |
| 6952 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80), |
| 6953 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80), |
| 6954 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80), |
| 6955 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80), |
| 6956 | |
| 6957 | /* Tabla 1.1 CLASSG Changes */ |
| 6958 | TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 6959 | }; |
| 6960 | |
| 6961 | static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = { |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6962 | /* Tabla 2.0 MICBIAS changes */ |
| 6963 | TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02), |
| 6964 | }; |
| 6965 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6966 | static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = { |
| 6967 | TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24), |
| 6968 | }; |
| 6969 | |
| 6970 | static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = { |
| 6971 | TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24), |
| 6972 | }; |
| 6973 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6974 | static void tabla_update_reg_defaults(struct snd_soc_codec *codec) |
| 6975 | { |
| 6976 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6977 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6978 | |
| 6979 | for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++) |
| 6980 | snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg, |
| 6981 | tabla_1_1_reg_defaults[i].val); |
| 6982 | |
| 6983 | for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++) |
| 6984 | snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg, |
| 6985 | tabla_2_0_reg_defaults[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6986 | |
| 6987 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 6988 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults); |
| 6989 | i++) |
| 6990 | snd_soc_write(codec, |
| 6991 | tabla_1_x_only_reg_2_0_defaults[i].reg, |
| 6992 | tabla_1_x_only_reg_2_0_defaults[i].val); |
| 6993 | } else { |
| 6994 | for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++) |
| 6995 | snd_soc_write(codec, |
| 6996 | tabla_2_only_reg_2_0_defaults[i].reg, |
| 6997 | tabla_2_only_reg_2_0_defaults[i].val); |
| 6998 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 6999 | } |
| 7000 | |
| 7001 | static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7002 | /* Initialize current threshold to 350MA |
| 7003 | * number of wait and run cycles to 4096 |
| 7004 | */ |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7005 | {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7006 | {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7007 | |
Santosh Mardi | 3217101 | 2011-10-28 23:32:06 +0530 | [diff] [blame] | 7008 | {TABLA_A_QFUSE_CTL, 0xFF, 0x03}, |
| 7009 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7010 | /* Initialize gain registers to use register gain */ |
| 7011 | {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 7012 | {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 7013 | {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 7014 | {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 7015 | {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10}, |
| 7016 | {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10}, |
| 7017 | |
| 7018 | /* Initialize mic biases to differential mode */ |
| 7019 | {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 7020 | {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 7021 | {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7022 | |
| 7023 | {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 7024 | |
| 7025 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 7026 | {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 7027 | {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 7028 | {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 7029 | {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 7030 | {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 7031 | {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20}, |
| 7032 | |
| 7033 | /* Use 16 bit sample size for TX7 to TX10 */ |
| 7034 | {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40}, |
| 7035 | {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40}, |
| 7036 | {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40}, |
| 7037 | {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40}, |
| 7038 | |
| 7039 | /* Use 16 bit sample size for RX */ |
| 7040 | {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 7041 | {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA}, |
| 7042 | |
| 7043 | /*enable HPF filter for TX paths */ |
| 7044 | {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 7045 | {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 7046 | {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 7047 | {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 7048 | {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0}, |
| 7049 | {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0}, |
| 7050 | {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0}, |
| 7051 | {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0}, |
| 7052 | {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0}, |
| 7053 | {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0}, |
| 7054 | }; |
| 7055 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7056 | static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = { |
| 7057 | /* Initialize mic biases to differential mode */ |
| 7058 | {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 7059 | }; |
| 7060 | |
| 7061 | static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = { |
| 7062 | /* Initialize mic biases to differential mode */ |
| 7063 | {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 7064 | }; |
| 7065 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7066 | static void tabla_codec_init_reg(struct snd_soc_codec *codec) |
| 7067 | { |
| 7068 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7069 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7070 | |
| 7071 | for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++) |
| 7072 | snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg, |
| 7073 | tabla_codec_reg_init_val[i].mask, |
| 7074 | tabla_codec_reg_init_val[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7075 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 7076 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++) |
| 7077 | snd_soc_update_bits(codec, |
| 7078 | tabla_1_x_codec_reg_init_val[i].reg, |
| 7079 | tabla_1_x_codec_reg_init_val[i].mask, |
| 7080 | tabla_1_x_codec_reg_init_val[i].val); |
| 7081 | } else { |
| 7082 | for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val); |
| 7083 | i++) |
| 7084 | snd_soc_update_bits(codec, |
| 7085 | tabla_2_higher_codec_reg_init_val[i].reg, |
| 7086 | tabla_2_higher_codec_reg_init_val[i].mask, |
| 7087 | tabla_2_higher_codec_reg_init_val[i].val); |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | static void tabla_update_reg_address(struct tabla_priv *priv) |
| 7092 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7093 | struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7094 | struct tabla_reg_address *reg_addr = &priv->reg_addr; |
| 7095 | |
| 7096 | if (TABLA_IS_1_X(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 7097 | reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC; |
| 7098 | reg_addr->micb_4_int_rbias = TABLA_1_A_MICB_4_INT_RBIAS; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7099 | reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7100 | } else if (TABLA_IS_2_0(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 7101 | reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC; |
| 7102 | reg_addr->micb_4_int_rbias = TABLA_2_A_MICB_4_INT_RBIAS; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7103 | reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7104 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 7105 | } |
| 7106 | |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7107 | #ifdef CONFIG_DEBUG_FS |
| 7108 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 7109 | { |
| 7110 | file->private_data = inode->i_private; |
| 7111 | return 0; |
| 7112 | } |
| 7113 | |
| 7114 | static ssize_t codec_debug_write(struct file *filp, |
| 7115 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 7116 | { |
| 7117 | char lbuf[32]; |
| 7118 | char *buf; |
| 7119 | int rc; |
| 7120 | struct tabla_priv *tabla = filp->private_data; |
| 7121 | |
| 7122 | if (cnt > sizeof(lbuf) - 1) |
| 7123 | return -EINVAL; |
| 7124 | |
| 7125 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 7126 | if (rc) |
| 7127 | return -EFAULT; |
| 7128 | |
| 7129 | lbuf[cnt] = '\0'; |
| 7130 | buf = (char *)lbuf; |
| 7131 | tabla->no_mic_headset_override = (*strsep(&buf, " ") == '0') ? |
| 7132 | false : true; |
| 7133 | return rc; |
| 7134 | } |
| 7135 | |
| 7136 | static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf, |
| 7137 | size_t count, loff_t *pos) |
| 7138 | { |
| 7139 | const int size = 768; |
| 7140 | char buffer[size]; |
| 7141 | int n = 0; |
| 7142 | struct tabla_priv *tabla = file->private_data; |
| 7143 | struct snd_soc_codec *codec = tabla->codec; |
| 7144 | const struct mbhc_internal_cal_data *p = &tabla->mbhc_data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7145 | const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true); |
| 7146 | const s16 v_ins_h_cur = tabla_get_current_v_ins(tabla, false); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7147 | |
| 7148 | n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z, |
| 7149 | tabla_codec_sta_dce_v(codec, 1, p->dce_z)); |
| 7150 | n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n", |
| 7151 | p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb)); |
| 7152 | n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n", |
| 7153 | p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z)); |
| 7154 | n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n", |
| 7155 | p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb)); |
| 7156 | n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce); |
| 7157 | n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta); |
| 7158 | n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n", |
| 7159 | p->micb_mv); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7160 | n += scnprintf(buffer + n, size - n, "v_ins_hu = %x(%dmv)%s\n", |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7161 | p->v_ins_hu, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7162 | tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu), |
| 7163 | p->v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 7164 | n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n", |
| 7165 | p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h), |
| 7166 | p->v_ins_h == v_ins_h_cur ? "*" : ""); |
| 7167 | n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n", |
| 7168 | p->adj_v_ins_hu, |
| 7169 | tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu), |
| 7170 | p->adj_v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 7171 | n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n", |
| 7172 | p->adj_v_ins_h, |
| 7173 | tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h), |
| 7174 | p->adj_v_ins_h == v_ins_h_cur ? "*" : ""); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7175 | n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n", |
| 7176 | p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu)); |
| 7177 | n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n", |
| 7178 | p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h)); |
| 7179 | n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n", |
| 7180 | p->v_b1_huc, |
| 7181 | tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc)); |
| 7182 | n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n", |
| 7183 | p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh)); |
| 7184 | n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl, |
| 7185 | tabla_codec_sta_dce_v(codec, 0, p->v_brl)); |
| 7186 | n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n", |
| 7187 | p->v_no_mic, |
| 7188 | tabla_codec_sta_dce_v(codec, 0, p->v_no_mic)); |
| 7189 | n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll); |
| 7190 | n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n", |
| 7191 | p->nbounce_wait); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7192 | n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n", |
| 7193 | p->v_inval_ins_low); |
| 7194 | n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n", |
| 7195 | p->v_inval_ins_high); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7196 | buffer[n] = 0; |
| 7197 | |
| 7198 | return simple_read_from_buffer(buf, count, pos, buffer, n); |
| 7199 | } |
| 7200 | |
| 7201 | static const struct file_operations codec_debug_ops = { |
| 7202 | .open = codec_debug_open, |
| 7203 | .write = codec_debug_write, |
| 7204 | }; |
| 7205 | |
| 7206 | static const struct file_operations codec_mbhc_debug_ops = { |
| 7207 | .open = codec_debug_open, |
| 7208 | .read = codec_mbhc_debug_read, |
| 7209 | }; |
| 7210 | #endif |
| 7211 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7212 | static int tabla_codec_probe(struct snd_soc_codec *codec) |
| 7213 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7214 | struct wcd9xxx *control; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7215 | struct tabla_priv *tabla; |
| 7216 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 7217 | int ret = 0; |
| 7218 | int i; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7219 | int ch_cnt; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7220 | |
| 7221 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 7222 | control = codec->control_data; |
| 7223 | |
| 7224 | tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL); |
| 7225 | if (!tabla) { |
| 7226 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 7227 | return -ENOMEM; |
| 7228 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 7229 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 7230 | tx_hpf_work[i].tabla = tabla; |
| 7231 | tx_hpf_work[i].decimator = i + 1; |
| 7232 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 7233 | tx_hpf_corner_freq_callback); |
| 7234 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7235 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 7236 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 7237 | memset(&tabla->mbhc_bias_regs, 0, |
| 7238 | sizeof(struct mbhc_micbias_regs)); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 7239 | tabla->mbhc_micbias_switched = false; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 7240 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7241 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 7242 | memset(&tabla->mbhc_data, 0, |
| 7243 | sizeof(struct mbhc_internal_cal_data)); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 7244 | tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7245 | tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 7246 | tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7247 | snd_soc_codec_set_drvdata(codec, tabla); |
| 7248 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 7249 | tabla->mclk_enabled = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7250 | tabla->bandgap_type = TABLA_BANDGAP_OFF; |
| 7251 | tabla->clock_active = false; |
| 7252 | tabla->config_mode_active = false; |
| 7253 | tabla->mbhc_polling_active = false; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 7254 | tabla->mbhc_fake_ins_start = 0; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7255 | tabla->no_mic_headset_override = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7256 | tabla->hs_polling_irq_prepared = false; |
| 7257 | mutex_init(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7258 | tabla->codec = codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7259 | tabla->mbhc_state = MBHC_STATE_NONE; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7260 | tabla->mbhc_last_resume = 0; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 7261 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 7262 | tabla->comp_enabled[i] = 0; |
| 7263 | tabla->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 7264 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7265 | tabla->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7266 | tabla->intf_type = wcd9xxx_get_intf_type(); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 7267 | tabla->aux_pga_cnt = 0; |
| 7268 | tabla->aux_l_gain = 0x1F; |
| 7269 | tabla->aux_r_gain = 0x1F; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7270 | tabla_update_reg_address(tabla); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7271 | tabla_update_reg_defaults(codec); |
| 7272 | tabla_codec_init_reg(codec); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7273 | ret = tabla_handle_pdata(tabla); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7274 | if (IS_ERR_VALUE(ret)) { |
| 7275 | pr_err("%s: bad pdata\n", __func__); |
| 7276 | goto err_pdata; |
| 7277 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7278 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7279 | snd_soc_add_controls(codec, tabla_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7280 | ARRAY_SIZE(tabla_snd_controls)); |
| 7281 | if (TABLA_IS_1_X(control->version)) |
| 7282 | snd_soc_add_controls(codec, tabla_1_x_snd_controls, |
| 7283 | ARRAY_SIZE(tabla_1_x_snd_controls)); |
| 7284 | else |
| 7285 | snd_soc_add_controls(codec, tabla_2_higher_snd_controls, |
| 7286 | ARRAY_SIZE(tabla_2_higher_snd_controls)); |
| 7287 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7288 | snd_soc_dapm_new_controls(dapm, tabla_dapm_widgets, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7289 | ARRAY_SIZE(tabla_dapm_widgets)); |
| 7290 | if (TABLA_IS_1_X(control->version)) |
| 7291 | snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets, |
| 7292 | ARRAY_SIZE(tabla_1_x_dapm_widgets)); |
| 7293 | else |
| 7294 | snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets, |
| 7295 | ARRAY_SIZE(tabla_2_higher_dapm_widgets)); |
| 7296 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7297 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 7298 | snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets, |
| 7299 | ARRAY_SIZE(tabla_dapm_i2s_widgets)); |
| 7300 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 7301 | ARRAY_SIZE(audio_i2s_map)); |
| 7302 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7303 | snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map)); |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 7304 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7305 | if (TABLA_IS_1_X(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7306 | snd_soc_dapm_add_routes(dapm, tabla_1_x_lineout_2_to_4_map, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7307 | ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map)); |
| 7308 | } else if (TABLA_IS_2_0(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7309 | snd_soc_dapm_add_routes(dapm, tabla_2_x_lineout_2_to_4_map, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7310 | ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map)); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7311 | } else { |
| 7312 | pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n", |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7313 | __func__, control->version); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 7314 | goto err_pdata; |
| 7315 | } |
| 7316 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7317 | snd_soc_dapm_sync(dapm); |
| 7318 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7319 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7320 | tabla_hs_insert_irq, "Headset insert detect", tabla); |
| 7321 | if (ret) { |
| 7322 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7323 | TABLA_IRQ_MBHC_INSERTION); |
| 7324 | goto err_insert_irq; |
| 7325 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7326 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7327 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7328 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7329 | tabla_hs_remove_irq, "Headset remove detect", tabla); |
| 7330 | if (ret) { |
| 7331 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7332 | TABLA_IRQ_MBHC_REMOVAL); |
| 7333 | goto err_remove_irq; |
| 7334 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7335 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7336 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7337 | tabla_dce_handler, "DC Estimation detect", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7338 | if (ret) { |
| 7339 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7340 | TABLA_IRQ_MBHC_POTENTIAL); |
| 7341 | goto err_potential_irq; |
| 7342 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7343 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7344 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7345 | tabla_release_handler, "Button Release detect", tabla); |
| 7346 | if (ret) { |
| 7347 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7348 | TABLA_IRQ_MBHC_RELEASE); |
| 7349 | goto err_release_irq; |
| 7350 | } |
| 7351 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7352 | ret = wcd9xxx_request_irq(codec->control_data, TABLA_IRQ_SLIMBUS, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7353 | tabla_slimbus_irq, "SLIMBUS Slave", tabla); |
| 7354 | if (ret) { |
| 7355 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7356 | TABLA_IRQ_SLIMBUS); |
| 7357 | goto err_slimbus_irq; |
| 7358 | } |
| 7359 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7360 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 7361 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7362 | TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 7363 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7364 | ret = wcd9xxx_request_irq(codec->control_data, |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7365 | TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla_hphl_ocp_irq, |
| 7366 | "HPH_L OCP detect", tabla); |
| 7367 | if (ret) { |
| 7368 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7369 | TABLA_IRQ_HPH_PA_OCPL_FAULT); |
| 7370 | goto err_hphl_ocp_irq; |
| 7371 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7372 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7373 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7374 | ret = wcd9xxx_request_irq(codec->control_data, |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7375 | TABLA_IRQ_HPH_PA_OCPR_FAULT, tabla_hphr_ocp_irq, |
| 7376 | "HPH_R OCP detect", tabla); |
| 7377 | if (ret) { |
| 7378 | pr_err("%s: Failed to request irq %d\n", __func__, |
| 7379 | TABLA_IRQ_HPH_PA_OCPR_FAULT); |
| 7380 | goto err_hphr_ocp_irq; |
| 7381 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7382 | wcd9xxx_disable_irq(codec->control_data, TABLA_IRQ_HPH_PA_OCPR_FAULT); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7383 | for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) { |
| 7384 | switch (tabla_dai[i].id) { |
| 7385 | case AIF1_PB: |
| 7386 | ch_cnt = tabla_dai[i].playback.channels_max; |
| 7387 | break; |
| 7388 | case AIF1_CAP: |
| 7389 | ch_cnt = tabla_dai[i].capture.channels_max; |
| 7390 | break; |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 7391 | case AIF2_PB: |
| 7392 | ch_cnt = tabla_dai[i].playback.channels_max; |
| 7393 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 7394 | case AIF2_CAP: |
| 7395 | ch_cnt = tabla_dai[i].capture.channels_max; |
| 7396 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7397 | default: |
| 7398 | continue; |
| 7399 | } |
| 7400 | tabla->dai[i].ch_num = kzalloc((sizeof(unsigned int)* |
| 7401 | ch_cnt), GFP_KERNEL); |
| 7402 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7403 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7404 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7405 | if (ret == 0) { |
| 7406 | tabla->debugfs_poke = |
| 7407 | debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla, |
| 7408 | &codec_debug_ops); |
| 7409 | tabla->debugfs_mbhc = |
| 7410 | debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO, |
| 7411 | NULL, tabla, &codec_mbhc_debug_ops); |
| 7412 | } |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7413 | #endif |
| 7414 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7415 | return ret; |
| 7416 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7417 | err_hphr_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7418 | wcd9xxx_free_irq(codec->control_data, |
| 7419 | TABLA_IRQ_HPH_PA_OCPL_FAULT, tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7420 | err_hphl_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7421 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7422 | err_slimbus_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7423 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7424 | err_release_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7425 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7426 | err_potential_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7427 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7428 | err_remove_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7429 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7430 | err_insert_irq: |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7431 | err_pdata: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7432 | mutex_destroy(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7433 | kfree(tabla); |
| 7434 | return ret; |
| 7435 | } |
| 7436 | static int tabla_codec_remove(struct snd_soc_codec *codec) |
| 7437 | { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7438 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7439 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7440 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_SLIMBUS, tabla); |
| 7441 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_RELEASE, tabla); |
| 7442 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_POTENTIAL, tabla); |
| 7443 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_REMOVAL, tabla); |
| 7444 | wcd9xxx_free_irq(codec->control_data, TABLA_IRQ_MBHC_INSERTION, tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7445 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7446 | tabla_codec_disable_clock_block(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7447 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7448 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 7449 | if (tabla->mbhc_fw) |
| 7450 | release_firmware(tabla->mbhc_fw); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 7451 | for (i = 0; i < ARRAY_SIZE(tabla_dai); i++) |
| 7452 | kfree(tabla->dai[i].ch_num); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7453 | mutex_destroy(&tabla->codec_resource_lock); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 7454 | #ifdef CONFIG_DEBUG_FS |
| 7455 | debugfs_remove(tabla->debugfs_poke); |
| 7456 | debugfs_remove(tabla->debugfs_mbhc); |
| 7457 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7458 | kfree(tabla); |
| 7459 | return 0; |
| 7460 | } |
| 7461 | static struct snd_soc_codec_driver soc_codec_dev_tabla = { |
| 7462 | .probe = tabla_codec_probe, |
| 7463 | .remove = tabla_codec_remove, |
| 7464 | .read = tabla_read, |
| 7465 | .write = tabla_write, |
| 7466 | |
| 7467 | .readable_register = tabla_readable, |
| 7468 | .volatile_register = tabla_volatile, |
| 7469 | |
| 7470 | .reg_cache_size = TABLA_CACHE_SIZE, |
| 7471 | .reg_cache_default = tabla_reg_defaults, |
| 7472 | .reg_word_size = 1, |
| 7473 | }; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 7474 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7475 | #ifdef CONFIG_PM |
| 7476 | static int tabla_suspend(struct device *dev) |
| 7477 | { |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7478 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 7479 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | static int tabla_resume(struct device *dev) |
| 7483 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7484 | struct platform_device *pdev = to_platform_device(dev); |
| 7485 | struct tabla_priv *tabla = platform_get_drvdata(pdev); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7486 | dev_dbg(dev, "%s: system resume\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7487 | tabla->mbhc_last_resume = jiffies; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 7488 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | static const struct dev_pm_ops tabla_pm_ops = { |
| 7492 | .suspend = tabla_suspend, |
| 7493 | .resume = tabla_resume, |
| 7494 | }; |
| 7495 | #endif |
| 7496 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7497 | static int __devinit tabla_probe(struct platform_device *pdev) |
| 7498 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 7499 | int ret = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7500 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 7501 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 7502 | tabla_dai, ARRAY_SIZE(tabla_dai)); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7503 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 7504 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 7505 | tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai)); |
| 7506 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7507 | } |
| 7508 | static int __devexit tabla_remove(struct platform_device *pdev) |
| 7509 | { |
| 7510 | snd_soc_unregister_codec(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7511 | return 0; |
| 7512 | } |
| 7513 | static struct platform_driver tabla_codec_driver = { |
| 7514 | .probe = tabla_probe, |
| 7515 | .remove = tabla_remove, |
| 7516 | .driver = { |
| 7517 | .name = "tabla_codec", |
| 7518 | .owner = THIS_MODULE, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7519 | #ifdef CONFIG_PM |
| 7520 | .pm = &tabla_pm_ops, |
| 7521 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7522 | }, |
| 7523 | }; |
| 7524 | |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 7525 | static struct platform_driver tabla1x_codec_driver = { |
| 7526 | .probe = tabla_probe, |
| 7527 | .remove = tabla_remove, |
| 7528 | .driver = { |
| 7529 | .name = "tabla1x_codec", |
| 7530 | .owner = THIS_MODULE, |
| 7531 | #ifdef CONFIG_PM |
| 7532 | .pm = &tabla_pm_ops, |
| 7533 | #endif |
| 7534 | }, |
| 7535 | }; |
| 7536 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7537 | static int __init tabla_codec_init(void) |
| 7538 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 7539 | int rtn = platform_driver_register(&tabla_codec_driver); |
| 7540 | if (rtn == 0) { |
| 7541 | rtn = platform_driver_register(&tabla1x_codec_driver); |
| 7542 | if (rtn != 0) |
| 7543 | platform_driver_unregister(&tabla_codec_driver); |
| 7544 | } |
| 7545 | return rtn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
| 7548 | static void __exit tabla_codec_exit(void) |
| 7549 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 7550 | platform_driver_unregister(&tabla1x_codec_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7551 | platform_driver_unregister(&tabla_codec_driver); |
| 7552 | } |
| 7553 | |
| 7554 | module_init(tabla_codec_init); |
| 7555 | module_exit(tabla_codec_exit); |
| 7556 | |
| 7557 | MODULE_DESCRIPTION("Tabla codec driver"); |
| 7558 | MODULE_VERSION("1.0"); |
| 7559 | MODULE_LICENSE("GPL v2"); |