Simmi Pateriya | 1b9a309 | 2013-01-02 11:49:26 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. 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> |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 21 | #include <linux/wait.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 22 | #include <linux/mfd/wcd9xxx/core.h> |
| 23 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 24 | #include <linux/mfd/wcd9xxx/wcd9310_registers.h> |
| 25 | #include <linux/mfd/wcd9xxx/pdata.h> |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | #include <sound/soc.h> |
| 29 | #include <sound/soc-dapm.h> |
| 30 | #include <sound/tlv.h> |
| 31 | #include <linux/bitops.h> |
| 32 | #include <linux/delay.h> |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 33 | #include <linux/pm_runtime.h> |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 34 | #include <linux/kernel.h> |
| 35 | #include <linux/gpio.h> |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 36 | #include <linux/irq.h> |
| 37 | #include <linux/wakelock.h> |
| 38 | #include <linux/suspend.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | #include "wcd9310.h" |
| 40 | |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 41 | static int cfilt_adjust_ms = 10; |
| 42 | module_param(cfilt_adjust_ms, int, 0644); |
| 43 | MODULE_PARM_DESC(cfilt_adjust_ms, "delay after adjusting cfilt voltage in ms"); |
| 44 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 45 | #define WCD9310_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\ |
| 46 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |\ |
| 47 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) |
| 48 | |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 49 | |
| 50 | #define NUM_DECIMATORS 10 |
| 51 | #define NUM_INTERPOLATORS 7 |
| 52 | #define BITS_PER_REG 8 |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 53 | #define TABLA_CFILT_FAST_MODE 0x00 |
| 54 | #define TABLA_CFILT_SLOW_MODE 0x40 |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 55 | #define MBHC_FW_READ_ATTEMPTS 15 |
| 56 | #define MBHC_FW_READ_TIMEOUT 2000000 |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 57 | #define MBHC_VDDIO_SWITCH_WAIT_MS 10 |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 58 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 59 | #define SLIM_CLOSE_TIMEOUT 1000 |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 60 | /* The wait time value comes from codec HW specification */ |
| 61 | #define COMP_BRINGUP_WAIT_TIME 2000 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 62 | enum { |
| 63 | MBHC_USE_HPHL_TRIGGER = 1, |
| 64 | MBHC_USE_MB_TRIGGER = 2 |
| 65 | }; |
| 66 | |
| 67 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 68 | #define NUM_ATTEMPTS_INSERT_DETECT 25 |
| 69 | #define NUM_ATTEMPTS_TO_REPORT 5 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 70 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 71 | #define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \ |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 72 | SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \ |
| 73 | SND_JACK_UNSUPPORTED) |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 74 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 75 | #define TABLA_I2S_MASTER_MODE_MASK 0x08 |
| 76 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 77 | #define TABLA_OCP_ATTEMPT 1 |
| 78 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 79 | enum { |
| 80 | AIF1_PB = 0, |
| 81 | AIF1_CAP, |
| 82 | AIF2_PB, |
| 83 | AIF2_CAP, |
| 84 | AIF3_PB, |
| 85 | AIF3_CAP, |
| 86 | NUM_CODEC_DAIS, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 89 | enum { |
| 90 | RX_MIX1_INP_SEL_ZERO = 0, |
| 91 | RX_MIX1_INP_SEL_SRC1, |
| 92 | RX_MIX1_INP_SEL_SRC2, |
| 93 | RX_MIX1_INP_SEL_IIR1, |
| 94 | RX_MIX1_INP_SEL_IIR2, |
| 95 | RX_MIX1_INP_SEL_RX1, |
| 96 | RX_MIX1_INP_SEL_RX2, |
| 97 | RX_MIX1_INP_SEL_RX3, |
| 98 | RX_MIX1_INP_SEL_RX4, |
| 99 | RX_MIX1_INP_SEL_RX5, |
| 100 | RX_MIX1_INP_SEL_RX6, |
| 101 | RX_MIX1_INP_SEL_RX7, |
| 102 | }; |
| 103 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 104 | #define TABLA_COMP_DIGITAL_GAIN_HP_OFFSET 3 |
| 105 | #define TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET 6 |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 106 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 107 | #define TABLA_MCLK_RATE_12288KHZ 12288000 |
| 108 | #define TABLA_MCLK_RATE_9600KHZ 9600000 |
| 109 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 110 | #define TABLA_FAKE_INS_THRESHOLD_MS 2500 |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 111 | #define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50 |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 112 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 113 | #define TABLA_MBHC_BUTTON_MIN 0x8000 |
| 114 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 115 | #define TABLA_MBHC_FAKE_INSERT_LOW 10 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 116 | #define TABLA_MBHC_FAKE_INSERT_HIGH 80 |
| 117 | #define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 118 | |
| 119 | #define TABLA_MBHC_STATUS_REL_DETECTION 0x0C |
| 120 | |
Joonwoo Park | db606b0 | 2012-08-11 13:46:30 -0700 | [diff] [blame] | 121 | #define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 50 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 122 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 123 | #define TABLA_MBHC_FAKE_INS_DELTA_MV 200 |
| 124 | #define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 125 | |
| 126 | #define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000) |
| 127 | #define TABLA_HS_DETECT_PLUG_INERVAL_MS 100 |
| 128 | |
| 129 | #define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000 |
| 130 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 131 | #define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2 |
| 132 | |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 133 | #define TABLA_ACQUIRE_LOCK(x) do { \ |
| 134 | mutex_lock_nested(&x, SINGLE_DEPTH_NESTING); \ |
| 135 | } while (0) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 136 | #define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0) |
| 137 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 138 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 139 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 140 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 141 | static struct snd_soc_dai_driver tabla_dai[]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 142 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 143 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 144 | struct snd_kcontrol *kcontrol, int event); |
| 145 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 146 | struct snd_kcontrol *kcontrol, int event); |
| 147 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 148 | |
| 149 | enum tabla_bandgap_type { |
| 150 | TABLA_BANDGAP_OFF = 0, |
| 151 | TABLA_BANDGAP_AUDIO_MODE, |
| 152 | TABLA_BANDGAP_MBHC_MODE, |
| 153 | }; |
| 154 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 155 | struct mbhc_micbias_regs { |
| 156 | u16 cfilt_val; |
| 157 | u16 cfilt_ctl; |
| 158 | u16 mbhc_reg; |
| 159 | u16 int_rbias; |
| 160 | u16 ctl_reg; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 161 | u8 cfilt_sel; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 164 | /* Codec supports 2 IIR filters */ |
| 165 | enum { |
| 166 | IIR1 = 0, |
| 167 | IIR2, |
| 168 | IIR_MAX, |
| 169 | }; |
| 170 | /* Codec supports 5 bands */ |
| 171 | enum { |
| 172 | BAND1 = 0, |
| 173 | BAND2, |
| 174 | BAND3, |
| 175 | BAND4, |
| 176 | BAND5, |
| 177 | BAND_MAX, |
| 178 | }; |
| 179 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 180 | enum { |
| 181 | COMPANDER_1 = 0, |
| 182 | COMPANDER_2, |
| 183 | COMPANDER_MAX, |
| 184 | }; |
| 185 | |
| 186 | enum { |
| 187 | COMPANDER_FS_8KHZ = 0, |
| 188 | COMPANDER_FS_16KHZ, |
| 189 | COMPANDER_FS_32KHZ, |
| 190 | COMPANDER_FS_48KHZ, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 191 | COMPANDER_FS_96KHZ, |
| 192 | COMPANDER_FS_192KHZ, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 193 | COMPANDER_FS_MAX, |
| 194 | }; |
| 195 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 196 | enum { |
| 197 | COMP_SHUTDWN_TIMEOUT_PCM_1 = 0, |
| 198 | COMP_SHUTDWN_TIMEOUT_PCM_240, |
| 199 | COMP_SHUTDWN_TIMEOUT_PCM_480, |
| 200 | COMP_SHUTDWN_TIMEOUT_PCM_960, |
| 201 | COMP_SHUTDWN_TIMEOUT_PCM_1440, |
| 202 | COMP_SHUTDWN_TIMEOUT_PCM_2880, |
| 203 | COMP_SHUTDWN_TIMEOUT_PCM_5760, |
| 204 | }; |
| 205 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 206 | /* Flags to track of PA and DAC state. |
| 207 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 208 | * only PA to be turned on without DAC being on. */ |
| 209 | enum tabla_priv_ack_flags { |
| 210 | TABLA_HPHL_PA_OFF_ACK = 0, |
| 211 | TABLA_HPHR_PA_OFF_ACK, |
| 212 | TABLA_HPHL_DAC_OFF_ACK, |
| 213 | TABLA_HPHR_DAC_OFF_ACK |
| 214 | }; |
| 215 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 216 | |
| 217 | struct comp_sample_dependent_params { |
| 218 | u32 peak_det_timeout; |
| 219 | u32 rms_meter_div_fact; |
| 220 | u32 rms_meter_resamp_fact; |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 221 | u32 shutdown_timeout; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 222 | }; |
| 223 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 224 | /* Data used by MBHC */ |
| 225 | struct mbhc_internal_cal_data { |
| 226 | u16 dce_z; |
| 227 | u16 dce_mb; |
| 228 | u16 sta_z; |
| 229 | u16 sta_mb; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 230 | u32 t_sta_dce; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 231 | u32 t_dce; |
| 232 | u32 t_sta; |
| 233 | u32 micb_mv; |
| 234 | u16 v_ins_hu; |
| 235 | u16 v_ins_h; |
| 236 | u16 v_b1_hu; |
| 237 | u16 v_b1_h; |
| 238 | u16 v_b1_huc; |
| 239 | u16 v_brh; |
| 240 | u16 v_brl; |
| 241 | u16 v_no_mic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 242 | u8 npoll; |
| 243 | u8 nbounce_wait; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 244 | s16 adj_v_hs_max; |
| 245 | u16 adj_v_ins_hu; |
| 246 | u16 adj_v_ins_h; |
| 247 | s16 v_inval_ins_low; |
| 248 | s16 v_inval_ins_high; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 249 | }; |
| 250 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 251 | struct tabla_reg_address { |
| 252 | u16 micb_4_ctl; |
| 253 | u16 micb_4_int_rbias; |
| 254 | u16 micb_4_mbhc; |
| 255 | }; |
| 256 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 257 | enum tabla_mbhc_plug_type { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 258 | PLUG_TYPE_INVALID = -1, |
| 259 | PLUG_TYPE_NONE, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 260 | PLUG_TYPE_HEADSET, |
| 261 | PLUG_TYPE_HEADPHONE, |
| 262 | PLUG_TYPE_HIGH_HPH, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 263 | PLUG_TYPE_GND_MIC_SWAP, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | enum tabla_mbhc_state { |
| 267 | MBHC_STATE_NONE = -1, |
| 268 | MBHC_STATE_POTENTIAL, |
| 269 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 270 | MBHC_STATE_RELEASE, |
| 271 | }; |
| 272 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 273 | struct hpf_work { |
| 274 | struct tabla_priv *tabla; |
| 275 | u32 decimator; |
| 276 | u8 tx_hpf_cut_of_freq; |
| 277 | struct delayed_work dwork; |
| 278 | }; |
| 279 | |
| 280 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 281 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 282 | static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = { |
| 283 | WCD9XXX_CH(10, 0), |
| 284 | WCD9XXX_CH(11, 1), |
| 285 | WCD9XXX_CH(12, 2), |
| 286 | WCD9XXX_CH(13, 3), |
| 287 | WCD9XXX_CH(14, 4), |
| 288 | WCD9XXX_CH(15, 5), |
| 289 | WCD9XXX_CH(16, 6) |
| 290 | }; |
| 291 | |
| 292 | static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = { |
| 293 | WCD9XXX_CH(0, 0), |
| 294 | WCD9XXX_CH(1, 1), |
| 295 | WCD9XXX_CH(2, 2), |
| 296 | WCD9XXX_CH(3, 3), |
| 297 | WCD9XXX_CH(4, 4), |
| 298 | WCD9XXX_CH(5, 5), |
| 299 | WCD9XXX_CH(6, 6), |
| 300 | WCD9XXX_CH(7, 7), |
| 301 | WCD9XXX_CH(8, 8), |
| 302 | WCD9XXX_CH(9, 9) |
| 303 | }; |
| 304 | |
| 305 | static const u32 vport_check_table[NUM_CODEC_DAIS] = { |
| 306 | 0, /* AIF1_PB */ |
| 307 | (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */ |
| 308 | 0, /* AIF2_PB */ |
| 309 | (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */ |
| 310 | 0, /* AIF2_PB */ |
| 311 | (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */ |
| 312 | }; |
| 313 | |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 314 | static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = { |
| 315 | 0, /* AIF1_PB */ |
| 316 | 0, /* AIF1_CAP */ |
| 317 | }; |
| 318 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 319 | struct tabla_priv { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 320 | struct snd_soc_codec *codec; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 321 | struct tabla_reg_address reg_addr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 322 | u32 adc_count; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 323 | u32 cfilt1_cnt; |
| 324 | u32 cfilt2_cnt; |
| 325 | u32 cfilt3_cnt; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 326 | u32 rx_bias_count; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 327 | s32 dmic_1_2_clk_cnt; |
| 328 | s32 dmic_3_4_clk_cnt; |
| 329 | s32 dmic_5_6_clk_cnt; |
| 330 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | enum tabla_bandgap_type bandgap_type; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 332 | bool mclk_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 333 | bool clock_active; |
| 334 | bool config_mode_active; |
| 335 | bool mbhc_polling_active; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 336 | unsigned long mbhc_fake_ins_start; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 337 | int buttons_pressed; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 338 | enum tabla_mbhc_state mbhc_state; |
| 339 | struct tabla_mbhc_config mbhc_cfg; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 340 | struct mbhc_internal_cal_data mbhc_data; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 341 | u32 ldo_h_count; |
| 342 | u32 micbias_enable_count[TABLA_NUM_MICBIAS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 343 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 344 | struct wcd9xxx_pdata *pdata; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 345 | u32 anc_slot; |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 346 | bool anc_func; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 347 | bool no_mic_headset_override; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 348 | /* Delayed work to report long button press */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 349 | struct delayed_work mbhc_btn_dwork; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 350 | |
| 351 | struct mbhc_micbias_regs mbhc_bias_regs; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 352 | bool mbhc_micbias_switched; |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 353 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 354 | /* track PA/DAC state */ |
| 355 | unsigned long hph_pa_dac_state; |
| 356 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 357 | /*track tabla interface type*/ |
| 358 | u8 intf_type; |
| 359 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 360 | u32 hph_status; /* track headhpone status */ |
| 361 | /* define separate work for left and right headphone OCP to avoid |
| 362 | * additional checking on which OCP event to report so no locking |
| 363 | * to ensure synchronization is required |
| 364 | */ |
| 365 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 366 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 367 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 368 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 369 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 370 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 371 | /* Work to perform MBHC Firmware Read */ |
| 372 | struct delayed_work mbhc_firmware_dwork; |
| 373 | const struct firmware *mbhc_fw; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 374 | |
| 375 | /* num of slim ports required */ |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 376 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 377 | |
| 378 | /*compander*/ |
| 379 | int comp_enabled[COMPANDER_MAX]; |
| 380 | u32 comp_fs[COMPANDER_MAX]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 381 | |
| 382 | /* Maintain the status of AUX PGA */ |
| 383 | int aux_pga_cnt; |
| 384 | u8 aux_l_gain; |
| 385 | u8 aux_r_gain; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 386 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 387 | struct delayed_work mbhc_insert_dwork; |
| 388 | unsigned long mbhc_last_resume; /* in jiffies */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 389 | |
| 390 | u8 current_plug; |
| 391 | struct work_struct hs_correct_plug_work; |
| 392 | bool hs_detect_work_stop; |
| 393 | bool hs_polling_irq_prepared; |
| 394 | bool lpi_enabled; /* low power insertion detection */ |
| 395 | bool in_gpio_handler; |
| 396 | /* Currently, only used for mbhc purpose, to protect |
| 397 | * concurrent execution of mbhc threaded irq handlers and |
| 398 | * kill race between DAPM and MBHC.But can serve as a |
| 399 | * general lock to protect codec resource |
| 400 | */ |
| 401 | struct mutex codec_resource_lock; |
| 402 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 403 | /* Work to perform polling on microphone voltage |
| 404 | * in order to correct plug type once plug type |
| 405 | * is detected as headphone |
| 406 | */ |
| 407 | struct work_struct hs_correct_plug_work_nogpio; |
| 408 | |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 409 | bool gpio_irq_resend; |
| 410 | struct wake_lock irq_resend_wlock; |
| 411 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 412 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 413 | struct dentry *debugfs_poke; |
| 414 | struct dentry *debugfs_mbhc; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 415 | #endif |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 416 | }; |
| 417 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 418 | static const u32 comp_shift[] = { |
| 419 | 0, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 420 | 1, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | static const int comp_rx_path[] = { |
| 424 | COMPANDER_1, |
| 425 | COMPANDER_1, |
| 426 | COMPANDER_2, |
| 427 | COMPANDER_2, |
| 428 | COMPANDER_2, |
| 429 | COMPANDER_2, |
| 430 | COMPANDER_MAX, |
| 431 | }; |
| 432 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 433 | static const struct comp_sample_dependent_params |
| 434 | comp_samp_params[COMPANDER_FS_MAX] = { |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 435 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 436 | .peak_det_timeout = 0x6, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 437 | .rms_meter_div_fact = 0x9 << 4, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 438 | .rms_meter_resamp_fact = 0x06, |
| 439 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_240 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 440 | }, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 441 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 442 | .peak_det_timeout = 0x7, |
| 443 | .rms_meter_div_fact = 0xA << 4, |
| 444 | .rms_meter_resamp_fact = 0x0C, |
| 445 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_480 << 3, |
| 446 | }, |
| 447 | { |
| 448 | .peak_det_timeout = 0x8, |
| 449 | .rms_meter_div_fact = 0xB << 4, |
| 450 | .rms_meter_resamp_fact = 0x30, |
| 451 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_960 << 3, |
| 452 | }, |
| 453 | { |
| 454 | .peak_det_timeout = 0x9, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 455 | .rms_meter_div_fact = 0xB << 4, |
| 456 | .rms_meter_resamp_fact = 0x28, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 457 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_1440 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 458 | }, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 459 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 460 | .peak_det_timeout = 0xA, |
| 461 | .rms_meter_div_fact = 0xC << 4, |
| 462 | .rms_meter_resamp_fact = 0x50, |
| 463 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_2880 << 3, |
| 464 | }, |
| 465 | { |
| 466 | .peak_det_timeout = 0xB, |
| 467 | .rms_meter_div_fact = 0xC << 4, |
| 468 | .rms_meter_resamp_fact = 0x50, |
| 469 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_5760 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 470 | }, |
| 471 | }; |
| 472 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 473 | static unsigned short rx_digital_gain_reg[] = { |
| 474 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 475 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 476 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 477 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 478 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 479 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 480 | TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 481 | }; |
| 482 | |
| 483 | |
| 484 | static unsigned short tx_digital_gain_reg[] = { |
| 485 | TABLA_A_CDC_TX1_VOL_CTL_GAIN, |
| 486 | TABLA_A_CDC_TX2_VOL_CTL_GAIN, |
| 487 | TABLA_A_CDC_TX3_VOL_CTL_GAIN, |
| 488 | TABLA_A_CDC_TX4_VOL_CTL_GAIN, |
| 489 | TABLA_A_CDC_TX5_VOL_CTL_GAIN, |
| 490 | TABLA_A_CDC_TX6_VOL_CTL_GAIN, |
| 491 | TABLA_A_CDC_TX7_VOL_CTL_GAIN, |
| 492 | TABLA_A_CDC_TX8_VOL_CTL_GAIN, |
| 493 | TABLA_A_CDC_TX9_VOL_CTL_GAIN, |
| 494 | TABLA_A_CDC_TX10_VOL_CTL_GAIN, |
| 495 | }; |
| 496 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 498 | struct snd_kcontrol *kcontrol, int event) |
| 499 | { |
| 500 | struct snd_soc_codec *codec = w->codec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 501 | |
| 502 | pr_debug("%s %d\n", __func__, event); |
| 503 | switch (event) { |
| 504 | case SND_SOC_DAPM_POST_PMU: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 505 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 506 | 0x01); |
| 507 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 508 | usleep_range(200, 200); |
| 509 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00); |
| 510 | break; |
| 511 | case SND_SOC_DAPM_PRE_PMD: |
| 512 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 513 | 0x10); |
| 514 | usleep_range(20, 20); |
| 515 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08); |
| 516 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10); |
| 517 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 518 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 519 | 0x00); |
Fred Oh | 54d24d7 | 2012-11-29 15:57:36 -0800 | [diff] [blame] | 520 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 521 | 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 523 | break; |
| 524 | } |
| 525 | return 0; |
| 526 | } |
| 527 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 528 | static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 529 | struct snd_ctl_elem_value *ucontrol) |
| 530 | { |
| 531 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 532 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 533 | ucontrol->value.integer.value[0] = tabla->anc_slot; |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 538 | struct snd_ctl_elem_value *ucontrol) |
| 539 | { |
| 540 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 541 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 542 | tabla->anc_slot = ucontrol->value.integer.value[0]; |
| 543 | return 0; |
| 544 | } |
| 545 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 546 | static int tabla_get_anc_func(struct snd_kcontrol *kcontrol, |
| 547 | struct snd_ctl_elem_value *ucontrol) |
| 548 | { |
| 549 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 550 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 551 | |
| 552 | mutex_lock(&codec->dapm.codec->mutex); |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 553 | ucontrol->value.integer.value[0] = (tabla->anc_func == true ? 1 : 0); |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 554 | mutex_unlock(&codec->dapm.codec->mutex); |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | static int tabla_put_anc_func(struct snd_kcontrol *kcontrol, |
| 559 | struct snd_ctl_elem_value *ucontrol) |
| 560 | { |
| 561 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 562 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 563 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 564 | |
| 565 | mutex_lock(&dapm->codec->mutex); |
| 566 | |
| 567 | tabla->anc_func = (!ucontrol->value.integer.value[0] ? false : true); |
| 568 | |
| 569 | dev_dbg(codec->dev, "%s: anc_func %x", __func__, tabla->anc_func); |
| 570 | |
| 571 | if (tabla->anc_func == true) { |
| 572 | snd_soc_dapm_enable_pin(dapm, "ANC HPHR"); |
| 573 | snd_soc_dapm_enable_pin(dapm, "ANC HPHL"); |
| 574 | snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE"); |
| 575 | snd_soc_dapm_disable_pin(dapm, "HPHR"); |
| 576 | snd_soc_dapm_disable_pin(dapm, "HPHL"); |
| 577 | snd_soc_dapm_disable_pin(dapm, "HEADPHONE"); |
| 578 | } else { |
| 579 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 580 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 581 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 582 | snd_soc_dapm_enable_pin(dapm, "HPHR"); |
| 583 | snd_soc_dapm_enable_pin(dapm, "HPHL"); |
| 584 | snd_soc_dapm_enable_pin(dapm, "HEADPHONE"); |
| 585 | } |
| 586 | snd_soc_dapm_sync(dapm); |
| 587 | mutex_unlock(&dapm->codec->mutex); |
| 588 | return 0; |
| 589 | } |
| 590 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 591 | static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 592 | struct snd_ctl_elem_value *ucontrol) |
| 593 | { |
| 594 | u8 ear_pa_gain; |
| 595 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 596 | |
| 597 | ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN); |
| 598 | |
| 599 | ear_pa_gain = ear_pa_gain >> 5; |
| 600 | |
| 601 | if (ear_pa_gain == 0x00) { |
| 602 | ucontrol->value.integer.value[0] = 0; |
| 603 | } else if (ear_pa_gain == 0x04) { |
| 604 | ucontrol->value.integer.value[0] = 1; |
| 605 | } else { |
| 606 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 607 | __func__, ear_pa_gain); |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 617 | struct snd_ctl_elem_value *ucontrol) |
| 618 | { |
| 619 | u8 ear_pa_gain; |
| 620 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 621 | |
| 622 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 623 | ucontrol->value.integer.value[0]); |
| 624 | |
| 625 | switch (ucontrol->value.integer.value[0]) { |
| 626 | case 0: |
| 627 | ear_pa_gain = 0x00; |
| 628 | break; |
| 629 | case 1: |
| 630 | ear_pa_gain = 0x80; |
| 631 | break; |
| 632 | default: |
| 633 | return -EINVAL; |
| 634 | } |
| 635 | |
| 636 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 637 | return 0; |
| 638 | } |
| 639 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 640 | static int tabla_get_iir_enable_audio_mixer( |
| 641 | struct snd_kcontrol *kcontrol, |
| 642 | struct snd_ctl_elem_value *ucontrol) |
| 643 | { |
| 644 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 645 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 646 | kcontrol->private_value)->reg; |
| 647 | int band_idx = ((struct soc_multi_mixer_control *) |
| 648 | kcontrol->private_value)->shift; |
| 649 | |
| 650 | ucontrol->value.integer.value[0] = |
| 651 | snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 652 | (1 << band_idx); |
| 653 | |
| 654 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 655 | iir_idx, band_idx, |
| 656 | (uint32_t)ucontrol->value.integer.value[0]); |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static int tabla_put_iir_enable_audio_mixer( |
| 661 | struct snd_kcontrol *kcontrol, |
| 662 | struct snd_ctl_elem_value *ucontrol) |
| 663 | { |
| 664 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 665 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 666 | kcontrol->private_value)->reg; |
| 667 | int band_idx = ((struct soc_multi_mixer_control *) |
| 668 | kcontrol->private_value)->shift; |
| 669 | int value = ucontrol->value.integer.value[0]; |
| 670 | |
| 671 | /* Mask first 5 bits, 6-8 are reserved */ |
| 672 | snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 673 | (1 << band_idx), (value << band_idx)); |
| 674 | |
| 675 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 676 | iir_idx, band_idx, value); |
| 677 | return 0; |
| 678 | } |
| 679 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 680 | int iir_idx, int band_idx, |
| 681 | int coeff_idx) |
| 682 | { |
| 683 | /* Address does not automatically update if reading */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 684 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 685 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 686 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 687 | |
| 688 | /* Mask bits top 2 bits since they are reserved */ |
| 689 | return ((snd_soc_read(codec, |
| 690 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 691 | (snd_soc_read(codec, |
| 692 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 693 | (snd_soc_read(codec, |
| 694 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 695 | (snd_soc_read(codec, |
| 696 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 697 | 0x3FFFFFFF; |
| 698 | } |
| 699 | |
| 700 | static int tabla_get_iir_band_audio_mixer( |
| 701 | struct snd_kcontrol *kcontrol, |
| 702 | struct snd_ctl_elem_value *ucontrol) |
| 703 | { |
| 704 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 705 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 706 | kcontrol->private_value)->reg; |
| 707 | int band_idx = ((struct soc_multi_mixer_control *) |
| 708 | kcontrol->private_value)->shift; |
| 709 | |
| 710 | ucontrol->value.integer.value[0] = |
| 711 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 712 | ucontrol->value.integer.value[1] = |
| 713 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 714 | ucontrol->value.integer.value[2] = |
| 715 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 716 | ucontrol->value.integer.value[3] = |
| 717 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 718 | ucontrol->value.integer.value[4] = |
| 719 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 720 | |
| 721 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 722 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 723 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 724 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 725 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 726 | __func__, iir_idx, band_idx, |
| 727 | (uint32_t)ucontrol->value.integer.value[0], |
| 728 | __func__, iir_idx, band_idx, |
| 729 | (uint32_t)ucontrol->value.integer.value[1], |
| 730 | __func__, iir_idx, band_idx, |
| 731 | (uint32_t)ucontrol->value.integer.value[2], |
| 732 | __func__, iir_idx, band_idx, |
| 733 | (uint32_t)ucontrol->value.integer.value[3], |
| 734 | __func__, iir_idx, band_idx, |
| 735 | (uint32_t)ucontrol->value.integer.value[4]); |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 740 | int iir_idx, int band_idx, |
| 741 | int coeff_idx, uint32_t value) |
| 742 | { |
| 743 | /* Mask top 3 bits, 6-8 are reserved */ |
| 744 | /* Update address manually each time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 745 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 746 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 747 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 748 | |
| 749 | /* Mask top 2 bits, 7-8 are reserved */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 750 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 751 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 752 | (value >> 24) & 0x3F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 753 | |
| 754 | /* Isolate 8bits at a time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 755 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 756 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 757 | (value >> 16) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 758 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 759 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 760 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 761 | (value >> 8) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 762 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 763 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 764 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 765 | value & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static int tabla_put_iir_band_audio_mixer( |
| 769 | struct snd_kcontrol *kcontrol, |
| 770 | struct snd_ctl_elem_value *ucontrol) |
| 771 | { |
| 772 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 773 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 774 | kcontrol->private_value)->reg; |
| 775 | int band_idx = ((struct soc_multi_mixer_control *) |
| 776 | kcontrol->private_value)->shift; |
| 777 | |
| 778 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 779 | ucontrol->value.integer.value[0]); |
| 780 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 781 | ucontrol->value.integer.value[1]); |
| 782 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 783 | ucontrol->value.integer.value[2]); |
| 784 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 785 | ucontrol->value.integer.value[3]); |
| 786 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 787 | ucontrol->value.integer.value[4]); |
| 788 | |
| 789 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 790 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 791 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 792 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 793 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 794 | __func__, iir_idx, band_idx, |
| 795 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 796 | __func__, iir_idx, band_idx, |
| 797 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 798 | __func__, iir_idx, band_idx, |
| 799 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 800 | __func__, iir_idx, band_idx, |
| 801 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 802 | __func__, iir_idx, band_idx, |
| 803 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 804 | return 0; |
| 805 | } |
| 806 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 807 | static int tabla_compander_gain_offset( |
| 808 | struct snd_soc_codec *codec, u32 enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 809 | unsigned int reg, int mask, int event, u32 comp) |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 810 | { |
| 811 | int pa_mode = snd_soc_read(codec, reg) & mask; |
| 812 | int gain_offset = 0; |
| 813 | /* if PMU && enable is 1-> offset is 3 |
| 814 | * if PMU && enable is 0-> offset is 0 |
| 815 | * if PMD && pa_mode is PA -> offset is 0: PMU compander is off |
| 816 | * if PMD && pa_mode is comp -> offset is -3: PMU compander is on. |
| 817 | */ |
| 818 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 819 | if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) { |
| 820 | if (comp == COMPANDER_1) |
| 821 | gain_offset = TABLA_COMP_DIGITAL_GAIN_HP_OFFSET; |
| 822 | if (comp == COMPANDER_2) |
| 823 | gain_offset = TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET; |
| 824 | } |
| 825 | if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) { |
| 826 | if (comp == COMPANDER_1) |
| 827 | gain_offset = -TABLA_COMP_DIGITAL_GAIN_HP_OFFSET; |
| 828 | if (comp == COMPANDER_2) |
| 829 | gain_offset = -TABLA_COMP_DIGITAL_GAIN_LINEOUT_OFFSET; |
| 830 | |
| 831 | } |
| 832 | pr_debug("%s: compander #%d gain_offset %d\n", |
| 833 | __func__, comp + 1, gain_offset); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 834 | return gain_offset; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | static int tabla_config_gain_compander( |
| 839 | struct snd_soc_codec *codec, |
| 840 | u32 compander, u32 enable, int event) |
| 841 | { |
| 842 | int value = 0; |
| 843 | int mask = 1 << 4; |
| 844 | int gain = 0; |
| 845 | int gain_offset; |
| 846 | if (compander >= COMPANDER_MAX) { |
| 847 | pr_err("%s: Error, invalid compander channel\n", __func__); |
| 848 | return -EINVAL; |
| 849 | } |
| 850 | |
| 851 | if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event)) |
| 852 | value = 1 << 4; |
| 853 | |
| 854 | if (compander == COMPANDER_1) { |
| 855 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 856 | TABLA_A_RX_HPH_L_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 857 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value); |
| 858 | gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL); |
| 859 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 860 | 0xFF, gain - gain_offset); |
| 861 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 862 | TABLA_A_RX_HPH_R_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 863 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value); |
| 864 | gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL); |
| 865 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 866 | 0xFF, gain - gain_offset); |
| 867 | } else if (compander == COMPANDER_2) { |
| 868 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 869 | TABLA_A_RX_LINE_1_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 870 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value); |
| 871 | gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL); |
| 872 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 873 | 0xFF, gain - gain_offset); |
| 874 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 875 | TABLA_A_RX_LINE_3_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 876 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value); |
| 877 | gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL); |
| 878 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 879 | 0xFF, gain - gain_offset); |
| 880 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 881 | TABLA_A_RX_LINE_2_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 882 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value); |
| 883 | gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL); |
| 884 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 885 | 0xFF, gain - gain_offset); |
| 886 | gain_offset = tabla_compander_gain_offset(codec, enable, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 887 | TABLA_A_RX_LINE_4_GAIN, mask, event, compander); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 888 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value); |
| 889 | gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL); |
| 890 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 891 | 0xFF, gain - gain_offset); |
| 892 | } |
| 893 | return 0; |
| 894 | } |
| 895 | static int tabla_get_compander(struct snd_kcontrol *kcontrol, |
| 896 | struct snd_ctl_elem_value *ucontrol) |
| 897 | { |
| 898 | |
| 899 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 900 | int comp = ((struct soc_multi_mixer_control *) |
| 901 | kcontrol->private_value)->max; |
| 902 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 903 | |
| 904 | ucontrol->value.integer.value[0] = tabla->comp_enabled[comp]; |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | static int tabla_set_compander(struct snd_kcontrol *kcontrol, |
| 910 | struct snd_ctl_elem_value *ucontrol) |
| 911 | { |
| 912 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 913 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 914 | int comp = ((struct soc_multi_mixer_control *) |
| 915 | kcontrol->private_value)->max; |
| 916 | int value = ucontrol->value.integer.value[0]; |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 917 | pr_debug("%s: compander #%d enable %d\n", |
| 918 | __func__, comp + 1, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 919 | if (value == tabla->comp_enabled[comp]) { |
| 920 | pr_debug("%s: compander #%d enable %d no change\n", |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 921 | __func__, comp + 1, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 922 | return 0; |
| 923 | } |
| 924 | tabla->comp_enabled[comp] = value; |
| 925 | return 0; |
| 926 | } |
| 927 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 928 | static int tabla_config_compander(struct snd_soc_dapm_widget *w, |
| 929 | struct snd_kcontrol *kcontrol, |
| 930 | int event) |
| 931 | { |
| 932 | struct snd_soc_codec *codec = w->codec; |
| 933 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 934 | u32 rate = tabla->comp_fs[w->shift]; |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 935 | |
| 936 | pr_debug("%s: compander #%d enable %d event %d widget name %s\n", |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 937 | __func__, w->shift + 1, |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 938 | tabla->comp_enabled[w->shift], event , w->name); |
| 939 | if (tabla->comp_enabled[w->shift] == 0) |
| 940 | goto rtn; |
| 941 | if ((w->shift == COMPANDER_1) && (tabla->anc_func)) { |
| 942 | pr_debug("%s: ANC is enabled so compander #%d cannot be enabled\n", |
| 943 | __func__, w->shift + 1); |
| 944 | goto rtn; |
| 945 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 946 | switch (event) { |
| 947 | case SND_SOC_DAPM_PRE_PMU: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 948 | /* Update compander sample rate */ |
| 949 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG + |
| 950 | w->shift * 8, 0x07, rate); |
| 951 | /* Enable both L/R compander clocks */ |
| 952 | snd_soc_update_bits(codec, |
| 953 | TABLA_A_CDC_CLK_RX_B2_CTL, |
| 954 | 1 << comp_shift[w->shift], |
| 955 | 1 << comp_shift[w->shift]); |
| 956 | /* Toggle compander reset bits */ |
| 957 | snd_soc_update_bits(codec, |
| 958 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 959 | 1 << comp_shift[w->shift], |
| 960 | 1 << comp_shift[w->shift]); |
| 961 | snd_soc_update_bits(codec, |
| 962 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 963 | 1 << comp_shift[w->shift], 0); |
| 964 | tabla_config_gain_compander(codec, w->shift, 1, event); |
| 965 | /* Compander enable -> 0x370/0x378 */ |
| 966 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 967 | w->shift * 8, 0x03, 0x03); |
| 968 | /* Update the RMS meter resampling */ |
| 969 | snd_soc_update_bits(codec, |
| 970 | TABLA_A_CDC_COMP1_B3_CTL + |
| 971 | w->shift * 8, 0xFF, 0x01); |
| 972 | snd_soc_update_bits(codec, |
| 973 | TABLA_A_CDC_COMP1_B2_CTL + |
| 974 | w->shift * 8, 0xF0, 0x50); |
| 975 | usleep_range(COMP_BRINGUP_WAIT_TIME, COMP_BRINGUP_WAIT_TIME); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 976 | break; |
| 977 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 978 | /* Set sample rate dependent paramater */ |
| 979 | if (w->shift == COMPANDER_1) { |
| 980 | snd_soc_update_bits(codec, |
| 981 | TABLA_A_CDC_CLSG_CTL, |
| 982 | 0x11, 0x00); |
| 983 | snd_soc_write(codec, |
| 984 | TABLA_A_CDC_CONN_CLSG_CTL, 0x11); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 985 | } |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 986 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 987 | w->shift * 8, 0x0F, |
| 988 | comp_samp_params[rate].peak_det_timeout); |
| 989 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 990 | w->shift * 8, 0xF0, |
| 991 | comp_samp_params[rate].rms_meter_div_fact); |
| 992 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL + |
| 993 | w->shift * 8, 0xFF, |
| 994 | comp_samp_params[rate].rms_meter_resamp_fact); |
| 995 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 996 | w->shift * 8, 0x38, |
| 997 | comp_samp_params[rate].shutdown_timeout); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 998 | break; |
| 999 | case SND_SOC_DAPM_PRE_PMD: |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1000 | break; |
| 1001 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 1002 | /* Disable the compander */ |
| 1003 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 1004 | w->shift * 8, 0x03, 0x00); |
| 1005 | /* Toggle compander reset bits */ |
| 1006 | snd_soc_update_bits(codec, |
| 1007 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1008 | 1 << comp_shift[w->shift], |
| 1009 | 1 << comp_shift[w->shift]); |
| 1010 | snd_soc_update_bits(codec, |
| 1011 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1012 | 1 << comp_shift[w->shift], 0); |
| 1013 | /* Turn off the clock for compander in pair */ |
| 1014 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL, |
| 1015 | 0x03 << comp_shift[w->shift], 0); |
| 1016 | /* Restore the gain */ |
| 1017 | tabla_config_gain_compander(codec, w->shift, |
| 1018 | tabla->comp_enabled[w->shift], |
| 1019 | event); |
| 1020 | if (w->shift == COMPANDER_1) { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 1021 | snd_soc_update_bits(codec, |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 1022 | TABLA_A_CDC_CLSG_CTL, |
| 1023 | 0x11, 0x11); |
| 1024 | snd_soc_write(codec, |
| 1025 | TABLA_A_CDC_CONN_CLSG_CTL, 0x14); |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 1026 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1027 | break; |
| 1028 | } |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 1029 | rtn: |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static int tabla_codec_hphr_dem_input_selection(struct snd_soc_dapm_widget *w, |
| 1034 | struct snd_kcontrol *kcontrol, |
| 1035 | int event) |
| 1036 | { |
| 1037 | struct snd_soc_codec *codec = w->codec; |
| 1038 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1039 | |
| 1040 | pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n", |
| 1041 | __func__, tabla->comp_enabled[COMPANDER_1], |
| 1042 | TABLA_A_CDC_RX1_B6_CTL, |
| 1043 | snd_soc_read(codec, TABLA_A_CDC_RX1_B6_CTL), event); |
| 1044 | switch (event) { |
| 1045 | case SND_SOC_DAPM_POST_PMU: |
| 1046 | if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func) |
| 1047 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1048 | 1 << w->shift, 0); |
| 1049 | else |
| 1050 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1051 | 1 << w->shift, 1 << w->shift); |
| 1052 | break; |
| 1053 | case SND_SOC_DAPM_POST_PMD: |
| 1054 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1055 | 1 << w->shift, 0); |
| 1056 | break; |
| 1057 | default: |
| 1058 | return -EINVAL; |
| 1059 | } |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int tabla_codec_hphl_dem_input_selection(struct snd_soc_dapm_widget *w, |
| 1064 | struct snd_kcontrol *kcontrol, |
| 1065 | int event) |
| 1066 | { |
| 1067 | struct snd_soc_codec *codec = w->codec; |
| 1068 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1069 | |
| 1070 | pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n", |
| 1071 | __func__, tabla->comp_enabled[COMPANDER_1], |
| 1072 | TABLA_A_CDC_RX2_B6_CTL, |
| 1073 | snd_soc_read(codec, TABLA_A_CDC_RX2_B6_CTL), event); |
| 1074 | switch (event) { |
| 1075 | case SND_SOC_DAPM_POST_PMU: |
| 1076 | if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func) |
| 1077 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1078 | 1 << w->shift, 0); |
| 1079 | else |
| 1080 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1081 | 1 << w->shift, 1 << w->shift); |
| 1082 | break; |
| 1083 | case SND_SOC_DAPM_POST_PMD: |
| 1084 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1085 | 1 << w->shift, 0); |
| 1086 | break; |
| 1087 | default: |
| 1088 | return -EINVAL; |
| 1089 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1090 | return 0; |
| 1091 | } |
| 1092 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 1093 | static const char *const tabla_anc_func_text[] = {"OFF", "ON"}; |
| 1094 | static const struct soc_enum tabla_anc_func_enum = |
| 1095 | SOC_ENUM_SINGLE_EXT(2, tabla_anc_func_text); |
| 1096 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 1097 | static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 1098 | static const struct soc_enum tabla_ear_pa_gain_enum[] = { |
| 1099 | SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text), |
| 1100 | }; |
| 1101 | |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 1102 | /*cut of frequency for high pass filter*/ |
| 1103 | static const char *cf_text[] = { |
| 1104 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 1105 | }; |
| 1106 | |
| 1107 | static const struct soc_enum cf_dec1_enum = |
| 1108 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 1109 | |
| 1110 | static const struct soc_enum cf_dec2_enum = |
| 1111 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 1112 | |
| 1113 | static const struct soc_enum cf_dec3_enum = |
| 1114 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 1115 | |
| 1116 | static const struct soc_enum cf_dec4_enum = |
| 1117 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 1118 | |
| 1119 | static const struct soc_enum cf_dec5_enum = |
| 1120 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text); |
| 1121 | |
| 1122 | static const struct soc_enum cf_dec6_enum = |
| 1123 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text); |
| 1124 | |
| 1125 | static const struct soc_enum cf_dec7_enum = |
| 1126 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text); |
| 1127 | |
| 1128 | static const struct soc_enum cf_dec8_enum = |
| 1129 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text); |
| 1130 | |
| 1131 | static const struct soc_enum cf_dec9_enum = |
| 1132 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text); |
| 1133 | |
| 1134 | static const struct soc_enum cf_dec10_enum = |
| 1135 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text); |
| 1136 | |
| 1137 | static const struct soc_enum cf_rxmix1_enum = |
| 1138 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 1139 | |
| 1140 | static const struct soc_enum cf_rxmix2_enum = |
| 1141 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text); |
| 1142 | |
| 1143 | static const struct soc_enum cf_rxmix3_enum = |
| 1144 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text); |
| 1145 | |
| 1146 | static const struct soc_enum cf_rxmix4_enum = |
| 1147 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text); |
| 1148 | |
| 1149 | static const struct soc_enum cf_rxmix5_enum = |
| 1150 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text) |
| 1151 | ; |
| 1152 | static const struct soc_enum cf_rxmix6_enum = |
| 1153 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text); |
| 1154 | |
| 1155 | static const struct soc_enum cf_rxmix7_enum = |
| 1156 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text); |
| 1157 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1158 | static const struct snd_kcontrol_new tabla_snd_controls[] = { |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 1159 | |
| 1160 | SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0], |
| 1161 | tabla_pa_gain_get, tabla_pa_gain_put), |
| 1162 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1163 | SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 1164 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1165 | SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 1166 | line_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1167 | SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1, |
| 1168 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1169 | SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1, |
| 1170 | line_gain), |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1171 | SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1, |
| 1172 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1173 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1174 | SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 1175 | line_gain), |
| 1176 | SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 1177 | line_gain), |
| 1178 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1179 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 1180 | -84, 40, digital_gain), |
| 1181 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 1182 | -84, 40, digital_gain), |
| 1183 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 1184 | -84, 40, digital_gain), |
| 1185 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 1186 | -84, 40, digital_gain), |
| 1187 | SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 1188 | -84, 40, digital_gain), |
| 1189 | SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 1190 | -84, 40, digital_gain), |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 1191 | SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 1192 | -84, 40, digital_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1193 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1194 | 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] | 1195 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1196 | 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] | 1197 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1198 | SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 1199 | digital_gain), |
| 1200 | SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 1201 | digital_gain), |
| 1202 | SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40, |
| 1203 | digital_gain), |
| 1204 | SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40, |
| 1205 | digital_gain), |
| 1206 | SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40, |
| 1207 | digital_gain), |
| 1208 | SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40, |
| 1209 | digital_gain), |
| 1210 | SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40, |
| 1211 | digital_gain), |
| 1212 | SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84, |
| 1213 | 40, digital_gain), |
Patrick Lai | 2900637 | 2011-09-28 17:57:42 -0700 | [diff] [blame] | 1214 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 1215 | 40, digital_gain), |
| 1216 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 1217 | 40, digital_gain), |
| 1218 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 1219 | 40, digital_gain), |
| 1220 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 1221 | 40, digital_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1222 | SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 1223 | 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] | 1224 | SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain), |
| 1225 | 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] | 1226 | SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain), |
| 1227 | 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] | 1228 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1229 | SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0, |
| 1230 | aux_pga_gain), |
| 1231 | SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0, |
| 1232 | aux_pga_gain), |
| 1233 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1234 | 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] | 1235 | 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] | 1236 | 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] | 1237 | |
| 1238 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot, |
| 1239 | tabla_put_anc_slot), |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 1240 | SOC_ENUM_EXT("ANC Function", tabla_anc_func_enum, tabla_get_anc_func, |
| 1241 | tabla_put_anc_func), |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 1242 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 1243 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 1244 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 1245 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 1246 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 1247 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 1248 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 1249 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 1250 | SOC_ENUM("TX9 HPF cut off", cf_dec9_enum), |
| 1251 | SOC_ENUM("TX10 HPF cut off", cf_dec10_enum), |
| 1252 | |
| 1253 | SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 1254 | SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 1255 | SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 1256 | SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 1257 | SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0), |
| 1258 | SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0), |
| 1259 | SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0), |
| 1260 | SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0), |
| 1261 | SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0), |
| 1262 | SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0), |
| 1263 | |
| 1264 | SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 1265 | SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 1266 | SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 1267 | SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1268 | SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0), |
| 1269 | SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0), |
| 1270 | SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0), |
| 1271 | |
| 1272 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1273 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1274 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 1275 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 1276 | SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum), |
| 1277 | SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum), |
| 1278 | SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum), |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 1279 | |
| 1280 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1281 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1282 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1283 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1284 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1285 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1286 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1287 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1288 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1289 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1290 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1291 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1292 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1293 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1294 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1295 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1296 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1297 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1298 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1299 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1300 | |
| 1301 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1302 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1303 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1304 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1305 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1306 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1307 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1308 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1309 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1310 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1311 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1312 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1313 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1314 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1315 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1316 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1317 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1318 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1319 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1320 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1321 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0, |
| 1322 | tabla_get_compander, tabla_set_compander), |
| 1323 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0, |
| 1324 | tabla_get_compander, tabla_set_compander), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1325 | }; |
| 1326 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 1327 | static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = { |
| 1328 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1), |
| 1329 | }; |
| 1330 | |
| 1331 | static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = { |
| 1332 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1), |
| 1333 | }; |
| 1334 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1335 | static const char *rx_mix1_text[] = { |
| 1336 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1337 | "RX5", "RX6", "RX7" |
| 1338 | }; |
| 1339 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1340 | static const char *rx_mix2_text[] = { |
| 1341 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1342 | }; |
| 1343 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1344 | static const char *rx_dsm_text[] = { |
| 1345 | "CIC_OUT", "DSM_INV" |
| 1346 | }; |
| 1347 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1348 | static const char *sb_tx1_mux_text[] = { |
| 1349 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1350 | "DEC1" |
| 1351 | }; |
| 1352 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1353 | static const char *sb_tx2_mux_text[] = { |
| 1354 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1355 | "DEC2" |
| 1356 | }; |
| 1357 | |
| 1358 | static const char *sb_tx3_mux_text[] = { |
| 1359 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1360 | "DEC3" |
| 1361 | }; |
| 1362 | |
| 1363 | static const char *sb_tx4_mux_text[] = { |
| 1364 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1365 | "DEC4" |
| 1366 | }; |
| 1367 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1368 | static const char *sb_tx5_mux_text[] = { |
| 1369 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1370 | "DEC5" |
| 1371 | }; |
| 1372 | |
| 1373 | static const char *sb_tx6_mux_text[] = { |
| 1374 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1375 | "DEC6" |
| 1376 | }; |
| 1377 | |
| 1378 | static const char const *sb_tx7_to_tx10_mux_text[] = { |
| 1379 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1380 | "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1381 | "DEC9", "DEC10" |
| 1382 | }; |
| 1383 | |
| 1384 | static const char *dec1_mux_text[] = { |
| 1385 | "ZERO", "DMIC1", "ADC6", |
| 1386 | }; |
| 1387 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1388 | static const char *dec2_mux_text[] = { |
| 1389 | "ZERO", "DMIC2", "ADC5", |
| 1390 | }; |
| 1391 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1392 | static const char *dec3_mux_text[] = { |
| 1393 | "ZERO", "DMIC3", "ADC4", |
| 1394 | }; |
| 1395 | |
| 1396 | static const char *dec4_mux_text[] = { |
| 1397 | "ZERO", "DMIC4", "ADC3", |
| 1398 | }; |
| 1399 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1400 | static const char *dec5_mux_text[] = { |
| 1401 | "ZERO", "DMIC5", "ADC2", |
| 1402 | }; |
| 1403 | |
| 1404 | static const char *dec6_mux_text[] = { |
| 1405 | "ZERO", "DMIC6", "ADC1", |
| 1406 | }; |
| 1407 | |
| 1408 | static const char const *dec7_mux_text[] = { |
| 1409 | "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB", |
| 1410 | }; |
| 1411 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1412 | static const char *dec8_mux_text[] = { |
| 1413 | "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5", |
| 1414 | }; |
| 1415 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1416 | static const char *dec9_mux_text[] = { |
| 1417 | "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1418 | }; |
| 1419 | |
| 1420 | static const char *dec10_mux_text[] = { |
| 1421 | "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1422 | }; |
| 1423 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1424 | static const char const *anc_mux_text[] = { |
| 1425 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB", |
| 1426 | "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6" |
| 1427 | }; |
| 1428 | |
| 1429 | static const char const *anc1_fb_mux_text[] = { |
| 1430 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1431 | }; |
| 1432 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1433 | static const char *const iir_inp1_text[] = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1434 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1435 | "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 1436 | }; |
| 1437 | |
| 1438 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 1439 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text); |
| 1440 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1441 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 1442 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text); |
| 1443 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1444 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
| 1445 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text); |
| 1446 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1447 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 1448 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text); |
| 1449 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1450 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 1451 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text); |
| 1452 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1453 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 1454 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text); |
| 1455 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1456 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 1457 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text); |
| 1458 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1459 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
| 1460 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text); |
| 1461 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1462 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
| 1463 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text); |
| 1464 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1465 | static const struct soc_enum rx5_mix1_inp1_chain_enum = |
| 1466 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text); |
| 1467 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1468 | static const struct soc_enum rx5_mix1_inp2_chain_enum = |
| 1469 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text); |
| 1470 | |
| 1471 | static const struct soc_enum rx6_mix1_inp1_chain_enum = |
| 1472 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text); |
| 1473 | |
| 1474 | static const struct soc_enum rx6_mix1_inp2_chain_enum = |
| 1475 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text); |
| 1476 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1477 | static const struct soc_enum rx7_mix1_inp1_chain_enum = |
| 1478 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text); |
| 1479 | |
| 1480 | static const struct soc_enum rx7_mix1_inp2_chain_enum = |
| 1481 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text); |
| 1482 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1483 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1484 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1485 | |
| 1486 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1487 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1488 | |
| 1489 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1490 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1491 | |
| 1492 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1493 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1494 | |
| 1495 | static const struct soc_enum rx3_mix2_inp1_chain_enum = |
| 1496 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text); |
| 1497 | |
| 1498 | static const struct soc_enum rx3_mix2_inp2_chain_enum = |
| 1499 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text); |
| 1500 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1501 | static const struct soc_enum rx4_dsm_enum = |
| 1502 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text); |
| 1503 | |
| 1504 | static const struct soc_enum rx6_dsm_enum = |
| 1505 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text); |
| 1506 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1507 | static const struct soc_enum sb_tx1_mux_enum = |
| 1508 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 1509 | |
| 1510 | static const struct soc_enum sb_tx2_mux_enum = |
| 1511 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 1512 | |
| 1513 | static const struct soc_enum sb_tx3_mux_enum = |
| 1514 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 1515 | |
| 1516 | static const struct soc_enum sb_tx4_mux_enum = |
| 1517 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 1518 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1519 | static const struct soc_enum sb_tx5_mux_enum = |
| 1520 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 1521 | |
| 1522 | static const struct soc_enum sb_tx6_mux_enum = |
| 1523 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text); |
| 1524 | |
| 1525 | static const struct soc_enum sb_tx7_mux_enum = |
| 1526 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18, |
| 1527 | sb_tx7_to_tx10_mux_text); |
| 1528 | |
| 1529 | static const struct soc_enum sb_tx8_mux_enum = |
| 1530 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18, |
| 1531 | sb_tx7_to_tx10_mux_text); |
| 1532 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1533 | static const struct soc_enum sb_tx9_mux_enum = |
| 1534 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18, |
| 1535 | sb_tx7_to_tx10_mux_text); |
| 1536 | |
| 1537 | static const struct soc_enum sb_tx10_mux_enum = |
| 1538 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18, |
| 1539 | sb_tx7_to_tx10_mux_text); |
| 1540 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1541 | static const struct soc_enum dec1_mux_enum = |
| 1542 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text); |
| 1543 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1544 | static const struct soc_enum dec2_mux_enum = |
| 1545 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text); |
| 1546 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1547 | static const struct soc_enum dec3_mux_enum = |
| 1548 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text); |
| 1549 | |
| 1550 | static const struct soc_enum dec4_mux_enum = |
| 1551 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text); |
| 1552 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1553 | static const struct soc_enum dec5_mux_enum = |
| 1554 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text); |
| 1555 | |
| 1556 | static const struct soc_enum dec6_mux_enum = |
| 1557 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text); |
| 1558 | |
| 1559 | static const struct soc_enum dec7_mux_enum = |
| 1560 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text); |
| 1561 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1562 | static const struct soc_enum dec8_mux_enum = |
| 1563 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text); |
| 1564 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1565 | static const struct soc_enum dec9_mux_enum = |
| 1566 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text); |
| 1567 | |
| 1568 | static const struct soc_enum dec10_mux_enum = |
| 1569 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text); |
| 1570 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1571 | static const struct soc_enum anc1_mux_enum = |
| 1572 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text); |
| 1573 | |
| 1574 | static const struct soc_enum anc2_mux_enum = |
| 1575 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text); |
| 1576 | |
| 1577 | static const struct soc_enum anc1_fb_mux_enum = |
| 1578 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1579 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1580 | static const struct soc_enum iir1_inp1_mux_enum = |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1581 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir_inp1_text); |
| 1582 | |
| 1583 | static const struct soc_enum iir2_inp1_mux_enum = |
| 1584 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ2_B1_CTL, 0, 18, iir_inp1_text); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1585 | |
| 1586 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1587 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1588 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1589 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1590 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1591 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1592 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1593 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1594 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1595 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1596 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1597 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1598 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1599 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1600 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1601 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1602 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1603 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1604 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1605 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1606 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1607 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1608 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1609 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1610 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1611 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1612 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1613 | static const struct snd_kcontrol_new rx5_mix1_inp1_mux = |
| 1614 | SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum); |
| 1615 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1616 | static const struct snd_kcontrol_new rx5_mix1_inp2_mux = |
| 1617 | SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum); |
| 1618 | |
| 1619 | static const struct snd_kcontrol_new rx6_mix1_inp1_mux = |
| 1620 | SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum); |
| 1621 | |
| 1622 | static const struct snd_kcontrol_new rx6_mix1_inp2_mux = |
| 1623 | SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum); |
| 1624 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1625 | static const struct snd_kcontrol_new rx7_mix1_inp1_mux = |
| 1626 | SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum); |
| 1627 | |
| 1628 | static const struct snd_kcontrol_new rx7_mix1_inp2_mux = |
| 1629 | SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum); |
| 1630 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1631 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1632 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1633 | |
| 1634 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1635 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1636 | |
| 1637 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1638 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1639 | |
| 1640 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1641 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1642 | |
| 1643 | static const struct snd_kcontrol_new rx3_mix2_inp1_mux = |
| 1644 | SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum); |
| 1645 | |
| 1646 | static const struct snd_kcontrol_new rx3_mix2_inp2_mux = |
| 1647 | SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum); |
| 1648 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1649 | static const struct snd_kcontrol_new rx4_dsm_mux = |
| 1650 | SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum); |
| 1651 | |
| 1652 | static const struct snd_kcontrol_new rx6_dsm_mux = |
| 1653 | SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum); |
| 1654 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1655 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1656 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1657 | |
| 1658 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1659 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1660 | |
| 1661 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1662 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1663 | |
| 1664 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1665 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1666 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1667 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 1668 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 1669 | |
| 1670 | static const struct snd_kcontrol_new sb_tx6_mux = |
| 1671 | SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); |
| 1672 | |
| 1673 | static const struct snd_kcontrol_new sb_tx7_mux = |
| 1674 | SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); |
| 1675 | |
| 1676 | static const struct snd_kcontrol_new sb_tx8_mux = |
| 1677 | SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); |
| 1678 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1679 | static const struct snd_kcontrol_new sb_tx9_mux = |
| 1680 | SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum); |
| 1681 | |
| 1682 | static const struct snd_kcontrol_new sb_tx10_mux = |
| 1683 | SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum); |
| 1684 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1685 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1686 | static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1687 | struct snd_ctl_elem_value *ucontrol) |
| 1688 | { |
| 1689 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1690 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1691 | struct snd_soc_codec *codec = w->codec; |
| 1692 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1693 | unsigned int dec_mux, decimator; |
| 1694 | char *dec_name = NULL; |
| 1695 | char *widget_name = NULL; |
| 1696 | char *temp; |
| 1697 | u16 tx_mux_ctl_reg; |
| 1698 | u8 adc_dmic_sel = 0x0; |
| 1699 | int ret = 0; |
| 1700 | |
| 1701 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1702 | return -EINVAL; |
| 1703 | |
| 1704 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1705 | |
| 1706 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1707 | if (!widget_name) |
| 1708 | return -ENOMEM; |
| 1709 | temp = widget_name; |
| 1710 | |
| 1711 | dec_name = strsep(&widget_name, " "); |
| 1712 | widget_name = temp; |
| 1713 | if (!dec_name) { |
| 1714 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1715 | ret = -EINVAL; |
| 1716 | goto out; |
| 1717 | } |
| 1718 | |
| 1719 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 1720 | if (ret < 0) { |
| 1721 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1722 | ret = -EINVAL; |
| 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u" |
| 1727 | " dec_mux = %u\n", __func__, w->name, dec_name, decimator, |
| 1728 | dec_mux); |
| 1729 | |
| 1730 | |
| 1731 | switch (decimator) { |
| 1732 | case 1: |
| 1733 | case 2: |
| 1734 | case 3: |
| 1735 | case 4: |
| 1736 | case 5: |
| 1737 | case 6: |
| 1738 | if (dec_mux == 1) |
| 1739 | adc_dmic_sel = 0x1; |
| 1740 | else |
| 1741 | adc_dmic_sel = 0x0; |
| 1742 | break; |
| 1743 | case 7: |
| 1744 | case 8: |
| 1745 | case 9: |
| 1746 | case 10: |
| 1747 | if ((dec_mux == 1) || (dec_mux == 2)) |
| 1748 | adc_dmic_sel = 0x1; |
| 1749 | else |
| 1750 | adc_dmic_sel = 0x0; |
| 1751 | break; |
| 1752 | default: |
| 1753 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1754 | ret = -EINVAL; |
| 1755 | goto out; |
| 1756 | } |
| 1757 | |
| 1758 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1759 | |
| 1760 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1761 | |
| 1762 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1763 | |
| 1764 | out: |
| 1765 | kfree(widget_name); |
| 1766 | return ret; |
| 1767 | } |
| 1768 | |
| 1769 | #define WCD9310_DEC_ENUM(xname, xenum) \ |
| 1770 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1771 | .info = snd_soc_info_enum_double, \ |
| 1772 | .get = snd_soc_dapm_get_enum_double, \ |
| 1773 | .put = wcd9310_put_dec_enum, \ |
| 1774 | .private_value = (unsigned long)&xenum } |
| 1775 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | static const struct snd_kcontrol_new dec1_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1777 | WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1778 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1779 | static const struct snd_kcontrol_new dec2_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1780 | WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1781 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1782 | static const struct snd_kcontrol_new dec3_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1783 | WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1784 | |
| 1785 | static const struct snd_kcontrol_new dec4_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1786 | WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1787 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1788 | static const struct snd_kcontrol_new dec5_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1789 | WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1790 | |
| 1791 | static const struct snd_kcontrol_new dec6_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1792 | WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1793 | |
| 1794 | static const struct snd_kcontrol_new dec7_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1795 | WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1796 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1797 | static const struct snd_kcontrol_new dec8_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1798 | WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1799 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1800 | static const struct snd_kcontrol_new dec9_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1801 | WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1802 | |
| 1803 | static const struct snd_kcontrol_new dec10_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1804 | WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1805 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1806 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1807 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1808 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1809 | static const struct snd_kcontrol_new iir2_inp1_mux = |
| 1810 | SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum); |
| 1811 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1812 | static const struct snd_kcontrol_new anc1_mux = |
| 1813 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1814 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1815 | static const struct snd_kcontrol_new anc2_mux = |
| 1816 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1817 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1818 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1819 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1820 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1821 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1822 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0) |
| 1823 | }; |
| 1824 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1825 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1826 | }; |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1827 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1828 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1829 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1830 | 7, 1, 0), |
| 1831 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1832 | 7, 1, 0), |
| 1833 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1834 | TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0), |
| 1835 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1836 | TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0), |
| 1837 | }; |
| 1838 | |
| 1839 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1840 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1841 | 6, 1, 0), |
| 1842 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1843 | 6, 1, 0), |
| 1844 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1845 | TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0), |
| 1846 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1847 | TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0), |
| 1848 | }; |
| 1849 | |
| 1850 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1851 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1852 | 5, 1, 0), |
| 1853 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1854 | 5, 1, 0), |
| 1855 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1856 | TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0), |
| 1857 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1858 | TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0), |
| 1859 | }; |
| 1860 | |
| 1861 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1862 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1863 | 4, 1, 0), |
| 1864 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1865 | 4, 1, 0), |
| 1866 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1867 | TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0), |
| 1868 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1869 | TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0), |
| 1870 | }; |
| 1871 | |
| 1872 | static const struct snd_kcontrol_new lineout3_pa_mix[] = { |
| 1873 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1874 | 3, 1, 0), |
| 1875 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1876 | 3, 1, 0), |
| 1877 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1878 | TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0), |
| 1879 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1880 | TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0), |
| 1881 | }; |
| 1882 | |
| 1883 | static const struct snd_kcontrol_new lineout4_pa_mix[] = { |
| 1884 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1885 | 2, 1, 0), |
| 1886 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1887 | 2, 1, 0), |
| 1888 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1889 | TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0), |
| 1890 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1891 | TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0), |
| 1892 | }; |
| 1893 | |
| 1894 | static const struct snd_kcontrol_new lineout5_pa_mix[] = { |
| 1895 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1896 | 1, 1, 0), |
| 1897 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1898 | 1, 1, 0), |
| 1899 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1900 | TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0), |
| 1901 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1902 | TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0), |
| 1903 | }; |
| 1904 | |
| 1905 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1906 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1907 | 0, 1, 0), |
| 1908 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1909 | 0, 1, 0), |
| 1910 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1911 | TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0), |
| 1912 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1913 | TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0), |
| 1914 | }; |
| 1915 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1916 | static const struct snd_kcontrol_new lineout3_ground_switch = |
| 1917 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0); |
| 1918 | |
| 1919 | static const struct snd_kcontrol_new lineout4_ground_switch = |
| 1920 | 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] | 1921 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1922 | /* virtual port entries */ |
| 1923 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1924 | struct snd_ctl_elem_value *ucontrol) |
| 1925 | { |
| 1926 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1927 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1928 | |
| 1929 | ucontrol->value.integer.value[0] = widget->value; |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1934 | struct snd_ctl_elem_value *ucontrol) |
| 1935 | { |
| 1936 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1937 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1938 | struct snd_soc_codec *codec = widget->codec; |
| 1939 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 1940 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1941 | struct soc_multi_mixer_control *mixer = |
| 1942 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1943 | u32 dai_id = widget->shift; |
| 1944 | u32 port_id = mixer->shift; |
| 1945 | u32 enable = ucontrol->value.integer.value[0]; |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 1946 | u32 vtable = vport_check_table[dai_id]; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1947 | |
| 1948 | pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__, |
| 1949 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 1950 | ucontrol->value.integer.value[0]); |
| 1951 | |
| 1952 | mutex_lock(&codec->mutex); |
| 1953 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1954 | if (dai_id != AIF1_CAP) { |
| 1955 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1956 | __func__); |
| 1957 | mutex_unlock(&codec->mutex); |
| 1958 | return -EINVAL; |
| 1959 | } |
| 1960 | } |
| 1961 | switch (dai_id) { |
| 1962 | case AIF1_CAP: |
| 1963 | case AIF2_CAP: |
| 1964 | case AIF3_CAP: |
| 1965 | /* only add to the list if value not set |
| 1966 | */ |
| 1967 | if (enable && !(widget->value & 1 << port_id)) { |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 1968 | if (tabla_p->intf_type == |
| 1969 | WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 1970 | vtable = vport_check_table[dai_id]; |
| 1971 | if (tabla_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) |
| 1972 | vtable = vport_i2s_check_table[dai_id]; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1973 | if (wcd9xxx_tx_vport_validation( |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 1974 | vtable, |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1975 | port_id, |
| 1976 | tabla_p->dai)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1977 | pr_info("%s: TX%u is used by other virtual port\n", |
| 1978 | __func__, port_id + 1); |
| 1979 | mutex_unlock(&codec->mutex); |
| 1980 | return -EINVAL; |
| 1981 | } |
| 1982 | widget->value |= 1 << port_id; |
| 1983 | list_add_tail(&core->tx_chs[port_id].list, |
| 1984 | &tabla_p->dai[dai_id].wcd9xxx_ch_list |
| 1985 | ); |
| 1986 | } else if (!enable && (widget->value & 1 << port_id)) { |
| 1987 | widget->value &= ~(1 << port_id); |
| 1988 | list_del_init(&core->tx_chs[port_id].list); |
| 1989 | } else { |
| 1990 | if (enable) |
| 1991 | pr_info("%s: TX%u port is used by this virtual port\n", |
| 1992 | __func__, port_id + 1); |
| 1993 | else |
| 1994 | pr_info("%s: TX%u port is not used by this virtual port\n", |
| 1995 | __func__, port_id + 1); |
| 1996 | /* avoid update power function */ |
| 1997 | mutex_unlock(&codec->mutex); |
| 1998 | return 0; |
| 1999 | } |
| 2000 | break; |
| 2001 | default: |
| 2002 | pr_err("Unknown AIF %d\n", dai_id); |
| 2003 | mutex_unlock(&codec->mutex); |
| 2004 | return -EINVAL; |
| 2005 | } |
| 2006 | pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__, |
| 2007 | widget->name, widget->sname, widget->value, widget->shift); |
| 2008 | |
| 2009 | snd_soc_dapm_mixer_update_power(widget, kcontrol, enable); |
| 2010 | |
| 2011 | mutex_unlock(&codec->mutex); |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 2016 | struct snd_ctl_elem_value *ucontrol) |
| 2017 | { |
| 2018 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2019 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2020 | |
| 2021 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2022 | return 0; |
| 2023 | } |
| 2024 | |
| 2025 | static const char *const slim_rx_mux_text[] = { |
| 2026 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB" |
| 2027 | }; |
| 2028 | |
| 2029 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 2030 | struct snd_ctl_elem_value *ucontrol) |
| 2031 | { |
| 2032 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2033 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2034 | struct snd_soc_codec *codec = widget->codec; |
| 2035 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 2036 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 2037 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2038 | u32 port_id = widget->shift; |
| 2039 | |
| 2040 | pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__, |
| 2041 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 2042 | ucontrol->value.enumerated.item[0]); |
| 2043 | |
| 2044 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2045 | |
| 2046 | mutex_lock(&codec->mutex); |
| 2047 | |
| 2048 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 2049 | if (widget->value > 1) { |
| 2050 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 2051 | __func__); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2052 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | /* value need to match the Virtual port and AIF number |
| 2056 | */ |
| 2057 | switch (widget->value) { |
| 2058 | case 0: |
| 2059 | list_del_init(&core->rx_chs[port_id].list); |
| 2060 | break; |
| 2061 | case 1: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2062 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2063 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2064 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2065 | list_add_tail(&core->rx_chs[port_id].list, |
| 2066 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 2067 | break; |
| 2068 | case 2: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2069 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2070 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2071 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2072 | list_add_tail(&core->rx_chs[port_id].list, |
| 2073 | &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 2074 | break; |
| 2075 | case 3: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2076 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2077 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2078 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2079 | list_add_tail(&core->rx_chs[port_id].list, |
| 2080 | &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 2081 | break; |
| 2082 | default: |
| 2083 | pr_err("Unknown AIF %d\n", widget->value); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2084 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e); |
| 2088 | |
| 2089 | mutex_unlock(&codec->mutex); |
| 2090 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2091 | |
| 2092 | pr_err: |
| 2093 | pr_err("%s: RX%u is used by current requesting AIF_PB itself\n", |
| 2094 | __func__, port_id + 1); |
Santosh Mardi | 2a831d7 | 2012-11-07 20:45:52 +0530 | [diff] [blame] | 2095 | mutex_unlock(&codec->mutex); |
| 2096 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2097 | err: |
| 2098 | mutex_unlock(&codec->mutex); |
| 2099 | return -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | static const struct soc_enum slim_rx_mux_enum = |
| 2103 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); |
| 2104 | |
| 2105 | static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = { |
| 2106 | SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, |
| 2107 | slim_rx_mux_get, slim_rx_mux_put), |
| 2108 | SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, |
| 2109 | slim_rx_mux_get, slim_rx_mux_put), |
| 2110 | SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, |
| 2111 | slim_rx_mux_get, slim_rx_mux_put), |
| 2112 | SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, |
| 2113 | slim_rx_mux_get, slim_rx_mux_put), |
| 2114 | SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, |
| 2115 | slim_rx_mux_get, slim_rx_mux_put), |
| 2116 | SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum, |
| 2117 | slim_rx_mux_get, slim_rx_mux_put), |
| 2118 | SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum, |
| 2119 | slim_rx_mux_get, slim_rx_mux_put), |
| 2120 | }; |
| 2121 | |
| 2122 | static const struct snd_kcontrol_new aif_cap_mixer[] = { |
| 2123 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0, |
| 2124 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2125 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0, |
| 2126 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2127 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0, |
| 2128 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2129 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0, |
| 2130 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2131 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0, |
| 2132 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2133 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0, |
| 2134 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2135 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0, |
| 2136 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2137 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0, |
| 2138 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2139 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0, |
| 2140 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2141 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0, |
| 2142 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2143 | }; |
| 2144 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2145 | static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2146 | int enable) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2147 | { |
| 2148 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2149 | |
| 2150 | pr_debug("%s %d\n", __func__, enable); |
| 2151 | |
| 2152 | if (enable) { |
| 2153 | tabla->adc_count++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2154 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2); |
| 2155 | } else { |
| 2156 | tabla->adc_count--; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2157 | if (!tabla->adc_count) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2158 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2159 | 0x2, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 2164 | struct snd_kcontrol *kcontrol, int event) |
| 2165 | { |
| 2166 | struct snd_soc_codec *codec = w->codec; |
| 2167 | u16 adc_reg; |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2168 | u8 init_bit_shift; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2169 | |
| 2170 | pr_debug("%s %d\n", __func__, event); |
| 2171 | |
| 2172 | if (w->reg == TABLA_A_TX_1_2_EN) |
| 2173 | adc_reg = TABLA_A_TX_1_2_TEST_CTL; |
| 2174 | else if (w->reg == TABLA_A_TX_3_4_EN) |
| 2175 | adc_reg = TABLA_A_TX_3_4_TEST_CTL; |
| 2176 | else if (w->reg == TABLA_A_TX_5_6_EN) |
| 2177 | adc_reg = TABLA_A_TX_5_6_TEST_CTL; |
| 2178 | else { |
| 2179 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 2180 | return -EINVAL; |
| 2181 | } |
| 2182 | |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2183 | if (w->shift == 3) |
| 2184 | init_bit_shift = 6; |
| 2185 | else if (w->shift == 7) |
| 2186 | init_bit_shift = 7; |
| 2187 | else { |
| 2188 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 2189 | __func__); |
| 2190 | return -EINVAL; |
| 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2195 | switch (event) { |
| 2196 | case SND_SOC_DAPM_PRE_PMU: |
| 2197 | tabla_codec_enable_adc_block(codec, 1); |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2198 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 2199 | 1 << init_bit_shift); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2200 | break; |
| 2201 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2202 | |
| 2203 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 2204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2205 | break; |
| 2206 | case SND_SOC_DAPM_POST_PMD: |
| 2207 | tabla_codec_enable_adc_block(codec, 0); |
| 2208 | break; |
| 2209 | } |
| 2210 | return 0; |
| 2211 | } |
| 2212 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2213 | static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 2214 | { |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2215 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2216 | 0x80); |
| 2217 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 2218 | 0x04); |
| 2219 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2220 | 0x01); |
| 2221 | usleep_range(1000, 1000); |
| 2222 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2223 | 0x00); |
| 2224 | } |
| 2225 | |
| 2226 | static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 2227 | enum tabla_bandgap_type choice) |
| 2228 | { |
| 2229 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2230 | |
| 2231 | /* TODO lock resources accessed by audio streams and threaded |
| 2232 | * interrupt handlers |
| 2233 | */ |
| 2234 | |
| 2235 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
| 2236 | tabla->bandgap_type); |
| 2237 | |
| 2238 | if (tabla->bandgap_type == choice) |
| 2239 | return; |
| 2240 | |
| 2241 | if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) && |
| 2242 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 2243 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2244 | } else if (choice == TABLA_BANDGAP_MBHC_MODE) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2245 | /* bandgap mode becomes fast, |
| 2246 | * mclk should be off or clk buff source souldn't be VBG |
| 2247 | * Let's turn off mclk always */ |
| 2248 | WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2)); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2249 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 2250 | 0x2); |
| 2251 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2252 | 0x80); |
| 2253 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 2254 | 0x4); |
| 2255 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2256 | 0x01); |
| 2257 | usleep_range(1000, 1000); |
| 2258 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2259 | 0x00); |
| 2260 | } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) && |
| 2261 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2262 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2263 | usleep_range(100, 100); |
| 2264 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2265 | } else if (choice == TABLA_BANDGAP_OFF) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2266 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2267 | } else { |
| 2268 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 2269 | } |
| 2270 | tabla->bandgap_type = choice; |
| 2271 | } |
| 2272 | |
| 2273 | static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 2274 | { |
| 2275 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2276 | pr_debug("%s\n", __func__); |
| 2277 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2278 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2279 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 2280 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2281 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2282 | tabla->clock_active = false; |
| 2283 | } |
| 2284 | |
| 2285 | static int tabla_codec_mclk_index(const struct tabla_priv *tabla) |
| 2286 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2287 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2288 | return 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2289 | else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2290 | return 1; |
| 2291 | else { |
| 2292 | BUG_ON(1); |
| 2293 | return -EINVAL; |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 2298 | { |
| 2299 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2300 | |
| 2301 | if (enable) { |
| 2302 | tabla->rx_bias_count++; |
| 2303 | if (tabla->rx_bias_count == 1) |
| 2304 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2305 | 0x80, 0x80); |
| 2306 | } else { |
| 2307 | tabla->rx_bias_count--; |
| 2308 | if (!tabla->rx_bias_count) |
| 2309 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2310 | 0x80, 0x00); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 2315 | int enable) |
| 2316 | { |
| 2317 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2318 | |
| 2319 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 2320 | if (enable) { |
| 2321 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2322 | /* bandgap mode to fast */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2323 | snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17); |
| 2324 | usleep_range(5, 5); |
| 2325 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2326 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2327 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2328 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2329 | usleep_range(10, 10); |
| 2330 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2331 | usleep_range(10000, 10000); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2332 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 2333 | } else { |
| 2334 | snd_soc_update_bits(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x1, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2335 | 0); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2336 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2337 | /* clk source to ext clk and clk buff ref to VBG */ |
| 2338 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2339 | } |
| 2340 | tabla->config_mode_active = enable ? true : false; |
| 2341 | |
| 2342 | return 0; |
| 2343 | } |
| 2344 | |
| 2345 | static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2346 | int config_mode) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2347 | { |
| 2348 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2349 | |
| 2350 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 2351 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2352 | /* transit to RCO requires mclk off */ |
| 2353 | WARN_ON(snd_soc_read(codec, TABLA_A_CLK_BUFF_EN2) & (1 << 2)); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2354 | if (config_mode) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2355 | /* enable RCO and switch to it */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2356 | tabla_codec_enable_config_mode(codec, 1); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2357 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2358 | usleep_range(1000, 1000); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2359 | } else { |
| 2360 | /* switch to MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2361 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 2362 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2363 | if (tabla->mbhc_polling_active) { |
| 2364 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 2365 | tabla_codec_enable_config_mode(codec, 0); |
| 2366 | } |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2369 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2370 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2371 | /* on MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2372 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 2373 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 2374 | usleep_range(50, 50); |
| 2375 | tabla->clock_active = true; |
| 2376 | return 0; |
| 2377 | } |
| 2378 | |
| 2379 | static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 2380 | struct snd_kcontrol *kcontrol, int event) |
| 2381 | { |
| 2382 | struct snd_soc_codec *codec = w->codec; |
| 2383 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2384 | |
| 2385 | pr_debug("%s: %d\n", __func__, event); |
| 2386 | |
| 2387 | switch (event) { |
| 2388 | case SND_SOC_DAPM_PRE_PMU: |
| 2389 | tabla_codec_enable_bandgap(codec, |
| 2390 | TABLA_BANDGAP_AUDIO_MODE); |
| 2391 | tabla_enable_rx_bias(codec, 1); |
| 2392 | |
| 2393 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2394 | 0x08, 0x08); |
| 2395 | /* Enable Zero Cross detect for AUX PGA channel |
| 2396 | * and set the initial AUX PGA gain to NEG_0P0_DB |
| 2397 | * to avoid glitches. |
| 2398 | */ |
| 2399 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2400 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2401 | 0x20, 0x20); |
| 2402 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2403 | TABLA_A_AUX_L_GAIN); |
| 2404 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2405 | } else { |
| 2406 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2407 | 0x20, 0x20); |
| 2408 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2409 | TABLA_A_AUX_R_GAIN); |
| 2410 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2411 | } |
| 2412 | if (tabla->aux_pga_cnt++ == 1 |
| 2413 | && !tabla->mclk_enabled) { |
| 2414 | tabla_codec_enable_clock_block(codec, 1); |
| 2415 | pr_debug("AUX PGA enabled RC osc\n"); |
| 2416 | } |
| 2417 | break; |
| 2418 | |
| 2419 | case SND_SOC_DAPM_POST_PMU: |
| 2420 | if (w->reg == TABLA_A_AUX_L_EN) |
| 2421 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2422 | tabla->aux_l_gain); |
| 2423 | else |
| 2424 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2425 | tabla->aux_r_gain); |
| 2426 | break; |
| 2427 | |
| 2428 | case SND_SOC_DAPM_PRE_PMD: |
| 2429 | /* Mute AUX PGA channel in use before disabling AUX PGA */ |
| 2430 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2431 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2432 | TABLA_A_AUX_L_GAIN); |
| 2433 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2434 | } else { |
| 2435 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2436 | TABLA_A_AUX_R_GAIN); |
| 2437 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2438 | } |
| 2439 | break; |
| 2440 | |
| 2441 | case SND_SOC_DAPM_POST_PMD: |
| 2442 | tabla_enable_rx_bias(codec, 0); |
| 2443 | |
| 2444 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2445 | 0x08, 0x00); |
| 2446 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2447 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2448 | tabla->aux_l_gain); |
| 2449 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2450 | 0x20, 0x00); |
| 2451 | } else { |
| 2452 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2453 | tabla->aux_r_gain); |
| 2454 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2455 | 0x20, 0x00); |
| 2456 | } |
| 2457 | |
| 2458 | if (tabla->aux_pga_cnt-- == 0) { |
| 2459 | if (tabla->mbhc_polling_active) |
| 2460 | tabla_codec_enable_bandgap(codec, |
| 2461 | TABLA_BANDGAP_MBHC_MODE); |
| 2462 | else |
| 2463 | tabla_codec_enable_bandgap(codec, |
| 2464 | TABLA_BANDGAP_OFF); |
| 2465 | |
| 2466 | if (!tabla->mclk_enabled && |
| 2467 | !tabla->mbhc_polling_active) { |
| 2468 | tabla_codec_enable_clock_block(codec, 0); |
| 2469 | } |
| 2470 | } |
| 2471 | break; |
| 2472 | } |
| 2473 | return 0; |
| 2474 | } |
| 2475 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2476 | static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 2477 | struct snd_kcontrol *kcontrol, int event) |
| 2478 | { |
| 2479 | struct snd_soc_codec *codec = w->codec; |
| 2480 | u16 lineout_gain_reg; |
| 2481 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2482 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2483 | |
| 2484 | switch (w->shift) { |
| 2485 | case 0: |
| 2486 | lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN; |
| 2487 | break; |
| 2488 | case 1: |
| 2489 | lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN; |
| 2490 | break; |
| 2491 | case 2: |
| 2492 | lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN; |
| 2493 | break; |
| 2494 | case 3: |
| 2495 | lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN; |
| 2496 | break; |
| 2497 | case 4: |
| 2498 | lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN; |
| 2499 | break; |
| 2500 | default: |
| 2501 | pr_err("%s: Error, incorrect lineout register value\n", |
| 2502 | __func__); |
| 2503 | return -EINVAL; |
| 2504 | } |
| 2505 | |
| 2506 | switch (event) { |
| 2507 | case SND_SOC_DAPM_PRE_PMU: |
| 2508 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 2509 | break; |
| 2510 | case SND_SOC_DAPM_POST_PMU: |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2511 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2512 | __func__, w->name); |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2513 | usleep_range(16000, 16000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2514 | break; |
| 2515 | case SND_SOC_DAPM_POST_PMD: |
| 2516 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 2517 | break; |
| 2518 | } |
| 2519 | return 0; |
| 2520 | } |
| 2521 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2522 | |
| 2523 | static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2524 | struct snd_kcontrol *kcontrol, int event) |
| 2525 | { |
| 2526 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2527 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2528 | u8 dmic_clk_en; |
| 2529 | s32 *dmic_clk_cnt; |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2530 | unsigned int dmic; |
| 2531 | int ret; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2532 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2533 | ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic); |
| 2534 | if (ret < 0) { |
| 2535 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2536 | return -EINVAL; |
| 2537 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2538 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2539 | switch (dmic) { |
| 2540 | case 1: |
| 2541 | case 2: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2542 | dmic_clk_en = 0x01; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2543 | dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt); |
| 2544 | |
| 2545 | pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 2546 | __func__, event, dmic, *dmic_clk_cnt); |
| 2547 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2548 | break; |
| 2549 | |
| 2550 | case 3: |
| 2551 | case 4: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2552 | dmic_clk_en = 0x04; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2553 | dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt); |
| 2554 | |
| 2555 | pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 2556 | __func__, event, dmic, *dmic_clk_cnt); |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2557 | break; |
| 2558 | |
| 2559 | case 5: |
| 2560 | case 6: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2561 | dmic_clk_en = 0x10; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2562 | dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt); |
| 2563 | |
| 2564 | pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n", |
| 2565 | __func__, event, dmic, *dmic_clk_cnt); |
| 2566 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2567 | break; |
| 2568 | |
| 2569 | default: |
| 2570 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2571 | return -EINVAL; |
| 2572 | } |
| 2573 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2574 | switch (event) { |
| 2575 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2576 | |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2577 | (*dmic_clk_cnt)++; |
| 2578 | if (*dmic_clk_cnt == 1) |
| 2579 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2580 | dmic_clk_en, dmic_clk_en); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2581 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2582 | break; |
| 2583 | case SND_SOC_DAPM_POST_PMD: |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2584 | |
| 2585 | (*dmic_clk_cnt)--; |
| 2586 | if (*dmic_clk_cnt == 0) |
| 2587 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2588 | dmic_clk_en, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2589 | break; |
| 2590 | } |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2594 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2595 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2596 | static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 2597 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2598 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2599 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
| 2600 | int mbhc_state = tabla->mbhc_state; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2601 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2602 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2603 | if (!tabla->mbhc_polling_active) { |
| 2604 | pr_debug("Polling is not active, do not start polling\n"); |
| 2605 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2606 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2607 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2608 | |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 2609 | if (tabla->no_mic_headset_override) { |
| 2610 | pr_debug("%s setting button threshold to min", __func__); |
| 2611 | /* set to min */ |
| 2612 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80); |
| 2613 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00); |
| 2614 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80); |
| 2615 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00); |
| 2616 | } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) { |
| 2617 | pr_debug("%s recovering MBHC state machine\n", __func__); |
| 2618 | tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
| 2619 | /* set to max button press threshold */ |
| 2620 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F); |
| 2621 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF); |
| 2622 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 2623 | (TABLA_IS_1_X(tabla_core->version) ? |
| 2624 | 0x07 : 0x7F)); |
| 2625 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF); |
| 2626 | /* set to max */ |
| 2627 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F); |
| 2628 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2631 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
| 2632 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2633 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2634 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2635 | } |
| 2636 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2637 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2638 | static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 2639 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2640 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2641 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2642 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2643 | if (!tabla->mbhc_polling_active) { |
| 2644 | pr_debug("polling not active, nothing to pause\n"); |
| 2645 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2646 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2647 | |
Simmi Pateriya | 1b9a309 | 2013-01-02 11:49:26 +0530 | [diff] [blame] | 2648 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 2649 | msleep(250); |
| 2650 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2651 | 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] | 2652 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2655 | 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] | 2656 | { |
| 2657 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2658 | u8 reg_mode_val, cur_mode_val; |
| 2659 | bool mbhc_was_polling = false; |
| 2660 | |
| 2661 | if (mode) |
| 2662 | reg_mode_val = TABLA_CFILT_FAST_MODE; |
| 2663 | else |
| 2664 | reg_mode_val = TABLA_CFILT_SLOW_MODE; |
| 2665 | |
| 2666 | cur_mode_val = snd_soc_read(codec, |
| 2667 | tabla->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 2668 | |
| 2669 | if (cur_mode_val != reg_mode_val) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2670 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2671 | if (tabla->mbhc_polling_active) { |
| 2672 | tabla_codec_pause_hs_polling(codec); |
| 2673 | mbhc_was_polling = true; |
| 2674 | } |
| 2675 | snd_soc_update_bits(codec, |
| 2676 | tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 2677 | if (mbhc_was_polling) |
| 2678 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2679 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2680 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
| 2681 | cur_mode_val, reg_mode_val); |
| 2682 | } else { |
| 2683 | pr_debug("%s: CFILT Value is already %x\n", |
| 2684 | __func__, cur_mode_val); |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 2689 | u8 cfilt_sel, int inc) |
| 2690 | { |
| 2691 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2692 | u32 *cfilt_cnt_ptr = NULL; |
| 2693 | u16 micb_cfilt_reg; |
| 2694 | |
| 2695 | switch (cfilt_sel) { |
| 2696 | case TABLA_CFILT1_SEL: |
| 2697 | cfilt_cnt_ptr = &tabla->cfilt1_cnt; |
| 2698 | micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL; |
| 2699 | break; |
| 2700 | case TABLA_CFILT2_SEL: |
| 2701 | cfilt_cnt_ptr = &tabla->cfilt2_cnt; |
| 2702 | micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL; |
| 2703 | break; |
| 2704 | case TABLA_CFILT3_SEL: |
| 2705 | cfilt_cnt_ptr = &tabla->cfilt3_cnt; |
| 2706 | micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL; |
| 2707 | break; |
| 2708 | default: |
| 2709 | return; /* should not happen */ |
| 2710 | } |
| 2711 | |
| 2712 | if (inc) { |
| 2713 | if (!(*cfilt_cnt_ptr)++) { |
| 2714 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 2715 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2716 | tabla_codec_switch_cfilt_mode(codec, 0); |
| 2717 | |
| 2718 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 2719 | } |
| 2720 | } else { |
| 2721 | /* check if count not zero, decrement |
| 2722 | * then check if zero, go ahead disable cfilter |
| 2723 | */ |
| 2724 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 2725 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 2726 | |
| 2727 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 2728 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2729 | tabla_codec_switch_cfilt_mode(codec, 1); |
| 2730 | } |
| 2731 | } |
| 2732 | } |
| 2733 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2734 | static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 2735 | { |
| 2736 | int rc = -EINVAL; |
| 2737 | unsigned min_mv, max_mv; |
| 2738 | |
| 2739 | switch (ldoh_v) { |
| 2740 | case TABLA_LDOH_1P95_V: |
| 2741 | min_mv = 160; |
| 2742 | max_mv = 1800; |
| 2743 | break; |
| 2744 | case TABLA_LDOH_2P35_V: |
| 2745 | min_mv = 200; |
| 2746 | max_mv = 2200; |
| 2747 | break; |
| 2748 | case TABLA_LDOH_2P75_V: |
| 2749 | min_mv = 240; |
| 2750 | max_mv = 2600; |
| 2751 | break; |
| 2752 | case TABLA_LDOH_2P85_V: |
| 2753 | min_mv = 250; |
| 2754 | max_mv = 2700; |
| 2755 | break; |
| 2756 | default: |
| 2757 | goto done; |
| 2758 | } |
| 2759 | |
| 2760 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 2761 | goto done; |
| 2762 | |
| 2763 | for (rc = 4; rc <= 44; rc++) { |
| 2764 | min_mv = max_mv * (rc) / 44; |
| 2765 | if (min_mv >= cfilt_mv) { |
| 2766 | rc -= 4; |
| 2767 | break; |
| 2768 | } |
| 2769 | } |
| 2770 | done: |
| 2771 | return rc; |
| 2772 | } |
| 2773 | |
| 2774 | static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec) |
| 2775 | { |
| 2776 | u8 hph_reg_val = 0; |
| 2777 | hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN); |
| 2778 | |
| 2779 | return (hph_reg_val & 0x30) ? true : false; |
| 2780 | } |
| 2781 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2782 | static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 2783 | { |
| 2784 | u8 hph_reg_val = 0; |
| 2785 | if (left) |
| 2786 | hph_reg_val = snd_soc_read(codec, |
| 2787 | TABLA_A_RX_HPH_L_DAC_CTL); |
| 2788 | else |
| 2789 | hph_reg_val = snd_soc_read(codec, |
| 2790 | TABLA_A_RX_HPH_R_DAC_CTL); |
| 2791 | |
| 2792 | return (hph_reg_val & 0xC0) ? true : false; |
| 2793 | } |
| 2794 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2795 | static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 2796 | { |
| 2797 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 2798 | } |
| 2799 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2800 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2801 | static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec, |
| 2802 | int usec) |
| 2803 | { |
| 2804 | int cfilt_k_val; |
| 2805 | bool set = true; |
| 2806 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2807 | |
| 2808 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 2809 | tabla->mbhc_micbias_switched) { |
| 2810 | pr_debug("%s: set mic V to micbias V\n", __func__); |
| 2811 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2812 | tabla_turn_onoff_override(codec, true); |
| 2813 | while (1) { |
| 2814 | cfilt_k_val = tabla_find_k_value( |
| 2815 | tabla->pdata->micbias.ldoh_v, |
| 2816 | set ? tabla->mbhc_data.micb_mv : |
| 2817 | VDDIO_MICBIAS_MV); |
| 2818 | snd_soc_update_bits(codec, |
| 2819 | tabla->mbhc_bias_regs.cfilt_val, |
| 2820 | 0xFC, (cfilt_k_val << 2)); |
| 2821 | if (!set) |
| 2822 | break; |
| 2823 | usleep_range(usec, usec); |
| 2824 | set = false; |
| 2825 | } |
| 2826 | tabla_turn_onoff_override(codec, false); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | /* called under codec_resource_lock acquisition */ |
| 2831 | static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2832 | int vddio_switch, bool restartpolling, |
| 2833 | bool checkpolling) |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2834 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2835 | int cfilt_k_val; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2836 | bool override; |
| 2837 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2838 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2839 | if (vddio_switch && !tabla->mbhc_micbias_switched && |
| 2840 | (!checkpolling || tabla->mbhc_polling_active)) { |
| 2841 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2842 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2843 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 2844 | if (!override) |
| 2845 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2846 | /* Adjust threshold if Mic Bias voltage changes */ |
| 2847 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2848 | cfilt_k_val = tabla_find_k_value( |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2849 | tabla->pdata->micbias.ldoh_v, |
| 2850 | VDDIO_MICBIAS_MV); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2851 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2852 | tabla->mbhc_bias_regs.cfilt_val, |
| 2853 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2854 | usleep_range(cfilt_adjust_ms * 1000, |
| 2855 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2856 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2857 | tabla->mbhc_data.adj_v_ins_hu & 0xFF); |
| 2858 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2859 | (tabla->mbhc_data.adj_v_ins_hu >> 8) & |
| 2860 | 0xFF); |
| 2861 | pr_debug("%s: Programmed MBHC thresholds to VDDIO\n", |
| 2862 | __func__); |
| 2863 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2864 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2865 | /* enable MIC BIAS Switch to VDDIO */ |
| 2866 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2867 | 0x80, 0x80); |
| 2868 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2869 | 0x10, 0x00); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2870 | if (!override) |
| 2871 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2872 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2873 | tabla_codec_start_hs_polling(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2874 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2875 | tabla->mbhc_micbias_switched = true; |
| 2876 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2877 | } else if (!vddio_switch && tabla->mbhc_micbias_switched) { |
| 2878 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2879 | restartpolling) |
| 2880 | tabla_codec_pause_hs_polling(codec); |
| 2881 | /* Reprogram thresholds */ |
| 2882 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 2883 | cfilt_k_val = tabla_find_k_value( |
| 2884 | tabla->pdata->micbias.ldoh_v, |
| 2885 | tabla->mbhc_data.micb_mv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2886 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2887 | tabla->mbhc_bias_regs.cfilt_val, |
| 2888 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2889 | usleep_range(cfilt_adjust_ms * 1000, |
| 2890 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2891 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2892 | tabla->mbhc_data.v_ins_hu & 0xFF); |
| 2893 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2894 | (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF); |
| 2895 | pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n", |
| 2896 | __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2897 | } |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2898 | |
| 2899 | /* Disable MIC BIAS Switch to VDDIO */ |
| 2900 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2901 | 0x80, 0x00); |
| 2902 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2903 | 0x10, 0x00); |
| 2904 | |
| 2905 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2906 | restartpolling) |
| 2907 | tabla_codec_start_hs_polling(codec); |
| 2908 | |
| 2909 | tabla->mbhc_micbias_switched = false; |
| 2910 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2914 | static void tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2915 | int vddio_switch) |
| 2916 | { |
| 2917 | return __tabla_codec_switch_micbias(codec, vddio_switch, true, true); |
| 2918 | } |
| 2919 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2920 | static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2921 | struct snd_kcontrol *kcontrol, int event) |
| 2922 | { |
| 2923 | struct snd_soc_codec *codec = w->codec; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2924 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2925 | u16 micb_int_reg; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2926 | int micb_line; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2927 | u8 cfilt_sel_val = 0; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2928 | char *internal1_text = "Internal1"; |
| 2929 | char *internal2_text = "Internal2"; |
| 2930 | char *internal3_text = "Internal3"; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2931 | const char *micbias1_text = "MIC BIAS1 "; |
| 2932 | const char *micbias2_text = "MIC BIAS2 "; |
| 2933 | const char *micbias3_text = "MIC BIAS3 "; |
| 2934 | const char *micbias4_text = "MIC BIAS4 "; |
| 2935 | u32 *micbias_enable_count; |
| 2936 | u16 wreg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2937 | |
| 2938 | pr_debug("%s %d\n", __func__, event); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2939 | if (strnstr(w->name, micbias1_text, strlen(micbias1_text))) { |
| 2940 | wreg = TABLA_A_MICB_1_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2941 | micb_int_reg = TABLA_A_MICB_1_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2942 | cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2943 | micb_line = TABLA_MICBIAS1; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2944 | } else if (strnstr(w->name, micbias2_text, strlen(micbias2_text))) { |
| 2945 | wreg = TABLA_A_MICB_2_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2946 | micb_int_reg = TABLA_A_MICB_2_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2947 | cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2948 | micb_line = TABLA_MICBIAS2; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2949 | } else if (strnstr(w->name, micbias3_text, strlen(micbias3_text))) { |
| 2950 | wreg = TABLA_A_MICB_3_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2951 | micb_int_reg = TABLA_A_MICB_3_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2952 | cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2953 | micb_line = TABLA_MICBIAS3; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2954 | } else if (strnstr(w->name, micbias4_text, strlen(micbias4_text))) { |
| 2955 | wreg = tabla->reg_addr.micb_4_ctl; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2956 | micb_int_reg = tabla->reg_addr.micb_4_int_rbias; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2957 | cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2958 | micb_line = TABLA_MICBIAS4; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2959 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2960 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 2961 | return -EINVAL; |
| 2962 | } |
| 2963 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2964 | micbias_enable_count = &tabla->micbias_enable_count[micb_line]; |
| 2965 | pr_debug("%s: counter %d\n", __func__, *micbias_enable_count); |
| 2966 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2967 | switch (event) { |
| 2968 | case SND_SOC_DAPM_PRE_PMU: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2969 | if (++*micbias_enable_count > 1) { |
| 2970 | pr_debug("%s: do nothing, counter %d\n", |
| 2971 | __func__, *micbias_enable_count); |
| 2972 | break; |
| 2973 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2974 | /* Decide whether to switch the micbias for MBHC */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2975 | if (wreg == tabla->mbhc_bias_regs.ctl_reg) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2976 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2977 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2978 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2979 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2980 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2981 | snd_soc_update_bits(codec, wreg, 0x0E, 0x0A); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2982 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2983 | |
| 2984 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2985 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2986 | else if (strnstr(w->name, internal2_text, 30)) |
| 2987 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 2988 | else if (strnstr(w->name, internal3_text, 30)) |
| 2989 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 2990 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2991 | snd_soc_update_bits(codec, wreg, 1 << 7, 1 << 7); |
| 2992 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2993 | break; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2994 | case SND_SOC_DAPM_POST_PMU: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2995 | if (*micbias_enable_count > 1) { |
| 2996 | pr_debug("%s: do nothing, counter %d\n", |
| 2997 | __func__, *micbias_enable_count); |
| 2998 | break; |
| 2999 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3000 | usleep_range(20000, 20000); |
| 3001 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3002 | if (tabla->mbhc_polling_active && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3003 | tabla->mbhc_cfg.micbias == micb_line) { |
| 3004 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3005 | tabla_codec_pause_hs_polling(codec); |
| 3006 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3007 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3008 | } |
| 3009 | break; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3010 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3011 | case SND_SOC_DAPM_POST_PMD: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3012 | if (--*micbias_enable_count > 0) { |
| 3013 | pr_debug("%s: do nothing, counter %d\n", |
| 3014 | __func__, *micbias_enable_count); |
| 3015 | break; |
| 3016 | } |
| 3017 | |
| 3018 | snd_soc_update_bits(codec, wreg, 1 << 7, 0); |
| 3019 | |
| 3020 | if ((wreg == tabla->mbhc_bias_regs.ctl_reg) && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3021 | tabla_is_hph_pa_on(codec)) { |
| 3022 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3023 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3024 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3025 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3026 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3027 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3028 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3029 | else if (strnstr(w->name, internal2_text, 30)) |
| 3030 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 3031 | else if (strnstr(w->name, internal3_text, 30)) |
| 3032 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 3033 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3034 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3035 | break; |
| 3036 | } |
| 3037 | |
| 3038 | return 0; |
| 3039 | } |
| 3040 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3041 | |
| 3042 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 3043 | { |
| 3044 | struct delayed_work *hpf_delayed_work; |
| 3045 | struct hpf_work *hpf_work; |
| 3046 | struct tabla_priv *tabla; |
| 3047 | struct snd_soc_codec *codec; |
| 3048 | u16 tx_mux_ctl_reg; |
| 3049 | u8 hpf_cut_of_freq; |
| 3050 | |
| 3051 | hpf_delayed_work = to_delayed_work(work); |
| 3052 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 3053 | tabla = hpf_work->tabla; |
| 3054 | codec = hpf_work->tabla->codec; |
| 3055 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 3056 | |
| 3057 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + |
| 3058 | (hpf_work->decimator - 1) * 8; |
| 3059 | |
| 3060 | pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__, |
| 3061 | hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 3062 | |
| 3063 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 3064 | } |
| 3065 | |
| 3066 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 3067 | #define CF_MIN_3DB_4HZ 0x0 |
| 3068 | #define CF_MIN_3DB_75HZ 0x1 |
| 3069 | #define CF_MIN_3DB_150HZ 0x2 |
| 3070 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3071 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 3072 | struct snd_kcontrol *kcontrol, int event); |
| 3073 | |
| 3074 | static int tabla_codec_enable_micbias_power(struct snd_soc_dapm_widget *w, |
| 3075 | struct snd_kcontrol *kcontrol, |
| 3076 | int event) |
| 3077 | { |
| 3078 | struct snd_soc_codec *codec = w->codec; |
| 3079 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3080 | |
| 3081 | pr_debug("%s %d\n", __func__, event); |
| 3082 | |
| 3083 | switch (event) { |
| 3084 | case SND_SOC_DAPM_PRE_PMU: |
| 3085 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, true); |
| 3086 | tabla_codec_enable_ldo_h(w, kcontrol, event); |
| 3087 | tabla_codec_enable_micbias(w, kcontrol, event); |
| 3088 | break; |
| 3089 | case SND_SOC_DAPM_POST_PMU: |
| 3090 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, true); |
| 3091 | break; |
| 3092 | case SND_SOC_DAPM_POST_PMD: |
| 3093 | tabla_codec_enable_micbias(w, kcontrol, event); |
| 3094 | tabla_codec_enable_ldo_h(w, kcontrol, event); |
| 3095 | break; |
| 3096 | } |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3100 | static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 3101 | struct snd_kcontrol *kcontrol, int event) |
| 3102 | { |
| 3103 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3104 | unsigned int decimator; |
| 3105 | char *dec_name = NULL; |
| 3106 | char *widget_name = NULL; |
| 3107 | char *temp; |
| 3108 | int ret = 0; |
| 3109 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 3110 | u8 dec_hpf_cut_of_freq; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3111 | int offset; |
| 3112 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3113 | |
| 3114 | pr_debug("%s %d\n", __func__, event); |
| 3115 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3116 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 3117 | if (!widget_name) |
| 3118 | return -ENOMEM; |
| 3119 | temp = widget_name; |
| 3120 | |
| 3121 | dec_name = strsep(&widget_name, " "); |
| 3122 | widget_name = temp; |
| 3123 | if (!dec_name) { |
| 3124 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 3125 | ret = -EINVAL; |
| 3126 | goto out; |
| 3127 | } |
| 3128 | |
| 3129 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 3130 | if (ret < 0) { |
| 3131 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 3132 | ret = -EINVAL; |
| 3133 | goto out; |
| 3134 | } |
| 3135 | |
| 3136 | pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__, |
| 3137 | w->name, dec_name, decimator); |
| 3138 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3139 | if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3140 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3141 | offset = 0; |
| 3142 | } 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] | 3143 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3144 | offset = 8; |
| 3145 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3146 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 3147 | return -EINVAL; |
| 3148 | } |
| 3149 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3150 | tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1); |
| 3151 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 3152 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3153 | switch (event) { |
| 3154 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3155 | |
| 3156 | // Enableable TX digital mute */ |
| 3157 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3158 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3159 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 3160 | 1 << w->shift); |
| 3161 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3162 | |
| 3163 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 3164 | |
| 3165 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 3166 | |
| 3167 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 3168 | dec_hpf_cut_of_freq; |
| 3169 | |
| 3170 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 3171 | |
| 3172 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 3173 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3174 | CF_MIN_3DB_150HZ << 4); |
| 3175 | } |
| 3176 | |
| 3177 | /* enable HPF */ |
| 3178 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 3179 | |
| 3180 | break; |
| 3181 | |
| 3182 | case SND_SOC_DAPM_POST_PMU: |
| 3183 | |
| 3184 | /* Disable TX digital mute */ |
| 3185 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 3186 | |
| 3187 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 3188 | CF_MIN_3DB_150HZ) { |
| 3189 | |
| 3190 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 3191 | msecs_to_jiffies(300)); |
| 3192 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3193 | /* apply the digital gain after the decimator is enabled*/ |
Damir Didjusto | ed406e2 | 2012-11-16 15:44:57 -0800 | [diff] [blame] | 3194 | if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg)) |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3195 | snd_soc_write(codec, |
| 3196 | tx_digital_gain_reg[w->shift + offset], |
| 3197 | snd_soc_read(codec, |
| 3198 | tx_digital_gain_reg[w->shift + offset]) |
| 3199 | ); |
| 3200 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3201 | break; |
| 3202 | |
| 3203 | case SND_SOC_DAPM_PRE_PMD: |
| 3204 | |
| 3205 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3206 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 3207 | break; |
| 3208 | |
| 3209 | case SND_SOC_DAPM_POST_PMD: |
| 3210 | |
| 3211 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 3212 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3213 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 3214 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3215 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3216 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3217 | out: |
| 3218 | kfree(widget_name); |
| 3219 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3222 | static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3223 | struct snd_kcontrol *kcontrol, int event) |
| 3224 | { |
| 3225 | struct snd_soc_codec *codec = w->codec; |
| 3226 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3227 | pr_debug("%s %d %s\n", __func__, event, w->name); |
| 3228 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3229 | switch (event) { |
| 3230 | case SND_SOC_DAPM_PRE_PMU: |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3231 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3232 | 1 << w->shift, 1 << w->shift); |
| 3233 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3234 | 1 << w->shift, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3235 | break; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3236 | case SND_SOC_DAPM_POST_PMU: |
| 3237 | /* apply the digital gain after the interpolator is enabled*/ |
| 3238 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 3239 | snd_soc_write(codec, |
| 3240 | rx_digital_gain_reg[w->shift], |
| 3241 | snd_soc_read(codec, |
| 3242 | rx_digital_gain_reg[w->shift]) |
| 3243 | ); |
| 3244 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3245 | } |
| 3246 | return 0; |
| 3247 | } |
| 3248 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3249 | static void tabla_enable_ldo_h(struct snd_soc_codec *codec, u32 enable) |
| 3250 | { |
| 3251 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3252 | |
| 3253 | if (enable) { |
| 3254 | if (++tabla->ldo_h_count == 1) |
| 3255 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, |
| 3256 | 0x80, 0x80); |
| 3257 | } else { |
| 3258 | if (--tabla->ldo_h_count == 0) |
| 3259 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, |
| 3260 | 0x80, 0x00); |
| 3261 | } |
| 3262 | } |
| 3263 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3264 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 3265 | struct snd_kcontrol *kcontrol, int event) |
| 3266 | { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3267 | struct snd_soc_codec *codec = w->codec; |
| 3268 | |
| 3269 | pr_debug("%s %d\n", __func__, event); |
| 3270 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3271 | switch (event) { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3272 | case SND_SOC_DAPM_PRE_PMU: |
| 3273 | tabla_enable_ldo_h(codec, 1); |
| 3274 | usleep_range(1000, 1000); |
| 3275 | break; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3276 | case SND_SOC_DAPM_POST_PMD: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3277 | tabla_enable_ldo_h(codec, 0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3278 | usleep_range(1000, 1000); |
| 3279 | break; |
| 3280 | } |
| 3281 | return 0; |
| 3282 | } |
| 3283 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3284 | static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 3285 | struct snd_kcontrol *kcontrol, int event) |
| 3286 | { |
| 3287 | struct snd_soc_codec *codec = w->codec; |
| 3288 | |
| 3289 | pr_debug("%s %d\n", __func__, event); |
| 3290 | |
| 3291 | switch (event) { |
| 3292 | case SND_SOC_DAPM_PRE_PMU: |
| 3293 | tabla_enable_rx_bias(codec, 1); |
| 3294 | break; |
| 3295 | case SND_SOC_DAPM_POST_PMD: |
| 3296 | tabla_enable_rx_bias(codec, 0); |
| 3297 | break; |
| 3298 | } |
| 3299 | return 0; |
| 3300 | } |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3301 | static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 3302 | struct snd_kcontrol *kcontrol, int event) |
| 3303 | { |
| 3304 | struct snd_soc_codec *codec = w->codec; |
| 3305 | |
| 3306 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3307 | |
| 3308 | switch (event) { |
| 3309 | case SND_SOC_DAPM_PRE_PMU: |
| 3310 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3311 | break; |
| 3312 | case SND_SOC_DAPM_POST_PMD: |
| 3313 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3314 | break; |
| 3315 | } |
| 3316 | return 0; |
| 3317 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3318 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3319 | static void tabla_snd_soc_jack_report(struct tabla_priv *tabla, |
| 3320 | struct snd_soc_jack *jack, int status, |
| 3321 | int mask) |
| 3322 | { |
| 3323 | /* XXX: wake_lock_timeout()? */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3324 | snd_soc_jack_report_no_dapm(jack, status, mask); |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3327 | static void hphocp_off_report(struct tabla_priv *tabla, |
| 3328 | u32 jack_status, int irq) |
| 3329 | { |
| 3330 | struct snd_soc_codec *codec; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3331 | if (!tabla) { |
| 3332 | pr_err("%s: Bad tabla private data\n", __func__); |
| 3333 | return; |
| 3334 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3335 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3336 | pr_debug("%s: clear ocp status %x\n", __func__, jack_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3337 | codec = tabla->codec; |
| 3338 | if (tabla->hph_status & jack_status) { |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3339 | tabla->hph_status &= ~jack_status; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3340 | if (tabla->mbhc_cfg.headset_jack) |
| 3341 | tabla_snd_soc_jack_report(tabla, |
| 3342 | tabla->mbhc_cfg.headset_jack, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3343 | tabla->hph_status, |
| 3344 | TABLA_JACK_MASK); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3345 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 3346 | 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] | 3347 | /* reset retry counter as PA is turned off signifying |
| 3348 | * start of new OCP detection session |
| 3349 | */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3350 | if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 3351 | tabla->hphlocp_cnt = 0; |
| 3352 | else |
| 3353 | tabla->hphrocp_cnt = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3354 | wcd9xxx_enable_irq(codec->control_data, irq); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3355 | } |
| 3356 | } |
| 3357 | |
| 3358 | static void hphlocp_off_report(struct work_struct *work) |
| 3359 | { |
| 3360 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3361 | hphlocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3362 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
| 3363 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | static void hphrocp_off_report(struct work_struct *work) |
| 3367 | { |
| 3368 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3369 | hphrocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3370 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
| 3371 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3374 | static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 3375 | struct snd_kcontrol *kcontrol, int event) |
| 3376 | { |
| 3377 | struct snd_soc_codec *codec = w->codec; |
| 3378 | const char *filename; |
| 3379 | const struct firmware *fw; |
| 3380 | int i; |
| 3381 | int ret; |
| 3382 | int num_anc_slots; |
| 3383 | struct anc_header *anc_head; |
| 3384 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3385 | u32 anc_writes_size = 0; |
| 3386 | int anc_size_remaining; |
| 3387 | u32 *anc_ptr; |
| 3388 | u16 reg; |
| 3389 | u8 mask, val, old_val; |
| 3390 | u8 mbhc_micb_ctl_val; |
| 3391 | |
| 3392 | pr_debug("%s: DAPM Event %d ANC func is %d\n", |
| 3393 | __func__, event, tabla->anc_func); |
| 3394 | |
| 3395 | if (tabla->anc_func == 0) |
| 3396 | return 0; |
| 3397 | |
| 3398 | switch (event) { |
| 3399 | case SND_SOC_DAPM_PRE_PMU: |
| 3400 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 3401 | tabla->mbhc_bias_regs.ctl_reg); |
| 3402 | |
| 3403 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 3404 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3405 | tabla_codec_switch_micbias(codec, 1); |
| 3406 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3407 | } |
| 3408 | |
| 3409 | filename = "wcd9310/wcd9310_anc.bin"; |
| 3410 | |
| 3411 | ret = request_firmware(&fw, filename, codec->dev); |
| 3412 | if (ret != 0) { |
| 3413 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 3414 | ret); |
| 3415 | return -ENODEV; |
| 3416 | } |
| 3417 | |
| 3418 | if (fw->size < sizeof(struct anc_header)) { |
| 3419 | dev_err(codec->dev, "Not enough data\n"); |
| 3420 | release_firmware(fw); |
| 3421 | return -ENOMEM; |
| 3422 | } |
| 3423 | |
| 3424 | /* First number is the number of register writes */ |
| 3425 | anc_head = (struct anc_header *)(fw->data); |
| 3426 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 3427 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 3428 | num_anc_slots = anc_head->num_anc_slots; |
| 3429 | |
| 3430 | if (tabla->anc_slot >= num_anc_slots) { |
| 3431 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 3432 | release_firmware(fw); |
| 3433 | return -EINVAL; |
| 3434 | } |
| 3435 | |
| 3436 | for (i = 0; i < num_anc_slots; i++) { |
| 3437 | |
| 3438 | if (anc_size_remaining < TABLA_PACKED_REG_SIZE) { |
| 3439 | dev_err(codec->dev, "Invalid register format\n"); |
| 3440 | release_firmware(fw); |
| 3441 | return -EINVAL; |
| 3442 | } |
| 3443 | anc_writes_size = (u32)(*anc_ptr); |
| 3444 | anc_size_remaining -= sizeof(u32); |
| 3445 | anc_ptr += 1; |
| 3446 | |
| 3447 | if (anc_writes_size * TABLA_PACKED_REG_SIZE |
| 3448 | > anc_size_remaining) { |
| 3449 | dev_err(codec->dev, "Invalid register format\n"); |
| 3450 | release_firmware(fw); |
| 3451 | return -ENOMEM; |
| 3452 | } |
| 3453 | |
| 3454 | if (tabla->anc_slot == i) |
| 3455 | break; |
| 3456 | |
| 3457 | anc_size_remaining -= (anc_writes_size * |
| 3458 | TABLA_PACKED_REG_SIZE); |
| 3459 | anc_ptr += anc_writes_size; |
| 3460 | } |
| 3461 | if (i == num_anc_slots) { |
| 3462 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
| 3463 | release_firmware(fw); |
| 3464 | return -ENOMEM; |
| 3465 | } |
| 3466 | |
| 3467 | for (i = 0; i < anc_writes_size; i++) { |
| 3468 | TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
| 3469 | mask, val); |
| 3470 | old_val = snd_soc_read(codec, reg); |
| 3471 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 3472 | (val & mask)); |
| 3473 | } |
| 3474 | usleep_range(10000, 10000); |
| 3475 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x30); |
| 3476 | msleep(30); |
| 3477 | release_firmware(fw); |
| 3478 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3479 | /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */ |
| 3480 | if (tabla->mbhc_polling_active) |
| 3481 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, |
| 3482 | 0x80); |
| 3483 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3484 | break; |
| 3485 | case SND_SOC_DAPM_POST_PMD: |
| 3486 | /* schedule work is required because at the time HPH PA DAPM |
| 3487 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 3488 | * would have been locked while snd_soc_jack_report also |
| 3489 | * attempts to acquire same lock. |
| 3490 | */ |
| 3491 | if (w->shift == 5) { |
| 3492 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 3493 | &tabla->hph_pa_dac_state); |
| 3494 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 3495 | &tabla->hph_pa_dac_state); |
| 3496 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 3497 | schedule_work(&tabla->hphlocp_work); |
| 3498 | } else if (w->shift == 4) { |
| 3499 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 3500 | &tabla->hph_pa_dac_state); |
| 3501 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 3502 | &tabla->hph_pa_dac_state); |
| 3503 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 3504 | schedule_work(&tabla->hphrocp_work); |
| 3505 | } |
| 3506 | |
| 3507 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3508 | tabla_codec_switch_micbias(codec, 0); |
| 3509 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3510 | |
| 3511 | break; |
| 3512 | case SND_SOC_DAPM_PRE_PMD: |
| 3513 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 3514 | msleep(40); |
| 3515 | /* unset TX7_MBHC_EN bit 7 */ |
| 3516 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00); |
| 3517 | snd_soc_update_bits(codec, TABLA_A_CDC_ANC1_CTL, 0x01, 0x00); |
| 3518 | snd_soc_update_bits(codec, TABLA_A_CDC_ANC2_CTL, 0x01, 0x00); |
| 3519 | msleep(20); |
| 3520 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0x0F); |
| 3521 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
| 3522 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 3523 | break; |
| 3524 | } |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3528 | static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 3529 | struct snd_kcontrol *kcontrol, int event) |
| 3530 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3531 | struct snd_soc_codec *codec = w->codec; |
| 3532 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3533 | u8 mbhc_micb_ctl_val; |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3534 | pr_debug("%s: event = %d\n", __func__, event); |
| 3535 | |
| 3536 | switch (event) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3537 | case SND_SOC_DAPM_PRE_PMU: |
| 3538 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 3539 | tabla->mbhc_bias_regs.ctl_reg); |
| 3540 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3541 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 3542 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3543 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3544 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3545 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3546 | break; |
| 3547 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3548 | case SND_SOC_DAPM_POST_PMD: |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3549 | /* schedule work is required because at the time HPH PA DAPM |
| 3550 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 3551 | * would have been locked while snd_soc_jack_report also |
| 3552 | * attempts to acquire same lock. |
| 3553 | */ |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 3554 | if (w->shift == 5) { |
| 3555 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 3556 | &tabla->hph_pa_dac_state); |
| 3557 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 3558 | &tabla->hph_pa_dac_state); |
| 3559 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 3560 | schedule_work(&tabla->hphlocp_work); |
| 3561 | } else if (w->shift == 4) { |
| 3562 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 3563 | &tabla->hph_pa_dac_state); |
| 3564 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 3565 | &tabla->hph_pa_dac_state); |
| 3566 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 3567 | schedule_work(&tabla->hphrocp_work); |
| 3568 | } |
| 3569 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3570 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3571 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3572 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3573 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3574 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 3575 | w->name); |
| 3576 | usleep_range(10000, 10000); |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3577 | break; |
| 3578 | } |
| 3579 | return 0; |
| 3580 | } |
| 3581 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3582 | static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3583 | struct mbhc_micbias_regs *micbias_regs) |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3584 | { |
| 3585 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3586 | unsigned int cfilt; |
| 3587 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3588 | switch (tabla->mbhc_cfg.micbias) { |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3589 | case TABLA_MICBIAS1: |
| 3590 | cfilt = tabla->pdata->micbias.bias1_cfilt_sel; |
| 3591 | micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC; |
| 3592 | micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS; |
| 3593 | micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL; |
| 3594 | break; |
| 3595 | case TABLA_MICBIAS2: |
| 3596 | cfilt = tabla->pdata->micbias.bias2_cfilt_sel; |
| 3597 | micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC; |
| 3598 | micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS; |
| 3599 | micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL; |
| 3600 | break; |
| 3601 | case TABLA_MICBIAS3: |
| 3602 | cfilt = tabla->pdata->micbias.bias3_cfilt_sel; |
| 3603 | micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC; |
| 3604 | micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS; |
| 3605 | micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL; |
| 3606 | break; |
| 3607 | case TABLA_MICBIAS4: |
| 3608 | cfilt = tabla->pdata->micbias.bias4_cfilt_sel; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3609 | micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc; |
| 3610 | micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias; |
| 3611 | micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3612 | break; |
| 3613 | default: |
| 3614 | /* Should never reach here */ |
| 3615 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
Jordan Crouse | 239d841 | 2011-11-23 11:47:02 -0700 | [diff] [blame] | 3616 | return; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 3619 | micbias_regs->cfilt_sel = cfilt; |
| 3620 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3621 | switch (cfilt) { |
| 3622 | case TABLA_CFILT1_SEL: |
| 3623 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL; |
| 3624 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3625 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3626 | break; |
| 3627 | case TABLA_CFILT2_SEL: |
| 3628 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL; |
| 3629 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3630 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3631 | break; |
| 3632 | case TABLA_CFILT3_SEL: |
| 3633 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL; |
| 3634 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3635 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3636 | break; |
| 3637 | } |
| 3638 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3639 | static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = { |
| 3640 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3641 | 4, 0, NULL, 0), |
| 3642 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4, |
| 3643 | 0, NULL, 0), |
| 3644 | }; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3645 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3646 | static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 3647 | struct snd_kcontrol *kcontrol, int event) |
| 3648 | { |
| 3649 | struct snd_soc_codec *codec = w->codec; |
| 3650 | |
| 3651 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3652 | |
| 3653 | switch (event) { |
| 3654 | case SND_SOC_DAPM_PRE_PMU: |
| 3655 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3656 | break; |
| 3657 | |
| 3658 | case SND_SOC_DAPM_POST_PMD: |
| 3659 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3660 | break; |
| 3661 | } |
| 3662 | return 0; |
| 3663 | } |
| 3664 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 3665 | static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w, |
| 3666 | struct snd_kcontrol *kcontrol, int event) |
| 3667 | { |
| 3668 | struct snd_soc_codec *codec = w->codec; |
| 3669 | |
| 3670 | pr_debug("%s %d\n", __func__, event); |
| 3671 | |
| 3672 | switch (event) { |
| 3673 | case SND_SOC_DAPM_PRE_PMU: |
| 3674 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50); |
| 3675 | break; |
| 3676 | |
| 3677 | case SND_SOC_DAPM_PRE_PMD: |
| 3678 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00); |
| 3679 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00); |
| 3680 | break; |
| 3681 | } |
| 3682 | return 0; |
| 3683 | } |
| 3684 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3685 | static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3686 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3687 | 0, tabla_codec_enable_micbias, |
| 3688 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3689 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3690 | }; |
| 3691 | |
| 3692 | static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3693 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3694 | 0, tabla_codec_enable_micbias, |
| 3695 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3696 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3697 | }; |
| 3698 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3699 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 3700 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 3701 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 3702 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 3703 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 3704 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 3705 | |
| 3706 | {"SLIM TX7", NULL, "TX_I2S_CLK"}, |
| 3707 | {"SLIM TX8", NULL, "TX_I2S_CLK"}, |
| 3708 | {"SLIM TX9", NULL, "TX_I2S_CLK"}, |
| 3709 | {"SLIM TX10", NULL, "TX_I2S_CLK"}, |
| 3710 | }; |
| 3711 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3712 | static const struct snd_soc_dapm_route audio_map[] = { |
| 3713 | /* SLIMBUS Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3714 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3715 | {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, |
| 3716 | {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, |
| 3717 | {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3718 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3719 | /* SLIM_MIXER("AIF1_CAP Mixer"),*/ |
| 3720 | {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3721 | {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3722 | {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3723 | {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3724 | {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3725 | {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3726 | {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3727 | {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3728 | {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3729 | {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3730 | /* SLIM_MIXER("AIF2_CAP Mixer"),*/ |
| 3731 | {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3732 | {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3733 | {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3734 | {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3735 | {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3736 | {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3737 | {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3738 | {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3739 | {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3740 | {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3741 | /* SLIM_MIXER("AIF3_CAP Mixer"),*/ |
| 3742 | {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3743 | {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3744 | {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3745 | {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3746 | {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3747 | {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3748 | {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3749 | {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3750 | {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3751 | {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3752 | |
| 3753 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3754 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 3755 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3756 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3757 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 3758 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 3759 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 3760 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
| 3761 | {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"}, |
| 3762 | {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"}, |
| 3763 | {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3764 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3765 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
| 3766 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3767 | {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3768 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 3769 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 3770 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 3771 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
| 3772 | {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"}, |
| 3773 | {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"}, |
| 3774 | {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3775 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3776 | {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"}, |
| 3777 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3778 | {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3779 | {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3780 | {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"}, |
| 3781 | {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3782 | {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"}, |
| 3783 | {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3784 | {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"}, |
| 3785 | {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3786 | {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"}, |
| 3787 | {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3788 | {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"}, |
| 3789 | {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"}, |
| 3790 | {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"}, |
| 3791 | {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"}, |
| 3792 | {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"}, |
| 3793 | {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"}, |
| 3794 | {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3795 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3796 | {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"}, |
| 3797 | {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"}, |
| 3798 | {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | 9ec83cd | 2011-09-23 17:25:07 -0700 | [diff] [blame] | 3799 | {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3800 | {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"}, |
| 3801 | {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3802 | {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"}, |
| 3803 | {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"}, |
| 3804 | {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"}, |
| 3805 | {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3806 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3807 | {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"}, |
| 3808 | {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"}, |
| 3809 | {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"}, |
| 3810 | {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"}, |
| 3811 | {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"}, |
| 3812 | {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"}, |
| 3813 | {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"}, |
| 3814 | {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"}, |
| 3815 | {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"}, |
| 3816 | {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"}, |
| 3817 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3818 | {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"}, |
| 3819 | {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"}, |
| 3820 | {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"}, |
| 3821 | {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"}, |
| 3822 | {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"}, |
| 3823 | {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"}, |
| 3824 | {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"}, |
| 3825 | {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"}, |
| 3826 | {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"}, |
| 3827 | {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"}, |
| 3828 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3829 | /* Earpiece (RX MIX1) */ |
| 3830 | {"EAR", NULL, "EAR PA"}, |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3831 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 3832 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3833 | {"DAC1", NULL, "CP"}, |
| 3834 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3835 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 3836 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3837 | |
| 3838 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3839 | {"HEADPHONE", NULL, "HPHL"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3840 | {"HEADPHONE", NULL, "HPHR"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3841 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3842 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3843 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3844 | |
| 3845 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3846 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3847 | |
| 3848 | {"HPHL DAC", NULL, "CP"}, |
| 3849 | {"HPHR DAC", NULL, "CP"}, |
| 3850 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3851 | {"ANC HEADPHONE", NULL, "ANC HPHL"}, |
| 3852 | {"ANC HEADPHONE", NULL, "ANC HPHR"}, |
| 3853 | |
| 3854 | {"ANC HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3855 | {"ANC HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3856 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3857 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 3858 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 3859 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 3860 | {"ANC1 MUX", "ADC4", "ADC4"}, |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3861 | {"ANC1 MUX", "DMIC1", "DMIC1"}, |
| 3862 | {"ANC1 MUX", "DMIC2", "DMIC2"}, |
| 3863 | {"ANC1 MUX", "DMIC3", "DMIC3"}, |
| 3864 | {"ANC1 MUX", "DMIC4", "DMIC4"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3865 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 3866 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 3867 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 3868 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 3869 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3870 | {"ANC HPHR", NULL, "CDC_CONN"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3871 | {"DAC1", "Switch", "RX1 CHAIN"}, |
| 3872 | {"HPHL DAC", "Switch", "RX1 CHAIN"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3873 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3874 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 3875 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3876 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 3877 | {"LINEOUT3", NULL, "LINEOUT3 PA"}, |
| 3878 | {"LINEOUT4", NULL, "LINEOUT4 PA"}, |
| 3879 | {"LINEOUT5", NULL, "LINEOUT5 PA"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3880 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3881 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3882 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 3883 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3884 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3885 | {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"}, |
| 3886 | {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"}, |
| 3887 | {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"}, |
| 3888 | {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"}, |
| 3889 | {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"}, |
| 3890 | {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3891 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3892 | {"LINEOUT1 DAC", NULL, "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3893 | {"LINEOUT5 DAC", NULL, "RX7 MIX1"}, |
| 3894 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3895 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3896 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3897 | {"RX1 MIX2", NULL, "ANC1 MUX"}, |
| 3898 | {"RX2 MIX2", NULL, "ANC2 MUX"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3899 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3900 | {"CP", NULL, "RX_BIAS"}, |
| 3901 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3902 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
| 3903 | {"LINEOUT3 DAC", NULL, "RX_BIAS"}, |
| 3904 | {"LINEOUT4 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3905 | {"LINEOUT5 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3906 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3907 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 3908 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 3909 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 3910 | {"RX5 MIX1", NULL, "COMP2_CLK"}, |
| 3911 | |
| 3912 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3913 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3914 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3915 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3916 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3917 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3918 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3919 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 3920 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 3921 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 3922 | {"RX5 MIX1", NULL, "RX5 MIX1 INP1"}, |
| 3923 | {"RX5 MIX1", NULL, "RX5 MIX1 INP2"}, |
| 3924 | {"RX6 MIX1", NULL, "RX6 MIX1 INP1"}, |
| 3925 | {"RX6 MIX1", NULL, "RX6 MIX1 INP2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3926 | {"RX7 MIX1", NULL, "RX7 MIX1 INP1"}, |
| 3927 | {"RX7 MIX1", NULL, "RX7 MIX1 INP2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3928 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3929 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3930 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3931 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3932 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3933 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
| 3934 | {"RX3 MIX2", NULL, "RX3 MIX1"}, |
| 3935 | {"RX3 MIX2", NULL, "RX3 MIX2 INP1"}, |
| 3936 | {"RX3 MIX2", NULL, "RX3 MIX2 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3937 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3938 | /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/ |
| 3939 | {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3940 | {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3941 | {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3942 | {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3943 | {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3944 | {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3945 | {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3946 | /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/ |
| 3947 | {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3948 | {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3949 | {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3950 | {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3951 | {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3952 | {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3953 | {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3954 | /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/ |
| 3955 | {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3956 | {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3957 | {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3958 | {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3959 | {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3960 | {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3961 | {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3962 | |
| 3963 | {"SLIM RX1", NULL, "SLIM RX1 MUX"}, |
| 3964 | {"SLIM RX2", NULL, "SLIM RX2 MUX"}, |
| 3965 | {"SLIM RX3", NULL, "SLIM RX3 MUX"}, |
| 3966 | {"SLIM RX4", NULL, "SLIM RX4 MUX"}, |
| 3967 | {"SLIM RX5", NULL, "SLIM RX5 MUX"}, |
| 3968 | {"SLIM RX6", NULL, "SLIM RX6 MUX"}, |
| 3969 | {"SLIM RX7", NULL, "SLIM RX7 MUX"}, |
| 3970 | |
| 3971 | /* Mixer control for output path */ |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3972 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3973 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3974 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3975 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3976 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3977 | {"RX1 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3978 | {"RX1 MIX1 INP1", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3979 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 3980 | {"RX1 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3981 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3982 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3983 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3984 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3985 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3986 | {"RX1 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3987 | {"RX1 MIX1 INP2", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3988 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 3989 | {"RX1 MIX1 INP2", "IIR2", "IIR2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3990 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 3991 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 3992 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 3993 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 3994 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
| 3995 | {"RX1 MIX1 INP3", "RX6", "SLIM RX6"}, |
| 3996 | {"RX1 MIX1 INP3", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3997 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3998 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3999 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4000 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4001 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4002 | {"RX2 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4003 | {"RX2 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4004 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4005 | {"RX2 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4006 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4007 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4008 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4009 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4010 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4011 | {"RX2 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4012 | {"RX2 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4013 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4014 | {"RX2 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4015 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4016 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4017 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4018 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4019 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4020 | {"RX3 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4021 | {"RX3 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4022 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4023 | {"RX3 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4024 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4025 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4026 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4027 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4028 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4029 | {"RX3 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4030 | {"RX3 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4031 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4032 | {"RX3 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4033 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4034 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4035 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4036 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4037 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4038 | {"RX4 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4039 | {"RX4 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4040 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4041 | {"RX4 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4042 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4043 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4044 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4045 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4046 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4047 | {"RX4 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4048 | {"RX4 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4049 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4050 | {"RX4 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4051 | {"RX5 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4052 | {"RX5 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4053 | {"RX5 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4054 | {"RX5 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4055 | {"RX5 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4056 | {"RX5 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4057 | {"RX5 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4058 | {"RX5 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4059 | {"RX5 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4060 | {"RX5 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4061 | {"RX5 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4062 | {"RX5 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4063 | {"RX5 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4064 | {"RX5 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4065 | {"RX5 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4066 | {"RX5 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4067 | {"RX5 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4068 | {"RX5 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4069 | {"RX6 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4070 | {"RX6 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4071 | {"RX6 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4072 | {"RX6 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4073 | {"RX6 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4074 | {"RX6 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4075 | {"RX6 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4076 | {"RX6 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4077 | {"RX6 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4078 | {"RX6 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4079 | {"RX6 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4080 | {"RX6 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4081 | {"RX6 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4082 | {"RX6 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4083 | {"RX6 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4084 | {"RX6 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4085 | {"RX6 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4086 | {"RX6 MIX1 INP2", "IIR2", "IIR2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 4087 | {"RX7 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4088 | {"RX7 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4089 | {"RX7 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4090 | {"RX7 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4091 | {"RX7 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4092 | {"RX7 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4093 | {"RX7 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4094 | {"RX7 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4095 | {"RX7 MIX1 INP1", "IIR2", "IIR2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 4096 | {"RX7 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4097 | {"RX7 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4098 | {"RX7 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4099 | {"RX7 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4100 | {"RX7 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4101 | {"RX7 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4102 | {"RX7 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4103 | {"RX7 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4104 | {"RX7 MIX1 INP2", "IIR2", "IIR2"}, |
| 4105 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4106 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4107 | {"RX1 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4108 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4109 | {"RX1 MIX2 INP2", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4110 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4111 | {"RX2 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4112 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4113 | {"RX2 MIX2 INP2", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4114 | {"RX3 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4115 | {"RX3 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4116 | {"RX3 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4117 | {"RX3 MIX2 INP2", "IIR2", "IIR2"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4118 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4119 | /* Decimator Inputs */ |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4120 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4121 | {"DEC1 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4122 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4123 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4124 | {"DEC2 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4125 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4126 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4127 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4128 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4129 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4130 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4131 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4132 | {"DEC5 MUX", "DMIC5", "DMIC5"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4133 | {"DEC5 MUX", "ADC2", "ADC2"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4134 | {"DEC5 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4135 | {"DEC6 MUX", "DMIC6", "DMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4136 | {"DEC6 MUX", "ADC1", "ADC1"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4137 | {"DEC6 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4138 | {"DEC7 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4139 | {"DEC7 MUX", "DMIC6", "DMIC6"}, |
| 4140 | {"DEC7 MUX", "ADC1", "ADC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4141 | {"DEC7 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4142 | {"DEC7 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4143 | {"DEC8 MUX", "DMIC2", "DMIC2"}, |
| 4144 | {"DEC8 MUX", "DMIC5", "DMIC5"}, |
| 4145 | {"DEC8 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4146 | {"DEC8 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4147 | {"DEC8 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4148 | {"DEC9 MUX", "DMIC4", "DMIC4"}, |
| 4149 | {"DEC9 MUX", "DMIC5", "DMIC5"}, |
| 4150 | {"DEC9 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4151 | {"DEC9 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4152 | {"DEC9 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4153 | {"DEC10 MUX", "DMIC3", "DMIC3"}, |
| 4154 | {"DEC10 MUX", "DMIC6", "DMIC6"}, |
| 4155 | {"DEC10 MUX", "ADC1", "ADC1"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4156 | {"DEC10 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4157 | {"DEC10 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4158 | |
| 4159 | /* ADC Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4160 | {"ADC1", NULL, "AMIC1"}, |
| 4161 | {"ADC2", NULL, "AMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4162 | {"ADC3", NULL, "AMIC3"}, |
| 4163 | {"ADC4", NULL, "AMIC4"}, |
| 4164 | {"ADC5", NULL, "AMIC5"}, |
| 4165 | {"ADC6", NULL, "AMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4166 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 4167 | /* AUX PGA Connections */ |
| 4168 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4169 | {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4170 | {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4171 | {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4172 | {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4173 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4174 | {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4175 | {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4176 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4177 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4178 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4179 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4180 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4181 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4182 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4183 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4184 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4185 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4186 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4187 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4188 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4189 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4190 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4191 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4192 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4193 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4194 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4195 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4196 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4197 | {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4198 | {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4199 | {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4200 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 4201 | {"AUX_PGA_Right", NULL, "AMIC6"}, |
| 4202 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4203 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4204 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 4205 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 4206 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 4207 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 4208 | {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4209 | {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4210 | {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 4211 | {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 4212 | {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 4213 | {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4214 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4215 | {"IIR2", NULL, "IIR2 INP1 MUX"}, |
| 4216 | {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 4217 | {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 4218 | {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 4219 | {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 4220 | {"IIR2 INP1 MUX", "DEC5", "DEC5 MUX"}, |
| 4221 | {"IIR2 INP1 MUX", "DEC6", "DEC6 MUX"}, |
| 4222 | {"IIR2 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 4223 | {"IIR2 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 4224 | {"IIR2 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 4225 | {"IIR2 INP1 MUX", "DEC10", "DEC10 MUX"}, |
| 4226 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4227 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 4228 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 4229 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 4230 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 4231 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 4232 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 4233 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 4234 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 4235 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 4236 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 4237 | {"MIC BIAS4 External", NULL, "LDO_H"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4238 | }; |
| 4239 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4240 | static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = { |
| 4241 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4242 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4243 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 4244 | |
| 4245 | {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"}, |
| 4246 | |
| 4247 | {"LINEOUT3 DAC", NULL, "RX5 MIX1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4248 | {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4249 | {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"}, |
| 4250 | |
| 4251 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 4252 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 4253 | |
| 4254 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 4255 | {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"}, |
| 4256 | {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"}, |
| 4257 | }; |
| 4258 | |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 4259 | |
| 4260 | static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = { |
| 4261 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4262 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 4263 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 4264 | |
| 4265 | {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"}, |
| 4266 | |
| 4267 | {"LINEOUT2 DAC", NULL, "RX5 MIX1"}, |
| 4268 | |
| 4269 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 4270 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 4271 | |
| 4272 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 4273 | }; |
| 4274 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4275 | static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 4276 | { |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 4277 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4278 | struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 4279 | |
| 4280 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 4281 | for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) { |
| 4282 | if (tabla_1_reg_readable[i] == reg) |
| 4283 | return 1; |
| 4284 | } |
| 4285 | } else { |
| 4286 | for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) { |
| 4287 | if (tabla_2_reg_readable[i] == reg) |
| 4288 | return 1; |
| 4289 | } |
| 4290 | } |
| 4291 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4292 | return tabla_reg_readable[reg]; |
| 4293 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4294 | static bool tabla_is_digital_gain_register(unsigned int reg) |
| 4295 | { |
| 4296 | bool rtn = false; |
| 4297 | switch (reg) { |
| 4298 | case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 4299 | case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 4300 | case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 4301 | case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 4302 | case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL: |
| 4303 | case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL: |
| 4304 | case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL: |
| 4305 | case TABLA_A_CDC_TX1_VOL_CTL_GAIN: |
| 4306 | case TABLA_A_CDC_TX2_VOL_CTL_GAIN: |
| 4307 | case TABLA_A_CDC_TX3_VOL_CTL_GAIN: |
| 4308 | case TABLA_A_CDC_TX4_VOL_CTL_GAIN: |
| 4309 | case TABLA_A_CDC_TX5_VOL_CTL_GAIN: |
| 4310 | case TABLA_A_CDC_TX6_VOL_CTL_GAIN: |
| 4311 | case TABLA_A_CDC_TX7_VOL_CTL_GAIN: |
| 4312 | case TABLA_A_CDC_TX8_VOL_CTL_GAIN: |
| 4313 | case TABLA_A_CDC_TX9_VOL_CTL_GAIN: |
| 4314 | case TABLA_A_CDC_TX10_VOL_CTL_GAIN: |
| 4315 | rtn = true; |
| 4316 | break; |
| 4317 | default: |
| 4318 | break; |
| 4319 | } |
| 4320 | return rtn; |
| 4321 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4322 | static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 4323 | { |
| 4324 | /* Registers lower than 0x100 are top level registers which can be |
| 4325 | * written by the Tabla core driver. |
| 4326 | */ |
| 4327 | |
| 4328 | if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 4329 | return 1; |
| 4330 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 4331 | /* IIR Coeff registers are not cacheable */ |
| 4332 | if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) && |
| 4333 | (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL)) |
| 4334 | return 1; |
| 4335 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 4336 | /* ANC filter registers are not cacheable */ |
| 4337 | if ((reg >= TABLA_A_CDC_ANC1_FILT1_B1_CTL) && |
| 4338 | (reg <= TABLA_A_CDC_ANC1_FILT2_B3_CTL)) |
| 4339 | return 1; |
| 4340 | if ((reg >= TABLA_A_CDC_ANC2_FILT1_B1_CTL) && |
| 4341 | (reg <= TABLA_A_CDC_ANC2_FILT2_B3_CTL)) |
| 4342 | return 1; |
| 4343 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4344 | /* Digital gain register is not cacheable so we have to write |
| 4345 | * the setting even it is the same |
| 4346 | */ |
| 4347 | if (tabla_is_digital_gain_register(reg)) |
| 4348 | return 1; |
| 4349 | |
Joonwoo Park | ab2c587 | 2012-05-03 15:16:02 -0700 | [diff] [blame] | 4350 | /* HPH status registers */ |
| 4351 | if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS) |
| 4352 | return 1; |
| 4353 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 4354 | if (reg == TABLA_A_CDC_COMP1_SHUT_DOWN_STATUS || |
| 4355 | reg == TABLA_A_CDC_COMP2_SHUT_DOWN_STATUS) |
| 4356 | return 1; |
| 4357 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4358 | return 0; |
| 4359 | } |
| 4360 | |
| 4361 | #define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 4362 | static int tabla_write(struct snd_soc_codec *codec, unsigned int reg, |
| 4363 | unsigned int value) |
| 4364 | { |
| 4365 | int ret; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4366 | |
| 4367 | if (reg == SND_SOC_NOPM) |
| 4368 | return 0; |
| 4369 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4370 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 4371 | |
| 4372 | if (!tabla_volatile(codec, reg)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4373 | ret = snd_soc_cache_write(codec, reg, value); |
| 4374 | if (ret != 0) |
| 4375 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 4376 | reg, ret); |
| 4377 | } |
| 4378 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4379 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4380 | } |
| 4381 | static unsigned int tabla_read(struct snd_soc_codec *codec, |
| 4382 | unsigned int reg) |
| 4383 | { |
| 4384 | unsigned int val; |
| 4385 | int ret; |
| 4386 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4387 | if (reg == SND_SOC_NOPM) |
| 4388 | return 0; |
| 4389 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4390 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 4391 | |
| 4392 | if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) && |
| 4393 | reg < codec->driver->reg_cache_size) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4394 | ret = snd_soc_cache_read(codec, reg, &val); |
| 4395 | if (ret >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4396 | return val; |
| 4397 | } else |
| 4398 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 4399 | reg, ret); |
| 4400 | } |
| 4401 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4402 | val = wcd9xxx_reg_read(codec->control_data, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4403 | return val; |
| 4404 | } |
| 4405 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4406 | static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu) |
| 4407 | { |
| 4408 | s16 v_ins; |
| 4409 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4410 | tabla->mbhc_micbias_switched) |
| 4411 | v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu : |
| 4412 | (s16)tabla->mbhc_data.adj_v_ins_h; |
| 4413 | else |
| 4414 | v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu : |
| 4415 | (s16)tabla->mbhc_data.v_ins_h; |
| 4416 | return v_ins; |
| 4417 | } |
| 4418 | |
| 4419 | static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla) |
| 4420 | { |
| 4421 | s16 v_hs_max; |
| 4422 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 4423 | |
| 4424 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 4425 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4426 | tabla->mbhc_micbias_switched) |
| 4427 | v_hs_max = tabla->mbhc_data.adj_v_hs_max; |
| 4428 | else |
| 4429 | v_hs_max = plug_type->v_hs_max; |
| 4430 | return v_hs_max; |
| 4431 | } |
| 4432 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4433 | static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4434 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4435 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4436 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4437 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 4438 | tabla->mbhc_data.v_b1_hu & 0xFF); |
| 4439 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 4440 | (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 4441 | |
| 4442 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 4443 | tabla->mbhc_data.v_b1_h & 0xFF); |
| 4444 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 4445 | (tabla->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 4446 | |
| 4447 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, |
| 4448 | tabla->mbhc_data.v_brh & 0xFF); |
| 4449 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, |
| 4450 | (tabla->mbhc_data.v_brh >> 8) & 0xFF); |
| 4451 | |
| 4452 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL, |
| 4453 | tabla->mbhc_data.v_brl & 0xFF); |
| 4454 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL, |
| 4455 | (tabla->mbhc_data.v_brl >> 8) & 0xFF); |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 4459 | { |
| 4460 | u8 *n_ready, *n_cic; |
| 4461 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 4462 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4463 | const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true); |
| 4464 | |
| 4465 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 4466 | |
| 4467 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 4468 | v_ins_hu & 0xFF); |
| 4469 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 4470 | (v_ins_hu >> 8) & 0xFF); |
| 4471 | |
| 4472 | tabla_codec_calibrate_rel(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4473 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4474 | 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] | 4475 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4476 | n_ready[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4477 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, |
| 4478 | tabla->mbhc_data.npoll); |
| 4479 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, |
| 4480 | tabla->mbhc_data.nbounce_wait); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4481 | 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] | 4482 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, |
| 4483 | n_cic[tabla_codec_mclk_index(tabla)]); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4484 | } |
| 4485 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4486 | static int tabla_startup(struct snd_pcm_substream *substream, |
| 4487 | struct snd_soc_dai *dai) |
| 4488 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4489 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4490 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4491 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4492 | if ((tabla_core != NULL) && |
| 4493 | (tabla_core->dev != NULL) && |
| 4494 | (tabla_core->dev->parent != NULL)) |
| 4495 | pm_runtime_get_sync(tabla_core->dev->parent); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4496 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4497 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4498 | } |
| 4499 | |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4500 | static void tabla_shutdown(struct snd_pcm_substream *substream, |
| 4501 | struct snd_soc_dai *dai) |
| 4502 | { |
| 4503 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
| 4504 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4505 | u32 active = 0; |
| 4506 | |
| 4507 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4508 | substream->name, substream->stream); |
| 4509 | if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4510 | return; |
| 4511 | |
| 4512 | if (dai->id <= NUM_CODEC_DAIS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4513 | if (tabla->dai[dai->id].ch_mask) { |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4514 | active = 1; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 4515 | pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4516 | __func__, dai->id, tabla->dai[dai->id].ch_mask); |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | if ((tabla_core != NULL) && |
| 4521 | (tabla_core->dev != NULL) && |
| 4522 | (tabla_core->dev->parent != NULL) && |
| 4523 | (active == 0)) { |
| 4524 | pm_runtime_mark_last_busy(tabla_core->dev->parent); |
| 4525 | pm_runtime_put(tabla_core->dev->parent); |
| 4526 | } |
| 4527 | } |
| 4528 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4529 | 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] | 4530 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4531 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4532 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4533 | pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable, |
| 4534 | dapm); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4535 | if (dapm) |
| 4536 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4537 | if (mclk_enable) { |
| 4538 | tabla->mclk_enabled = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4539 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4540 | if (tabla->mbhc_polling_active) { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4541 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4542 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4543 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4544 | TABLA_BANDGAP_AUDIO_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4545 | tabla_codec_enable_clock_block(codec, 0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4546 | tabla_codec_calibrate_hs_polling(codec); |
| 4547 | tabla_codec_start_hs_polling(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4548 | } else { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4549 | tabla_codec_disable_clock_block(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4550 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4551 | TABLA_BANDGAP_AUDIO_MODE); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4552 | tabla_codec_enable_clock_block(codec, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4553 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4554 | } else { |
| 4555 | |
| 4556 | if (!tabla->mclk_enabled) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4557 | if (dapm) |
| 4558 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4559 | pr_err("Error, MCLK already diabled\n"); |
| 4560 | return -EINVAL; |
| 4561 | } |
| 4562 | tabla->mclk_enabled = false; |
| 4563 | |
| 4564 | if (tabla->mbhc_polling_active) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4565 | tabla_codec_pause_hs_polling(codec); |
| 4566 | tabla_codec_disable_clock_block(codec); |
| 4567 | tabla_codec_enable_bandgap(codec, |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 4568 | TABLA_BANDGAP_MBHC_MODE); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4569 | tabla_enable_rx_bias(codec, 1); |
| 4570 | tabla_codec_enable_clock_block(codec, 1); |
| 4571 | tabla_codec_calibrate_hs_polling(codec); |
| 4572 | tabla_codec_start_hs_polling(codec); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4573 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, |
| 4574 | 0x05, 0x01); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4575 | } else { |
| 4576 | tabla_codec_disable_clock_block(codec); |
| 4577 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4578 | TABLA_BANDGAP_OFF); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4579 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4580 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4581 | if (dapm) |
| 4582 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4583 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4584 | } |
| 4585 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4586 | static int tabla_set_dai_sysclk(struct snd_soc_dai *dai, |
| 4587 | int clk_id, unsigned int freq, int dir) |
| 4588 | { |
| 4589 | pr_debug("%s\n", __func__); |
| 4590 | return 0; |
| 4591 | } |
| 4592 | |
| 4593 | static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 4594 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4595 | u8 val = 0; |
| 4596 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4597 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4598 | pr_debug("%s\n", __func__); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4599 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 4600 | case SND_SOC_DAIFMT_CBS_CFS: |
| 4601 | /* CPU is master */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4602 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4603 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4604 | snd_soc_update_bits(dai->codec, |
| 4605 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 4606 | TABLA_I2S_MASTER_MODE_MASK, 0); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4607 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4608 | snd_soc_update_bits(dai->codec, |
| 4609 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 4610 | TABLA_I2S_MASTER_MODE_MASK, 0); |
| 4611 | } |
| 4612 | break; |
| 4613 | case SND_SOC_DAIFMT_CBM_CFM: |
| 4614 | /* CPU is slave */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4615 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4616 | val = TABLA_I2S_MASTER_MODE_MASK; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4617 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4618 | snd_soc_update_bits(dai->codec, |
| 4619 | TABLA_A_CDC_CLK_TX_I2S_CTL, val, val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4620 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4621 | snd_soc_update_bits(dai->codec, |
| 4622 | TABLA_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 4623 | } |
| 4624 | break; |
| 4625 | default: |
| 4626 | return -EINVAL; |
| 4627 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4628 | return 0; |
| 4629 | } |
| 4630 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4631 | static int tabla_set_channel_map(struct snd_soc_dai *dai, |
| 4632 | unsigned int tx_num, unsigned int *tx_slot, |
| 4633 | unsigned int rx_num, unsigned int *rx_slot) |
| 4634 | |
| 4635 | { |
| 4636 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4637 | struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent); |
| 4638 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4639 | if (!tx_slot && !rx_slot) { |
| 4640 | pr_err("%s: Invalid\n", __func__); |
| 4641 | return -EINVAL; |
| 4642 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4643 | pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n" |
| 4644 | "tabla->intf_type %d\n", |
| 4645 | __func__, dai->name, dai->id, tx_num, rx_num, |
| 4646 | tabla->intf_type); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4647 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4648 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4649 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 4650 | tx_num, tx_slot, rx_num, rx_slot); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4651 | return 0; |
| 4652 | } |
| 4653 | |
| 4654 | static int tabla_get_channel_map(struct snd_soc_dai *dai, |
| 4655 | unsigned int *tx_num, unsigned int *tx_slot, |
| 4656 | unsigned int *rx_num, unsigned int *rx_slot) |
| 4657 | |
| 4658 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4659 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec); |
| 4660 | u32 i = 0; |
| 4661 | struct wcd9xxx_ch *ch; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4662 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4663 | switch (dai->id) { |
| 4664 | case AIF1_PB: |
| 4665 | case AIF2_PB: |
| 4666 | case AIF3_PB: |
| 4667 | if (!rx_slot || !rx_num) { |
| 4668 | pr_err("%s: Invalid rx_slot %d or rx_num %d\n", |
| 4669 | __func__, (u32) rx_slot, (u32) rx_num); |
| 4670 | return -EINVAL; |
| 4671 | } |
| 4672 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4673 | list) { |
| 4674 | rx_slot[i++] = ch->ch_num; |
| 4675 | } |
| 4676 | *rx_num = i; |
| 4677 | break; |
| 4678 | case AIF1_CAP: |
| 4679 | case AIF2_CAP: |
| 4680 | case AIF3_CAP: |
| 4681 | if (!tx_slot || !tx_num) { |
| 4682 | pr_err("%s: Invalid tx_slot %d or tx_num %d\n", |
| 4683 | __func__, (u32) tx_slot, (u32) tx_num); |
| 4684 | return -EINVAL; |
| 4685 | } |
| 4686 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4687 | list) { |
| 4688 | tx_slot[i++] = ch->ch_num; |
| 4689 | } |
| 4690 | *tx_num = i; |
| 4691 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4692 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4693 | default: |
| 4694 | pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id); |
| 4695 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4696 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4697 | return 0; |
| 4698 | } |
| 4699 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4700 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4701 | static int tabla_set_interpolator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4702 | u8 rx_fs_rate_reg_val, |
| 4703 | u32 compander_fs, |
| 4704 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4705 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4706 | u32 j; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4707 | u8 rx_mix1_inp; |
| 4708 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 4709 | u16 rx_fs_reg; |
| 4710 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
| 4711 | struct snd_soc_codec *codec = dai->codec; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4712 | struct wcd9xxx_ch *ch; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4713 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4714 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4715 | list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4716 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4717 | rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4718 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4719 | if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) || |
| 4720 | (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) { |
| 4721 | pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n", |
| 4722 | __func__, rx_mix1_inp - 5 , dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4723 | return -EINVAL; |
| 4724 | } |
| 4725 | |
| 4726 | rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL; |
| 4727 | |
| 4728 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4729 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 4730 | |
| 4731 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4732 | rx_mix_1_reg_1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4733 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4734 | rx_mix_1_reg_2); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4735 | |
| 4736 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4737 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) || |
| 4738 | ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4739 | |
| 4740 | rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j; |
| 4741 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4742 | pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n", |
| 4743 | __func__, dai->id, j + 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4744 | |
| 4745 | pr_debug("%s: set RX%u sample rate to %u\n", |
| 4746 | __func__, j + 1, sample_rate); |
| 4747 | |
| 4748 | snd_soc_update_bits(codec, rx_fs_reg, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4749 | 0xE0, rx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4750 | |
| 4751 | if (comp_rx_path[j] < COMPANDER_MAX) |
| 4752 | tabla->comp_fs[comp_rx_path[j]] |
| 4753 | = compander_fs; |
| 4754 | } |
| 4755 | if (j <= 2) |
| 4756 | rx_mix_1_reg_1 += 3; |
| 4757 | else |
| 4758 | rx_mix_1_reg_1 += 2; |
| 4759 | } |
| 4760 | } |
| 4761 | return 0; |
| 4762 | } |
| 4763 | |
| 4764 | static int tabla_set_decimator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4765 | u8 tx_fs_rate_reg_val, |
| 4766 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4767 | { |
| 4768 | struct snd_soc_codec *codec = dai->codec; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4769 | struct wcd9xxx_ch *ch; |
| 4770 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4771 | u32 tx_port; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4772 | u16 tx_port_reg, tx_fs_reg; |
| 4773 | u8 tx_port_reg_val; |
| 4774 | s8 decimator; |
| 4775 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4776 | list_for_each_entry(ch, &tabla->dai[dai->id].wcd9xxx_ch_list, list) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4777 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4778 | tx_port = ch->port + 1; |
| 4779 | pr_debug("%s: dai->id = %d, tx_port = %d", |
| 4780 | __func__, dai->id, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4781 | |
| 4782 | if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4783 | pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n", |
| 4784 | __func__, tx_port, dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4785 | return -EINVAL; |
| 4786 | } |
| 4787 | |
| 4788 | tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 4789 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 4790 | |
| 4791 | decimator = 0; |
| 4792 | |
| 4793 | if ((tx_port >= 1) && (tx_port <= 6)) { |
| 4794 | |
| 4795 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
| 4796 | if (tx_port_reg_val == 0x8) |
| 4797 | decimator = tx_port; |
| 4798 | |
| 4799 | } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) { |
| 4800 | |
| 4801 | tx_port_reg_val = tx_port_reg_val & 0x1F; |
| 4802 | |
| 4803 | if ((tx_port_reg_val >= 0x8) && |
| 4804 | (tx_port_reg_val <= 0x11)) { |
| 4805 | |
| 4806 | decimator = (tx_port_reg_val - 0x8) + 1; |
| 4807 | } |
| 4808 | } |
| 4809 | |
| 4810 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 4811 | |
| 4812 | tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL + |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4813 | 8 * (decimator - 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4814 | |
| 4815 | pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 4816 | __func__, decimator, tx_port, sample_rate); |
| 4817 | |
| 4818 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4819 | tx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4820 | |
| 4821 | } else { |
| 4822 | if ((tx_port_reg_val >= 0x1) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4823 | (tx_port_reg_val <= 0x7)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4824 | |
| 4825 | pr_debug("%s: RMIX%u going to SLIM TX%u\n", |
| 4826 | __func__, tx_port_reg_val, tx_port); |
| 4827 | |
| 4828 | } else if ((tx_port_reg_val >= 0x8) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4829 | (tx_port_reg_val <= 0x11)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4830 | |
| 4831 | pr_err("%s: ERROR: Should not be here\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4832 | __func__); |
| 4833 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n", |
| 4834 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4835 | return -EINVAL; |
| 4836 | |
| 4837 | } else if (tx_port_reg_val == 0) { |
| 4838 | pr_debug("%s: no signal to SLIM TX%u\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4839 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4840 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4841 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n", |
| 4842 | __func__, tx_port); |
| 4843 | pr_err("%s: ERROR: wrong signal = %u\n", |
| 4844 | __func__, tx_port_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4845 | return -EINVAL; |
| 4846 | } |
| 4847 | } |
| 4848 | } |
| 4849 | return 0; |
| 4850 | } |
| 4851 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4852 | static int tabla_hw_params(struct snd_pcm_substream *substream, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4853 | struct snd_pcm_hw_params *params, |
| 4854 | struct snd_soc_dai *dai) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4855 | { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4856 | struct snd_soc_codec *codec = dai->codec; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4857 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4858 | u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4859 | u32 compander_fs; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4860 | int ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4861 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4862 | pr_debug("%s: dai_name = %s DAI-ID %x rate %d num_ch %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4863 | dai->name, dai->id, params_rate(params), |
| 4864 | params_channels(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4865 | |
| 4866 | switch (params_rate(params)) { |
| 4867 | case 8000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4868 | tx_fs_rate_reg_val = 0x00; |
| 4869 | rx_fs_rate_reg_val = 0x00; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4870 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4871 | break; |
| 4872 | case 16000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4873 | tx_fs_rate_reg_val = 0x01; |
| 4874 | rx_fs_rate_reg_val = 0x20; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4875 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4876 | break; |
| 4877 | case 32000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4878 | tx_fs_rate_reg_val = 0x02; |
| 4879 | rx_fs_rate_reg_val = 0x40; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4880 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4881 | break; |
| 4882 | case 48000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4883 | tx_fs_rate_reg_val = 0x03; |
| 4884 | rx_fs_rate_reg_val = 0x60; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4885 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4886 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4887 | case 96000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4888 | tx_fs_rate_reg_val = 0x04; |
| 4889 | rx_fs_rate_reg_val = 0x80; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4890 | compander_fs = COMPANDER_FS_96KHZ; |
| 4891 | break; |
| 4892 | case 192000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4893 | tx_fs_rate_reg_val = 0x05; |
| 4894 | rx_fs_rate_reg_val = 0xA0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4895 | compander_fs = COMPANDER_FS_192KHZ; |
| 4896 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4897 | default: |
| 4898 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4899 | params_rate(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4900 | return -EINVAL; |
| 4901 | } |
| 4902 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4903 | switch (substream->stream) { |
| 4904 | case SNDRV_PCM_STREAM_CAPTURE: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4905 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4906 | ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4907 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4908 | if (ret < 0) { |
| 4909 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4910 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4911 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4912 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4913 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4914 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4915 | switch (params_format(params)) { |
| 4916 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4917 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4918 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4919 | break; |
| 4920 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4921 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4922 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4923 | break; |
| 4924 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4925 | pr_err("%s: Invalid format %d\n", __func__, |
| 4926 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4927 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4928 | } |
| 4929 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4930 | 0x07, tx_fs_rate_reg_val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4931 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4932 | switch (params_format(params)) { |
| 4933 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4934 | tabla->dai[dai->id].bit_width = 16; |
| 4935 | break; |
| 4936 | default: |
| 4937 | pr_err("%s: Invalid TX format %d\n", __func__, |
| 4938 | params_format(params)); |
| 4939 | return -EINVAL; |
| 4940 | } |
| 4941 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4942 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4943 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4944 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4945 | case SNDRV_PCM_STREAM_PLAYBACK: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4946 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4947 | ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4948 | compander_fs, |
| 4949 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4950 | if (ret < 0) { |
| 4951 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4952 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4953 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4954 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4955 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4956 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4957 | switch (params_format(params)) { |
| 4958 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4959 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4960 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4961 | break; |
| 4962 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4963 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4964 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4965 | break; |
| 4966 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4967 | pr_err("%s: Invalid RX format %d\n", __func__, |
| 4968 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4969 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4970 | } |
| 4971 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4972 | 0x03, (rx_fs_rate_reg_val >> 0x05)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4973 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4974 | switch (params_format(params)) { |
| 4975 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4976 | tabla->dai[dai->id].bit_width = 16; |
| 4977 | break; |
| 4978 | default: |
| 4979 | pr_err("%s: Invalid format %d\n", __func__, |
| 4980 | params_format(params)); |
| 4981 | return -EINVAL; |
| 4982 | } |
| 4983 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4984 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4985 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4986 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4987 | default: |
| 4988 | pr_err("%s: Invalid stream type %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4989 | substream->stream); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4990 | return -EINVAL; |
| 4991 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4992 | return 0; |
| 4993 | } |
| 4994 | |
| 4995 | static struct snd_soc_dai_ops tabla_dai_ops = { |
| 4996 | .startup = tabla_startup, |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4997 | .shutdown = tabla_shutdown, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4998 | .hw_params = tabla_hw_params, |
| 4999 | .set_sysclk = tabla_set_dai_sysclk, |
| 5000 | .set_fmt = tabla_set_dai_fmt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5001 | .set_channel_map = tabla_set_channel_map, |
| 5002 | .get_channel_map = tabla_get_channel_map, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5003 | }; |
| 5004 | |
| 5005 | static struct snd_soc_dai_driver tabla_dai[] = { |
| 5006 | { |
| 5007 | .name = "tabla_rx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5008 | .id = AIF1_PB, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5009 | .playback = { |
| 5010 | .stream_name = "AIF1 Playback", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5011 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5012 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5013 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5014 | .rate_min = 8000, |
| 5015 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5016 | .channels_max = 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5017 | }, |
| 5018 | .ops = &tabla_dai_ops, |
| 5019 | }, |
| 5020 | { |
| 5021 | .name = "tabla_tx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5022 | .id = AIF1_CAP, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5023 | .capture = { |
| 5024 | .stream_name = "AIF1 Capture", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5025 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5026 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5027 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5028 | .rate_min = 8000, |
| 5029 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5030 | .channels_max = 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5031 | }, |
| 5032 | .ops = &tabla_dai_ops, |
| 5033 | }, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 5034 | { |
| 5035 | .name = "tabla_rx2", |
| 5036 | .id = AIF2_PB, |
| 5037 | .playback = { |
| 5038 | .stream_name = "AIF2 Playback", |
| 5039 | .rates = WCD9310_RATES, |
| 5040 | .formats = TABLA_FORMATS, |
| 5041 | .rate_min = 8000, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5042 | .rate_max = 192000, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 5043 | .channels_min = 1, |
| 5044 | .channels_max = 2, |
| 5045 | }, |
| 5046 | .ops = &tabla_dai_ops, |
| 5047 | }, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5048 | { |
| 5049 | .name = "tabla_tx2", |
| 5050 | .id = AIF2_CAP, |
| 5051 | .capture = { |
| 5052 | .stream_name = "AIF2 Capture", |
| 5053 | .rates = WCD9310_RATES, |
| 5054 | .formats = TABLA_FORMATS, |
| 5055 | .rate_max = 192000, |
| 5056 | .rate_min = 8000, |
| 5057 | .channels_min = 1, |
| 5058 | .channels_max = 4, |
| 5059 | }, |
| 5060 | .ops = &tabla_dai_ops, |
| 5061 | }, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 5062 | { |
| 5063 | .name = "tabla_tx3", |
| 5064 | .id = AIF3_CAP, |
| 5065 | .capture = { |
| 5066 | .stream_name = "AIF3 Capture", |
| 5067 | .rates = WCD9310_RATES, |
| 5068 | .formats = TABLA_FORMATS, |
| 5069 | .rate_max = 48000, |
| 5070 | .rate_min = 8000, |
| 5071 | .channels_min = 1, |
| 5072 | .channels_max = 2, |
| 5073 | }, |
| 5074 | .ops = &tabla_dai_ops, |
| 5075 | }, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5076 | { |
| 5077 | .name = "tabla_rx3", |
| 5078 | .id = AIF3_PB, |
| 5079 | .playback = { |
| 5080 | .stream_name = "AIF3 Playback", |
| 5081 | .rates = WCD9310_RATES, |
| 5082 | .formats = TABLA_FORMATS, |
| 5083 | .rate_min = 8000, |
| 5084 | .rate_max = 192000, |
| 5085 | .channels_min = 1, |
| 5086 | .channels_max = 2, |
| 5087 | }, |
| 5088 | .ops = &tabla_dai_ops, |
| 5089 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5090 | }; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5091 | |
| 5092 | static struct snd_soc_dai_driver tabla_i2s_dai[] = { |
| 5093 | { |
| 5094 | .name = "tabla_i2s_rx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5095 | .id = AIF1_PB, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5096 | .playback = { |
| 5097 | .stream_name = "AIF1 Playback", |
| 5098 | .rates = WCD9310_RATES, |
| 5099 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5100 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5101 | .rate_min = 8000, |
| 5102 | .channels_min = 1, |
| 5103 | .channels_max = 4, |
| 5104 | }, |
| 5105 | .ops = &tabla_dai_ops, |
| 5106 | }, |
| 5107 | { |
| 5108 | .name = "tabla_i2s_tx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5109 | .id = AIF1_CAP, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5110 | .capture = { |
| 5111 | .stream_name = "AIF1 Capture", |
| 5112 | .rates = WCD9310_RATES, |
| 5113 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5114 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5115 | .rate_min = 8000, |
| 5116 | .channels_min = 1, |
| 5117 | .channels_max = 4, |
| 5118 | }, |
| 5119 | .ops = &tabla_dai_ops, |
| 5120 | }, |
| 5121 | }; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5122 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5123 | static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5124 | int event, int index) |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5125 | { |
| 5126 | int ret = 0; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5127 | struct wcd9xxx_ch *ch; |
| 5128 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5129 | switch (event) { |
| 5130 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5131 | list_for_each_entry(ch, |
| 5132 | &tabla_p->dai[index].wcd9xxx_ch_list, list) { |
| 5133 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5134 | if (ret < 0) { |
| 5135 | pr_err("%s: Invalid slave port ID: %d\n", |
| 5136 | __func__, ret); |
| 5137 | ret = -EINVAL; |
| 5138 | break; |
| 5139 | } |
| 5140 | tabla_p->dai[index].ch_mask |= 1 << ret; |
| 5141 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5142 | break; |
| 5143 | case SND_SOC_DAPM_POST_PMD: |
| 5144 | ret = wait_event_timeout(tabla_p->dai[index].dai_wait, |
| 5145 | (tabla_p->dai[index].ch_mask == 0), |
| 5146 | msecs_to_jiffies(SLIM_CLOSE_TIMEOUT)); |
| 5147 | if (!ret) { |
| 5148 | pr_err("%s: Slim close tx/rx wait timeout\n", |
| 5149 | __func__); |
| 5150 | ret = -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5151 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5152 | break; |
| 5153 | } |
| 5154 | return ret; |
| 5155 | } |
| 5156 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5157 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5158 | struct snd_kcontrol *kcontrol, |
| 5159 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5160 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5161 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5162 | struct snd_soc_codec *codec = w->codec; |
| 5163 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5164 | u32 ret = 0; |
| 5165 | struct wcd9xxx_codec_dai_data *dai; |
| 5166 | |
| 5167 | core = dev_get_drvdata(codec->dev->parent); |
| 5168 | |
| 5169 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 5170 | "stream name %s event %d\n", |
| 5171 | __func__, w->codec->name, w->codec->num_dai, |
| 5172 | w->sname, event); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5173 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5174 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5175 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5176 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 5177 | (core->dev != NULL) && |
| 5178 | (core->dev->parent != NULL)) { |
| 5179 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5180 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5181 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5182 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5183 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5184 | pr_debug("%s: w->name %s w->shift %d event %d\n", |
| 5185 | __func__, w->name, w->shift, event); |
| 5186 | dai = &tabla_p->dai[w->shift]; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5187 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5188 | switch (event) { |
| 5189 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5190 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 5191 | w->shift); |
| 5192 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 5193 | dai->rate, dai->bit_width, |
| 5194 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5195 | break; |
| 5196 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5197 | ret = wcd9xxx_close_slim_sch_rx(core, |
| 5198 | &dai->wcd9xxx_ch_list, |
| 5199 | dai->grph); |
| 5200 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 5201 | w->shift); |
| 5202 | if (ret < 0) { |
| 5203 | ret = wcd9xxx_disconnect_port(core, |
| 5204 | &dai->wcd9xxx_ch_list, |
| 5205 | dai->grph); |
| 5206 | pr_info("%s: Disconnect RX port, ret = %d\n", |
| 5207 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5208 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5209 | if ((core != NULL) && |
| 5210 | (core->dev != NULL) && |
| 5211 | (core->dev->parent != NULL)) { |
| 5212 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5213 | pm_runtime_put(core->dev->parent); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5214 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5215 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5216 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5217 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5218 | return ret; |
| 5219 | } |
| 5220 | |
| 5221 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5222 | struct snd_kcontrol *kcontrol, |
| 5223 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5224 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5225 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5226 | struct snd_soc_codec *codec = w->codec; |
| 5227 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5228 | u32 ret = 0; |
| 5229 | struct wcd9xxx_codec_dai_data *dai; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5230 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5231 | core = dev_get_drvdata(codec->dev->parent); |
| 5232 | |
| 5233 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 5234 | "stream name %s\n", __func__, w->codec->name, |
| 5235 | w->codec->num_dai, w->sname); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5236 | |
| 5237 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5238 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5239 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 5240 | (core->dev != NULL) && |
| 5241 | (core->dev->parent != NULL)) { |
| 5242 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5243 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5244 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5245 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5246 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5247 | |
| 5248 | pr_debug("%s(): %s %d\n", __func__, w->name, event); |
| 5249 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5250 | dai = &tabla_p->dai[w->shift]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5251 | switch (event) { |
| 5252 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5253 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 5254 | w->shift); |
| 5255 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 5256 | dai->rate, |
| 5257 | dai->bit_width, |
| 5258 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5259 | break; |
| 5260 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5261 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 5262 | dai->grph); |
| 5263 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 5264 | w->shift); |
| 5265 | if (ret < 0) { |
| 5266 | ret = wcd9xxx_disconnect_port(core, |
| 5267 | &dai->wcd9xxx_ch_list, |
| 5268 | dai->grph); |
| 5269 | pr_info("%s: Disconnect TX port, ret = %d\n", |
| 5270 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5271 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5272 | if ((core != NULL) && |
| 5273 | (core->dev != NULL) && |
| 5274 | (core->dev->parent != NULL)) { |
| 5275 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5276 | pm_runtime_put(core->dev->parent); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5277 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5278 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5279 | } |
| 5280 | return ret; |
| 5281 | } |
| 5282 | |
| 5283 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 5284 | * Might Need to have callbacks registered only for slimbus |
| 5285 | */ |
| 5286 | static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = { |
| 5287 | /*RX stuff */ |
| 5288 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 5289 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 5290 | SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL, |
| 5291 | 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5292 | SND_SOC_DAPM_PRE_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5293 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 5294 | SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5295 | ARRAY_SIZE(dac1_switch)), |
| 5296 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5297 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 5298 | AIF1_PB, 0, tabla_codec_enable_slimrx, |
| 5299 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5300 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 5301 | AIF2_PB, 0, tabla_codec_enable_slimrx, |
| 5302 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5303 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 5304 | AIF3_PB, 0, tabla_codec_enable_slimrx, |
| 5305 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5306 | |
| 5307 | SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0, |
| 5308 | &slim_rx_mux[TABLA_RX1]), |
| 5309 | SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0, |
| 5310 | &slim_rx_mux[TABLA_RX2]), |
| 5311 | SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0, |
| 5312 | &slim_rx_mux[TABLA_RX3]), |
| 5313 | SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0, |
| 5314 | &slim_rx_mux[TABLA_RX4]), |
| 5315 | SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0, |
| 5316 | &slim_rx_mux[TABLA_RX5]), |
| 5317 | SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0, |
| 5318 | &slim_rx_mux[TABLA_RX6]), |
| 5319 | SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0, |
| 5320 | &slim_rx_mux[TABLA_RX7]), |
| 5321 | |
| 5322 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5323 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5324 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5325 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5326 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5327 | SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5328 | SND_SOC_DAPM_MIXER("SLIM RX7", SND_SOC_NOPM, 0, 0, NULL, 0), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5329 | /* Headphone */ |
| 5330 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 5331 | SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 5332 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5333 | SND_SOC_DAPM_POST_PMD), |
| 5334 | SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 5335 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 5336 | |
| 5337 | SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 5338 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5339 | SND_SOC_DAPM_POST_PMD), |
| 5340 | |
| 5341 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 5342 | tabla_hphr_dac_event, |
| 5343 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5344 | |
| 5345 | /* Speaker */ |
| 5346 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 5347 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 5348 | SND_SOC_DAPM_OUTPUT("LINEOUT3"), |
| 5349 | SND_SOC_DAPM_OUTPUT("LINEOUT4"), |
| 5350 | SND_SOC_DAPM_OUTPUT("LINEOUT5"), |
| 5351 | |
| 5352 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 5353 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5354 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5355 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 5356 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5357 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5358 | SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL, |
| 5359 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5360 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5361 | SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL, |
| 5362 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5363 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5364 | SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0, |
| 5365 | tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5366 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5367 | |
| 5368 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 5369 | , tabla_lineout_dac_event, |
| 5370 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5371 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 5372 | , tabla_lineout_dac_event, |
| 5373 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5374 | SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0 |
| 5375 | , tabla_lineout_dac_event, |
| 5376 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5377 | SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 5378 | &lineout3_ground_switch), |
| 5379 | SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0 |
| 5380 | , tabla_lineout_dac_event, |
| 5381 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5382 | SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 5383 | &lineout4_ground_switch), |
| 5384 | SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0 |
| 5385 | , tabla_lineout_dac_event, |
| 5386 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5387 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5388 | 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] | 5389 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5390 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5391 | 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] | 5392 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5393 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5394 | 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] | 5395 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5396 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5397 | 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] | 5398 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5399 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5400 | 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] | 5401 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5402 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5403 | 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] | 5404 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5405 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5406 | 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] | 5407 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5408 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5409 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5410 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5411 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5412 | SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5413 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5414 | SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, |
| 5415 | &rx4_dsm_mux, tabla_codec_reset_interpolator, |
| 5416 | SND_SOC_DAPM_PRE_PMU), |
| 5417 | |
| 5418 | SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, |
| 5419 | &rx6_dsm_mux, tabla_codec_reset_interpolator, |
| 5420 | SND_SOC_DAPM_PRE_PMU), |
| 5421 | |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame^] | 5422 | SND_SOC_DAPM_MIXER_E("RX1 CHAIN", SND_SOC_NOPM, 5, 0, NULL, |
| 5423 | 0, tabla_codec_hphr_dem_input_selection, |
| 5424 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5425 | SND_SOC_DAPM_MIXER_E("RX2 CHAIN", SND_SOC_NOPM, 5, 0, NULL, |
| 5426 | 0, tabla_codec_hphl_dem_input_selection, |
| 5427 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5428 | |
| 5429 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5430 | &rx_mix1_inp1_mux), |
| 5431 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5432 | &rx_mix1_inp2_mux), |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5433 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 5434 | &rx_mix1_inp3_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5435 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5436 | &rx2_mix1_inp1_mux), |
| 5437 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5438 | &rx2_mix1_inp2_mux), |
| 5439 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5440 | &rx3_mix1_inp1_mux), |
| 5441 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5442 | &rx3_mix1_inp2_mux), |
| 5443 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5444 | &rx4_mix1_inp1_mux), |
| 5445 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5446 | &rx4_mix1_inp2_mux), |
| 5447 | SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5448 | &rx5_mix1_inp1_mux), |
| 5449 | SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5450 | &rx5_mix1_inp2_mux), |
| 5451 | SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5452 | &rx6_mix1_inp1_mux), |
| 5453 | SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5454 | &rx6_mix1_inp2_mux), |
| 5455 | SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5456 | &rx7_mix1_inp1_mux), |
| 5457 | SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5458 | &rx7_mix1_inp2_mux), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5459 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5460 | &rx1_mix2_inp1_mux), |
| 5461 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5462 | &rx1_mix2_inp2_mux), |
| 5463 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5464 | &rx2_mix2_inp1_mux), |
| 5465 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5466 | &rx2_mix2_inp2_mux), |
| 5467 | SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5468 | &rx3_mix2_inp1_mux), |
| 5469 | SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5470 | &rx3_mix2_inp2_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5471 | |
| 5472 | SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0, |
| 5473 | tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 5474 | SND_SOC_DAPM_PRE_PMD), |
| 5475 | |
| 5476 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 5477 | tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 5478 | SND_SOC_DAPM_POST_PMD), |
| 5479 | |
| 5480 | /* TX */ |
| 5481 | |
| 5482 | SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 5483 | 0), |
| 5484 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5485 | SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 0, 0, |
| 5486 | tabla_codec_enable_ldo_h, SND_SOC_DAPM_PRE_PMU | |
| 5487 | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5488 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 5489 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0, |
| 5490 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5491 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5492 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0, |
| 5493 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5494 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5495 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5496 | SND_SOC_DAPM_INPUT("AMIC1"), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5497 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5498 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5499 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5500 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5501 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5502 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5503 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5504 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5505 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5506 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0, |
| 5507 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5508 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5509 | |
| 5510 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 5511 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0, |
| 5512 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5513 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5514 | |
| 5515 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 5516 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0, |
| 5517 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5518 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5519 | |
| 5520 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 5521 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0, |
| 5522 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5523 | |
| 5524 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 5525 | SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0, |
| 5526 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5527 | |
| 5528 | 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] | 5529 | &dec1_mux, tabla_codec_enable_dec, |
| 5530 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5531 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5532 | |
| 5533 | 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] | 5534 | &dec2_mux, tabla_codec_enable_dec, |
| 5535 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5536 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5537 | |
| 5538 | 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] | 5539 | &dec3_mux, tabla_codec_enable_dec, |
| 5540 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5541 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5542 | |
| 5543 | 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] | 5544 | &dec4_mux, tabla_codec_enable_dec, |
| 5545 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5546 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5547 | |
| 5548 | 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] | 5549 | &dec5_mux, tabla_codec_enable_dec, |
| 5550 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5551 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5552 | |
| 5553 | 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] | 5554 | &dec6_mux, tabla_codec_enable_dec, |
| 5555 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5556 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5557 | |
| 5558 | 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] | 5559 | &dec7_mux, tabla_codec_enable_dec, |
| 5560 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5561 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5562 | |
| 5563 | 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] | 5564 | &dec8_mux, tabla_codec_enable_dec, |
| 5565 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5566 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5567 | |
| 5568 | 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] | 5569 | &dec9_mux, tabla_codec_enable_dec, |
| 5570 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5571 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5572 | |
| 5573 | 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] | 5574 | &dec10_mux, tabla_codec_enable_dec, |
| 5575 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5576 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5577 | |
| 5578 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 5579 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 5580 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 5581 | SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"), |
| 5582 | SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 5583 | tabla_codec_enable_anc, |
| 5584 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 5585 | SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 5586 | tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU), |
| 5587 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5588 | |
| 5589 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 5590 | |
| 5591 | SND_SOC_DAPM_INPUT("AMIC2"), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5592 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5593 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5594 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5595 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Power External", |
| 5596 | TABLA_A_MICB_2_CTL, 7, 0, |
| 5597 | tabla_codec_enable_micbias_power, |
| 5598 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5599 | SND_SOC_DAPM_POST_PMD), |
| 5600 | |
| 5601 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5602 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5603 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5604 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5605 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5606 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5607 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5608 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5609 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5610 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5611 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5612 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5613 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5614 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5615 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5616 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", SND_SOC_NOPM, 0, 0, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5617 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5618 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5619 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0, |
| 5620 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5621 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5622 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5623 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 5624 | AIF1_CAP, 0, tabla_codec_enable_slimtx, |
| 5625 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5626 | |
| 5627 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 5628 | AIF2_CAP, 0, tabla_codec_enable_slimtx, |
| 5629 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5630 | |
| 5631 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 5632 | AIF3_CAP, 0, tabla_codec_enable_slimtx, |
| 5633 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5634 | |
| 5635 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 5636 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5637 | |
| 5638 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 5639 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5640 | |
| 5641 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 5642 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5643 | |
| 5644 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0, |
| 5645 | &sb_tx1_mux), |
| 5646 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0, |
| 5647 | &sb_tx2_mux), |
| 5648 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0, |
| 5649 | &sb_tx3_mux), |
| 5650 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0, |
| 5651 | &sb_tx4_mux), |
| 5652 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0, |
| 5653 | &sb_tx5_mux), |
| 5654 | SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0, |
| 5655 | &sb_tx6_mux), |
| 5656 | SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0, |
| 5657 | &sb_tx7_mux), |
| 5658 | SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0, |
| 5659 | &sb_tx8_mux), |
| 5660 | SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0, |
| 5661 | &sb_tx9_mux), |
| 5662 | SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0, |
| 5663 | &sb_tx10_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5664 | |
| 5665 | /* Digital Mic Inputs */ |
| 5666 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 5667 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5668 | SND_SOC_DAPM_POST_PMD), |
| 5669 | |
| 5670 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 5671 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5672 | SND_SOC_DAPM_POST_PMD), |
| 5673 | |
| 5674 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 5675 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5676 | SND_SOC_DAPM_POST_PMD), |
| 5677 | |
| 5678 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 5679 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5680 | SND_SOC_DAPM_POST_PMD), |
| 5681 | |
| 5682 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 5683 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5684 | SND_SOC_DAPM_POST_PMD), |
| 5685 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 5686 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5687 | SND_SOC_DAPM_POST_PMD), |
| 5688 | |
| 5689 | /* Sidetone */ |
| 5690 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 5691 | 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] | 5692 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 5693 | SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux), |
| 5694 | SND_SOC_DAPM_PGA("IIR2", TABLA_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0), |
| 5695 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 5696 | /* AUX PGA */ |
| 5697 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0, |
| 5698 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5699 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5700 | SND_SOC_DAPM_POST_PMD), |
| 5701 | |
| 5702 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0, |
| 5703 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5704 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5705 | SND_SOC_DAPM_POST_PMD), |
| 5706 | |
| 5707 | /* Lineout, ear and HPH PA Mixers */ |
| 5708 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5709 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 5710 | |
| 5711 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5712 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 5713 | |
| 5714 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5715 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 5716 | |
| 5717 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5718 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
| 5719 | |
| 5720 | SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5721 | lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)), |
| 5722 | |
| 5723 | SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5724 | lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)), |
| 5725 | |
| 5726 | SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5727 | lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)), |
| 5728 | |
| 5729 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5730 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5731 | }; |
| 5732 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5733 | static short tabla_codec_read_sta_result(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5734 | { |
| 5735 | u8 bias_msb, bias_lsb; |
| 5736 | short bias_value; |
| 5737 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5738 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS); |
| 5739 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS); |
| 5740 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5741 | return bias_value; |
| 5742 | } |
| 5743 | |
| 5744 | static short tabla_codec_read_dce_result(struct snd_soc_codec *codec) |
| 5745 | { |
| 5746 | u8 bias_msb, bias_lsb; |
| 5747 | short bias_value; |
| 5748 | |
| 5749 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS); |
| 5750 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS); |
| 5751 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5752 | return bias_value; |
| 5753 | } |
| 5754 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5755 | 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] | 5756 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5757 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 5758 | } |
| 5759 | |
| 5760 | static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5761 | bool override_bypass, bool noreldetection) |
| 5762 | { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5763 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5764 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5765 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5766 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5767 | if (noreldetection) |
| 5768 | tabla_turn_onoff_rel_detection(codec, false); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5769 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5770 | /* Turn on the override */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5771 | if (!override_bypass) |
| 5772 | 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] | 5773 | if (dce) { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5774 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5775 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
| 5776 | 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] | 5777 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5778 | tabla->mbhc_data.t_sta_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5779 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5780 | usleep_range(tabla->mbhc_data.t_dce, |
| 5781 | tabla->mbhc_data.t_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5782 | bias_value = tabla_codec_read_dce_result(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5783 | } else { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5784 | 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] | 5785 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5786 | 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] | 5787 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5788 | tabla->mbhc_data.t_sta_dce); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5789 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5790 | usleep_range(tabla->mbhc_data.t_sta, |
| 5791 | tabla->mbhc_data.t_sta); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5792 | bias_value = tabla_codec_read_sta_result(codec); |
| 5793 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5794 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5795 | } |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5796 | /* Turn off the override after measuring mic voltage */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5797 | if (!override_bypass) |
| 5798 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 5799 | |
| 5800 | if (noreldetection) |
| 5801 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5802 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5803 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5804 | return bias_value; |
| 5805 | } |
| 5806 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5807 | static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5808 | bool norel) |
| 5809 | { |
| 5810 | return __tabla_codec_sta_dce(codec, dce, false, norel); |
| 5811 | } |
| 5812 | |
| 5813 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5814 | static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5815 | { |
| 5816 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5817 | short bias_value; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5818 | u8 cfilt_mode = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5819 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5820 | pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5821 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5822 | pr_err("Error, no tabla calibration\n"); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5823 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5824 | } |
| 5825 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5826 | if (!tabla->mclk_enabled) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 5827 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5828 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5829 | tabla_enable_rx_bias(codec, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5830 | tabla_codec_enable_clock_block(codec, 1); |
| 5831 | } |
| 5832 | |
| 5833 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5834 | if (!tabla->mbhc_cfg.micbias_always_on) { |
| 5835 | /* Make sure CFILT is in fast mode, save current mode */ |
| 5836 | cfilt_mode = snd_soc_read(codec, |
| 5837 | tabla->mbhc_bias_regs.cfilt_ctl); |
| 5838 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 5839 | 0x70, 0x00); |
| 5840 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 5841 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5842 | 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] | 5843 | |
| 5844 | 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] | 5845 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5846 | |
| 5847 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80); |
| 5848 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C); |
| 5849 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40); |
| 5850 | |
| 5851 | 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] | 5852 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5853 | 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] | 5854 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5855 | 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] | 5856 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5857 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5858 | tabla_codec_calibrate_hs_polling(codec); |
| 5859 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5860 | /* don't flip override */ |
| 5861 | bias_value = __tabla_codec_sta_dce(codec, 1, true, true); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5862 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 5863 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 5864 | 0x40, cfilt_mode); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5865 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5866 | |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5867 | return bias_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5868 | } |
| 5869 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5870 | static int tabla_cancel_btn_work(struct tabla_priv *tabla) |
| 5871 | { |
| 5872 | int r = 0; |
| 5873 | struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent); |
| 5874 | |
| 5875 | if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) { |
| 5876 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 5877 | * we have to unlock from here instead btn_work */ |
| 5878 | wcd9xxx_unlock_sleep(core); |
| 5879 | r = 1; |
| 5880 | } |
| 5881 | return r; |
| 5882 | } |
| 5883 | |
| 5884 | /* called under codec_resource_lock acquisition */ |
| 5885 | void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5886 | { |
| 5887 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5888 | u8 wg_time; |
| 5889 | |
| 5890 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5891 | wg_time += 1; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5892 | |
| 5893 | /* If headphone PA is on, check if userspace receives |
| 5894 | * removal event to sync-up PA's state */ |
| 5895 | if (tabla_is_hph_pa_on(codec)) { |
| 5896 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 5897 | set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5898 | set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5899 | } else { |
| 5900 | pr_debug("%s PA is off\n", __func__); |
| 5901 | } |
| 5902 | |
| 5903 | if (tabla_is_hph_dac_on(codec, 1)) |
| 5904 | set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5905 | if (tabla_is_hph_dac_on(codec, 0)) |
| 5906 | set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5907 | |
| 5908 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 5909 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL, |
Gopikrishnaiah Anandan | 3b230b2 | 2012-12-07 11:36:58 -0500 | [diff] [blame] | 5910 | 0x80, 0x00); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5911 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5912 | 0xC0, 0x00); |
| 5913 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5914 | } |
| 5915 | |
| 5916 | static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla) |
| 5917 | { |
| 5918 | bool pa_turned_on = false; |
| 5919 | struct snd_soc_codec *codec = tabla->codec; |
| 5920 | u8 wg_time; |
| 5921 | |
| 5922 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5923 | wg_time += 1; |
| 5924 | |
| 5925 | if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 5926 | &tabla->hph_pa_dac_state)) { |
| 5927 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 5928 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5929 | 0xC0, 0xC0); |
| 5930 | } |
| 5931 | if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 5932 | &tabla->hph_pa_dac_state)) { |
| 5933 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 5934 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5935 | 0xC0, 0xC0); |
| 5936 | } |
| 5937 | |
| 5938 | if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 5939 | &tabla->hph_pa_dac_state)) { |
| 5940 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 5941 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10, |
| 5942 | 1 << 4); |
| 5943 | pa_turned_on = true; |
| 5944 | } |
| 5945 | if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 5946 | &tabla->hph_pa_dac_state)) { |
| 5947 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 5948 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20, |
| 5949 | 1 << 5); |
| 5950 | pa_turned_on = true; |
| 5951 | } |
| 5952 | |
| 5953 | if (pa_turned_on) { |
| 5954 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 5955 | __func__); |
| 5956 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5957 | } |
| 5958 | } |
| 5959 | |
| 5960 | /* called under codec_resource_lock acquisition */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5961 | static void tabla_codec_enable_mbhc_micbias(struct snd_soc_codec *codec, |
| 5962 | bool enable) |
| 5963 | { |
| 5964 | int r; |
| 5965 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5966 | |
| 5967 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 5968 | return; |
| 5969 | if (enable) { |
| 5970 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 5971 | tabla_codec_update_cfilt_usage(codec, |
| 5972 | tabla->mbhc_bias_regs.cfilt_sel, 1); |
| 5973 | r = snd_soc_dapm_force_enable_pin(&codec->dapm, |
| 5974 | "MIC BIAS2 Power External"); |
| 5975 | snd_soc_dapm_sync(&codec->dapm); |
| 5976 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 5977 | pr_debug("%s: Turning on MICBIAS2 r %d\n", __func__, r); |
| 5978 | } else { |
| 5979 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 5980 | r = snd_soc_dapm_disable_pin(&codec->dapm, |
| 5981 | "MIC BIAS2 Power External"); |
| 5982 | snd_soc_dapm_sync(&codec->dapm); |
| 5983 | tabla_codec_update_cfilt_usage(codec, |
| 5984 | tabla->mbhc_bias_regs.cfilt_sel, 0); |
| 5985 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 5986 | pr_debug("%s: Turning off MICBIAS2 r %d\n", __func__, r); |
| 5987 | } |
| 5988 | } |
| 5989 | |
| 5990 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5991 | static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 5992 | enum snd_jack_types jack_type) |
| 5993 | { |
| 5994 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5995 | pr_debug("%s: enter insertion %d hph_status %x\n", |
| 5996 | __func__, insertion, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5997 | if (!insertion) { |
| 5998 | /* Report removal */ |
| 5999 | tabla->hph_status &= ~jack_type; |
| 6000 | if (tabla->mbhc_cfg.headset_jack) { |
| 6001 | /* cancel possibly scheduled btn work and |
| 6002 | * report release if we reported button press */ |
| 6003 | if (tabla_cancel_btn_work(tabla)) { |
| 6004 | pr_debug("%s: button press is canceled\n", |
| 6005 | __func__); |
| 6006 | } else if (tabla->buttons_pressed) { |
| 6007 | pr_debug("%s: Reporting release for reported " |
| 6008 | "button press %d\n", __func__, |
| 6009 | jack_type); |
| 6010 | tabla_snd_soc_jack_report(tabla, |
| 6011 | tabla->mbhc_cfg.button_jack, 0, |
| 6012 | tabla->buttons_pressed); |
| 6013 | tabla->buttons_pressed &= |
| 6014 | ~TABLA_JACK_BUTTON_MASK; |
| 6015 | } |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6016 | if (jack_type == SND_JACK_HEADSET) |
| 6017 | tabla_codec_enable_mbhc_micbias(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6018 | pr_debug("%s: Reporting removal %d(%x)\n", __func__, |
| 6019 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6020 | tabla_snd_soc_jack_report(tabla, |
| 6021 | tabla->mbhc_cfg.headset_jack, |
| 6022 | tabla->hph_status, |
| 6023 | TABLA_JACK_MASK); |
| 6024 | } |
| 6025 | tabla_set_and_turnoff_hph_padac(codec); |
| 6026 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6027 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6028 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6029 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6030 | tabla->current_plug = PLUG_TYPE_NONE; |
| 6031 | tabla->mbhc_polling_active = false; |
| 6032 | } else { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6033 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 6034 | /* Report removal of current jack type */ |
| 6035 | if (tabla->hph_status != jack_type && |
| 6036 | tabla->mbhc_cfg.headset_jack) { |
| 6037 | pr_debug("%s: Reporting removal (%x)\n", |
| 6038 | __func__, tabla->hph_status); |
| 6039 | tabla_snd_soc_jack_report(tabla, |
| 6040 | tabla->mbhc_cfg.headset_jack, |
| 6041 | 0, TABLA_JACK_MASK); |
| 6042 | tabla->hph_status = 0; |
| 6043 | } |
| 6044 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6045 | /* Report insertion */ |
| 6046 | tabla->hph_status |= jack_type; |
| 6047 | |
| 6048 | if (jack_type == SND_JACK_HEADPHONE) |
| 6049 | tabla->current_plug = PLUG_TYPE_HEADPHONE; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6050 | else if (jack_type == SND_JACK_UNSUPPORTED) |
| 6051 | tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6052 | else if (jack_type == SND_JACK_HEADSET) { |
| 6053 | tabla->mbhc_polling_active = true; |
| 6054 | tabla->current_plug = PLUG_TYPE_HEADSET; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6055 | tabla_codec_enable_mbhc_micbias(codec, true); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6056 | } else if (jack_type == SND_JACK_LINEOUT) |
| 6057 | tabla->current_plug = PLUG_TYPE_HIGH_HPH; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6058 | if (tabla->mbhc_cfg.headset_jack) { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6059 | pr_debug("%s: Reporting insertion %d(%x)\n", __func__, |
| 6060 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6061 | tabla_snd_soc_jack_report(tabla, |
| 6062 | tabla->mbhc_cfg.headset_jack, |
| 6063 | tabla->hph_status, |
| 6064 | TABLA_JACK_MASK); |
| 6065 | } |
| 6066 | tabla_clr_and_turnon_hph_padac(tabla); |
| 6067 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6068 | pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6069 | } |
| 6070 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6071 | static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6072 | int insertion, int trigger, |
| 6073 | bool padac_off) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6074 | { |
| 6075 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6076 | int central_bias_enabled = 0; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6077 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6078 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6079 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6080 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6081 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6082 | pr_debug("%s: enter insertion(%d) trigger(0x%x)\n", |
| 6083 | __func__, insertion, trigger); |
| 6084 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6085 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6086 | pr_err("Error, no tabla calibration\n"); |
| 6087 | return -EINVAL; |
| 6088 | } |
| 6089 | |
| 6090 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 6091 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6092 | /* Make sure mic bias and Mic line schmitt trigger |
| 6093 | * are turned OFF |
| 6094 | */ |
| 6095 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 6096 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6097 | |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6098 | if (insertion) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 6099 | pr_debug("%s: setup for insertion\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6100 | tabla_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6101 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6102 | /* DAPM can manipulate PA/DAC bits concurrently */ |
| 6103 | if (padac_off == true) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6104 | tabla_set_and_turnoff_hph_padac(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6105 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6106 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6107 | if (trigger & MBHC_USE_HPHL_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6108 | /* Enable HPH Schmitt Trigger */ |
| 6109 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11, |
| 6110 | 0x11); |
| 6111 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C, |
| 6112 | plug_det->hph_current << 2); |
| 6113 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02, |
| 6114 | 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6115 | } |
| 6116 | if (trigger & MBHC_USE_MB_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6117 | /* enable the mic line schmitt trigger */ |
| 6118 | snd_soc_update_bits(codec, |
| 6119 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6120 | 0x60, plug_det->mic_current << 5); |
| 6121 | snd_soc_update_bits(codec, |
| 6122 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6123 | 0x80, 0x80); |
| 6124 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
| 6125 | snd_soc_update_bits(codec, |
| 6126 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6127 | 0x00); |
| 6128 | snd_soc_update_bits(codec, |
| 6129 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6130 | 0x10, 0x10); |
| 6131 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6132 | |
| 6133 | /* setup for insetion detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6134 | 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] | 6135 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6136 | pr_debug("setup for removal detection\n"); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6137 | /* Make sure the HPH schmitt trigger is OFF */ |
| 6138 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00); |
| 6139 | |
| 6140 | /* enable the mic line schmitt trigger */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6141 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 6142 | 0x01, 0x00); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6143 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6144 | plug_det->mic_current << 5); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6145 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 6146 | 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6147 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6148 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 6149 | 0x10, 0x10); |
| 6150 | |
| 6151 | /* Setup for low power removal detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6152 | 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] | 6153 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6154 | |
| 6155 | if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6156 | /* called called by interrupt */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6157 | if (!(tabla->clock_active)) { |
| 6158 | tabla_codec_enable_config_mode(codec, 1); |
| 6159 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6160 | 0x06, 0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6161 | usleep_range(generic->t_shutdown_plug_rem, |
| 6162 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6163 | tabla_codec_enable_config_mode(codec, 0); |
| 6164 | } else |
| 6165 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6166 | 0x06, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6167 | } |
| 6168 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 6169 | 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] | 6170 | |
| 6171 | /* If central bandgap disabled */ |
| 6172 | if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) { |
| 6173 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6174 | usleep_range(generic->t_bg_fast_settle, |
| 6175 | generic->t_bg_fast_settle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6176 | central_bias_enabled = 1; |
| 6177 | } |
| 6178 | |
| 6179 | /* If LDO_H disabled */ |
| 6180 | if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) { |
| 6181 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0); |
| 6182 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6183 | usleep_range(generic->t_ldoh, generic->t_ldoh); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6184 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0); |
| 6185 | |
| 6186 | if (central_bias_enabled) |
| 6187 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0); |
| 6188 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6189 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6190 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6191 | tabla->mbhc_cfg.micbias); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6192 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6193 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6194 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0x1); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6195 | pr_debug("%s: leave\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6196 | return 0; |
| 6197 | } |
| 6198 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6199 | static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 6200 | s16 vin_mv) |
| 6201 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6202 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6203 | s16 diff, zero; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6204 | u32 mb_mv, in; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6205 | u16 value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6206 | |
| 6207 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6208 | mb_mv = tabla->mbhc_data.micb_mv; |
| 6209 | |
| 6210 | if (mb_mv == 0) { |
| 6211 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 6212 | return -EINVAL; |
| 6213 | } |
| 6214 | |
| 6215 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6216 | diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z); |
| 6217 | zero = (tabla->mbhc_data.dce_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6218 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6219 | diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z); |
| 6220 | zero = (tabla->mbhc_data.sta_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6221 | } |
| 6222 | in = (u32) diff * vin_mv; |
| 6223 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6224 | value = (u16) (in / mb_mv) + zero; |
| 6225 | return value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 6229 | u16 bias_value) |
| 6230 | { |
| 6231 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6232 | s16 value, z, mb; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6233 | s32 mv; |
| 6234 | |
| 6235 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6236 | value = bias_value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6237 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6238 | z = (tabla->mbhc_data.dce_z); |
| 6239 | mb = (tabla->mbhc_data.dce_mb); |
| 6240 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6241 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6242 | z = (tabla->mbhc_data.sta_z); |
| 6243 | mb = (tabla->mbhc_data.sta_mb); |
| 6244 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | return mv; |
| 6248 | } |
| 6249 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6250 | static void btn_lpress_fn(struct work_struct *work) |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6251 | { |
| 6252 | struct delayed_work *delayed_work; |
| 6253 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6254 | short bias_value; |
| 6255 | int dce_mv, sta_mv; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6256 | struct wcd9xxx *core; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6257 | |
| 6258 | pr_debug("%s:\n", __func__); |
| 6259 | |
| 6260 | delayed_work = to_delayed_work(work); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6261 | tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6262 | core = dev_get_drvdata(tabla->codec->dev->parent); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6263 | |
| 6264 | if (tabla) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6265 | if (tabla->mbhc_cfg.button_jack) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6266 | bias_value = tabla_codec_read_sta_result(tabla->codec); |
| 6267 | sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6268 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6269 | bias_value = tabla_codec_read_dce_result(tabla->codec); |
| 6270 | dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6271 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6272 | pr_debug("%s: Reporting long button press event" |
| 6273 | " STA: %d, DCE: %d\n", __func__, |
| 6274 | sta_mv, dce_mv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6275 | tabla_snd_soc_jack_report(tabla, |
| 6276 | tabla->mbhc_cfg.button_jack, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6277 | tabla->buttons_pressed, |
| 6278 | tabla->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6279 | } |
| 6280 | } else { |
| 6281 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6282 | } |
| 6283 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6284 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6285 | wcd9xxx_unlock_sleep(core); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6286 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6287 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6288 | static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt) |
| 6289 | { |
| 6290 | u16 reg; |
| 6291 | |
| 6292 | switch (cfilt) { |
| 6293 | case TABLA_CFILT1_SEL: |
| 6294 | reg = TABLA_A_MICB_CFILT_1_CTL; |
| 6295 | break; |
| 6296 | case TABLA_CFILT2_SEL: |
| 6297 | reg = TABLA_A_MICB_CFILT_2_CTL; |
| 6298 | break; |
| 6299 | case TABLA_CFILT3_SEL: |
| 6300 | reg = TABLA_A_MICB_CFILT_3_CTL; |
| 6301 | break; |
| 6302 | default: |
| 6303 | BUG(); |
| 6304 | } |
| 6305 | return reg; |
| 6306 | } |
| 6307 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6308 | void tabla_mbhc_cal(struct snd_soc_codec *codec) |
| 6309 | { |
| 6310 | struct tabla_priv *tabla; |
| 6311 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6312 | u8 cfilt_mode, micbias2_cfilt_mode, bg_mode; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6313 | u8 ncic, nmeas, navg; |
| 6314 | u32 mclk_rate; |
| 6315 | u32 dce_wait, sta_wait; |
| 6316 | u8 *n_cic; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6317 | void *calibration; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6318 | u16 bias2_ctl; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6319 | |
| 6320 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6321 | calibration = tabla->mbhc_cfg.calibration; |
| 6322 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6323 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6324 | tabla_turn_onoff_rel_detection(codec, false); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6325 | |
| 6326 | /* First compute the DCE / STA wait times |
| 6327 | * depending on tunable parameters. |
| 6328 | * The value is computed in microseconds |
| 6329 | */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6330 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6331 | 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] | 6332 | ncic = n_cic[tabla_codec_mclk_index(tabla)]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6333 | nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 6334 | navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 6335 | mclk_rate = tabla->mbhc_cfg.mclk_rate; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 6336 | dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000); |
| 6337 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6338 | |
| 6339 | tabla->mbhc_data.t_dce = dce_wait; |
| 6340 | tabla->mbhc_data.t_sta = sta_wait; |
| 6341 | |
| 6342 | /* LDOH and CFILT are already configured during pdata handling. |
| 6343 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 6344 | * Need to restore defaults once calculation is done. |
| 6345 | */ |
| 6346 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6347 | micbias2_cfilt_mode = |
| 6348 | snd_soc_read(codec, tabla_get_cfilt_reg(codec, |
| 6349 | tabla->pdata->micbias.bias2_cfilt_sel)); |
| 6350 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 6351 | TABLA_CFILT_FAST_MODE); |
| 6352 | snd_soc_update_bits(codec, |
| 6353 | tabla_get_cfilt_reg(codec, |
| 6354 | tabla->pdata->micbias.bias2_cfilt_sel), |
| 6355 | 0x40, TABLA_CFILT_FAST_MODE); |
| 6356 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6357 | bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 6358 | 0x02); |
| 6359 | |
| 6360 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 6361 | * to perform ADC calibration |
| 6362 | */ |
| 6363 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6364 | tabla->mbhc_cfg.micbias << 5); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6365 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6366 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60); |
| 6367 | snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78); |
| 6368 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 6369 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6370 | /* MICBIAS2 routing for calibration */ |
| 6371 | bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL); |
| 6372 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2); |
| 6373 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, |
| 6374 | snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg)); |
| 6375 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6376 | /* DCE measurement for 0 volts */ |
| 6377 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6378 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6379 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6380 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 6381 | usleep_range(100, 100); |
| 6382 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6383 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 6384 | tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec); |
| 6385 | |
| 6386 | /* DCE measurment for MB voltage */ |
| 6387 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6388 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
| 6389 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 6390 | usleep_range(100, 100); |
| 6391 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6392 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 6393 | tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec); |
| 6394 | |
| 6395 | /* Sta measuremnt for 0 volts */ |
| 6396 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6397 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6398 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6399 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 6400 | usleep_range(100, 100); |
| 6401 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6402 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 6403 | tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec); |
| 6404 | |
| 6405 | /* STA Measurement for MB Voltage */ |
| 6406 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 6407 | usleep_range(100, 100); |
| 6408 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6409 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 6410 | tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec); |
| 6411 | |
| 6412 | /* Restore default settings. */ |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6413 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl); |
| 6414 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 6415 | tabla->mbhc_cfg.micbias); |
| 6416 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6417 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6418 | snd_soc_update_bits(codec, |
| 6419 | tabla_get_cfilt_reg(codec, |
| 6420 | tabla->pdata->micbias.bias2_cfilt_sel), 0x40, |
| 6421 | micbias2_cfilt_mode); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6422 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 6423 | cfilt_mode); |
| 6424 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 6425 | |
| 6426 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 6427 | usleep_range(100, 100); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6428 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6429 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6430 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6431 | } |
| 6432 | |
| 6433 | void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det, |
| 6434 | const enum tabla_mbhc_btn_det_mem mem) |
| 6435 | { |
| 6436 | void *ret = &btn_det->_v_btn_low; |
| 6437 | |
| 6438 | switch (mem) { |
| 6439 | case TABLA_BTN_DET_GAIN: |
| 6440 | ret += sizeof(btn_det->_n_cic); |
| 6441 | case TABLA_BTN_DET_N_CIC: |
| 6442 | ret += sizeof(btn_det->_n_ready); |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6443 | case TABLA_BTN_DET_N_READY: |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6444 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 6445 | case TABLA_BTN_DET_V_BTN_HIGH: |
| 6446 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 6447 | case TABLA_BTN_DET_V_BTN_LOW: |
| 6448 | /* do nothing */ |
| 6449 | break; |
| 6450 | default: |
| 6451 | ret = NULL; |
| 6452 | } |
| 6453 | |
| 6454 | return ret; |
| 6455 | } |
| 6456 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6457 | static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v, |
| 6458 | bool tovddio) |
| 6459 | { |
| 6460 | int r; |
| 6461 | int vddio_k, mb_k; |
| 6462 | vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6463 | VDDIO_MICBIAS_MV); |
| 6464 | mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6465 | tabla->mbhc_data.micb_mv); |
| 6466 | if (tovddio) |
| 6467 | r = v * vddio_k / mb_k; |
| 6468 | else |
| 6469 | r = v * mb_k / vddio_k; |
| 6470 | return r; |
| 6471 | } |
| 6472 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6473 | static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6474 | { |
| 6475 | s16 deltamv; |
| 6476 | struct tabla_priv *tabla; |
| 6477 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6478 | |
| 6479 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6480 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6481 | |
| 6482 | tabla->mbhc_data.v_b1_h = |
| 6483 | tabla_codec_v_sta_dce(codec, DCE, |
| 6484 | mv + btn_det->v_btn_press_delta_cic); |
| 6485 | |
| 6486 | tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h; |
| 6487 | |
| 6488 | tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN; |
| 6489 | |
| 6490 | deltamv = mv + btn_det->v_btn_press_delta_sta; |
| 6491 | tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv); |
| 6492 | |
| 6493 | deltamv = mv + btn_det->v_btn_press_delta_cic; |
| 6494 | tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv); |
| 6495 | } |
| 6496 | |
| 6497 | static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6498 | { |
| 6499 | tabla_mbhc_calc_rel_thres(codec, mv); |
| 6500 | tabla_codec_calibrate_rel(codec); |
| 6501 | } |
| 6502 | |
| 6503 | static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec) |
| 6504 | { |
| 6505 | struct tabla_priv *tabla; |
| 6506 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6507 | u16 *btn_high; |
| 6508 | |
| 6509 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6510 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6511 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH); |
| 6512 | |
| 6513 | return btn_high[btn_det->num_btn - 1]; |
| 6514 | } |
| 6515 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6516 | static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 6517 | { |
| 6518 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6519 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6520 | struct tabla_mbhc_plug_type_cfg *plug_type; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6521 | u8 *n_ready; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6522 | |
| 6523 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6524 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6525 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6526 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6527 | 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] | 6528 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6529 | tabla->mbhc_data.npoll = 4; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6530 | tabla->mbhc_data.nbounce_wait = 30; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6531 | } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6532 | tabla->mbhc_data.npoll = 7; |
| 6533 | tabla->mbhc_data.nbounce_wait = 23; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6534 | } |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6535 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6536 | tabla->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 6537 | (tabla->mbhc_cfg.mclk_rate / 1000) * |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6538 | n_ready[tabla_codec_mclk_index(tabla)]) + |
| 6539 | 10; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6540 | tabla->mbhc_data.v_ins_hu = |
| 6541 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 6542 | tabla->mbhc_data.v_ins_h = |
| 6543 | tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 6544 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6545 | tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW; |
| 6546 | if (tabla->mbhc_cfg.gpio) |
| 6547 | tabla->mbhc_data.v_inval_ins_high = |
| 6548 | TABLA_MBHC_FAKE_INSERT_HIGH; |
| 6549 | else |
| 6550 | tabla->mbhc_data.v_inval_ins_high = |
| 6551 | TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO; |
| 6552 | |
| 6553 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 6554 | tabla->mbhc_data.adj_v_hs_max = |
| 6555 | tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true); |
| 6556 | tabla->mbhc_data.adj_v_ins_hu = |
| 6557 | tabla_codec_v_sta_dce(codec, STA, |
| 6558 | tabla->mbhc_data.adj_v_hs_max); |
| 6559 | tabla->mbhc_data.adj_v_ins_h = |
| 6560 | tabla_codec_v_sta_dce(codec, DCE, |
| 6561 | tabla->mbhc_data.adj_v_hs_max); |
| 6562 | tabla->mbhc_data.v_inval_ins_low = |
| 6563 | tabla_scale_v_micb_vddio(tabla, |
| 6564 | tabla->mbhc_data.v_inval_ins_low, |
| 6565 | false); |
| 6566 | tabla->mbhc_data.v_inval_ins_high = |
| 6567 | tabla_scale_v_micb_vddio(tabla, |
| 6568 | tabla->mbhc_data.v_inval_ins_high, |
| 6569 | false); |
| 6570 | } |
| 6571 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6572 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6573 | |
| 6574 | tabla->mbhc_data.v_no_mic = |
| 6575 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 6576 | } |
| 6577 | |
| 6578 | void tabla_mbhc_init(struct snd_soc_codec *codec) |
| 6579 | { |
| 6580 | struct tabla_priv *tabla; |
| 6581 | struct tabla_mbhc_general_cfg *generic; |
| 6582 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6583 | int n; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6584 | u8 *n_cic, *gain; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6585 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6586 | |
| 6587 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6588 | generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
| 6589 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6590 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6591 | for (n = 0; n < 8; n++) { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 6592 | if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6593 | snd_soc_update_bits(codec, |
| 6594 | TABLA_A_CDC_MBHC_FEATURE_B1_CFG, |
| 6595 | 0x07, n); |
| 6596 | snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG, |
| 6597 | btn_det->c[n]); |
| 6598 | } |
| 6599 | } |
| 6600 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07, |
| 6601 | btn_det->nc); |
| 6602 | |
| 6603 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
| 6604 | 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] | 6605 | n_cic[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6606 | |
| 6607 | 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] | 6608 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78, |
| 6609 | gain[tabla_codec_mclk_index(tabla)] << 3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6610 | |
| 6611 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 6612 | generic->mbhc_nsa << 4); |
| 6613 | |
| 6614 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 6615 | btn_det->n_meas); |
| 6616 | |
| 6617 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 6618 | |
| 6619 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 6620 | |
| 6621 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78, |
| 6622 | btn_det->mbhc_nsc << 3); |
| 6623 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6624 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03, |
| 6625 | TABLA_MICBIAS2); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6626 | |
| 6627 | 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] | 6628 | |
| 6629 | snd_soc_update_bits(codec, TABLA_A_MBHC_SCALING_MUX_2, 0xF0, 0xF0); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6630 | |
| 6631 | /* override mbhc's micbias */ |
| 6632 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 6633 | tabla->mbhc_cfg.micbias); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6634 | } |
| 6635 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 6636 | static bool tabla_mbhc_fw_validate(const struct firmware *fw) |
| 6637 | { |
| 6638 | u32 cfg_offset; |
| 6639 | struct tabla_mbhc_imped_detect_cfg *imped_cfg; |
| 6640 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 6641 | |
| 6642 | if (fw->size < TABLA_MBHC_CAL_MIN_SIZE) |
| 6643 | return false; |
| 6644 | |
| 6645 | /* previous check guarantees that there is enough fw data up |
| 6646 | * to num_btn |
| 6647 | */ |
| 6648 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 6649 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 6650 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 6651 | return false; |
| 6652 | |
| 6653 | /* previous check guarantees that there is enough fw data up |
| 6654 | * to start of impedance detection configuration |
| 6655 | */ |
| 6656 | imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 6657 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 6658 | |
| 6659 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ)) |
| 6660 | return false; |
| 6661 | |
| 6662 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 6663 | return false; |
| 6664 | |
| 6665 | return true; |
| 6666 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6667 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6668 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6669 | static int tabla_determine_button(const struct tabla_priv *priv, |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6670 | const s32 micmv) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6671 | { |
| 6672 | s16 *v_btn_low, *v_btn_high; |
| 6673 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6674 | int i, btn = -1; |
| 6675 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6676 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6677 | v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW); |
| 6678 | v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6679 | TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6680 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6681 | for (i = 0; i < btn_det->num_btn; i++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6682 | if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6683 | btn = i; |
| 6684 | break; |
| 6685 | } |
| 6686 | } |
| 6687 | |
| 6688 | if (btn == -1) |
| 6689 | pr_debug("%s: couldn't find button number for mic mv %d\n", |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6690 | __func__, micmv); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6691 | |
| 6692 | return btn; |
| 6693 | } |
| 6694 | |
| 6695 | static int tabla_get_button_mask(const int btn) |
| 6696 | { |
| 6697 | int mask = 0; |
| 6698 | switch (btn) { |
| 6699 | case 0: |
| 6700 | mask = SND_JACK_BTN_0; |
| 6701 | break; |
| 6702 | case 1: |
| 6703 | mask = SND_JACK_BTN_1; |
| 6704 | break; |
| 6705 | case 2: |
| 6706 | mask = SND_JACK_BTN_2; |
| 6707 | break; |
| 6708 | case 3: |
| 6709 | mask = SND_JACK_BTN_3; |
| 6710 | break; |
| 6711 | case 4: |
| 6712 | mask = SND_JACK_BTN_4; |
| 6713 | break; |
| 6714 | case 5: |
| 6715 | mask = SND_JACK_BTN_5; |
| 6716 | break; |
| 6717 | case 6: |
| 6718 | mask = SND_JACK_BTN_6; |
| 6719 | break; |
| 6720 | case 7: |
| 6721 | mask = SND_JACK_BTN_7; |
| 6722 | break; |
| 6723 | } |
| 6724 | return mask; |
| 6725 | } |
| 6726 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6727 | static irqreturn_t tabla_dce_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6728 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6729 | int i, mask; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6730 | short dce, sta; |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6731 | s32 mv, mv_s, stamv, stamv_s; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6732 | bool vddio; |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6733 | u16 *btn_high; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6734 | int btn = -1, meas = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6735 | struct tabla_priv *priv = data; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6736 | const struct tabla_mbhc_btn_detect_cfg *d = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6737 | TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6738 | short btnmeas[d->n_btn_meas + 1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6739 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6740 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6741 | int n_btn_meas = d->n_btn_meas; |
| 6742 | 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] | 6743 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6744 | pr_debug("%s: enter\n", __func__); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6745 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6746 | btn_high = tabla_mbhc_cal_btn_det_mp(d, TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6747 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6748 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 6749 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 6750 | __func__); |
| 6751 | goto done; |
| 6752 | } |
| 6753 | |
| 6754 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 6755 | |
| 6756 | if (!priv->mbhc_polling_active) { |
| 6757 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 6758 | __func__); |
| 6759 | goto done; |
| 6760 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6761 | |
| 6762 | dce = tabla_codec_read_dce_result(codec); |
| 6763 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6764 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6765 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 6766 | if (priv->in_gpio_handler) { |
| 6767 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 6768 | __func__); |
| 6769 | btn = -1; |
| 6770 | goto done; |
| 6771 | } |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6772 | vddio = !priv->mbhc_cfg.micbias_always_on && |
| 6773 | (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6774 | priv->mbhc_micbias_switched); |
| 6775 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6776 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6777 | if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) { |
| 6778 | if (priv->mbhc_last_resume && |
| 6779 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 6780 | pr_debug("%s: Button is already released shortly after " |
| 6781 | "resume\n", __func__); |
| 6782 | n_btn_meas = 0; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6783 | } |
| 6784 | } |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 6785 | |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6786 | /* save hw dce */ |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6787 | btnmeas[meas++] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6788 | pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__, |
| 6789 | dce, mv, mv_s, btnmeas[0]); |
| 6790 | if (n_btn_meas == 0) { |
| 6791 | sta = tabla_codec_read_sta_result(codec); |
| 6792 | stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta); |
| 6793 | if (vddio) |
| 6794 | stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false); |
| 6795 | btn = tabla_determine_button(priv, stamv_s); |
| 6796 | pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__, |
| 6797 | sta, stamv, stamv_s, btn); |
| 6798 | BUG_ON(meas != 1); |
| 6799 | if (btnmeas[0] != btn) |
| 6800 | btn = -1; |
| 6801 | } |
| 6802 | |
| 6803 | /* determine pressed button */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6804 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6805 | dce = tabla_codec_sta_dce(codec, 1, false); |
| 6806 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6807 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6808 | |
| 6809 | btnmeas[meas] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6810 | pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n", |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6811 | __func__, meas, dce, mv, mv_s, btnmeas[meas]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6812 | /* if large enough measurements are collected, |
| 6813 | * start to check if last all n_btn_con measurements were |
| 6814 | * in same button low/high range */ |
| 6815 | if (meas + 1 >= d->n_btn_con) { |
| 6816 | for (i = 0; i < d->n_btn_con; i++) |
| 6817 | if ((btnmeas[meas] < 0) || |
| 6818 | (btnmeas[meas] != btnmeas[meas - i])) |
| 6819 | break; |
| 6820 | if (i == d->n_btn_con) { |
| 6821 | /* button pressed */ |
| 6822 | btn = btnmeas[meas]; |
| 6823 | break; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6824 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 6825 | /* if left measurements are less than n_btn_con, |
| 6826 | * it's impossible to find button number */ |
| 6827 | break; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6828 | } |
| 6829 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6830 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6831 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6832 | if (btn >= 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6833 | if (priv->in_gpio_handler) { |
| 6834 | pr_debug("%s: GPIO already triggered, ignore button " |
| 6835 | "press\n", __func__); |
| 6836 | goto done; |
| 6837 | } |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6838 | /* narrow down release threshold */ |
| 6839 | tabla_mbhc_set_rel_thres(codec, btn_high[btn]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6840 | mask = tabla_get_button_mask(btn); |
| 6841 | priv->buttons_pressed |= mask; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6842 | wcd9xxx_lock_sleep(core); |
| 6843 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 6844 | msecs_to_jiffies(400)) == 0) { |
| 6845 | WARN(1, "Button pressed twice without release" |
| 6846 | "event\n"); |
| 6847 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6848 | } |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6849 | } else { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6850 | pr_debug("%s: bogus button press, too short press?\n", |
| 6851 | __func__); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6852 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6853 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6854 | done: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6855 | pr_debug("%s: leave\n", __func__); |
| 6856 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6857 | return IRQ_HANDLED; |
| 6858 | } |
| 6859 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6860 | static int tabla_is_fake_press(struct tabla_priv *priv) |
| 6861 | { |
| 6862 | int i; |
| 6863 | int r = 0; |
| 6864 | struct snd_soc_codec *codec = priv->codec; |
| 6865 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6866 | s16 mb_v, v_ins_hu, v_ins_h; |
| 6867 | |
| 6868 | v_ins_hu = tabla_get_current_v_ins(priv, true); |
| 6869 | v_ins_h = tabla_get_current_v_ins(priv, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6870 | |
| 6871 | for (i = 0; i < dces; i++) { |
| 6872 | usleep_range(10000, 10000); |
| 6873 | if (i == 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6874 | mb_v = tabla_codec_sta_dce(codec, 0, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6875 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 6876 | tabla_codec_sta_dce_v(codec, 0, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6877 | if (mb_v < (s16)priv->mbhc_data.v_b1_hu || |
| 6878 | mb_v > v_ins_hu) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6879 | r = 1; |
| 6880 | break; |
| 6881 | } |
| 6882 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6883 | mb_v = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6884 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 6885 | tabla_codec_sta_dce_v(codec, 1, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6886 | if (mb_v < (s16)priv->mbhc_data.v_b1_h || |
| 6887 | mb_v > v_ins_h) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6888 | r = 1; |
| 6889 | break; |
| 6890 | } |
| 6891 | } |
| 6892 | } |
| 6893 | |
| 6894 | return r; |
| 6895 | } |
| 6896 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6897 | static irqreturn_t tabla_release_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6898 | { |
Joonwoo Park | e5d3aa9 | 2012-01-11 14:47:15 -0800 | [diff] [blame] | 6899 | int ret; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6900 | struct tabla_priv *priv = data; |
| 6901 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6902 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6903 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6904 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6905 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6906 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6907 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6908 | tabla_codec_drive_v_to_micbias(codec, 10000); |
| 6909 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6910 | if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6911 | ret = tabla_cancel_btn_work(priv); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6912 | if (ret == 0) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6913 | pr_debug("%s: Reporting long button release event\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6914 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6915 | if (priv->mbhc_cfg.button_jack) |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6916 | tabla_snd_soc_jack_report(priv, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6917 | priv->mbhc_cfg.button_jack, 0, |
| 6918 | priv->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6919 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6920 | if (tabla_is_fake_press(priv)) { |
| 6921 | pr_debug("%s: Fake button press interrupt\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6922 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6923 | } else if (priv->mbhc_cfg.button_jack) { |
| 6924 | if (priv->in_gpio_handler) { |
| 6925 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 6926 | __func__); |
| 6927 | } else { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6928 | pr_debug("%s: Reporting short button " |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6929 | "press and release\n", |
| 6930 | __func__); |
| 6931 | tabla_snd_soc_jack_report(priv, |
| 6932 | priv->mbhc_cfg.button_jack, |
| 6933 | priv->buttons_pressed, |
| 6934 | priv->buttons_pressed); |
| 6935 | tabla_snd_soc_jack_report(priv, |
| 6936 | priv->mbhc_cfg.button_jack, 0, |
| 6937 | priv->buttons_pressed); |
| 6938 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6939 | } |
| 6940 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6941 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6942 | priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK; |
| 6943 | } |
| 6944 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6945 | /* revert narrowed release threshold */ |
| 6946 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6947 | tabla_codec_calibrate_hs_polling(codec); |
| 6948 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6949 | if (priv->mbhc_cfg.gpio) |
| 6950 | msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6951 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6952 | tabla_codec_start_hs_polling(codec); |
| 6953 | |
| 6954 | pr_debug("%s: leave\n", __func__); |
| 6955 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6956 | return IRQ_HANDLED; |
| 6957 | } |
| 6958 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6959 | static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 6960 | { |
| 6961 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6962 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6963 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6964 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6965 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6966 | tabla_codec_enable_config_mode(codec, 1); |
| 6967 | |
| 6968 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 6969 | 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] | 6970 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6971 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 6972 | |
| 6973 | usleep_range(generic->t_shutdown_plug_rem, |
| 6974 | generic->t_shutdown_plug_rem); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6975 | |
| 6976 | 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] | 6977 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6978 | tabla_codec_enable_config_mode(codec, 0); |
| 6979 | |
| 6980 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00); |
| 6981 | } |
| 6982 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6983 | static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6984 | { |
| 6985 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6986 | |
| 6987 | tabla_codec_shutdown_hs_removal_detect(codec); |
| 6988 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6989 | if (!tabla->mclk_enabled) { |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 6990 | tabla_codec_disable_clock_block(codec); |
| 6991 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | tabla->mbhc_polling_active = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6995 | tabla->mbhc_state = MBHC_STATE_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6996 | } |
| 6997 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6998 | static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data) |
| 6999 | { |
| 7000 | struct tabla_priv *tabla = data; |
| 7001 | struct snd_soc_codec *codec; |
| 7002 | |
| 7003 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 7004 | |
| 7005 | if (tabla) { |
| 7006 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7007 | if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) && |
| 7008 | (!tabla->hphrocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7009 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7010 | tabla->hphlocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7011 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7012 | 0x00); |
| 7013 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7014 | 0x10); |
| 7015 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7016 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7017 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7018 | tabla->hph_status |= SND_JACK_OC_HPHL; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7019 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7020 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7021 | tabla->mbhc_cfg.headset_jack, |
| 7022 | tabla->hph_status, |
| 7023 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7024 | } |
| 7025 | } else { |
| 7026 | pr_err("%s: Bad tabla private data\n", __func__); |
| 7027 | } |
| 7028 | |
| 7029 | return IRQ_HANDLED; |
| 7030 | } |
| 7031 | |
| 7032 | static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data) |
| 7033 | { |
| 7034 | struct tabla_priv *tabla = data; |
| 7035 | struct snd_soc_codec *codec; |
| 7036 | |
| 7037 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 7038 | |
| 7039 | if (tabla) { |
| 7040 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7041 | if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) && |
| 7042 | (!tabla->hphlocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7043 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7044 | tabla->hphrocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7045 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7046 | 0x00); |
| 7047 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7048 | 0x10); |
| 7049 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7050 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7051 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7052 | tabla->hph_status |= SND_JACK_OC_HPHR; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7053 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7054 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7055 | tabla->mbhc_cfg.headset_jack, |
| 7056 | tabla->hph_status, |
| 7057 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7058 | } |
| 7059 | } else { |
| 7060 | pr_err("%s: Bad tabla private data\n", __func__); |
| 7061 | } |
| 7062 | |
| 7063 | return IRQ_HANDLED; |
| 7064 | } |
| 7065 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7066 | static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec, |
| 7067 | s32 mic_volt, bool highhph, bool *highv) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7068 | { |
| 7069 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7070 | bool invalid = false; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7071 | s16 v_hs_max; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7072 | |
| 7073 | /* Perform this check only when the high voltage headphone |
| 7074 | * needs to be considered as invalid |
| 7075 | */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7076 | v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7077 | *highv = mic_volt > v_hs_max; |
| 7078 | if (!highhph && *highv) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7079 | invalid = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7080 | else if (mic_volt < tabla->mbhc_data.v_inval_ins_high && |
| 7081 | (mic_volt > tabla->mbhc_data.v_inval_ins_low)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7082 | invalid = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7083 | |
| 7084 | return invalid; |
| 7085 | } |
| 7086 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7087 | static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec, |
| 7088 | int mic_volt, int mic_volt_prev, |
| 7089 | int threshold) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7090 | { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7091 | return abs(mic_volt - mic_volt_prev) > threshold; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7092 | } |
| 7093 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7094 | /* called under codec_resource_lock acquisition */ |
| 7095 | void tabla_find_plug_and_report(struct snd_soc_codec *codec, |
| 7096 | enum tabla_mbhc_plug_type plug_type) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7097 | { |
| 7098 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7099 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7100 | pr_debug("%s: enter current_plug(%d) new_plug(%d)\n", |
| 7101 | __func__, tabla->current_plug, plug_type); |
| 7102 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7103 | if (plug_type == PLUG_TYPE_HEADPHONE && |
| 7104 | tabla->current_plug == PLUG_TYPE_NONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7105 | /* Nothing was reported previously |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7106 | * report a headphone or unsupported |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7107 | */ |
| 7108 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7109 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7110 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7111 | if (!tabla->mbhc_cfg.detect_extn_cable) { |
| 7112 | if (tabla->current_plug == PLUG_TYPE_HEADSET) |
| 7113 | tabla_codec_report_plug(codec, 0, |
| 7114 | SND_JACK_HEADSET); |
| 7115 | else if (tabla->current_plug == PLUG_TYPE_HEADPHONE) |
| 7116 | tabla_codec_report_plug(codec, 0, |
| 7117 | SND_JACK_HEADPHONE); |
| 7118 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7119 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 7120 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7121 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 7122 | /* If Headphone was reported previously, this will |
| 7123 | * only report the mic line |
| 7124 | */ |
| 7125 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame] | 7126 | if (!tabla->mbhc_micbias_switched && |
| 7127 | tabla_is_hph_pa_on(codec)) { |
| 7128 | /*If the headphone path is on, switch the micbias |
| 7129 | to VDDIO to avoid noise due to button polling */ |
| 7130 | tabla_codec_switch_micbias(codec, 1); |
| 7131 | pr_debug("%s: HPH path is still up\n", __func__); |
| 7132 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7133 | msleep(100); |
| 7134 | tabla_codec_start_hs_polling(codec); |
| 7135 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7136 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7137 | /* High impedance device found. Report as LINEOUT*/ |
| 7138 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 7139 | tabla_codec_cleanup_hs_polling(codec); |
| 7140 | pr_debug("%s: setup mic trigger for further detection\n", |
| 7141 | __func__); |
| 7142 | tabla->lpi_enabled = true; |
| 7143 | /* |
| 7144 | * Do not enable HPHL trigger. If playback is active, |
| 7145 | * it might lead to continuous false HPHL triggers |
| 7146 | */ |
| 7147 | tabla_codec_enable_hs_detect(codec, 1, |
| 7148 | MBHC_USE_MB_TRIGGER, |
| 7149 | false); |
| 7150 | } else { |
| 7151 | if (tabla->current_plug == PLUG_TYPE_NONE) |
| 7152 | tabla_codec_report_plug(codec, 1, |
| 7153 | SND_JACK_HEADPHONE); |
| 7154 | tabla_codec_cleanup_hs_polling(codec); |
| 7155 | pr_debug("setup mic trigger for further detection\n"); |
| 7156 | tabla->lpi_enabled = true; |
| 7157 | tabla_codec_enable_hs_detect(codec, 1, |
| 7158 | MBHC_USE_MB_TRIGGER | |
| 7159 | MBHC_USE_HPHL_TRIGGER, |
| 7160 | false); |
| 7161 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7162 | } else { |
| 7163 | WARN(1, "Unexpected current plug_type %d, plug_type %d\n", |
| 7164 | tabla->current_plug, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7165 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7166 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7167 | } |
| 7168 | |
| 7169 | /* should be called under interrupt context that hold suspend */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7170 | static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla, |
| 7171 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7172 | { |
| 7173 | pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__); |
| 7174 | tabla->hs_detect_work_stop = false; |
| 7175 | wcd9xxx_lock_sleep(tabla->codec->control_data); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7176 | schedule_work(correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7177 | } |
| 7178 | |
| 7179 | /* called under codec_resource_lock acquisition */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7180 | static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla, |
| 7181 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7182 | { |
| 7183 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 7184 | tabla->hs_detect_work_stop = true; |
| 7185 | wmb(); |
| 7186 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7187 | if (cancel_work_sync(correct_plug_work)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7188 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 7189 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 7190 | } |
| 7191 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7192 | } |
| 7193 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7194 | static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla) |
| 7195 | { |
| 7196 | return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) != |
| 7197 | tabla->mbhc_cfg.gpio_level_insert); |
| 7198 | } |
| 7199 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7200 | /* called under codec_resource_lock acquisition */ |
| 7201 | static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on) |
| 7202 | { |
| 7203 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on); |
| 7204 | if (on) |
| 7205 | usleep_range(5000, 5000); |
| 7206 | } |
| 7207 | |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7208 | |
| 7209 | static void tabla_codec_onoff_vddio_switch(struct snd_soc_codec *codec, bool on) |
| 7210 | { |
| 7211 | bool override; |
| 7212 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7213 | |
| 7214 | pr_debug("%s: enter\n", __func__); |
| 7215 | if (on) { |
| 7216 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 7217 | if (!override) |
| 7218 | tabla_turn_onoff_override(codec, true); |
| 7219 | |
| 7220 | /* enable the vddio switch */ |
| 7221 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 7222 | 0x91, 0x81); |
| 7223 | |
| 7224 | /* deroute the override from MicBias2 to MicBias4 */ |
| 7225 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, |
| 7226 | 0x03, 0x03); |
| 7227 | |
| 7228 | usleep_range(MBHC_VDDIO_SWITCH_WAIT_MS * 1000, |
| 7229 | MBHC_VDDIO_SWITCH_WAIT_MS * 1000); |
| 7230 | |
| 7231 | if (!override) |
| 7232 | tabla_turn_onoff_override(codec, false); |
| 7233 | tabla->mbhc_micbias_switched = true; |
| 7234 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
| 7235 | |
| 7236 | } else { |
| 7237 | |
| 7238 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 7239 | 0x91, 0x00); |
| 7240 | |
| 7241 | /* reroute the override to MicBias2 */ |
| 7242 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, |
| 7243 | 0x03, 0x01); |
| 7244 | |
| 7245 | tabla->mbhc_micbias_switched = false; |
| 7246 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
| 7247 | } |
| 7248 | } |
| 7249 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7250 | /* called under codec_resource_lock acquisition and mbhc override = 1 */ |
| 7251 | static enum tabla_mbhc_plug_type |
| 7252 | tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph) |
| 7253 | { |
| 7254 | int i; |
| 7255 | bool gndswitch, vddioswitch; |
| 7256 | int scaled; |
| 7257 | struct tabla_mbhc_plug_type_cfg *plug_type_ptr; |
| 7258 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 7259 | const bool vddio = !tabla->mbhc_cfg.micbias_always_on && |
| 7260 | (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV); |
| 7261 | int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7262 | enum tabla_mbhc_plug_type plug_type[num_det]; |
| 7263 | s16 mb_v[num_det]; |
| 7264 | s32 mic_mv[num_det]; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7265 | bool inval; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7266 | bool highdelta = false; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7267 | bool ahighv = false, highv; |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7268 | bool gndmicswapped = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7269 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7270 | pr_debug("%s: enter\n", __func__); |
| 7271 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7272 | /* make sure override is on */ |
| 7273 | WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04)); |
| 7274 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7275 | /* GND and MIC swap detection requires at least 2 rounds of DCE */ |
| 7276 | BUG_ON(num_det < 2); |
| 7277 | |
| 7278 | plug_type_ptr = |
| 7279 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 7280 | |
| 7281 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7282 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7283 | /* performs DCEs for N times |
| 7284 | * 1st: check if voltage is in invalid range |
| 7285 | * 2nd - N-2nd: check voltage range and delta |
| 7286 | * N-1st: check voltage range, delta with HPHR GND switch |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7287 | * Nth: check voltage range with VDDIO switch */ |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7288 | for (i = 0; i < num_det; i++) { |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7289 | gndswitch = (i == (num_det - 2)); |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7290 | vddioswitch = (i == (num_det - 1)); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7291 | if (i == 0) { |
| 7292 | mb_v[i] = tabla_codec_setup_hs_polling(codec); |
| 7293 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7294 | inval = tabla_is_inval_ins_range(codec, mic_mv[i], |
| 7295 | highhph, &highv); |
| 7296 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7297 | scaled = mic_mv[i]; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7298 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7299 | if (vddioswitch) |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7300 | tabla_codec_onoff_vddio_switch(codec, true); |
| 7301 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7302 | if (gndswitch) |
| 7303 | tabla_codec_hphr_gnd_switch(codec, true); |
| 7304 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 7305 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7306 | if (vddioswitch) |
| 7307 | scaled = tabla_scale_v_micb_vddio(tabla, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7308 | mic_mv[i], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7309 | false); |
| 7310 | else |
| 7311 | scaled = mic_mv[i]; |
| 7312 | /* !gndswitch & vddioswitch means the previous DCE |
| 7313 | * was done with gndswitch, don't compare with DCE |
| 7314 | * with gndswitch */ |
| 7315 | highdelta = tabla_is_inval_ins_delta(codec, scaled, |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7316 | mic_mv[i - 1], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7317 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV); |
| 7318 | inval = (tabla_is_inval_ins_range(codec, mic_mv[i], |
| 7319 | highhph, &highv) || |
| 7320 | highdelta); |
| 7321 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7322 | if (gndswitch) |
| 7323 | tabla_codec_hphr_gnd_switch(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7324 | if (vddioswitch) |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7325 | tabla_codec_onoff_vddio_switch(codec, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7326 | } |
| 7327 | pr_debug("%s: DCE #%d, %04x, V %d, scaled V %d, GND %d, " |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7328 | "VDDIO %d, inval %d\n", __func__, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7329 | i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7330 | vddioswitch, inval); |
| 7331 | /* don't need to run further DCEs */ |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7332 | if ((ahighv || !vddioswitch) && inval) |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7333 | break; |
| 7334 | mic_mv[i] = scaled; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7335 | |
| 7336 | /* |
| 7337 | * claim UNSUPPORTED plug insertion when |
| 7338 | * good headset is detected but HPHR GND switch makes |
| 7339 | * delta difference |
| 7340 | */ |
| 7341 | if (i == (num_det - 2) && highdelta && !ahighv) |
| 7342 | gndmicswapped = true; |
| 7343 | else if (i == (num_det - 1) && inval) { |
| 7344 | if (gndmicswapped) |
| 7345 | plug_type[0] = PLUG_TYPE_GND_MIC_SWAP; |
| 7346 | else |
| 7347 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7348 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7349 | } |
| 7350 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7351 | for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) && |
| 7352 | i < num_det; i++) { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7353 | /* |
| 7354 | * If we are here, means none of the all |
| 7355 | * measurements are fake, continue plug type detection. |
| 7356 | * If all three measurements do not produce same |
| 7357 | * plug type, restart insertion detection |
| 7358 | */ |
| 7359 | if (mic_mv[i] < plug_type_ptr->v_no_mic) { |
| 7360 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 7361 | pr_debug("%s: Detect attempt %d, detected Headphone\n", |
| 7362 | __func__, i); |
| 7363 | } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) { |
| 7364 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 7365 | pr_debug("%s: Detect attempt %d, detected High " |
| 7366 | "Headphone\n", __func__, i); |
| 7367 | } else { |
| 7368 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 7369 | pr_debug("%s: Detect attempt %d, detected Headset\n", |
| 7370 | __func__, i); |
| 7371 | } |
| 7372 | |
| 7373 | if (i > 0 && (plug_type[i - 1] != plug_type[i])) { |
| 7374 | pr_err("%s: Detect attempt %d and %d are not same", |
| 7375 | __func__, i - 1, i); |
| 7376 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7377 | inval = true; |
| 7378 | break; |
| 7379 | } |
| 7380 | } |
| 7381 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7382 | pr_debug("%s: Detected plug type %d\n", __func__, plug_type[0]); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7383 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7384 | return plug_type[0]; |
| 7385 | } |
| 7386 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7387 | static void tabla_hs_correct_gpio_plug(struct work_struct *work) |
| 7388 | { |
| 7389 | struct tabla_priv *tabla; |
| 7390 | struct snd_soc_codec *codec; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7391 | int retry = 0, pt_gnd_mic_swap_cnt = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7392 | bool correction = false; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7393 | enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7394 | unsigned long timeout; |
| 7395 | |
| 7396 | tabla = container_of(work, struct tabla_priv, hs_correct_plug_work); |
| 7397 | codec = tabla->codec; |
| 7398 | |
| 7399 | pr_debug("%s: enter\n", __func__); |
| 7400 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 7401 | |
| 7402 | /* Keep override on during entire plug type correction work. |
| 7403 | * |
| 7404 | * This is okay under the assumption that any GPIO irqs which use |
| 7405 | * MBHC block cancel and sync this work so override is off again |
| 7406 | * prior to GPIO interrupt handler's MBHC block usage. |
| 7407 | * Also while this correction work is running, we can guarantee |
| 7408 | * DAPM doesn't use any MBHC block as this work only runs with |
| 7409 | * headphone detection. |
| 7410 | */ |
| 7411 | tabla_turn_onoff_override(codec, true); |
| 7412 | |
| 7413 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7414 | while (!time_after(jiffies, timeout)) { |
| 7415 | ++retry; |
| 7416 | rmb(); |
| 7417 | if (tabla->hs_detect_work_stop) { |
| 7418 | pr_debug("%s: stop requested\n", __func__); |
| 7419 | break; |
| 7420 | } |
| 7421 | |
| 7422 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 7423 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 7424 | pr_debug("%s: GPIO value is low\n", __func__); |
| 7425 | break; |
| 7426 | } |
| 7427 | |
| 7428 | /* can race with removal interrupt */ |
| 7429 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7430 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7431 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7432 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7433 | pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n", |
| 7434 | __func__, retry, tabla->current_plug, plug_type); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7435 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7436 | pr_debug("Invalid plug in attempt # %d\n", retry); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7437 | if (!tabla->mbhc_cfg.detect_extn_cable && |
| 7438 | retry == NUM_ATTEMPTS_TO_REPORT && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7439 | tabla->current_plug == PLUG_TYPE_NONE) { |
| 7440 | tabla_codec_report_plug(codec, 1, |
| 7441 | SND_JACK_HEADPHONE); |
| 7442 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7443 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7444 | pr_debug("Good headphone detected, continue polling mic\n"); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7445 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7446 | if (tabla->current_plug != plug_type) |
| 7447 | tabla_codec_report_plug(codec, 1, |
| 7448 | SND_JACK_HEADPHONE); |
| 7449 | } else if (tabla->current_plug == PLUG_TYPE_NONE) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7450 | tabla_codec_report_plug(codec, 1, |
| 7451 | SND_JACK_HEADPHONE); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7452 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7453 | if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 7454 | pt_gnd_mic_swap_cnt++; |
| 7455 | if (pt_gnd_mic_swap_cnt < |
| 7456 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) |
| 7457 | continue; |
| 7458 | else if (pt_gnd_mic_swap_cnt > |
| 7459 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) { |
| 7460 | /* This is due to GND/MIC switch didn't |
| 7461 | * work, Report unsupported plug */ |
| 7462 | } else if (tabla->mbhc_cfg.swap_gnd_mic) { |
| 7463 | /* if switch is toggled, check again, |
| 7464 | * otherwise report unsupported plug */ |
| 7465 | if (tabla->mbhc_cfg.swap_gnd_mic(codec)) |
| 7466 | continue; |
| 7467 | } |
| 7468 | } else |
| 7469 | pt_gnd_mic_swap_cnt = 0; |
| 7470 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7471 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7472 | /* Turn off override */ |
| 7473 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7474 | /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP |
| 7475 | */ |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7476 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7477 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7478 | pr_debug("Attempt %d found correct plug %d\n", retry, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7479 | plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7480 | correction = true; |
| 7481 | break; |
| 7482 | } |
| 7483 | } |
| 7484 | |
| 7485 | /* Turn off override */ |
| 7486 | if (!correction) |
| 7487 | tabla_turn_onoff_override(codec, false); |
| 7488 | |
| 7489 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7490 | |
| 7491 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7492 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7493 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE || |
| 7494 | tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP || |
| 7495 | tabla->current_plug == PLUG_TYPE_INVALID || |
| 7496 | plug_type == PLUG_TYPE_INVALID) { |
| 7497 | /* Enable removal detection */ |
| 7498 | tabla_codec_cleanup_hs_polling(codec); |
| 7499 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 7500 | } |
| 7501 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7502 | } |
| 7503 | pr_debug("%s: leave current_plug(%d)\n", |
| 7504 | __func__, tabla->current_plug); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7505 | /* unlock sleep */ |
| 7506 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 7507 | } |
| 7508 | |
| 7509 | /* called under codec_resource_lock acquisition */ |
| 7510 | static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 7511 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7512 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7513 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7514 | |
| 7515 | pr_debug("%s: enter\n", __func__); |
| 7516 | |
| 7517 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7518 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7519 | tabla_turn_onoff_override(codec, false); |
| 7520 | |
| 7521 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 7522 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 7523 | __func__); |
| 7524 | return; |
| 7525 | } |
| 7526 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7527 | if (plug_type == PLUG_TYPE_INVALID || |
| 7528 | plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7529 | tabla_schedule_hs_detect_plug(tabla, |
| 7530 | &tabla->hs_correct_plug_work); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7531 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7532 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7533 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7534 | tabla_schedule_hs_detect_plug(tabla, |
| 7535 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7536 | } else { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7537 | pr_debug("%s: Valid plug found, determine plug type %d\n", |
| 7538 | __func__, plug_type); |
| 7539 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7540 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7541 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7542 | } |
| 7543 | |
| 7544 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7545 | static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 7546 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7547 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7548 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7549 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
| 7550 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7551 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7552 | /* Turn on the override, |
| 7553 | * tabla_codec_setup_hs_polling requires override on */ |
| 7554 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7555 | |
| 7556 | if (plug_det->t_ins_complete > 20) |
| 7557 | msleep(plug_det->t_ins_complete); |
| 7558 | else |
| 7559 | usleep_range(plug_det->t_ins_complete * 1000, |
| 7560 | plug_det->t_ins_complete * 1000); |
| 7561 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7562 | if (tabla->mbhc_cfg.gpio) { |
| 7563 | /* Turn off the override */ |
| 7564 | tabla_turn_onoff_override(codec, false); |
| 7565 | if (tabla_hs_gpio_level_remove(tabla)) |
| 7566 | pr_debug("%s: GPIO value is low when determining " |
| 7567 | "plug\n", __func__); |
| 7568 | else |
| 7569 | tabla_codec_decide_gpio_plug(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7570 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7571 | return; |
| 7572 | } |
| 7573 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7574 | plug_type = tabla_codec_get_plug_type(codec, false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7575 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7576 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7577 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7578 | pr_debug("%s: Invalid plug type detected\n", __func__); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7579 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7580 | tabla_codec_cleanup_hs_polling(codec); |
| 7581 | tabla_codec_enable_hs_detect(codec, 1, |
| 7582 | MBHC_USE_MB_TRIGGER | |
| 7583 | MBHC_USE_HPHL_TRIGGER, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7584 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 7585 | pr_debug("%s: GND-MIC swapped plug type detected\n", __func__); |
| 7586 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 7587 | tabla_codec_cleanup_hs_polling(codec); |
| 7588 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7589 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7590 | pr_debug("%s: Headphone Detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7591 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7592 | tabla_codec_cleanup_hs_polling(codec); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7593 | tabla_schedule_hs_detect_plug(tabla, |
| 7594 | &tabla->hs_correct_plug_work_nogpio); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7595 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7596 | pr_debug("%s: Headset detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7597 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7598 | /* avoid false button press detect */ |
| 7599 | msleep(50); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7600 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7601 | } else if (tabla->mbhc_cfg.detect_extn_cable && |
| 7602 | plug_type == PLUG_TYPE_HIGH_HPH) { |
| 7603 | pr_debug("%s: High impedance plug type detected\n", __func__); |
| 7604 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 7605 | /* Enable insertion detection on the other end of cable */ |
| 7606 | tabla_codec_cleanup_hs_polling(codec); |
| 7607 | tabla_codec_enable_hs_detect(codec, 1, |
| 7608 | MBHC_USE_MB_TRIGGER, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7609 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7610 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7611 | } |
| 7612 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7613 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7614 | 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] | 7615 | { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7616 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7617 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7618 | |
| 7619 | if (!is_removal) { |
| 7620 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
| 7621 | |
| 7622 | rmb(); |
| 7623 | if (priv->lpi_enabled) |
| 7624 | msleep(100); |
| 7625 | |
| 7626 | rmb(); |
| 7627 | if (!priv->lpi_enabled) { |
| 7628 | pr_debug("%s: lpi is disabled\n", __func__); |
| 7629 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 7630 | priv->mbhc_cfg.gpio_level_insert) { |
| 7631 | pr_debug("%s: Valid insertion, " |
| 7632 | "detect plug type\n", __func__); |
| 7633 | tabla_codec_decide_gpio_plug(codec); |
| 7634 | } else { |
| 7635 | pr_debug("%s: Invalid insertion, " |
| 7636 | "stop plug detection\n", __func__); |
| 7637 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7638 | } else if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7639 | pr_debug("%s: Removal\n", __func__); |
| 7640 | if (!tabla_hs_gpio_level_remove(tabla)) { |
| 7641 | /* |
| 7642 | * gpio says, something is still inserted, could be |
| 7643 | * extension cable i.e. headset is removed from |
| 7644 | * extension cable |
| 7645 | */ |
| 7646 | /* cancel detect plug */ |
| 7647 | tabla_cancel_hs_detect_plug(tabla, |
| 7648 | &tabla->hs_correct_plug_work); |
| 7649 | tabla_codec_decide_gpio_plug(codec); |
| 7650 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7651 | } else { |
| 7652 | pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__); |
| 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7657 | static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal, |
| 7658 | bool is_mb_trigger) |
| 7659 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7660 | int ret; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7661 | struct snd_soc_codec *codec = priv->codec; |
| 7662 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7663 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7664 | |
| 7665 | /* Cancel possibly running hs_detect_work */ |
| 7666 | tabla_cancel_hs_detect_plug(tabla, |
| 7667 | &tabla->hs_correct_plug_work_nogpio); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 7668 | |
| 7669 | if (is_removal) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7670 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 7671 | /* |
| 7672 | * If headphone is removed while playback is in progress, |
| 7673 | * it is possible that micbias will be switched to VDDIO. |
| 7674 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7675 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7676 | if (priv->current_plug == PLUG_TYPE_HEADPHONE) |
| 7677 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 7678 | else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP) |
| 7679 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 7680 | else |
| 7681 | WARN(1, "%s: Unexpected current plug type %d\n", |
| 7682 | __func__, priv->current_plug); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7683 | tabla_codec_shutdown_hs_removal_detect(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7684 | tabla_codec_enable_hs_detect(codec, 1, |
| 7685 | MBHC_USE_MB_TRIGGER | |
| 7686 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7687 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7688 | } else if (is_mb_trigger && !is_removal) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7689 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7690 | __func__); |
| 7691 | wcd9xxx_lock_sleep(core); |
| 7692 | if (schedule_delayed_work(&priv->mbhc_insert_dwork, |
| 7693 | usecs_to_jiffies(1000000)) == 0) { |
| 7694 | pr_err("%s: mbhc_insert_dwork is already scheduled\n", |
| 7695 | __func__); |
| 7696 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 7697 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7698 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7699 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7700 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7701 | ret = cancel_delayed_work(&priv->mbhc_insert_dwork); |
| 7702 | if (ret != 0) { |
| 7703 | pr_debug("%s: Complete plug insertion, Detecting plug " |
| 7704 | "type\n", __func__); |
| 7705 | tabla_codec_detect_plug_type(codec); |
| 7706 | wcd9xxx_unlock_sleep(core); |
| 7707 | } else { |
| 7708 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7709 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7710 | pr_err("%s: Error detecting plug insertion\n", |
| 7711 | __func__); |
| 7712 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7713 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7714 | } |
Bhalchandra Gajare | 9494fa26 | 2011-11-10 19:25:59 -0800 | [diff] [blame] | 7715 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7716 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7717 | static void tabla_hs_insert_irq_extn(struct tabla_priv *priv, |
| 7718 | bool is_mb_trigger) |
| 7719 | { |
| 7720 | struct snd_soc_codec *codec = priv->codec; |
| 7721 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7722 | |
| 7723 | /* Cancel possibly running hs_detect_work */ |
| 7724 | tabla_cancel_hs_detect_plug(tabla, |
| 7725 | &tabla->hs_correct_plug_work); |
| 7726 | |
| 7727 | if (is_mb_trigger) { |
| 7728 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7729 | __func__); |
| 7730 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7731 | false); |
| 7732 | } else { |
| 7733 | pr_debug("%s: HPHL trigger received, detecting plug type\n", |
| 7734 | __func__); |
| 7735 | tabla_codec_detect_plug_type(codec); |
| 7736 | } |
| 7737 | } |
| 7738 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7739 | static irqreturn_t tabla_hs_insert_irq(int irq, void *data) |
| 7740 | { |
| 7741 | bool is_mb_trigger, is_removal; |
| 7742 | struct tabla_priv *priv = data; |
| 7743 | struct snd_soc_codec *codec = priv->codec; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7744 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7745 | pr_debug("%s: enter\n", __func__); |
| 7746 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7747 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7748 | |
| 7749 | is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) & |
| 7750 | 0x10); |
| 7751 | is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02); |
| 7752 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 7753 | |
| 7754 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 7755 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 7756 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 7757 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 7758 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7759 | if (priv->mbhc_cfg.detect_extn_cable && |
| 7760 | priv->current_plug == PLUG_TYPE_HIGH_HPH) |
| 7761 | tabla_hs_insert_irq_extn(priv, is_mb_trigger); |
| 7762 | else if (priv->mbhc_cfg.gpio) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7763 | tabla_hs_insert_irq_gpio(priv, is_removal); |
| 7764 | else |
| 7765 | tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger); |
| 7766 | |
| 7767 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7768 | return IRQ_HANDLED; |
| 7769 | } |
| 7770 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7771 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 7772 | { |
| 7773 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7774 | const struct tabla_mbhc_plug_type_cfg *plug_type = |
| 7775 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 7776 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7777 | |
| 7778 | 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] | 7779 | && (mic_mv < v_hs_max)) ? true : false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | /* called under codec_resource_lock acquisition |
| 7783 | * returns true if mic voltage range is back to normal insertion |
| 7784 | * returns false either if timedout or removed */ |
| 7785 | static bool tabla_hs_remove_settle(struct snd_soc_codec *codec) |
| 7786 | { |
| 7787 | int i; |
| 7788 | bool timedout, settled = false; |
| 7789 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7790 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7791 | unsigned long retry = 0, timeout; |
| 7792 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7793 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7794 | |
| 7795 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7796 | while (!(timedout = time_after(jiffies, timeout))) { |
| 7797 | retry++; |
| 7798 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7799 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7800 | break; |
| 7801 | } |
| 7802 | |
| 7803 | if (tabla->mbhc_cfg.gpio) { |
| 7804 | if (retry > 1) |
| 7805 | msleep(250); |
| 7806 | else |
| 7807 | msleep(50); |
| 7808 | } |
| 7809 | |
| 7810 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7811 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7812 | break; |
| 7813 | } |
| 7814 | |
| 7815 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 7816 | mb_v[i] = tabla_codec_sta_dce(codec, 1, true); |
| 7817 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 7818 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 7819 | __func__, retry, mic_mv[i], mb_v[i]); |
| 7820 | } |
| 7821 | |
| 7822 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7823 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7824 | break; |
| 7825 | } |
| 7826 | |
| 7827 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 7828 | pr_debug("%s : headset/headphone is removed\n", |
| 7829 | __func__); |
| 7830 | break; |
| 7831 | } |
| 7832 | |
| 7833 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 7834 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 7835 | break; |
| 7836 | |
| 7837 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7838 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 7839 | settled = true; |
| 7840 | msleep(200); |
| 7841 | break; |
| 7842 | } |
| 7843 | |
| 7844 | /* only for non-GPIO remove irq */ |
| 7845 | if (!tabla->mbhc_cfg.gpio) { |
| 7846 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7847 | if (mic_mv[i] < v_hs_max) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7848 | break; |
| 7849 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7850 | pr_debug("%s: Headset is removed\n", __func__); |
| 7851 | break; |
| 7852 | } |
| 7853 | } |
| 7854 | } |
| 7855 | |
| 7856 | if (timedout) |
| 7857 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 7858 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7859 | return settled; |
| 7860 | } |
| 7861 | |
| 7862 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7863 | static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv) |
| 7864 | { |
| 7865 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7866 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7867 | if (tabla_hs_remove_settle(codec)) |
| 7868 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7869 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7873 | static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7874 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7875 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7876 | bool removed = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7877 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7878 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7879 | TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7880 | int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7881 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7882 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7883 | if (priv->current_plug != PLUG_TYPE_HEADSET) { |
| 7884 | pr_debug("%s(): Headset is not inserted, ignore removal\n", |
| 7885 | __func__); |
| 7886 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7887 | 0x08, 0x08); |
| 7888 | return; |
| 7889 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7890 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7891 | usleep_range(generic->t_shutdown_plug_rem, |
| 7892 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7893 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7894 | do { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7895 | bias_value = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7896 | pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value, |
| 7897 | tabla_codec_sta_dce_v(codec, 1, bias_value), min_us); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7898 | if (bias_value < tabla_get_current_v_ins(priv, false)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7899 | pr_debug("%s: checking false removal\n", __func__); |
| 7900 | msleep(500); |
| 7901 | removed = !tabla_hs_remove_settle(codec); |
| 7902 | pr_debug("%s: headset %sactually removed\n", __func__, |
| 7903 | removed ? "" : "not "); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7904 | break; |
| 7905 | } |
| 7906 | min_us -= priv->mbhc_data.t_dce; |
| 7907 | } while (min_us > 0); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 7908 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7909 | if (removed) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7910 | if (priv->mbhc_cfg.detect_extn_cable) { |
| 7911 | if (!tabla_hs_gpio_level_remove(priv)) { |
| 7912 | /* |
| 7913 | * extension cable is still plugged in |
| 7914 | * report it as LINEOUT device |
| 7915 | */ |
| 7916 | tabla_codec_report_plug(codec, 1, |
| 7917 | SND_JACK_LINEOUT); |
| 7918 | tabla_codec_cleanup_hs_polling(codec); |
| 7919 | tabla_codec_enable_hs_detect(codec, 1, |
| 7920 | MBHC_USE_MB_TRIGGER, |
| 7921 | false); |
| 7922 | } |
| 7923 | } else { |
| 7924 | /* Cancel possibly running hs_detect_work */ |
| 7925 | tabla_cancel_hs_detect_plug(priv, |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7926 | &priv->hs_correct_plug_work_nogpio); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7927 | /* |
| 7928 | * If this removal is not false, first check the micbias |
| 7929 | * switch status and switch it to LDOH if it is already |
| 7930 | * switched to VDDIO. |
| 7931 | */ |
| 7932 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7933 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7934 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 7935 | tabla_codec_cleanup_hs_polling(codec); |
| 7936 | tabla_codec_enable_hs_detect(codec, 1, |
| 7937 | MBHC_USE_MB_TRIGGER | |
| 7938 | MBHC_USE_HPHL_TRIGGER, |
| 7939 | true); |
| 7940 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7941 | } else { |
| 7942 | tabla_codec_start_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7943 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7944 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7945 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7946 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7947 | static irqreturn_t tabla_hs_remove_irq(int irq, void *data) |
| 7948 | { |
| 7949 | struct tabla_priv *priv = data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7950 | bool vddio; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7951 | pr_debug("%s: enter, removal interrupt\n", __func__); |
| 7952 | |
| 7953 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 7954 | vddio = !priv->mbhc_cfg.micbias_always_on && |
| 7955 | (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7956 | priv->mbhc_micbias_switched); |
| 7957 | if (vddio) |
| 7958 | __tabla_codec_switch_micbias(priv->codec, 0, false, true); |
| 7959 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7960 | if ((priv->mbhc_cfg.detect_extn_cable && |
| 7961 | !tabla_hs_gpio_level_remove(priv)) || |
| 7962 | !priv->mbhc_cfg.gpio) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7963 | tabla_hs_remove_irq_nogpio(priv); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7964 | } else |
| 7965 | tabla_hs_remove_irq_gpio(priv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7966 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7967 | /* if driver turned off vddio switch and headset is not removed, |
| 7968 | * turn on the vddio switch back, if headset is removed then vddio |
| 7969 | * switch is off by time now and shouldn't be turn on again from here */ |
| 7970 | if (vddio && priv->current_plug == PLUG_TYPE_HEADSET) |
| 7971 | __tabla_codec_switch_micbias(priv->codec, 1, true, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7972 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7974 | return IRQ_HANDLED; |
| 7975 | } |
| 7976 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7977 | void mbhc_insert_work(struct work_struct *work) |
| 7978 | { |
| 7979 | struct delayed_work *dwork; |
| 7980 | struct tabla_priv *tabla; |
| 7981 | struct snd_soc_codec *codec; |
| 7982 | struct wcd9xxx *tabla_core; |
| 7983 | |
| 7984 | dwork = to_delayed_work(work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7985 | tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7986 | codec = tabla->codec; |
| 7987 | tabla_core = dev_get_drvdata(codec->dev->parent); |
| 7988 | |
| 7989 | pr_debug("%s:\n", __func__); |
| 7990 | |
| 7991 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 7992 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 7993 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 7994 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7995 | wcd9xxx_disable_irq_sync(codec->control_data, |
| 7996 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7997 | tabla_codec_detect_plug_type(codec); |
| 7998 | wcd9xxx_unlock_sleep(tabla_core); |
| 7999 | } |
| 8000 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8001 | static void tabla_hs_gpio_handler(struct snd_soc_codec *codec) |
| 8002 | { |
| 8003 | bool insert; |
| 8004 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8005 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8006 | bool is_removed = false; |
| 8007 | |
| 8008 | pr_debug("%s: enter\n", __func__); |
| 8009 | |
| 8010 | tabla->in_gpio_handler = true; |
| 8011 | /* Wait here for debounce time */ |
| 8012 | usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 8013 | TABLA_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 8014 | |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8015 | wcd9xxx_nested_irq_lock(core); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8016 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8017 | |
| 8018 | /* cancel pending button press */ |
| 8019 | if (tabla_cancel_btn_work(tabla)) |
| 8020 | pr_debug("%s: button press is canceled\n", __func__); |
| 8021 | |
| 8022 | insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) == |
| 8023 | tabla->mbhc_cfg.gpio_level_insert); |
| 8024 | if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) { |
| 8025 | tabla->lpi_enabled = false; |
| 8026 | wmb(); |
| 8027 | |
| 8028 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8029 | tabla_cancel_hs_detect_plug(tabla, |
| 8030 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8031 | |
| 8032 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 8033 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 8034 | 0x00); |
| 8035 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00); |
| 8036 | tabla_codec_detect_plug_type(codec); |
| 8037 | } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 8038 | tabla->lpi_enabled = false; |
| 8039 | wmb(); |
| 8040 | |
| 8041 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8042 | tabla_cancel_hs_detect_plug(tabla, |
| 8043 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8044 | |
| 8045 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE) { |
| 8046 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 8047 | is_removed = true; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 8048 | } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) { |
| 8049 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 8050 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8051 | } else if (tabla->current_plug == PLUG_TYPE_HEADSET) { |
| 8052 | tabla_codec_pause_hs_polling(codec); |
| 8053 | tabla_codec_cleanup_hs_polling(codec); |
| 8054 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 8055 | is_removed = true; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 8056 | } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) { |
| 8057 | tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT); |
| 8058 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8059 | } |
| 8060 | |
| 8061 | if (is_removed) { |
| 8062 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 8063 | snd_soc_update_bits(codec, |
| 8064 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 8065 | 0x01); |
| 8066 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 8067 | 0x01); |
| 8068 | /* Make sure mic trigger is turned off */ |
| 8069 | snd_soc_update_bits(codec, |
| 8070 | tabla->mbhc_bias_regs.ctl_reg, |
| 8071 | 0x01, 0x01); |
| 8072 | snd_soc_update_bits(codec, |
| 8073 | tabla->mbhc_bias_regs.mbhc_reg, |
| 8074 | 0x90, 0x00); |
| 8075 | /* Reset MBHC State Machine */ |
| 8076 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 8077 | 0x08, 0x08); |
| 8078 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 8079 | 0x08, 0x00); |
| 8080 | /* Turn off override */ |
| 8081 | tabla_turn_onoff_override(codec, false); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame] | 8082 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8083 | } |
| 8084 | } |
| 8085 | |
| 8086 | tabla->in_gpio_handler = false; |
| 8087 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8088 | wcd9xxx_nested_irq_unlock(core); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8089 | pr_debug("%s: leave\n", __func__); |
| 8090 | } |
| 8091 | |
| 8092 | static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data) |
| 8093 | { |
| 8094 | int r = IRQ_HANDLED; |
| 8095 | struct snd_soc_codec *codec = data; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8096 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8097 | |
| 8098 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 8099 | pr_warn("%s: failed to hold suspend\n", __func__); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8100 | /* |
| 8101 | * Give up this IRQ for now and resend this IRQ so IRQ can be |
| 8102 | * handled after system resume |
| 8103 | */ |
| 8104 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8105 | tabla->gpio_irq_resend = true; |
| 8106 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8107 | wake_lock_timeout(&tabla->irq_resend_wlock, HZ); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8108 | r = IRQ_NONE; |
| 8109 | } else { |
| 8110 | tabla_hs_gpio_handler(codec); |
| 8111 | wcd9xxx_unlock_sleep(codec->control_data); |
| 8112 | } |
| 8113 | |
| 8114 | return r; |
| 8115 | } |
| 8116 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8117 | static void tabla_hs_correct_plug_nogpio(struct work_struct *work) |
| 8118 | { |
| 8119 | struct tabla_priv *tabla; |
| 8120 | struct snd_soc_codec *codec; |
| 8121 | unsigned long timeout; |
| 8122 | int retry = 0; |
| 8123 | enum tabla_mbhc_plug_type plug_type; |
| 8124 | bool is_headset = false; |
| 8125 | |
| 8126 | pr_debug("%s(): Poll Microphone voltage for %d seconds\n", |
| 8127 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000); |
| 8128 | |
| 8129 | tabla = container_of(work, struct tabla_priv, |
| 8130 | hs_correct_plug_work_nogpio); |
| 8131 | codec = tabla->codec; |
| 8132 | |
| 8133 | /* Make sure the MBHC mux is connected to MIC Path */ |
| 8134 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 8135 | |
| 8136 | /* setup for microphone polling */ |
| 8137 | tabla_turn_onoff_override(codec, true); |
| 8138 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 8139 | |
| 8140 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 8141 | while (!time_after(jiffies, timeout)) { |
| 8142 | ++retry; |
| 8143 | |
| 8144 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 8145 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8146 | plug_type = tabla_codec_get_plug_type(codec, false); |
| 8147 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8148 | |
| 8149 | if (plug_type == PLUG_TYPE_HIGH_HPH |
| 8150 | || plug_type == PLUG_TYPE_INVALID) { |
| 8151 | |
| 8152 | /* this means the plug is removed |
| 8153 | * End microphone polling and setup |
| 8154 | * for low power removal detection. |
| 8155 | */ |
| 8156 | pr_debug("%s(): Plug may be removed, setup removal\n", |
| 8157 | __func__); |
| 8158 | break; |
| 8159 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 8160 | /* Plug is corrected from headphone to headset, |
| 8161 | * report headset and end the polling |
| 8162 | */ |
| 8163 | is_headset = true; |
| 8164 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8165 | tabla_turn_onoff_override(codec, false); |
| 8166 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 8167 | tabla_codec_start_hs_polling(codec); |
| 8168 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8169 | pr_debug("%s(): corrected from headphone to headset\n", |
| 8170 | __func__); |
| 8171 | break; |
| 8172 | } |
| 8173 | } |
| 8174 | |
| 8175 | /* Undo setup for microphone polling depending |
| 8176 | * result from polling |
| 8177 | */ |
| 8178 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 8179 | if (!is_headset) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 8180 | pr_debug("%s: Inserted headphone is not a headset\n", |
| 8181 | __func__); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8182 | tabla_turn_onoff_override(codec, false); |
| 8183 | tabla_codec_cleanup_hs_polling(codec); |
| 8184 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 8185 | } |
| 8186 | wcd9xxx_unlock_sleep(codec->control_data); |
| 8187 | } |
| 8188 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8189 | static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla) |
| 8190 | { |
| 8191 | int ret = 0; |
| 8192 | struct snd_soc_codec *codec = tabla->codec; |
| 8193 | |
| 8194 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 8195 | tabla_mbhc_init(codec); |
| 8196 | tabla_mbhc_cal(codec); |
| 8197 | tabla_mbhc_calc_thres(codec); |
| 8198 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 8199 | tabla_codec_calibrate_hs_polling(codec); |
| 8200 | if (!tabla->mbhc_cfg.gpio) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8201 | INIT_WORK(&tabla->hs_correct_plug_work_nogpio, |
| 8202 | tabla_hs_correct_plug_nogpio); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8203 | ret = tabla_codec_enable_hs_detect(codec, 1, |
| 8204 | MBHC_USE_MB_TRIGGER | |
| 8205 | MBHC_USE_HPHL_TRIGGER, |
| 8206 | false); |
| 8207 | |
| 8208 | if (IS_ERR_VALUE(ret)) |
| 8209 | pr_err("%s: Failed to setup MBHC detection\n", |
| 8210 | __func__); |
| 8211 | } else { |
| 8212 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 8213 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 8214 | 0x01, 0x01); |
| 8215 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01); |
| 8216 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 8217 | tabla_hs_correct_gpio_plug); |
| 8218 | } |
| 8219 | |
| 8220 | if (!IS_ERR_VALUE(ret)) { |
| 8221 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
| 8222 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8223 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8224 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8225 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8226 | |
| 8227 | if (tabla->mbhc_cfg.gpio) { |
| 8228 | ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, |
| 8229 | NULL, |
| 8230 | tabla_mechanical_plug_detect_irq, |
| 8231 | (IRQF_TRIGGER_RISING | |
| 8232 | IRQF_TRIGGER_FALLING), |
| 8233 | "tabla-gpio", codec); |
| 8234 | if (!IS_ERR_VALUE(ret)) { |
| 8235 | ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq); |
| 8236 | /* Bootup time detection */ |
| 8237 | tabla_hs_gpio_handler(codec); |
| 8238 | } |
| 8239 | } |
| 8240 | } |
| 8241 | |
| 8242 | return ret; |
| 8243 | } |
| 8244 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8245 | static void mbhc_fw_read(struct work_struct *work) |
| 8246 | { |
| 8247 | struct delayed_work *dwork; |
| 8248 | struct tabla_priv *tabla; |
| 8249 | struct snd_soc_codec *codec; |
| 8250 | const struct firmware *fw; |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8251 | int ret = -1, retry = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8252 | |
| 8253 | dwork = to_delayed_work(work); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8254 | tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8255 | codec = tabla->codec; |
| 8256 | |
| 8257 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 8258 | retry++; |
| 8259 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 8260 | __func__, retry); |
| 8261 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 8262 | codec->dev); |
| 8263 | |
| 8264 | if (ret != 0) { |
| 8265 | usleep_range(MBHC_FW_READ_TIMEOUT, |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8266 | MBHC_FW_READ_TIMEOUT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8267 | } else { |
| 8268 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 8269 | break; |
| 8270 | } |
| 8271 | } |
| 8272 | |
| 8273 | if (ret != 0) { |
| 8274 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 8275 | __func__); |
| 8276 | } else if (tabla_mbhc_fw_validate(fw) == false) { |
| 8277 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 8278 | __func__); |
| 8279 | release_firmware(fw); |
| 8280 | } else { |
| 8281 | tabla->mbhc_cfg.calibration = (void *)fw->data; |
| 8282 | tabla->mbhc_fw = fw; |
| 8283 | } |
| 8284 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8285 | (void) tabla_mbhc_init_and_calibrate(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8286 | } |
| 8287 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8288 | int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8289 | const struct tabla_mbhc_config *cfg) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8290 | { |
| 8291 | struct tabla_priv *tabla; |
| 8292 | int rc = 0; |
| 8293 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8294 | if (!codec || !cfg->calibration) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8295 | pr_err("Error: no codec or calibration\n"); |
| 8296 | return -EINVAL; |
| 8297 | } |
| 8298 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8299 | if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) { |
| 8300 | if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8301 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8302 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8303 | else |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8304 | pr_err("Error: unsupported clock rate %d\n", |
| 8305 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8306 | return -EINVAL; |
| 8307 | } |
| 8308 | |
| 8309 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8310 | tabla->mbhc_cfg = *cfg; |
| 8311 | tabla->in_gpio_handler = false; |
| 8312 | tabla->current_plug = PLUG_TYPE_NONE; |
| 8313 | tabla->lpi_enabled = false; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8314 | tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs); |
| 8315 | |
| 8316 | /* Put CFILT in fast mode by default */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 8317 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 8318 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8319 | 0x40, TABLA_CFILT_FAST_MODE); |
| 8320 | INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read); |
| 8321 | INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn); |
| 8322 | INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report); |
| 8323 | INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report); |
| 8324 | INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work); |
| 8325 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8326 | if (!tabla->mbhc_cfg.read_fw_bin) |
| 8327 | rc = tabla_mbhc_init_and_calibrate(tabla); |
| 8328 | else |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8329 | schedule_delayed_work(&tabla->mbhc_firmware_dwork, |
| 8330 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8331 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8332 | return rc; |
| 8333 | } |
| 8334 | EXPORT_SYMBOL_GPL(tabla_hs_detect); |
| 8335 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8336 | static irqreturn_t tabla_slimbus_irq(int irq, void *data) |
| 8337 | { |
| 8338 | struct tabla_priv *priv = data; |
| 8339 | struct snd_soc_codec *codec = priv->codec; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8340 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 8341 | int i, j, port_id, k, ch_mask_temp; |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 8342 | unsigned long slimbus_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8343 | u8 val; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8344 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 8345 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8346 | TABLA_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 8347 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8348 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8349 | TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 8350 | if (val & 0x1) |
| 8351 | pr_err_ratelimited("overflow error on port %x," |
| 8352 | " value %x\n", i*8 + j, val); |
| 8353 | if (val & 0x2) |
| 8354 | pr_err_ratelimited("underflow error on port %x," |
| 8355 | " value %x\n", i*8 + j, val); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8356 | if (val & 0x4) { |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8357 | port_id = i*8 + j; |
| 8358 | for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) { |
| 8359 | ch_mask_temp = 1 << port_id; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 8360 | pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8361 | __func__, k, |
| 8362 | tabla_p->dai[k].ch_mask); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8363 | if (ch_mask_temp & |
| 8364 | tabla_p->dai[k].ch_mask) { |
| 8365 | tabla_p->dai[k].ch_mask &= |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8366 | ~ch_mask_temp; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8367 | if (!tabla_p->dai[k].ch_mask) |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8368 | wake_up( |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8369 | &tabla_p->dai[k].dai_wait); |
| 8370 | } |
| 8371 | } |
| 8372 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8373 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8374 | wcd9xxx_interface_reg_write(codec->control_data, |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 8375 | TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value); |
| 8376 | val = 0x0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8377 | } |
| 8378 | |
| 8379 | return IRQ_HANDLED; |
| 8380 | } |
| 8381 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8382 | static int tabla_handle_pdata(struct tabla_priv *tabla) |
| 8383 | { |
| 8384 | struct snd_soc_codec *codec = tabla->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8385 | struct wcd9xxx_pdata *pdata = tabla->pdata; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8386 | int k1, k2, k3, rc = 0; |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8387 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 8388 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 8389 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 8390 | u8 flag = pdata->amic_settings.use_pdata; |
| 8391 | u8 i = 0, j = 0; |
| 8392 | u8 val_txfe = 0, value = 0; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8393 | |
| 8394 | if (!pdata) { |
| 8395 | rc = -ENODEV; |
| 8396 | goto done; |
| 8397 | } |
| 8398 | |
| 8399 | /* Make sure settings are correct */ |
| 8400 | if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) || |
| 8401 | (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8402 | (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8403 | (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8404 | (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) { |
| 8405 | rc = -EINVAL; |
| 8406 | goto done; |
| 8407 | } |
| 8408 | |
| 8409 | /* figure out k value */ |
| 8410 | k1 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8411 | pdata->micbias.cfilt1_mv); |
| 8412 | k2 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8413 | pdata->micbias.cfilt2_mv); |
| 8414 | k3 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8415 | pdata->micbias.cfilt3_mv); |
| 8416 | |
| 8417 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
| 8418 | rc = -EINVAL; |
| 8419 | goto done; |
| 8420 | } |
| 8421 | |
| 8422 | /* Set voltage level and always use LDO */ |
| 8423 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C, |
| 8424 | (pdata->micbias.ldoh_v << 2)); |
| 8425 | |
| 8426 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC, |
| 8427 | (k1 << 2)); |
| 8428 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC, |
| 8429 | (k2 << 2)); |
| 8430 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC, |
| 8431 | (k3 << 2)); |
| 8432 | |
| 8433 | snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60, |
| 8434 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 8435 | snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60, |
| 8436 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 8437 | snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60, |
| 8438 | (pdata->micbias.bias3_cfilt_sel << 5)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8439 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60, |
| 8440 | (pdata->micbias.bias4_cfilt_sel << 5)); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8441 | |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8442 | for (i = 0; i < 6; j++, i += 2) { |
| 8443 | if (flag & (0x01 << i)) { |
| 8444 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 8445 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 8446 | val_txfe = val_txfe | |
| 8447 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 8448 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 8449 | 0x10, value); |
| 8450 | snd_soc_update_bits(codec, |
| 8451 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 8452 | 0x30, val_txfe); |
| 8453 | } |
| 8454 | if (flag & (0x01 << (i + 1))) { |
| 8455 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 8456 | val_txfe = (txfe_bypass & |
| 8457 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 8458 | val_txfe |= (txfe_buff & |
| 8459 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 8460 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 8461 | 0x01, value); |
| 8462 | snd_soc_update_bits(codec, |
| 8463 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 8464 | 0x03, val_txfe); |
| 8465 | } |
| 8466 | } |
| 8467 | if (flag & 0x40) { |
| 8468 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 8469 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 8470 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 8471 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, |
| 8472 | 0x13, value); |
| 8473 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8474 | |
| 8475 | if (pdata->ocp.use_pdata) { |
| 8476 | /* not defined in CODEC specification */ |
| 8477 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 8478 | pdata->ocp.hph_ocp_limit == 5) { |
| 8479 | rc = -EINVAL; |
| 8480 | goto done; |
| 8481 | } |
| 8482 | snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL, |
| 8483 | 0x0F, pdata->ocp.num_attempts); |
| 8484 | snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT, |
| 8485 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 8486 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, |
| 8487 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 8488 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8489 | |
| 8490 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 8491 | if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) { |
| 8492 | if (pdata->regulator[i].min_uV == 1800000 && |
| 8493 | pdata->regulator[i].max_uV == 1800000) { |
| 8494 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8495 | 0x1C); |
| 8496 | } else if (pdata->regulator[i].min_uV == 2200000 && |
| 8497 | pdata->regulator[i].max_uV == 2200000) { |
| 8498 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8499 | 0x1E); |
| 8500 | } else { |
| 8501 | pr_err("%s: unsupported CDC_VDDA_RX voltage " |
| 8502 | "min %d, max %d\n", __func__, |
| 8503 | pdata->regulator[i].min_uV, |
| 8504 | pdata->regulator[i].max_uV); |
| 8505 | rc = -EINVAL; |
| 8506 | } |
| 8507 | break; |
| 8508 | } |
| 8509 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8510 | done: |
| 8511 | return rc; |
| 8512 | } |
| 8513 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8514 | static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = { |
| 8515 | |
| 8516 | /* Tabla 1.1 MICBIAS changes */ |
| 8517 | TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24), |
| 8518 | TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24), |
| 8519 | TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24), |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8520 | |
| 8521 | /* Tabla 1.1 HPH changes */ |
| 8522 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57), |
| 8523 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56), |
| 8524 | |
| 8525 | /* Tabla 1.1 EAR PA changes */ |
| 8526 | TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6), |
| 8527 | TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02), |
| 8528 | TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03), |
| 8529 | |
| 8530 | /* Tabla 1.1 Lineout_5 Changes */ |
| 8531 | TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10), |
| 8532 | |
| 8533 | /* Tabla 1.1 RX Changes */ |
| 8534 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78), |
| 8535 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78), |
| 8536 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78), |
| 8537 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78), |
| 8538 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78), |
| 8539 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78), |
| 8540 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78), |
| 8541 | |
| 8542 | /* Tabla 1.1 RX1 and RX2 Changes */ |
| 8543 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0), |
| 8544 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0), |
| 8545 | |
| 8546 | /* Tabla 1.1 RX3 to RX7 Changes */ |
| 8547 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80), |
| 8548 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80), |
| 8549 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80), |
| 8550 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80), |
| 8551 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80), |
| 8552 | |
| 8553 | /* Tabla 1.1 CLASSG Changes */ |
| 8554 | TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 8555 | }; |
| 8556 | |
| 8557 | static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = { |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8558 | /* Tabla 2.0 MICBIAS changes */ |
| 8559 | TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02), |
| 8560 | }; |
| 8561 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8562 | static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = { |
| 8563 | TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24), |
| 8564 | }; |
| 8565 | |
| 8566 | static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = { |
| 8567 | TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24), |
| 8568 | }; |
| 8569 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8570 | static void tabla_update_reg_defaults(struct snd_soc_codec *codec) |
| 8571 | { |
| 8572 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8573 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8574 | |
| 8575 | for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++) |
| 8576 | snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg, |
| 8577 | tabla_1_1_reg_defaults[i].val); |
| 8578 | |
| 8579 | for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++) |
| 8580 | snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg, |
| 8581 | tabla_2_0_reg_defaults[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8582 | |
| 8583 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8584 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults); |
| 8585 | i++) |
| 8586 | snd_soc_write(codec, |
| 8587 | tabla_1_x_only_reg_2_0_defaults[i].reg, |
| 8588 | tabla_1_x_only_reg_2_0_defaults[i].val); |
| 8589 | } else { |
| 8590 | for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++) |
| 8591 | snd_soc_write(codec, |
| 8592 | tabla_2_only_reg_2_0_defaults[i].reg, |
| 8593 | tabla_2_only_reg_2_0_defaults[i].val); |
| 8594 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8595 | } |
| 8596 | |
| 8597 | static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8598 | /* Initialize current threshold to 350MA |
| 8599 | * number of wait and run cycles to 4096 |
| 8600 | */ |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8601 | {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8602 | {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8603 | |
Santosh Mardi | 3217101 | 2011-10-28 23:32:06 +0530 | [diff] [blame] | 8604 | {TABLA_A_QFUSE_CTL, 0xFF, 0x03}, |
| 8605 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8606 | /* Initialize gain registers to use register gain */ |
| 8607 | {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 8608 | {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 8609 | {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 8610 | {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 8611 | {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10}, |
| 8612 | {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10}, |
| 8613 | |
Kuirong Wang | ccb29c6 | 2012-06-15 11:09:07 -0700 | [diff] [blame] | 8614 | /* Set the MICBIAS default output as pull down*/ |
| 8615 | {TABLA_A_MICB_1_CTL, 0x01, 0x01}, |
| 8616 | {TABLA_A_MICB_2_CTL, 0x01, 0x01}, |
| 8617 | {TABLA_A_MICB_3_CTL, 0x01, 0x01}, |
| 8618 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8619 | /* Initialize mic biases to differential mode */ |
| 8620 | {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 8621 | {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 8622 | {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8623 | |
| 8624 | {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 8625 | |
| 8626 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 8627 | {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 8628 | {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 8629 | {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 8630 | {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 8631 | {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 8632 | {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20}, |
| 8633 | |
| 8634 | /* Use 16 bit sample size for TX7 to TX10 */ |
| 8635 | {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40}, |
| 8636 | {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40}, |
| 8637 | {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40}, |
| 8638 | {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40}, |
| 8639 | |
| 8640 | /* Use 16 bit sample size for RX */ |
| 8641 | {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 8642 | {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA}, |
| 8643 | |
| 8644 | /*enable HPF filter for TX paths */ |
| 8645 | {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 8646 | {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 8647 | {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 8648 | {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 8649 | {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0}, |
| 8650 | {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0}, |
| 8651 | {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0}, |
| 8652 | {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0}, |
| 8653 | {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0}, |
| 8654 | {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0}, |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 8655 | |
| 8656 | /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */ |
| 8657 | {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1}, |
| 8658 | {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1}, |
| 8659 | {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1}, |
| 8660 | {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1}, |
| 8661 | {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1}, |
| 8662 | {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1}, |
| 8663 | {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1}, |
| 8664 | {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1}, |
| 8665 | {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1}, |
| 8666 | {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1}, |
| 8667 | |
| 8668 | /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */ |
| 8669 | {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A}, |
| 8670 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8671 | }; |
| 8672 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8673 | static const struct tabla_reg_mask_val tabla_1_x_codec_reg_init_val[] = { |
Kuirong Wang | ccb29c6 | 2012-06-15 11:09:07 -0700 | [diff] [blame] | 8674 | /* Set the MICBIAS default output as pull down*/ |
| 8675 | {TABLA_1_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8676 | /* Initialize mic biases to differential mode */ |
| 8677 | {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8678 | }; |
| 8679 | |
| 8680 | static const struct tabla_reg_mask_val tabla_2_higher_codec_reg_init_val[] = { |
Kuirong Wang | ccb29c6 | 2012-06-15 11:09:07 -0700 | [diff] [blame] | 8681 | |
| 8682 | /* Set the MICBIAS default output as pull down*/ |
| 8683 | {TABLA_2_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8684 | /* Initialize mic biases to differential mode */ |
| 8685 | {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8686 | }; |
| 8687 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8688 | static void tabla_codec_init_reg(struct snd_soc_codec *codec) |
| 8689 | { |
| 8690 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8691 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8692 | |
| 8693 | for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++) |
| 8694 | snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg, |
| 8695 | tabla_codec_reg_init_val[i].mask, |
| 8696 | tabla_codec_reg_init_val[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8697 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8698 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++) |
| 8699 | snd_soc_update_bits(codec, |
| 8700 | tabla_1_x_codec_reg_init_val[i].reg, |
| 8701 | tabla_1_x_codec_reg_init_val[i].mask, |
| 8702 | tabla_1_x_codec_reg_init_val[i].val); |
| 8703 | } else { |
| 8704 | for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val); |
| 8705 | i++) |
| 8706 | snd_soc_update_bits(codec, |
| 8707 | tabla_2_higher_codec_reg_init_val[i].reg, |
| 8708 | tabla_2_higher_codec_reg_init_val[i].mask, |
| 8709 | tabla_2_higher_codec_reg_init_val[i].val); |
| 8710 | } |
| 8711 | } |
| 8712 | |
| 8713 | static void tabla_update_reg_address(struct tabla_priv *priv) |
| 8714 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8715 | struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8716 | struct tabla_reg_address *reg_addr = &priv->reg_addr; |
| 8717 | |
| 8718 | if (TABLA_IS_1_X(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8719 | reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC; |
| 8720 | 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] | 8721 | reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8722 | } else if (TABLA_IS_2_0(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8723 | reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC; |
| 8724 | 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] | 8725 | reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8726 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8727 | } |
| 8728 | |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8729 | #ifdef CONFIG_DEBUG_FS |
| 8730 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 8731 | { |
| 8732 | file->private_data = inode->i_private; |
| 8733 | return 0; |
| 8734 | } |
| 8735 | |
| 8736 | static ssize_t codec_debug_write(struct file *filp, |
| 8737 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 8738 | { |
| 8739 | char lbuf[32]; |
| 8740 | char *buf; |
| 8741 | int rc; |
| 8742 | struct tabla_priv *tabla = filp->private_data; |
| 8743 | |
| 8744 | if (cnt > sizeof(lbuf) - 1) |
| 8745 | return -EINVAL; |
| 8746 | |
| 8747 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 8748 | if (rc) |
| 8749 | return -EFAULT; |
| 8750 | |
| 8751 | lbuf[cnt] = '\0'; |
| 8752 | buf = (char *)lbuf; |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 8753 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8754 | tabla->no_mic_headset_override = |
| 8755 | (*strsep(&buf, " ") == '0') ? false : true; |
| 8756 | if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) { |
| 8757 | tabla_codec_pause_hs_polling(tabla->codec); |
| 8758 | tabla_codec_start_hs_polling(tabla->codec); |
| 8759 | } |
| 8760 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8761 | return cnt; |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8762 | } |
| 8763 | |
| 8764 | static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf, |
| 8765 | size_t count, loff_t *pos) |
| 8766 | { |
| 8767 | const int size = 768; |
| 8768 | char buffer[size]; |
| 8769 | int n = 0; |
| 8770 | struct tabla_priv *tabla = file->private_data; |
| 8771 | struct snd_soc_codec *codec = tabla->codec; |
| 8772 | const struct mbhc_internal_cal_data *p = &tabla->mbhc_data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8773 | const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true); |
| 8774 | 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] | 8775 | |
| 8776 | n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z, |
| 8777 | tabla_codec_sta_dce_v(codec, 1, p->dce_z)); |
| 8778 | n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n", |
| 8779 | p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb)); |
| 8780 | n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n", |
| 8781 | p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z)); |
| 8782 | n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n", |
| 8783 | p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb)); |
| 8784 | n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce); |
| 8785 | n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta); |
| 8786 | n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n", |
| 8787 | p->micb_mv); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8788 | 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] | 8789 | p->v_ins_hu, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8790 | tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu), |
| 8791 | p->v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8792 | n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n", |
| 8793 | p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h), |
| 8794 | p->v_ins_h == v_ins_h_cur ? "*" : ""); |
| 8795 | n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n", |
| 8796 | p->adj_v_ins_hu, |
| 8797 | tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu), |
| 8798 | p->adj_v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8799 | n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n", |
| 8800 | p->adj_v_ins_h, |
| 8801 | tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h), |
| 8802 | p->adj_v_ins_h == v_ins_h_cur ? "*" : ""); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8803 | n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n", |
| 8804 | p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu)); |
| 8805 | n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n", |
| 8806 | p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h)); |
| 8807 | n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n", |
| 8808 | p->v_b1_huc, |
| 8809 | tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc)); |
| 8810 | n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n", |
| 8811 | p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh)); |
| 8812 | n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl, |
| 8813 | tabla_codec_sta_dce_v(codec, 0, p->v_brl)); |
| 8814 | n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n", |
| 8815 | p->v_no_mic, |
| 8816 | tabla_codec_sta_dce_v(codec, 0, p->v_no_mic)); |
| 8817 | n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll); |
| 8818 | n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n", |
| 8819 | p->nbounce_wait); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8820 | n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n", |
| 8821 | p->v_inval_ins_low); |
| 8822 | n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n", |
| 8823 | p->v_inval_ins_high); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 8824 | if (tabla->mbhc_cfg.gpio) |
| 8825 | n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n", |
| 8826 | tabla_hs_gpio_level_remove(tabla)); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8827 | buffer[n] = 0; |
| 8828 | |
| 8829 | return simple_read_from_buffer(buf, count, pos, buffer, n); |
| 8830 | } |
| 8831 | |
| 8832 | static const struct file_operations codec_debug_ops = { |
| 8833 | .open = codec_debug_open, |
| 8834 | .write = codec_debug_write, |
| 8835 | }; |
| 8836 | |
| 8837 | static const struct file_operations codec_mbhc_debug_ops = { |
| 8838 | .open = codec_debug_open, |
| 8839 | .read = codec_mbhc_debug_read, |
| 8840 | }; |
| 8841 | #endif |
| 8842 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8843 | static int tabla_codec_probe(struct snd_soc_codec *codec) |
| 8844 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8845 | struct wcd9xxx *control; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8846 | struct tabla_priv *tabla; |
| 8847 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 8848 | int ret = 0; |
| 8849 | int i; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8850 | void *ptr = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8851 | |
| 8852 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 8853 | control = codec->control_data; |
| 8854 | |
| 8855 | tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL); |
| 8856 | if (!tabla) { |
| 8857 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 8858 | return -ENOMEM; |
| 8859 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 8860 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 8861 | tx_hpf_work[i].tabla = tabla; |
| 8862 | tx_hpf_work[i].decimator = i + 1; |
| 8863 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 8864 | tx_hpf_corner_freq_callback); |
| 8865 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8866 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8867 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 8868 | memset(&tabla->mbhc_bias_regs, 0, |
| 8869 | sizeof(struct mbhc_micbias_regs)); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 8870 | tabla->mbhc_micbias_switched = false; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8871 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8872 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 8873 | memset(&tabla->mbhc_data, 0, |
| 8874 | sizeof(struct mbhc_internal_cal_data)); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 8875 | tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8876 | tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 8877 | tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8878 | snd_soc_codec_set_drvdata(codec, tabla); |
| 8879 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 8880 | tabla->mclk_enabled = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8881 | tabla->bandgap_type = TABLA_BANDGAP_OFF; |
| 8882 | tabla->clock_active = false; |
| 8883 | tabla->config_mode_active = false; |
| 8884 | tabla->mbhc_polling_active = false; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 8885 | tabla->mbhc_fake_ins_start = 0; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8886 | tabla->no_mic_headset_override = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8887 | tabla->hs_polling_irq_prepared = false; |
| 8888 | mutex_init(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8889 | tabla->codec = codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8890 | tabla->mbhc_state = MBHC_STATE_NONE; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8891 | tabla->mbhc_last_resume = 0; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 8892 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 8893 | tabla->comp_enabled[i] = 0; |
| 8894 | tabla->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 8895 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8896 | tabla->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8897 | tabla->intf_type = wcd9xxx_get_intf_type(); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 8898 | tabla->aux_pga_cnt = 0; |
| 8899 | tabla->aux_l_gain = 0x1F; |
| 8900 | tabla->aux_r_gain = 0x1F; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8901 | tabla_update_reg_address(tabla); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8902 | tabla_update_reg_defaults(codec); |
| 8903 | tabla_codec_init_reg(codec); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8904 | ret = tabla_handle_pdata(tabla); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8905 | if (IS_ERR_VALUE(ret)) { |
| 8906 | pr_err("%s: bad pdata\n", __func__); |
| 8907 | goto err_pdata; |
| 8908 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8909 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8910 | if (TABLA_IS_1_X(control->version)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8911 | snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8912 | ARRAY_SIZE(tabla_1_x_snd_controls)); |
| 8913 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8914 | snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8915 | ARRAY_SIZE(tabla_2_higher_snd_controls)); |
| 8916 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8917 | if (TABLA_IS_1_X(control->version)) |
| 8918 | snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets, |
| 8919 | ARRAY_SIZE(tabla_1_x_dapm_widgets)); |
| 8920 | else |
| 8921 | snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets, |
| 8922 | ARRAY_SIZE(tabla_2_higher_dapm_widgets)); |
| 8923 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8924 | ptr = kmalloc((sizeof(tabla_rx_chs) + |
| 8925 | sizeof(tabla_tx_chs)), GFP_KERNEL); |
| 8926 | if (!ptr) { |
| 8927 | pr_err("%s: no mem for slim chan ctl data\n", __func__); |
| 8928 | ret = -ENOMEM; |
| 8929 | goto err_nomem_slimch; |
| 8930 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8931 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8932 | snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets, |
| 8933 | ARRAY_SIZE(tabla_dapm_i2s_widgets)); |
| 8934 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 8935 | ARRAY_SIZE(audio_i2s_map)); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8936 | for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++) |
| 8937 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8938 | } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 8939 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 8940 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8941 | init_waitqueue_head(&tabla->dai[i].dai_wait); |
| 8942 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8943 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8944 | |
| 8945 | control->num_rx_port = TABLA_RX_MAX; |
| 8946 | control->rx_chs = ptr; |
| 8947 | memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs)); |
| 8948 | control->num_tx_port = TABLA_TX_MAX; |
| 8949 | control->tx_chs = ptr + sizeof(tabla_rx_chs); |
| 8950 | memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs)); |
| 8951 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 8952 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8953 | if (TABLA_IS_1_X(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8954 | 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] | 8955 | ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map)); |
| 8956 | } else if (TABLA_IS_2_0(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8957 | 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] | 8958 | ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map)); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8959 | } else { |
| 8960 | pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n", |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8961 | __func__, control->version); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8962 | goto err_pdata; |
| 8963 | } |
| 8964 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8965 | snd_soc_dapm_sync(dapm); |
| 8966 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8967 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8968 | WCD9XXX_IRQ_MBHC_INSERTION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8969 | tabla_hs_insert_irq, "Headset insert detect", tabla); |
| 8970 | if (ret) { |
| 8971 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8972 | WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8973 | goto err_insert_irq; |
| 8974 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8975 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8976 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8977 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8978 | WCD9XXX_IRQ_MBHC_REMOVAL, |
| 8979 | tabla_hs_remove_irq, |
| 8980 | "Headset remove detect", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8981 | if (ret) { |
| 8982 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8983 | WCD9XXX_IRQ_MBHC_REMOVAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8984 | goto err_remove_irq; |
| 8985 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8986 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8987 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8988 | WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 8989 | tabla_dce_handler, "DC Estimation detect", |
| 8990 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8991 | if (ret) { |
| 8992 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8993 | WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8994 | goto err_potential_irq; |
| 8995 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8996 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8997 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, |
| 8998 | tabla_release_handler, |
| 8999 | "Button Release detect", tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9000 | if (ret) { |
| 9001 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9002 | WCD9XXX_IRQ_MBHC_RELEASE); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9003 | goto err_release_irq; |
| 9004 | } |
| 9005 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9006 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, |
| 9007 | tabla_slimbus_irq, "SLIMBUS Slave", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9008 | if (ret) { |
| 9009 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9010 | WCD9XXX_IRQ_SLIMBUS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9011 | goto err_slimbus_irq; |
| 9012 | } |
| 9013 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9014 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 9015 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9016 | TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 9017 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9018 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9019 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, |
| 9020 | tabla_hphl_ocp_irq, |
| 9021 | "HPH_L OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9022 | if (ret) { |
| 9023 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9024 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9025 | goto err_hphl_ocp_irq; |
| 9026 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9027 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9028 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9029 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9030 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT, |
| 9031 | tabla_hphr_ocp_irq, |
| 9032 | "HPH_R OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9033 | if (ret) { |
| 9034 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9035 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9036 | goto err_hphr_ocp_irq; |
| 9037 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9038 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9039 | |
| 9040 | /* |
| 9041 | * Register suspend lock and notifier to resend edge triggered |
| 9042 | * gpio IRQs |
| 9043 | */ |
| 9044 | wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND, |
| 9045 | "tabla_gpio_irq_resend"); |
| 9046 | tabla->gpio_irq_resend = false; |
| 9047 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 9048 | mutex_lock(&dapm->codec->mutex); |
| 9049 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 9050 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 9051 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 9052 | snd_soc_dapm_sync(dapm); |
| 9053 | mutex_unlock(&dapm->codec->mutex); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9054 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9055 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 9056 | if (ret == 0) { |
| 9057 | tabla->debugfs_poke = |
| 9058 | debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla, |
| 9059 | &codec_debug_ops); |
| 9060 | tabla->debugfs_mbhc = |
| 9061 | debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO, |
| 9062 | NULL, tabla, &codec_mbhc_debug_ops); |
| 9063 | } |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9064 | #endif |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9065 | codec->ignore_pmdown_time = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9066 | return ret; |
| 9067 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9068 | err_hphr_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9069 | wcd9xxx_free_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9070 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9071 | err_hphl_ocp_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9072 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9073 | err_slimbus_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9074 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9075 | err_release_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9076 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 9077 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9078 | err_potential_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9079 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9080 | err_remove_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9081 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 9082 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9083 | err_insert_irq: |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 9084 | err_pdata: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 9085 | kfree(ptr); |
| 9086 | err_nomem_slimch: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9087 | mutex_destroy(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9088 | kfree(tabla); |
| 9089 | return ret; |
| 9090 | } |
| 9091 | static int tabla_codec_remove(struct snd_soc_codec *codec) |
| 9092 | { |
| 9093 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9094 | |
| 9095 | wake_lock_destroy(&tabla->irq_resend_wlock); |
| 9096 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9097 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
| 9098 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
| 9099 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 9100 | tabla); |
| 9101 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
| 9102 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 9103 | tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9104 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9105 | tabla_codec_disable_clock_block(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9106 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9107 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 9108 | if (tabla->mbhc_fw) |
| 9109 | release_firmware(tabla->mbhc_fw); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9110 | mutex_destroy(&tabla->codec_resource_lock); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 9111 | #ifdef CONFIG_DEBUG_FS |
| 9112 | debugfs_remove(tabla->debugfs_poke); |
| 9113 | debugfs_remove(tabla->debugfs_mbhc); |
| 9114 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9115 | kfree(tabla); |
| 9116 | return 0; |
| 9117 | } |
| 9118 | static struct snd_soc_codec_driver soc_codec_dev_tabla = { |
| 9119 | .probe = tabla_codec_probe, |
| 9120 | .remove = tabla_codec_remove, |
| 9121 | .read = tabla_read, |
| 9122 | .write = tabla_write, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9123 | .readable_register = tabla_readable, |
| 9124 | .volatile_register = tabla_volatile, |
| 9125 | |
| 9126 | .reg_cache_size = TABLA_CACHE_SIZE, |
| 9127 | .reg_cache_default = tabla_reg_defaults, |
| 9128 | .reg_word_size = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9129 | .controls = tabla_snd_controls, |
| 9130 | .num_controls = ARRAY_SIZE(tabla_snd_controls), |
| 9131 | .dapm_widgets = tabla_dapm_widgets, |
| 9132 | .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets), |
| 9133 | .dapm_routes = audio_map, |
| 9134 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9135 | }; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9136 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9137 | #ifdef CONFIG_PM |
| 9138 | static int tabla_suspend(struct device *dev) |
| 9139 | { |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 9140 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 9141 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9142 | } |
| 9143 | |
| 9144 | static int tabla_resume(struct device *dev) |
| 9145 | { |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9146 | int irq; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 9147 | struct platform_device *pdev = to_platform_device(dev); |
| 9148 | struct tabla_priv *tabla = platform_get_drvdata(pdev); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9149 | |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 9150 | dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9151 | if (tabla) { |
| 9152 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 9153 | tabla->mbhc_last_resume = jiffies; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9154 | if (tabla->gpio_irq_resend) { |
| 9155 | WARN_ON(!tabla->mbhc_cfg.gpio_irq); |
| 9156 | tabla->gpio_irq_resend = false; |
| 9157 | |
| 9158 | irq = tabla->mbhc_cfg.gpio_irq; |
| 9159 | pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq); |
| 9160 | irq_set_pending(irq); |
| 9161 | check_irq_resend(irq_to_desc(irq), irq); |
| 9162 | |
| 9163 | /* release suspend lock */ |
| 9164 | wake_unlock(&tabla->irq_resend_wlock); |
| 9165 | } |
| 9166 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 9167 | } |
| 9168 | |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 9169 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9170 | } |
| 9171 | |
| 9172 | static const struct dev_pm_ops tabla_pm_ops = { |
| 9173 | .suspend = tabla_suspend, |
| 9174 | .resume = tabla_resume, |
| 9175 | }; |
| 9176 | #endif |
| 9177 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9178 | static int __devinit tabla_probe(struct platform_device *pdev) |
| 9179 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9180 | int ret = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9181 | pr_err("tabla_probe\n"); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9182 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9183 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 9184 | tabla_dai, ARRAY_SIZE(tabla_dai)); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9185 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9186 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 9187 | tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai)); |
| 9188 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9189 | } |
| 9190 | static int __devexit tabla_remove(struct platform_device *pdev) |
| 9191 | { |
| 9192 | snd_soc_unregister_codec(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9193 | return 0; |
| 9194 | } |
| 9195 | static struct platform_driver tabla_codec_driver = { |
| 9196 | .probe = tabla_probe, |
| 9197 | .remove = tabla_remove, |
| 9198 | .driver = { |
| 9199 | .name = "tabla_codec", |
| 9200 | .owner = THIS_MODULE, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9201 | #ifdef CONFIG_PM |
| 9202 | .pm = &tabla_pm_ops, |
| 9203 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9204 | }, |
| 9205 | }; |
| 9206 | |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9207 | static struct platform_driver tabla1x_codec_driver = { |
| 9208 | .probe = tabla_probe, |
| 9209 | .remove = tabla_remove, |
| 9210 | .driver = { |
| 9211 | .name = "tabla1x_codec", |
| 9212 | .owner = THIS_MODULE, |
| 9213 | #ifdef CONFIG_PM |
| 9214 | .pm = &tabla_pm_ops, |
| 9215 | #endif |
| 9216 | }, |
| 9217 | }; |
| 9218 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9219 | static int __init tabla_codec_init(void) |
| 9220 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9221 | int rtn = platform_driver_register(&tabla_codec_driver); |
| 9222 | if (rtn == 0) { |
| 9223 | rtn = platform_driver_register(&tabla1x_codec_driver); |
| 9224 | if (rtn != 0) |
| 9225 | platform_driver_unregister(&tabla_codec_driver); |
| 9226 | } |
| 9227 | return rtn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9228 | } |
| 9229 | |
| 9230 | static void __exit tabla_codec_exit(void) |
| 9231 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9232 | platform_driver_unregister(&tabla1x_codec_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9233 | platform_driver_unregister(&tabla_codec_driver); |
| 9234 | } |
| 9235 | |
| 9236 | module_init(tabla_codec_init); |
| 9237 | module_exit(tabla_codec_exit); |
| 9238 | |
| 9239 | MODULE_DESCRIPTION("Tabla codec driver"); |
| 9240 | MODULE_VERSION("1.0"); |
| 9241 | MODULE_LICENSE("GPL v2"); |