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 |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 58 | #define COMP_DIGITAL_DB_GAIN_APPLY(a, b) \ |
| 59 | (((a) <= 0) ? ((a) - b) : (a)) |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 60 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 61 | #define SLIM_CLOSE_TIMEOUT 1000 |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 62 | /* The wait time value comes from codec HW specification */ |
| 63 | #define COMP_BRINGUP_WAIT_TIME 2000 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 64 | enum { |
| 65 | MBHC_USE_HPHL_TRIGGER = 1, |
| 66 | MBHC_USE_MB_TRIGGER = 2 |
| 67 | }; |
| 68 | |
| 69 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 70 | #define NUM_ATTEMPTS_INSERT_DETECT 25 |
| 71 | #define NUM_ATTEMPTS_TO_REPORT 5 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 72 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 73 | #define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \ |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 74 | SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \ |
| 75 | SND_JACK_UNSUPPORTED) |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 76 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 77 | #define TABLA_I2S_MASTER_MODE_MASK 0x08 |
| 78 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 79 | #define TABLA_OCP_ATTEMPT 1 |
| 80 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 81 | enum { |
| 82 | AIF1_PB = 0, |
| 83 | AIF1_CAP, |
| 84 | AIF2_PB, |
| 85 | AIF2_CAP, |
| 86 | AIF3_PB, |
| 87 | AIF3_CAP, |
| 88 | NUM_CODEC_DAIS, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 91 | enum { |
| 92 | RX_MIX1_INP_SEL_ZERO = 0, |
| 93 | RX_MIX1_INP_SEL_SRC1, |
| 94 | RX_MIX1_INP_SEL_SRC2, |
| 95 | RX_MIX1_INP_SEL_IIR1, |
| 96 | RX_MIX1_INP_SEL_IIR2, |
| 97 | RX_MIX1_INP_SEL_RX1, |
| 98 | RX_MIX1_INP_SEL_RX2, |
| 99 | RX_MIX1_INP_SEL_RX3, |
| 100 | RX_MIX1_INP_SEL_RX4, |
| 101 | RX_MIX1_INP_SEL_RX5, |
| 102 | RX_MIX1_INP_SEL_RX6, |
| 103 | RX_MIX1_INP_SEL_RX7, |
| 104 | }; |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 105 | #define MAX_PA_GAIN_OPTIONS 13 |
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 | |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 224 | struct comp_dgtl_gain_offset { |
| 225 | u8 whole_db_gain; |
| 226 | u8 half_db_gain; |
| 227 | }; |
| 228 | |
| 229 | static const struct comp_dgtl_gain_offset |
| 230 | comp_dgtl_gain[MAX_PA_GAIN_OPTIONS] = { |
| 231 | {0, 0}, |
| 232 | {1, 1}, |
| 233 | {3, 0}, |
| 234 | {4, 1}, |
| 235 | {6, 0}, |
| 236 | {7, 1}, |
| 237 | {9, 0}, |
| 238 | {10, 1}, |
| 239 | {12, 0}, |
| 240 | {13, 1}, |
| 241 | {15, 0}, |
| 242 | {16, 1}, |
| 243 | {18, 0}, |
| 244 | }; |
| 245 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 246 | /* Data used by MBHC */ |
| 247 | struct mbhc_internal_cal_data { |
| 248 | u16 dce_z; |
| 249 | u16 dce_mb; |
| 250 | u16 sta_z; |
| 251 | u16 sta_mb; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 252 | u32 t_sta_dce; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 253 | u32 t_dce; |
| 254 | u32 t_sta; |
| 255 | u32 micb_mv; |
| 256 | u16 v_ins_hu; |
| 257 | u16 v_ins_h; |
| 258 | u16 v_b1_hu; |
| 259 | u16 v_b1_h; |
| 260 | u16 v_b1_huc; |
| 261 | u16 v_brh; |
| 262 | u16 v_brl; |
| 263 | u16 v_no_mic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 264 | u8 npoll; |
| 265 | u8 nbounce_wait; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 266 | s16 adj_v_hs_max; |
| 267 | u16 adj_v_ins_hu; |
| 268 | u16 adj_v_ins_h; |
| 269 | s16 v_inval_ins_low; |
| 270 | s16 v_inval_ins_high; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 271 | }; |
| 272 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 273 | struct tabla_reg_address { |
| 274 | u16 micb_4_ctl; |
| 275 | u16 micb_4_int_rbias; |
| 276 | u16 micb_4_mbhc; |
| 277 | }; |
| 278 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 279 | enum tabla_mbhc_plug_type { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 280 | PLUG_TYPE_INVALID = -1, |
| 281 | PLUG_TYPE_NONE, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 282 | PLUG_TYPE_HEADSET, |
| 283 | PLUG_TYPE_HEADPHONE, |
| 284 | PLUG_TYPE_HIGH_HPH, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 285 | PLUG_TYPE_GND_MIC_SWAP, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | enum tabla_mbhc_state { |
| 289 | MBHC_STATE_NONE = -1, |
| 290 | MBHC_STATE_POTENTIAL, |
| 291 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 292 | MBHC_STATE_RELEASE, |
| 293 | }; |
| 294 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 295 | struct hpf_work { |
| 296 | struct tabla_priv *tabla; |
| 297 | u32 decimator; |
| 298 | u8 tx_hpf_cut_of_freq; |
| 299 | struct delayed_work dwork; |
| 300 | }; |
| 301 | |
| 302 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 303 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 304 | static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = { |
| 305 | WCD9XXX_CH(10, 0), |
| 306 | WCD9XXX_CH(11, 1), |
| 307 | WCD9XXX_CH(12, 2), |
| 308 | WCD9XXX_CH(13, 3), |
| 309 | WCD9XXX_CH(14, 4), |
| 310 | WCD9XXX_CH(15, 5), |
| 311 | WCD9XXX_CH(16, 6) |
| 312 | }; |
| 313 | |
| 314 | static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = { |
| 315 | WCD9XXX_CH(0, 0), |
| 316 | WCD9XXX_CH(1, 1), |
| 317 | WCD9XXX_CH(2, 2), |
| 318 | WCD9XXX_CH(3, 3), |
| 319 | WCD9XXX_CH(4, 4), |
| 320 | WCD9XXX_CH(5, 5), |
| 321 | WCD9XXX_CH(6, 6), |
| 322 | WCD9XXX_CH(7, 7), |
| 323 | WCD9XXX_CH(8, 8), |
| 324 | WCD9XXX_CH(9, 9) |
| 325 | }; |
| 326 | |
| 327 | static const u32 vport_check_table[NUM_CODEC_DAIS] = { |
| 328 | 0, /* AIF1_PB */ |
| 329 | (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */ |
| 330 | 0, /* AIF2_PB */ |
| 331 | (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */ |
| 332 | 0, /* AIF2_PB */ |
| 333 | (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */ |
| 334 | }; |
| 335 | |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 336 | static const u32 vport_i2s_check_table[NUM_CODEC_DAIS] = { |
| 337 | 0, /* AIF1_PB */ |
| 338 | 0, /* AIF1_CAP */ |
| 339 | }; |
| 340 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 341 | struct tabla_priv { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 342 | struct snd_soc_codec *codec; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 343 | struct tabla_reg_address reg_addr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | u32 adc_count; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 345 | u32 cfilt1_cnt; |
| 346 | u32 cfilt2_cnt; |
| 347 | u32 cfilt3_cnt; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 348 | u32 rx_bias_count; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 349 | s32 dmic_1_2_clk_cnt; |
| 350 | s32 dmic_3_4_clk_cnt; |
| 351 | s32 dmic_5_6_clk_cnt; |
| 352 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 353 | enum tabla_bandgap_type bandgap_type; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 354 | bool mclk_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 355 | bool clock_active; |
| 356 | bool config_mode_active; |
| 357 | bool mbhc_polling_active; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 358 | unsigned long mbhc_fake_ins_start; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 359 | int buttons_pressed; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 360 | enum tabla_mbhc_state mbhc_state; |
| 361 | struct tabla_mbhc_config mbhc_cfg; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 362 | struct mbhc_internal_cal_data mbhc_data; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 363 | u32 ldo_h_count; |
| 364 | u32 micbias_enable_count[TABLA_NUM_MICBIAS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 365 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 366 | struct wcd9xxx_pdata *pdata; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 367 | u32 anc_slot; |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 368 | bool anc_func; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 369 | bool no_mic_headset_override; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 370 | /* Delayed work to report long button press */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 371 | struct delayed_work mbhc_btn_dwork; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 372 | |
| 373 | struct mbhc_micbias_regs mbhc_bias_regs; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 374 | bool mbhc_micbias_switched; |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 375 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 376 | /* track PA/DAC state */ |
| 377 | unsigned long hph_pa_dac_state; |
| 378 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 379 | /*track tabla interface type*/ |
| 380 | u8 intf_type; |
| 381 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 382 | u32 hph_status; /* track headhpone status */ |
| 383 | /* define separate work for left and right headphone OCP to avoid |
| 384 | * additional checking on which OCP event to report so no locking |
| 385 | * to ensure synchronization is required |
| 386 | */ |
| 387 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 388 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 389 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 390 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 391 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 392 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 393 | /* Work to perform MBHC Firmware Read */ |
| 394 | struct delayed_work mbhc_firmware_dwork; |
| 395 | const struct firmware *mbhc_fw; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 396 | |
| 397 | /* num of slim ports required */ |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 398 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 399 | |
| 400 | /*compander*/ |
| 401 | int comp_enabled[COMPANDER_MAX]; |
| 402 | u32 comp_fs[COMPANDER_MAX]; |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 403 | u8 comp_gain_offset[TABLA_SB_PGD_MAX_NUMBER_OF_RX_SLAVE_DEV_PORTS - 1]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 404 | |
| 405 | /* Maintain the status of AUX PGA */ |
| 406 | int aux_pga_cnt; |
| 407 | u8 aux_l_gain; |
| 408 | u8 aux_r_gain; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 409 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 410 | struct delayed_work mbhc_insert_dwork; |
| 411 | unsigned long mbhc_last_resume; /* in jiffies */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 412 | |
| 413 | u8 current_plug; |
| 414 | struct work_struct hs_correct_plug_work; |
| 415 | bool hs_detect_work_stop; |
| 416 | bool hs_polling_irq_prepared; |
| 417 | bool lpi_enabled; /* low power insertion detection */ |
| 418 | bool in_gpio_handler; |
| 419 | /* Currently, only used for mbhc purpose, to protect |
| 420 | * concurrent execution of mbhc threaded irq handlers and |
| 421 | * kill race between DAPM and MBHC.But can serve as a |
| 422 | * general lock to protect codec resource |
| 423 | */ |
| 424 | struct mutex codec_resource_lock; |
| 425 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 426 | /* Work to perform polling on microphone voltage |
| 427 | * in order to correct plug type once plug type |
| 428 | * is detected as headphone |
| 429 | */ |
| 430 | struct work_struct hs_correct_plug_work_nogpio; |
| 431 | |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 432 | bool gpio_irq_resend; |
| 433 | struct wake_lock irq_resend_wlock; |
| 434 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 435 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 436 | struct dentry *debugfs_poke; |
| 437 | struct dentry *debugfs_mbhc; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 438 | #endif |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 439 | }; |
| 440 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 441 | static const u32 comp_shift[] = { |
| 442 | 0, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 443 | 1, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | static const int comp_rx_path[] = { |
| 447 | COMPANDER_1, |
| 448 | COMPANDER_1, |
| 449 | COMPANDER_2, |
| 450 | COMPANDER_2, |
| 451 | COMPANDER_2, |
| 452 | COMPANDER_2, |
| 453 | COMPANDER_MAX, |
| 454 | }; |
| 455 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 456 | static const struct comp_sample_dependent_params |
| 457 | comp_samp_params[COMPANDER_FS_MAX] = { |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 458 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 459 | .peak_det_timeout = 0x6, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 460 | .rms_meter_div_fact = 0x9 << 4, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 461 | .rms_meter_resamp_fact = 0x06, |
| 462 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_240 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 463 | }, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 464 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 465 | .peak_det_timeout = 0x7, |
| 466 | .rms_meter_div_fact = 0xA << 4, |
| 467 | .rms_meter_resamp_fact = 0x0C, |
| 468 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_480 << 3, |
| 469 | }, |
| 470 | { |
| 471 | .peak_det_timeout = 0x8, |
| 472 | .rms_meter_div_fact = 0xB << 4, |
| 473 | .rms_meter_resamp_fact = 0x30, |
| 474 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_960 << 3, |
| 475 | }, |
| 476 | { |
| 477 | .peak_det_timeout = 0x9, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 478 | .rms_meter_div_fact = 0xB << 4, |
| 479 | .rms_meter_resamp_fact = 0x28, |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 480 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_1440 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 481 | }, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 482 | { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 483 | .peak_det_timeout = 0xA, |
| 484 | .rms_meter_div_fact = 0xC << 4, |
| 485 | .rms_meter_resamp_fact = 0x50, |
| 486 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_2880 << 3, |
| 487 | }, |
| 488 | { |
| 489 | .peak_det_timeout = 0xB, |
| 490 | .rms_meter_div_fact = 0xC << 4, |
| 491 | .rms_meter_resamp_fact = 0x50, |
| 492 | .shutdown_timeout = COMP_SHUTDWN_TIMEOUT_PCM_5760 << 3, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 493 | }, |
| 494 | }; |
| 495 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 496 | static unsigned short rx_digital_gain_reg[] = { |
| 497 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 498 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 499 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 500 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 501 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 502 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 503 | TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 504 | }; |
| 505 | |
| 506 | |
| 507 | static unsigned short tx_digital_gain_reg[] = { |
| 508 | TABLA_A_CDC_TX1_VOL_CTL_GAIN, |
| 509 | TABLA_A_CDC_TX2_VOL_CTL_GAIN, |
| 510 | TABLA_A_CDC_TX3_VOL_CTL_GAIN, |
| 511 | TABLA_A_CDC_TX4_VOL_CTL_GAIN, |
| 512 | TABLA_A_CDC_TX5_VOL_CTL_GAIN, |
| 513 | TABLA_A_CDC_TX6_VOL_CTL_GAIN, |
| 514 | TABLA_A_CDC_TX7_VOL_CTL_GAIN, |
| 515 | TABLA_A_CDC_TX8_VOL_CTL_GAIN, |
| 516 | TABLA_A_CDC_TX9_VOL_CTL_GAIN, |
| 517 | TABLA_A_CDC_TX10_VOL_CTL_GAIN, |
| 518 | }; |
| 519 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 520 | static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 521 | struct snd_kcontrol *kcontrol, int event) |
| 522 | { |
| 523 | struct snd_soc_codec *codec = w->codec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | |
| 525 | pr_debug("%s %d\n", __func__, event); |
| 526 | switch (event) { |
| 527 | case SND_SOC_DAPM_POST_PMU: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 528 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 529 | 0x01); |
| 530 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 531 | usleep_range(200, 200); |
| 532 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00); |
| 533 | break; |
| 534 | case SND_SOC_DAPM_PRE_PMD: |
| 535 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 536 | 0x10); |
| 537 | usleep_range(20, 20); |
| 538 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08); |
| 539 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10); |
| 540 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 541 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 542 | 0x00); |
Fred Oh | 54d24d7 | 2012-11-29 15:57:36 -0800 | [diff] [blame] | 543 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 544 | 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 545 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 546 | break; |
| 547 | } |
| 548 | return 0; |
| 549 | } |
| 550 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 551 | static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 552 | struct snd_ctl_elem_value *ucontrol) |
| 553 | { |
| 554 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 555 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 556 | ucontrol->value.integer.value[0] = tabla->anc_slot; |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 561 | struct snd_ctl_elem_value *ucontrol) |
| 562 | { |
| 563 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 564 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 565 | tabla->anc_slot = ucontrol->value.integer.value[0]; |
| 566 | return 0; |
| 567 | } |
| 568 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 569 | static int tabla_get_anc_func(struct snd_kcontrol *kcontrol, |
| 570 | struct snd_ctl_elem_value *ucontrol) |
| 571 | { |
| 572 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 573 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 574 | |
| 575 | mutex_lock(&codec->dapm.codec->mutex); |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 576 | ucontrol->value.integer.value[0] = (tabla->anc_func == true ? 1 : 0); |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 577 | mutex_unlock(&codec->dapm.codec->mutex); |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | static int tabla_put_anc_func(struct snd_kcontrol *kcontrol, |
| 582 | struct snd_ctl_elem_value *ucontrol) |
| 583 | { |
| 584 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 585 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 586 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 587 | |
| 588 | mutex_lock(&dapm->codec->mutex); |
| 589 | |
| 590 | tabla->anc_func = (!ucontrol->value.integer.value[0] ? false : true); |
| 591 | |
| 592 | dev_dbg(codec->dev, "%s: anc_func %x", __func__, tabla->anc_func); |
| 593 | |
| 594 | if (tabla->anc_func == true) { |
| 595 | snd_soc_dapm_enable_pin(dapm, "ANC HPHR"); |
| 596 | snd_soc_dapm_enable_pin(dapm, "ANC HPHL"); |
| 597 | snd_soc_dapm_enable_pin(dapm, "ANC HEADPHONE"); |
| 598 | snd_soc_dapm_disable_pin(dapm, "HPHR"); |
| 599 | snd_soc_dapm_disable_pin(dapm, "HPHL"); |
| 600 | snd_soc_dapm_disable_pin(dapm, "HEADPHONE"); |
| 601 | } else { |
| 602 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 603 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 604 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 605 | snd_soc_dapm_enable_pin(dapm, "HPHR"); |
| 606 | snd_soc_dapm_enable_pin(dapm, "HPHL"); |
| 607 | snd_soc_dapm_enable_pin(dapm, "HEADPHONE"); |
| 608 | } |
| 609 | snd_soc_dapm_sync(dapm); |
| 610 | mutex_unlock(&dapm->codec->mutex); |
| 611 | return 0; |
| 612 | } |
| 613 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 614 | static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 615 | struct snd_ctl_elem_value *ucontrol) |
| 616 | { |
| 617 | u8 ear_pa_gain; |
| 618 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 619 | |
| 620 | ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN); |
| 621 | |
| 622 | ear_pa_gain = ear_pa_gain >> 5; |
| 623 | |
| 624 | if (ear_pa_gain == 0x00) { |
| 625 | ucontrol->value.integer.value[0] = 0; |
| 626 | } else if (ear_pa_gain == 0x04) { |
| 627 | ucontrol->value.integer.value[0] = 1; |
| 628 | } else { |
| 629 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 630 | __func__, ear_pa_gain); |
| 631 | return -EINVAL; |
| 632 | } |
| 633 | |
| 634 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
| 639 | static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 640 | struct snd_ctl_elem_value *ucontrol) |
| 641 | { |
| 642 | u8 ear_pa_gain; |
| 643 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 644 | |
| 645 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 646 | ucontrol->value.integer.value[0]); |
| 647 | |
| 648 | switch (ucontrol->value.integer.value[0]) { |
| 649 | case 0: |
| 650 | ear_pa_gain = 0x00; |
| 651 | break; |
| 652 | case 1: |
| 653 | ear_pa_gain = 0x80; |
| 654 | break; |
| 655 | default: |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
| 659 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 660 | return 0; |
| 661 | } |
| 662 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 663 | static int tabla_get_iir_enable_audio_mixer( |
| 664 | struct snd_kcontrol *kcontrol, |
| 665 | struct snd_ctl_elem_value *ucontrol) |
| 666 | { |
| 667 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 668 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 669 | kcontrol->private_value)->reg; |
| 670 | int band_idx = ((struct soc_multi_mixer_control *) |
| 671 | kcontrol->private_value)->shift; |
| 672 | |
| 673 | ucontrol->value.integer.value[0] = |
| 674 | snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 675 | (1 << band_idx); |
| 676 | |
| 677 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 678 | iir_idx, band_idx, |
| 679 | (uint32_t)ucontrol->value.integer.value[0]); |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int tabla_put_iir_enable_audio_mixer( |
| 684 | struct snd_kcontrol *kcontrol, |
| 685 | struct snd_ctl_elem_value *ucontrol) |
| 686 | { |
| 687 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 688 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 689 | kcontrol->private_value)->reg; |
| 690 | int band_idx = ((struct soc_multi_mixer_control *) |
| 691 | kcontrol->private_value)->shift; |
| 692 | int value = ucontrol->value.integer.value[0]; |
| 693 | |
| 694 | /* Mask first 5 bits, 6-8 are reserved */ |
| 695 | snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 696 | (1 << band_idx), (value << band_idx)); |
| 697 | |
| 698 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 699 | iir_idx, band_idx, value); |
| 700 | return 0; |
| 701 | } |
| 702 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 703 | int iir_idx, int band_idx, |
| 704 | int coeff_idx) |
| 705 | { |
| 706 | /* Address does not automatically update if reading */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 707 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 708 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 709 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 710 | |
| 711 | /* Mask bits top 2 bits since they are reserved */ |
| 712 | return ((snd_soc_read(codec, |
| 713 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 714 | (snd_soc_read(codec, |
| 715 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 716 | (snd_soc_read(codec, |
| 717 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 718 | (snd_soc_read(codec, |
| 719 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 720 | 0x3FFFFFFF; |
| 721 | } |
| 722 | |
| 723 | static int tabla_get_iir_band_audio_mixer( |
| 724 | struct snd_kcontrol *kcontrol, |
| 725 | struct snd_ctl_elem_value *ucontrol) |
| 726 | { |
| 727 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 728 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 729 | kcontrol->private_value)->reg; |
| 730 | int band_idx = ((struct soc_multi_mixer_control *) |
| 731 | kcontrol->private_value)->shift; |
| 732 | |
| 733 | ucontrol->value.integer.value[0] = |
| 734 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 735 | ucontrol->value.integer.value[1] = |
| 736 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 737 | ucontrol->value.integer.value[2] = |
| 738 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 739 | ucontrol->value.integer.value[3] = |
| 740 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 741 | ucontrol->value.integer.value[4] = |
| 742 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 743 | |
| 744 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 745 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 746 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 747 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 748 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 749 | __func__, iir_idx, band_idx, |
| 750 | (uint32_t)ucontrol->value.integer.value[0], |
| 751 | __func__, iir_idx, band_idx, |
| 752 | (uint32_t)ucontrol->value.integer.value[1], |
| 753 | __func__, iir_idx, band_idx, |
| 754 | (uint32_t)ucontrol->value.integer.value[2], |
| 755 | __func__, iir_idx, band_idx, |
| 756 | (uint32_t)ucontrol->value.integer.value[3], |
| 757 | __func__, iir_idx, band_idx, |
| 758 | (uint32_t)ucontrol->value.integer.value[4]); |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 763 | int iir_idx, int band_idx, |
| 764 | int coeff_idx, uint32_t value) |
| 765 | { |
| 766 | /* Mask top 3 bits, 6-8 are reserved */ |
| 767 | /* Update address manually each time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 768 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 769 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 770 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 771 | |
| 772 | /* Mask top 2 bits, 7-8 are reserved */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 773 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 774 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 775 | (value >> 24) & 0x3F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 776 | |
| 777 | /* Isolate 8bits at a time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 778 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 779 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 780 | (value >> 16) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 781 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 782 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 783 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 784 | (value >> 8) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 785 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 786 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 787 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 788 | value & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static int tabla_put_iir_band_audio_mixer( |
| 792 | struct snd_kcontrol *kcontrol, |
| 793 | struct snd_ctl_elem_value *ucontrol) |
| 794 | { |
| 795 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 796 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 797 | kcontrol->private_value)->reg; |
| 798 | int band_idx = ((struct soc_multi_mixer_control *) |
| 799 | kcontrol->private_value)->shift; |
| 800 | |
| 801 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 802 | ucontrol->value.integer.value[0]); |
| 803 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 804 | ucontrol->value.integer.value[1]); |
| 805 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 806 | ucontrol->value.integer.value[2]); |
| 807 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 808 | ucontrol->value.integer.value[3]); |
| 809 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 810 | ucontrol->value.integer.value[4]); |
| 811 | |
| 812 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 813 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 814 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 815 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 816 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 817 | __func__, iir_idx, band_idx, |
| 818 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 819 | __func__, iir_idx, band_idx, |
| 820 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 821 | __func__, iir_idx, band_idx, |
| 822 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 823 | __func__, iir_idx, band_idx, |
| 824 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 825 | __func__, iir_idx, band_idx, |
| 826 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 827 | return 0; |
| 828 | } |
| 829 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 830 | static int tabla_compander_gain_offset( |
| 831 | struct snd_soc_codec *codec, u32 enable, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 832 | unsigned int pa_reg, unsigned int vol_reg, |
| 833 | int mask, int event, |
| 834 | struct comp_dgtl_gain_offset *gain_offset, |
| 835 | int index) |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 836 | { |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 837 | unsigned int pa_gain = snd_soc_read(codec, pa_reg); |
| 838 | unsigned int digital_vol = snd_soc_read(codec, vol_reg); |
| 839 | int pa_mode = pa_gain & mask; |
| 840 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 841 | |
| 842 | pr_debug("%s: pa_gain(0x%x=0x%x)digital_vol(0x%x=0x%x)event(0x%x) index(%d)\n", |
| 843 | __func__, pa_reg, pa_gain, vol_reg, digital_vol, event, index); |
| 844 | if (((pa_gain & 0xF) + 1) > ARRAY_SIZE(comp_dgtl_gain) || |
| 845 | (index >= ARRAY_SIZE(tabla->comp_gain_offset))) { |
| 846 | pr_err("%s: Out of array boundary\n", __func__); |
| 847 | return -EINVAL; |
| 848 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 849 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 850 | if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) { |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 851 | gain_offset->whole_db_gain = COMP_DIGITAL_DB_GAIN_APPLY( |
| 852 | (digital_vol - comp_dgtl_gain[pa_gain & 0xF].whole_db_gain), |
| 853 | comp_dgtl_gain[pa_gain & 0xF].half_db_gain); |
| 854 | pr_debug("%s: listed whole_db_gain:0x%x, adjusted whole_db_gain:0x%x\n", |
| 855 | __func__, comp_dgtl_gain[pa_gain & 0xF].whole_db_gain, |
| 856 | gain_offset->whole_db_gain); |
| 857 | gain_offset->half_db_gain = |
| 858 | comp_dgtl_gain[pa_gain & 0xF].half_db_gain; |
| 859 | tabla->comp_gain_offset[index] = digital_vol - |
| 860 | gain_offset->whole_db_gain ; |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 861 | } |
| 862 | if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) { |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 863 | gain_offset->whole_db_gain = digital_vol + |
| 864 | tabla->comp_gain_offset[index]; |
| 865 | pr_debug("%s: listed whole_db_gain:0x%x, adjusted whole_db_gain:0x%x\n", |
| 866 | __func__, comp_dgtl_gain[pa_gain & 0xF].whole_db_gain, |
| 867 | gain_offset->whole_db_gain); |
| 868 | gain_offset->half_db_gain = 0; |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 869 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 870 | |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 871 | pr_debug("%s: half_db_gain(%d)whole_db_gain(%d)comp_gain_offset[%d](%d)\n", |
| 872 | __func__, gain_offset->half_db_gain, |
| 873 | gain_offset->whole_db_gain, index, |
| 874 | tabla->comp_gain_offset[index]); |
| 875 | return 0; |
| 876 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 877 | |
| 878 | static int tabla_config_gain_compander( |
| 879 | struct snd_soc_codec *codec, |
| 880 | u32 compander, u32 enable, int event) |
| 881 | { |
| 882 | int value = 0; |
| 883 | int mask = 1 << 4; |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 884 | struct comp_dgtl_gain_offset gain_offset = {0, 0}; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 885 | if (compander >= COMPANDER_MAX) { |
| 886 | pr_err("%s: Error, invalid compander channel\n", __func__); |
| 887 | return -EINVAL; |
| 888 | } |
| 889 | |
| 890 | if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event)) |
| 891 | value = 1 << 4; |
| 892 | |
| 893 | if (compander == COMPANDER_1) { |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 894 | tabla_compander_gain_offset(codec, enable, |
| 895 | TABLA_A_RX_HPH_L_GAIN, |
| 896 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 897 | mask, event, &gain_offset, 0); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 898 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 899 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 900 | 0xFF, gain_offset.whole_db_gain); |
| 901 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 902 | 0x02, gain_offset.half_db_gain); |
| 903 | tabla_compander_gain_offset(codec, enable, |
| 904 | TABLA_A_RX_HPH_R_GAIN, |
| 905 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 906 | mask, event, &gain_offset, 1); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 907 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 908 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 909 | 0xFF, gain_offset.whole_db_gain); |
| 910 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 911 | 0x02, gain_offset.half_db_gain); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 912 | } else if (compander == COMPANDER_2) { |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 913 | tabla_compander_gain_offset(codec, enable, |
| 914 | TABLA_A_RX_LINE_1_GAIN, |
| 915 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 916 | mask, event, &gain_offset, 2); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 917 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 918 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 919 | 0xFF, gain_offset.whole_db_gain); |
| 920 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_B6_CTL, |
| 921 | 0x02, gain_offset.half_db_gain); |
| 922 | tabla_compander_gain_offset(codec, enable, |
| 923 | TABLA_A_RX_LINE_3_GAIN, |
| 924 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 925 | mask, event, &gain_offset, 3); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 926 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 927 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 928 | 0xFF, gain_offset.whole_db_gain); |
| 929 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_B6_CTL, |
| 930 | 0x02, gain_offset.half_db_gain); |
| 931 | tabla_compander_gain_offset(codec, enable, |
| 932 | TABLA_A_RX_LINE_2_GAIN, |
| 933 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 934 | mask, event, &gain_offset, 4); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 935 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 936 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 937 | 0xFF, gain_offset.whole_db_gain); |
| 938 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_B6_CTL, |
| 939 | 0x02, gain_offset.half_db_gain); |
| 940 | tabla_compander_gain_offset(codec, enable, |
| 941 | TABLA_A_RX_LINE_4_GAIN, |
| 942 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 943 | mask, event, &gain_offset, 5); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 944 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 945 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
Kuirong Wang | 57b4d89 | 2013-02-11 09:54:45 -0800 | [diff] [blame^] | 946 | 0xFF, gain_offset.whole_db_gain); |
| 947 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_B6_CTL, |
| 948 | 0x02, gain_offset.half_db_gain); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 949 | } |
| 950 | return 0; |
| 951 | } |
| 952 | static int tabla_get_compander(struct snd_kcontrol *kcontrol, |
| 953 | struct snd_ctl_elem_value *ucontrol) |
| 954 | { |
| 955 | |
| 956 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 957 | int comp = ((struct soc_multi_mixer_control *) |
| 958 | kcontrol->private_value)->max; |
| 959 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 960 | |
| 961 | ucontrol->value.integer.value[0] = tabla->comp_enabled[comp]; |
| 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | static int tabla_set_compander(struct snd_kcontrol *kcontrol, |
| 967 | struct snd_ctl_elem_value *ucontrol) |
| 968 | { |
| 969 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 970 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 971 | int comp = ((struct soc_multi_mixer_control *) |
| 972 | kcontrol->private_value)->max; |
| 973 | int value = ucontrol->value.integer.value[0]; |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 974 | pr_debug("%s: compander #%d enable %d\n", |
| 975 | __func__, comp + 1, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 976 | if (value == tabla->comp_enabled[comp]) { |
| 977 | pr_debug("%s: compander #%d enable %d no change\n", |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 978 | __func__, comp + 1, value); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 979 | return 0; |
| 980 | } |
| 981 | tabla->comp_enabled[comp] = value; |
| 982 | return 0; |
| 983 | } |
| 984 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 985 | static int tabla_config_compander(struct snd_soc_dapm_widget *w, |
| 986 | struct snd_kcontrol *kcontrol, |
| 987 | int event) |
| 988 | { |
| 989 | struct snd_soc_codec *codec = w->codec; |
| 990 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 991 | u32 rate = tabla->comp_fs[w->shift]; |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 992 | |
| 993 | 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] | 994 | __func__, w->shift + 1, |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 995 | tabla->comp_enabled[w->shift], event , w->name); |
| 996 | if (tabla->comp_enabled[w->shift] == 0) |
| 997 | goto rtn; |
| 998 | if ((w->shift == COMPANDER_1) && (tabla->anc_func)) { |
| 999 | pr_debug("%s: ANC is enabled so compander #%d cannot be enabled\n", |
| 1000 | __func__, w->shift + 1); |
| 1001 | goto rtn; |
| 1002 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1003 | switch (event) { |
| 1004 | case SND_SOC_DAPM_PRE_PMU: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1005 | /* Update compander sample rate */ |
| 1006 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG + |
| 1007 | w->shift * 8, 0x07, rate); |
| 1008 | /* Enable both L/R compander clocks */ |
| 1009 | snd_soc_update_bits(codec, |
| 1010 | TABLA_A_CDC_CLK_RX_B2_CTL, |
| 1011 | 1 << comp_shift[w->shift], |
| 1012 | 1 << comp_shift[w->shift]); |
| 1013 | /* Toggle compander reset bits */ |
| 1014 | snd_soc_update_bits(codec, |
| 1015 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1016 | 1 << comp_shift[w->shift], |
| 1017 | 1 << comp_shift[w->shift]); |
| 1018 | snd_soc_update_bits(codec, |
| 1019 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1020 | 1 << comp_shift[w->shift], 0); |
| 1021 | tabla_config_gain_compander(codec, w->shift, 1, event); |
| 1022 | /* Compander enable -> 0x370/0x378 */ |
| 1023 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 1024 | w->shift * 8, 0x03, 0x03); |
| 1025 | /* Update the RMS meter resampling */ |
| 1026 | snd_soc_update_bits(codec, |
| 1027 | TABLA_A_CDC_COMP1_B3_CTL + |
| 1028 | w->shift * 8, 0xFF, 0x01); |
| 1029 | snd_soc_update_bits(codec, |
| 1030 | TABLA_A_CDC_COMP1_B2_CTL + |
| 1031 | w->shift * 8, 0xF0, 0x50); |
| 1032 | usleep_range(COMP_BRINGUP_WAIT_TIME, COMP_BRINGUP_WAIT_TIME); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1033 | break; |
| 1034 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1035 | /* Set sample rate dependent paramater */ |
| 1036 | if (w->shift == COMPANDER_1) { |
| 1037 | snd_soc_update_bits(codec, |
| 1038 | TABLA_A_CDC_CLSG_CTL, |
| 1039 | 0x11, 0x00); |
| 1040 | snd_soc_write(codec, |
| 1041 | TABLA_A_CDC_CONN_CLSG_CTL, 0x11); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1042 | } |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1043 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 1044 | w->shift * 8, 0x0F, |
| 1045 | comp_samp_params[rate].peak_det_timeout); |
| 1046 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 1047 | w->shift * 8, 0xF0, |
| 1048 | comp_samp_params[rate].rms_meter_div_fact); |
| 1049 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL + |
| 1050 | w->shift * 8, 0xFF, |
| 1051 | comp_samp_params[rate].rms_meter_resamp_fact); |
| 1052 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 1053 | w->shift * 8, 0x38, |
| 1054 | comp_samp_params[rate].shutdown_timeout); |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1055 | break; |
| 1056 | case SND_SOC_DAPM_PRE_PMD: |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1057 | break; |
| 1058 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1059 | /* Disable the compander */ |
| 1060 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 1061 | w->shift * 8, 0x03, 0x00); |
| 1062 | /* Toggle compander reset bits */ |
| 1063 | snd_soc_update_bits(codec, |
| 1064 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1065 | 1 << comp_shift[w->shift], |
| 1066 | 1 << comp_shift[w->shift]); |
| 1067 | snd_soc_update_bits(codec, |
| 1068 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 1069 | 1 << comp_shift[w->shift], 0); |
| 1070 | /* Turn off the clock for compander in pair */ |
| 1071 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL, |
| 1072 | 0x03 << comp_shift[w->shift], 0); |
| 1073 | /* Restore the gain */ |
| 1074 | tabla_config_gain_compander(codec, w->shift, |
| 1075 | tabla->comp_enabled[w->shift], |
| 1076 | event); |
| 1077 | if (w->shift == COMPANDER_1) { |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 1078 | snd_soc_update_bits(codec, |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1079 | TABLA_A_CDC_CLSG_CTL, |
| 1080 | 0x11, 0x11); |
| 1081 | snd_soc_write(codec, |
| 1082 | TABLA_A_CDC_CONN_CLSG_CTL, 0x14); |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 1083 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1084 | break; |
| 1085 | } |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 1086 | rtn: |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int tabla_codec_hphr_dem_input_selection(struct snd_soc_dapm_widget *w, |
| 1091 | struct snd_kcontrol *kcontrol, |
| 1092 | int event) |
| 1093 | { |
| 1094 | struct snd_soc_codec *codec = w->codec; |
| 1095 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1096 | |
| 1097 | pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n", |
| 1098 | __func__, tabla->comp_enabled[COMPANDER_1], |
| 1099 | TABLA_A_CDC_RX1_B6_CTL, |
| 1100 | snd_soc_read(codec, TABLA_A_CDC_RX1_B6_CTL), event); |
| 1101 | switch (event) { |
| 1102 | case SND_SOC_DAPM_POST_PMU: |
| 1103 | if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func) |
| 1104 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1105 | 1 << w->shift, 0); |
| 1106 | else |
| 1107 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1108 | 1 << w->shift, 1 << w->shift); |
| 1109 | break; |
| 1110 | case SND_SOC_DAPM_POST_PMD: |
| 1111 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_B6_CTL, |
| 1112 | 1 << w->shift, 0); |
| 1113 | break; |
| 1114 | default: |
| 1115 | return -EINVAL; |
| 1116 | } |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | static int tabla_codec_hphl_dem_input_selection(struct snd_soc_dapm_widget *w, |
| 1121 | struct snd_kcontrol *kcontrol, |
| 1122 | int event) |
| 1123 | { |
| 1124 | struct snd_soc_codec *codec = w->codec; |
| 1125 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1126 | |
| 1127 | pr_debug("%s: compander#1->enable(%d) reg(0x%x = 0x%x) event(%d)\n", |
| 1128 | __func__, tabla->comp_enabled[COMPANDER_1], |
| 1129 | TABLA_A_CDC_RX2_B6_CTL, |
| 1130 | snd_soc_read(codec, TABLA_A_CDC_RX2_B6_CTL), event); |
| 1131 | switch (event) { |
| 1132 | case SND_SOC_DAPM_POST_PMU: |
| 1133 | if (tabla->comp_enabled[COMPANDER_1] && !tabla->anc_func) |
| 1134 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1135 | 1 << w->shift, 0); |
| 1136 | else |
| 1137 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1138 | 1 << w->shift, 1 << w->shift); |
| 1139 | break; |
| 1140 | case SND_SOC_DAPM_POST_PMD: |
| 1141 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_B6_CTL, |
| 1142 | 1 << w->shift, 0); |
| 1143 | break; |
| 1144 | default: |
| 1145 | return -EINVAL; |
| 1146 | } |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1147 | return 0; |
| 1148 | } |
| 1149 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 1150 | static const char *const tabla_anc_func_text[] = {"OFF", "ON"}; |
| 1151 | static const struct soc_enum tabla_anc_func_enum = |
| 1152 | SOC_ENUM_SINGLE_EXT(2, tabla_anc_func_text); |
| 1153 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 1154 | static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 1155 | static const struct soc_enum tabla_ear_pa_gain_enum[] = { |
| 1156 | SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text), |
| 1157 | }; |
| 1158 | |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 1159 | /*cut of frequency for high pass filter*/ |
| 1160 | static const char *cf_text[] = { |
| 1161 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 1162 | }; |
| 1163 | |
| 1164 | static const struct soc_enum cf_dec1_enum = |
| 1165 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 1166 | |
| 1167 | static const struct soc_enum cf_dec2_enum = |
| 1168 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 1169 | |
| 1170 | static const struct soc_enum cf_dec3_enum = |
| 1171 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 1172 | |
| 1173 | static const struct soc_enum cf_dec4_enum = |
| 1174 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 1175 | |
| 1176 | static const struct soc_enum cf_dec5_enum = |
| 1177 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text); |
| 1178 | |
| 1179 | static const struct soc_enum cf_dec6_enum = |
| 1180 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text); |
| 1181 | |
| 1182 | static const struct soc_enum cf_dec7_enum = |
| 1183 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text); |
| 1184 | |
| 1185 | static const struct soc_enum cf_dec8_enum = |
| 1186 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text); |
| 1187 | |
| 1188 | static const struct soc_enum cf_dec9_enum = |
| 1189 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text); |
| 1190 | |
| 1191 | static const struct soc_enum cf_dec10_enum = |
| 1192 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text); |
| 1193 | |
| 1194 | static const struct soc_enum cf_rxmix1_enum = |
| 1195 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 1196 | |
| 1197 | static const struct soc_enum cf_rxmix2_enum = |
| 1198 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text); |
| 1199 | |
| 1200 | static const struct soc_enum cf_rxmix3_enum = |
| 1201 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text); |
| 1202 | |
| 1203 | static const struct soc_enum cf_rxmix4_enum = |
| 1204 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text); |
| 1205 | |
| 1206 | static const struct soc_enum cf_rxmix5_enum = |
| 1207 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text) |
| 1208 | ; |
| 1209 | static const struct soc_enum cf_rxmix6_enum = |
| 1210 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text); |
| 1211 | |
| 1212 | static const struct soc_enum cf_rxmix7_enum = |
| 1213 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text); |
| 1214 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1215 | static const struct snd_kcontrol_new tabla_snd_controls[] = { |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 1216 | |
| 1217 | SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0], |
| 1218 | tabla_pa_gain_get, tabla_pa_gain_put), |
| 1219 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1220 | SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 1221 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1222 | SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 1223 | line_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1224 | SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1, |
| 1225 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1226 | SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1, |
| 1227 | line_gain), |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1228 | SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1, |
| 1229 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1230 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1231 | SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 1232 | line_gain), |
| 1233 | SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 1234 | line_gain), |
| 1235 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1236 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 1237 | -84, 40, digital_gain), |
| 1238 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 1239 | -84, 40, digital_gain), |
| 1240 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 1241 | -84, 40, digital_gain), |
| 1242 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 1243 | -84, 40, digital_gain), |
| 1244 | SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 1245 | -84, 40, digital_gain), |
| 1246 | SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 1247 | -84, 40, digital_gain), |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 1248 | SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 1249 | -84, 40, digital_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1250 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1251 | 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] | 1252 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1253 | 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] | 1254 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1255 | SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 1256 | digital_gain), |
| 1257 | SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 1258 | digital_gain), |
| 1259 | SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40, |
| 1260 | digital_gain), |
| 1261 | SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40, |
| 1262 | digital_gain), |
| 1263 | SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40, |
| 1264 | digital_gain), |
| 1265 | SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40, |
| 1266 | digital_gain), |
| 1267 | SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40, |
| 1268 | digital_gain), |
| 1269 | SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84, |
| 1270 | 40, digital_gain), |
Patrick Lai | 2900637 | 2011-09-28 17:57:42 -0700 | [diff] [blame] | 1271 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 1272 | 40, digital_gain), |
| 1273 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 1274 | 40, digital_gain), |
| 1275 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 1276 | 40, digital_gain), |
| 1277 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 1278 | 40, digital_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1279 | SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 1280 | 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] | 1281 | SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain), |
| 1282 | 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] | 1283 | SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain), |
| 1284 | 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] | 1285 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1286 | SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0, |
| 1287 | aux_pga_gain), |
| 1288 | SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0, |
| 1289 | aux_pga_gain), |
| 1290 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1291 | 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] | 1292 | 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] | 1293 | 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] | 1294 | |
| 1295 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot, |
| 1296 | tabla_put_anc_slot), |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 1297 | SOC_ENUM_EXT("ANC Function", tabla_anc_func_enum, tabla_get_anc_func, |
| 1298 | tabla_put_anc_func), |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 1299 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 1300 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 1301 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 1302 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 1303 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 1304 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 1305 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 1306 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 1307 | SOC_ENUM("TX9 HPF cut off", cf_dec9_enum), |
| 1308 | SOC_ENUM("TX10 HPF cut off", cf_dec10_enum), |
| 1309 | |
| 1310 | SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 1311 | SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 1312 | SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 1313 | SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 1314 | SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0), |
| 1315 | SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0), |
| 1316 | SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0), |
| 1317 | SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0), |
| 1318 | SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0), |
| 1319 | SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0), |
| 1320 | |
| 1321 | SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 1322 | SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 1323 | SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 1324 | SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1325 | SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0), |
| 1326 | SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0), |
| 1327 | SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0), |
| 1328 | |
| 1329 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1330 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1331 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 1332 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 1333 | SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum), |
| 1334 | SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum), |
| 1335 | SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum), |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 1336 | |
| 1337 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1338 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1339 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1340 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1341 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1342 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1343 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1344 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1345 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1346 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1347 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1348 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1349 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1350 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1351 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1352 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1353 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1354 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1355 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1356 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1357 | |
| 1358 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1359 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1360 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1361 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1362 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1363 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1364 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1365 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1366 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1367 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1368 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1369 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1370 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1371 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1372 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1373 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1374 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1375 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1376 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1377 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1378 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0, |
| 1379 | tabla_get_compander, tabla_set_compander), |
| 1380 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0, |
| 1381 | tabla_get_compander, tabla_set_compander), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1382 | }; |
| 1383 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 1384 | static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = { |
| 1385 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1), |
| 1386 | }; |
| 1387 | |
| 1388 | static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = { |
| 1389 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1), |
| 1390 | }; |
| 1391 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1392 | static const char *rx_mix1_text[] = { |
| 1393 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1394 | "RX5", "RX6", "RX7" |
| 1395 | }; |
| 1396 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1397 | static const char *rx_mix2_text[] = { |
| 1398 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1399 | }; |
| 1400 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1401 | static const char *rx_dsm_text[] = { |
| 1402 | "CIC_OUT", "DSM_INV" |
| 1403 | }; |
| 1404 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1405 | static const char *sb_tx1_mux_text[] = { |
| 1406 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1407 | "DEC1" |
| 1408 | }; |
| 1409 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1410 | static const char *sb_tx2_mux_text[] = { |
| 1411 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1412 | "DEC2" |
| 1413 | }; |
| 1414 | |
| 1415 | static const char *sb_tx3_mux_text[] = { |
| 1416 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1417 | "DEC3" |
| 1418 | }; |
| 1419 | |
| 1420 | static const char *sb_tx4_mux_text[] = { |
| 1421 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1422 | "DEC4" |
| 1423 | }; |
| 1424 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1425 | static const char *sb_tx5_mux_text[] = { |
| 1426 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1427 | "DEC5" |
| 1428 | }; |
| 1429 | |
| 1430 | static const char *sb_tx6_mux_text[] = { |
| 1431 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1432 | "DEC6" |
| 1433 | }; |
| 1434 | |
| 1435 | static const char const *sb_tx7_to_tx10_mux_text[] = { |
| 1436 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1437 | "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1438 | "DEC9", "DEC10" |
| 1439 | }; |
| 1440 | |
| 1441 | static const char *dec1_mux_text[] = { |
| 1442 | "ZERO", "DMIC1", "ADC6", |
| 1443 | }; |
| 1444 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1445 | static const char *dec2_mux_text[] = { |
| 1446 | "ZERO", "DMIC2", "ADC5", |
| 1447 | }; |
| 1448 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1449 | static const char *dec3_mux_text[] = { |
| 1450 | "ZERO", "DMIC3", "ADC4", |
| 1451 | }; |
| 1452 | |
| 1453 | static const char *dec4_mux_text[] = { |
| 1454 | "ZERO", "DMIC4", "ADC3", |
| 1455 | }; |
| 1456 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1457 | static const char *dec5_mux_text[] = { |
| 1458 | "ZERO", "DMIC5", "ADC2", |
| 1459 | }; |
| 1460 | |
| 1461 | static const char *dec6_mux_text[] = { |
| 1462 | "ZERO", "DMIC6", "ADC1", |
| 1463 | }; |
| 1464 | |
| 1465 | static const char const *dec7_mux_text[] = { |
| 1466 | "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB", |
| 1467 | }; |
| 1468 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1469 | static const char *dec8_mux_text[] = { |
| 1470 | "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5", |
| 1471 | }; |
| 1472 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1473 | static const char *dec9_mux_text[] = { |
| 1474 | "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1475 | }; |
| 1476 | |
| 1477 | static const char *dec10_mux_text[] = { |
| 1478 | "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1479 | }; |
| 1480 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1481 | static const char const *anc_mux_text[] = { |
| 1482 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB", |
| 1483 | "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6" |
| 1484 | }; |
| 1485 | |
| 1486 | static const char const *anc1_fb_mux_text[] = { |
| 1487 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1488 | }; |
| 1489 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1490 | static const char *const iir_inp1_text[] = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1491 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1492 | "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 1493 | }; |
| 1494 | |
| 1495 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 1496 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text); |
| 1497 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1498 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 1499 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text); |
| 1500 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1501 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
| 1502 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text); |
| 1503 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1504 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 1505 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text); |
| 1506 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1507 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 1508 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text); |
| 1509 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1510 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 1511 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text); |
| 1512 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1513 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 1514 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text); |
| 1515 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1516 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
| 1517 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text); |
| 1518 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1519 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
| 1520 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text); |
| 1521 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1522 | static const struct soc_enum rx5_mix1_inp1_chain_enum = |
| 1523 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text); |
| 1524 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1525 | static const struct soc_enum rx5_mix1_inp2_chain_enum = |
| 1526 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text); |
| 1527 | |
| 1528 | static const struct soc_enum rx6_mix1_inp1_chain_enum = |
| 1529 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text); |
| 1530 | |
| 1531 | static const struct soc_enum rx6_mix1_inp2_chain_enum = |
| 1532 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text); |
| 1533 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1534 | static const struct soc_enum rx7_mix1_inp1_chain_enum = |
| 1535 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text); |
| 1536 | |
| 1537 | static const struct soc_enum rx7_mix1_inp2_chain_enum = |
| 1538 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text); |
| 1539 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1540 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1541 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1542 | |
| 1543 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1544 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1545 | |
| 1546 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1547 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1548 | |
| 1549 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1550 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1551 | |
| 1552 | static const struct soc_enum rx3_mix2_inp1_chain_enum = |
| 1553 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text); |
| 1554 | |
| 1555 | static const struct soc_enum rx3_mix2_inp2_chain_enum = |
| 1556 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text); |
| 1557 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1558 | static const struct soc_enum rx4_dsm_enum = |
| 1559 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text); |
| 1560 | |
| 1561 | static const struct soc_enum rx6_dsm_enum = |
| 1562 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text); |
| 1563 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1564 | static const struct soc_enum sb_tx1_mux_enum = |
| 1565 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 1566 | |
| 1567 | static const struct soc_enum sb_tx2_mux_enum = |
| 1568 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 1569 | |
| 1570 | static const struct soc_enum sb_tx3_mux_enum = |
| 1571 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 1572 | |
| 1573 | static const struct soc_enum sb_tx4_mux_enum = |
| 1574 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 1575 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1576 | static const struct soc_enum sb_tx5_mux_enum = |
| 1577 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 1578 | |
| 1579 | static const struct soc_enum sb_tx6_mux_enum = |
| 1580 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text); |
| 1581 | |
| 1582 | static const struct soc_enum sb_tx7_mux_enum = |
| 1583 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18, |
| 1584 | sb_tx7_to_tx10_mux_text); |
| 1585 | |
| 1586 | static const struct soc_enum sb_tx8_mux_enum = |
| 1587 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18, |
| 1588 | sb_tx7_to_tx10_mux_text); |
| 1589 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1590 | static const struct soc_enum sb_tx9_mux_enum = |
| 1591 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18, |
| 1592 | sb_tx7_to_tx10_mux_text); |
| 1593 | |
| 1594 | static const struct soc_enum sb_tx10_mux_enum = |
| 1595 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18, |
| 1596 | sb_tx7_to_tx10_mux_text); |
| 1597 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1598 | static const struct soc_enum dec1_mux_enum = |
| 1599 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text); |
| 1600 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1601 | static const struct soc_enum dec2_mux_enum = |
| 1602 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text); |
| 1603 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1604 | static const struct soc_enum dec3_mux_enum = |
| 1605 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text); |
| 1606 | |
| 1607 | static const struct soc_enum dec4_mux_enum = |
| 1608 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text); |
| 1609 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1610 | static const struct soc_enum dec5_mux_enum = |
| 1611 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text); |
| 1612 | |
| 1613 | static const struct soc_enum dec6_mux_enum = |
| 1614 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text); |
| 1615 | |
| 1616 | static const struct soc_enum dec7_mux_enum = |
| 1617 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text); |
| 1618 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1619 | static const struct soc_enum dec8_mux_enum = |
| 1620 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text); |
| 1621 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1622 | static const struct soc_enum dec9_mux_enum = |
| 1623 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text); |
| 1624 | |
| 1625 | static const struct soc_enum dec10_mux_enum = |
| 1626 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text); |
| 1627 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1628 | static const struct soc_enum anc1_mux_enum = |
| 1629 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text); |
| 1630 | |
| 1631 | static const struct soc_enum anc2_mux_enum = |
| 1632 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text); |
| 1633 | |
| 1634 | static const struct soc_enum anc1_fb_mux_enum = |
| 1635 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1636 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1637 | static const struct soc_enum iir1_inp1_mux_enum = |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1638 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir_inp1_text); |
| 1639 | |
| 1640 | static const struct soc_enum iir2_inp1_mux_enum = |
| 1641 | 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] | 1642 | |
| 1643 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1644 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1645 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1646 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1647 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1648 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1649 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1650 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1651 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1652 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1653 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1654 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1655 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1656 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1657 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1658 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1659 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1660 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1661 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1662 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1663 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1664 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1665 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1666 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1667 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1668 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1669 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1670 | static const struct snd_kcontrol_new rx5_mix1_inp1_mux = |
| 1671 | SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum); |
| 1672 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1673 | static const struct snd_kcontrol_new rx5_mix1_inp2_mux = |
| 1674 | SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum); |
| 1675 | |
| 1676 | static const struct snd_kcontrol_new rx6_mix1_inp1_mux = |
| 1677 | SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum); |
| 1678 | |
| 1679 | static const struct snd_kcontrol_new rx6_mix1_inp2_mux = |
| 1680 | SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum); |
| 1681 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1682 | static const struct snd_kcontrol_new rx7_mix1_inp1_mux = |
| 1683 | SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum); |
| 1684 | |
| 1685 | static const struct snd_kcontrol_new rx7_mix1_inp2_mux = |
| 1686 | SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum); |
| 1687 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1688 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1689 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1690 | |
| 1691 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1692 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1693 | |
| 1694 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1695 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1696 | |
| 1697 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1698 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1699 | |
| 1700 | static const struct snd_kcontrol_new rx3_mix2_inp1_mux = |
| 1701 | SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum); |
| 1702 | |
| 1703 | static const struct snd_kcontrol_new rx3_mix2_inp2_mux = |
| 1704 | SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum); |
| 1705 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1706 | static const struct snd_kcontrol_new rx4_dsm_mux = |
| 1707 | SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum); |
| 1708 | |
| 1709 | static const struct snd_kcontrol_new rx6_dsm_mux = |
| 1710 | SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum); |
| 1711 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1712 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1713 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1714 | |
| 1715 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1716 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1717 | |
| 1718 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1719 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1720 | |
| 1721 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1722 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1723 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1724 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 1725 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 1726 | |
| 1727 | static const struct snd_kcontrol_new sb_tx6_mux = |
| 1728 | SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); |
| 1729 | |
| 1730 | static const struct snd_kcontrol_new sb_tx7_mux = |
| 1731 | SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); |
| 1732 | |
| 1733 | static const struct snd_kcontrol_new sb_tx8_mux = |
| 1734 | SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); |
| 1735 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1736 | static const struct snd_kcontrol_new sb_tx9_mux = |
| 1737 | SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum); |
| 1738 | |
| 1739 | static const struct snd_kcontrol_new sb_tx10_mux = |
| 1740 | SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum); |
| 1741 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1742 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1743 | static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1744 | struct snd_ctl_elem_value *ucontrol) |
| 1745 | { |
| 1746 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1747 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1748 | struct snd_soc_codec *codec = w->codec; |
| 1749 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1750 | unsigned int dec_mux, decimator; |
| 1751 | char *dec_name = NULL; |
| 1752 | char *widget_name = NULL; |
| 1753 | char *temp; |
| 1754 | u16 tx_mux_ctl_reg; |
| 1755 | u8 adc_dmic_sel = 0x0; |
| 1756 | int ret = 0; |
| 1757 | |
| 1758 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1759 | return -EINVAL; |
| 1760 | |
| 1761 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1762 | |
| 1763 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1764 | if (!widget_name) |
| 1765 | return -ENOMEM; |
| 1766 | temp = widget_name; |
| 1767 | |
| 1768 | dec_name = strsep(&widget_name, " "); |
| 1769 | widget_name = temp; |
| 1770 | if (!dec_name) { |
| 1771 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1772 | ret = -EINVAL; |
| 1773 | goto out; |
| 1774 | } |
| 1775 | |
| 1776 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 1777 | if (ret < 0) { |
| 1778 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1779 | ret = -EINVAL; |
| 1780 | goto out; |
| 1781 | } |
| 1782 | |
| 1783 | dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u" |
| 1784 | " dec_mux = %u\n", __func__, w->name, dec_name, decimator, |
| 1785 | dec_mux); |
| 1786 | |
| 1787 | |
| 1788 | switch (decimator) { |
| 1789 | case 1: |
| 1790 | case 2: |
| 1791 | case 3: |
| 1792 | case 4: |
| 1793 | case 5: |
| 1794 | case 6: |
| 1795 | if (dec_mux == 1) |
| 1796 | adc_dmic_sel = 0x1; |
| 1797 | else |
| 1798 | adc_dmic_sel = 0x0; |
| 1799 | break; |
| 1800 | case 7: |
| 1801 | case 8: |
| 1802 | case 9: |
| 1803 | case 10: |
| 1804 | if ((dec_mux == 1) || (dec_mux == 2)) |
| 1805 | adc_dmic_sel = 0x1; |
| 1806 | else |
| 1807 | adc_dmic_sel = 0x0; |
| 1808 | break; |
| 1809 | default: |
| 1810 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1811 | ret = -EINVAL; |
| 1812 | goto out; |
| 1813 | } |
| 1814 | |
| 1815 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1816 | |
| 1817 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1818 | |
| 1819 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1820 | |
| 1821 | out: |
| 1822 | kfree(widget_name); |
| 1823 | return ret; |
| 1824 | } |
| 1825 | |
| 1826 | #define WCD9310_DEC_ENUM(xname, xenum) \ |
| 1827 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1828 | .info = snd_soc_info_enum_double, \ |
| 1829 | .get = snd_soc_dapm_get_enum_double, \ |
| 1830 | .put = wcd9310_put_dec_enum, \ |
| 1831 | .private_value = (unsigned long)&xenum } |
| 1832 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1833 | static const struct snd_kcontrol_new dec1_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1834 | WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1835 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1836 | static const struct snd_kcontrol_new dec2_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1837 | WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1838 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1839 | static const struct snd_kcontrol_new dec3_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1840 | WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1841 | |
| 1842 | static const struct snd_kcontrol_new dec4_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1843 | WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1844 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1845 | static const struct snd_kcontrol_new dec5_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1846 | WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1847 | |
| 1848 | static const struct snd_kcontrol_new dec6_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1849 | WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1850 | |
| 1851 | static const struct snd_kcontrol_new dec7_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1852 | WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1853 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1854 | static const struct snd_kcontrol_new dec8_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1855 | WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1856 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1857 | static const struct snd_kcontrol_new dec9_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1858 | WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1859 | |
| 1860 | static const struct snd_kcontrol_new dec10_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1861 | WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1862 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1863 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1864 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1865 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 1866 | static const struct snd_kcontrol_new iir2_inp1_mux = |
| 1867 | SOC_DAPM_ENUM("IIR2 INP1 Mux", iir2_inp1_mux_enum); |
| 1868 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1869 | static const struct snd_kcontrol_new anc1_mux = |
| 1870 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1871 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1872 | static const struct snd_kcontrol_new anc2_mux = |
| 1873 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1874 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1875 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1876 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1877 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1878 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1879 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0) |
| 1880 | }; |
| 1881 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1882 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1883 | }; |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1884 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1885 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1886 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1887 | 7, 1, 0), |
| 1888 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1889 | 7, 1, 0), |
| 1890 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1891 | TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0), |
| 1892 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1893 | TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0), |
| 1894 | }; |
| 1895 | |
| 1896 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1897 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1898 | 6, 1, 0), |
| 1899 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1900 | 6, 1, 0), |
| 1901 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1902 | TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0), |
| 1903 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1904 | TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0), |
| 1905 | }; |
| 1906 | |
| 1907 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1908 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1909 | 5, 1, 0), |
| 1910 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1911 | 5, 1, 0), |
| 1912 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1913 | TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0), |
| 1914 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1915 | TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0), |
| 1916 | }; |
| 1917 | |
| 1918 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1919 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1920 | 4, 1, 0), |
| 1921 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1922 | 4, 1, 0), |
| 1923 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1924 | TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0), |
| 1925 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1926 | TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0), |
| 1927 | }; |
| 1928 | |
| 1929 | static const struct snd_kcontrol_new lineout3_pa_mix[] = { |
| 1930 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1931 | 3, 1, 0), |
| 1932 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1933 | 3, 1, 0), |
| 1934 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1935 | TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0), |
| 1936 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1937 | TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0), |
| 1938 | }; |
| 1939 | |
| 1940 | static const struct snd_kcontrol_new lineout4_pa_mix[] = { |
| 1941 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1942 | 2, 1, 0), |
| 1943 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1944 | 2, 1, 0), |
| 1945 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1946 | TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0), |
| 1947 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1948 | TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0), |
| 1949 | }; |
| 1950 | |
| 1951 | static const struct snd_kcontrol_new lineout5_pa_mix[] = { |
| 1952 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1953 | 1, 1, 0), |
| 1954 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1955 | 1, 1, 0), |
| 1956 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1957 | TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0), |
| 1958 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1959 | TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0), |
| 1960 | }; |
| 1961 | |
| 1962 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1963 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1964 | 0, 1, 0), |
| 1965 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1966 | 0, 1, 0), |
| 1967 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1968 | TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0), |
| 1969 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1970 | TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0), |
| 1971 | }; |
| 1972 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1973 | static const struct snd_kcontrol_new lineout3_ground_switch = |
| 1974 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0); |
| 1975 | |
| 1976 | static const struct snd_kcontrol_new lineout4_ground_switch = |
| 1977 | 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] | 1978 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1979 | /* virtual port entries */ |
| 1980 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1981 | struct snd_ctl_elem_value *ucontrol) |
| 1982 | { |
| 1983 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1984 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1985 | |
| 1986 | ucontrol->value.integer.value[0] = widget->value; |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1991 | struct snd_ctl_elem_value *ucontrol) |
| 1992 | { |
| 1993 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1994 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1995 | struct snd_soc_codec *codec = widget->codec; |
| 1996 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 1997 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1998 | struct soc_multi_mixer_control *mixer = |
| 1999 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 2000 | u32 dai_id = widget->shift; |
| 2001 | u32 port_id = mixer->shift; |
| 2002 | u32 enable = ucontrol->value.integer.value[0]; |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 2003 | u32 vtable = vport_check_table[dai_id]; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2004 | |
| 2005 | pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__, |
| 2006 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 2007 | ucontrol->value.integer.value[0]); |
| 2008 | |
| 2009 | mutex_lock(&codec->mutex); |
| 2010 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 2011 | if (dai_id != AIF1_CAP) { |
| 2012 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 2013 | __func__); |
| 2014 | mutex_unlock(&codec->mutex); |
| 2015 | return -EINVAL; |
| 2016 | } |
| 2017 | } |
| 2018 | switch (dai_id) { |
| 2019 | case AIF1_CAP: |
| 2020 | case AIF2_CAP: |
| 2021 | case AIF3_CAP: |
| 2022 | /* only add to the list if value not set |
| 2023 | */ |
| 2024 | if (enable && !(widget->value & 1 << port_id)) { |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 2025 | if (tabla_p->intf_type == |
| 2026 | WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 2027 | vtable = vport_check_table[dai_id]; |
| 2028 | if (tabla_p->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) |
| 2029 | vtable = vport_i2s_check_table[dai_id]; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2030 | if (wcd9xxx_tx_vport_validation( |
Venkat Sudhir | 96dd28c | 2012-12-04 17:00:19 -0800 | [diff] [blame] | 2031 | vtable, |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2032 | port_id, |
| 2033 | tabla_p->dai)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2034 | pr_info("%s: TX%u is used by other virtual port\n", |
| 2035 | __func__, port_id + 1); |
| 2036 | mutex_unlock(&codec->mutex); |
| 2037 | return -EINVAL; |
| 2038 | } |
| 2039 | widget->value |= 1 << port_id; |
| 2040 | list_add_tail(&core->tx_chs[port_id].list, |
| 2041 | &tabla_p->dai[dai_id].wcd9xxx_ch_list |
| 2042 | ); |
| 2043 | } else if (!enable && (widget->value & 1 << port_id)) { |
| 2044 | widget->value &= ~(1 << port_id); |
| 2045 | list_del_init(&core->tx_chs[port_id].list); |
| 2046 | } else { |
| 2047 | if (enable) |
| 2048 | pr_info("%s: TX%u port is used by this virtual port\n", |
| 2049 | __func__, port_id + 1); |
| 2050 | else |
| 2051 | pr_info("%s: TX%u port is not used by this virtual port\n", |
| 2052 | __func__, port_id + 1); |
| 2053 | /* avoid update power function */ |
| 2054 | mutex_unlock(&codec->mutex); |
| 2055 | return 0; |
| 2056 | } |
| 2057 | break; |
| 2058 | default: |
| 2059 | pr_err("Unknown AIF %d\n", dai_id); |
| 2060 | mutex_unlock(&codec->mutex); |
| 2061 | return -EINVAL; |
| 2062 | } |
| 2063 | pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__, |
| 2064 | widget->name, widget->sname, widget->value, widget->shift); |
| 2065 | |
| 2066 | snd_soc_dapm_mixer_update_power(widget, kcontrol, enable); |
| 2067 | |
| 2068 | mutex_unlock(&codec->mutex); |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 2073 | struct snd_ctl_elem_value *ucontrol) |
| 2074 | { |
| 2075 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2076 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2077 | |
| 2078 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2079 | return 0; |
| 2080 | } |
| 2081 | |
| 2082 | static const char *const slim_rx_mux_text[] = { |
| 2083 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB" |
| 2084 | }; |
| 2085 | |
| 2086 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 2087 | struct snd_ctl_elem_value *ucontrol) |
| 2088 | { |
| 2089 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2090 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2091 | struct snd_soc_codec *codec = widget->codec; |
| 2092 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 2093 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 2094 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 2095 | u32 port_id = widget->shift; |
| 2096 | |
| 2097 | pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__, |
| 2098 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 2099 | ucontrol->value.enumerated.item[0]); |
| 2100 | |
| 2101 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2102 | |
| 2103 | mutex_lock(&codec->mutex); |
| 2104 | |
| 2105 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 2106 | if (widget->value > 1) { |
| 2107 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 2108 | __func__); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2109 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | /* value need to match the Virtual port and AIF number |
| 2113 | */ |
| 2114 | switch (widget->value) { |
| 2115 | case 0: |
| 2116 | list_del_init(&core->rx_chs[port_id].list); |
| 2117 | break; |
| 2118 | case 1: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2119 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2120 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2121 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2122 | list_add_tail(&core->rx_chs[port_id].list, |
| 2123 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 2124 | break; |
| 2125 | case 2: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2126 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2127 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2128 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2129 | list_add_tail(&core->rx_chs[port_id].list, |
| 2130 | &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 2131 | break; |
| 2132 | case 3: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2133 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 2134 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 2135 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2136 | list_add_tail(&core->rx_chs[port_id].list, |
| 2137 | &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 2138 | break; |
| 2139 | default: |
| 2140 | pr_err("Unknown AIF %d\n", widget->value); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2141 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e); |
| 2145 | |
| 2146 | mutex_unlock(&codec->mutex); |
| 2147 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2148 | |
| 2149 | pr_err: |
| 2150 | pr_err("%s: RX%u is used by current requesting AIF_PB itself\n", |
| 2151 | __func__, port_id + 1); |
Santosh Mardi | 2a831d7 | 2012-11-07 20:45:52 +0530 | [diff] [blame] | 2152 | mutex_unlock(&codec->mutex); |
| 2153 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 2154 | err: |
| 2155 | mutex_unlock(&codec->mutex); |
| 2156 | return -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static const struct soc_enum slim_rx_mux_enum = |
| 2160 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); |
| 2161 | |
| 2162 | static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = { |
| 2163 | SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, |
| 2164 | slim_rx_mux_get, slim_rx_mux_put), |
| 2165 | SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, |
| 2166 | slim_rx_mux_get, slim_rx_mux_put), |
| 2167 | SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, |
| 2168 | slim_rx_mux_get, slim_rx_mux_put), |
| 2169 | SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, |
| 2170 | slim_rx_mux_get, slim_rx_mux_put), |
| 2171 | SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, |
| 2172 | slim_rx_mux_get, slim_rx_mux_put), |
| 2173 | SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum, |
| 2174 | slim_rx_mux_get, slim_rx_mux_put), |
| 2175 | SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum, |
| 2176 | slim_rx_mux_get, slim_rx_mux_put), |
| 2177 | }; |
| 2178 | |
| 2179 | static const struct snd_kcontrol_new aif_cap_mixer[] = { |
| 2180 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0, |
| 2181 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2182 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0, |
| 2183 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2184 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0, |
| 2185 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2186 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0, |
| 2187 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2188 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0, |
| 2189 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2190 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0, |
| 2191 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2192 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0, |
| 2193 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2194 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0, |
| 2195 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2196 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0, |
| 2197 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2198 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0, |
| 2199 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 2200 | }; |
| 2201 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2202 | static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2203 | int enable) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2204 | { |
| 2205 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2206 | |
| 2207 | pr_debug("%s %d\n", __func__, enable); |
| 2208 | |
| 2209 | if (enable) { |
| 2210 | tabla->adc_count++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2211 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2); |
| 2212 | } else { |
| 2213 | tabla->adc_count--; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2214 | if (!tabla->adc_count) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2215 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2216 | 0x2, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 2221 | struct snd_kcontrol *kcontrol, int event) |
| 2222 | { |
| 2223 | struct snd_soc_codec *codec = w->codec; |
| 2224 | u16 adc_reg; |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2225 | u8 init_bit_shift; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2226 | |
| 2227 | pr_debug("%s %d\n", __func__, event); |
| 2228 | |
| 2229 | if (w->reg == TABLA_A_TX_1_2_EN) |
| 2230 | adc_reg = TABLA_A_TX_1_2_TEST_CTL; |
| 2231 | else if (w->reg == TABLA_A_TX_3_4_EN) |
| 2232 | adc_reg = TABLA_A_TX_3_4_TEST_CTL; |
| 2233 | else if (w->reg == TABLA_A_TX_5_6_EN) |
| 2234 | adc_reg = TABLA_A_TX_5_6_TEST_CTL; |
| 2235 | else { |
| 2236 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 2237 | return -EINVAL; |
| 2238 | } |
| 2239 | |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2240 | if (w->shift == 3) |
| 2241 | init_bit_shift = 6; |
| 2242 | else if (w->shift == 7) |
| 2243 | init_bit_shift = 7; |
| 2244 | else { |
| 2245 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 2246 | __func__); |
| 2247 | return -EINVAL; |
| 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2252 | switch (event) { |
| 2253 | case SND_SOC_DAPM_PRE_PMU: |
| 2254 | tabla_codec_enable_adc_block(codec, 1); |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2255 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 2256 | 1 << init_bit_shift); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2257 | break; |
| 2258 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 2259 | |
| 2260 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 2261 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2262 | break; |
| 2263 | case SND_SOC_DAPM_POST_PMD: |
| 2264 | tabla_codec_enable_adc_block(codec, 0); |
| 2265 | break; |
| 2266 | } |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2270 | static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 2271 | { |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2272 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2273 | 0x80); |
| 2274 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 2275 | 0x04); |
| 2276 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2277 | 0x01); |
| 2278 | usleep_range(1000, 1000); |
| 2279 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2280 | 0x00); |
| 2281 | } |
| 2282 | |
| 2283 | static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 2284 | enum tabla_bandgap_type choice) |
| 2285 | { |
| 2286 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2287 | |
| 2288 | /* TODO lock resources accessed by audio streams and threaded |
| 2289 | * interrupt handlers |
| 2290 | */ |
| 2291 | |
| 2292 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
| 2293 | tabla->bandgap_type); |
| 2294 | |
| 2295 | if (tabla->bandgap_type == choice) |
| 2296 | return; |
| 2297 | |
| 2298 | if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) && |
| 2299 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 2300 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2301 | } else if (choice == TABLA_BANDGAP_MBHC_MODE) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2302 | /* bandgap mode becomes fast, |
| 2303 | * mclk should be off or clk buff source souldn't be VBG |
| 2304 | * Let's turn off mclk always */ |
| 2305 | 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] | 2306 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 2307 | 0x2); |
| 2308 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2309 | 0x80); |
| 2310 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 2311 | 0x4); |
| 2312 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2313 | 0x01); |
| 2314 | usleep_range(1000, 1000); |
| 2315 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2316 | 0x00); |
| 2317 | } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) && |
| 2318 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2319 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2320 | usleep_range(100, 100); |
| 2321 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2322 | } else if (choice == TABLA_BANDGAP_OFF) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2323 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2324 | } else { |
| 2325 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 2326 | } |
| 2327 | tabla->bandgap_type = choice; |
| 2328 | } |
| 2329 | |
| 2330 | static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 2331 | { |
| 2332 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2333 | pr_debug("%s\n", __func__); |
| 2334 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2335 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2336 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 2337 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2338 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2339 | tabla->clock_active = false; |
| 2340 | } |
| 2341 | |
| 2342 | static int tabla_codec_mclk_index(const struct tabla_priv *tabla) |
| 2343 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2344 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2345 | return 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2346 | else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2347 | return 1; |
| 2348 | else { |
| 2349 | BUG_ON(1); |
| 2350 | return -EINVAL; |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 2355 | { |
| 2356 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2357 | |
| 2358 | if (enable) { |
| 2359 | tabla->rx_bias_count++; |
| 2360 | if (tabla->rx_bias_count == 1) |
| 2361 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2362 | 0x80, 0x80); |
| 2363 | } else { |
| 2364 | tabla->rx_bias_count--; |
| 2365 | if (!tabla->rx_bias_count) |
| 2366 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2367 | 0x80, 0x00); |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 2372 | int enable) |
| 2373 | { |
| 2374 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2375 | |
| 2376 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 2377 | if (enable) { |
| 2378 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2379 | /* bandgap mode to fast */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2380 | snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17); |
| 2381 | usleep_range(5, 5); |
| 2382 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2383 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2384 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2385 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2386 | usleep_range(10, 10); |
| 2387 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2388 | usleep_range(10000, 10000); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2389 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 2390 | } else { |
| 2391 | 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] | 2392 | 0); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2393 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2394 | /* clk source to ext clk and clk buff ref to VBG */ |
| 2395 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2396 | } |
| 2397 | tabla->config_mode_active = enable ? true : false; |
| 2398 | |
| 2399 | return 0; |
| 2400 | } |
| 2401 | |
| 2402 | static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2403 | int config_mode) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2404 | { |
| 2405 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2406 | |
| 2407 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 2408 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2409 | /* transit to RCO requires mclk off */ |
| 2410 | 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] | 2411 | if (config_mode) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2412 | /* enable RCO and switch to it */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2413 | tabla_codec_enable_config_mode(codec, 1); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2414 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2415 | usleep_range(1000, 1000); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2416 | } else { |
| 2417 | /* switch to MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2418 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 2419 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2420 | if (tabla->mbhc_polling_active) { |
| 2421 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 2422 | tabla_codec_enable_config_mode(codec, 0); |
| 2423 | } |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2424 | } |
| 2425 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2426 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2427 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2428 | /* on MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2429 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 2430 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 2431 | usleep_range(50, 50); |
| 2432 | tabla->clock_active = true; |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
| 2436 | static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 2437 | struct snd_kcontrol *kcontrol, int event) |
| 2438 | { |
| 2439 | struct snd_soc_codec *codec = w->codec; |
| 2440 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2441 | |
| 2442 | pr_debug("%s: %d\n", __func__, event); |
| 2443 | |
| 2444 | switch (event) { |
| 2445 | case SND_SOC_DAPM_PRE_PMU: |
| 2446 | tabla_codec_enable_bandgap(codec, |
| 2447 | TABLA_BANDGAP_AUDIO_MODE); |
| 2448 | tabla_enable_rx_bias(codec, 1); |
| 2449 | |
| 2450 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2451 | 0x08, 0x08); |
| 2452 | /* Enable Zero Cross detect for AUX PGA channel |
| 2453 | * and set the initial AUX PGA gain to NEG_0P0_DB |
| 2454 | * to avoid glitches. |
| 2455 | */ |
| 2456 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2457 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2458 | 0x20, 0x20); |
| 2459 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2460 | TABLA_A_AUX_L_GAIN); |
| 2461 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2462 | } else { |
| 2463 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2464 | 0x20, 0x20); |
| 2465 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2466 | TABLA_A_AUX_R_GAIN); |
| 2467 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2468 | } |
| 2469 | if (tabla->aux_pga_cnt++ == 1 |
| 2470 | && !tabla->mclk_enabled) { |
| 2471 | tabla_codec_enable_clock_block(codec, 1); |
| 2472 | pr_debug("AUX PGA enabled RC osc\n"); |
| 2473 | } |
| 2474 | break; |
| 2475 | |
| 2476 | case SND_SOC_DAPM_POST_PMU: |
| 2477 | if (w->reg == TABLA_A_AUX_L_EN) |
| 2478 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2479 | tabla->aux_l_gain); |
| 2480 | else |
| 2481 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2482 | tabla->aux_r_gain); |
| 2483 | break; |
| 2484 | |
| 2485 | case SND_SOC_DAPM_PRE_PMD: |
| 2486 | /* Mute AUX PGA channel in use before disabling AUX PGA */ |
| 2487 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2488 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2489 | TABLA_A_AUX_L_GAIN); |
| 2490 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2491 | } else { |
| 2492 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2493 | TABLA_A_AUX_R_GAIN); |
| 2494 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2495 | } |
| 2496 | break; |
| 2497 | |
| 2498 | case SND_SOC_DAPM_POST_PMD: |
| 2499 | tabla_enable_rx_bias(codec, 0); |
| 2500 | |
| 2501 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2502 | 0x08, 0x00); |
| 2503 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2504 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2505 | tabla->aux_l_gain); |
| 2506 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2507 | 0x20, 0x00); |
| 2508 | } else { |
| 2509 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2510 | tabla->aux_r_gain); |
| 2511 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2512 | 0x20, 0x00); |
| 2513 | } |
| 2514 | |
| 2515 | if (tabla->aux_pga_cnt-- == 0) { |
| 2516 | if (tabla->mbhc_polling_active) |
| 2517 | tabla_codec_enable_bandgap(codec, |
| 2518 | TABLA_BANDGAP_MBHC_MODE); |
| 2519 | else |
| 2520 | tabla_codec_enable_bandgap(codec, |
| 2521 | TABLA_BANDGAP_OFF); |
| 2522 | |
| 2523 | if (!tabla->mclk_enabled && |
| 2524 | !tabla->mbhc_polling_active) { |
| 2525 | tabla_codec_enable_clock_block(codec, 0); |
| 2526 | } |
| 2527 | } |
| 2528 | break; |
| 2529 | } |
| 2530 | return 0; |
| 2531 | } |
| 2532 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2533 | static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 2534 | struct snd_kcontrol *kcontrol, int event) |
| 2535 | { |
| 2536 | struct snd_soc_codec *codec = w->codec; |
| 2537 | u16 lineout_gain_reg; |
| 2538 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2539 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2540 | |
| 2541 | switch (w->shift) { |
| 2542 | case 0: |
| 2543 | lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN; |
| 2544 | break; |
| 2545 | case 1: |
| 2546 | lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN; |
| 2547 | break; |
| 2548 | case 2: |
| 2549 | lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN; |
| 2550 | break; |
| 2551 | case 3: |
| 2552 | lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN; |
| 2553 | break; |
| 2554 | case 4: |
| 2555 | lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN; |
| 2556 | break; |
| 2557 | default: |
| 2558 | pr_err("%s: Error, incorrect lineout register value\n", |
| 2559 | __func__); |
| 2560 | return -EINVAL; |
| 2561 | } |
| 2562 | |
| 2563 | switch (event) { |
| 2564 | case SND_SOC_DAPM_PRE_PMU: |
| 2565 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 2566 | break; |
| 2567 | case SND_SOC_DAPM_POST_PMU: |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2568 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2569 | __func__, w->name); |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2570 | usleep_range(16000, 16000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2571 | break; |
| 2572 | case SND_SOC_DAPM_POST_PMD: |
| 2573 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 2574 | break; |
| 2575 | } |
| 2576 | return 0; |
| 2577 | } |
| 2578 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2579 | |
| 2580 | static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2581 | struct snd_kcontrol *kcontrol, int event) |
| 2582 | { |
| 2583 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2584 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2585 | u8 dmic_clk_en; |
| 2586 | s32 *dmic_clk_cnt; |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2587 | unsigned int dmic; |
| 2588 | int ret; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2589 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2590 | ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic); |
| 2591 | if (ret < 0) { |
| 2592 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2593 | return -EINVAL; |
| 2594 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2595 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2596 | switch (dmic) { |
| 2597 | case 1: |
| 2598 | case 2: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2599 | dmic_clk_en = 0x01; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2600 | dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt); |
| 2601 | |
| 2602 | pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 2603 | __func__, event, dmic, *dmic_clk_cnt); |
| 2604 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2605 | break; |
| 2606 | |
| 2607 | case 3: |
| 2608 | case 4: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2609 | dmic_clk_en = 0x04; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2610 | dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt); |
| 2611 | |
| 2612 | pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 2613 | __func__, event, dmic, *dmic_clk_cnt); |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2614 | break; |
| 2615 | |
| 2616 | case 5: |
| 2617 | case 6: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2618 | dmic_clk_en = 0x10; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2619 | dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt); |
| 2620 | |
| 2621 | pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n", |
| 2622 | __func__, event, dmic, *dmic_clk_cnt); |
| 2623 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2624 | break; |
| 2625 | |
| 2626 | default: |
| 2627 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2628 | return -EINVAL; |
| 2629 | } |
| 2630 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2631 | switch (event) { |
| 2632 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2633 | |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2634 | (*dmic_clk_cnt)++; |
| 2635 | if (*dmic_clk_cnt == 1) |
| 2636 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2637 | dmic_clk_en, dmic_clk_en); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2638 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2639 | break; |
| 2640 | case SND_SOC_DAPM_POST_PMD: |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2641 | |
| 2642 | (*dmic_clk_cnt)--; |
| 2643 | if (*dmic_clk_cnt == 0) |
| 2644 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2645 | dmic_clk_en, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2646 | break; |
| 2647 | } |
| 2648 | return 0; |
| 2649 | } |
| 2650 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2651 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2652 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2653 | static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 2654 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2655 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2656 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
| 2657 | int mbhc_state = tabla->mbhc_state; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2658 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2659 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2660 | if (!tabla->mbhc_polling_active) { |
| 2661 | pr_debug("Polling is not active, do not start polling\n"); |
| 2662 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2663 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2664 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2665 | |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 2666 | if (tabla->no_mic_headset_override) { |
| 2667 | pr_debug("%s setting button threshold to min", __func__); |
| 2668 | /* set to min */ |
| 2669 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80); |
| 2670 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00); |
| 2671 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80); |
| 2672 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00); |
| 2673 | } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) { |
| 2674 | pr_debug("%s recovering MBHC state machine\n", __func__); |
| 2675 | tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
| 2676 | /* set to max button press threshold */ |
| 2677 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F); |
| 2678 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF); |
| 2679 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 2680 | (TABLA_IS_1_X(tabla_core->version) ? |
| 2681 | 0x07 : 0x7F)); |
| 2682 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF); |
| 2683 | /* set to max */ |
| 2684 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F); |
| 2685 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2688 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
| 2689 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2690 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2691 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2694 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2695 | static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 2696 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2697 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2698 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2699 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2700 | if (!tabla->mbhc_polling_active) { |
| 2701 | pr_debug("polling not active, nothing to pause\n"); |
| 2702 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2703 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2704 | |
Simmi Pateriya | 1b9a309 | 2013-01-02 11:49:26 +0530 | [diff] [blame] | 2705 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 2706 | msleep(250); |
| 2707 | 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] | 2708 | 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] | 2709 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2712 | 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] | 2713 | { |
| 2714 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2715 | u8 reg_mode_val, cur_mode_val; |
| 2716 | bool mbhc_was_polling = false; |
| 2717 | |
| 2718 | if (mode) |
| 2719 | reg_mode_val = TABLA_CFILT_FAST_MODE; |
| 2720 | else |
| 2721 | reg_mode_val = TABLA_CFILT_SLOW_MODE; |
| 2722 | |
| 2723 | cur_mode_val = snd_soc_read(codec, |
| 2724 | tabla->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 2725 | |
| 2726 | if (cur_mode_val != reg_mode_val) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2727 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2728 | if (tabla->mbhc_polling_active) { |
| 2729 | tabla_codec_pause_hs_polling(codec); |
| 2730 | mbhc_was_polling = true; |
| 2731 | } |
| 2732 | snd_soc_update_bits(codec, |
| 2733 | tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 2734 | if (mbhc_was_polling) |
| 2735 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2736 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2737 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
| 2738 | cur_mode_val, reg_mode_val); |
| 2739 | } else { |
| 2740 | pr_debug("%s: CFILT Value is already %x\n", |
| 2741 | __func__, cur_mode_val); |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 2746 | u8 cfilt_sel, int inc) |
| 2747 | { |
| 2748 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2749 | u32 *cfilt_cnt_ptr = NULL; |
| 2750 | u16 micb_cfilt_reg; |
| 2751 | |
| 2752 | switch (cfilt_sel) { |
| 2753 | case TABLA_CFILT1_SEL: |
| 2754 | cfilt_cnt_ptr = &tabla->cfilt1_cnt; |
| 2755 | micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL; |
| 2756 | break; |
| 2757 | case TABLA_CFILT2_SEL: |
| 2758 | cfilt_cnt_ptr = &tabla->cfilt2_cnt; |
| 2759 | micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL; |
| 2760 | break; |
| 2761 | case TABLA_CFILT3_SEL: |
| 2762 | cfilt_cnt_ptr = &tabla->cfilt3_cnt; |
| 2763 | micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL; |
| 2764 | break; |
| 2765 | default: |
| 2766 | return; /* should not happen */ |
| 2767 | } |
| 2768 | |
| 2769 | if (inc) { |
| 2770 | if (!(*cfilt_cnt_ptr)++) { |
| 2771 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 2772 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2773 | tabla_codec_switch_cfilt_mode(codec, 0); |
| 2774 | |
| 2775 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 2776 | } |
| 2777 | } else { |
| 2778 | /* check if count not zero, decrement |
| 2779 | * then check if zero, go ahead disable cfilter |
| 2780 | */ |
| 2781 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 2782 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 2783 | |
| 2784 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 2785 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2786 | tabla_codec_switch_cfilt_mode(codec, 1); |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2791 | static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 2792 | { |
| 2793 | int rc = -EINVAL; |
| 2794 | unsigned min_mv, max_mv; |
| 2795 | |
| 2796 | switch (ldoh_v) { |
| 2797 | case TABLA_LDOH_1P95_V: |
| 2798 | min_mv = 160; |
| 2799 | max_mv = 1800; |
| 2800 | break; |
| 2801 | case TABLA_LDOH_2P35_V: |
| 2802 | min_mv = 200; |
| 2803 | max_mv = 2200; |
| 2804 | break; |
| 2805 | case TABLA_LDOH_2P75_V: |
| 2806 | min_mv = 240; |
| 2807 | max_mv = 2600; |
| 2808 | break; |
| 2809 | case TABLA_LDOH_2P85_V: |
| 2810 | min_mv = 250; |
| 2811 | max_mv = 2700; |
| 2812 | break; |
| 2813 | default: |
| 2814 | goto done; |
| 2815 | } |
| 2816 | |
| 2817 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 2818 | goto done; |
| 2819 | |
| 2820 | for (rc = 4; rc <= 44; rc++) { |
| 2821 | min_mv = max_mv * (rc) / 44; |
| 2822 | if (min_mv >= cfilt_mv) { |
| 2823 | rc -= 4; |
| 2824 | break; |
| 2825 | } |
| 2826 | } |
| 2827 | done: |
| 2828 | return rc; |
| 2829 | } |
| 2830 | |
| 2831 | static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec) |
| 2832 | { |
| 2833 | u8 hph_reg_val = 0; |
| 2834 | hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN); |
| 2835 | |
| 2836 | return (hph_reg_val & 0x30) ? true : false; |
| 2837 | } |
| 2838 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2839 | static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 2840 | { |
| 2841 | u8 hph_reg_val = 0; |
| 2842 | if (left) |
| 2843 | hph_reg_val = snd_soc_read(codec, |
| 2844 | TABLA_A_RX_HPH_L_DAC_CTL); |
| 2845 | else |
| 2846 | hph_reg_val = snd_soc_read(codec, |
| 2847 | TABLA_A_RX_HPH_R_DAC_CTL); |
| 2848 | |
| 2849 | return (hph_reg_val & 0xC0) ? true : false; |
| 2850 | } |
| 2851 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2852 | static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 2853 | { |
| 2854 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 2855 | } |
| 2856 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2857 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2858 | static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec, |
| 2859 | int usec) |
| 2860 | { |
| 2861 | int cfilt_k_val; |
| 2862 | bool set = true; |
| 2863 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2864 | |
| 2865 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 2866 | tabla->mbhc_micbias_switched) { |
| 2867 | pr_debug("%s: set mic V to micbias V\n", __func__); |
| 2868 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2869 | tabla_turn_onoff_override(codec, true); |
| 2870 | while (1) { |
| 2871 | cfilt_k_val = tabla_find_k_value( |
| 2872 | tabla->pdata->micbias.ldoh_v, |
| 2873 | set ? tabla->mbhc_data.micb_mv : |
| 2874 | VDDIO_MICBIAS_MV); |
| 2875 | snd_soc_update_bits(codec, |
| 2876 | tabla->mbhc_bias_regs.cfilt_val, |
| 2877 | 0xFC, (cfilt_k_val << 2)); |
| 2878 | if (!set) |
| 2879 | break; |
| 2880 | usleep_range(usec, usec); |
| 2881 | set = false; |
| 2882 | } |
| 2883 | tabla_turn_onoff_override(codec, false); |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | /* called under codec_resource_lock acquisition */ |
| 2888 | static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2889 | int vddio_switch, bool restartpolling, |
| 2890 | bool checkpolling) |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2891 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2892 | int cfilt_k_val; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2893 | bool override; |
| 2894 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2895 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2896 | if (vddio_switch && !tabla->mbhc_micbias_switched && |
| 2897 | (!checkpolling || tabla->mbhc_polling_active)) { |
| 2898 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2899 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2900 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 2901 | if (!override) |
| 2902 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2903 | /* Adjust threshold if Mic Bias voltage changes */ |
| 2904 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2905 | cfilt_k_val = tabla_find_k_value( |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2906 | tabla->pdata->micbias.ldoh_v, |
| 2907 | VDDIO_MICBIAS_MV); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2908 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2909 | tabla->mbhc_bias_regs.cfilt_val, |
| 2910 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2911 | usleep_range(cfilt_adjust_ms * 1000, |
| 2912 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2913 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2914 | tabla->mbhc_data.adj_v_ins_hu & 0xFF); |
| 2915 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2916 | (tabla->mbhc_data.adj_v_ins_hu >> 8) & |
| 2917 | 0xFF); |
| 2918 | pr_debug("%s: Programmed MBHC thresholds to VDDIO\n", |
| 2919 | __func__); |
| 2920 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2921 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2922 | /* enable MIC BIAS Switch to VDDIO */ |
| 2923 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2924 | 0x80, 0x80); |
| 2925 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2926 | 0x10, 0x00); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2927 | if (!override) |
| 2928 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2929 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2930 | tabla_codec_start_hs_polling(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2931 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2932 | tabla->mbhc_micbias_switched = true; |
| 2933 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2934 | } else if (!vddio_switch && tabla->mbhc_micbias_switched) { |
| 2935 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2936 | restartpolling) |
| 2937 | tabla_codec_pause_hs_polling(codec); |
| 2938 | /* Reprogram thresholds */ |
| 2939 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 2940 | cfilt_k_val = tabla_find_k_value( |
| 2941 | tabla->pdata->micbias.ldoh_v, |
| 2942 | tabla->mbhc_data.micb_mv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2943 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2944 | tabla->mbhc_bias_regs.cfilt_val, |
| 2945 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2946 | usleep_range(cfilt_adjust_ms * 1000, |
| 2947 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2948 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2949 | tabla->mbhc_data.v_ins_hu & 0xFF); |
| 2950 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2951 | (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF); |
| 2952 | pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n", |
| 2953 | __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2954 | } |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2955 | |
| 2956 | /* Disable MIC BIAS Switch to VDDIO */ |
| 2957 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2958 | 0x80, 0x00); |
| 2959 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2960 | 0x10, 0x00); |
| 2961 | |
| 2962 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2963 | restartpolling) |
| 2964 | tabla_codec_start_hs_polling(codec); |
| 2965 | |
| 2966 | tabla->mbhc_micbias_switched = false; |
| 2967 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2968 | } |
| 2969 | } |
| 2970 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2971 | static void tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2972 | int vddio_switch) |
| 2973 | { |
| 2974 | return __tabla_codec_switch_micbias(codec, vddio_switch, true, true); |
| 2975 | } |
| 2976 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2977 | static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2978 | struct snd_kcontrol *kcontrol, int event) |
| 2979 | { |
| 2980 | struct snd_soc_codec *codec = w->codec; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2981 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2982 | u16 micb_int_reg; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2983 | int micb_line; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2984 | u8 cfilt_sel_val = 0; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2985 | char *internal1_text = "Internal1"; |
| 2986 | char *internal2_text = "Internal2"; |
| 2987 | char *internal3_text = "Internal3"; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2988 | const char *micbias1_text = "MIC BIAS1 "; |
| 2989 | const char *micbias2_text = "MIC BIAS2 "; |
| 2990 | const char *micbias3_text = "MIC BIAS3 "; |
| 2991 | const char *micbias4_text = "MIC BIAS4 "; |
| 2992 | u32 *micbias_enable_count; |
| 2993 | u16 wreg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2994 | |
| 2995 | pr_debug("%s %d\n", __func__, event); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 2996 | if (strnstr(w->name, micbias1_text, strlen(micbias1_text))) { |
| 2997 | wreg = TABLA_A_MICB_1_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2998 | micb_int_reg = TABLA_A_MICB_1_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2999 | cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3000 | micb_line = TABLA_MICBIAS1; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3001 | } else if (strnstr(w->name, micbias2_text, strlen(micbias2_text))) { |
| 3002 | wreg = TABLA_A_MICB_2_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3003 | micb_int_reg = TABLA_A_MICB_2_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3004 | cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3005 | micb_line = TABLA_MICBIAS2; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3006 | } else if (strnstr(w->name, micbias3_text, strlen(micbias3_text))) { |
| 3007 | wreg = TABLA_A_MICB_3_CTL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3008 | micb_int_reg = TABLA_A_MICB_3_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3009 | cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3010 | micb_line = TABLA_MICBIAS3; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3011 | } else if (strnstr(w->name, micbias4_text, strlen(micbias4_text))) { |
| 3012 | wreg = tabla->reg_addr.micb_4_ctl; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3013 | micb_int_reg = tabla->reg_addr.micb_4_int_rbias; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3014 | cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3015 | micb_line = TABLA_MICBIAS4; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3016 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3017 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 3018 | return -EINVAL; |
| 3019 | } |
| 3020 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3021 | micbias_enable_count = &tabla->micbias_enable_count[micb_line]; |
| 3022 | pr_debug("%s: counter %d\n", __func__, *micbias_enable_count); |
| 3023 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3024 | switch (event) { |
| 3025 | case SND_SOC_DAPM_PRE_PMU: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3026 | if (++*micbias_enable_count > 1) { |
| 3027 | pr_debug("%s: do nothing, counter %d\n", |
| 3028 | __func__, *micbias_enable_count); |
| 3029 | break; |
| 3030 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3031 | /* Decide whether to switch the micbias for MBHC */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3032 | if (wreg == tabla->mbhc_bias_regs.ctl_reg) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3033 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3034 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3035 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3036 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3037 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3038 | snd_soc_update_bits(codec, wreg, 0x0E, 0x0A); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3039 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3040 | |
| 3041 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3042 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3043 | else if (strnstr(w->name, internal2_text, 30)) |
| 3044 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 3045 | else if (strnstr(w->name, internal3_text, 30)) |
| 3046 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 3047 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3048 | snd_soc_update_bits(codec, wreg, 1 << 7, 1 << 7); |
| 3049 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3050 | break; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3051 | case SND_SOC_DAPM_POST_PMU: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3052 | if (*micbias_enable_count > 1) { |
| 3053 | pr_debug("%s: do nothing, counter %d\n", |
| 3054 | __func__, *micbias_enable_count); |
| 3055 | break; |
| 3056 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3057 | usleep_range(20000, 20000); |
| 3058 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3059 | if (tabla->mbhc_polling_active && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3060 | tabla->mbhc_cfg.micbias == micb_line) { |
| 3061 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3062 | tabla_codec_pause_hs_polling(codec); |
| 3063 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3064 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 3065 | } |
| 3066 | break; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3067 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3068 | case SND_SOC_DAPM_POST_PMD: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3069 | if (--*micbias_enable_count > 0) { |
| 3070 | pr_debug("%s: do nothing, counter %d\n", |
| 3071 | __func__, *micbias_enable_count); |
| 3072 | break; |
| 3073 | } |
| 3074 | |
| 3075 | snd_soc_update_bits(codec, wreg, 1 << 7, 0); |
| 3076 | |
| 3077 | if ((wreg == tabla->mbhc_bias_regs.ctl_reg) && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3078 | tabla_is_hph_pa_on(codec)) { |
| 3079 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3080 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3081 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3082 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3083 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3084 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3085 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3086 | else if (strnstr(w->name, internal2_text, 30)) |
| 3087 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 3088 | else if (strnstr(w->name, internal3_text, 30)) |
| 3089 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 3090 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 3091 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3092 | break; |
| 3093 | } |
| 3094 | |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3098 | |
| 3099 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 3100 | { |
| 3101 | struct delayed_work *hpf_delayed_work; |
| 3102 | struct hpf_work *hpf_work; |
| 3103 | struct tabla_priv *tabla; |
| 3104 | struct snd_soc_codec *codec; |
| 3105 | u16 tx_mux_ctl_reg; |
| 3106 | u8 hpf_cut_of_freq; |
| 3107 | |
| 3108 | hpf_delayed_work = to_delayed_work(work); |
| 3109 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 3110 | tabla = hpf_work->tabla; |
| 3111 | codec = hpf_work->tabla->codec; |
| 3112 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 3113 | |
| 3114 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + |
| 3115 | (hpf_work->decimator - 1) * 8; |
| 3116 | |
| 3117 | pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__, |
| 3118 | hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 3119 | |
| 3120 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 3121 | } |
| 3122 | |
| 3123 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 3124 | #define CF_MIN_3DB_4HZ 0x0 |
| 3125 | #define CF_MIN_3DB_75HZ 0x1 |
| 3126 | #define CF_MIN_3DB_150HZ 0x2 |
| 3127 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3128 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 3129 | struct snd_kcontrol *kcontrol, int event); |
| 3130 | |
| 3131 | static int tabla_codec_enable_micbias_power(struct snd_soc_dapm_widget *w, |
| 3132 | struct snd_kcontrol *kcontrol, |
| 3133 | int event) |
| 3134 | { |
| 3135 | struct snd_soc_codec *codec = w->codec; |
| 3136 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3137 | |
| 3138 | pr_debug("%s %d\n", __func__, event); |
| 3139 | |
| 3140 | switch (event) { |
| 3141 | case SND_SOC_DAPM_PRE_PMU: |
| 3142 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, true); |
| 3143 | tabla_codec_enable_ldo_h(w, kcontrol, event); |
| 3144 | tabla_codec_enable_micbias(w, kcontrol, event); |
| 3145 | break; |
| 3146 | case SND_SOC_DAPM_POST_PMU: |
| 3147 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, true); |
| 3148 | break; |
| 3149 | case SND_SOC_DAPM_POST_PMD: |
| 3150 | tabla_codec_enable_micbias(w, kcontrol, event); |
| 3151 | tabla_codec_enable_ldo_h(w, kcontrol, event); |
| 3152 | break; |
| 3153 | } |
| 3154 | return 0; |
| 3155 | } |
| 3156 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3157 | static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 3158 | struct snd_kcontrol *kcontrol, int event) |
| 3159 | { |
| 3160 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3161 | unsigned int decimator; |
| 3162 | char *dec_name = NULL; |
| 3163 | char *widget_name = NULL; |
| 3164 | char *temp; |
| 3165 | int ret = 0; |
| 3166 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 3167 | u8 dec_hpf_cut_of_freq; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3168 | int offset; |
| 3169 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3170 | |
| 3171 | pr_debug("%s %d\n", __func__, event); |
| 3172 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3173 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 3174 | if (!widget_name) |
| 3175 | return -ENOMEM; |
| 3176 | temp = widget_name; |
| 3177 | |
| 3178 | dec_name = strsep(&widget_name, " "); |
| 3179 | widget_name = temp; |
| 3180 | if (!dec_name) { |
| 3181 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 3182 | ret = -EINVAL; |
| 3183 | goto out; |
| 3184 | } |
| 3185 | |
| 3186 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 3187 | if (ret < 0) { |
| 3188 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 3189 | ret = -EINVAL; |
| 3190 | goto out; |
| 3191 | } |
| 3192 | |
| 3193 | pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__, |
| 3194 | w->name, dec_name, decimator); |
| 3195 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3196 | if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3197 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3198 | offset = 0; |
| 3199 | } 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] | 3200 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3201 | offset = 8; |
| 3202 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3203 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 3204 | return -EINVAL; |
| 3205 | } |
| 3206 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3207 | tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1); |
| 3208 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 3209 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3210 | switch (event) { |
| 3211 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3212 | |
| 3213 | // Enableable TX digital mute */ |
| 3214 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3215 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3216 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 3217 | 1 << w->shift); |
| 3218 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3219 | |
| 3220 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 3221 | |
| 3222 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 3223 | |
| 3224 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 3225 | dec_hpf_cut_of_freq; |
| 3226 | |
| 3227 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 3228 | |
| 3229 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 3230 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3231 | CF_MIN_3DB_150HZ << 4); |
| 3232 | } |
| 3233 | |
| 3234 | /* enable HPF */ |
| 3235 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 3236 | |
| 3237 | break; |
| 3238 | |
| 3239 | case SND_SOC_DAPM_POST_PMU: |
| 3240 | |
| 3241 | /* Disable TX digital mute */ |
| 3242 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 3243 | |
| 3244 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 3245 | CF_MIN_3DB_150HZ) { |
| 3246 | |
| 3247 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 3248 | msecs_to_jiffies(300)); |
| 3249 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3250 | /* apply the digital gain after the decimator is enabled*/ |
Damir Didjusto | ed406e2 | 2012-11-16 15:44:57 -0800 | [diff] [blame] | 3251 | if ((w->shift + offset) < ARRAY_SIZE(tx_digital_gain_reg)) |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3252 | snd_soc_write(codec, |
| 3253 | tx_digital_gain_reg[w->shift + offset], |
| 3254 | snd_soc_read(codec, |
| 3255 | tx_digital_gain_reg[w->shift + offset]) |
| 3256 | ); |
| 3257 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3258 | break; |
| 3259 | |
| 3260 | case SND_SOC_DAPM_PRE_PMD: |
| 3261 | |
| 3262 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3263 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 3264 | break; |
| 3265 | |
| 3266 | case SND_SOC_DAPM_POST_PMD: |
| 3267 | |
| 3268 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 3269 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3270 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 3271 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3272 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3273 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3274 | out: |
| 3275 | kfree(widget_name); |
| 3276 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3277 | } |
| 3278 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3279 | static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3280 | struct snd_kcontrol *kcontrol, int event) |
| 3281 | { |
| 3282 | struct snd_soc_codec *codec = w->codec; |
| 3283 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3284 | pr_debug("%s %d %s\n", __func__, event, w->name); |
| 3285 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3286 | switch (event) { |
| 3287 | case SND_SOC_DAPM_PRE_PMU: |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3288 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3289 | 1 << w->shift, 1 << w->shift); |
| 3290 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3291 | 1 << w->shift, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3292 | break; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3293 | case SND_SOC_DAPM_POST_PMU: |
| 3294 | /* apply the digital gain after the interpolator is enabled*/ |
| 3295 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 3296 | snd_soc_write(codec, |
| 3297 | rx_digital_gain_reg[w->shift], |
| 3298 | snd_soc_read(codec, |
| 3299 | rx_digital_gain_reg[w->shift]) |
| 3300 | ); |
| 3301 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3302 | } |
| 3303 | return 0; |
| 3304 | } |
| 3305 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3306 | static void tabla_enable_ldo_h(struct snd_soc_codec *codec, u32 enable) |
| 3307 | { |
| 3308 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3309 | |
| 3310 | if (enable) { |
| 3311 | if (++tabla->ldo_h_count == 1) |
| 3312 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, |
| 3313 | 0x80, 0x80); |
| 3314 | } else { |
| 3315 | if (--tabla->ldo_h_count == 0) |
| 3316 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, |
| 3317 | 0x80, 0x00); |
| 3318 | } |
| 3319 | } |
| 3320 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3321 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 3322 | struct snd_kcontrol *kcontrol, int event) |
| 3323 | { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3324 | struct snd_soc_codec *codec = w->codec; |
| 3325 | |
| 3326 | pr_debug("%s %d\n", __func__, event); |
| 3327 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3328 | switch (event) { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3329 | case SND_SOC_DAPM_PRE_PMU: |
| 3330 | tabla_enable_ldo_h(codec, 1); |
| 3331 | usleep_range(1000, 1000); |
| 3332 | break; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3333 | case SND_SOC_DAPM_POST_PMD: |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3334 | tabla_enable_ldo_h(codec, 0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3335 | usleep_range(1000, 1000); |
| 3336 | break; |
| 3337 | } |
| 3338 | return 0; |
| 3339 | } |
| 3340 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3341 | static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 3342 | struct snd_kcontrol *kcontrol, int event) |
| 3343 | { |
| 3344 | struct snd_soc_codec *codec = w->codec; |
| 3345 | |
| 3346 | pr_debug("%s %d\n", __func__, event); |
| 3347 | |
| 3348 | switch (event) { |
| 3349 | case SND_SOC_DAPM_PRE_PMU: |
| 3350 | tabla_enable_rx_bias(codec, 1); |
| 3351 | break; |
| 3352 | case SND_SOC_DAPM_POST_PMD: |
| 3353 | tabla_enable_rx_bias(codec, 0); |
| 3354 | break; |
| 3355 | } |
| 3356 | return 0; |
| 3357 | } |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3358 | static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 3359 | struct snd_kcontrol *kcontrol, int event) |
| 3360 | { |
| 3361 | struct snd_soc_codec *codec = w->codec; |
| 3362 | |
| 3363 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3364 | |
| 3365 | switch (event) { |
| 3366 | case SND_SOC_DAPM_PRE_PMU: |
| 3367 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3368 | break; |
| 3369 | case SND_SOC_DAPM_POST_PMD: |
| 3370 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3371 | break; |
| 3372 | } |
| 3373 | return 0; |
| 3374 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3375 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3376 | static void tabla_snd_soc_jack_report(struct tabla_priv *tabla, |
| 3377 | struct snd_soc_jack *jack, int status, |
| 3378 | int mask) |
| 3379 | { |
| 3380 | /* XXX: wake_lock_timeout()? */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3381 | snd_soc_jack_report_no_dapm(jack, status, mask); |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3382 | } |
| 3383 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3384 | static void hphocp_off_report(struct tabla_priv *tabla, |
| 3385 | u32 jack_status, int irq) |
| 3386 | { |
| 3387 | struct snd_soc_codec *codec; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3388 | if (!tabla) { |
| 3389 | pr_err("%s: Bad tabla private data\n", __func__); |
| 3390 | return; |
| 3391 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3392 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3393 | pr_debug("%s: clear ocp status %x\n", __func__, jack_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3394 | codec = tabla->codec; |
| 3395 | if (tabla->hph_status & jack_status) { |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3396 | tabla->hph_status &= ~jack_status; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3397 | if (tabla->mbhc_cfg.headset_jack) |
| 3398 | tabla_snd_soc_jack_report(tabla, |
| 3399 | tabla->mbhc_cfg.headset_jack, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3400 | tabla->hph_status, |
| 3401 | TABLA_JACK_MASK); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3402 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 3403 | 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] | 3404 | /* reset retry counter as PA is turned off signifying |
| 3405 | * start of new OCP detection session |
| 3406 | */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3407 | if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 3408 | tabla->hphlocp_cnt = 0; |
| 3409 | else |
| 3410 | tabla->hphrocp_cnt = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3411 | wcd9xxx_enable_irq(codec->control_data, irq); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | static void hphlocp_off_report(struct work_struct *work) |
| 3416 | { |
| 3417 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3418 | hphlocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3419 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
| 3420 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
| 3423 | static void hphrocp_off_report(struct work_struct *work) |
| 3424 | { |
| 3425 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3426 | hphrocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3427 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
| 3428 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3429 | } |
| 3430 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3431 | static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 3432 | struct snd_kcontrol *kcontrol, int event) |
| 3433 | { |
| 3434 | struct snd_soc_codec *codec = w->codec; |
| 3435 | const char *filename; |
| 3436 | const struct firmware *fw; |
| 3437 | int i; |
| 3438 | int ret; |
| 3439 | int num_anc_slots; |
| 3440 | struct anc_header *anc_head; |
| 3441 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3442 | u32 anc_writes_size = 0; |
| 3443 | int anc_size_remaining; |
| 3444 | u32 *anc_ptr; |
| 3445 | u16 reg; |
| 3446 | u8 mask, val, old_val; |
| 3447 | u8 mbhc_micb_ctl_val; |
| 3448 | |
| 3449 | pr_debug("%s: DAPM Event %d ANC func is %d\n", |
| 3450 | __func__, event, tabla->anc_func); |
| 3451 | |
| 3452 | if (tabla->anc_func == 0) |
| 3453 | return 0; |
| 3454 | |
| 3455 | switch (event) { |
| 3456 | case SND_SOC_DAPM_PRE_PMU: |
| 3457 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 3458 | tabla->mbhc_bias_regs.ctl_reg); |
| 3459 | |
| 3460 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 3461 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3462 | tabla_codec_switch_micbias(codec, 1); |
| 3463 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3464 | } |
| 3465 | |
| 3466 | filename = "wcd9310/wcd9310_anc.bin"; |
| 3467 | |
| 3468 | ret = request_firmware(&fw, filename, codec->dev); |
| 3469 | if (ret != 0) { |
| 3470 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 3471 | ret); |
| 3472 | return -ENODEV; |
| 3473 | } |
| 3474 | |
| 3475 | if (fw->size < sizeof(struct anc_header)) { |
| 3476 | dev_err(codec->dev, "Not enough data\n"); |
| 3477 | release_firmware(fw); |
| 3478 | return -ENOMEM; |
| 3479 | } |
| 3480 | |
| 3481 | /* First number is the number of register writes */ |
| 3482 | anc_head = (struct anc_header *)(fw->data); |
| 3483 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 3484 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 3485 | num_anc_slots = anc_head->num_anc_slots; |
| 3486 | |
| 3487 | if (tabla->anc_slot >= num_anc_slots) { |
| 3488 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 3489 | release_firmware(fw); |
| 3490 | return -EINVAL; |
| 3491 | } |
| 3492 | |
| 3493 | for (i = 0; i < num_anc_slots; i++) { |
| 3494 | |
| 3495 | if (anc_size_remaining < TABLA_PACKED_REG_SIZE) { |
| 3496 | dev_err(codec->dev, "Invalid register format\n"); |
| 3497 | release_firmware(fw); |
| 3498 | return -EINVAL; |
| 3499 | } |
| 3500 | anc_writes_size = (u32)(*anc_ptr); |
| 3501 | anc_size_remaining -= sizeof(u32); |
| 3502 | anc_ptr += 1; |
| 3503 | |
| 3504 | if (anc_writes_size * TABLA_PACKED_REG_SIZE |
| 3505 | > anc_size_remaining) { |
| 3506 | dev_err(codec->dev, "Invalid register format\n"); |
| 3507 | release_firmware(fw); |
| 3508 | return -ENOMEM; |
| 3509 | } |
| 3510 | |
| 3511 | if (tabla->anc_slot == i) |
| 3512 | break; |
| 3513 | |
| 3514 | anc_size_remaining -= (anc_writes_size * |
| 3515 | TABLA_PACKED_REG_SIZE); |
| 3516 | anc_ptr += anc_writes_size; |
| 3517 | } |
| 3518 | if (i == num_anc_slots) { |
| 3519 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
| 3520 | release_firmware(fw); |
| 3521 | return -ENOMEM; |
| 3522 | } |
| 3523 | |
| 3524 | for (i = 0; i < anc_writes_size; i++) { |
| 3525 | TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
| 3526 | mask, val); |
| 3527 | old_val = snd_soc_read(codec, reg); |
| 3528 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 3529 | (val & mask)); |
| 3530 | } |
| 3531 | usleep_range(10000, 10000); |
| 3532 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x30); |
| 3533 | msleep(30); |
| 3534 | release_firmware(fw); |
| 3535 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3536 | /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */ |
| 3537 | if (tabla->mbhc_polling_active) |
| 3538 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, |
| 3539 | 0x80); |
| 3540 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3541 | break; |
| 3542 | case SND_SOC_DAPM_POST_PMD: |
| 3543 | /* schedule work is required because at the time HPH PA DAPM |
| 3544 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 3545 | * would have been locked while snd_soc_jack_report also |
| 3546 | * attempts to acquire same lock. |
| 3547 | */ |
| 3548 | if (w->shift == 5) { |
| 3549 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 3550 | &tabla->hph_pa_dac_state); |
| 3551 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 3552 | &tabla->hph_pa_dac_state); |
| 3553 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 3554 | schedule_work(&tabla->hphlocp_work); |
| 3555 | } else if (w->shift == 4) { |
| 3556 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 3557 | &tabla->hph_pa_dac_state); |
| 3558 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 3559 | &tabla->hph_pa_dac_state); |
| 3560 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 3561 | schedule_work(&tabla->hphrocp_work); |
| 3562 | } |
| 3563 | |
| 3564 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 3565 | tabla_codec_switch_micbias(codec, 0); |
| 3566 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3567 | |
| 3568 | break; |
| 3569 | case SND_SOC_DAPM_PRE_PMD: |
| 3570 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 3571 | msleep(40); |
| 3572 | /* unset TX7_MBHC_EN bit 7 */ |
| 3573 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00); |
| 3574 | snd_soc_update_bits(codec, TABLA_A_CDC_ANC1_CTL, 0x01, 0x00); |
| 3575 | snd_soc_update_bits(codec, TABLA_A_CDC_ANC2_CTL, 0x01, 0x00); |
| 3576 | msleep(20); |
| 3577 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0x0F); |
| 3578 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
| 3579 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 3580 | break; |
| 3581 | } |
| 3582 | return 0; |
| 3583 | } |
| 3584 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3585 | static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 3586 | struct snd_kcontrol *kcontrol, int event) |
| 3587 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3588 | struct snd_soc_codec *codec = w->codec; |
| 3589 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3590 | u8 mbhc_micb_ctl_val; |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3591 | pr_debug("%s: event = %d\n", __func__, event); |
| 3592 | |
| 3593 | switch (event) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3594 | case SND_SOC_DAPM_PRE_PMU: |
| 3595 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 3596 | tabla->mbhc_bias_regs.ctl_reg); |
| 3597 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3598 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 3599 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3600 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3601 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3602 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3603 | break; |
| 3604 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3605 | case SND_SOC_DAPM_POST_PMD: |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3606 | /* schedule work is required because at the time HPH PA DAPM |
| 3607 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 3608 | * would have been locked while snd_soc_jack_report also |
| 3609 | * attempts to acquire same lock. |
| 3610 | */ |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 3611 | if (w->shift == 5) { |
| 3612 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 3613 | &tabla->hph_pa_dac_state); |
| 3614 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 3615 | &tabla->hph_pa_dac_state); |
| 3616 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 3617 | schedule_work(&tabla->hphlocp_work); |
| 3618 | } else if (w->shift == 4) { |
| 3619 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 3620 | &tabla->hph_pa_dac_state); |
| 3621 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 3622 | &tabla->hph_pa_dac_state); |
| 3623 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 3624 | schedule_work(&tabla->hphrocp_work); |
| 3625 | } |
| 3626 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3627 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3628 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3629 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3630 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3631 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 3632 | w->name); |
| 3633 | usleep_range(10000, 10000); |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3634 | break; |
| 3635 | } |
| 3636 | return 0; |
| 3637 | } |
| 3638 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3639 | static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3640 | struct mbhc_micbias_regs *micbias_regs) |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3641 | { |
| 3642 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3643 | unsigned int cfilt; |
| 3644 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3645 | switch (tabla->mbhc_cfg.micbias) { |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3646 | case TABLA_MICBIAS1: |
| 3647 | cfilt = tabla->pdata->micbias.bias1_cfilt_sel; |
| 3648 | micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC; |
| 3649 | micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS; |
| 3650 | micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL; |
| 3651 | break; |
| 3652 | case TABLA_MICBIAS2: |
| 3653 | cfilt = tabla->pdata->micbias.bias2_cfilt_sel; |
| 3654 | micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC; |
| 3655 | micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS; |
| 3656 | micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL; |
| 3657 | break; |
| 3658 | case TABLA_MICBIAS3: |
| 3659 | cfilt = tabla->pdata->micbias.bias3_cfilt_sel; |
| 3660 | micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC; |
| 3661 | micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS; |
| 3662 | micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL; |
| 3663 | break; |
| 3664 | case TABLA_MICBIAS4: |
| 3665 | cfilt = tabla->pdata->micbias.bias4_cfilt_sel; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3666 | micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc; |
| 3667 | micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias; |
| 3668 | micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3669 | break; |
| 3670 | default: |
| 3671 | /* Should never reach here */ |
| 3672 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
Jordan Crouse | 239d841 | 2011-11-23 11:47:02 -0700 | [diff] [blame] | 3673 | return; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 3676 | micbias_regs->cfilt_sel = cfilt; |
| 3677 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3678 | switch (cfilt) { |
| 3679 | case TABLA_CFILT1_SEL: |
| 3680 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL; |
| 3681 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3682 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3683 | break; |
| 3684 | case TABLA_CFILT2_SEL: |
| 3685 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL; |
| 3686 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3687 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3688 | break; |
| 3689 | case TABLA_CFILT3_SEL: |
| 3690 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL; |
| 3691 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3692 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3693 | break; |
| 3694 | } |
| 3695 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3696 | static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = { |
| 3697 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3698 | 4, 0, NULL, 0), |
| 3699 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4, |
| 3700 | 0, NULL, 0), |
| 3701 | }; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3702 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3703 | static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 3704 | struct snd_kcontrol *kcontrol, int event) |
| 3705 | { |
| 3706 | struct snd_soc_codec *codec = w->codec; |
| 3707 | |
| 3708 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3709 | |
| 3710 | switch (event) { |
| 3711 | case SND_SOC_DAPM_PRE_PMU: |
| 3712 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3713 | break; |
| 3714 | |
| 3715 | case SND_SOC_DAPM_POST_PMD: |
| 3716 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3717 | break; |
| 3718 | } |
| 3719 | return 0; |
| 3720 | } |
| 3721 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 3722 | static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w, |
| 3723 | struct snd_kcontrol *kcontrol, int event) |
| 3724 | { |
| 3725 | struct snd_soc_codec *codec = w->codec; |
| 3726 | |
| 3727 | pr_debug("%s %d\n", __func__, event); |
| 3728 | |
| 3729 | switch (event) { |
| 3730 | case SND_SOC_DAPM_PRE_PMU: |
| 3731 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50); |
| 3732 | break; |
| 3733 | |
| 3734 | case SND_SOC_DAPM_PRE_PMD: |
| 3735 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00); |
| 3736 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00); |
| 3737 | break; |
| 3738 | } |
| 3739 | return 0; |
| 3740 | } |
| 3741 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3742 | static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3743 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3744 | 0, tabla_codec_enable_micbias, |
| 3745 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3746 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3747 | }; |
| 3748 | |
| 3749 | static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = { |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 3750 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", SND_SOC_NOPM, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3751 | 0, tabla_codec_enable_micbias, |
| 3752 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3753 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3754 | }; |
| 3755 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3756 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 3757 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 3758 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 3759 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 3760 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 3761 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 3762 | |
| 3763 | {"SLIM TX7", NULL, "TX_I2S_CLK"}, |
| 3764 | {"SLIM TX8", NULL, "TX_I2S_CLK"}, |
| 3765 | {"SLIM TX9", NULL, "TX_I2S_CLK"}, |
| 3766 | {"SLIM TX10", NULL, "TX_I2S_CLK"}, |
| 3767 | }; |
| 3768 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3769 | static const struct snd_soc_dapm_route audio_map[] = { |
| 3770 | /* SLIMBUS Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3771 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3772 | {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, |
| 3773 | {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, |
| 3774 | {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3775 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3776 | /* SLIM_MIXER("AIF1_CAP Mixer"),*/ |
| 3777 | {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3778 | {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3779 | {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3780 | {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3781 | {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3782 | {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3783 | {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3784 | {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3785 | {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3786 | {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3787 | /* SLIM_MIXER("AIF2_CAP Mixer"),*/ |
| 3788 | {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3789 | {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3790 | {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3791 | {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3792 | {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3793 | {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3794 | {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3795 | {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3796 | {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3797 | {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3798 | /* SLIM_MIXER("AIF3_CAP Mixer"),*/ |
| 3799 | {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3800 | {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3801 | {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3802 | {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3803 | {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3804 | {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3805 | {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3806 | {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3807 | {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3808 | {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3809 | |
| 3810 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3811 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 3812 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3813 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3814 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 3815 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 3816 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 3817 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
| 3818 | {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"}, |
| 3819 | {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"}, |
| 3820 | {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3821 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3822 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
| 3823 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3824 | {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3825 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 3826 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 3827 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 3828 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
| 3829 | {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"}, |
| 3830 | {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"}, |
| 3831 | {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3832 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3833 | {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"}, |
| 3834 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3835 | {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3836 | {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3837 | {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"}, |
| 3838 | {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3839 | {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"}, |
| 3840 | {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3841 | {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"}, |
| 3842 | {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3843 | {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"}, |
| 3844 | {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3845 | {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"}, |
| 3846 | {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"}, |
| 3847 | {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"}, |
| 3848 | {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"}, |
| 3849 | {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"}, |
| 3850 | {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"}, |
| 3851 | {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3852 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3853 | {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"}, |
| 3854 | {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"}, |
| 3855 | {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | 9ec83cd | 2011-09-23 17:25:07 -0700 | [diff] [blame] | 3856 | {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3857 | {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"}, |
| 3858 | {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3859 | {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"}, |
| 3860 | {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"}, |
| 3861 | {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"}, |
| 3862 | {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3863 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3864 | {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"}, |
| 3865 | {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"}, |
| 3866 | {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"}, |
| 3867 | {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"}, |
| 3868 | {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"}, |
| 3869 | {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"}, |
| 3870 | {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"}, |
| 3871 | {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"}, |
| 3872 | {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"}, |
| 3873 | {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"}, |
| 3874 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3875 | {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"}, |
| 3876 | {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"}, |
| 3877 | {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"}, |
| 3878 | {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"}, |
| 3879 | {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"}, |
| 3880 | {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"}, |
| 3881 | {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"}, |
| 3882 | {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"}, |
| 3883 | {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"}, |
| 3884 | {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"}, |
| 3885 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3886 | /* Earpiece (RX MIX1) */ |
| 3887 | {"EAR", NULL, "EAR PA"}, |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3888 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 3889 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3890 | {"DAC1", NULL, "CP"}, |
| 3891 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3892 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 3893 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3894 | |
| 3895 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3896 | {"HEADPHONE", NULL, "HPHL"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3897 | {"HEADPHONE", NULL, "HPHR"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3898 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3899 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3900 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3901 | |
| 3902 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3903 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3904 | |
| 3905 | {"HPHL DAC", NULL, "CP"}, |
| 3906 | {"HPHR DAC", NULL, "CP"}, |
| 3907 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3908 | {"ANC HEADPHONE", NULL, "ANC HPHL"}, |
| 3909 | {"ANC HEADPHONE", NULL, "ANC HPHR"}, |
| 3910 | |
| 3911 | {"ANC HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3912 | {"ANC HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3913 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3914 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 3915 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 3916 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 3917 | {"ANC1 MUX", "ADC4", "ADC4"}, |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3918 | {"ANC1 MUX", "DMIC1", "DMIC1"}, |
| 3919 | {"ANC1 MUX", "DMIC2", "DMIC2"}, |
| 3920 | {"ANC1 MUX", "DMIC3", "DMIC3"}, |
| 3921 | {"ANC1 MUX", "DMIC4", "DMIC4"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3922 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 3923 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 3924 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 3925 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 3926 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3927 | {"ANC HPHR", NULL, "CDC_CONN"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3928 | {"DAC1", "Switch", "RX1 CHAIN"}, |
| 3929 | {"HPHL DAC", "Switch", "RX1 CHAIN"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3930 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3931 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 3932 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3933 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 3934 | {"LINEOUT3", NULL, "LINEOUT3 PA"}, |
| 3935 | {"LINEOUT4", NULL, "LINEOUT4 PA"}, |
| 3936 | {"LINEOUT5", NULL, "LINEOUT5 PA"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3937 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3938 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3939 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 3940 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3941 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3942 | {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"}, |
| 3943 | {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"}, |
| 3944 | {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"}, |
| 3945 | {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"}, |
| 3946 | {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"}, |
| 3947 | {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3948 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3949 | {"LINEOUT1 DAC", NULL, "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3950 | {"LINEOUT5 DAC", NULL, "RX7 MIX1"}, |
| 3951 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3952 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3953 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 3954 | {"RX1 MIX2", NULL, "ANC1 MUX"}, |
| 3955 | {"RX2 MIX2", NULL, "ANC2 MUX"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3956 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3957 | {"CP", NULL, "RX_BIAS"}, |
| 3958 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3959 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
| 3960 | {"LINEOUT3 DAC", NULL, "RX_BIAS"}, |
| 3961 | {"LINEOUT4 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3962 | {"LINEOUT5 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3963 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3964 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 3965 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 3966 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 3967 | {"RX5 MIX1", NULL, "COMP2_CLK"}, |
| 3968 | |
| 3969 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3970 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3971 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3972 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3973 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3974 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3975 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3976 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 3977 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 3978 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 3979 | {"RX5 MIX1", NULL, "RX5 MIX1 INP1"}, |
| 3980 | {"RX5 MIX1", NULL, "RX5 MIX1 INP2"}, |
| 3981 | {"RX6 MIX1", NULL, "RX6 MIX1 INP1"}, |
| 3982 | {"RX6 MIX1", NULL, "RX6 MIX1 INP2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3983 | {"RX7 MIX1", NULL, "RX7 MIX1 INP1"}, |
| 3984 | {"RX7 MIX1", NULL, "RX7 MIX1 INP2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3985 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3986 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3987 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3988 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3989 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3990 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
| 3991 | {"RX3 MIX2", NULL, "RX3 MIX1"}, |
| 3992 | {"RX3 MIX2", NULL, "RX3 MIX2 INP1"}, |
| 3993 | {"RX3 MIX2", NULL, "RX3 MIX2 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3994 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3995 | /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/ |
| 3996 | {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3997 | {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3998 | {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3999 | {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, |
| 4000 | {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, |
| 4001 | {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"}, |
| 4002 | {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"}, |
| 4003 | /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/ |
| 4004 | {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4005 | {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4006 | {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4007 | {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4008 | {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4009 | {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4010 | {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"}, |
| 4011 | /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/ |
| 4012 | {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4013 | {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4014 | {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4015 | {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4016 | {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4017 | {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4018 | {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"}, |
| 4019 | |
| 4020 | {"SLIM RX1", NULL, "SLIM RX1 MUX"}, |
| 4021 | {"SLIM RX2", NULL, "SLIM RX2 MUX"}, |
| 4022 | {"SLIM RX3", NULL, "SLIM RX3 MUX"}, |
| 4023 | {"SLIM RX4", NULL, "SLIM RX4 MUX"}, |
| 4024 | {"SLIM RX5", NULL, "SLIM RX5 MUX"}, |
| 4025 | {"SLIM RX6", NULL, "SLIM RX6 MUX"}, |
| 4026 | {"SLIM RX7", NULL, "SLIM RX7 MUX"}, |
| 4027 | |
| 4028 | /* Mixer control for output path */ |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4029 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4030 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4031 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4032 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4033 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4034 | {"RX1 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4035 | {"RX1 MIX1 INP1", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4036 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4037 | {"RX1 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4038 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4039 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4040 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4041 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4042 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4043 | {"RX1 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4044 | {"RX1 MIX1 INP2", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4045 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4046 | {"RX1 MIX1 INP2", "IIR2", "IIR2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4047 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 4048 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 4049 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 4050 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 4051 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
| 4052 | {"RX1 MIX1 INP3", "RX6", "SLIM RX6"}, |
| 4053 | {"RX1 MIX1 INP3", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4054 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4055 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4056 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4057 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4058 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4059 | {"RX2 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4060 | {"RX2 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4061 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4062 | {"RX2 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4063 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4064 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4065 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4066 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4067 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4068 | {"RX2 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4069 | {"RX2 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4070 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4071 | {"RX2 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4072 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4073 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4074 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4075 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4076 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4077 | {"RX3 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4078 | {"RX3 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4079 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4080 | {"RX3 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4081 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4082 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4083 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4084 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4085 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4086 | {"RX3 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4087 | {"RX3 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4088 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4089 | {"RX3 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4090 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4091 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4092 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4093 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4094 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4095 | {"RX4 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4096 | {"RX4 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4097 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4098 | {"RX4 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4099 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4100 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4101 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4102 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4103 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4104 | {"RX4 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4105 | {"RX4 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4106 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4107 | {"RX4 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4108 | {"RX5 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4109 | {"RX5 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4110 | {"RX5 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4111 | {"RX5 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4112 | {"RX5 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4113 | {"RX5 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4114 | {"RX5 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4115 | {"RX5 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4116 | {"RX5 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4117 | {"RX5 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4118 | {"RX5 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4119 | {"RX5 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4120 | {"RX5 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4121 | {"RX5 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4122 | {"RX5 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4123 | {"RX5 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4124 | {"RX5 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4125 | {"RX5 MIX1 INP2", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4126 | {"RX6 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4127 | {"RX6 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4128 | {"RX6 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4129 | {"RX6 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4130 | {"RX6 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4131 | {"RX6 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4132 | {"RX6 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4133 | {"RX6 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4134 | {"RX6 MIX1 INP1", "IIR2", "IIR2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4135 | {"RX6 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4136 | {"RX6 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4137 | {"RX6 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4138 | {"RX6 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4139 | {"RX6 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4140 | {"RX6 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4141 | {"RX6 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4142 | {"RX6 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4143 | {"RX6 MIX1 INP2", "IIR2", "IIR2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 4144 | {"RX7 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 4145 | {"RX7 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4146 | {"RX7 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 4147 | {"RX7 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4148 | {"RX7 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4149 | {"RX7 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 4150 | {"RX7 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4151 | {"RX7 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4152 | {"RX7 MIX1 INP1", "IIR2", "IIR2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 4153 | {"RX7 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 4154 | {"RX7 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4155 | {"RX7 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 4156 | {"RX7 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4157 | {"RX7 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4158 | {"RX7 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 4159 | {"RX7 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4160 | {"RX7 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4161 | {"RX7 MIX1 INP2", "IIR2", "IIR2"}, |
| 4162 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4163 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4164 | {"RX1 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4165 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4166 | {"RX1 MIX2 INP2", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4167 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4168 | {"RX2 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4169 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4170 | {"RX2 MIX2 INP2", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4171 | {"RX3 MIX2 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4172 | {"RX3 MIX2 INP1", "IIR2", "IIR2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4173 | {"RX3 MIX2 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4174 | {"RX3 MIX2 INP2", "IIR2", "IIR2"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4175 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4176 | /* Decimator Inputs */ |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4177 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4178 | {"DEC1 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4179 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4180 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4181 | {"DEC2 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4182 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4183 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4184 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4185 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4186 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4187 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4188 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4189 | {"DEC5 MUX", "DMIC5", "DMIC5"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4190 | {"DEC5 MUX", "ADC2", "ADC2"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4191 | {"DEC5 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 4192 | {"DEC6 MUX", "DMIC6", "DMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4193 | {"DEC6 MUX", "ADC1", "ADC1"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4194 | {"DEC6 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4195 | {"DEC7 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4196 | {"DEC7 MUX", "DMIC6", "DMIC6"}, |
| 4197 | {"DEC7 MUX", "ADC1", "ADC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 4198 | {"DEC7 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4199 | {"DEC7 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4200 | {"DEC8 MUX", "DMIC2", "DMIC2"}, |
| 4201 | {"DEC8 MUX", "DMIC5", "DMIC5"}, |
| 4202 | {"DEC8 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4203 | {"DEC8 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4204 | {"DEC8 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4205 | {"DEC9 MUX", "DMIC4", "DMIC4"}, |
| 4206 | {"DEC9 MUX", "DMIC5", "DMIC5"}, |
| 4207 | {"DEC9 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4208 | {"DEC9 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4209 | {"DEC9 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4210 | {"DEC10 MUX", "DMIC3", "DMIC3"}, |
| 4211 | {"DEC10 MUX", "DMIC6", "DMIC6"}, |
| 4212 | {"DEC10 MUX", "ADC1", "ADC1"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4213 | {"DEC10 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 4214 | {"DEC10 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4215 | |
| 4216 | /* ADC Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4217 | {"ADC1", NULL, "AMIC1"}, |
| 4218 | {"ADC2", NULL, "AMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 4219 | {"ADC3", NULL, "AMIC3"}, |
| 4220 | {"ADC4", NULL, "AMIC4"}, |
| 4221 | {"ADC5", NULL, "AMIC5"}, |
| 4222 | {"ADC6", NULL, "AMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4223 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 4224 | /* AUX PGA Connections */ |
| 4225 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4226 | {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4227 | {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4228 | {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4229 | {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4230 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4231 | {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4232 | {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4233 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4234 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4235 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4236 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4237 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4238 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4239 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4240 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4241 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4242 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4243 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4244 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4245 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4246 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4247 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4248 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4249 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4250 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4251 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4252 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4253 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 4254 | {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 4255 | {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 4256 | {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 4257 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 4258 | {"AUX_PGA_Right", NULL, "AMIC6"}, |
| 4259 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4260 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4261 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 4262 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 4263 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 4264 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 4265 | {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4266 | {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 4267 | {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 4268 | {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 4269 | {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 4270 | {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4271 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 4272 | {"IIR2", NULL, "IIR2 INP1 MUX"}, |
| 4273 | {"IIR2 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 4274 | {"IIR2 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 4275 | {"IIR2 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 4276 | {"IIR2 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 4277 | {"IIR2 INP1 MUX", "DEC5", "DEC5 MUX"}, |
| 4278 | {"IIR2 INP1 MUX", "DEC6", "DEC6 MUX"}, |
| 4279 | {"IIR2 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 4280 | {"IIR2 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 4281 | {"IIR2 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 4282 | {"IIR2 INP1 MUX", "DEC10", "DEC10 MUX"}, |
| 4283 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 4284 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 4285 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 4286 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 4287 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 4288 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 4289 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 4290 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 4291 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 4292 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 4293 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 4294 | {"MIC BIAS4 External", NULL, "LDO_H"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4295 | }; |
| 4296 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4297 | static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = { |
| 4298 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4299 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4300 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 4301 | |
| 4302 | {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"}, |
| 4303 | |
| 4304 | {"LINEOUT3 DAC", NULL, "RX5 MIX1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4305 | {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 4306 | {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"}, |
| 4307 | |
| 4308 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 4309 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 4310 | |
| 4311 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 4312 | {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"}, |
| 4313 | {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"}, |
| 4314 | }; |
| 4315 | |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 4316 | |
| 4317 | static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = { |
| 4318 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 4319 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 4320 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 4321 | |
| 4322 | {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"}, |
| 4323 | |
| 4324 | {"LINEOUT2 DAC", NULL, "RX5 MIX1"}, |
| 4325 | |
| 4326 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 4327 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 4328 | |
| 4329 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 4330 | }; |
| 4331 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4332 | static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 4333 | { |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 4334 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4335 | struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 4336 | |
| 4337 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 4338 | for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) { |
| 4339 | if (tabla_1_reg_readable[i] == reg) |
| 4340 | return 1; |
| 4341 | } |
| 4342 | } else { |
| 4343 | for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) { |
| 4344 | if (tabla_2_reg_readable[i] == reg) |
| 4345 | return 1; |
| 4346 | } |
| 4347 | } |
| 4348 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4349 | return tabla_reg_readable[reg]; |
| 4350 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4351 | static bool tabla_is_digital_gain_register(unsigned int reg) |
| 4352 | { |
| 4353 | bool rtn = false; |
| 4354 | switch (reg) { |
| 4355 | case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 4356 | case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 4357 | case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 4358 | case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 4359 | case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL: |
| 4360 | case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL: |
| 4361 | case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL: |
| 4362 | case TABLA_A_CDC_TX1_VOL_CTL_GAIN: |
| 4363 | case TABLA_A_CDC_TX2_VOL_CTL_GAIN: |
| 4364 | case TABLA_A_CDC_TX3_VOL_CTL_GAIN: |
| 4365 | case TABLA_A_CDC_TX4_VOL_CTL_GAIN: |
| 4366 | case TABLA_A_CDC_TX5_VOL_CTL_GAIN: |
| 4367 | case TABLA_A_CDC_TX6_VOL_CTL_GAIN: |
| 4368 | case TABLA_A_CDC_TX7_VOL_CTL_GAIN: |
| 4369 | case TABLA_A_CDC_TX8_VOL_CTL_GAIN: |
| 4370 | case TABLA_A_CDC_TX9_VOL_CTL_GAIN: |
| 4371 | case TABLA_A_CDC_TX10_VOL_CTL_GAIN: |
| 4372 | rtn = true; |
| 4373 | break; |
| 4374 | default: |
| 4375 | break; |
| 4376 | } |
| 4377 | return rtn; |
| 4378 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4379 | static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 4380 | { |
| 4381 | /* Registers lower than 0x100 are top level registers which can be |
| 4382 | * written by the Tabla core driver. |
| 4383 | */ |
| 4384 | |
| 4385 | if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 4386 | return 1; |
| 4387 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 4388 | /* IIR Coeff registers are not cacheable */ |
| 4389 | if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) && |
| 4390 | (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL)) |
| 4391 | return 1; |
| 4392 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 4393 | /* ANC filter registers are not cacheable */ |
| 4394 | if ((reg >= TABLA_A_CDC_ANC1_FILT1_B1_CTL) && |
| 4395 | (reg <= TABLA_A_CDC_ANC1_FILT2_B3_CTL)) |
| 4396 | return 1; |
| 4397 | if ((reg >= TABLA_A_CDC_ANC2_FILT1_B1_CTL) && |
| 4398 | (reg <= TABLA_A_CDC_ANC2_FILT2_B3_CTL)) |
| 4399 | return 1; |
| 4400 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 4401 | /* Digital gain register is not cacheable so we have to write |
| 4402 | * the setting even it is the same |
| 4403 | */ |
| 4404 | if (tabla_is_digital_gain_register(reg)) |
| 4405 | return 1; |
| 4406 | |
Joonwoo Park | ab2c587 | 2012-05-03 15:16:02 -0700 | [diff] [blame] | 4407 | /* HPH status registers */ |
| 4408 | if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS) |
| 4409 | return 1; |
| 4410 | |
Kuirong Wang | 678e417 | 2012-06-26 15:35:22 -0700 | [diff] [blame] | 4411 | if (reg == TABLA_A_CDC_COMP1_SHUT_DOWN_STATUS || |
| 4412 | reg == TABLA_A_CDC_COMP2_SHUT_DOWN_STATUS) |
| 4413 | return 1; |
| 4414 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | #define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 4419 | static int tabla_write(struct snd_soc_codec *codec, unsigned int reg, |
| 4420 | unsigned int value) |
| 4421 | { |
| 4422 | int ret; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4423 | |
| 4424 | if (reg == SND_SOC_NOPM) |
| 4425 | return 0; |
| 4426 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4427 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 4428 | |
| 4429 | if (!tabla_volatile(codec, reg)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4430 | ret = snd_soc_cache_write(codec, reg, value); |
| 4431 | if (ret != 0) |
| 4432 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 4433 | reg, ret); |
| 4434 | } |
| 4435 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4436 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4437 | } |
| 4438 | static unsigned int tabla_read(struct snd_soc_codec *codec, |
| 4439 | unsigned int reg) |
| 4440 | { |
| 4441 | unsigned int val; |
| 4442 | int ret; |
| 4443 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4444 | if (reg == SND_SOC_NOPM) |
| 4445 | return 0; |
| 4446 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4447 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 4448 | |
| 4449 | if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) && |
| 4450 | reg < codec->driver->reg_cache_size) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4451 | ret = snd_soc_cache_read(codec, reg, &val); |
| 4452 | if (ret >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4453 | return val; |
| 4454 | } else |
| 4455 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 4456 | reg, ret); |
| 4457 | } |
| 4458 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4459 | val = wcd9xxx_reg_read(codec->control_data, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4460 | return val; |
| 4461 | } |
| 4462 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4463 | static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu) |
| 4464 | { |
| 4465 | s16 v_ins; |
| 4466 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4467 | tabla->mbhc_micbias_switched) |
| 4468 | v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu : |
| 4469 | (s16)tabla->mbhc_data.adj_v_ins_h; |
| 4470 | else |
| 4471 | v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu : |
| 4472 | (s16)tabla->mbhc_data.v_ins_h; |
| 4473 | return v_ins; |
| 4474 | } |
| 4475 | |
| 4476 | static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla) |
| 4477 | { |
| 4478 | s16 v_hs_max; |
| 4479 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 4480 | |
| 4481 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 4482 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4483 | tabla->mbhc_micbias_switched) |
| 4484 | v_hs_max = tabla->mbhc_data.adj_v_hs_max; |
| 4485 | else |
| 4486 | v_hs_max = plug_type->v_hs_max; |
| 4487 | return v_hs_max; |
| 4488 | } |
| 4489 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4490 | static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4491 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4492 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4493 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4494 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 4495 | tabla->mbhc_data.v_b1_hu & 0xFF); |
| 4496 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 4497 | (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 4498 | |
| 4499 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 4500 | tabla->mbhc_data.v_b1_h & 0xFF); |
| 4501 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 4502 | (tabla->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 4503 | |
| 4504 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, |
| 4505 | tabla->mbhc_data.v_brh & 0xFF); |
| 4506 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, |
| 4507 | (tabla->mbhc_data.v_brh >> 8) & 0xFF); |
| 4508 | |
| 4509 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL, |
| 4510 | tabla->mbhc_data.v_brl & 0xFF); |
| 4511 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL, |
| 4512 | (tabla->mbhc_data.v_brl >> 8) & 0xFF); |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 4516 | { |
| 4517 | u8 *n_ready, *n_cic; |
| 4518 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 4519 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4520 | const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true); |
| 4521 | |
| 4522 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 4523 | |
| 4524 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 4525 | v_ins_hu & 0xFF); |
| 4526 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 4527 | (v_ins_hu >> 8) & 0xFF); |
| 4528 | |
| 4529 | tabla_codec_calibrate_rel(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4530 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4531 | 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] | 4532 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4533 | n_ready[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4534 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, |
| 4535 | tabla->mbhc_data.npoll); |
| 4536 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, |
| 4537 | tabla->mbhc_data.nbounce_wait); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4538 | 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] | 4539 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, |
| 4540 | n_cic[tabla_codec_mclk_index(tabla)]); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4541 | } |
| 4542 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4543 | static int tabla_startup(struct snd_pcm_substream *substream, |
| 4544 | struct snd_soc_dai *dai) |
| 4545 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4546 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4547 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4548 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4549 | if ((tabla_core != NULL) && |
| 4550 | (tabla_core->dev != NULL) && |
| 4551 | (tabla_core->dev->parent != NULL)) |
| 4552 | pm_runtime_get_sync(tabla_core->dev->parent); |
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 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4555 | } |
| 4556 | |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4557 | static void tabla_shutdown(struct snd_pcm_substream *substream, |
| 4558 | struct snd_soc_dai *dai) |
| 4559 | { |
| 4560 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
| 4561 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4562 | u32 active = 0; |
| 4563 | |
| 4564 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4565 | substream->name, substream->stream); |
| 4566 | if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4567 | return; |
| 4568 | |
| 4569 | if (dai->id <= NUM_CODEC_DAIS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4570 | if (tabla->dai[dai->id].ch_mask) { |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4571 | active = 1; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 4572 | pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4573 | __func__, dai->id, tabla->dai[dai->id].ch_mask); |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | if ((tabla_core != NULL) && |
| 4578 | (tabla_core->dev != NULL) && |
| 4579 | (tabla_core->dev->parent != NULL) && |
| 4580 | (active == 0)) { |
| 4581 | pm_runtime_mark_last_busy(tabla_core->dev->parent); |
| 4582 | pm_runtime_put(tabla_core->dev->parent); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4586 | 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] | 4587 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4588 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4589 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4590 | pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable, |
| 4591 | dapm); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4592 | if (dapm) |
| 4593 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4594 | if (mclk_enable) { |
| 4595 | tabla->mclk_enabled = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4596 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4597 | if (tabla->mbhc_polling_active) { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4598 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4599 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4600 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4601 | TABLA_BANDGAP_AUDIO_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4602 | tabla_codec_enable_clock_block(codec, 0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4603 | tabla_codec_calibrate_hs_polling(codec); |
| 4604 | tabla_codec_start_hs_polling(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4605 | } else { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4606 | tabla_codec_disable_clock_block(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4607 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4608 | TABLA_BANDGAP_AUDIO_MODE); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4609 | tabla_codec_enable_clock_block(codec, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4610 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4611 | } else { |
| 4612 | |
| 4613 | if (!tabla->mclk_enabled) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4614 | if (dapm) |
| 4615 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4616 | pr_err("Error, MCLK already diabled\n"); |
| 4617 | return -EINVAL; |
| 4618 | } |
| 4619 | tabla->mclk_enabled = false; |
| 4620 | |
| 4621 | if (tabla->mbhc_polling_active) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4622 | tabla_codec_pause_hs_polling(codec); |
| 4623 | tabla_codec_disable_clock_block(codec); |
| 4624 | tabla_codec_enable_bandgap(codec, |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 4625 | TABLA_BANDGAP_MBHC_MODE); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4626 | tabla_enable_rx_bias(codec, 1); |
| 4627 | tabla_codec_enable_clock_block(codec, 1); |
| 4628 | tabla_codec_calibrate_hs_polling(codec); |
| 4629 | tabla_codec_start_hs_polling(codec); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4630 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, |
| 4631 | 0x05, 0x01); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4632 | } else { |
| 4633 | tabla_codec_disable_clock_block(codec); |
| 4634 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4635 | TABLA_BANDGAP_OFF); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4636 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4637 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4638 | if (dapm) |
| 4639 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4640 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4643 | static int tabla_set_dai_sysclk(struct snd_soc_dai *dai, |
| 4644 | int clk_id, unsigned int freq, int dir) |
| 4645 | { |
| 4646 | pr_debug("%s\n", __func__); |
| 4647 | return 0; |
| 4648 | } |
| 4649 | |
| 4650 | static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 4651 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4652 | u8 val = 0; |
| 4653 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4654 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4655 | pr_debug("%s\n", __func__); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4656 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 4657 | case SND_SOC_DAIFMT_CBS_CFS: |
| 4658 | /* CPU is master */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4659 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4660 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4661 | snd_soc_update_bits(dai->codec, |
| 4662 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 4663 | TABLA_I2S_MASTER_MODE_MASK, 0); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4664 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4665 | snd_soc_update_bits(dai->codec, |
| 4666 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 4667 | TABLA_I2S_MASTER_MODE_MASK, 0); |
| 4668 | } |
| 4669 | break; |
| 4670 | case SND_SOC_DAIFMT_CBM_CFM: |
| 4671 | /* CPU is slave */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4672 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4673 | val = TABLA_I2S_MASTER_MODE_MASK; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4674 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4675 | snd_soc_update_bits(dai->codec, |
| 4676 | TABLA_A_CDC_CLK_TX_I2S_CTL, val, val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4677 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4678 | snd_soc_update_bits(dai->codec, |
| 4679 | TABLA_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 4680 | } |
| 4681 | break; |
| 4682 | default: |
| 4683 | return -EINVAL; |
| 4684 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4685 | return 0; |
| 4686 | } |
| 4687 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4688 | static int tabla_set_channel_map(struct snd_soc_dai *dai, |
| 4689 | unsigned int tx_num, unsigned int *tx_slot, |
| 4690 | unsigned int rx_num, unsigned int *rx_slot) |
| 4691 | |
| 4692 | { |
| 4693 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4694 | struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent); |
| 4695 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4696 | if (!tx_slot && !rx_slot) { |
| 4697 | pr_err("%s: Invalid\n", __func__); |
| 4698 | return -EINVAL; |
| 4699 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4700 | pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n" |
| 4701 | "tabla->intf_type %d\n", |
| 4702 | __func__, dai->name, dai->id, tx_num, rx_num, |
| 4703 | tabla->intf_type); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4704 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4705 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4706 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 4707 | tx_num, tx_slot, rx_num, rx_slot); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4708 | return 0; |
| 4709 | } |
| 4710 | |
| 4711 | static int tabla_get_channel_map(struct snd_soc_dai *dai, |
| 4712 | unsigned int *tx_num, unsigned int *tx_slot, |
| 4713 | unsigned int *rx_num, unsigned int *rx_slot) |
| 4714 | |
| 4715 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4716 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec); |
| 4717 | u32 i = 0; |
| 4718 | struct wcd9xxx_ch *ch; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4719 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4720 | switch (dai->id) { |
| 4721 | case AIF1_PB: |
| 4722 | case AIF2_PB: |
| 4723 | case AIF3_PB: |
| 4724 | if (!rx_slot || !rx_num) { |
| 4725 | pr_err("%s: Invalid rx_slot %d or rx_num %d\n", |
| 4726 | __func__, (u32) rx_slot, (u32) rx_num); |
| 4727 | return -EINVAL; |
| 4728 | } |
| 4729 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4730 | list) { |
| 4731 | rx_slot[i++] = ch->ch_num; |
| 4732 | } |
| 4733 | *rx_num = i; |
| 4734 | break; |
| 4735 | case AIF1_CAP: |
| 4736 | case AIF2_CAP: |
| 4737 | case AIF3_CAP: |
| 4738 | if (!tx_slot || !tx_num) { |
| 4739 | pr_err("%s: Invalid tx_slot %d or tx_num %d\n", |
| 4740 | __func__, (u32) tx_slot, (u32) tx_num); |
| 4741 | return -EINVAL; |
| 4742 | } |
| 4743 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4744 | list) { |
| 4745 | tx_slot[i++] = ch->ch_num; |
| 4746 | } |
| 4747 | *tx_num = i; |
| 4748 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4749 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4750 | default: |
| 4751 | pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id); |
| 4752 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4753 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4754 | return 0; |
| 4755 | } |
| 4756 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4757 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4758 | static int tabla_set_interpolator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4759 | u8 rx_fs_rate_reg_val, |
| 4760 | u32 compander_fs, |
| 4761 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4762 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4763 | u32 j; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4764 | u8 rx_mix1_inp; |
| 4765 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 4766 | u16 rx_fs_reg; |
| 4767 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
| 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; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4770 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4771 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4772 | 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] | 4773 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4774 | rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4775 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4776 | if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) || |
| 4777 | (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) { |
| 4778 | pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n", |
| 4779 | __func__, rx_mix1_inp - 5 , dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4780 | return -EINVAL; |
| 4781 | } |
| 4782 | |
| 4783 | rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL; |
| 4784 | |
| 4785 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4786 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 4787 | |
| 4788 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4789 | rx_mix_1_reg_1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4790 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4791 | rx_mix_1_reg_2); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4792 | |
| 4793 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4794 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) || |
| 4795 | ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4796 | |
| 4797 | rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j; |
| 4798 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4799 | pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n", |
| 4800 | __func__, dai->id, j + 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4801 | |
| 4802 | pr_debug("%s: set RX%u sample rate to %u\n", |
| 4803 | __func__, j + 1, sample_rate); |
| 4804 | |
| 4805 | snd_soc_update_bits(codec, rx_fs_reg, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4806 | 0xE0, rx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4807 | |
| 4808 | if (comp_rx_path[j] < COMPANDER_MAX) |
| 4809 | tabla->comp_fs[comp_rx_path[j]] |
| 4810 | = compander_fs; |
| 4811 | } |
| 4812 | if (j <= 2) |
| 4813 | rx_mix_1_reg_1 += 3; |
| 4814 | else |
| 4815 | rx_mix_1_reg_1 += 2; |
| 4816 | } |
| 4817 | } |
| 4818 | return 0; |
| 4819 | } |
| 4820 | |
| 4821 | static int tabla_set_decimator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4822 | u8 tx_fs_rate_reg_val, |
| 4823 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4824 | { |
| 4825 | struct snd_soc_codec *codec = dai->codec; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4826 | struct wcd9xxx_ch *ch; |
| 4827 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4828 | u32 tx_port; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4829 | u16 tx_port_reg, tx_fs_reg; |
| 4830 | u8 tx_port_reg_val; |
| 4831 | s8 decimator; |
| 4832 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4833 | 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] | 4834 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4835 | tx_port = ch->port + 1; |
| 4836 | pr_debug("%s: dai->id = %d, tx_port = %d", |
| 4837 | __func__, dai->id, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4838 | |
| 4839 | if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4840 | pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n", |
| 4841 | __func__, tx_port, dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4842 | return -EINVAL; |
| 4843 | } |
| 4844 | |
| 4845 | tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 4846 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 4847 | |
| 4848 | decimator = 0; |
| 4849 | |
| 4850 | if ((tx_port >= 1) && (tx_port <= 6)) { |
| 4851 | |
| 4852 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
| 4853 | if (tx_port_reg_val == 0x8) |
| 4854 | decimator = tx_port; |
| 4855 | |
| 4856 | } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) { |
| 4857 | |
| 4858 | tx_port_reg_val = tx_port_reg_val & 0x1F; |
| 4859 | |
| 4860 | if ((tx_port_reg_val >= 0x8) && |
| 4861 | (tx_port_reg_val <= 0x11)) { |
| 4862 | |
| 4863 | decimator = (tx_port_reg_val - 0x8) + 1; |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 4868 | |
| 4869 | tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL + |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4870 | 8 * (decimator - 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4871 | |
| 4872 | pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 4873 | __func__, decimator, tx_port, sample_rate); |
| 4874 | |
| 4875 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4876 | tx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4877 | |
| 4878 | } else { |
| 4879 | if ((tx_port_reg_val >= 0x1) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4880 | (tx_port_reg_val <= 0x7)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4881 | |
| 4882 | pr_debug("%s: RMIX%u going to SLIM TX%u\n", |
| 4883 | __func__, tx_port_reg_val, tx_port); |
| 4884 | |
| 4885 | } else if ((tx_port_reg_val >= 0x8) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4886 | (tx_port_reg_val <= 0x11)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4887 | |
| 4888 | pr_err("%s: ERROR: Should not be here\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4889 | __func__); |
| 4890 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n", |
| 4891 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4892 | return -EINVAL; |
| 4893 | |
| 4894 | } else if (tx_port_reg_val == 0) { |
| 4895 | pr_debug("%s: no signal to SLIM TX%u\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4896 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4897 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4898 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n", |
| 4899 | __func__, tx_port); |
| 4900 | pr_err("%s: ERROR: wrong signal = %u\n", |
| 4901 | __func__, tx_port_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4902 | return -EINVAL; |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | return 0; |
| 4907 | } |
| 4908 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4909 | static int tabla_hw_params(struct snd_pcm_substream *substream, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4910 | struct snd_pcm_hw_params *params, |
| 4911 | struct snd_soc_dai *dai) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4912 | { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4913 | struct snd_soc_codec *codec = dai->codec; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4914 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4915 | u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4916 | u32 compander_fs; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4917 | int ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4918 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4919 | 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] | 4920 | dai->name, dai->id, params_rate(params), |
| 4921 | params_channels(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4922 | |
| 4923 | switch (params_rate(params)) { |
| 4924 | case 8000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4925 | tx_fs_rate_reg_val = 0x00; |
| 4926 | rx_fs_rate_reg_val = 0x00; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4927 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4928 | break; |
| 4929 | case 16000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4930 | tx_fs_rate_reg_val = 0x01; |
| 4931 | rx_fs_rate_reg_val = 0x20; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4932 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4933 | break; |
| 4934 | case 32000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4935 | tx_fs_rate_reg_val = 0x02; |
| 4936 | rx_fs_rate_reg_val = 0x40; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4937 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4938 | break; |
| 4939 | case 48000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4940 | tx_fs_rate_reg_val = 0x03; |
| 4941 | rx_fs_rate_reg_val = 0x60; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4942 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4943 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4944 | case 96000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4945 | tx_fs_rate_reg_val = 0x04; |
| 4946 | rx_fs_rate_reg_val = 0x80; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4947 | compander_fs = COMPANDER_FS_96KHZ; |
| 4948 | break; |
| 4949 | case 192000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4950 | tx_fs_rate_reg_val = 0x05; |
| 4951 | rx_fs_rate_reg_val = 0xA0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4952 | compander_fs = COMPANDER_FS_192KHZ; |
| 4953 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4954 | default: |
| 4955 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4956 | params_rate(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4957 | return -EINVAL; |
| 4958 | } |
| 4959 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4960 | switch (substream->stream) { |
| 4961 | case SNDRV_PCM_STREAM_CAPTURE: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4962 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4963 | ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4964 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4965 | if (ret < 0) { |
| 4966 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4967 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4968 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4969 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4970 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4971 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4972 | switch (params_format(params)) { |
| 4973 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4974 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4975 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4976 | break; |
| 4977 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4978 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4979 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4980 | break; |
| 4981 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4982 | pr_err("%s: Invalid format %d\n", __func__, |
| 4983 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4984 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4985 | } |
| 4986 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4987 | 0x07, tx_fs_rate_reg_val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4988 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4989 | switch (params_format(params)) { |
| 4990 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4991 | tabla->dai[dai->id].bit_width = 16; |
| 4992 | break; |
| 4993 | default: |
| 4994 | pr_err("%s: Invalid TX format %d\n", __func__, |
| 4995 | params_format(params)); |
| 4996 | return -EINVAL; |
| 4997 | } |
| 4998 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4999 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5000 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5001 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5002 | case SNDRV_PCM_STREAM_PLAYBACK: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5003 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5004 | ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5005 | compander_fs, |
| 5006 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5007 | if (ret < 0) { |
| 5008 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5009 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5010 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5011 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5012 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5013 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5014 | switch (params_format(params)) { |
| 5015 | case SNDRV_PCM_FORMAT_S16_LE: |
| 5016 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5017 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5018 | break; |
| 5019 | case SNDRV_PCM_FORMAT_S32_LE: |
| 5020 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5021 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5022 | break; |
| 5023 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5024 | pr_err("%s: Invalid RX format %d\n", __func__, |
| 5025 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5026 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5027 | } |
| 5028 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5029 | 0x03, (rx_fs_rate_reg_val >> 0x05)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5030 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5031 | switch (params_format(params)) { |
| 5032 | case SNDRV_PCM_FORMAT_S16_LE: |
| 5033 | tabla->dai[dai->id].bit_width = 16; |
| 5034 | break; |
| 5035 | default: |
| 5036 | pr_err("%s: Invalid format %d\n", __func__, |
| 5037 | params_format(params)); |
| 5038 | return -EINVAL; |
| 5039 | } |
| 5040 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5041 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5042 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5043 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5044 | default: |
| 5045 | pr_err("%s: Invalid stream type %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5046 | substream->stream); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 5047 | return -EINVAL; |
| 5048 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5049 | return 0; |
| 5050 | } |
| 5051 | |
| 5052 | static struct snd_soc_dai_ops tabla_dai_ops = { |
| 5053 | .startup = tabla_startup, |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 5054 | .shutdown = tabla_shutdown, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5055 | .hw_params = tabla_hw_params, |
| 5056 | .set_sysclk = tabla_set_dai_sysclk, |
| 5057 | .set_fmt = tabla_set_dai_fmt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5058 | .set_channel_map = tabla_set_channel_map, |
| 5059 | .get_channel_map = tabla_get_channel_map, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5060 | }; |
| 5061 | |
| 5062 | static struct snd_soc_dai_driver tabla_dai[] = { |
| 5063 | { |
| 5064 | .name = "tabla_rx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5065 | .id = AIF1_PB, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5066 | .playback = { |
| 5067 | .stream_name = "AIF1 Playback", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5068 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5069 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5070 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5071 | .rate_min = 8000, |
| 5072 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5073 | .channels_max = 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5074 | }, |
| 5075 | .ops = &tabla_dai_ops, |
| 5076 | }, |
| 5077 | { |
| 5078 | .name = "tabla_tx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5079 | .id = AIF1_CAP, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5080 | .capture = { |
| 5081 | .stream_name = "AIF1 Capture", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 5082 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5083 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5084 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5085 | .rate_min = 8000, |
| 5086 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5087 | .channels_max = 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5088 | }, |
| 5089 | .ops = &tabla_dai_ops, |
| 5090 | }, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 5091 | { |
| 5092 | .name = "tabla_rx2", |
| 5093 | .id = AIF2_PB, |
| 5094 | .playback = { |
| 5095 | .stream_name = "AIF2 Playback", |
| 5096 | .rates = WCD9310_RATES, |
| 5097 | .formats = TABLA_FORMATS, |
| 5098 | .rate_min = 8000, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5099 | .rate_max = 192000, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 5100 | .channels_min = 1, |
| 5101 | .channels_max = 2, |
| 5102 | }, |
| 5103 | .ops = &tabla_dai_ops, |
| 5104 | }, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5105 | { |
| 5106 | .name = "tabla_tx2", |
| 5107 | .id = AIF2_CAP, |
| 5108 | .capture = { |
| 5109 | .stream_name = "AIF2 Capture", |
| 5110 | .rates = WCD9310_RATES, |
| 5111 | .formats = TABLA_FORMATS, |
| 5112 | .rate_max = 192000, |
| 5113 | .rate_min = 8000, |
| 5114 | .channels_min = 1, |
| 5115 | .channels_max = 4, |
| 5116 | }, |
| 5117 | .ops = &tabla_dai_ops, |
| 5118 | }, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 5119 | { |
| 5120 | .name = "tabla_tx3", |
| 5121 | .id = AIF3_CAP, |
| 5122 | .capture = { |
| 5123 | .stream_name = "AIF3 Capture", |
| 5124 | .rates = WCD9310_RATES, |
| 5125 | .formats = TABLA_FORMATS, |
| 5126 | .rate_max = 48000, |
| 5127 | .rate_min = 8000, |
| 5128 | .channels_min = 1, |
| 5129 | .channels_max = 2, |
| 5130 | }, |
| 5131 | .ops = &tabla_dai_ops, |
| 5132 | }, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5133 | { |
| 5134 | .name = "tabla_rx3", |
| 5135 | .id = AIF3_PB, |
| 5136 | .playback = { |
| 5137 | .stream_name = "AIF3 Playback", |
| 5138 | .rates = WCD9310_RATES, |
| 5139 | .formats = TABLA_FORMATS, |
| 5140 | .rate_min = 8000, |
| 5141 | .rate_max = 192000, |
| 5142 | .channels_min = 1, |
| 5143 | .channels_max = 2, |
| 5144 | }, |
| 5145 | .ops = &tabla_dai_ops, |
| 5146 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5147 | }; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5148 | |
| 5149 | static struct snd_soc_dai_driver tabla_i2s_dai[] = { |
| 5150 | { |
| 5151 | .name = "tabla_i2s_rx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5152 | .id = AIF1_PB, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5153 | .playback = { |
| 5154 | .stream_name = "AIF1 Playback", |
| 5155 | .rates = WCD9310_RATES, |
| 5156 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5157 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5158 | .rate_min = 8000, |
| 5159 | .channels_min = 1, |
| 5160 | .channels_max = 4, |
| 5161 | }, |
| 5162 | .ops = &tabla_dai_ops, |
| 5163 | }, |
| 5164 | { |
| 5165 | .name = "tabla_i2s_tx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5166 | .id = AIF1_CAP, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5167 | .capture = { |
| 5168 | .stream_name = "AIF1 Capture", |
| 5169 | .rates = WCD9310_RATES, |
| 5170 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5171 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 5172 | .rate_min = 8000, |
| 5173 | .channels_min = 1, |
| 5174 | .channels_max = 4, |
| 5175 | }, |
| 5176 | .ops = &tabla_dai_ops, |
| 5177 | }, |
| 5178 | }; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5179 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5180 | static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5181 | int event, int index) |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5182 | { |
| 5183 | int ret = 0; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5184 | struct wcd9xxx_ch *ch; |
| 5185 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5186 | switch (event) { |
| 5187 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5188 | list_for_each_entry(ch, |
| 5189 | &tabla_p->dai[index].wcd9xxx_ch_list, list) { |
| 5190 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5191 | if (ret < 0) { |
| 5192 | pr_err("%s: Invalid slave port ID: %d\n", |
| 5193 | __func__, ret); |
| 5194 | ret = -EINVAL; |
| 5195 | break; |
| 5196 | } |
| 5197 | tabla_p->dai[index].ch_mask |= 1 << ret; |
| 5198 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5199 | break; |
| 5200 | case SND_SOC_DAPM_POST_PMD: |
| 5201 | ret = wait_event_timeout(tabla_p->dai[index].dai_wait, |
| 5202 | (tabla_p->dai[index].ch_mask == 0), |
| 5203 | msecs_to_jiffies(SLIM_CLOSE_TIMEOUT)); |
| 5204 | if (!ret) { |
| 5205 | pr_err("%s: Slim close tx/rx wait timeout\n", |
| 5206 | __func__); |
| 5207 | ret = -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5208 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 5209 | break; |
| 5210 | } |
| 5211 | return ret; |
| 5212 | } |
| 5213 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5214 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5215 | struct snd_kcontrol *kcontrol, |
| 5216 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5217 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5218 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5219 | struct snd_soc_codec *codec = w->codec; |
| 5220 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5221 | u32 ret = 0; |
| 5222 | struct wcd9xxx_codec_dai_data *dai; |
| 5223 | |
| 5224 | core = dev_get_drvdata(codec->dev->parent); |
| 5225 | |
| 5226 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 5227 | "stream name %s event %d\n", |
| 5228 | __func__, w->codec->name, w->codec->num_dai, |
| 5229 | w->sname, event); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5230 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5231 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5232 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5233 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 5234 | (core->dev != NULL) && |
| 5235 | (core->dev->parent != NULL)) { |
| 5236 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5237 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5238 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5239 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5240 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5241 | pr_debug("%s: w->name %s w->shift %d event %d\n", |
| 5242 | __func__, w->name, w->shift, event); |
| 5243 | dai = &tabla_p->dai[w->shift]; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5244 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5245 | switch (event) { |
| 5246 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5247 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 5248 | w->shift); |
| 5249 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 5250 | dai->rate, dai->bit_width, |
| 5251 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5252 | break; |
| 5253 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5254 | ret = wcd9xxx_close_slim_sch_rx(core, |
| 5255 | &dai->wcd9xxx_ch_list, |
| 5256 | dai->grph); |
| 5257 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 5258 | w->shift); |
| 5259 | if (ret < 0) { |
| 5260 | ret = wcd9xxx_disconnect_port(core, |
| 5261 | &dai->wcd9xxx_ch_list, |
| 5262 | dai->grph); |
| 5263 | pr_info("%s: Disconnect RX port, ret = %d\n", |
| 5264 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5265 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5266 | if ((core != NULL) && |
| 5267 | (core->dev != NULL) && |
| 5268 | (core->dev->parent != NULL)) { |
| 5269 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5270 | pm_runtime_put(core->dev->parent); |
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 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5273 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5274 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5275 | return ret; |
| 5276 | } |
| 5277 | |
| 5278 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5279 | struct snd_kcontrol *kcontrol, |
| 5280 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5281 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5282 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5283 | struct snd_soc_codec *codec = w->codec; |
| 5284 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5285 | u32 ret = 0; |
| 5286 | struct wcd9xxx_codec_dai_data *dai; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5287 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5288 | core = dev_get_drvdata(codec->dev->parent); |
| 5289 | |
| 5290 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 5291 | "stream name %s\n", __func__, w->codec->name, |
| 5292 | w->codec->num_dai, w->sname); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5293 | |
| 5294 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5295 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5296 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 5297 | (core->dev != NULL) && |
| 5298 | (core->dev->parent != NULL)) { |
| 5299 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5300 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5301 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5302 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 5303 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 5304 | |
| 5305 | pr_debug("%s(): %s %d\n", __func__, w->name, event); |
| 5306 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5307 | dai = &tabla_p->dai[w->shift]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5308 | switch (event) { |
| 5309 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5310 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 5311 | w->shift); |
| 5312 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 5313 | dai->rate, |
| 5314 | dai->bit_width, |
| 5315 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5316 | break; |
| 5317 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5318 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 5319 | dai->grph); |
| 5320 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 5321 | w->shift); |
| 5322 | if (ret < 0) { |
| 5323 | ret = wcd9xxx_disconnect_port(core, |
| 5324 | &dai->wcd9xxx_ch_list, |
| 5325 | dai->grph); |
| 5326 | pr_info("%s: Disconnect TX port, ret = %d\n", |
| 5327 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5328 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5329 | if ((core != NULL) && |
| 5330 | (core->dev != NULL) && |
| 5331 | (core->dev->parent != NULL)) { |
| 5332 | pm_runtime_mark_last_busy(core->dev->parent); |
| 5333 | pm_runtime_put(core->dev->parent); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5334 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5335 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5336 | } |
| 5337 | return ret; |
| 5338 | } |
| 5339 | |
| 5340 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 5341 | * Might Need to have callbacks registered only for slimbus |
| 5342 | */ |
| 5343 | static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = { |
| 5344 | /*RX stuff */ |
| 5345 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 5346 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 5347 | SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL, |
| 5348 | 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5349 | SND_SOC_DAPM_PRE_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5350 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 5351 | SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5352 | ARRAY_SIZE(dac1_switch)), |
| 5353 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5354 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 5355 | AIF1_PB, 0, tabla_codec_enable_slimrx, |
| 5356 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5357 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 5358 | AIF2_PB, 0, tabla_codec_enable_slimrx, |
| 5359 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5360 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 5361 | AIF3_PB, 0, tabla_codec_enable_slimrx, |
| 5362 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5363 | |
| 5364 | SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0, |
| 5365 | &slim_rx_mux[TABLA_RX1]), |
| 5366 | SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0, |
| 5367 | &slim_rx_mux[TABLA_RX2]), |
| 5368 | SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0, |
| 5369 | &slim_rx_mux[TABLA_RX3]), |
| 5370 | SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0, |
| 5371 | &slim_rx_mux[TABLA_RX4]), |
| 5372 | SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0, |
| 5373 | &slim_rx_mux[TABLA_RX5]), |
| 5374 | SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0, |
| 5375 | &slim_rx_mux[TABLA_RX6]), |
| 5376 | SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0, |
| 5377 | &slim_rx_mux[TABLA_RX7]), |
| 5378 | |
| 5379 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5380 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5381 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5382 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5383 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5384 | SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5385 | 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] | 5386 | /* Headphone */ |
| 5387 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 5388 | SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 5389 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5390 | SND_SOC_DAPM_POST_PMD), |
| 5391 | SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 5392 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 5393 | |
| 5394 | SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 5395 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 5396 | SND_SOC_DAPM_POST_PMD), |
| 5397 | |
| 5398 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 5399 | tabla_hphr_dac_event, |
| 5400 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5401 | |
| 5402 | /* Speaker */ |
| 5403 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 5404 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 5405 | SND_SOC_DAPM_OUTPUT("LINEOUT3"), |
| 5406 | SND_SOC_DAPM_OUTPUT("LINEOUT4"), |
| 5407 | SND_SOC_DAPM_OUTPUT("LINEOUT5"), |
| 5408 | |
| 5409 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 5410 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5411 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5412 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 5413 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5414 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5415 | SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL, |
| 5416 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5417 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5418 | SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL, |
| 5419 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5420 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5421 | SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0, |
| 5422 | tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 5423 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5424 | |
| 5425 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 5426 | , tabla_lineout_dac_event, |
| 5427 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5428 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 5429 | , tabla_lineout_dac_event, |
| 5430 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5431 | SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0 |
| 5432 | , tabla_lineout_dac_event, |
| 5433 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5434 | SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 5435 | &lineout3_ground_switch), |
| 5436 | SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0 |
| 5437 | , tabla_lineout_dac_event, |
| 5438 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5439 | SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 5440 | &lineout4_ground_switch), |
| 5441 | SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0 |
| 5442 | , tabla_lineout_dac_event, |
| 5443 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5444 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5445 | 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] | 5446 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5447 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5448 | 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] | 5449 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5450 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5451 | 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] | 5452 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5453 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5454 | 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] | 5455 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5456 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5457 | 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] | 5458 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5459 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5460 | 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] | 5461 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5462 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5463 | 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] | 5464 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5465 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5466 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5467 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5468 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5469 | SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5470 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5471 | SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, |
| 5472 | &rx4_dsm_mux, tabla_codec_reset_interpolator, |
| 5473 | SND_SOC_DAPM_PRE_PMU), |
| 5474 | |
| 5475 | SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, |
| 5476 | &rx6_dsm_mux, tabla_codec_reset_interpolator, |
| 5477 | SND_SOC_DAPM_PRE_PMU), |
| 5478 | |
Kuirong Wang | 84ee880 | 2013-02-09 12:52:06 -0800 | [diff] [blame] | 5479 | SND_SOC_DAPM_MIXER_E("RX1 CHAIN", SND_SOC_NOPM, 5, 0, NULL, |
| 5480 | 0, tabla_codec_hphr_dem_input_selection, |
| 5481 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5482 | SND_SOC_DAPM_MIXER_E("RX2 CHAIN", SND_SOC_NOPM, 5, 0, NULL, |
| 5483 | 0, tabla_codec_hphl_dem_input_selection, |
| 5484 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5485 | |
| 5486 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5487 | &rx_mix1_inp1_mux), |
| 5488 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5489 | &rx_mix1_inp2_mux), |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5490 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 5491 | &rx_mix1_inp3_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5492 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5493 | &rx2_mix1_inp1_mux), |
| 5494 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5495 | &rx2_mix1_inp2_mux), |
| 5496 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5497 | &rx3_mix1_inp1_mux), |
| 5498 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5499 | &rx3_mix1_inp2_mux), |
| 5500 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5501 | &rx4_mix1_inp1_mux), |
| 5502 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5503 | &rx4_mix1_inp2_mux), |
| 5504 | SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5505 | &rx5_mix1_inp1_mux), |
| 5506 | SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5507 | &rx5_mix1_inp2_mux), |
| 5508 | SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5509 | &rx6_mix1_inp1_mux), |
| 5510 | SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5511 | &rx6_mix1_inp2_mux), |
| 5512 | SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5513 | &rx7_mix1_inp1_mux), |
| 5514 | SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5515 | &rx7_mix1_inp2_mux), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5516 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5517 | &rx1_mix2_inp1_mux), |
| 5518 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5519 | &rx1_mix2_inp2_mux), |
| 5520 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5521 | &rx2_mix2_inp1_mux), |
| 5522 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5523 | &rx2_mix2_inp2_mux), |
| 5524 | SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5525 | &rx3_mix2_inp1_mux), |
| 5526 | SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5527 | &rx3_mix2_inp2_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5528 | |
| 5529 | SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0, |
| 5530 | tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 5531 | SND_SOC_DAPM_PRE_PMD), |
| 5532 | |
| 5533 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 5534 | tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 5535 | SND_SOC_DAPM_POST_PMD), |
| 5536 | |
| 5537 | /* TX */ |
| 5538 | |
| 5539 | SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 5540 | 0), |
| 5541 | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5542 | SND_SOC_DAPM_SUPPLY("LDO_H", SND_SOC_NOPM, 0, 0, |
| 5543 | tabla_codec_enable_ldo_h, SND_SOC_DAPM_PRE_PMU | |
| 5544 | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5545 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 5546 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0, |
| 5547 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5548 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5549 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0, |
| 5550 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5551 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5552 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5553 | SND_SOC_DAPM_INPUT("AMIC1"), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5554 | 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] | 5555 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5556 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5557 | 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] | 5558 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5559 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5560 | 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] | 5561 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5562 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5563 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0, |
| 5564 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5565 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5566 | |
| 5567 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 5568 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0, |
| 5569 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5570 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5571 | |
| 5572 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 5573 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0, |
| 5574 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5575 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5576 | |
| 5577 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 5578 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0, |
| 5579 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5580 | |
| 5581 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 5582 | SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0, |
| 5583 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5584 | |
| 5585 | 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] | 5586 | &dec1_mux, tabla_codec_enable_dec, |
| 5587 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5588 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5589 | |
| 5590 | 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] | 5591 | &dec2_mux, tabla_codec_enable_dec, |
| 5592 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5593 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5594 | |
| 5595 | 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] | 5596 | &dec3_mux, tabla_codec_enable_dec, |
| 5597 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5598 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5599 | |
| 5600 | 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] | 5601 | &dec4_mux, tabla_codec_enable_dec, |
| 5602 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5603 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5604 | |
| 5605 | 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] | 5606 | &dec5_mux, tabla_codec_enable_dec, |
| 5607 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5608 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5609 | |
| 5610 | 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] | 5611 | &dec6_mux, tabla_codec_enable_dec, |
| 5612 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5613 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5614 | |
| 5615 | 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] | 5616 | &dec7_mux, tabla_codec_enable_dec, |
| 5617 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5618 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5619 | |
| 5620 | 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] | 5621 | &dec8_mux, tabla_codec_enable_dec, |
| 5622 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5623 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5624 | |
| 5625 | 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] | 5626 | &dec9_mux, tabla_codec_enable_dec, |
| 5627 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5628 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5629 | |
| 5630 | 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] | 5631 | &dec10_mux, tabla_codec_enable_dec, |
| 5632 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5633 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5634 | |
| 5635 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 5636 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 5637 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 5638 | SND_SOC_DAPM_OUTPUT("ANC HEADPHONE"), |
| 5639 | SND_SOC_DAPM_PGA_E("ANC HPHL", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 5640 | tabla_codec_enable_anc, |
| 5641 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
| 5642 | SND_SOC_DAPM_PGA_E("ANC HPHR", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 5643 | tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU), |
| 5644 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5645 | |
| 5646 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 5647 | |
| 5648 | SND_SOC_DAPM_INPUT("AMIC2"), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5649 | 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] | 5650 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5651 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5652 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Power External", |
| 5653 | TABLA_A_MICB_2_CTL, 7, 0, |
| 5654 | tabla_codec_enable_micbias_power, |
| 5655 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5656 | SND_SOC_DAPM_POST_PMD), |
| 5657 | |
| 5658 | 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] | 5659 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5660 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5661 | 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] | 5662 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5663 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5664 | 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] | 5665 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5666 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5667 | 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] | 5668 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5669 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5670 | 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] | 5671 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5672 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5673 | 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] | 5674 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5675 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5676 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0, |
| 5677 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5678 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5679 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5680 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 5681 | AIF1_CAP, 0, tabla_codec_enable_slimtx, |
| 5682 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5683 | |
| 5684 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 5685 | AIF2_CAP, 0, tabla_codec_enable_slimtx, |
| 5686 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5687 | |
| 5688 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 5689 | AIF3_CAP, 0, tabla_codec_enable_slimtx, |
| 5690 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5691 | |
| 5692 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 5693 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5694 | |
| 5695 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 5696 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5697 | |
| 5698 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 5699 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5700 | |
| 5701 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0, |
| 5702 | &sb_tx1_mux), |
| 5703 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0, |
| 5704 | &sb_tx2_mux), |
| 5705 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0, |
| 5706 | &sb_tx3_mux), |
| 5707 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0, |
| 5708 | &sb_tx4_mux), |
| 5709 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0, |
| 5710 | &sb_tx5_mux), |
| 5711 | SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0, |
| 5712 | &sb_tx6_mux), |
| 5713 | SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0, |
| 5714 | &sb_tx7_mux), |
| 5715 | SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0, |
| 5716 | &sb_tx8_mux), |
| 5717 | SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0, |
| 5718 | &sb_tx9_mux), |
| 5719 | SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0, |
| 5720 | &sb_tx10_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5721 | |
| 5722 | /* Digital Mic Inputs */ |
| 5723 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 5724 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5725 | SND_SOC_DAPM_POST_PMD), |
| 5726 | |
| 5727 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 5728 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5729 | SND_SOC_DAPM_POST_PMD), |
| 5730 | |
| 5731 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 5732 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5733 | SND_SOC_DAPM_POST_PMD), |
| 5734 | |
| 5735 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 5736 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5737 | SND_SOC_DAPM_POST_PMD), |
| 5738 | |
| 5739 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 5740 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5741 | SND_SOC_DAPM_POST_PMD), |
| 5742 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 5743 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5744 | SND_SOC_DAPM_POST_PMD), |
| 5745 | |
| 5746 | /* Sidetone */ |
| 5747 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 5748 | 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] | 5749 | |
Bhalchandra Gajare | 8ba4446 | 2012-07-26 18:08:21 -0700 | [diff] [blame] | 5750 | SND_SOC_DAPM_MUX("IIR2 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir2_inp1_mux), |
| 5751 | SND_SOC_DAPM_PGA("IIR2", TABLA_A_CDC_CLK_SD_CTL, 1, 0, NULL, 0), |
| 5752 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 5753 | /* AUX PGA */ |
| 5754 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0, |
| 5755 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5756 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5757 | SND_SOC_DAPM_POST_PMD), |
| 5758 | |
| 5759 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0, |
| 5760 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5761 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5762 | SND_SOC_DAPM_POST_PMD), |
| 5763 | |
| 5764 | /* Lineout, ear and HPH PA Mixers */ |
| 5765 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5766 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 5767 | |
| 5768 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5769 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 5770 | |
| 5771 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5772 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 5773 | |
| 5774 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5775 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
| 5776 | |
| 5777 | SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5778 | lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)), |
| 5779 | |
| 5780 | SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5781 | lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)), |
| 5782 | |
| 5783 | SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5784 | lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)), |
| 5785 | |
| 5786 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5787 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5788 | }; |
| 5789 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5790 | static short tabla_codec_read_sta_result(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5791 | { |
| 5792 | u8 bias_msb, bias_lsb; |
| 5793 | short bias_value; |
| 5794 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5795 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS); |
| 5796 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS); |
| 5797 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5798 | return bias_value; |
| 5799 | } |
| 5800 | |
| 5801 | static short tabla_codec_read_dce_result(struct snd_soc_codec *codec) |
| 5802 | { |
| 5803 | u8 bias_msb, bias_lsb; |
| 5804 | short bias_value; |
| 5805 | |
| 5806 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS); |
| 5807 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS); |
| 5808 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5809 | return bias_value; |
| 5810 | } |
| 5811 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5812 | 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] | 5813 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5814 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 5815 | } |
| 5816 | |
| 5817 | static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5818 | bool override_bypass, bool noreldetection) |
| 5819 | { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5820 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5821 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5822 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5823 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5824 | if (noreldetection) |
| 5825 | tabla_turn_onoff_rel_detection(codec, false); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5826 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5827 | /* Turn on the override */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5828 | if (!override_bypass) |
| 5829 | 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] | 5830 | if (dce) { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5831 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5832 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
| 5833 | 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] | 5834 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5835 | tabla->mbhc_data.t_sta_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5836 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5837 | usleep_range(tabla->mbhc_data.t_dce, |
| 5838 | tabla->mbhc_data.t_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5839 | bias_value = tabla_codec_read_dce_result(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5840 | } else { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5841 | 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] | 5842 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5843 | 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] | 5844 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5845 | tabla->mbhc_data.t_sta_dce); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5846 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5847 | usleep_range(tabla->mbhc_data.t_sta, |
| 5848 | tabla->mbhc_data.t_sta); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5849 | bias_value = tabla_codec_read_sta_result(codec); |
| 5850 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5851 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5852 | } |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5853 | /* Turn off the override after measuring mic voltage */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5854 | if (!override_bypass) |
| 5855 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 5856 | |
| 5857 | if (noreldetection) |
| 5858 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5859 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5860 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5861 | return bias_value; |
| 5862 | } |
| 5863 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5864 | static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5865 | bool norel) |
| 5866 | { |
| 5867 | return __tabla_codec_sta_dce(codec, dce, false, norel); |
| 5868 | } |
| 5869 | |
| 5870 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5871 | static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5872 | { |
| 5873 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5874 | short bias_value; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5875 | u8 cfilt_mode = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5876 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5877 | pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5878 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5879 | pr_err("Error, no tabla calibration\n"); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5880 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5883 | if (!tabla->mclk_enabled) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 5884 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5885 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5886 | tabla_enable_rx_bias(codec, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5887 | tabla_codec_enable_clock_block(codec, 1); |
| 5888 | } |
| 5889 | |
| 5890 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5891 | if (!tabla->mbhc_cfg.micbias_always_on) { |
| 5892 | /* Make sure CFILT is in fast mode, save current mode */ |
| 5893 | cfilt_mode = snd_soc_read(codec, |
| 5894 | tabla->mbhc_bias_regs.cfilt_ctl); |
| 5895 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 5896 | 0x70, 0x00); |
| 5897 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 5898 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5899 | 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] | 5900 | |
| 5901 | 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] | 5902 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5903 | |
| 5904 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80); |
| 5905 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C); |
| 5906 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40); |
| 5907 | |
| 5908 | 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] | 5909 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5910 | 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] | 5911 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5912 | 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] | 5913 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5914 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5915 | tabla_codec_calibrate_hs_polling(codec); |
| 5916 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5917 | /* don't flip override */ |
| 5918 | bias_value = __tabla_codec_sta_dce(codec, 1, true, true); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 5919 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 5920 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 5921 | 0x40, cfilt_mode); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5922 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5923 | |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5924 | return bias_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5925 | } |
| 5926 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5927 | static int tabla_cancel_btn_work(struct tabla_priv *tabla) |
| 5928 | { |
| 5929 | int r = 0; |
| 5930 | struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent); |
| 5931 | |
| 5932 | if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) { |
| 5933 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 5934 | * we have to unlock from here instead btn_work */ |
| 5935 | wcd9xxx_unlock_sleep(core); |
| 5936 | r = 1; |
| 5937 | } |
| 5938 | return r; |
| 5939 | } |
| 5940 | |
| 5941 | /* called under codec_resource_lock acquisition */ |
| 5942 | void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5943 | { |
| 5944 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5945 | u8 wg_time; |
| 5946 | |
| 5947 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5948 | wg_time += 1; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5949 | |
| 5950 | /* If headphone PA is on, check if userspace receives |
| 5951 | * removal event to sync-up PA's state */ |
| 5952 | if (tabla_is_hph_pa_on(codec)) { |
| 5953 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 5954 | set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5955 | set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5956 | } else { |
| 5957 | pr_debug("%s PA is off\n", __func__); |
| 5958 | } |
| 5959 | |
| 5960 | if (tabla_is_hph_dac_on(codec, 1)) |
| 5961 | set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5962 | if (tabla_is_hph_dac_on(codec, 0)) |
| 5963 | set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5964 | |
| 5965 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 5966 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL, |
Gopikrishnaiah Anandan | 3b230b2 | 2012-12-07 11:36:58 -0500 | [diff] [blame] | 5967 | 0x80, 0x00); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5968 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5969 | 0xC0, 0x00); |
| 5970 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5971 | } |
| 5972 | |
| 5973 | static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla) |
| 5974 | { |
| 5975 | bool pa_turned_on = false; |
| 5976 | struct snd_soc_codec *codec = tabla->codec; |
| 5977 | u8 wg_time; |
| 5978 | |
| 5979 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5980 | wg_time += 1; |
| 5981 | |
| 5982 | if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 5983 | &tabla->hph_pa_dac_state)) { |
| 5984 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 5985 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5986 | 0xC0, 0xC0); |
| 5987 | } |
| 5988 | if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 5989 | &tabla->hph_pa_dac_state)) { |
| 5990 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 5991 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5992 | 0xC0, 0xC0); |
| 5993 | } |
| 5994 | |
| 5995 | if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 5996 | &tabla->hph_pa_dac_state)) { |
| 5997 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 5998 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10, |
| 5999 | 1 << 4); |
| 6000 | pa_turned_on = true; |
| 6001 | } |
| 6002 | if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 6003 | &tabla->hph_pa_dac_state)) { |
| 6004 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 6005 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20, |
| 6006 | 1 << 5); |
| 6007 | pa_turned_on = true; |
| 6008 | } |
| 6009 | |
| 6010 | if (pa_turned_on) { |
| 6011 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 6012 | __func__); |
| 6013 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 6014 | } |
| 6015 | } |
| 6016 | |
| 6017 | /* called under codec_resource_lock acquisition */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6018 | static void tabla_codec_enable_mbhc_micbias(struct snd_soc_codec *codec, |
| 6019 | bool enable) |
| 6020 | { |
| 6021 | int r; |
| 6022 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 6023 | |
| 6024 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 6025 | return; |
| 6026 | if (enable) { |
| 6027 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6028 | tabla_codec_update_cfilt_usage(codec, |
| 6029 | tabla->mbhc_bias_regs.cfilt_sel, 1); |
| 6030 | r = snd_soc_dapm_force_enable_pin(&codec->dapm, |
| 6031 | "MIC BIAS2 Power External"); |
| 6032 | snd_soc_dapm_sync(&codec->dapm); |
| 6033 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6034 | pr_debug("%s: Turning on MICBIAS2 r %d\n", __func__, r); |
| 6035 | } else { |
| 6036 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6037 | r = snd_soc_dapm_disable_pin(&codec->dapm, |
| 6038 | "MIC BIAS2 Power External"); |
| 6039 | snd_soc_dapm_sync(&codec->dapm); |
| 6040 | tabla_codec_update_cfilt_usage(codec, |
| 6041 | tabla->mbhc_bias_regs.cfilt_sel, 0); |
| 6042 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6043 | pr_debug("%s: Turning off MICBIAS2 r %d\n", __func__, r); |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6048 | static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 6049 | enum snd_jack_types jack_type) |
| 6050 | { |
| 6051 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6052 | pr_debug("%s: enter insertion %d hph_status %x\n", |
| 6053 | __func__, insertion, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6054 | if (!insertion) { |
| 6055 | /* Report removal */ |
| 6056 | tabla->hph_status &= ~jack_type; |
| 6057 | if (tabla->mbhc_cfg.headset_jack) { |
| 6058 | /* cancel possibly scheduled btn work and |
| 6059 | * report release if we reported button press */ |
| 6060 | if (tabla_cancel_btn_work(tabla)) { |
| 6061 | pr_debug("%s: button press is canceled\n", |
| 6062 | __func__); |
| 6063 | } else if (tabla->buttons_pressed) { |
| 6064 | pr_debug("%s: Reporting release for reported " |
| 6065 | "button press %d\n", __func__, |
| 6066 | jack_type); |
| 6067 | tabla_snd_soc_jack_report(tabla, |
| 6068 | tabla->mbhc_cfg.button_jack, 0, |
| 6069 | tabla->buttons_pressed); |
| 6070 | tabla->buttons_pressed &= |
| 6071 | ~TABLA_JACK_BUTTON_MASK; |
| 6072 | } |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6073 | if (jack_type == SND_JACK_HEADSET) |
| 6074 | tabla_codec_enable_mbhc_micbias(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6075 | pr_debug("%s: Reporting removal %d(%x)\n", __func__, |
| 6076 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6077 | tabla_snd_soc_jack_report(tabla, |
| 6078 | tabla->mbhc_cfg.headset_jack, |
| 6079 | tabla->hph_status, |
| 6080 | TABLA_JACK_MASK); |
| 6081 | } |
| 6082 | tabla_set_and_turnoff_hph_padac(codec); |
| 6083 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6084 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6085 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6086 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6087 | tabla->current_plug = PLUG_TYPE_NONE; |
| 6088 | tabla->mbhc_polling_active = false; |
| 6089 | } else { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6090 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 6091 | /* Report removal of current jack type */ |
| 6092 | if (tabla->hph_status != jack_type && |
| 6093 | tabla->mbhc_cfg.headset_jack) { |
| 6094 | pr_debug("%s: Reporting removal (%x)\n", |
| 6095 | __func__, tabla->hph_status); |
| 6096 | tabla_snd_soc_jack_report(tabla, |
| 6097 | tabla->mbhc_cfg.headset_jack, |
| 6098 | 0, TABLA_JACK_MASK); |
| 6099 | tabla->hph_status = 0; |
| 6100 | } |
| 6101 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6102 | /* Report insertion */ |
| 6103 | tabla->hph_status |= jack_type; |
| 6104 | |
| 6105 | if (jack_type == SND_JACK_HEADPHONE) |
| 6106 | tabla->current_plug = PLUG_TYPE_HEADPHONE; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6107 | else if (jack_type == SND_JACK_UNSUPPORTED) |
| 6108 | tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6109 | else if (jack_type == SND_JACK_HEADSET) { |
| 6110 | tabla->mbhc_polling_active = true; |
| 6111 | tabla->current_plug = PLUG_TYPE_HEADSET; |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6112 | tabla_codec_enable_mbhc_micbias(codec, true); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6113 | } else if (jack_type == SND_JACK_LINEOUT) |
| 6114 | tabla->current_plug = PLUG_TYPE_HIGH_HPH; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6115 | if (tabla->mbhc_cfg.headset_jack) { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6116 | pr_debug("%s: Reporting insertion %d(%x)\n", __func__, |
| 6117 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6118 | tabla_snd_soc_jack_report(tabla, |
| 6119 | tabla->mbhc_cfg.headset_jack, |
| 6120 | tabla->hph_status, |
| 6121 | TABLA_JACK_MASK); |
| 6122 | } |
| 6123 | tabla_clr_and_turnon_hph_padac(tabla); |
| 6124 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6125 | pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6126 | } |
| 6127 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6128 | static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6129 | int insertion, int trigger, |
| 6130 | bool padac_off) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6131 | { |
| 6132 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6133 | int central_bias_enabled = 0; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6134 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6135 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6136 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6137 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6138 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6139 | pr_debug("%s: enter insertion(%d) trigger(0x%x)\n", |
| 6140 | __func__, insertion, trigger); |
| 6141 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6142 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6143 | pr_err("Error, no tabla calibration\n"); |
| 6144 | return -EINVAL; |
| 6145 | } |
| 6146 | |
| 6147 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 6148 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6149 | /* Make sure mic bias and Mic line schmitt trigger |
| 6150 | * are turned OFF |
| 6151 | */ |
| 6152 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 6153 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 6154 | |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6155 | if (insertion) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 6156 | pr_debug("%s: setup for insertion\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6157 | tabla_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6158 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6159 | /* DAPM can manipulate PA/DAC bits concurrently */ |
| 6160 | if (padac_off == true) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6161 | tabla_set_and_turnoff_hph_padac(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6162 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6163 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6164 | if (trigger & MBHC_USE_HPHL_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6165 | /* Enable HPH Schmitt Trigger */ |
| 6166 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11, |
| 6167 | 0x11); |
| 6168 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C, |
| 6169 | plug_det->hph_current << 2); |
| 6170 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02, |
| 6171 | 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6172 | } |
| 6173 | if (trigger & MBHC_USE_MB_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6174 | /* enable the mic line schmitt trigger */ |
| 6175 | snd_soc_update_bits(codec, |
| 6176 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6177 | 0x60, plug_det->mic_current << 5); |
| 6178 | snd_soc_update_bits(codec, |
| 6179 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6180 | 0x80, 0x80); |
| 6181 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
| 6182 | snd_soc_update_bits(codec, |
| 6183 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 6184 | 0x00); |
| 6185 | snd_soc_update_bits(codec, |
| 6186 | tabla->mbhc_bias_regs.mbhc_reg, |
| 6187 | 0x10, 0x10); |
| 6188 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6189 | |
| 6190 | /* setup for insetion detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6191 | 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] | 6192 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6193 | pr_debug("setup for removal detection\n"); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6194 | /* Make sure the HPH schmitt trigger is OFF */ |
| 6195 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00); |
| 6196 | |
| 6197 | /* enable the mic line schmitt trigger */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6198 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 6199 | 0x01, 0x00); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6200 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6201 | plug_det->mic_current << 5); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6202 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 6203 | 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6204 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 6205 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 6206 | 0x10, 0x10); |
| 6207 | |
| 6208 | /* Setup for low power removal detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6209 | 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] | 6210 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6211 | |
| 6212 | if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6213 | /* called called by interrupt */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6214 | if (!(tabla->clock_active)) { |
| 6215 | tabla_codec_enable_config_mode(codec, 1); |
| 6216 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6217 | 0x06, 0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6218 | usleep_range(generic->t_shutdown_plug_rem, |
| 6219 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6220 | tabla_codec_enable_config_mode(codec, 0); |
| 6221 | } else |
| 6222 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6223 | 0x06, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 6226 | 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] | 6227 | |
| 6228 | /* If central bandgap disabled */ |
| 6229 | if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) { |
| 6230 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6231 | usleep_range(generic->t_bg_fast_settle, |
| 6232 | generic->t_bg_fast_settle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6233 | central_bias_enabled = 1; |
| 6234 | } |
| 6235 | |
| 6236 | /* If LDO_H disabled */ |
| 6237 | if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) { |
| 6238 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0); |
| 6239 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6240 | usleep_range(generic->t_ldoh, generic->t_ldoh); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6241 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0); |
| 6242 | |
| 6243 | if (central_bias_enabled) |
| 6244 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0); |
| 6245 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6246 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6247 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6248 | tabla->mbhc_cfg.micbias); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6249 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6250 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6251 | 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] | 6252 | pr_debug("%s: leave\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6253 | return 0; |
| 6254 | } |
| 6255 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6256 | static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 6257 | s16 vin_mv) |
| 6258 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6259 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6260 | s16 diff, zero; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6261 | u32 mb_mv, in; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6262 | u16 value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6263 | |
| 6264 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6265 | mb_mv = tabla->mbhc_data.micb_mv; |
| 6266 | |
| 6267 | if (mb_mv == 0) { |
| 6268 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 6269 | return -EINVAL; |
| 6270 | } |
| 6271 | |
| 6272 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6273 | diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z); |
| 6274 | zero = (tabla->mbhc_data.dce_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6275 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6276 | diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z); |
| 6277 | zero = (tabla->mbhc_data.sta_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6278 | } |
| 6279 | in = (u32) diff * vin_mv; |
| 6280 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6281 | value = (u16) (in / mb_mv) + zero; |
| 6282 | return value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 6286 | u16 bias_value) |
| 6287 | { |
| 6288 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6289 | s16 value, z, mb; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6290 | s32 mv; |
| 6291 | |
| 6292 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6293 | value = bias_value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6294 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6295 | z = (tabla->mbhc_data.dce_z); |
| 6296 | mb = (tabla->mbhc_data.dce_mb); |
| 6297 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6298 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6299 | z = (tabla->mbhc_data.sta_z); |
| 6300 | mb = (tabla->mbhc_data.sta_mb); |
| 6301 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | return mv; |
| 6305 | } |
| 6306 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6307 | static void btn_lpress_fn(struct work_struct *work) |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6308 | { |
| 6309 | struct delayed_work *delayed_work; |
| 6310 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6311 | short bias_value; |
| 6312 | int dce_mv, sta_mv; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6313 | struct wcd9xxx *core; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6314 | |
| 6315 | pr_debug("%s:\n", __func__); |
| 6316 | |
| 6317 | delayed_work = to_delayed_work(work); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6318 | tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6319 | core = dev_get_drvdata(tabla->codec->dev->parent); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6320 | |
| 6321 | if (tabla) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6322 | if (tabla->mbhc_cfg.button_jack) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6323 | bias_value = tabla_codec_read_sta_result(tabla->codec); |
| 6324 | sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6325 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6326 | bias_value = tabla_codec_read_dce_result(tabla->codec); |
| 6327 | dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6328 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6329 | pr_debug("%s: Reporting long button press event" |
| 6330 | " STA: %d, DCE: %d\n", __func__, |
| 6331 | sta_mv, dce_mv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6332 | tabla_snd_soc_jack_report(tabla, |
| 6333 | tabla->mbhc_cfg.button_jack, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6334 | tabla->buttons_pressed, |
| 6335 | tabla->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6336 | } |
| 6337 | } else { |
| 6338 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6339 | } |
| 6340 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6341 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6342 | wcd9xxx_unlock_sleep(core); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6343 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 6344 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6345 | static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt) |
| 6346 | { |
| 6347 | u16 reg; |
| 6348 | |
| 6349 | switch (cfilt) { |
| 6350 | case TABLA_CFILT1_SEL: |
| 6351 | reg = TABLA_A_MICB_CFILT_1_CTL; |
| 6352 | break; |
| 6353 | case TABLA_CFILT2_SEL: |
| 6354 | reg = TABLA_A_MICB_CFILT_2_CTL; |
| 6355 | break; |
| 6356 | case TABLA_CFILT3_SEL: |
| 6357 | reg = TABLA_A_MICB_CFILT_3_CTL; |
| 6358 | break; |
| 6359 | default: |
| 6360 | BUG(); |
| 6361 | } |
| 6362 | return reg; |
| 6363 | } |
| 6364 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6365 | void tabla_mbhc_cal(struct snd_soc_codec *codec) |
| 6366 | { |
| 6367 | struct tabla_priv *tabla; |
| 6368 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6369 | u8 cfilt_mode, micbias2_cfilt_mode, bg_mode; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6370 | u8 ncic, nmeas, navg; |
| 6371 | u32 mclk_rate; |
| 6372 | u32 dce_wait, sta_wait; |
| 6373 | u8 *n_cic; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6374 | void *calibration; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6375 | u16 bias2_ctl; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6376 | |
| 6377 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6378 | calibration = tabla->mbhc_cfg.calibration; |
| 6379 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6380 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6381 | tabla_turn_onoff_rel_detection(codec, false); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6382 | |
| 6383 | /* First compute the DCE / STA wait times |
| 6384 | * depending on tunable parameters. |
| 6385 | * The value is computed in microseconds |
| 6386 | */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6387 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6388 | 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] | 6389 | ncic = n_cic[tabla_codec_mclk_index(tabla)]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6390 | nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 6391 | navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 6392 | mclk_rate = tabla->mbhc_cfg.mclk_rate; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 6393 | dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000); |
| 6394 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6395 | |
| 6396 | tabla->mbhc_data.t_dce = dce_wait; |
| 6397 | tabla->mbhc_data.t_sta = sta_wait; |
| 6398 | |
| 6399 | /* LDOH and CFILT are already configured during pdata handling. |
| 6400 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 6401 | * Need to restore defaults once calculation is done. |
| 6402 | */ |
| 6403 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6404 | micbias2_cfilt_mode = |
| 6405 | snd_soc_read(codec, tabla_get_cfilt_reg(codec, |
| 6406 | tabla->pdata->micbias.bias2_cfilt_sel)); |
| 6407 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 6408 | TABLA_CFILT_FAST_MODE); |
| 6409 | snd_soc_update_bits(codec, |
| 6410 | tabla_get_cfilt_reg(codec, |
| 6411 | tabla->pdata->micbias.bias2_cfilt_sel), |
| 6412 | 0x40, TABLA_CFILT_FAST_MODE); |
| 6413 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6414 | bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 6415 | 0x02); |
| 6416 | |
| 6417 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 6418 | * to perform ADC calibration |
| 6419 | */ |
| 6420 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6421 | tabla->mbhc_cfg.micbias << 5); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6422 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 6423 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60); |
| 6424 | snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78); |
| 6425 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 6426 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6427 | /* MICBIAS2 routing for calibration */ |
| 6428 | bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL); |
| 6429 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2); |
| 6430 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, |
| 6431 | snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg)); |
| 6432 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6433 | /* DCE measurement for 0 volts */ |
| 6434 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6435 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6436 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6437 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 6438 | usleep_range(100, 100); |
| 6439 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6440 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 6441 | tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec); |
| 6442 | |
| 6443 | /* DCE measurment for MB voltage */ |
| 6444 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6445 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
| 6446 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 6447 | usleep_range(100, 100); |
| 6448 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 6449 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 6450 | tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec); |
| 6451 | |
| 6452 | /* Sta measuremnt for 0 volts */ |
| 6453 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 6454 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6455 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6456 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 6457 | usleep_range(100, 100); |
| 6458 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6459 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 6460 | tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec); |
| 6461 | |
| 6462 | /* STA Measurement for MB Voltage */ |
| 6463 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 6464 | usleep_range(100, 100); |
| 6465 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 6466 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 6467 | tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec); |
| 6468 | |
| 6469 | /* Restore default settings. */ |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 6470 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl); |
| 6471 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 6472 | tabla->mbhc_cfg.micbias); |
| 6473 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6474 | 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] | 6475 | snd_soc_update_bits(codec, |
| 6476 | tabla_get_cfilt_reg(codec, |
| 6477 | tabla->pdata->micbias.bias2_cfilt_sel), 0x40, |
| 6478 | micbias2_cfilt_mode); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6479 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 6480 | cfilt_mode); |
| 6481 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 6482 | |
| 6483 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 6484 | usleep_range(100, 100); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6485 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6486 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6487 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det, |
| 6491 | const enum tabla_mbhc_btn_det_mem mem) |
| 6492 | { |
| 6493 | void *ret = &btn_det->_v_btn_low; |
| 6494 | |
| 6495 | switch (mem) { |
| 6496 | case TABLA_BTN_DET_GAIN: |
| 6497 | ret += sizeof(btn_det->_n_cic); |
| 6498 | case TABLA_BTN_DET_N_CIC: |
| 6499 | ret += sizeof(btn_det->_n_ready); |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6500 | case TABLA_BTN_DET_N_READY: |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6501 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 6502 | case TABLA_BTN_DET_V_BTN_HIGH: |
| 6503 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 6504 | case TABLA_BTN_DET_V_BTN_LOW: |
| 6505 | /* do nothing */ |
| 6506 | break; |
| 6507 | default: |
| 6508 | ret = NULL; |
| 6509 | } |
| 6510 | |
| 6511 | return ret; |
| 6512 | } |
| 6513 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6514 | static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v, |
| 6515 | bool tovddio) |
| 6516 | { |
| 6517 | int r; |
| 6518 | int vddio_k, mb_k; |
| 6519 | vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6520 | VDDIO_MICBIAS_MV); |
| 6521 | mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6522 | tabla->mbhc_data.micb_mv); |
| 6523 | if (tovddio) |
| 6524 | r = v * vddio_k / mb_k; |
| 6525 | else |
| 6526 | r = v * mb_k / vddio_k; |
| 6527 | return r; |
| 6528 | } |
| 6529 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6530 | static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6531 | { |
| 6532 | s16 deltamv; |
| 6533 | struct tabla_priv *tabla; |
| 6534 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6535 | |
| 6536 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6537 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6538 | |
| 6539 | tabla->mbhc_data.v_b1_h = |
| 6540 | tabla_codec_v_sta_dce(codec, DCE, |
| 6541 | mv + btn_det->v_btn_press_delta_cic); |
| 6542 | |
| 6543 | tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h; |
| 6544 | |
| 6545 | tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN; |
| 6546 | |
| 6547 | deltamv = mv + btn_det->v_btn_press_delta_sta; |
| 6548 | tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv); |
| 6549 | |
| 6550 | deltamv = mv + btn_det->v_btn_press_delta_cic; |
| 6551 | tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv); |
| 6552 | } |
| 6553 | |
| 6554 | static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6555 | { |
| 6556 | tabla_mbhc_calc_rel_thres(codec, mv); |
| 6557 | tabla_codec_calibrate_rel(codec); |
| 6558 | } |
| 6559 | |
| 6560 | static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec) |
| 6561 | { |
| 6562 | struct tabla_priv *tabla; |
| 6563 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6564 | u16 *btn_high; |
| 6565 | |
| 6566 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6567 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6568 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH); |
| 6569 | |
| 6570 | return btn_high[btn_det->num_btn - 1]; |
| 6571 | } |
| 6572 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6573 | static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 6574 | { |
| 6575 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6576 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6577 | struct tabla_mbhc_plug_type_cfg *plug_type; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6578 | u8 *n_ready; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6579 | |
| 6580 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6581 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6582 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6583 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6584 | 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] | 6585 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6586 | tabla->mbhc_data.npoll = 4; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6587 | tabla->mbhc_data.nbounce_wait = 30; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6588 | } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6589 | tabla->mbhc_data.npoll = 7; |
| 6590 | tabla->mbhc_data.nbounce_wait = 23; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6591 | } |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6592 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6593 | tabla->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 6594 | (tabla->mbhc_cfg.mclk_rate / 1000) * |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6595 | n_ready[tabla_codec_mclk_index(tabla)]) + |
| 6596 | 10; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6597 | tabla->mbhc_data.v_ins_hu = |
| 6598 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 6599 | tabla->mbhc_data.v_ins_h = |
| 6600 | tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 6601 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6602 | tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW; |
| 6603 | if (tabla->mbhc_cfg.gpio) |
| 6604 | tabla->mbhc_data.v_inval_ins_high = |
| 6605 | TABLA_MBHC_FAKE_INSERT_HIGH; |
| 6606 | else |
| 6607 | tabla->mbhc_data.v_inval_ins_high = |
| 6608 | TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO; |
| 6609 | |
| 6610 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 6611 | tabla->mbhc_data.adj_v_hs_max = |
| 6612 | tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true); |
| 6613 | tabla->mbhc_data.adj_v_ins_hu = |
| 6614 | tabla_codec_v_sta_dce(codec, STA, |
| 6615 | tabla->mbhc_data.adj_v_hs_max); |
| 6616 | tabla->mbhc_data.adj_v_ins_h = |
| 6617 | tabla_codec_v_sta_dce(codec, DCE, |
| 6618 | tabla->mbhc_data.adj_v_hs_max); |
| 6619 | tabla->mbhc_data.v_inval_ins_low = |
| 6620 | tabla_scale_v_micb_vddio(tabla, |
| 6621 | tabla->mbhc_data.v_inval_ins_low, |
| 6622 | false); |
| 6623 | tabla->mbhc_data.v_inval_ins_high = |
| 6624 | tabla_scale_v_micb_vddio(tabla, |
| 6625 | tabla->mbhc_data.v_inval_ins_high, |
| 6626 | false); |
| 6627 | } |
| 6628 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6629 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6630 | |
| 6631 | tabla->mbhc_data.v_no_mic = |
| 6632 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 6633 | } |
| 6634 | |
| 6635 | void tabla_mbhc_init(struct snd_soc_codec *codec) |
| 6636 | { |
| 6637 | struct tabla_priv *tabla; |
| 6638 | struct tabla_mbhc_general_cfg *generic; |
| 6639 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6640 | int n; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6641 | u8 *n_cic, *gain; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6642 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6643 | |
| 6644 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6645 | generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
| 6646 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6647 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6648 | for (n = 0; n < 8; n++) { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 6649 | if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6650 | snd_soc_update_bits(codec, |
| 6651 | TABLA_A_CDC_MBHC_FEATURE_B1_CFG, |
| 6652 | 0x07, n); |
| 6653 | snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG, |
| 6654 | btn_det->c[n]); |
| 6655 | } |
| 6656 | } |
| 6657 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07, |
| 6658 | btn_det->nc); |
| 6659 | |
| 6660 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
| 6661 | 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] | 6662 | n_cic[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6663 | |
| 6664 | 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] | 6665 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78, |
| 6666 | gain[tabla_codec_mclk_index(tabla)] << 3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6667 | |
| 6668 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 6669 | generic->mbhc_nsa << 4); |
| 6670 | |
| 6671 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 6672 | btn_det->n_meas); |
| 6673 | |
| 6674 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 6675 | |
| 6676 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 6677 | |
| 6678 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78, |
| 6679 | btn_det->mbhc_nsc << 3); |
| 6680 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6681 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03, |
| 6682 | TABLA_MICBIAS2); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6683 | |
| 6684 | 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] | 6685 | |
| 6686 | 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] | 6687 | |
| 6688 | /* override mbhc's micbias */ |
| 6689 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 6690 | tabla->mbhc_cfg.micbias); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6691 | } |
| 6692 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 6693 | static bool tabla_mbhc_fw_validate(const struct firmware *fw) |
| 6694 | { |
| 6695 | u32 cfg_offset; |
| 6696 | struct tabla_mbhc_imped_detect_cfg *imped_cfg; |
| 6697 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 6698 | |
| 6699 | if (fw->size < TABLA_MBHC_CAL_MIN_SIZE) |
| 6700 | return false; |
| 6701 | |
| 6702 | /* previous check guarantees that there is enough fw data up |
| 6703 | * to num_btn |
| 6704 | */ |
| 6705 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 6706 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 6707 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 6708 | return false; |
| 6709 | |
| 6710 | /* previous check guarantees that there is enough fw data up |
| 6711 | * to start of impedance detection configuration |
| 6712 | */ |
| 6713 | imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 6714 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 6715 | |
| 6716 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ)) |
| 6717 | return false; |
| 6718 | |
| 6719 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 6720 | return false; |
| 6721 | |
| 6722 | return true; |
| 6723 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6724 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6725 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6726 | static int tabla_determine_button(const struct tabla_priv *priv, |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6727 | const s32 micmv) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6728 | { |
| 6729 | s16 *v_btn_low, *v_btn_high; |
| 6730 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6731 | int i, btn = -1; |
| 6732 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6733 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6734 | v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW); |
| 6735 | v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6736 | TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6737 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6738 | for (i = 0; i < btn_det->num_btn; i++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6739 | if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6740 | btn = i; |
| 6741 | break; |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | if (btn == -1) |
| 6746 | 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] | 6747 | __func__, micmv); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6748 | |
| 6749 | return btn; |
| 6750 | } |
| 6751 | |
| 6752 | static int tabla_get_button_mask(const int btn) |
| 6753 | { |
| 6754 | int mask = 0; |
| 6755 | switch (btn) { |
| 6756 | case 0: |
| 6757 | mask = SND_JACK_BTN_0; |
| 6758 | break; |
| 6759 | case 1: |
| 6760 | mask = SND_JACK_BTN_1; |
| 6761 | break; |
| 6762 | case 2: |
| 6763 | mask = SND_JACK_BTN_2; |
| 6764 | break; |
| 6765 | case 3: |
| 6766 | mask = SND_JACK_BTN_3; |
| 6767 | break; |
| 6768 | case 4: |
| 6769 | mask = SND_JACK_BTN_4; |
| 6770 | break; |
| 6771 | case 5: |
| 6772 | mask = SND_JACK_BTN_5; |
| 6773 | break; |
| 6774 | case 6: |
| 6775 | mask = SND_JACK_BTN_6; |
| 6776 | break; |
| 6777 | case 7: |
| 6778 | mask = SND_JACK_BTN_7; |
| 6779 | break; |
| 6780 | } |
| 6781 | return mask; |
| 6782 | } |
| 6783 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6784 | static irqreturn_t tabla_dce_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6785 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6786 | int i, mask; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6787 | short dce, sta; |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6788 | s32 mv, mv_s, stamv, stamv_s; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6789 | bool vddio; |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6790 | u16 *btn_high; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6791 | int btn = -1, meas = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6792 | struct tabla_priv *priv = data; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6793 | const struct tabla_mbhc_btn_detect_cfg *d = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6794 | TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6795 | short btnmeas[d->n_btn_meas + 1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6796 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6797 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6798 | int n_btn_meas = d->n_btn_meas; |
| 6799 | 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] | 6800 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6801 | pr_debug("%s: enter\n", __func__); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6802 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6803 | 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] | 6804 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6805 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 6806 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 6807 | __func__); |
| 6808 | goto done; |
| 6809 | } |
| 6810 | |
| 6811 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 6812 | |
| 6813 | if (!priv->mbhc_polling_active) { |
| 6814 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 6815 | __func__); |
| 6816 | goto done; |
| 6817 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6818 | |
| 6819 | dce = tabla_codec_read_dce_result(codec); |
| 6820 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6821 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6822 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 6823 | if (priv->in_gpio_handler) { |
| 6824 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 6825 | __func__); |
| 6826 | btn = -1; |
| 6827 | goto done; |
| 6828 | } |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 6829 | vddio = !priv->mbhc_cfg.micbias_always_on && |
| 6830 | (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6831 | priv->mbhc_micbias_switched); |
| 6832 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6833 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6834 | if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) { |
| 6835 | if (priv->mbhc_last_resume && |
| 6836 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 6837 | pr_debug("%s: Button is already released shortly after " |
| 6838 | "resume\n", __func__); |
| 6839 | n_btn_meas = 0; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6840 | } |
| 6841 | } |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 6842 | |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6843 | /* save hw dce */ |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6844 | btnmeas[meas++] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6845 | pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__, |
| 6846 | dce, mv, mv_s, btnmeas[0]); |
| 6847 | if (n_btn_meas == 0) { |
| 6848 | sta = tabla_codec_read_sta_result(codec); |
| 6849 | stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta); |
| 6850 | if (vddio) |
| 6851 | stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false); |
| 6852 | btn = tabla_determine_button(priv, stamv_s); |
| 6853 | pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__, |
| 6854 | sta, stamv, stamv_s, btn); |
| 6855 | BUG_ON(meas != 1); |
| 6856 | if (btnmeas[0] != btn) |
| 6857 | btn = -1; |
| 6858 | } |
| 6859 | |
| 6860 | /* determine pressed button */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6861 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6862 | dce = tabla_codec_sta_dce(codec, 1, false); |
| 6863 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6864 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6865 | |
| 6866 | btnmeas[meas] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6867 | pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n", |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6868 | __func__, meas, dce, mv, mv_s, btnmeas[meas]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6869 | /* if large enough measurements are collected, |
| 6870 | * start to check if last all n_btn_con measurements were |
| 6871 | * in same button low/high range */ |
| 6872 | if (meas + 1 >= d->n_btn_con) { |
| 6873 | for (i = 0; i < d->n_btn_con; i++) |
| 6874 | if ((btnmeas[meas] < 0) || |
| 6875 | (btnmeas[meas] != btnmeas[meas - i])) |
| 6876 | break; |
| 6877 | if (i == d->n_btn_con) { |
| 6878 | /* button pressed */ |
| 6879 | btn = btnmeas[meas]; |
| 6880 | break; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6881 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 6882 | /* if left measurements are less than n_btn_con, |
| 6883 | * it's impossible to find button number */ |
| 6884 | break; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6885 | } |
| 6886 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6887 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6888 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6889 | if (btn >= 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6890 | if (priv->in_gpio_handler) { |
| 6891 | pr_debug("%s: GPIO already triggered, ignore button " |
| 6892 | "press\n", __func__); |
| 6893 | goto done; |
| 6894 | } |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6895 | /* narrow down release threshold */ |
| 6896 | tabla_mbhc_set_rel_thres(codec, btn_high[btn]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6897 | mask = tabla_get_button_mask(btn); |
| 6898 | priv->buttons_pressed |= mask; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6899 | wcd9xxx_lock_sleep(core); |
| 6900 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 6901 | msecs_to_jiffies(400)) == 0) { |
| 6902 | WARN(1, "Button pressed twice without release" |
| 6903 | "event\n"); |
| 6904 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6905 | } |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6906 | } else { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6907 | pr_debug("%s: bogus button press, too short press?\n", |
| 6908 | __func__); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6909 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6910 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6911 | done: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6912 | pr_debug("%s: leave\n", __func__); |
| 6913 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6914 | return IRQ_HANDLED; |
| 6915 | } |
| 6916 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6917 | static int tabla_is_fake_press(struct tabla_priv *priv) |
| 6918 | { |
| 6919 | int i; |
| 6920 | int r = 0; |
| 6921 | struct snd_soc_codec *codec = priv->codec; |
| 6922 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6923 | s16 mb_v, v_ins_hu, v_ins_h; |
| 6924 | |
| 6925 | v_ins_hu = tabla_get_current_v_ins(priv, true); |
| 6926 | v_ins_h = tabla_get_current_v_ins(priv, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6927 | |
| 6928 | for (i = 0; i < dces; i++) { |
| 6929 | usleep_range(10000, 10000); |
| 6930 | if (i == 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6931 | mb_v = tabla_codec_sta_dce(codec, 0, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6932 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 6933 | tabla_codec_sta_dce_v(codec, 0, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6934 | if (mb_v < (s16)priv->mbhc_data.v_b1_hu || |
| 6935 | mb_v > v_ins_hu) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6936 | r = 1; |
| 6937 | break; |
| 6938 | } |
| 6939 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6940 | mb_v = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6941 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 6942 | tabla_codec_sta_dce_v(codec, 1, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6943 | if (mb_v < (s16)priv->mbhc_data.v_b1_h || |
| 6944 | mb_v > v_ins_h) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6945 | r = 1; |
| 6946 | break; |
| 6947 | } |
| 6948 | } |
| 6949 | } |
| 6950 | |
| 6951 | return r; |
| 6952 | } |
| 6953 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6954 | static irqreturn_t tabla_release_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6955 | { |
Joonwoo Park | e5d3aa9 | 2012-01-11 14:47:15 -0800 | [diff] [blame] | 6956 | int ret; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6957 | struct tabla_priv *priv = data; |
| 6958 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6959 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6960 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6961 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6962 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6963 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6964 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6965 | tabla_codec_drive_v_to_micbias(codec, 10000); |
| 6966 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6967 | if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6968 | ret = tabla_cancel_btn_work(priv); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6969 | if (ret == 0) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6970 | pr_debug("%s: Reporting long button release event\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6971 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6972 | if (priv->mbhc_cfg.button_jack) |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6973 | tabla_snd_soc_jack_report(priv, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6974 | priv->mbhc_cfg.button_jack, 0, |
| 6975 | priv->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6976 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6977 | if (tabla_is_fake_press(priv)) { |
| 6978 | pr_debug("%s: Fake button press interrupt\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6979 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6980 | } else if (priv->mbhc_cfg.button_jack) { |
| 6981 | if (priv->in_gpio_handler) { |
| 6982 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 6983 | __func__); |
| 6984 | } else { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6985 | pr_debug("%s: Reporting short button " |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6986 | "press and release\n", |
| 6987 | __func__); |
| 6988 | tabla_snd_soc_jack_report(priv, |
| 6989 | priv->mbhc_cfg.button_jack, |
| 6990 | priv->buttons_pressed, |
| 6991 | priv->buttons_pressed); |
| 6992 | tabla_snd_soc_jack_report(priv, |
| 6993 | priv->mbhc_cfg.button_jack, 0, |
| 6994 | priv->buttons_pressed); |
| 6995 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6996 | } |
| 6997 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6998 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6999 | priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK; |
| 7000 | } |
| 7001 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 7002 | /* revert narrowed release threshold */ |
| 7003 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7004 | tabla_codec_calibrate_hs_polling(codec); |
| 7005 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7006 | if (priv->mbhc_cfg.gpio) |
| 7007 | msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7008 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7009 | tabla_codec_start_hs_polling(codec); |
| 7010 | |
| 7011 | pr_debug("%s: leave\n", __func__); |
| 7012 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7013 | return IRQ_HANDLED; |
| 7014 | } |
| 7015 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7016 | static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 7017 | { |
| 7018 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7019 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7020 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7021 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 7022 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7023 | tabla_codec_enable_config_mode(codec, 1); |
| 7024 | |
| 7025 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 7026 | 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] | 7027 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7028 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 7029 | |
| 7030 | usleep_range(generic->t_shutdown_plug_rem, |
| 7031 | generic->t_shutdown_plug_rem); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7032 | |
| 7033 | 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] | 7034 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7035 | tabla_codec_enable_config_mode(codec, 0); |
| 7036 | |
| 7037 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00); |
| 7038 | } |
| 7039 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7040 | static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7041 | { |
| 7042 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7043 | |
| 7044 | tabla_codec_shutdown_hs_removal_detect(codec); |
| 7045 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 7046 | if (!tabla->mclk_enabled) { |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 7047 | tabla_codec_disable_clock_block(codec); |
| 7048 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | tabla->mbhc_polling_active = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7052 | tabla->mbhc_state = MBHC_STATE_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7055 | static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data) |
| 7056 | { |
| 7057 | struct tabla_priv *tabla = data; |
| 7058 | struct snd_soc_codec *codec; |
| 7059 | |
| 7060 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 7061 | |
| 7062 | if (tabla) { |
| 7063 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7064 | if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) && |
| 7065 | (!tabla->hphrocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7066 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7067 | tabla->hphlocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7068 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7069 | 0x00); |
| 7070 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7071 | 0x10); |
| 7072 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7073 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7074 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7075 | tabla->hph_status |= SND_JACK_OC_HPHL; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7076 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7077 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7078 | tabla->mbhc_cfg.headset_jack, |
| 7079 | tabla->hph_status, |
| 7080 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7081 | } |
| 7082 | } else { |
| 7083 | pr_err("%s: Bad tabla private data\n", __func__); |
| 7084 | } |
| 7085 | |
| 7086 | return IRQ_HANDLED; |
| 7087 | } |
| 7088 | |
| 7089 | static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data) |
| 7090 | { |
| 7091 | struct tabla_priv *tabla = data; |
| 7092 | struct snd_soc_codec *codec; |
| 7093 | |
| 7094 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 7095 | |
| 7096 | if (tabla) { |
| 7097 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7098 | if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) && |
| 7099 | (!tabla->hphlocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7100 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 7101 | tabla->hphrocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7102 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7103 | 0x00); |
| 7104 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 7105 | 0x10); |
| 7106 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7107 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7108 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7109 | tabla->hph_status |= SND_JACK_OC_HPHR; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7110 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 7111 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7112 | tabla->mbhc_cfg.headset_jack, |
| 7113 | tabla->hph_status, |
| 7114 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7115 | } |
| 7116 | } else { |
| 7117 | pr_err("%s: Bad tabla private data\n", __func__); |
| 7118 | } |
| 7119 | |
| 7120 | return IRQ_HANDLED; |
| 7121 | } |
| 7122 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7123 | static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec, |
| 7124 | s32 mic_volt, bool highhph, bool *highv) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7125 | { |
| 7126 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7127 | bool invalid = false; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7128 | s16 v_hs_max; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7129 | |
| 7130 | /* Perform this check only when the high voltage headphone |
| 7131 | * needs to be considered as invalid |
| 7132 | */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7133 | v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7134 | *highv = mic_volt > v_hs_max; |
| 7135 | if (!highhph && *highv) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7136 | invalid = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7137 | else if (mic_volt < tabla->mbhc_data.v_inval_ins_high && |
| 7138 | (mic_volt > tabla->mbhc_data.v_inval_ins_low)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7139 | invalid = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7140 | |
| 7141 | return invalid; |
| 7142 | } |
| 7143 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7144 | static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec, |
| 7145 | int mic_volt, int mic_volt_prev, |
| 7146 | int threshold) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7147 | { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7148 | return abs(mic_volt - mic_volt_prev) > threshold; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7149 | } |
| 7150 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7151 | /* called under codec_resource_lock acquisition */ |
| 7152 | void tabla_find_plug_and_report(struct snd_soc_codec *codec, |
| 7153 | enum tabla_mbhc_plug_type plug_type) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7154 | { |
| 7155 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7156 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7157 | pr_debug("%s: enter current_plug(%d) new_plug(%d)\n", |
| 7158 | __func__, tabla->current_plug, plug_type); |
| 7159 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7160 | if (plug_type == PLUG_TYPE_HEADPHONE && |
| 7161 | tabla->current_plug == PLUG_TYPE_NONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7162 | /* Nothing was reported previously |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7163 | * report a headphone or unsupported |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7164 | */ |
| 7165 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7166 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7167 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7168 | if (!tabla->mbhc_cfg.detect_extn_cable) { |
| 7169 | if (tabla->current_plug == PLUG_TYPE_HEADSET) |
| 7170 | tabla_codec_report_plug(codec, 0, |
| 7171 | SND_JACK_HEADSET); |
| 7172 | else if (tabla->current_plug == PLUG_TYPE_HEADPHONE) |
| 7173 | tabla_codec_report_plug(codec, 0, |
| 7174 | SND_JACK_HEADPHONE); |
| 7175 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7176 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 7177 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7178 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 7179 | /* If Headphone was reported previously, this will |
| 7180 | * only report the mic line |
| 7181 | */ |
| 7182 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame] | 7183 | if (!tabla->mbhc_micbias_switched && |
| 7184 | tabla_is_hph_pa_on(codec)) { |
| 7185 | /*If the headphone path is on, switch the micbias |
| 7186 | to VDDIO to avoid noise due to button polling */ |
| 7187 | tabla_codec_switch_micbias(codec, 1); |
| 7188 | pr_debug("%s: HPH path is still up\n", __func__); |
| 7189 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7190 | msleep(100); |
| 7191 | tabla_codec_start_hs_polling(codec); |
| 7192 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7193 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7194 | /* High impedance device found. Report as LINEOUT*/ |
| 7195 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 7196 | tabla_codec_cleanup_hs_polling(codec); |
| 7197 | pr_debug("%s: setup mic trigger for further detection\n", |
| 7198 | __func__); |
| 7199 | tabla->lpi_enabled = true; |
| 7200 | /* |
| 7201 | * Do not enable HPHL trigger. If playback is active, |
| 7202 | * it might lead to continuous false HPHL triggers |
| 7203 | */ |
| 7204 | tabla_codec_enable_hs_detect(codec, 1, |
| 7205 | MBHC_USE_MB_TRIGGER, |
| 7206 | false); |
| 7207 | } else { |
| 7208 | if (tabla->current_plug == PLUG_TYPE_NONE) |
| 7209 | tabla_codec_report_plug(codec, 1, |
| 7210 | SND_JACK_HEADPHONE); |
| 7211 | tabla_codec_cleanup_hs_polling(codec); |
| 7212 | pr_debug("setup mic trigger for further detection\n"); |
| 7213 | tabla->lpi_enabled = true; |
| 7214 | tabla_codec_enable_hs_detect(codec, 1, |
| 7215 | MBHC_USE_MB_TRIGGER | |
| 7216 | MBHC_USE_HPHL_TRIGGER, |
| 7217 | false); |
| 7218 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7219 | } else { |
| 7220 | WARN(1, "Unexpected current plug_type %d, plug_type %d\n", |
| 7221 | tabla->current_plug, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7222 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7223 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | /* should be called under interrupt context that hold suspend */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7227 | static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla, |
| 7228 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7229 | { |
| 7230 | pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__); |
| 7231 | tabla->hs_detect_work_stop = false; |
| 7232 | wcd9xxx_lock_sleep(tabla->codec->control_data); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7233 | schedule_work(correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7234 | } |
| 7235 | |
| 7236 | /* called under codec_resource_lock acquisition */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7237 | static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla, |
| 7238 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7239 | { |
| 7240 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 7241 | tabla->hs_detect_work_stop = true; |
| 7242 | wmb(); |
| 7243 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7244 | if (cancel_work_sync(correct_plug_work)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7245 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 7246 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 7247 | } |
| 7248 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7249 | } |
| 7250 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7251 | static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla) |
| 7252 | { |
| 7253 | return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) != |
| 7254 | tabla->mbhc_cfg.gpio_level_insert); |
| 7255 | } |
| 7256 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7257 | /* called under codec_resource_lock acquisition */ |
| 7258 | static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on) |
| 7259 | { |
| 7260 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on); |
| 7261 | if (on) |
| 7262 | usleep_range(5000, 5000); |
| 7263 | } |
| 7264 | |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7265 | |
| 7266 | static void tabla_codec_onoff_vddio_switch(struct snd_soc_codec *codec, bool on) |
| 7267 | { |
| 7268 | bool override; |
| 7269 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7270 | |
| 7271 | pr_debug("%s: enter\n", __func__); |
| 7272 | if (on) { |
| 7273 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 7274 | if (!override) |
| 7275 | tabla_turn_onoff_override(codec, true); |
| 7276 | |
| 7277 | /* enable the vddio switch */ |
| 7278 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 7279 | 0x91, 0x81); |
| 7280 | |
| 7281 | /* deroute the override from MicBias2 to MicBias4 */ |
| 7282 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, |
| 7283 | 0x03, 0x03); |
| 7284 | |
| 7285 | usleep_range(MBHC_VDDIO_SWITCH_WAIT_MS * 1000, |
| 7286 | MBHC_VDDIO_SWITCH_WAIT_MS * 1000); |
| 7287 | |
| 7288 | if (!override) |
| 7289 | tabla_turn_onoff_override(codec, false); |
| 7290 | tabla->mbhc_micbias_switched = true; |
| 7291 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
| 7292 | |
| 7293 | } else { |
| 7294 | |
| 7295 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 7296 | 0x91, 0x00); |
| 7297 | |
| 7298 | /* reroute the override to MicBias2 */ |
| 7299 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, |
| 7300 | 0x03, 0x01); |
| 7301 | |
| 7302 | tabla->mbhc_micbias_switched = false; |
| 7303 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
| 7304 | } |
| 7305 | } |
| 7306 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7307 | /* called under codec_resource_lock acquisition and mbhc override = 1 */ |
| 7308 | static enum tabla_mbhc_plug_type |
| 7309 | tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph) |
| 7310 | { |
| 7311 | int i; |
| 7312 | bool gndswitch, vddioswitch; |
| 7313 | int scaled; |
| 7314 | struct tabla_mbhc_plug_type_cfg *plug_type_ptr; |
| 7315 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 7316 | const bool vddio = !tabla->mbhc_cfg.micbias_always_on && |
| 7317 | (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV); |
| 7318 | int num_det = (MBHC_NUM_DCE_PLUG_DETECT + vddio); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7319 | enum tabla_mbhc_plug_type plug_type[num_det]; |
| 7320 | s16 mb_v[num_det]; |
| 7321 | s32 mic_mv[num_det]; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7322 | bool inval; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7323 | bool highdelta = false; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7324 | bool ahighv = false, highv; |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7325 | bool gndmicswapped = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7326 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7327 | pr_debug("%s: enter\n", __func__); |
| 7328 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7329 | /* make sure override is on */ |
| 7330 | WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04)); |
| 7331 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7332 | /* GND and MIC swap detection requires at least 2 rounds of DCE */ |
| 7333 | BUG_ON(num_det < 2); |
| 7334 | |
| 7335 | plug_type_ptr = |
| 7336 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 7337 | |
| 7338 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7339 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7340 | /* performs DCEs for N times |
| 7341 | * 1st: check if voltage is in invalid range |
| 7342 | * 2nd - N-2nd: check voltage range and delta |
| 7343 | * N-1st: check voltage range, delta with HPHR GND switch |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7344 | * Nth: check voltage range with VDDIO switch */ |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7345 | for (i = 0; i < num_det; i++) { |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7346 | gndswitch = (i == (num_det - 2)); |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7347 | vddioswitch = (i == (num_det - 1)); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7348 | if (i == 0) { |
| 7349 | mb_v[i] = tabla_codec_setup_hs_polling(codec); |
| 7350 | 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] | 7351 | inval = tabla_is_inval_ins_range(codec, mic_mv[i], |
| 7352 | highhph, &highv); |
| 7353 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7354 | scaled = mic_mv[i]; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7355 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7356 | if (vddioswitch) |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7357 | tabla_codec_onoff_vddio_switch(codec, true); |
| 7358 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7359 | if (gndswitch) |
| 7360 | tabla_codec_hphr_gnd_switch(codec, true); |
| 7361 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 7362 | 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] | 7363 | if (vddioswitch) |
| 7364 | scaled = tabla_scale_v_micb_vddio(tabla, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7365 | mic_mv[i], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7366 | false); |
| 7367 | else |
| 7368 | scaled = mic_mv[i]; |
| 7369 | /* !gndswitch & vddioswitch means the previous DCE |
| 7370 | * was done with gndswitch, don't compare with DCE |
| 7371 | * with gndswitch */ |
| 7372 | highdelta = tabla_is_inval_ins_delta(codec, scaled, |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 7373 | mic_mv[i - 1], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7374 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV); |
| 7375 | inval = (tabla_is_inval_ins_range(codec, mic_mv[i], |
| 7376 | highhph, &highv) || |
| 7377 | highdelta); |
| 7378 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7379 | if (gndswitch) |
| 7380 | tabla_codec_hphr_gnd_switch(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7381 | if (vddioswitch) |
Simmi Pateriya | d60186a | 2012-11-27 13:50:11 +0530 | [diff] [blame] | 7382 | tabla_codec_onoff_vddio_switch(codec, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7383 | } |
| 7384 | 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] | 7385 | "VDDIO %d, inval %d\n", __func__, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7386 | i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7387 | vddioswitch, inval); |
| 7388 | /* don't need to run further DCEs */ |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7389 | if ((ahighv || !vddioswitch) && inval) |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7390 | break; |
| 7391 | mic_mv[i] = scaled; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 7392 | |
| 7393 | /* |
| 7394 | * claim UNSUPPORTED plug insertion when |
| 7395 | * good headset is detected but HPHR GND switch makes |
| 7396 | * delta difference |
| 7397 | */ |
| 7398 | if (i == (num_det - 2) && highdelta && !ahighv) |
| 7399 | gndmicswapped = true; |
| 7400 | else if (i == (num_det - 1) && inval) { |
| 7401 | if (gndmicswapped) |
| 7402 | plug_type[0] = PLUG_TYPE_GND_MIC_SWAP; |
| 7403 | else |
| 7404 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7405 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7406 | } |
| 7407 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7408 | for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) && |
| 7409 | i < num_det; i++) { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7410 | /* |
| 7411 | * If we are here, means none of the all |
| 7412 | * measurements are fake, continue plug type detection. |
| 7413 | * If all three measurements do not produce same |
| 7414 | * plug type, restart insertion detection |
| 7415 | */ |
| 7416 | if (mic_mv[i] < plug_type_ptr->v_no_mic) { |
| 7417 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 7418 | pr_debug("%s: Detect attempt %d, detected Headphone\n", |
| 7419 | __func__, i); |
| 7420 | } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) { |
| 7421 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 7422 | pr_debug("%s: Detect attempt %d, detected High " |
| 7423 | "Headphone\n", __func__, i); |
| 7424 | } else { |
| 7425 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 7426 | pr_debug("%s: Detect attempt %d, detected Headset\n", |
| 7427 | __func__, i); |
| 7428 | } |
| 7429 | |
| 7430 | if (i > 0 && (plug_type[i - 1] != plug_type[i])) { |
| 7431 | pr_err("%s: Detect attempt %d and %d are not same", |
| 7432 | __func__, i - 1, i); |
| 7433 | plug_type[0] = PLUG_TYPE_INVALID; |
| 7434 | inval = true; |
| 7435 | break; |
| 7436 | } |
| 7437 | } |
| 7438 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7439 | 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] | 7440 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7441 | return plug_type[0]; |
| 7442 | } |
| 7443 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7444 | static void tabla_hs_correct_gpio_plug(struct work_struct *work) |
| 7445 | { |
| 7446 | struct tabla_priv *tabla; |
| 7447 | struct snd_soc_codec *codec; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7448 | int retry = 0, pt_gnd_mic_swap_cnt = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7449 | bool correction = false; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7450 | enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7451 | unsigned long timeout; |
| 7452 | |
| 7453 | tabla = container_of(work, struct tabla_priv, hs_correct_plug_work); |
| 7454 | codec = tabla->codec; |
| 7455 | |
| 7456 | pr_debug("%s: enter\n", __func__); |
| 7457 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 7458 | |
| 7459 | /* Keep override on during entire plug type correction work. |
| 7460 | * |
| 7461 | * This is okay under the assumption that any GPIO irqs which use |
| 7462 | * MBHC block cancel and sync this work so override is off again |
| 7463 | * prior to GPIO interrupt handler's MBHC block usage. |
| 7464 | * Also while this correction work is running, we can guarantee |
| 7465 | * DAPM doesn't use any MBHC block as this work only runs with |
| 7466 | * headphone detection. |
| 7467 | */ |
| 7468 | tabla_turn_onoff_override(codec, true); |
| 7469 | |
| 7470 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7471 | while (!time_after(jiffies, timeout)) { |
| 7472 | ++retry; |
| 7473 | rmb(); |
| 7474 | if (tabla->hs_detect_work_stop) { |
| 7475 | pr_debug("%s: stop requested\n", __func__); |
| 7476 | break; |
| 7477 | } |
| 7478 | |
| 7479 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 7480 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 7481 | pr_debug("%s: GPIO value is low\n", __func__); |
| 7482 | break; |
| 7483 | } |
| 7484 | |
| 7485 | /* can race with removal interrupt */ |
| 7486 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7487 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7488 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7489 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7490 | pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n", |
| 7491 | __func__, retry, tabla->current_plug, plug_type); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7492 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7493 | pr_debug("Invalid plug in attempt # %d\n", retry); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7494 | if (!tabla->mbhc_cfg.detect_extn_cable && |
| 7495 | retry == NUM_ATTEMPTS_TO_REPORT && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7496 | tabla->current_plug == PLUG_TYPE_NONE) { |
| 7497 | tabla_codec_report_plug(codec, 1, |
| 7498 | SND_JACK_HEADPHONE); |
| 7499 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7500 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7501 | pr_debug("Good headphone detected, continue polling mic\n"); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7502 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7503 | if (tabla->current_plug != plug_type) |
| 7504 | tabla_codec_report_plug(codec, 1, |
| 7505 | SND_JACK_HEADPHONE); |
| 7506 | } else if (tabla->current_plug == PLUG_TYPE_NONE) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7507 | tabla_codec_report_plug(codec, 1, |
| 7508 | SND_JACK_HEADPHONE); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7509 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7510 | if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 7511 | pt_gnd_mic_swap_cnt++; |
| 7512 | if (pt_gnd_mic_swap_cnt < |
| 7513 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) |
| 7514 | continue; |
| 7515 | else if (pt_gnd_mic_swap_cnt > |
| 7516 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) { |
| 7517 | /* This is due to GND/MIC switch didn't |
| 7518 | * work, Report unsupported plug */ |
| 7519 | } else if (tabla->mbhc_cfg.swap_gnd_mic) { |
| 7520 | /* if switch is toggled, check again, |
| 7521 | * otherwise report unsupported plug */ |
| 7522 | if (tabla->mbhc_cfg.swap_gnd_mic(codec)) |
| 7523 | continue; |
| 7524 | } |
| 7525 | } else |
| 7526 | pt_gnd_mic_swap_cnt = 0; |
| 7527 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7528 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7529 | /* Turn off override */ |
| 7530 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7531 | /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP |
| 7532 | */ |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7533 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7534 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7535 | pr_debug("Attempt %d found correct plug %d\n", retry, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7536 | plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7537 | correction = true; |
| 7538 | break; |
| 7539 | } |
| 7540 | } |
| 7541 | |
| 7542 | /* Turn off override */ |
| 7543 | if (!correction) |
| 7544 | tabla_turn_onoff_override(codec, false); |
| 7545 | |
| 7546 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7547 | |
| 7548 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7549 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7550 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE || |
| 7551 | tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP || |
| 7552 | tabla->current_plug == PLUG_TYPE_INVALID || |
| 7553 | plug_type == PLUG_TYPE_INVALID) { |
| 7554 | /* Enable removal detection */ |
| 7555 | tabla_codec_cleanup_hs_polling(codec); |
| 7556 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 7557 | } |
| 7558 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7559 | } |
| 7560 | pr_debug("%s: leave current_plug(%d)\n", |
| 7561 | __func__, tabla->current_plug); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7562 | /* unlock sleep */ |
| 7563 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 7564 | } |
| 7565 | |
| 7566 | /* called under codec_resource_lock acquisition */ |
| 7567 | static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 7568 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7569 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7570 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7571 | |
| 7572 | pr_debug("%s: enter\n", __func__); |
| 7573 | |
| 7574 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7575 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7576 | tabla_turn_onoff_override(codec, false); |
| 7577 | |
| 7578 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 7579 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 7580 | __func__); |
| 7581 | return; |
| 7582 | } |
| 7583 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7584 | if (plug_type == PLUG_TYPE_INVALID || |
| 7585 | plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7586 | tabla_schedule_hs_detect_plug(tabla, |
| 7587 | &tabla->hs_correct_plug_work); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7588 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7589 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7590 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7591 | tabla_schedule_hs_detect_plug(tabla, |
| 7592 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7593 | } else { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7594 | pr_debug("%s: Valid plug found, determine plug type %d\n", |
| 7595 | __func__, plug_type); |
| 7596 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7597 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7598 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7599 | } |
| 7600 | |
| 7601 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7602 | static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 7603 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7604 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7605 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7606 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
| 7607 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7608 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7609 | /* Turn on the override, |
| 7610 | * tabla_codec_setup_hs_polling requires override on */ |
| 7611 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7612 | |
| 7613 | if (plug_det->t_ins_complete > 20) |
| 7614 | msleep(plug_det->t_ins_complete); |
| 7615 | else |
| 7616 | usleep_range(plug_det->t_ins_complete * 1000, |
| 7617 | plug_det->t_ins_complete * 1000); |
| 7618 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7619 | if (tabla->mbhc_cfg.gpio) { |
| 7620 | /* Turn off the override */ |
| 7621 | tabla_turn_onoff_override(codec, false); |
| 7622 | if (tabla_hs_gpio_level_remove(tabla)) |
| 7623 | pr_debug("%s: GPIO value is low when determining " |
| 7624 | "plug\n", __func__); |
| 7625 | else |
| 7626 | tabla_codec_decide_gpio_plug(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7627 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7628 | return; |
| 7629 | } |
| 7630 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7631 | plug_type = tabla_codec_get_plug_type(codec, false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7632 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7633 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7634 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7635 | pr_debug("%s: Invalid plug type detected\n", __func__); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7636 | 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] | 7637 | tabla_codec_cleanup_hs_polling(codec); |
| 7638 | tabla_codec_enable_hs_detect(codec, 1, |
| 7639 | MBHC_USE_MB_TRIGGER | |
| 7640 | MBHC_USE_HPHL_TRIGGER, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7641 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 7642 | pr_debug("%s: GND-MIC swapped plug type detected\n", __func__); |
| 7643 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 7644 | tabla_codec_cleanup_hs_polling(codec); |
| 7645 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7646 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7647 | pr_debug("%s: Headphone Detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7648 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7649 | tabla_codec_cleanup_hs_polling(codec); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7650 | tabla_schedule_hs_detect_plug(tabla, |
| 7651 | &tabla->hs_correct_plug_work_nogpio); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7652 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7653 | pr_debug("%s: Headset detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7654 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7655 | /* avoid false button press detect */ |
| 7656 | msleep(50); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7657 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7658 | } else if (tabla->mbhc_cfg.detect_extn_cable && |
| 7659 | plug_type == PLUG_TYPE_HIGH_HPH) { |
| 7660 | pr_debug("%s: High impedance plug type detected\n", __func__); |
| 7661 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 7662 | /* Enable insertion detection on the other end of cable */ |
| 7663 | tabla_codec_cleanup_hs_polling(codec); |
| 7664 | tabla_codec_enable_hs_detect(codec, 1, |
| 7665 | MBHC_USE_MB_TRIGGER, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7666 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7667 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7670 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7671 | 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] | 7672 | { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7673 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7674 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7675 | |
| 7676 | if (!is_removal) { |
| 7677 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
| 7678 | |
| 7679 | rmb(); |
| 7680 | if (priv->lpi_enabled) |
| 7681 | msleep(100); |
| 7682 | |
| 7683 | rmb(); |
| 7684 | if (!priv->lpi_enabled) { |
| 7685 | pr_debug("%s: lpi is disabled\n", __func__); |
| 7686 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 7687 | priv->mbhc_cfg.gpio_level_insert) { |
| 7688 | pr_debug("%s: Valid insertion, " |
| 7689 | "detect plug type\n", __func__); |
| 7690 | tabla_codec_decide_gpio_plug(codec); |
| 7691 | } else { |
| 7692 | pr_debug("%s: Invalid insertion, " |
| 7693 | "stop plug detection\n", __func__); |
| 7694 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7695 | } else if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7696 | pr_debug("%s: Removal\n", __func__); |
| 7697 | if (!tabla_hs_gpio_level_remove(tabla)) { |
| 7698 | /* |
| 7699 | * gpio says, something is still inserted, could be |
| 7700 | * extension cable i.e. headset is removed from |
| 7701 | * extension cable |
| 7702 | */ |
| 7703 | /* cancel detect plug */ |
| 7704 | tabla_cancel_hs_detect_plug(tabla, |
| 7705 | &tabla->hs_correct_plug_work); |
| 7706 | tabla_codec_decide_gpio_plug(codec); |
| 7707 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7708 | } else { |
| 7709 | pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__); |
| 7710 | } |
| 7711 | } |
| 7712 | |
| 7713 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7714 | static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal, |
| 7715 | bool is_mb_trigger) |
| 7716 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7717 | int ret; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7718 | struct snd_soc_codec *codec = priv->codec; |
| 7719 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7720 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7721 | |
| 7722 | /* Cancel possibly running hs_detect_work */ |
| 7723 | tabla_cancel_hs_detect_plug(tabla, |
| 7724 | &tabla->hs_correct_plug_work_nogpio); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 7725 | |
| 7726 | if (is_removal) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7727 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 7728 | /* |
| 7729 | * If headphone is removed while playback is in progress, |
| 7730 | * it is possible that micbias will be switched to VDDIO. |
| 7731 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7732 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7733 | if (priv->current_plug == PLUG_TYPE_HEADPHONE) |
| 7734 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 7735 | else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP) |
| 7736 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 7737 | else |
| 7738 | WARN(1, "%s: Unexpected current plug type %d\n", |
| 7739 | __func__, priv->current_plug); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7740 | tabla_codec_shutdown_hs_removal_detect(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7741 | tabla_codec_enable_hs_detect(codec, 1, |
| 7742 | MBHC_USE_MB_TRIGGER | |
| 7743 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7744 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7745 | } else if (is_mb_trigger && !is_removal) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7746 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7747 | __func__); |
| 7748 | wcd9xxx_lock_sleep(core); |
| 7749 | if (schedule_delayed_work(&priv->mbhc_insert_dwork, |
| 7750 | usecs_to_jiffies(1000000)) == 0) { |
| 7751 | pr_err("%s: mbhc_insert_dwork is already scheduled\n", |
| 7752 | __func__); |
| 7753 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 7754 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7755 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7756 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7757 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7758 | ret = cancel_delayed_work(&priv->mbhc_insert_dwork); |
| 7759 | if (ret != 0) { |
| 7760 | pr_debug("%s: Complete plug insertion, Detecting plug " |
| 7761 | "type\n", __func__); |
| 7762 | tabla_codec_detect_plug_type(codec); |
| 7763 | wcd9xxx_unlock_sleep(core); |
| 7764 | } else { |
| 7765 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7766 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7767 | pr_err("%s: Error detecting plug insertion\n", |
| 7768 | __func__); |
| 7769 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7770 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7771 | } |
Bhalchandra Gajare | 9494fa26 | 2011-11-10 19:25:59 -0800 | [diff] [blame] | 7772 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7773 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7774 | static void tabla_hs_insert_irq_extn(struct tabla_priv *priv, |
| 7775 | bool is_mb_trigger) |
| 7776 | { |
| 7777 | struct snd_soc_codec *codec = priv->codec; |
| 7778 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7779 | |
| 7780 | /* Cancel possibly running hs_detect_work */ |
| 7781 | tabla_cancel_hs_detect_plug(tabla, |
| 7782 | &tabla->hs_correct_plug_work); |
| 7783 | |
| 7784 | if (is_mb_trigger) { |
| 7785 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7786 | __func__); |
| 7787 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7788 | false); |
| 7789 | } else { |
| 7790 | pr_debug("%s: HPHL trigger received, detecting plug type\n", |
| 7791 | __func__); |
| 7792 | tabla_codec_detect_plug_type(codec); |
| 7793 | } |
| 7794 | } |
| 7795 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7796 | static irqreturn_t tabla_hs_insert_irq(int irq, void *data) |
| 7797 | { |
| 7798 | bool is_mb_trigger, is_removal; |
| 7799 | struct tabla_priv *priv = data; |
| 7800 | struct snd_soc_codec *codec = priv->codec; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7801 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7802 | pr_debug("%s: enter\n", __func__); |
| 7803 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7804 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7805 | |
| 7806 | is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) & |
| 7807 | 0x10); |
| 7808 | is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02); |
| 7809 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 7810 | |
| 7811 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 7812 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 7813 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 7814 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 7815 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7816 | if (priv->mbhc_cfg.detect_extn_cable && |
| 7817 | priv->current_plug == PLUG_TYPE_HIGH_HPH) |
| 7818 | tabla_hs_insert_irq_extn(priv, is_mb_trigger); |
| 7819 | else if (priv->mbhc_cfg.gpio) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7820 | tabla_hs_insert_irq_gpio(priv, is_removal); |
| 7821 | else |
| 7822 | tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger); |
| 7823 | |
| 7824 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7825 | return IRQ_HANDLED; |
| 7826 | } |
| 7827 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7828 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 7829 | { |
| 7830 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7831 | const struct tabla_mbhc_plug_type_cfg *plug_type = |
| 7832 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 7833 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7834 | |
| 7835 | 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] | 7836 | && (mic_mv < v_hs_max)) ? true : false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
| 7839 | /* called under codec_resource_lock acquisition |
| 7840 | * returns true if mic voltage range is back to normal insertion |
| 7841 | * returns false either if timedout or removed */ |
| 7842 | static bool tabla_hs_remove_settle(struct snd_soc_codec *codec) |
| 7843 | { |
| 7844 | int i; |
| 7845 | bool timedout, settled = false; |
| 7846 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7847 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7848 | unsigned long retry = 0, timeout; |
| 7849 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7850 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7851 | |
| 7852 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7853 | while (!(timedout = time_after(jiffies, timeout))) { |
| 7854 | retry++; |
| 7855 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7856 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7857 | break; |
| 7858 | } |
| 7859 | |
| 7860 | if (tabla->mbhc_cfg.gpio) { |
| 7861 | if (retry > 1) |
| 7862 | msleep(250); |
| 7863 | else |
| 7864 | msleep(50); |
| 7865 | } |
| 7866 | |
| 7867 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7868 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7869 | break; |
| 7870 | } |
| 7871 | |
| 7872 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 7873 | mb_v[i] = tabla_codec_sta_dce(codec, 1, true); |
| 7874 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 7875 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 7876 | __func__, retry, mic_mv[i], mb_v[i]); |
| 7877 | } |
| 7878 | |
| 7879 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7880 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7881 | break; |
| 7882 | } |
| 7883 | |
| 7884 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 7885 | pr_debug("%s : headset/headphone is removed\n", |
| 7886 | __func__); |
| 7887 | break; |
| 7888 | } |
| 7889 | |
| 7890 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 7891 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 7892 | break; |
| 7893 | |
| 7894 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7895 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 7896 | settled = true; |
| 7897 | msleep(200); |
| 7898 | break; |
| 7899 | } |
| 7900 | |
| 7901 | /* only for non-GPIO remove irq */ |
| 7902 | if (!tabla->mbhc_cfg.gpio) { |
| 7903 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7904 | if (mic_mv[i] < v_hs_max) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7905 | break; |
| 7906 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7907 | pr_debug("%s: Headset is removed\n", __func__); |
| 7908 | break; |
| 7909 | } |
| 7910 | } |
| 7911 | } |
| 7912 | |
| 7913 | if (timedout) |
| 7914 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 7915 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7916 | return settled; |
| 7917 | } |
| 7918 | |
| 7919 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7920 | static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv) |
| 7921 | { |
| 7922 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7923 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7924 | if (tabla_hs_remove_settle(codec)) |
| 7925 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7926 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7927 | } |
| 7928 | |
| 7929 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7930 | static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7931 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7932 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7933 | bool removed = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7934 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7935 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7936 | TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7937 | int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7938 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7939 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7940 | if (priv->current_plug != PLUG_TYPE_HEADSET) { |
| 7941 | pr_debug("%s(): Headset is not inserted, ignore removal\n", |
| 7942 | __func__); |
| 7943 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7944 | 0x08, 0x08); |
| 7945 | return; |
| 7946 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7947 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7948 | usleep_range(generic->t_shutdown_plug_rem, |
| 7949 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7950 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7951 | do { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7952 | bias_value = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7953 | pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value, |
| 7954 | tabla_codec_sta_dce_v(codec, 1, bias_value), min_us); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7955 | if (bias_value < tabla_get_current_v_ins(priv, false)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7956 | pr_debug("%s: checking false removal\n", __func__); |
| 7957 | msleep(500); |
| 7958 | removed = !tabla_hs_remove_settle(codec); |
| 7959 | pr_debug("%s: headset %sactually removed\n", __func__, |
| 7960 | removed ? "" : "not "); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7961 | break; |
| 7962 | } |
| 7963 | min_us -= priv->mbhc_data.t_dce; |
| 7964 | } while (min_us > 0); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 7965 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7966 | if (removed) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7967 | if (priv->mbhc_cfg.detect_extn_cable) { |
| 7968 | if (!tabla_hs_gpio_level_remove(priv)) { |
| 7969 | /* |
| 7970 | * extension cable is still plugged in |
| 7971 | * report it as LINEOUT device |
| 7972 | */ |
| 7973 | tabla_codec_report_plug(codec, 1, |
| 7974 | SND_JACK_LINEOUT); |
| 7975 | tabla_codec_cleanup_hs_polling(codec); |
| 7976 | tabla_codec_enable_hs_detect(codec, 1, |
| 7977 | MBHC_USE_MB_TRIGGER, |
| 7978 | false); |
| 7979 | } |
| 7980 | } else { |
| 7981 | /* Cancel possibly running hs_detect_work */ |
| 7982 | tabla_cancel_hs_detect_plug(priv, |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7983 | &priv->hs_correct_plug_work_nogpio); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7984 | /* |
| 7985 | * If this removal is not false, first check the micbias |
| 7986 | * switch status and switch it to LDOH if it is already |
| 7987 | * switched to VDDIO. |
| 7988 | */ |
| 7989 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7990 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7991 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 7992 | tabla_codec_cleanup_hs_polling(codec); |
| 7993 | tabla_codec_enable_hs_detect(codec, 1, |
| 7994 | MBHC_USE_MB_TRIGGER | |
| 7995 | MBHC_USE_HPHL_TRIGGER, |
| 7996 | true); |
| 7997 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7998 | } else { |
| 7999 | tabla_codec_start_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8000 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 8001 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8002 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8003 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8004 | static irqreturn_t tabla_hs_remove_irq(int irq, void *data) |
| 8005 | { |
| 8006 | struct tabla_priv *priv = data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8007 | bool vddio; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8008 | pr_debug("%s: enter, removal interrupt\n", __func__); |
| 8009 | |
| 8010 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 8011 | vddio = !priv->mbhc_cfg.micbias_always_on && |
| 8012 | (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8013 | priv->mbhc_micbias_switched); |
| 8014 | if (vddio) |
| 8015 | __tabla_codec_switch_micbias(priv->codec, 0, false, true); |
| 8016 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 8017 | if ((priv->mbhc_cfg.detect_extn_cable && |
| 8018 | !tabla_hs_gpio_level_remove(priv)) || |
| 8019 | !priv->mbhc_cfg.gpio) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8020 | tabla_hs_remove_irq_nogpio(priv); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 8021 | } else |
| 8022 | tabla_hs_remove_irq_gpio(priv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8023 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8024 | /* if driver turned off vddio switch and headset is not removed, |
| 8025 | * turn on the vddio switch back, if headset is removed then vddio |
| 8026 | * switch is off by time now and shouldn't be turn on again from here */ |
| 8027 | if (vddio && priv->current_plug == PLUG_TYPE_HEADSET) |
| 8028 | __tabla_codec_switch_micbias(priv->codec, 1, true, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8029 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8030 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8031 | return IRQ_HANDLED; |
| 8032 | } |
| 8033 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8034 | void mbhc_insert_work(struct work_struct *work) |
| 8035 | { |
| 8036 | struct delayed_work *dwork; |
| 8037 | struct tabla_priv *tabla; |
| 8038 | struct snd_soc_codec *codec; |
| 8039 | struct wcd9xxx *tabla_core; |
| 8040 | |
| 8041 | dwork = to_delayed_work(work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8042 | tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8043 | codec = tabla->codec; |
| 8044 | tabla_core = dev_get_drvdata(codec->dev->parent); |
| 8045 | |
| 8046 | pr_debug("%s:\n", __func__); |
| 8047 | |
| 8048 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 8049 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 8050 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 8051 | 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] | 8052 | wcd9xxx_disable_irq_sync(codec->control_data, |
| 8053 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8054 | tabla_codec_detect_plug_type(codec); |
| 8055 | wcd9xxx_unlock_sleep(tabla_core); |
| 8056 | } |
| 8057 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8058 | static void tabla_hs_gpio_handler(struct snd_soc_codec *codec) |
| 8059 | { |
| 8060 | bool insert; |
| 8061 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8062 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8063 | bool is_removed = false; |
| 8064 | |
| 8065 | pr_debug("%s: enter\n", __func__); |
| 8066 | |
| 8067 | tabla->in_gpio_handler = true; |
| 8068 | /* Wait here for debounce time */ |
| 8069 | usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 8070 | TABLA_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 8071 | |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8072 | wcd9xxx_nested_irq_lock(core); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8073 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8074 | |
| 8075 | /* cancel pending button press */ |
| 8076 | if (tabla_cancel_btn_work(tabla)) |
| 8077 | pr_debug("%s: button press is canceled\n", __func__); |
| 8078 | |
| 8079 | insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) == |
| 8080 | tabla->mbhc_cfg.gpio_level_insert); |
| 8081 | if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) { |
| 8082 | tabla->lpi_enabled = false; |
| 8083 | wmb(); |
| 8084 | |
| 8085 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8086 | tabla_cancel_hs_detect_plug(tabla, |
| 8087 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8088 | |
| 8089 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 8090 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 8091 | 0x00); |
| 8092 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00); |
| 8093 | tabla_codec_detect_plug_type(codec); |
| 8094 | } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 8095 | tabla->lpi_enabled = false; |
| 8096 | wmb(); |
| 8097 | |
| 8098 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8099 | tabla_cancel_hs_detect_plug(tabla, |
| 8100 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8101 | |
| 8102 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE) { |
| 8103 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 8104 | is_removed = true; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 8105 | } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) { |
| 8106 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 8107 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8108 | } else if (tabla->current_plug == PLUG_TYPE_HEADSET) { |
| 8109 | tabla_codec_pause_hs_polling(codec); |
| 8110 | tabla_codec_cleanup_hs_polling(codec); |
| 8111 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 8112 | is_removed = true; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 8113 | } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) { |
| 8114 | tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT); |
| 8115 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8116 | } |
| 8117 | |
| 8118 | if (is_removed) { |
| 8119 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 8120 | snd_soc_update_bits(codec, |
| 8121 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 8122 | 0x01); |
| 8123 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 8124 | 0x01); |
| 8125 | /* Make sure mic trigger is turned off */ |
| 8126 | snd_soc_update_bits(codec, |
| 8127 | tabla->mbhc_bias_regs.ctl_reg, |
| 8128 | 0x01, 0x01); |
| 8129 | snd_soc_update_bits(codec, |
| 8130 | tabla->mbhc_bias_regs.mbhc_reg, |
| 8131 | 0x90, 0x00); |
| 8132 | /* Reset MBHC State Machine */ |
| 8133 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 8134 | 0x08, 0x08); |
| 8135 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 8136 | 0x08, 0x00); |
| 8137 | /* Turn off override */ |
| 8138 | tabla_turn_onoff_override(codec, false); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame] | 8139 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8140 | } |
| 8141 | } |
| 8142 | |
| 8143 | tabla->in_gpio_handler = false; |
| 8144 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 1f9d7fd | 2013-01-07 12:40:03 -0800 | [diff] [blame] | 8145 | wcd9xxx_nested_irq_unlock(core); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8146 | pr_debug("%s: leave\n", __func__); |
| 8147 | } |
| 8148 | |
| 8149 | static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data) |
| 8150 | { |
| 8151 | int r = IRQ_HANDLED; |
| 8152 | struct snd_soc_codec *codec = data; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8153 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8154 | |
| 8155 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 8156 | pr_warn("%s: failed to hold suspend\n", __func__); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8157 | /* |
| 8158 | * Give up this IRQ for now and resend this IRQ so IRQ can be |
| 8159 | * handled after system resume |
| 8160 | */ |
| 8161 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8162 | tabla->gpio_irq_resend = true; |
| 8163 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8164 | wake_lock_timeout(&tabla->irq_resend_wlock, HZ); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8165 | r = IRQ_NONE; |
| 8166 | } else { |
| 8167 | tabla_hs_gpio_handler(codec); |
| 8168 | wcd9xxx_unlock_sleep(codec->control_data); |
| 8169 | } |
| 8170 | |
| 8171 | return r; |
| 8172 | } |
| 8173 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8174 | static void tabla_hs_correct_plug_nogpio(struct work_struct *work) |
| 8175 | { |
| 8176 | struct tabla_priv *tabla; |
| 8177 | struct snd_soc_codec *codec; |
| 8178 | unsigned long timeout; |
| 8179 | int retry = 0; |
| 8180 | enum tabla_mbhc_plug_type plug_type; |
| 8181 | bool is_headset = false; |
| 8182 | |
| 8183 | pr_debug("%s(): Poll Microphone voltage for %d seconds\n", |
| 8184 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000); |
| 8185 | |
| 8186 | tabla = container_of(work, struct tabla_priv, |
| 8187 | hs_correct_plug_work_nogpio); |
| 8188 | codec = tabla->codec; |
| 8189 | |
| 8190 | /* Make sure the MBHC mux is connected to MIC Path */ |
| 8191 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 8192 | |
| 8193 | /* setup for microphone polling */ |
| 8194 | tabla_turn_onoff_override(codec, true); |
| 8195 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 8196 | |
| 8197 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 8198 | while (!time_after(jiffies, timeout)) { |
| 8199 | ++retry; |
| 8200 | |
| 8201 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 8202 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8203 | plug_type = tabla_codec_get_plug_type(codec, false); |
| 8204 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8205 | |
| 8206 | if (plug_type == PLUG_TYPE_HIGH_HPH |
| 8207 | || plug_type == PLUG_TYPE_INVALID) { |
| 8208 | |
| 8209 | /* this means the plug is removed |
| 8210 | * End microphone polling and setup |
| 8211 | * for low power removal detection. |
| 8212 | */ |
| 8213 | pr_debug("%s(): Plug may be removed, setup removal\n", |
| 8214 | __func__); |
| 8215 | break; |
| 8216 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 8217 | /* Plug is corrected from headphone to headset, |
| 8218 | * report headset and end the polling |
| 8219 | */ |
| 8220 | is_headset = true; |
| 8221 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8222 | tabla_turn_onoff_override(codec, false); |
| 8223 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 8224 | tabla_codec_start_hs_polling(codec); |
| 8225 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8226 | pr_debug("%s(): corrected from headphone to headset\n", |
| 8227 | __func__); |
| 8228 | break; |
| 8229 | } |
| 8230 | } |
| 8231 | |
| 8232 | /* Undo setup for microphone polling depending |
| 8233 | * result from polling |
| 8234 | */ |
| 8235 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 8236 | if (!is_headset) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 8237 | pr_debug("%s: Inserted headphone is not a headset\n", |
| 8238 | __func__); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8239 | tabla_turn_onoff_override(codec, false); |
| 8240 | tabla_codec_cleanup_hs_polling(codec); |
| 8241 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 8242 | } |
| 8243 | wcd9xxx_unlock_sleep(codec->control_data); |
| 8244 | } |
| 8245 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8246 | static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla) |
| 8247 | { |
| 8248 | int ret = 0; |
| 8249 | struct snd_soc_codec *codec = tabla->codec; |
| 8250 | |
| 8251 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 8252 | tabla_mbhc_init(codec); |
| 8253 | tabla_mbhc_cal(codec); |
| 8254 | tabla_mbhc_calc_thres(codec); |
| 8255 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 8256 | tabla_codec_calibrate_hs_polling(codec); |
| 8257 | if (!tabla->mbhc_cfg.gpio) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 8258 | INIT_WORK(&tabla->hs_correct_plug_work_nogpio, |
| 8259 | tabla_hs_correct_plug_nogpio); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8260 | ret = tabla_codec_enable_hs_detect(codec, 1, |
| 8261 | MBHC_USE_MB_TRIGGER | |
| 8262 | MBHC_USE_HPHL_TRIGGER, |
| 8263 | false); |
| 8264 | |
| 8265 | if (IS_ERR_VALUE(ret)) |
| 8266 | pr_err("%s: Failed to setup MBHC detection\n", |
| 8267 | __func__); |
| 8268 | } else { |
| 8269 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 8270 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 8271 | 0x01, 0x01); |
| 8272 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01); |
| 8273 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 8274 | tabla_hs_correct_gpio_plug); |
| 8275 | } |
| 8276 | |
| 8277 | if (!IS_ERR_VALUE(ret)) { |
| 8278 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
| 8279 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8280 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8281 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8282 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8283 | |
| 8284 | if (tabla->mbhc_cfg.gpio) { |
| 8285 | ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, |
| 8286 | NULL, |
| 8287 | tabla_mechanical_plug_detect_irq, |
| 8288 | (IRQF_TRIGGER_RISING | |
| 8289 | IRQF_TRIGGER_FALLING), |
| 8290 | "tabla-gpio", codec); |
| 8291 | if (!IS_ERR_VALUE(ret)) { |
| 8292 | ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq); |
| 8293 | /* Bootup time detection */ |
| 8294 | tabla_hs_gpio_handler(codec); |
| 8295 | } |
| 8296 | } |
| 8297 | } |
| 8298 | |
| 8299 | return ret; |
| 8300 | } |
| 8301 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8302 | static void mbhc_fw_read(struct work_struct *work) |
| 8303 | { |
| 8304 | struct delayed_work *dwork; |
| 8305 | struct tabla_priv *tabla; |
| 8306 | struct snd_soc_codec *codec; |
| 8307 | const struct firmware *fw; |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8308 | int ret = -1, retry = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8309 | |
| 8310 | dwork = to_delayed_work(work); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8311 | tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8312 | codec = tabla->codec; |
| 8313 | |
| 8314 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 8315 | retry++; |
| 8316 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 8317 | __func__, retry); |
| 8318 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 8319 | codec->dev); |
| 8320 | |
| 8321 | if (ret != 0) { |
| 8322 | usleep_range(MBHC_FW_READ_TIMEOUT, |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8323 | MBHC_FW_READ_TIMEOUT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8324 | } else { |
| 8325 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 8326 | break; |
| 8327 | } |
| 8328 | } |
| 8329 | |
| 8330 | if (ret != 0) { |
| 8331 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 8332 | __func__); |
| 8333 | } else if (tabla_mbhc_fw_validate(fw) == false) { |
| 8334 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 8335 | __func__); |
| 8336 | release_firmware(fw); |
| 8337 | } else { |
| 8338 | tabla->mbhc_cfg.calibration = (void *)fw->data; |
| 8339 | tabla->mbhc_fw = fw; |
| 8340 | } |
| 8341 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8342 | (void) tabla_mbhc_init_and_calibrate(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8343 | } |
| 8344 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8345 | int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8346 | const struct tabla_mbhc_config *cfg) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8347 | { |
| 8348 | struct tabla_priv *tabla; |
| 8349 | int rc = 0; |
| 8350 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8351 | if (!codec || !cfg->calibration) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8352 | pr_err("Error: no codec or calibration\n"); |
| 8353 | return -EINVAL; |
| 8354 | } |
| 8355 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8356 | if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) { |
| 8357 | if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8358 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8359 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8360 | else |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8361 | pr_err("Error: unsupported clock rate %d\n", |
| 8362 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8363 | return -EINVAL; |
| 8364 | } |
| 8365 | |
| 8366 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8367 | tabla->mbhc_cfg = *cfg; |
| 8368 | tabla->in_gpio_handler = false; |
| 8369 | tabla->current_plug = PLUG_TYPE_NONE; |
| 8370 | tabla->lpi_enabled = false; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8371 | tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs); |
| 8372 | |
| 8373 | /* Put CFILT in fast mode by default */ |
Simmi Pateriya | 71d6387 | 2012-11-08 01:06:30 +0530 | [diff] [blame] | 8374 | if (!tabla->mbhc_cfg.micbias_always_on) |
| 8375 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8376 | 0x40, TABLA_CFILT_FAST_MODE); |
| 8377 | INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read); |
| 8378 | INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn); |
| 8379 | INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report); |
| 8380 | INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report); |
| 8381 | INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work); |
| 8382 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 8383 | if (!tabla->mbhc_cfg.read_fw_bin) |
| 8384 | rc = tabla_mbhc_init_and_calibrate(tabla); |
| 8385 | else |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8386 | schedule_delayed_work(&tabla->mbhc_firmware_dwork, |
| 8387 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8388 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8389 | return rc; |
| 8390 | } |
| 8391 | EXPORT_SYMBOL_GPL(tabla_hs_detect); |
| 8392 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8393 | static irqreturn_t tabla_slimbus_irq(int irq, void *data) |
| 8394 | { |
| 8395 | struct tabla_priv *priv = data; |
| 8396 | struct snd_soc_codec *codec = priv->codec; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8397 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 8398 | int i, j, port_id, k, ch_mask_temp; |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 8399 | unsigned long slimbus_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8400 | u8 val; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8401 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 8402 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8403 | TABLA_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 8404 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8405 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8406 | TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 8407 | if (val & 0x1) |
| 8408 | pr_err_ratelimited("overflow error on port %x," |
| 8409 | " value %x\n", i*8 + j, val); |
| 8410 | if (val & 0x2) |
| 8411 | pr_err_ratelimited("underflow error on port %x," |
| 8412 | " value %x\n", i*8 + j, val); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8413 | if (val & 0x4) { |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8414 | port_id = i*8 + j; |
| 8415 | for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) { |
| 8416 | ch_mask_temp = 1 << port_id; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 8417 | pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8418 | __func__, k, |
| 8419 | tabla_p->dai[k].ch_mask); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8420 | if (ch_mask_temp & |
| 8421 | tabla_p->dai[k].ch_mask) { |
| 8422 | tabla_p->dai[k].ch_mask &= |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8423 | ~ch_mask_temp; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8424 | if (!tabla_p->dai[k].ch_mask) |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8425 | wake_up( |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 8426 | &tabla_p->dai[k].dai_wait); |
| 8427 | } |
| 8428 | } |
| 8429 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8430 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8431 | wcd9xxx_interface_reg_write(codec->control_data, |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 8432 | TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value); |
| 8433 | val = 0x0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8434 | } |
| 8435 | |
| 8436 | return IRQ_HANDLED; |
| 8437 | } |
| 8438 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8439 | static int tabla_handle_pdata(struct tabla_priv *tabla) |
| 8440 | { |
| 8441 | struct snd_soc_codec *codec = tabla->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8442 | struct wcd9xxx_pdata *pdata = tabla->pdata; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8443 | int k1, k2, k3, rc = 0; |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8444 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 8445 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 8446 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 8447 | u8 flag = pdata->amic_settings.use_pdata; |
| 8448 | u8 i = 0, j = 0; |
| 8449 | u8 val_txfe = 0, value = 0; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8450 | |
| 8451 | if (!pdata) { |
| 8452 | rc = -ENODEV; |
| 8453 | goto done; |
| 8454 | } |
| 8455 | |
| 8456 | /* Make sure settings are correct */ |
| 8457 | if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) || |
| 8458 | (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8459 | (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8460 | (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) || |
| 8461 | (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) { |
| 8462 | rc = -EINVAL; |
| 8463 | goto done; |
| 8464 | } |
| 8465 | |
| 8466 | /* figure out k value */ |
| 8467 | k1 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8468 | pdata->micbias.cfilt1_mv); |
| 8469 | k2 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8470 | pdata->micbias.cfilt2_mv); |
| 8471 | k3 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 8472 | pdata->micbias.cfilt3_mv); |
| 8473 | |
| 8474 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
| 8475 | rc = -EINVAL; |
| 8476 | goto done; |
| 8477 | } |
| 8478 | |
| 8479 | /* Set voltage level and always use LDO */ |
| 8480 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C, |
| 8481 | (pdata->micbias.ldoh_v << 2)); |
| 8482 | |
| 8483 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC, |
| 8484 | (k1 << 2)); |
| 8485 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC, |
| 8486 | (k2 << 2)); |
| 8487 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC, |
| 8488 | (k3 << 2)); |
| 8489 | |
| 8490 | snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60, |
| 8491 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 8492 | snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60, |
| 8493 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 8494 | snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60, |
| 8495 | (pdata->micbias.bias3_cfilt_sel << 5)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8496 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60, |
| 8497 | (pdata->micbias.bias4_cfilt_sel << 5)); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8498 | |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8499 | for (i = 0; i < 6; j++, i += 2) { |
| 8500 | if (flag & (0x01 << i)) { |
| 8501 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 8502 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 8503 | val_txfe = val_txfe | |
| 8504 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 8505 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 8506 | 0x10, value); |
| 8507 | snd_soc_update_bits(codec, |
| 8508 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 8509 | 0x30, val_txfe); |
| 8510 | } |
| 8511 | if (flag & (0x01 << (i + 1))) { |
| 8512 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 8513 | val_txfe = (txfe_bypass & |
| 8514 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 8515 | val_txfe |= (txfe_buff & |
| 8516 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 8517 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 8518 | 0x01, value); |
| 8519 | snd_soc_update_bits(codec, |
| 8520 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 8521 | 0x03, val_txfe); |
| 8522 | } |
| 8523 | } |
| 8524 | if (flag & 0x40) { |
| 8525 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 8526 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 8527 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 8528 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, |
| 8529 | 0x13, value); |
| 8530 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8531 | |
| 8532 | if (pdata->ocp.use_pdata) { |
| 8533 | /* not defined in CODEC specification */ |
| 8534 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 8535 | pdata->ocp.hph_ocp_limit == 5) { |
| 8536 | rc = -EINVAL; |
| 8537 | goto done; |
| 8538 | } |
| 8539 | snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL, |
| 8540 | 0x0F, pdata->ocp.num_attempts); |
| 8541 | snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT, |
| 8542 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 8543 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, |
| 8544 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 8545 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8546 | |
| 8547 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 8548 | if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) { |
| 8549 | if (pdata->regulator[i].min_uV == 1800000 && |
| 8550 | pdata->regulator[i].max_uV == 1800000) { |
| 8551 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8552 | 0x1C); |
| 8553 | } else if (pdata->regulator[i].min_uV == 2200000 && |
| 8554 | pdata->regulator[i].max_uV == 2200000) { |
| 8555 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8556 | 0x1E); |
| 8557 | } else { |
| 8558 | pr_err("%s: unsupported CDC_VDDA_RX voltage " |
| 8559 | "min %d, max %d\n", __func__, |
| 8560 | pdata->regulator[i].min_uV, |
| 8561 | pdata->regulator[i].max_uV); |
| 8562 | rc = -EINVAL; |
| 8563 | } |
| 8564 | break; |
| 8565 | } |
| 8566 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8567 | done: |
| 8568 | return rc; |
| 8569 | } |
| 8570 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8571 | static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = { |
| 8572 | |
| 8573 | /* Tabla 1.1 MICBIAS changes */ |
| 8574 | TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24), |
| 8575 | TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24), |
| 8576 | TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24), |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8577 | |
| 8578 | /* Tabla 1.1 HPH changes */ |
| 8579 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57), |
| 8580 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56), |
| 8581 | |
| 8582 | /* Tabla 1.1 EAR PA changes */ |
| 8583 | TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6), |
| 8584 | TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02), |
| 8585 | TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03), |
| 8586 | |
| 8587 | /* Tabla 1.1 Lineout_5 Changes */ |
| 8588 | TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10), |
| 8589 | |
| 8590 | /* Tabla 1.1 RX Changes */ |
| 8591 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78), |
| 8592 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78), |
| 8593 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78), |
| 8594 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78), |
| 8595 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78), |
| 8596 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78), |
| 8597 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78), |
| 8598 | |
| 8599 | /* Tabla 1.1 RX1 and RX2 Changes */ |
| 8600 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0), |
| 8601 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0), |
| 8602 | |
| 8603 | /* Tabla 1.1 RX3 to RX7 Changes */ |
| 8604 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80), |
| 8605 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80), |
| 8606 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80), |
| 8607 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80), |
| 8608 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80), |
| 8609 | |
| 8610 | /* Tabla 1.1 CLASSG Changes */ |
| 8611 | TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 8612 | }; |
| 8613 | |
| 8614 | static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = { |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8615 | /* Tabla 2.0 MICBIAS changes */ |
| 8616 | TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02), |
| 8617 | }; |
| 8618 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8619 | static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = { |
| 8620 | TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24), |
| 8621 | }; |
| 8622 | |
| 8623 | static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = { |
| 8624 | TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24), |
| 8625 | }; |
| 8626 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8627 | static void tabla_update_reg_defaults(struct snd_soc_codec *codec) |
| 8628 | { |
| 8629 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8630 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8631 | |
| 8632 | for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++) |
| 8633 | snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg, |
| 8634 | tabla_1_1_reg_defaults[i].val); |
| 8635 | |
| 8636 | for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++) |
| 8637 | snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg, |
| 8638 | tabla_2_0_reg_defaults[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8639 | |
| 8640 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8641 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults); |
| 8642 | i++) |
| 8643 | snd_soc_write(codec, |
| 8644 | tabla_1_x_only_reg_2_0_defaults[i].reg, |
| 8645 | tabla_1_x_only_reg_2_0_defaults[i].val); |
| 8646 | } else { |
| 8647 | for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++) |
| 8648 | snd_soc_write(codec, |
| 8649 | tabla_2_only_reg_2_0_defaults[i].reg, |
| 8650 | tabla_2_only_reg_2_0_defaults[i].val); |
| 8651 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8652 | } |
| 8653 | |
| 8654 | static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8655 | /* Initialize current threshold to 350MA |
| 8656 | * number of wait and run cycles to 4096 |
| 8657 | */ |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8658 | {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8659 | {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8660 | |
Santosh Mardi | 3217101 | 2011-10-28 23:32:06 +0530 | [diff] [blame] | 8661 | {TABLA_A_QFUSE_CTL, 0xFF, 0x03}, |
| 8662 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8663 | /* Initialize gain registers to use register gain */ |
| 8664 | {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 8665 | {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 8666 | {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 8667 | {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 8668 | {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10}, |
| 8669 | {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10}, |
| 8670 | |
Kuirong Wang | ccb29c6 | 2012-06-15 11:09:07 -0700 | [diff] [blame] | 8671 | /* Set the MICBIAS default output as pull down*/ |
| 8672 | {TABLA_A_MICB_1_CTL, 0x01, 0x01}, |
| 8673 | {TABLA_A_MICB_2_CTL, 0x01, 0x01}, |
| 8674 | {TABLA_A_MICB_3_CTL, 0x01, 0x01}, |
| 8675 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8676 | /* Initialize mic biases to differential mode */ |
| 8677 | {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 8678 | {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 8679 | {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8680 | |
| 8681 | {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 8682 | |
| 8683 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 8684 | {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 8685 | {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 8686 | {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 8687 | {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 8688 | {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 8689 | {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20}, |
| 8690 | |
| 8691 | /* Use 16 bit sample size for TX7 to TX10 */ |
| 8692 | {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40}, |
| 8693 | {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40}, |
| 8694 | {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40}, |
| 8695 | {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40}, |
| 8696 | |
| 8697 | /* Use 16 bit sample size for RX */ |
| 8698 | {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 8699 | {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA}, |
| 8700 | |
| 8701 | /*enable HPF filter for TX paths */ |
| 8702 | {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 8703 | {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 8704 | {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 8705 | {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 8706 | {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0}, |
| 8707 | {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0}, |
| 8708 | {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0}, |
| 8709 | {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0}, |
| 8710 | {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0}, |
| 8711 | {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0}, |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 8712 | |
| 8713 | /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */ |
| 8714 | {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1}, |
| 8715 | {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1}, |
| 8716 | {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1}, |
| 8717 | {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1}, |
| 8718 | {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1}, |
| 8719 | {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1}, |
| 8720 | {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1}, |
| 8721 | {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1}, |
| 8722 | {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1}, |
| 8723 | {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1}, |
| 8724 | |
| 8725 | /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */ |
| 8726 | {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A}, |
| 8727 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8728 | }; |
| 8729 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8730 | 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] | 8731 | /* Set the MICBIAS default output as pull down*/ |
| 8732 | {TABLA_1_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8733 | /* Initialize mic biases to differential mode */ |
| 8734 | {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8735 | }; |
| 8736 | |
| 8737 | 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] | 8738 | |
| 8739 | /* Set the MICBIAS default output as pull down*/ |
| 8740 | {TABLA_2_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8741 | /* Initialize mic biases to differential mode */ |
| 8742 | {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8743 | }; |
| 8744 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8745 | static void tabla_codec_init_reg(struct snd_soc_codec *codec) |
| 8746 | { |
| 8747 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8748 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8749 | |
| 8750 | for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++) |
| 8751 | snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg, |
| 8752 | tabla_codec_reg_init_val[i].mask, |
| 8753 | tabla_codec_reg_init_val[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8754 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8755 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++) |
| 8756 | snd_soc_update_bits(codec, |
| 8757 | tabla_1_x_codec_reg_init_val[i].reg, |
| 8758 | tabla_1_x_codec_reg_init_val[i].mask, |
| 8759 | tabla_1_x_codec_reg_init_val[i].val); |
| 8760 | } else { |
| 8761 | for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val); |
| 8762 | i++) |
| 8763 | snd_soc_update_bits(codec, |
| 8764 | tabla_2_higher_codec_reg_init_val[i].reg, |
| 8765 | tabla_2_higher_codec_reg_init_val[i].mask, |
| 8766 | tabla_2_higher_codec_reg_init_val[i].val); |
| 8767 | } |
| 8768 | } |
| 8769 | |
| 8770 | static void tabla_update_reg_address(struct tabla_priv *priv) |
| 8771 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8772 | struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8773 | struct tabla_reg_address *reg_addr = &priv->reg_addr; |
| 8774 | |
| 8775 | if (TABLA_IS_1_X(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8776 | reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC; |
| 8777 | 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] | 8778 | reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8779 | } else if (TABLA_IS_2_0(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8780 | reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC; |
| 8781 | 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] | 8782 | reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8783 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8784 | } |
| 8785 | |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8786 | #ifdef CONFIG_DEBUG_FS |
| 8787 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 8788 | { |
| 8789 | file->private_data = inode->i_private; |
| 8790 | return 0; |
| 8791 | } |
| 8792 | |
| 8793 | static ssize_t codec_debug_write(struct file *filp, |
| 8794 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 8795 | { |
| 8796 | char lbuf[32]; |
| 8797 | char *buf; |
| 8798 | int rc; |
| 8799 | struct tabla_priv *tabla = filp->private_data; |
| 8800 | |
| 8801 | if (cnt > sizeof(lbuf) - 1) |
| 8802 | return -EINVAL; |
| 8803 | |
| 8804 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 8805 | if (rc) |
| 8806 | return -EFAULT; |
| 8807 | |
| 8808 | lbuf[cnt] = '\0'; |
| 8809 | buf = (char *)lbuf; |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 8810 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8811 | tabla->no_mic_headset_override = |
| 8812 | (*strsep(&buf, " ") == '0') ? false : true; |
| 8813 | if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) { |
| 8814 | tabla_codec_pause_hs_polling(tabla->codec); |
| 8815 | tabla_codec_start_hs_polling(tabla->codec); |
| 8816 | } |
| 8817 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8818 | return cnt; |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8819 | } |
| 8820 | |
| 8821 | static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf, |
| 8822 | size_t count, loff_t *pos) |
| 8823 | { |
| 8824 | const int size = 768; |
| 8825 | char buffer[size]; |
| 8826 | int n = 0; |
| 8827 | struct tabla_priv *tabla = file->private_data; |
| 8828 | struct snd_soc_codec *codec = tabla->codec; |
| 8829 | const struct mbhc_internal_cal_data *p = &tabla->mbhc_data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8830 | const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true); |
| 8831 | 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] | 8832 | |
| 8833 | n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z, |
| 8834 | tabla_codec_sta_dce_v(codec, 1, p->dce_z)); |
| 8835 | n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n", |
| 8836 | p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb)); |
| 8837 | n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n", |
| 8838 | p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z)); |
| 8839 | n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n", |
| 8840 | p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb)); |
| 8841 | n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce); |
| 8842 | n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta); |
| 8843 | n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n", |
| 8844 | p->micb_mv); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8845 | 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] | 8846 | p->v_ins_hu, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8847 | tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu), |
| 8848 | p->v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8849 | n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n", |
| 8850 | p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h), |
| 8851 | p->v_ins_h == v_ins_h_cur ? "*" : ""); |
| 8852 | n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n", |
| 8853 | p->adj_v_ins_hu, |
| 8854 | tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu), |
| 8855 | p->adj_v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8856 | n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n", |
| 8857 | p->adj_v_ins_h, |
| 8858 | tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h), |
| 8859 | p->adj_v_ins_h == v_ins_h_cur ? "*" : ""); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8860 | n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n", |
| 8861 | p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu)); |
| 8862 | n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n", |
| 8863 | p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h)); |
| 8864 | n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n", |
| 8865 | p->v_b1_huc, |
| 8866 | tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc)); |
| 8867 | n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n", |
| 8868 | p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh)); |
| 8869 | n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl, |
| 8870 | tabla_codec_sta_dce_v(codec, 0, p->v_brl)); |
| 8871 | n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n", |
| 8872 | p->v_no_mic, |
| 8873 | tabla_codec_sta_dce_v(codec, 0, p->v_no_mic)); |
| 8874 | n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll); |
| 8875 | n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n", |
| 8876 | p->nbounce_wait); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8877 | n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n", |
| 8878 | p->v_inval_ins_low); |
| 8879 | n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n", |
| 8880 | p->v_inval_ins_high); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 8881 | if (tabla->mbhc_cfg.gpio) |
| 8882 | n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n", |
| 8883 | tabla_hs_gpio_level_remove(tabla)); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8884 | buffer[n] = 0; |
| 8885 | |
| 8886 | return simple_read_from_buffer(buf, count, pos, buffer, n); |
| 8887 | } |
| 8888 | |
| 8889 | static const struct file_operations codec_debug_ops = { |
| 8890 | .open = codec_debug_open, |
| 8891 | .write = codec_debug_write, |
| 8892 | }; |
| 8893 | |
| 8894 | static const struct file_operations codec_mbhc_debug_ops = { |
| 8895 | .open = codec_debug_open, |
| 8896 | .read = codec_mbhc_debug_read, |
| 8897 | }; |
| 8898 | #endif |
| 8899 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8900 | static int tabla_codec_probe(struct snd_soc_codec *codec) |
| 8901 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8902 | struct wcd9xxx *control; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8903 | struct tabla_priv *tabla; |
| 8904 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 8905 | int ret = 0; |
| 8906 | int i; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8907 | void *ptr = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8908 | |
| 8909 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 8910 | control = codec->control_data; |
| 8911 | |
| 8912 | tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL); |
| 8913 | if (!tabla) { |
| 8914 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 8915 | return -ENOMEM; |
| 8916 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 8917 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 8918 | tx_hpf_work[i].tabla = tabla; |
| 8919 | tx_hpf_work[i].decimator = i + 1; |
| 8920 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 8921 | tx_hpf_corner_freq_callback); |
| 8922 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8923 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8924 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 8925 | memset(&tabla->mbhc_bias_regs, 0, |
| 8926 | sizeof(struct mbhc_micbias_regs)); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 8927 | tabla->mbhc_micbias_switched = false; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8928 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8929 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 8930 | memset(&tabla->mbhc_data, 0, |
| 8931 | sizeof(struct mbhc_internal_cal_data)); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 8932 | tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8933 | tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 8934 | tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8935 | snd_soc_codec_set_drvdata(codec, tabla); |
| 8936 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 8937 | tabla->mclk_enabled = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8938 | tabla->bandgap_type = TABLA_BANDGAP_OFF; |
| 8939 | tabla->clock_active = false; |
| 8940 | tabla->config_mode_active = false; |
| 8941 | tabla->mbhc_polling_active = false; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 8942 | tabla->mbhc_fake_ins_start = 0; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8943 | tabla->no_mic_headset_override = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8944 | tabla->hs_polling_irq_prepared = false; |
| 8945 | mutex_init(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8946 | tabla->codec = codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8947 | tabla->mbhc_state = MBHC_STATE_NONE; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8948 | tabla->mbhc_last_resume = 0; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 8949 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 8950 | tabla->comp_enabled[i] = 0; |
| 8951 | tabla->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 8952 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8953 | tabla->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8954 | tabla->intf_type = wcd9xxx_get_intf_type(); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 8955 | tabla->aux_pga_cnt = 0; |
| 8956 | tabla->aux_l_gain = 0x1F; |
| 8957 | tabla->aux_r_gain = 0x1F; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8958 | tabla_update_reg_address(tabla); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8959 | tabla_update_reg_defaults(codec); |
| 8960 | tabla_codec_init_reg(codec); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8961 | ret = tabla_handle_pdata(tabla); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8962 | if (IS_ERR_VALUE(ret)) { |
| 8963 | pr_err("%s: bad pdata\n", __func__); |
| 8964 | goto err_pdata; |
| 8965 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8966 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8967 | if (TABLA_IS_1_X(control->version)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8968 | snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8969 | ARRAY_SIZE(tabla_1_x_snd_controls)); |
| 8970 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8971 | snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8972 | ARRAY_SIZE(tabla_2_higher_snd_controls)); |
| 8973 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8974 | if (TABLA_IS_1_X(control->version)) |
| 8975 | snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets, |
| 8976 | ARRAY_SIZE(tabla_1_x_dapm_widgets)); |
| 8977 | else |
| 8978 | snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets, |
| 8979 | ARRAY_SIZE(tabla_2_higher_dapm_widgets)); |
| 8980 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8981 | ptr = kmalloc((sizeof(tabla_rx_chs) + |
| 8982 | sizeof(tabla_tx_chs)), GFP_KERNEL); |
| 8983 | if (!ptr) { |
| 8984 | pr_err("%s: no mem for slim chan ctl data\n", __func__); |
| 8985 | ret = -ENOMEM; |
| 8986 | goto err_nomem_slimch; |
| 8987 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8988 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8989 | snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets, |
| 8990 | ARRAY_SIZE(tabla_dapm_i2s_widgets)); |
| 8991 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 8992 | ARRAY_SIZE(audio_i2s_map)); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8993 | for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++) |
| 8994 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8995 | } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 8996 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 8997 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8998 | init_waitqueue_head(&tabla->dai[i].dai_wait); |
| 8999 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9000 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 9001 | |
| 9002 | control->num_rx_port = TABLA_RX_MAX; |
| 9003 | control->rx_chs = ptr; |
| 9004 | memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs)); |
| 9005 | control->num_tx_port = TABLA_TX_MAX; |
| 9006 | control->tx_chs = ptr + sizeof(tabla_rx_chs); |
| 9007 | memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs)); |
| 9008 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 9009 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 9010 | if (TABLA_IS_1_X(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 9011 | 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] | 9012 | ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map)); |
| 9013 | } else if (TABLA_IS_2_0(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 9014 | 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] | 9015 | ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map)); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 9016 | } else { |
| 9017 | pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n", |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9018 | __func__, control->version); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 9019 | goto err_pdata; |
| 9020 | } |
| 9021 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9022 | snd_soc_dapm_sync(dapm); |
| 9023 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9024 | ret = wcd9xxx_request_irq(codec->control_data, |
| 9025 | WCD9XXX_IRQ_MBHC_INSERTION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9026 | tabla_hs_insert_irq, "Headset insert detect", tabla); |
| 9027 | if (ret) { |
| 9028 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9029 | WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9030 | goto err_insert_irq; |
| 9031 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9032 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9033 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9034 | ret = wcd9xxx_request_irq(codec->control_data, |
| 9035 | WCD9XXX_IRQ_MBHC_REMOVAL, |
| 9036 | tabla_hs_remove_irq, |
| 9037 | "Headset remove detect", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9038 | if (ret) { |
| 9039 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9040 | WCD9XXX_IRQ_MBHC_REMOVAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9041 | goto err_remove_irq; |
| 9042 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9043 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9044 | ret = wcd9xxx_request_irq(codec->control_data, |
| 9045 | WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 9046 | tabla_dce_handler, "DC Estimation detect", |
| 9047 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9048 | if (ret) { |
| 9049 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9050 | WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9051 | goto err_potential_irq; |
| 9052 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9053 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9054 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, |
| 9055 | tabla_release_handler, |
| 9056 | "Button Release detect", tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9057 | if (ret) { |
| 9058 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9059 | WCD9XXX_IRQ_MBHC_RELEASE); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9060 | goto err_release_irq; |
| 9061 | } |
| 9062 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9063 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, |
| 9064 | tabla_slimbus_irq, "SLIMBUS Slave", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9065 | if (ret) { |
| 9066 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9067 | WCD9XXX_IRQ_SLIMBUS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9068 | goto err_slimbus_irq; |
| 9069 | } |
| 9070 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9071 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 9072 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9073 | TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 9074 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9075 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9076 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, |
| 9077 | tabla_hphl_ocp_irq, |
| 9078 | "HPH_L OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9079 | if (ret) { |
| 9080 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9081 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9082 | goto err_hphl_ocp_irq; |
| 9083 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9084 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9085 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9086 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9087 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT, |
| 9088 | tabla_hphr_ocp_irq, |
| 9089 | "HPH_R OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9090 | if (ret) { |
| 9091 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9092 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9093 | goto err_hphr_ocp_irq; |
| 9094 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9095 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9096 | |
| 9097 | /* |
| 9098 | * Register suspend lock and notifier to resend edge triggered |
| 9099 | * gpio IRQs |
| 9100 | */ |
| 9101 | wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND, |
| 9102 | "tabla_gpio_irq_resend"); |
| 9103 | tabla->gpio_irq_resend = false; |
| 9104 | |
Damir Didjusto | c6f83cb | 2012-12-03 00:54:14 -0800 | [diff] [blame] | 9105 | mutex_lock(&dapm->codec->mutex); |
| 9106 | snd_soc_dapm_disable_pin(dapm, "ANC HPHL"); |
| 9107 | snd_soc_dapm_disable_pin(dapm, "ANC HPHR"); |
| 9108 | snd_soc_dapm_disable_pin(dapm, "ANC HEADPHONE"); |
| 9109 | snd_soc_dapm_sync(dapm); |
| 9110 | mutex_unlock(&dapm->codec->mutex); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9111 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9112 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 9113 | if (ret == 0) { |
| 9114 | tabla->debugfs_poke = |
| 9115 | debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla, |
| 9116 | &codec_debug_ops); |
| 9117 | tabla->debugfs_mbhc = |
| 9118 | debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO, |
| 9119 | NULL, tabla, &codec_mbhc_debug_ops); |
| 9120 | } |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9121 | #endif |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9122 | codec->ignore_pmdown_time = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9123 | return ret; |
| 9124 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9125 | err_hphr_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9126 | wcd9xxx_free_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9127 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 9128 | err_hphl_ocp_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9129 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9130 | err_slimbus_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9131 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 9132 | err_release_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9133 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 9134 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9135 | err_potential_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9136 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9137 | err_remove_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9138 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 9139 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9140 | err_insert_irq: |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 9141 | err_pdata: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 9142 | kfree(ptr); |
| 9143 | err_nomem_slimch: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9144 | mutex_destroy(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9145 | kfree(tabla); |
| 9146 | return ret; |
| 9147 | } |
| 9148 | static int tabla_codec_remove(struct snd_soc_codec *codec) |
| 9149 | { |
| 9150 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9151 | |
| 9152 | wake_lock_destroy(&tabla->irq_resend_wlock); |
| 9153 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 9154 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
| 9155 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
| 9156 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 9157 | tabla); |
| 9158 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
| 9159 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 9160 | tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9161 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9162 | tabla_codec_disable_clock_block(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9163 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9164 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 9165 | if (tabla->mbhc_fw) |
| 9166 | release_firmware(tabla->mbhc_fw); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 9167 | mutex_destroy(&tabla->codec_resource_lock); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 9168 | #ifdef CONFIG_DEBUG_FS |
| 9169 | debugfs_remove(tabla->debugfs_poke); |
| 9170 | debugfs_remove(tabla->debugfs_mbhc); |
| 9171 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9172 | kfree(tabla); |
| 9173 | return 0; |
| 9174 | } |
| 9175 | static struct snd_soc_codec_driver soc_codec_dev_tabla = { |
| 9176 | .probe = tabla_codec_probe, |
| 9177 | .remove = tabla_codec_remove, |
| 9178 | .read = tabla_read, |
| 9179 | .write = tabla_write, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9180 | .readable_register = tabla_readable, |
| 9181 | .volatile_register = tabla_volatile, |
| 9182 | |
| 9183 | .reg_cache_size = TABLA_CACHE_SIZE, |
| 9184 | .reg_cache_default = tabla_reg_defaults, |
| 9185 | .reg_word_size = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9186 | .controls = tabla_snd_controls, |
| 9187 | .num_controls = ARRAY_SIZE(tabla_snd_controls), |
| 9188 | .dapm_widgets = tabla_dapm_widgets, |
| 9189 | .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets), |
| 9190 | .dapm_routes = audio_map, |
| 9191 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9192 | }; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 9193 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9194 | #ifdef CONFIG_PM |
| 9195 | static int tabla_suspend(struct device *dev) |
| 9196 | { |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 9197 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 9198 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9199 | } |
| 9200 | |
| 9201 | static int tabla_resume(struct device *dev) |
| 9202 | { |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9203 | int irq; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 9204 | struct platform_device *pdev = to_platform_device(dev); |
| 9205 | struct tabla_priv *tabla = platform_get_drvdata(pdev); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9206 | |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 9207 | dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9208 | if (tabla) { |
| 9209 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 9210 | tabla->mbhc_last_resume = jiffies; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 9211 | if (tabla->gpio_irq_resend) { |
| 9212 | WARN_ON(!tabla->mbhc_cfg.gpio_irq); |
| 9213 | tabla->gpio_irq_resend = false; |
| 9214 | |
| 9215 | irq = tabla->mbhc_cfg.gpio_irq; |
| 9216 | pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq); |
| 9217 | irq_set_pending(irq); |
| 9218 | check_irq_resend(irq_to_desc(irq), irq); |
| 9219 | |
| 9220 | /* release suspend lock */ |
| 9221 | wake_unlock(&tabla->irq_resend_wlock); |
| 9222 | } |
| 9223 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 9224 | } |
| 9225 | |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 9226 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9227 | } |
| 9228 | |
| 9229 | static const struct dev_pm_ops tabla_pm_ops = { |
| 9230 | .suspend = tabla_suspend, |
| 9231 | .resume = tabla_resume, |
| 9232 | }; |
| 9233 | #endif |
| 9234 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9235 | static int __devinit tabla_probe(struct platform_device *pdev) |
| 9236 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9237 | int ret = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 9238 | pr_err("tabla_probe\n"); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9239 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9240 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 9241 | tabla_dai, ARRAY_SIZE(tabla_dai)); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 9242 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 9243 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 9244 | tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai)); |
| 9245 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9246 | } |
| 9247 | static int __devexit tabla_remove(struct platform_device *pdev) |
| 9248 | { |
| 9249 | snd_soc_unregister_codec(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9250 | return 0; |
| 9251 | } |
| 9252 | static struct platform_driver tabla_codec_driver = { |
| 9253 | .probe = tabla_probe, |
| 9254 | .remove = tabla_remove, |
| 9255 | .driver = { |
| 9256 | .name = "tabla_codec", |
| 9257 | .owner = THIS_MODULE, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 9258 | #ifdef CONFIG_PM |
| 9259 | .pm = &tabla_pm_ops, |
| 9260 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9261 | }, |
| 9262 | }; |
| 9263 | |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9264 | static struct platform_driver tabla1x_codec_driver = { |
| 9265 | .probe = tabla_probe, |
| 9266 | .remove = tabla_remove, |
| 9267 | .driver = { |
| 9268 | .name = "tabla1x_codec", |
| 9269 | .owner = THIS_MODULE, |
| 9270 | #ifdef CONFIG_PM |
| 9271 | .pm = &tabla_pm_ops, |
| 9272 | #endif |
| 9273 | }, |
| 9274 | }; |
| 9275 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9276 | static int __init tabla_codec_init(void) |
| 9277 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9278 | int rtn = platform_driver_register(&tabla_codec_driver); |
| 9279 | if (rtn == 0) { |
| 9280 | rtn = platform_driver_register(&tabla1x_codec_driver); |
| 9281 | if (rtn != 0) |
| 9282 | platform_driver_unregister(&tabla_codec_driver); |
| 9283 | } |
| 9284 | return rtn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9285 | } |
| 9286 | |
| 9287 | static void __exit tabla_codec_exit(void) |
| 9288 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 9289 | platform_driver_unregister(&tabla1x_codec_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 9290 | platform_driver_unregister(&tabla_codec_driver); |
| 9291 | } |
| 9292 | |
| 9293 | module_init(tabla_codec_init); |
| 9294 | module_exit(tabla_codec_exit); |
| 9295 | |
| 9296 | MODULE_DESCRIPTION("Tabla codec driver"); |
| 9297 | MODULE_VERSION("1.0"); |
| 9298 | MODULE_LICENSE("GPL v2"); |