Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +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 |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 57 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 58 | #define SLIM_CLOSE_TIMEOUT 1000 |
| 59 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 60 | enum { |
| 61 | MBHC_USE_HPHL_TRIGGER = 1, |
| 62 | MBHC_USE_MB_TRIGGER = 2 |
| 63 | }; |
| 64 | |
| 65 | #define MBHC_NUM_DCE_PLUG_DETECT 3 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 66 | #define NUM_ATTEMPTS_INSERT_DETECT 25 |
| 67 | #define NUM_ATTEMPTS_TO_REPORT 5 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 68 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 69 | #define TABLA_JACK_MASK (SND_JACK_HEADSET | SND_JACK_OC_HPHL | \ |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 70 | SND_JACK_OC_HPHR | SND_JACK_LINEOUT | \ |
| 71 | SND_JACK_UNSUPPORTED) |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 72 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 73 | #define TABLA_I2S_MASTER_MODE_MASK 0x08 |
| 74 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 75 | #define TABLA_OCP_ATTEMPT 1 |
| 76 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 77 | enum { |
| 78 | AIF1_PB = 0, |
| 79 | AIF1_CAP, |
| 80 | AIF2_PB, |
| 81 | AIF2_CAP, |
| 82 | AIF3_PB, |
| 83 | AIF3_CAP, |
| 84 | NUM_CODEC_DAIS, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 87 | enum { |
| 88 | RX_MIX1_INP_SEL_ZERO = 0, |
| 89 | RX_MIX1_INP_SEL_SRC1, |
| 90 | RX_MIX1_INP_SEL_SRC2, |
| 91 | RX_MIX1_INP_SEL_IIR1, |
| 92 | RX_MIX1_INP_SEL_IIR2, |
| 93 | RX_MIX1_INP_SEL_RX1, |
| 94 | RX_MIX1_INP_SEL_RX2, |
| 95 | RX_MIX1_INP_SEL_RX3, |
| 96 | RX_MIX1_INP_SEL_RX4, |
| 97 | RX_MIX1_INP_SEL_RX5, |
| 98 | RX_MIX1_INP_SEL_RX6, |
| 99 | RX_MIX1_INP_SEL_RX7, |
| 100 | }; |
| 101 | |
| 102 | #define TABLA_COMP_DIGITAL_GAIN_OFFSET 3 |
| 103 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 104 | #define TABLA_MCLK_RATE_12288KHZ 12288000 |
| 105 | #define TABLA_MCLK_RATE_9600KHZ 9600000 |
| 106 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 107 | #define TABLA_FAKE_INS_THRESHOLD_MS 2500 |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 108 | #define TABLA_FAKE_REMOVAL_MIN_PERIOD_MS 50 |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 109 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 110 | #define TABLA_MBHC_BUTTON_MIN 0x8000 |
| 111 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 112 | #define TABLA_MBHC_FAKE_INSERT_LOW 10 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 113 | #define TABLA_MBHC_FAKE_INSERT_HIGH 80 |
| 114 | #define TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO 150 |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 115 | |
| 116 | #define TABLA_MBHC_STATUS_REL_DETECTION 0x0C |
| 117 | |
Joonwoo Park | db606b0 | 2012-08-11 13:46:30 -0700 | [diff] [blame] | 118 | #define TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS 50 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 119 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 120 | #define TABLA_MBHC_FAKE_INS_DELTA_MV 200 |
| 121 | #define TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV 300 |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 122 | |
| 123 | #define TABLA_HS_DETECT_PLUG_TIME_MS (5 * 1000) |
| 124 | #define TABLA_HS_DETECT_PLUG_INERVAL_MS 100 |
| 125 | |
| 126 | #define TABLA_GPIO_IRQ_DEBOUNCE_TIME_US 5000 |
| 127 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 128 | #define TABLA_MBHC_GND_MIC_SWAP_THRESHOLD 2 |
| 129 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 130 | #define TABLA_ACQUIRE_LOCK(x) do { mutex_lock(&x); } while (0) |
| 131 | #define TABLA_RELEASE_LOCK(x) do { mutex_unlock(&x); } while (0) |
| 132 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 133 | static const DECLARE_TLV_DB_SCALE(digital_gain, 0, 1, 0); |
| 134 | static const DECLARE_TLV_DB_SCALE(line_gain, 0, 7, 1); |
| 135 | static const DECLARE_TLV_DB_SCALE(analog_gain, 0, 25, 1); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 136 | static struct snd_soc_dai_driver tabla_dai[]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 137 | static const DECLARE_TLV_DB_SCALE(aux_pga_gain, 0, 2, 0); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 138 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
| 139 | struct snd_kcontrol *kcontrol, int event); |
| 140 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
| 141 | struct snd_kcontrol *kcontrol, int event); |
| 142 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 143 | |
| 144 | enum tabla_bandgap_type { |
| 145 | TABLA_BANDGAP_OFF = 0, |
| 146 | TABLA_BANDGAP_AUDIO_MODE, |
| 147 | TABLA_BANDGAP_MBHC_MODE, |
| 148 | }; |
| 149 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 150 | struct mbhc_micbias_regs { |
| 151 | u16 cfilt_val; |
| 152 | u16 cfilt_ctl; |
| 153 | u16 mbhc_reg; |
| 154 | u16 int_rbias; |
| 155 | u16 ctl_reg; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 156 | u8 cfilt_sel; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 159 | /* Codec supports 2 IIR filters */ |
| 160 | enum { |
| 161 | IIR1 = 0, |
| 162 | IIR2, |
| 163 | IIR_MAX, |
| 164 | }; |
| 165 | /* Codec supports 5 bands */ |
| 166 | enum { |
| 167 | BAND1 = 0, |
| 168 | BAND2, |
| 169 | BAND3, |
| 170 | BAND4, |
| 171 | BAND5, |
| 172 | BAND_MAX, |
| 173 | }; |
| 174 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 175 | enum { |
| 176 | COMPANDER_1 = 0, |
| 177 | COMPANDER_2, |
| 178 | COMPANDER_MAX, |
| 179 | }; |
| 180 | |
| 181 | enum { |
| 182 | COMPANDER_FS_8KHZ = 0, |
| 183 | COMPANDER_FS_16KHZ, |
| 184 | COMPANDER_FS_32KHZ, |
| 185 | COMPANDER_FS_48KHZ, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 186 | COMPANDER_FS_96KHZ, |
| 187 | COMPANDER_FS_192KHZ, |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 188 | COMPANDER_FS_MAX, |
| 189 | }; |
| 190 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 191 | /* Flags to track of PA and DAC state. |
| 192 | * PA and DAC should be tracked separately as AUXPGA loopback requires |
| 193 | * only PA to be turned on without DAC being on. */ |
| 194 | enum tabla_priv_ack_flags { |
| 195 | TABLA_HPHL_PA_OFF_ACK = 0, |
| 196 | TABLA_HPHR_PA_OFF_ACK, |
| 197 | TABLA_HPHL_DAC_OFF_ACK, |
| 198 | TABLA_HPHR_DAC_OFF_ACK |
| 199 | }; |
| 200 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 201 | |
| 202 | struct comp_sample_dependent_params { |
| 203 | u32 peak_det_timeout; |
| 204 | u32 rms_meter_div_fact; |
| 205 | u32 rms_meter_resamp_fact; |
| 206 | }; |
| 207 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 208 | /* Data used by MBHC */ |
| 209 | struct mbhc_internal_cal_data { |
| 210 | u16 dce_z; |
| 211 | u16 dce_mb; |
| 212 | u16 sta_z; |
| 213 | u16 sta_mb; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 214 | u32 t_sta_dce; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 215 | u32 t_dce; |
| 216 | u32 t_sta; |
| 217 | u32 micb_mv; |
| 218 | u16 v_ins_hu; |
| 219 | u16 v_ins_h; |
| 220 | u16 v_b1_hu; |
| 221 | u16 v_b1_h; |
| 222 | u16 v_b1_huc; |
| 223 | u16 v_brh; |
| 224 | u16 v_brl; |
| 225 | u16 v_no_mic; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 226 | u8 npoll; |
| 227 | u8 nbounce_wait; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 228 | s16 adj_v_hs_max; |
| 229 | u16 adj_v_ins_hu; |
| 230 | u16 adj_v_ins_h; |
| 231 | s16 v_inval_ins_low; |
| 232 | s16 v_inval_ins_high; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 233 | }; |
| 234 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 235 | struct tabla_reg_address { |
| 236 | u16 micb_4_ctl; |
| 237 | u16 micb_4_int_rbias; |
| 238 | u16 micb_4_mbhc; |
| 239 | }; |
| 240 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 241 | enum tabla_mbhc_plug_type { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 242 | PLUG_TYPE_INVALID = -1, |
| 243 | PLUG_TYPE_NONE, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 244 | PLUG_TYPE_HEADSET, |
| 245 | PLUG_TYPE_HEADPHONE, |
| 246 | PLUG_TYPE_HIGH_HPH, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 247 | PLUG_TYPE_GND_MIC_SWAP, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | enum tabla_mbhc_state { |
| 251 | MBHC_STATE_NONE = -1, |
| 252 | MBHC_STATE_POTENTIAL, |
| 253 | MBHC_STATE_POTENTIAL_RECOVERY, |
| 254 | MBHC_STATE_RELEASE, |
| 255 | }; |
| 256 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 257 | struct hpf_work { |
| 258 | struct tabla_priv *tabla; |
| 259 | u32 decimator; |
| 260 | u8 tx_hpf_cut_of_freq; |
| 261 | struct delayed_work dwork; |
| 262 | }; |
| 263 | |
| 264 | static struct hpf_work tx_hpf_work[NUM_DECIMATORS]; |
| 265 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 266 | static const struct wcd9xxx_ch tabla_rx_chs[TABLA_RX_MAX] = { |
| 267 | WCD9XXX_CH(10, 0), |
| 268 | WCD9XXX_CH(11, 1), |
| 269 | WCD9XXX_CH(12, 2), |
| 270 | WCD9XXX_CH(13, 3), |
| 271 | WCD9XXX_CH(14, 4), |
| 272 | WCD9XXX_CH(15, 5), |
| 273 | WCD9XXX_CH(16, 6) |
| 274 | }; |
| 275 | |
| 276 | static const struct wcd9xxx_ch tabla_tx_chs[TABLA_TX_MAX] = { |
| 277 | WCD9XXX_CH(0, 0), |
| 278 | WCD9XXX_CH(1, 1), |
| 279 | WCD9XXX_CH(2, 2), |
| 280 | WCD9XXX_CH(3, 3), |
| 281 | WCD9XXX_CH(4, 4), |
| 282 | WCD9XXX_CH(5, 5), |
| 283 | WCD9XXX_CH(6, 6), |
| 284 | WCD9XXX_CH(7, 7), |
| 285 | WCD9XXX_CH(8, 8), |
| 286 | WCD9XXX_CH(9, 9) |
| 287 | }; |
| 288 | |
| 289 | static const u32 vport_check_table[NUM_CODEC_DAIS] = { |
| 290 | 0, /* AIF1_PB */ |
| 291 | (1 << AIF2_CAP) | (1 << AIF3_CAP), /* AIF1_CAP */ |
| 292 | 0, /* AIF2_PB */ |
| 293 | (1 << AIF1_CAP) | (1 << AIF3_CAP), /* AIF2_CAP */ |
| 294 | 0, /* AIF2_PB */ |
| 295 | (1 << AIF1_CAP) | (1 << AIF2_CAP), /* AIF2_CAP */ |
| 296 | }; |
| 297 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 298 | struct tabla_priv { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 299 | struct snd_soc_codec *codec; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 300 | struct tabla_reg_address reg_addr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 301 | u32 adc_count; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 302 | u32 cfilt1_cnt; |
| 303 | u32 cfilt2_cnt; |
| 304 | u32 cfilt3_cnt; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 305 | u32 rx_bias_count; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 306 | s32 dmic_1_2_clk_cnt; |
| 307 | s32 dmic_3_4_clk_cnt; |
| 308 | s32 dmic_5_6_clk_cnt; |
| 309 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 310 | enum tabla_bandgap_type bandgap_type; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 311 | bool mclk_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | bool clock_active; |
| 313 | bool config_mode_active; |
| 314 | bool mbhc_polling_active; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 315 | unsigned long mbhc_fake_ins_start; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 316 | int buttons_pressed; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 317 | enum tabla_mbhc_state mbhc_state; |
| 318 | struct tabla_mbhc_config mbhc_cfg; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 319 | struct mbhc_internal_cal_data mbhc_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 320 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 321 | struct wcd9xxx_pdata *pdata; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 322 | u32 anc_slot; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 323 | |
| 324 | bool no_mic_headset_override; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 325 | /* Delayed work to report long button press */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 326 | struct delayed_work mbhc_btn_dwork; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 327 | |
| 328 | struct mbhc_micbias_regs mbhc_bias_regs; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 329 | bool mbhc_micbias_switched; |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 330 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 331 | /* track PA/DAC state */ |
| 332 | unsigned long hph_pa_dac_state; |
| 333 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 334 | /*track tabla interface type*/ |
| 335 | u8 intf_type; |
| 336 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 337 | u32 hph_status; /* track headhpone status */ |
| 338 | /* define separate work for left and right headphone OCP to avoid |
| 339 | * additional checking on which OCP event to report so no locking |
| 340 | * to ensure synchronization is required |
| 341 | */ |
| 342 | struct work_struct hphlocp_work; /* reporting left hph ocp off */ |
| 343 | struct work_struct hphrocp_work; /* reporting right hph ocp off */ |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 344 | |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 345 | u8 hphlocp_cnt; /* headphone left ocp retry */ |
| 346 | u8 hphrocp_cnt; /* headphone right ocp retry */ |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 347 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 348 | /* Work to perform MBHC Firmware Read */ |
| 349 | struct delayed_work mbhc_firmware_dwork; |
| 350 | const struct firmware *mbhc_fw; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 351 | |
| 352 | /* num of slim ports required */ |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 353 | struct wcd9xxx_codec_dai_data dai[NUM_CODEC_DAIS]; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 354 | |
| 355 | /*compander*/ |
| 356 | int comp_enabled[COMPANDER_MAX]; |
| 357 | u32 comp_fs[COMPANDER_MAX]; |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 358 | |
| 359 | /* Maintain the status of AUX PGA */ |
| 360 | int aux_pga_cnt; |
| 361 | u8 aux_l_gain; |
| 362 | u8 aux_r_gain; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 363 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 364 | struct delayed_work mbhc_insert_dwork; |
| 365 | unsigned long mbhc_last_resume; /* in jiffies */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 366 | |
| 367 | u8 current_plug; |
| 368 | struct work_struct hs_correct_plug_work; |
| 369 | bool hs_detect_work_stop; |
| 370 | bool hs_polling_irq_prepared; |
| 371 | bool lpi_enabled; /* low power insertion detection */ |
| 372 | bool in_gpio_handler; |
| 373 | /* Currently, only used for mbhc purpose, to protect |
| 374 | * concurrent execution of mbhc threaded irq handlers and |
| 375 | * kill race between DAPM and MBHC.But can serve as a |
| 376 | * general lock to protect codec resource |
| 377 | */ |
| 378 | struct mutex codec_resource_lock; |
| 379 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 380 | /* Work to perform polling on microphone voltage |
| 381 | * in order to correct plug type once plug type |
| 382 | * is detected as headphone |
| 383 | */ |
| 384 | struct work_struct hs_correct_plug_work_nogpio; |
| 385 | |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 386 | bool gpio_irq_resend; |
| 387 | struct wake_lock irq_resend_wlock; |
| 388 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 389 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 390 | struct dentry *debugfs_poke; |
| 391 | struct dentry *debugfs_mbhc; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 392 | #endif |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 393 | }; |
| 394 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 395 | static const u32 comp_shift[] = { |
| 396 | 0, |
| 397 | 2, |
| 398 | }; |
| 399 | |
| 400 | static const int comp_rx_path[] = { |
| 401 | COMPANDER_1, |
| 402 | COMPANDER_1, |
| 403 | COMPANDER_2, |
| 404 | COMPANDER_2, |
| 405 | COMPANDER_2, |
| 406 | COMPANDER_2, |
| 407 | COMPANDER_MAX, |
| 408 | }; |
| 409 | |
| 410 | static const struct comp_sample_dependent_params comp_samp_params[] = { |
| 411 | { |
| 412 | .peak_det_timeout = 0x2, |
| 413 | .rms_meter_div_fact = 0x8 << 4, |
| 414 | .rms_meter_resamp_fact = 0x21, |
| 415 | }, |
| 416 | { |
| 417 | .peak_det_timeout = 0x3, |
| 418 | .rms_meter_div_fact = 0x9 << 4, |
| 419 | .rms_meter_resamp_fact = 0x28, |
| 420 | }, |
| 421 | |
| 422 | { |
| 423 | .peak_det_timeout = 0x5, |
| 424 | .rms_meter_div_fact = 0xB << 4, |
| 425 | .rms_meter_resamp_fact = 0x28, |
| 426 | }, |
| 427 | |
| 428 | { |
| 429 | .peak_det_timeout = 0x5, |
| 430 | .rms_meter_div_fact = 0xB << 4, |
| 431 | .rms_meter_resamp_fact = 0x28, |
| 432 | }, |
| 433 | }; |
| 434 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 435 | static unsigned short rx_digital_gain_reg[] = { |
| 436 | TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 437 | TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 438 | TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 439 | TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 440 | TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 441 | TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 442 | TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 443 | }; |
| 444 | |
| 445 | |
| 446 | static unsigned short tx_digital_gain_reg[] = { |
| 447 | TABLA_A_CDC_TX1_VOL_CTL_GAIN, |
| 448 | TABLA_A_CDC_TX2_VOL_CTL_GAIN, |
| 449 | TABLA_A_CDC_TX3_VOL_CTL_GAIN, |
| 450 | TABLA_A_CDC_TX4_VOL_CTL_GAIN, |
| 451 | TABLA_A_CDC_TX5_VOL_CTL_GAIN, |
| 452 | TABLA_A_CDC_TX6_VOL_CTL_GAIN, |
| 453 | TABLA_A_CDC_TX7_VOL_CTL_GAIN, |
| 454 | TABLA_A_CDC_TX8_VOL_CTL_GAIN, |
| 455 | TABLA_A_CDC_TX9_VOL_CTL_GAIN, |
| 456 | TABLA_A_CDC_TX10_VOL_CTL_GAIN, |
| 457 | }; |
| 458 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 459 | static int tabla_codec_enable_charge_pump(struct snd_soc_dapm_widget *w, |
| 460 | struct snd_kcontrol *kcontrol, int event) |
| 461 | { |
| 462 | struct snd_soc_codec *codec = w->codec; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | |
| 464 | pr_debug("%s %d\n", __func__, event); |
| 465 | switch (event) { |
| 466 | case SND_SOC_DAPM_POST_PMU: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 467 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 468 | 0x01); |
| 469 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x08); |
| 470 | usleep_range(200, 200); |
| 471 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x00); |
| 472 | break; |
| 473 | case SND_SOC_DAPM_PRE_PMD: |
| 474 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_RESET_CTL, 0x10, |
| 475 | 0x10); |
| 476 | usleep_range(20, 20); |
| 477 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x08); |
| 478 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x10, 0x10); |
| 479 | snd_soc_update_bits(codec, TABLA_A_CDC_CLSG_CTL, 0x08, 0x00); |
| 480 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x01, |
| 481 | 0x00); |
| 482 | snd_soc_update_bits(codec, TABLA_A_CP_STATIC, 0x08, 0x00); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 483 | break; |
| 484 | } |
| 485 | return 0; |
| 486 | } |
| 487 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 488 | static int tabla_get_anc_slot(struct snd_kcontrol *kcontrol, |
| 489 | struct snd_ctl_elem_value *ucontrol) |
| 490 | { |
| 491 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 492 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 493 | ucontrol->value.integer.value[0] = tabla->anc_slot; |
| 494 | return 0; |
| 495 | } |
| 496 | |
| 497 | static int tabla_put_anc_slot(struct snd_kcontrol *kcontrol, |
| 498 | struct snd_ctl_elem_value *ucontrol) |
| 499 | { |
| 500 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 501 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 502 | tabla->anc_slot = ucontrol->value.integer.value[0]; |
| 503 | return 0; |
| 504 | } |
| 505 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 506 | static int tabla_pa_gain_get(struct snd_kcontrol *kcontrol, |
| 507 | struct snd_ctl_elem_value *ucontrol) |
| 508 | { |
| 509 | u8 ear_pa_gain; |
| 510 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 511 | |
| 512 | ear_pa_gain = snd_soc_read(codec, TABLA_A_RX_EAR_GAIN); |
| 513 | |
| 514 | ear_pa_gain = ear_pa_gain >> 5; |
| 515 | |
| 516 | if (ear_pa_gain == 0x00) { |
| 517 | ucontrol->value.integer.value[0] = 0; |
| 518 | } else if (ear_pa_gain == 0x04) { |
| 519 | ucontrol->value.integer.value[0] = 1; |
| 520 | } else { |
| 521 | pr_err("%s: ERROR: Unsupported Ear Gain = 0x%x\n", |
| 522 | __func__, ear_pa_gain); |
| 523 | return -EINVAL; |
| 524 | } |
| 525 | |
| 526 | pr_debug("%s: ear_pa_gain = 0x%x\n", __func__, ear_pa_gain); |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | static int tabla_pa_gain_put(struct snd_kcontrol *kcontrol, |
| 532 | struct snd_ctl_elem_value *ucontrol) |
| 533 | { |
| 534 | u8 ear_pa_gain; |
| 535 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 536 | |
| 537 | pr_debug("%s: ucontrol->value.integer.value[0] = %ld\n", __func__, |
| 538 | ucontrol->value.integer.value[0]); |
| 539 | |
| 540 | switch (ucontrol->value.integer.value[0]) { |
| 541 | case 0: |
| 542 | ear_pa_gain = 0x00; |
| 543 | break; |
| 544 | case 1: |
| 545 | ear_pa_gain = 0x80; |
| 546 | break; |
| 547 | default: |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_GAIN, 0xE0, ear_pa_gain); |
| 552 | return 0; |
| 553 | } |
| 554 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 555 | static int tabla_get_iir_enable_audio_mixer( |
| 556 | struct snd_kcontrol *kcontrol, |
| 557 | struct snd_ctl_elem_value *ucontrol) |
| 558 | { |
| 559 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 560 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 561 | kcontrol->private_value)->reg; |
| 562 | int band_idx = ((struct soc_multi_mixer_control *) |
| 563 | kcontrol->private_value)->shift; |
| 564 | |
| 565 | ucontrol->value.integer.value[0] = |
| 566 | snd_soc_read(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx)) & |
| 567 | (1 << band_idx); |
| 568 | |
| 569 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 570 | iir_idx, band_idx, |
| 571 | (uint32_t)ucontrol->value.integer.value[0]); |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int tabla_put_iir_enable_audio_mixer( |
| 576 | struct snd_kcontrol *kcontrol, |
| 577 | struct snd_ctl_elem_value *ucontrol) |
| 578 | { |
| 579 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 580 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 581 | kcontrol->private_value)->reg; |
| 582 | int band_idx = ((struct soc_multi_mixer_control *) |
| 583 | kcontrol->private_value)->shift; |
| 584 | int value = ucontrol->value.integer.value[0]; |
| 585 | |
| 586 | /* Mask first 5 bits, 6-8 are reserved */ |
| 587 | snd_soc_update_bits(codec, (TABLA_A_CDC_IIR1_CTL + 16 * iir_idx), |
| 588 | (1 << band_idx), (value << band_idx)); |
| 589 | |
| 590 | pr_debug("%s: IIR #%d band #%d enable %d\n", __func__, |
| 591 | iir_idx, band_idx, value); |
| 592 | return 0; |
| 593 | } |
| 594 | static uint32_t get_iir_band_coeff(struct snd_soc_codec *codec, |
| 595 | int iir_idx, int band_idx, |
| 596 | int coeff_idx) |
| 597 | { |
| 598 | /* Address does not automatically update if reading */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 599 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 600 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 601 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 602 | |
| 603 | /* Mask bits top 2 bits since they are reserved */ |
| 604 | return ((snd_soc_read(codec, |
| 605 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx)) << 24) | |
| 606 | (snd_soc_read(codec, |
| 607 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx)) << 16) | |
| 608 | (snd_soc_read(codec, |
| 609 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx)) << 8) | |
| 610 | (snd_soc_read(codec, |
| 611 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx)))) & |
| 612 | 0x3FFFFFFF; |
| 613 | } |
| 614 | |
| 615 | static int tabla_get_iir_band_audio_mixer( |
| 616 | struct snd_kcontrol *kcontrol, |
| 617 | struct snd_ctl_elem_value *ucontrol) |
| 618 | { |
| 619 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 620 | int iir_idx = ((struct soc_multi_mixer_control *) |
| 621 | kcontrol->private_value)->reg; |
| 622 | int band_idx = ((struct soc_multi_mixer_control *) |
| 623 | kcontrol->private_value)->shift; |
| 624 | |
| 625 | ucontrol->value.integer.value[0] = |
| 626 | get_iir_band_coeff(codec, iir_idx, band_idx, 0); |
| 627 | ucontrol->value.integer.value[1] = |
| 628 | get_iir_band_coeff(codec, iir_idx, band_idx, 1); |
| 629 | ucontrol->value.integer.value[2] = |
| 630 | get_iir_band_coeff(codec, iir_idx, band_idx, 2); |
| 631 | ucontrol->value.integer.value[3] = |
| 632 | get_iir_band_coeff(codec, iir_idx, band_idx, 3); |
| 633 | ucontrol->value.integer.value[4] = |
| 634 | get_iir_band_coeff(codec, iir_idx, band_idx, 4); |
| 635 | |
| 636 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 637 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 638 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 639 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 640 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 641 | __func__, iir_idx, band_idx, |
| 642 | (uint32_t)ucontrol->value.integer.value[0], |
| 643 | __func__, iir_idx, band_idx, |
| 644 | (uint32_t)ucontrol->value.integer.value[1], |
| 645 | __func__, iir_idx, band_idx, |
| 646 | (uint32_t)ucontrol->value.integer.value[2], |
| 647 | __func__, iir_idx, band_idx, |
| 648 | (uint32_t)ucontrol->value.integer.value[3], |
| 649 | __func__, iir_idx, band_idx, |
| 650 | (uint32_t)ucontrol->value.integer.value[4]); |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static void set_iir_band_coeff(struct snd_soc_codec *codec, |
| 655 | int iir_idx, int band_idx, |
| 656 | int coeff_idx, uint32_t value) |
| 657 | { |
| 658 | /* Mask top 3 bits, 6-8 are reserved */ |
| 659 | /* Update address manually each time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 660 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 661 | (TABLA_A_CDC_IIR1_COEF_B1_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 662 | (band_idx * BAND_MAX + coeff_idx) & 0x1F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 663 | |
| 664 | /* Mask top 2 bits, 7-8 are reserved */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 665 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 666 | (TABLA_A_CDC_IIR1_COEF_B2_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 667 | (value >> 24) & 0x3F); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 668 | |
| 669 | /* Isolate 8bits at a time */ |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 670 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 671 | (TABLA_A_CDC_IIR1_COEF_B3_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 672 | (value >> 16) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 673 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 674 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 675 | (TABLA_A_CDC_IIR1_COEF_B4_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 676 | (value >> 8) & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 677 | |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 678 | snd_soc_write(codec, |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 679 | (TABLA_A_CDC_IIR1_COEF_B5_CTL + 16 * iir_idx), |
Ben Romberger | 0915aae | 2012-02-06 23:32:43 -0800 | [diff] [blame] | 680 | value & 0xFF); |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static int tabla_put_iir_band_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 | |
| 693 | set_iir_band_coeff(codec, iir_idx, band_idx, 0, |
| 694 | ucontrol->value.integer.value[0]); |
| 695 | set_iir_band_coeff(codec, iir_idx, band_idx, 1, |
| 696 | ucontrol->value.integer.value[1]); |
| 697 | set_iir_band_coeff(codec, iir_idx, band_idx, 2, |
| 698 | ucontrol->value.integer.value[2]); |
| 699 | set_iir_band_coeff(codec, iir_idx, band_idx, 3, |
| 700 | ucontrol->value.integer.value[3]); |
| 701 | set_iir_band_coeff(codec, iir_idx, band_idx, 4, |
| 702 | ucontrol->value.integer.value[4]); |
| 703 | |
| 704 | pr_debug("%s: IIR #%d band #%d b0 = 0x%x\n" |
| 705 | "%s: IIR #%d band #%d b1 = 0x%x\n" |
| 706 | "%s: IIR #%d band #%d b2 = 0x%x\n" |
| 707 | "%s: IIR #%d band #%d a1 = 0x%x\n" |
| 708 | "%s: IIR #%d band #%d a2 = 0x%x\n", |
| 709 | __func__, iir_idx, band_idx, |
| 710 | get_iir_band_coeff(codec, iir_idx, band_idx, 0), |
| 711 | __func__, iir_idx, band_idx, |
| 712 | get_iir_band_coeff(codec, iir_idx, band_idx, 1), |
| 713 | __func__, iir_idx, band_idx, |
| 714 | get_iir_band_coeff(codec, iir_idx, band_idx, 2), |
| 715 | __func__, iir_idx, band_idx, |
| 716 | get_iir_band_coeff(codec, iir_idx, band_idx, 3), |
| 717 | __func__, iir_idx, band_idx, |
| 718 | get_iir_band_coeff(codec, iir_idx, band_idx, 4)); |
| 719 | return 0; |
| 720 | } |
| 721 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 722 | static int tabla_compander_gain_offset( |
| 723 | struct snd_soc_codec *codec, u32 enable, |
| 724 | unsigned int reg, int mask, int event) |
| 725 | { |
| 726 | int pa_mode = snd_soc_read(codec, reg) & mask; |
| 727 | int gain_offset = 0; |
| 728 | /* if PMU && enable is 1-> offset is 3 |
| 729 | * if PMU && enable is 0-> offset is 0 |
| 730 | * if PMD && pa_mode is PA -> offset is 0: PMU compander is off |
| 731 | * if PMD && pa_mode is comp -> offset is -3: PMU compander is on. |
| 732 | */ |
| 733 | |
| 734 | if (SND_SOC_DAPM_EVENT_ON(event) && (enable != 0)) |
| 735 | gain_offset = TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 736 | if (SND_SOC_DAPM_EVENT_OFF(event) && (pa_mode == 0)) |
| 737 | gain_offset = -TABLA_COMP_DIGITAL_GAIN_OFFSET; |
| 738 | return gain_offset; |
| 739 | } |
| 740 | |
| 741 | |
| 742 | static int tabla_config_gain_compander( |
| 743 | struct snd_soc_codec *codec, |
| 744 | u32 compander, u32 enable, int event) |
| 745 | { |
| 746 | int value = 0; |
| 747 | int mask = 1 << 4; |
| 748 | int gain = 0; |
| 749 | int gain_offset; |
| 750 | if (compander >= COMPANDER_MAX) { |
| 751 | pr_err("%s: Error, invalid compander channel\n", __func__); |
| 752 | return -EINVAL; |
| 753 | } |
| 754 | |
| 755 | if ((enable == 0) || SND_SOC_DAPM_EVENT_OFF(event)) |
| 756 | value = 1 << 4; |
| 757 | |
| 758 | if (compander == COMPANDER_1) { |
| 759 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 760 | TABLA_A_RX_HPH_L_GAIN, mask, event); |
| 761 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_GAIN, mask, value); |
| 762 | gain = snd_soc_read(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL); |
| 763 | snd_soc_update_bits(codec, TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 764 | 0xFF, gain - gain_offset); |
| 765 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 766 | TABLA_A_RX_HPH_R_GAIN, mask, event); |
| 767 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_GAIN, mask, value); |
| 768 | gain = snd_soc_read(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL); |
| 769 | snd_soc_update_bits(codec, TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 770 | 0xFF, gain - gain_offset); |
| 771 | } else if (compander == COMPANDER_2) { |
| 772 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 773 | TABLA_A_RX_LINE_1_GAIN, mask, event); |
| 774 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_1_GAIN, mask, value); |
| 775 | gain = snd_soc_read(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL); |
| 776 | snd_soc_update_bits(codec, TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 777 | 0xFF, gain - gain_offset); |
| 778 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 779 | TABLA_A_RX_LINE_3_GAIN, mask, event); |
| 780 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_3_GAIN, mask, value); |
| 781 | gain = snd_soc_read(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL); |
| 782 | snd_soc_update_bits(codec, TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 783 | 0xFF, gain - gain_offset); |
| 784 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 785 | TABLA_A_RX_LINE_2_GAIN, mask, event); |
| 786 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_2_GAIN, mask, value); |
| 787 | gain = snd_soc_read(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL); |
| 788 | snd_soc_update_bits(codec, TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 789 | 0xFF, gain - gain_offset); |
| 790 | gain_offset = tabla_compander_gain_offset(codec, enable, |
| 791 | TABLA_A_RX_LINE_4_GAIN, mask, event); |
| 792 | snd_soc_update_bits(codec, TABLA_A_RX_LINE_4_GAIN, mask, value); |
| 793 | gain = snd_soc_read(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL); |
| 794 | snd_soc_update_bits(codec, TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 795 | 0xFF, gain - gain_offset); |
| 796 | } |
| 797 | return 0; |
| 798 | } |
| 799 | static int tabla_get_compander(struct snd_kcontrol *kcontrol, |
| 800 | struct snd_ctl_elem_value *ucontrol) |
| 801 | { |
| 802 | |
| 803 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 804 | int comp = ((struct soc_multi_mixer_control *) |
| 805 | kcontrol->private_value)->max; |
| 806 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 807 | |
| 808 | ucontrol->value.integer.value[0] = tabla->comp_enabled[comp]; |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | static int tabla_set_compander(struct snd_kcontrol *kcontrol, |
| 814 | struct snd_ctl_elem_value *ucontrol) |
| 815 | { |
| 816 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 817 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 818 | int comp = ((struct soc_multi_mixer_control *) |
| 819 | kcontrol->private_value)->max; |
| 820 | int value = ucontrol->value.integer.value[0]; |
| 821 | |
| 822 | if (value == tabla->comp_enabled[comp]) { |
| 823 | pr_debug("%s: compander #%d enable %d no change\n", |
| 824 | __func__, comp, value); |
| 825 | return 0; |
| 826 | } |
| 827 | tabla->comp_enabled[comp] = value; |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | static int tabla_config_compander(struct snd_soc_dapm_widget *w, |
| 833 | struct snd_kcontrol *kcontrol, |
| 834 | int event) |
| 835 | { |
| 836 | struct snd_soc_codec *codec = w->codec; |
| 837 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 838 | u32 rate = tabla->comp_fs[w->shift]; |
| 839 | |
| 840 | switch (event) { |
| 841 | case SND_SOC_DAPM_PRE_PMU: |
| 842 | if (tabla->comp_enabled[w->shift] != 0) { |
| 843 | /* Enable both L/R compander clocks */ |
| 844 | snd_soc_update_bits(codec, |
| 845 | TABLA_A_CDC_CLK_RX_B2_CTL, |
| 846 | 0x03 << comp_shift[w->shift], |
| 847 | 0x03 << comp_shift[w->shift]); |
| 848 | /* Clar the HALT for the compander*/ |
| 849 | snd_soc_update_bits(codec, |
| 850 | TABLA_A_CDC_COMP1_B1_CTL + |
| 851 | w->shift * 8, 1 << 2, 0); |
| 852 | /* Toggle compander reset bits*/ |
| 853 | snd_soc_update_bits(codec, |
| 854 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 855 | 0x03 << comp_shift[w->shift], |
| 856 | 0x03 << comp_shift[w->shift]); |
| 857 | snd_soc_update_bits(codec, |
| 858 | TABLA_A_CDC_CLK_OTHR_RESET_CTL, |
| 859 | 0x03 << comp_shift[w->shift], 0); |
| 860 | tabla_config_gain_compander(codec, w->shift, 1, event); |
| 861 | /* Update the RMS meter resampling*/ |
| 862 | snd_soc_update_bits(codec, |
| 863 | TABLA_A_CDC_COMP1_B3_CTL + |
| 864 | w->shift * 8, 0xFF, 0x01); |
| 865 | /* Wait for 1ms*/ |
| 866 | usleep_range(1000, 1000); |
| 867 | } |
| 868 | break; |
| 869 | case SND_SOC_DAPM_POST_PMU: |
| 870 | /* Set sample rate dependent paramater*/ |
| 871 | if (tabla->comp_enabled[w->shift] != 0) { |
| 872 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_FS_CFG + |
| 873 | w->shift * 8, 0x03, rate); |
| 874 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 875 | w->shift * 8, 0x0F, |
| 876 | comp_samp_params[rate].peak_det_timeout); |
| 877 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B2_CTL + |
| 878 | w->shift * 8, 0xF0, |
| 879 | comp_samp_params[rate].rms_meter_div_fact); |
| 880 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B3_CTL + |
| 881 | w->shift * 8, 0xFF, |
| 882 | comp_samp_params[rate].rms_meter_resamp_fact); |
| 883 | /* Compander enable -> 0x370/0x378*/ |
| 884 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 885 | w->shift * 8, 0x03, 0x03); |
| 886 | } |
| 887 | break; |
| 888 | case SND_SOC_DAPM_PRE_PMD: |
| 889 | /* Halt the compander*/ |
| 890 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 891 | w->shift * 8, 1 << 2, 1 << 2); |
| 892 | break; |
| 893 | case SND_SOC_DAPM_POST_PMD: |
| 894 | /* Restore the gain */ |
| 895 | tabla_config_gain_compander(codec, w->shift, |
| 896 | tabla->comp_enabled[w->shift], event); |
| 897 | /* Disable the compander*/ |
| 898 | snd_soc_update_bits(codec, TABLA_A_CDC_COMP1_B1_CTL + |
| 899 | w->shift * 8, 0x03, 0x00); |
| 900 | /* Turn off the clock for compander in pair*/ |
| 901 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_B2_CTL, |
| 902 | 0x03 << comp_shift[w->shift], 0); |
| 903 | break; |
| 904 | } |
| 905 | return 0; |
| 906 | } |
| 907 | |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 908 | static const char *tabla_ear_pa_gain_text[] = {"POS_6_DB", "POS_2_DB"}; |
| 909 | static const struct soc_enum tabla_ear_pa_gain_enum[] = { |
| 910 | SOC_ENUM_SINGLE_EXT(2, tabla_ear_pa_gain_text), |
| 911 | }; |
| 912 | |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 913 | /*cut of frequency for high pass filter*/ |
| 914 | static const char *cf_text[] = { |
| 915 | "MIN_3DB_4Hz", "MIN_3DB_75Hz", "MIN_3DB_150Hz" |
| 916 | }; |
| 917 | |
| 918 | static const struct soc_enum cf_dec1_enum = |
| 919 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX1_MUX_CTL, 4, 3, cf_text); |
| 920 | |
| 921 | static const struct soc_enum cf_dec2_enum = |
| 922 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX2_MUX_CTL, 4, 3, cf_text); |
| 923 | |
| 924 | static const struct soc_enum cf_dec3_enum = |
| 925 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX3_MUX_CTL, 4, 3, cf_text); |
| 926 | |
| 927 | static const struct soc_enum cf_dec4_enum = |
| 928 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX4_MUX_CTL, 4, 3, cf_text); |
| 929 | |
| 930 | static const struct soc_enum cf_dec5_enum = |
| 931 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX5_MUX_CTL, 4, 3, cf_text); |
| 932 | |
| 933 | static const struct soc_enum cf_dec6_enum = |
| 934 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX6_MUX_CTL, 4, 3, cf_text); |
| 935 | |
| 936 | static const struct soc_enum cf_dec7_enum = |
| 937 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX7_MUX_CTL, 4, 3, cf_text); |
| 938 | |
| 939 | static const struct soc_enum cf_dec8_enum = |
| 940 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX8_MUX_CTL, 4, 3, cf_text); |
| 941 | |
| 942 | static const struct soc_enum cf_dec9_enum = |
| 943 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX9_MUX_CTL, 4, 3, cf_text); |
| 944 | |
| 945 | static const struct soc_enum cf_dec10_enum = |
| 946 | SOC_ENUM_SINGLE(TABLA_A_CDC_TX10_MUX_CTL, 4, 3, cf_text); |
| 947 | |
| 948 | static const struct soc_enum cf_rxmix1_enum = |
| 949 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX1_B4_CTL, 1, 3, cf_text); |
| 950 | |
| 951 | static const struct soc_enum cf_rxmix2_enum = |
| 952 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX2_B4_CTL, 1, 3, cf_text); |
| 953 | |
| 954 | static const struct soc_enum cf_rxmix3_enum = |
| 955 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX3_B4_CTL, 1, 3, cf_text); |
| 956 | |
| 957 | static const struct soc_enum cf_rxmix4_enum = |
| 958 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B4_CTL, 1, 3, cf_text); |
| 959 | |
| 960 | static const struct soc_enum cf_rxmix5_enum = |
| 961 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX5_B4_CTL, 1, 3, cf_text) |
| 962 | ; |
| 963 | static const struct soc_enum cf_rxmix6_enum = |
| 964 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B4_CTL, 1, 3, cf_text); |
| 965 | |
| 966 | static const struct soc_enum cf_rxmix7_enum = |
| 967 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX7_B4_CTL, 1, 3, cf_text); |
| 968 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 969 | static const struct snd_kcontrol_new tabla_snd_controls[] = { |
Kiran Kandi | d2d86b5 | 2011-09-09 17:44:28 -0700 | [diff] [blame] | 970 | |
| 971 | SOC_ENUM_EXT("EAR PA Gain", tabla_ear_pa_gain_enum[0], |
| 972 | tabla_pa_gain_get, tabla_pa_gain_put), |
| 973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 974 | SOC_SINGLE_TLV("LINEOUT1 Volume", TABLA_A_RX_LINE_1_GAIN, 0, 12, 1, |
| 975 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 976 | SOC_SINGLE_TLV("LINEOUT2 Volume", TABLA_A_RX_LINE_2_GAIN, 0, 12, 1, |
| 977 | line_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 978 | SOC_SINGLE_TLV("LINEOUT3 Volume", TABLA_A_RX_LINE_3_GAIN, 0, 12, 1, |
| 979 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 980 | SOC_SINGLE_TLV("LINEOUT4 Volume", TABLA_A_RX_LINE_4_GAIN, 0, 12, 1, |
| 981 | line_gain), |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 982 | SOC_SINGLE_TLV("LINEOUT5 Volume", TABLA_A_RX_LINE_5_GAIN, 0, 12, 1, |
| 983 | line_gain), |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 984 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 985 | SOC_SINGLE_TLV("HPHL Volume", TABLA_A_RX_HPH_L_GAIN, 0, 12, 1, |
| 986 | line_gain), |
| 987 | SOC_SINGLE_TLV("HPHR Volume", TABLA_A_RX_HPH_R_GAIN, 0, 12, 1, |
| 988 | line_gain), |
| 989 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 990 | SOC_SINGLE_S8_TLV("RX1 Digital Volume", TABLA_A_CDC_RX1_VOL_CTL_B2_CTL, |
| 991 | -84, 40, digital_gain), |
| 992 | SOC_SINGLE_S8_TLV("RX2 Digital Volume", TABLA_A_CDC_RX2_VOL_CTL_B2_CTL, |
| 993 | -84, 40, digital_gain), |
| 994 | SOC_SINGLE_S8_TLV("RX3 Digital Volume", TABLA_A_CDC_RX3_VOL_CTL_B2_CTL, |
| 995 | -84, 40, digital_gain), |
| 996 | SOC_SINGLE_S8_TLV("RX4 Digital Volume", TABLA_A_CDC_RX4_VOL_CTL_B2_CTL, |
| 997 | -84, 40, digital_gain), |
| 998 | SOC_SINGLE_S8_TLV("RX5 Digital Volume", TABLA_A_CDC_RX5_VOL_CTL_B2_CTL, |
| 999 | -84, 40, digital_gain), |
| 1000 | SOC_SINGLE_S8_TLV("RX6 Digital Volume", TABLA_A_CDC_RX6_VOL_CTL_B2_CTL, |
| 1001 | -84, 40, digital_gain), |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 1002 | SOC_SINGLE_S8_TLV("RX7 Digital Volume", TABLA_A_CDC_RX7_VOL_CTL_B2_CTL, |
| 1003 | -84, 40, digital_gain), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1004 | |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1005 | 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] | 1006 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1007 | 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] | 1008 | digital_gain), |
Bradley Rubin | 410383f | 2011-07-22 13:44:23 -0700 | [diff] [blame] | 1009 | SOC_SINGLE_S8_TLV("DEC3 Volume", TABLA_A_CDC_TX3_VOL_CTL_GAIN, -84, 40, |
| 1010 | digital_gain), |
| 1011 | SOC_SINGLE_S8_TLV("DEC4 Volume", TABLA_A_CDC_TX4_VOL_CTL_GAIN, -84, 40, |
| 1012 | digital_gain), |
| 1013 | SOC_SINGLE_S8_TLV("DEC5 Volume", TABLA_A_CDC_TX5_VOL_CTL_GAIN, -84, 40, |
| 1014 | digital_gain), |
| 1015 | SOC_SINGLE_S8_TLV("DEC6 Volume", TABLA_A_CDC_TX6_VOL_CTL_GAIN, -84, 40, |
| 1016 | digital_gain), |
| 1017 | SOC_SINGLE_S8_TLV("DEC7 Volume", TABLA_A_CDC_TX7_VOL_CTL_GAIN, -84, 40, |
| 1018 | digital_gain), |
| 1019 | SOC_SINGLE_S8_TLV("DEC8 Volume", TABLA_A_CDC_TX8_VOL_CTL_GAIN, -84, 40, |
| 1020 | digital_gain), |
| 1021 | SOC_SINGLE_S8_TLV("DEC9 Volume", TABLA_A_CDC_TX9_VOL_CTL_GAIN, -84, 40, |
| 1022 | digital_gain), |
| 1023 | SOC_SINGLE_S8_TLV("DEC10 Volume", TABLA_A_CDC_TX10_VOL_CTL_GAIN, -84, |
| 1024 | 40, digital_gain), |
Patrick Lai | 2900637 | 2011-09-28 17:57:42 -0700 | [diff] [blame] | 1025 | SOC_SINGLE_S8_TLV("IIR1 INP1 Volume", TABLA_A_CDC_IIR1_GAIN_B1_CTL, -84, |
| 1026 | 40, digital_gain), |
| 1027 | SOC_SINGLE_S8_TLV("IIR1 INP2 Volume", TABLA_A_CDC_IIR1_GAIN_B2_CTL, -84, |
| 1028 | 40, digital_gain), |
| 1029 | SOC_SINGLE_S8_TLV("IIR1 INP3 Volume", TABLA_A_CDC_IIR1_GAIN_B3_CTL, -84, |
| 1030 | 40, digital_gain), |
| 1031 | SOC_SINGLE_S8_TLV("IIR1 INP4 Volume", TABLA_A_CDC_IIR1_GAIN_B4_CTL, -84, |
| 1032 | 40, digital_gain), |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1033 | SOC_SINGLE_TLV("ADC1 Volume", TABLA_A_TX_1_2_EN, 5, 3, 0, analog_gain), |
| 1034 | 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] | 1035 | SOC_SINGLE_TLV("ADC3 Volume", TABLA_A_TX_3_4_EN, 5, 3, 0, analog_gain), |
| 1036 | 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] | 1037 | SOC_SINGLE_TLV("ADC5 Volume", TABLA_A_TX_5_6_EN, 5, 3, 0, analog_gain), |
| 1038 | 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] | 1039 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1040 | SOC_SINGLE_TLV("AUX_PGA_LEFT Volume", TABLA_A_AUX_L_GAIN, 0, 39, 0, |
| 1041 | aux_pga_gain), |
| 1042 | SOC_SINGLE_TLV("AUX_PGA_RIGHT Volume", TABLA_A_AUX_R_GAIN, 0, 39, 0, |
| 1043 | aux_pga_gain), |
| 1044 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1045 | 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] | 1046 | 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] | 1047 | 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] | 1048 | |
| 1049 | SOC_SINGLE_EXT("ANC Slot", SND_SOC_NOPM, 0, 0, 100, tabla_get_anc_slot, |
| 1050 | tabla_put_anc_slot), |
Santosh Mardi | 024010f | 2011-10-18 06:27:21 +0530 | [diff] [blame] | 1051 | SOC_ENUM("TX1 HPF cut off", cf_dec1_enum), |
| 1052 | SOC_ENUM("TX2 HPF cut off", cf_dec2_enum), |
| 1053 | SOC_ENUM("TX3 HPF cut off", cf_dec3_enum), |
| 1054 | SOC_ENUM("TX4 HPF cut off", cf_dec4_enum), |
| 1055 | SOC_ENUM("TX5 HPF cut off", cf_dec5_enum), |
| 1056 | SOC_ENUM("TX6 HPF cut off", cf_dec6_enum), |
| 1057 | SOC_ENUM("TX7 HPF cut off", cf_dec7_enum), |
| 1058 | SOC_ENUM("TX8 HPF cut off", cf_dec8_enum), |
| 1059 | SOC_ENUM("TX9 HPF cut off", cf_dec9_enum), |
| 1060 | SOC_ENUM("TX10 HPF cut off", cf_dec10_enum), |
| 1061 | |
| 1062 | SOC_SINGLE("TX1 HPF Switch", TABLA_A_CDC_TX1_MUX_CTL, 3, 1, 0), |
| 1063 | SOC_SINGLE("TX2 HPF Switch", TABLA_A_CDC_TX2_MUX_CTL, 3, 1, 0), |
| 1064 | SOC_SINGLE("TX3 HPF Switch", TABLA_A_CDC_TX3_MUX_CTL, 3, 1, 0), |
| 1065 | SOC_SINGLE("TX4 HPF Switch", TABLA_A_CDC_TX4_MUX_CTL, 3, 1, 0), |
| 1066 | SOC_SINGLE("TX5 HPF Switch", TABLA_A_CDC_TX5_MUX_CTL, 3, 1, 0), |
| 1067 | SOC_SINGLE("TX6 HPF Switch", TABLA_A_CDC_TX6_MUX_CTL, 3, 1, 0), |
| 1068 | SOC_SINGLE("TX7 HPF Switch", TABLA_A_CDC_TX7_MUX_CTL, 3, 1, 0), |
| 1069 | SOC_SINGLE("TX8 HPF Switch", TABLA_A_CDC_TX8_MUX_CTL, 3, 1, 0), |
| 1070 | SOC_SINGLE("TX9 HPF Switch", TABLA_A_CDC_TX9_MUX_CTL, 3, 1, 0), |
| 1071 | SOC_SINGLE("TX10 HPF Switch", TABLA_A_CDC_TX10_MUX_CTL, 3, 1, 0), |
| 1072 | |
| 1073 | SOC_SINGLE("RX1 HPF Switch", TABLA_A_CDC_RX1_B5_CTL, 2, 1, 0), |
| 1074 | SOC_SINGLE("RX2 HPF Switch", TABLA_A_CDC_RX2_B5_CTL, 2, 1, 0), |
| 1075 | SOC_SINGLE("RX3 HPF Switch", TABLA_A_CDC_RX3_B5_CTL, 2, 1, 0), |
| 1076 | SOC_SINGLE("RX4 HPF Switch", TABLA_A_CDC_RX4_B5_CTL, 2, 1, 0), |
| 1077 | SOC_SINGLE("RX5 HPF Switch", TABLA_A_CDC_RX5_B5_CTL, 2, 1, 0), |
| 1078 | SOC_SINGLE("RX6 HPF Switch", TABLA_A_CDC_RX6_B5_CTL, 2, 1, 0), |
| 1079 | SOC_SINGLE("RX7 HPF Switch", TABLA_A_CDC_RX7_B5_CTL, 2, 1, 0), |
| 1080 | |
| 1081 | SOC_ENUM("RX1 HPF cut off", cf_rxmix1_enum), |
| 1082 | SOC_ENUM("RX2 HPF cut off", cf_rxmix2_enum), |
| 1083 | SOC_ENUM("RX3 HPF cut off", cf_rxmix3_enum), |
| 1084 | SOC_ENUM("RX4 HPF cut off", cf_rxmix4_enum), |
| 1085 | SOC_ENUM("RX5 HPF cut off", cf_rxmix5_enum), |
| 1086 | SOC_ENUM("RX6 HPF cut off", cf_rxmix6_enum), |
| 1087 | SOC_ENUM("RX7 HPF cut off", cf_rxmix7_enum), |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 1088 | |
| 1089 | SOC_SINGLE_EXT("IIR1 Enable Band1", IIR1, BAND1, 1, 0, |
| 1090 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1091 | SOC_SINGLE_EXT("IIR1 Enable Band2", IIR1, BAND2, 1, 0, |
| 1092 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1093 | SOC_SINGLE_EXT("IIR1 Enable Band3", IIR1, BAND3, 1, 0, |
| 1094 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1095 | SOC_SINGLE_EXT("IIR1 Enable Band4", IIR1, BAND4, 1, 0, |
| 1096 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1097 | SOC_SINGLE_EXT("IIR1 Enable Band5", IIR1, BAND5, 1, 0, |
| 1098 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1099 | SOC_SINGLE_EXT("IIR2 Enable Band1", IIR2, BAND1, 1, 0, |
| 1100 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1101 | SOC_SINGLE_EXT("IIR2 Enable Band2", IIR2, BAND2, 1, 0, |
| 1102 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1103 | SOC_SINGLE_EXT("IIR2 Enable Band3", IIR2, BAND3, 1, 0, |
| 1104 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1105 | SOC_SINGLE_EXT("IIR2 Enable Band4", IIR2, BAND4, 1, 0, |
| 1106 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1107 | SOC_SINGLE_EXT("IIR2 Enable Band5", IIR2, BAND5, 1, 0, |
| 1108 | tabla_get_iir_enable_audio_mixer, tabla_put_iir_enable_audio_mixer), |
| 1109 | |
| 1110 | SOC_SINGLE_MULTI_EXT("IIR1 Band1", IIR1, BAND1, 255, 0, 5, |
| 1111 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1112 | SOC_SINGLE_MULTI_EXT("IIR1 Band2", IIR1, BAND2, 255, 0, 5, |
| 1113 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1114 | SOC_SINGLE_MULTI_EXT("IIR1 Band3", IIR1, BAND3, 255, 0, 5, |
| 1115 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1116 | SOC_SINGLE_MULTI_EXT("IIR1 Band4", IIR1, BAND4, 255, 0, 5, |
| 1117 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1118 | SOC_SINGLE_MULTI_EXT("IIR1 Band5", IIR1, BAND5, 255, 0, 5, |
| 1119 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1120 | SOC_SINGLE_MULTI_EXT("IIR2 Band1", IIR2, BAND1, 255, 0, 5, |
| 1121 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1122 | SOC_SINGLE_MULTI_EXT("IIR2 Band2", IIR2, BAND2, 255, 0, 5, |
| 1123 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1124 | SOC_SINGLE_MULTI_EXT("IIR2 Band3", IIR2, BAND3, 255, 0, 5, |
| 1125 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1126 | SOC_SINGLE_MULTI_EXT("IIR2 Band4", IIR2, BAND4, 255, 0, 5, |
| 1127 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
| 1128 | SOC_SINGLE_MULTI_EXT("IIR2 Band5", IIR2, BAND5, 255, 0, 5, |
| 1129 | tabla_get_iir_band_audio_mixer, tabla_put_iir_band_audio_mixer), |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 1130 | SOC_SINGLE_EXT("COMP1 Switch", SND_SOC_NOPM, 1, COMPANDER_1, 0, |
| 1131 | tabla_get_compander, tabla_set_compander), |
| 1132 | SOC_SINGLE_EXT("COMP2 Switch", SND_SOC_NOPM, 0, COMPANDER_2, 0, |
| 1133 | tabla_get_compander, tabla_set_compander), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1134 | }; |
| 1135 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 1136 | static const struct snd_kcontrol_new tabla_1_x_snd_controls[] = { |
| 1137 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_1_A_MICB_4_CTL, 4, 1, 1), |
| 1138 | }; |
| 1139 | |
| 1140 | static const struct snd_kcontrol_new tabla_2_higher_snd_controls[] = { |
| 1141 | SOC_SINGLE("MICBIAS4 CAPLESS Switch", TABLA_2_A_MICB_4_CTL, 4, 1, 1), |
| 1142 | }; |
| 1143 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1144 | static const char *rx_mix1_text[] = { |
| 1145 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2", "RX1", "RX2", "RX3", "RX4", |
| 1146 | "RX5", "RX6", "RX7" |
| 1147 | }; |
| 1148 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1149 | static const char *rx_mix2_text[] = { |
| 1150 | "ZERO", "SRC1", "SRC2", "IIR1", "IIR2" |
| 1151 | }; |
| 1152 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1153 | static const char *rx_dsm_text[] = { |
| 1154 | "CIC_OUT", "DSM_INV" |
| 1155 | }; |
| 1156 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1157 | static const char *sb_tx1_mux_text[] = { |
| 1158 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1159 | "DEC1" |
| 1160 | }; |
| 1161 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1162 | static const char *sb_tx2_mux_text[] = { |
| 1163 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1164 | "DEC2" |
| 1165 | }; |
| 1166 | |
| 1167 | static const char *sb_tx3_mux_text[] = { |
| 1168 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1169 | "DEC3" |
| 1170 | }; |
| 1171 | |
| 1172 | static const char *sb_tx4_mux_text[] = { |
| 1173 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1174 | "DEC4" |
| 1175 | }; |
| 1176 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1177 | static const char *sb_tx5_mux_text[] = { |
| 1178 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1179 | "DEC5" |
| 1180 | }; |
| 1181 | |
| 1182 | static const char *sb_tx6_mux_text[] = { |
| 1183 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1184 | "DEC6" |
| 1185 | }; |
| 1186 | |
| 1187 | static const char const *sb_tx7_to_tx10_mux_text[] = { |
| 1188 | "ZERO", "RMIX1", "RMIX2", "RMIX3", "RMIX4", "RMIX5", "RMIX6", "RMIX7", |
| 1189 | "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1190 | "DEC9", "DEC10" |
| 1191 | }; |
| 1192 | |
| 1193 | static const char *dec1_mux_text[] = { |
| 1194 | "ZERO", "DMIC1", "ADC6", |
| 1195 | }; |
| 1196 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1197 | static const char *dec2_mux_text[] = { |
| 1198 | "ZERO", "DMIC2", "ADC5", |
| 1199 | }; |
| 1200 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1201 | static const char *dec3_mux_text[] = { |
| 1202 | "ZERO", "DMIC3", "ADC4", |
| 1203 | }; |
| 1204 | |
| 1205 | static const char *dec4_mux_text[] = { |
| 1206 | "ZERO", "DMIC4", "ADC3", |
| 1207 | }; |
| 1208 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1209 | static const char *dec5_mux_text[] = { |
| 1210 | "ZERO", "DMIC5", "ADC2", |
| 1211 | }; |
| 1212 | |
| 1213 | static const char *dec6_mux_text[] = { |
| 1214 | "ZERO", "DMIC6", "ADC1", |
| 1215 | }; |
| 1216 | |
| 1217 | static const char const *dec7_mux_text[] = { |
| 1218 | "ZERO", "DMIC1", "DMIC6", "ADC1", "ADC6", "ANC1_FB", "ANC2_FB", |
| 1219 | }; |
| 1220 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1221 | static const char *dec8_mux_text[] = { |
| 1222 | "ZERO", "DMIC2", "DMIC5", "ADC2", "ADC5", |
| 1223 | }; |
| 1224 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1225 | static const char *dec9_mux_text[] = { |
| 1226 | "ZERO", "DMIC4", "DMIC5", "ADC2", "ADC3", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1227 | }; |
| 1228 | |
| 1229 | static const char *dec10_mux_text[] = { |
| 1230 | "ZERO", "DMIC3", "DMIC6", "ADC1", "ADC4", "ADCMB", "ANC1_FB", "ANC2_FB", |
| 1231 | }; |
| 1232 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1233 | static const char const *anc_mux_text[] = { |
| 1234 | "ZERO", "ADC1", "ADC2", "ADC3", "ADC4", "ADC5", "ADC6", "ADC_MB", |
| 1235 | "RSVD_1", "DMIC1", "DMIC2", "DMIC3", "DMIC4", "DMIC5", "DMIC6" |
| 1236 | }; |
| 1237 | |
| 1238 | static const char const *anc1_fb_mux_text[] = { |
| 1239 | "ZERO", "EAR_HPH_L", "EAR_LINE_1", |
| 1240 | }; |
| 1241 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1242 | static const char *iir1_inp1_text[] = { |
| 1243 | "ZERO", "DEC1", "DEC2", "DEC3", "DEC4", "DEC5", "DEC6", "DEC7", "DEC8", |
| 1244 | "DEC9", "DEC10", "RX1", "RX2", "RX3", "RX4", "RX5", "RX6", "RX7" |
| 1245 | }; |
| 1246 | |
| 1247 | static const struct soc_enum rx_mix1_inp1_chain_enum = |
| 1248 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 0, 12, rx_mix1_text); |
| 1249 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1250 | static const struct soc_enum rx_mix1_inp2_chain_enum = |
| 1251 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B1_CTL, 4, 12, rx_mix1_text); |
| 1252 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1253 | static const struct soc_enum rx_mix1_inp3_chain_enum = |
| 1254 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B2_CTL, 0, 12, rx_mix1_text); |
| 1255 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1256 | static const struct soc_enum rx2_mix1_inp1_chain_enum = |
| 1257 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 0, 12, rx_mix1_text); |
| 1258 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1259 | static const struct soc_enum rx2_mix1_inp2_chain_enum = |
| 1260 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B1_CTL, 4, 12, rx_mix1_text); |
| 1261 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1262 | static const struct soc_enum rx3_mix1_inp1_chain_enum = |
| 1263 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 0, 12, rx_mix1_text); |
| 1264 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1265 | static const struct soc_enum rx3_mix1_inp2_chain_enum = |
| 1266 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B1_CTL, 4, 12, rx_mix1_text); |
| 1267 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1268 | static const struct soc_enum rx4_mix1_inp1_chain_enum = |
| 1269 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 0, 12, rx_mix1_text); |
| 1270 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1271 | static const struct soc_enum rx4_mix1_inp2_chain_enum = |
| 1272 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX4_B1_CTL, 4, 12, rx_mix1_text); |
| 1273 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1274 | static const struct soc_enum rx5_mix1_inp1_chain_enum = |
| 1275 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 0, 12, rx_mix1_text); |
| 1276 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1277 | static const struct soc_enum rx5_mix1_inp2_chain_enum = |
| 1278 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX5_B1_CTL, 4, 12, rx_mix1_text); |
| 1279 | |
| 1280 | static const struct soc_enum rx6_mix1_inp1_chain_enum = |
| 1281 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 0, 12, rx_mix1_text); |
| 1282 | |
| 1283 | static const struct soc_enum rx6_mix1_inp2_chain_enum = |
| 1284 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX6_B1_CTL, 4, 12, rx_mix1_text); |
| 1285 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1286 | static const struct soc_enum rx7_mix1_inp1_chain_enum = |
| 1287 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 0, 12, rx_mix1_text); |
| 1288 | |
| 1289 | static const struct soc_enum rx7_mix1_inp2_chain_enum = |
| 1290 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX7_B1_CTL, 4, 12, rx_mix1_text); |
| 1291 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1292 | static const struct soc_enum rx1_mix2_inp1_chain_enum = |
| 1293 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 0, 5, rx_mix2_text); |
| 1294 | |
| 1295 | static const struct soc_enum rx1_mix2_inp2_chain_enum = |
| 1296 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX1_B3_CTL, 3, 5, rx_mix2_text); |
| 1297 | |
| 1298 | static const struct soc_enum rx2_mix2_inp1_chain_enum = |
| 1299 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 0, 5, rx_mix2_text); |
| 1300 | |
| 1301 | static const struct soc_enum rx2_mix2_inp2_chain_enum = |
| 1302 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX2_B3_CTL, 3, 5, rx_mix2_text); |
| 1303 | |
| 1304 | static const struct soc_enum rx3_mix2_inp1_chain_enum = |
| 1305 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 0, 5, rx_mix2_text); |
| 1306 | |
| 1307 | static const struct soc_enum rx3_mix2_inp2_chain_enum = |
| 1308 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_RX3_B3_CTL, 3, 5, rx_mix2_text); |
| 1309 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1310 | static const struct soc_enum rx4_dsm_enum = |
| 1311 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX4_B6_CTL, 4, 2, rx_dsm_text); |
| 1312 | |
| 1313 | static const struct soc_enum rx6_dsm_enum = |
| 1314 | SOC_ENUM_SINGLE(TABLA_A_CDC_RX6_B6_CTL, 4, 2, rx_dsm_text); |
| 1315 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1316 | static const struct soc_enum sb_tx1_mux_enum = |
| 1317 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0, 9, sb_tx1_mux_text); |
| 1318 | |
| 1319 | static const struct soc_enum sb_tx2_mux_enum = |
| 1320 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0, 9, sb_tx2_mux_text); |
| 1321 | |
| 1322 | static const struct soc_enum sb_tx3_mux_enum = |
| 1323 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0, 9, sb_tx3_mux_text); |
| 1324 | |
| 1325 | static const struct soc_enum sb_tx4_mux_enum = |
| 1326 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0, 9, sb_tx4_mux_text); |
| 1327 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1328 | static const struct soc_enum sb_tx5_mux_enum = |
| 1329 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0, 9, sb_tx5_mux_text); |
| 1330 | |
| 1331 | static const struct soc_enum sb_tx6_mux_enum = |
| 1332 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0, 9, sb_tx6_mux_text); |
| 1333 | |
| 1334 | static const struct soc_enum sb_tx7_mux_enum = |
| 1335 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0, 18, |
| 1336 | sb_tx7_to_tx10_mux_text); |
| 1337 | |
| 1338 | static const struct soc_enum sb_tx8_mux_enum = |
| 1339 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0, 18, |
| 1340 | sb_tx7_to_tx10_mux_text); |
| 1341 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1342 | static const struct soc_enum sb_tx9_mux_enum = |
| 1343 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0, 18, |
| 1344 | sb_tx7_to_tx10_mux_text); |
| 1345 | |
| 1346 | static const struct soc_enum sb_tx10_mux_enum = |
| 1347 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0, 18, |
| 1348 | sb_tx7_to_tx10_mux_text); |
| 1349 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1350 | static const struct soc_enum dec1_mux_enum = |
| 1351 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 0, 3, dec1_mux_text); |
| 1352 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1353 | static const struct soc_enum dec2_mux_enum = |
| 1354 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 2, 3, dec2_mux_text); |
| 1355 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1356 | static const struct soc_enum dec3_mux_enum = |
| 1357 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 4, 3, dec3_mux_text); |
| 1358 | |
| 1359 | static const struct soc_enum dec4_mux_enum = |
| 1360 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B1_CTL, 6, 3, dec4_mux_text); |
| 1361 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1362 | static const struct soc_enum dec5_mux_enum = |
| 1363 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 0, 3, dec5_mux_text); |
| 1364 | |
| 1365 | static const struct soc_enum dec6_mux_enum = |
| 1366 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 2, 3, dec6_mux_text); |
| 1367 | |
| 1368 | static const struct soc_enum dec7_mux_enum = |
| 1369 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B2_CTL, 4, 7, dec7_mux_text); |
| 1370 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1371 | static const struct soc_enum dec8_mux_enum = |
| 1372 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 0, 7, dec8_mux_text); |
| 1373 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1374 | static const struct soc_enum dec9_mux_enum = |
| 1375 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B3_CTL, 3, 8, dec9_mux_text); |
| 1376 | |
| 1377 | static const struct soc_enum dec10_mux_enum = |
| 1378 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_TX_B4_CTL, 0, 8, dec10_mux_text); |
| 1379 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1380 | static const struct soc_enum anc1_mux_enum = |
| 1381 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 0, 16, anc_mux_text); |
| 1382 | |
| 1383 | static const struct soc_enum anc2_mux_enum = |
| 1384 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B1_CTL, 4, 16, anc_mux_text); |
| 1385 | |
| 1386 | static const struct soc_enum anc1_fb_mux_enum = |
| 1387 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_ANC_B2_CTL, 0, 3, anc1_fb_mux_text); |
| 1388 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1389 | static const struct soc_enum iir1_inp1_mux_enum = |
| 1390 | SOC_ENUM_SINGLE(TABLA_A_CDC_CONN_EQ1_B1_CTL, 0, 18, iir1_inp1_text); |
| 1391 | |
| 1392 | static const struct snd_kcontrol_new rx_mix1_inp1_mux = |
| 1393 | SOC_DAPM_ENUM("RX1 MIX1 INP1 Mux", rx_mix1_inp1_chain_enum); |
| 1394 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1395 | static const struct snd_kcontrol_new rx_mix1_inp2_mux = |
| 1396 | SOC_DAPM_ENUM("RX1 MIX1 INP2 Mux", rx_mix1_inp2_chain_enum); |
| 1397 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 1398 | static const struct snd_kcontrol_new rx_mix1_inp3_mux = |
| 1399 | SOC_DAPM_ENUM("RX1 MIX1 INP3 Mux", rx_mix1_inp3_chain_enum); |
| 1400 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1401 | static const struct snd_kcontrol_new rx2_mix1_inp1_mux = |
| 1402 | SOC_DAPM_ENUM("RX2 MIX1 INP1 Mux", rx2_mix1_inp1_chain_enum); |
| 1403 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1404 | static const struct snd_kcontrol_new rx2_mix1_inp2_mux = |
| 1405 | SOC_DAPM_ENUM("RX2 MIX1 INP2 Mux", rx2_mix1_inp2_chain_enum); |
| 1406 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1407 | static const struct snd_kcontrol_new rx3_mix1_inp1_mux = |
| 1408 | SOC_DAPM_ENUM("RX3 MIX1 INP1 Mux", rx3_mix1_inp1_chain_enum); |
| 1409 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1410 | static const struct snd_kcontrol_new rx3_mix1_inp2_mux = |
| 1411 | SOC_DAPM_ENUM("RX3 MIX1 INP2 Mux", rx3_mix1_inp2_chain_enum); |
| 1412 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1413 | static const struct snd_kcontrol_new rx4_mix1_inp1_mux = |
| 1414 | SOC_DAPM_ENUM("RX4 MIX1 INP1 Mux", rx4_mix1_inp1_chain_enum); |
| 1415 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1416 | static const struct snd_kcontrol_new rx4_mix1_inp2_mux = |
| 1417 | SOC_DAPM_ENUM("RX4 MIX1 INP2 Mux", rx4_mix1_inp2_chain_enum); |
| 1418 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1419 | static const struct snd_kcontrol_new rx5_mix1_inp1_mux = |
| 1420 | SOC_DAPM_ENUM("RX5 MIX1 INP1 Mux", rx5_mix1_inp1_chain_enum); |
| 1421 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 1422 | static const struct snd_kcontrol_new rx5_mix1_inp2_mux = |
| 1423 | SOC_DAPM_ENUM("RX5 MIX1 INP2 Mux", rx5_mix1_inp2_chain_enum); |
| 1424 | |
| 1425 | static const struct snd_kcontrol_new rx6_mix1_inp1_mux = |
| 1426 | SOC_DAPM_ENUM("RX6 MIX1 INP1 Mux", rx6_mix1_inp1_chain_enum); |
| 1427 | |
| 1428 | static const struct snd_kcontrol_new rx6_mix1_inp2_mux = |
| 1429 | SOC_DAPM_ENUM("RX6 MIX1 INP2 Mux", rx6_mix1_inp2_chain_enum); |
| 1430 | |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 1431 | static const struct snd_kcontrol_new rx7_mix1_inp1_mux = |
| 1432 | SOC_DAPM_ENUM("RX7 MIX1 INP1 Mux", rx7_mix1_inp1_chain_enum); |
| 1433 | |
| 1434 | static const struct snd_kcontrol_new rx7_mix1_inp2_mux = |
| 1435 | SOC_DAPM_ENUM("RX7 MIX1 INP2 Mux", rx7_mix1_inp2_chain_enum); |
| 1436 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 1437 | static const struct snd_kcontrol_new rx1_mix2_inp1_mux = |
| 1438 | SOC_DAPM_ENUM("RX1 MIX2 INP1 Mux", rx1_mix2_inp1_chain_enum); |
| 1439 | |
| 1440 | static const struct snd_kcontrol_new rx1_mix2_inp2_mux = |
| 1441 | SOC_DAPM_ENUM("RX1 MIX2 INP2 Mux", rx1_mix2_inp2_chain_enum); |
| 1442 | |
| 1443 | static const struct snd_kcontrol_new rx2_mix2_inp1_mux = |
| 1444 | SOC_DAPM_ENUM("RX2 MIX2 INP1 Mux", rx2_mix2_inp1_chain_enum); |
| 1445 | |
| 1446 | static const struct snd_kcontrol_new rx2_mix2_inp2_mux = |
| 1447 | SOC_DAPM_ENUM("RX2 MIX2 INP2 Mux", rx2_mix2_inp2_chain_enum); |
| 1448 | |
| 1449 | static const struct snd_kcontrol_new rx3_mix2_inp1_mux = |
| 1450 | SOC_DAPM_ENUM("RX3 MIX2 INP1 Mux", rx3_mix2_inp1_chain_enum); |
| 1451 | |
| 1452 | static const struct snd_kcontrol_new rx3_mix2_inp2_mux = |
| 1453 | SOC_DAPM_ENUM("RX3 MIX2 INP2 Mux", rx3_mix2_inp2_chain_enum); |
| 1454 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1455 | static const struct snd_kcontrol_new rx4_dsm_mux = |
| 1456 | SOC_DAPM_ENUM("RX4 DSM MUX Mux", rx4_dsm_enum); |
| 1457 | |
| 1458 | static const struct snd_kcontrol_new rx6_dsm_mux = |
| 1459 | SOC_DAPM_ENUM("RX6 DSM MUX Mux", rx6_dsm_enum); |
| 1460 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 1461 | static const struct snd_kcontrol_new sb_tx1_mux = |
| 1462 | SOC_DAPM_ENUM("SLIM TX1 MUX Mux", sb_tx1_mux_enum); |
| 1463 | |
| 1464 | static const struct snd_kcontrol_new sb_tx2_mux = |
| 1465 | SOC_DAPM_ENUM("SLIM TX2 MUX Mux", sb_tx2_mux_enum); |
| 1466 | |
| 1467 | static const struct snd_kcontrol_new sb_tx3_mux = |
| 1468 | SOC_DAPM_ENUM("SLIM TX3 MUX Mux", sb_tx3_mux_enum); |
| 1469 | |
| 1470 | static const struct snd_kcontrol_new sb_tx4_mux = |
| 1471 | SOC_DAPM_ENUM("SLIM TX4 MUX Mux", sb_tx4_mux_enum); |
| 1472 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1473 | static const struct snd_kcontrol_new sb_tx5_mux = |
| 1474 | SOC_DAPM_ENUM("SLIM TX5 MUX Mux", sb_tx5_mux_enum); |
| 1475 | |
| 1476 | static const struct snd_kcontrol_new sb_tx6_mux = |
| 1477 | SOC_DAPM_ENUM("SLIM TX6 MUX Mux", sb_tx6_mux_enum); |
| 1478 | |
| 1479 | static const struct snd_kcontrol_new sb_tx7_mux = |
| 1480 | SOC_DAPM_ENUM("SLIM TX7 MUX Mux", sb_tx7_mux_enum); |
| 1481 | |
| 1482 | static const struct snd_kcontrol_new sb_tx8_mux = |
| 1483 | SOC_DAPM_ENUM("SLIM TX8 MUX Mux", sb_tx8_mux_enum); |
| 1484 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 1485 | static const struct snd_kcontrol_new sb_tx9_mux = |
| 1486 | SOC_DAPM_ENUM("SLIM TX9 MUX Mux", sb_tx9_mux_enum); |
| 1487 | |
| 1488 | static const struct snd_kcontrol_new sb_tx10_mux = |
| 1489 | SOC_DAPM_ENUM("SLIM TX10 MUX Mux", sb_tx10_mux_enum); |
| 1490 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1491 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1492 | static int wcd9310_put_dec_enum(struct snd_kcontrol *kcontrol, |
| 1493 | struct snd_ctl_elem_value *ucontrol) |
| 1494 | { |
| 1495 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1496 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
| 1497 | struct snd_soc_codec *codec = w->codec; |
| 1498 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1499 | unsigned int dec_mux, decimator; |
| 1500 | char *dec_name = NULL; |
| 1501 | char *widget_name = NULL; |
| 1502 | char *temp; |
| 1503 | u16 tx_mux_ctl_reg; |
| 1504 | u8 adc_dmic_sel = 0x0; |
| 1505 | int ret = 0; |
| 1506 | |
| 1507 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1508 | return -EINVAL; |
| 1509 | |
| 1510 | dec_mux = ucontrol->value.enumerated.item[0]; |
| 1511 | |
| 1512 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 1513 | if (!widget_name) |
| 1514 | return -ENOMEM; |
| 1515 | temp = widget_name; |
| 1516 | |
| 1517 | dec_name = strsep(&widget_name, " "); |
| 1518 | widget_name = temp; |
| 1519 | if (!dec_name) { |
| 1520 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 1521 | ret = -EINVAL; |
| 1522 | goto out; |
| 1523 | } |
| 1524 | |
| 1525 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 1526 | if (ret < 0) { |
| 1527 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 1528 | ret = -EINVAL; |
| 1529 | goto out; |
| 1530 | } |
| 1531 | |
| 1532 | dev_dbg(w->dapm->dev, "%s(): widget = %s dec_name = %s decimator = %u" |
| 1533 | " dec_mux = %u\n", __func__, w->name, dec_name, decimator, |
| 1534 | dec_mux); |
| 1535 | |
| 1536 | |
| 1537 | switch (decimator) { |
| 1538 | case 1: |
| 1539 | case 2: |
| 1540 | case 3: |
| 1541 | case 4: |
| 1542 | case 5: |
| 1543 | case 6: |
| 1544 | if (dec_mux == 1) |
| 1545 | adc_dmic_sel = 0x1; |
| 1546 | else |
| 1547 | adc_dmic_sel = 0x0; |
| 1548 | break; |
| 1549 | case 7: |
| 1550 | case 8: |
| 1551 | case 9: |
| 1552 | case 10: |
| 1553 | if ((dec_mux == 1) || (dec_mux == 2)) |
| 1554 | adc_dmic_sel = 0x1; |
| 1555 | else |
| 1556 | adc_dmic_sel = 0x0; |
| 1557 | break; |
| 1558 | default: |
| 1559 | pr_err("%s: Invalid Decimator = %u\n", __func__, decimator); |
| 1560 | ret = -EINVAL; |
| 1561 | goto out; |
| 1562 | } |
| 1563 | |
| 1564 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 1565 | |
| 1566 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x1, adc_dmic_sel); |
| 1567 | |
| 1568 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1569 | |
| 1570 | out: |
| 1571 | kfree(widget_name); |
| 1572 | return ret; |
| 1573 | } |
| 1574 | |
| 1575 | #define WCD9310_DEC_ENUM(xname, xenum) \ |
| 1576 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1577 | .info = snd_soc_info_enum_double, \ |
| 1578 | .get = snd_soc_dapm_get_enum_double, \ |
| 1579 | .put = wcd9310_put_dec_enum, \ |
| 1580 | .private_value = (unsigned long)&xenum } |
| 1581 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1582 | static const struct snd_kcontrol_new dec1_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1583 | WCD9310_DEC_ENUM("DEC1 MUX Mux", dec1_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1584 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1585 | static const struct snd_kcontrol_new dec2_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1586 | WCD9310_DEC_ENUM("DEC2 MUX Mux", dec2_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1587 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1588 | static const struct snd_kcontrol_new dec3_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1589 | WCD9310_DEC_ENUM("DEC3 MUX Mux", dec3_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1590 | |
| 1591 | static const struct snd_kcontrol_new dec4_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1592 | WCD9310_DEC_ENUM("DEC4 MUX Mux", dec4_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1593 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1594 | static const struct snd_kcontrol_new dec5_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1595 | WCD9310_DEC_ENUM("DEC5 MUX Mux", dec5_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1596 | |
| 1597 | static const struct snd_kcontrol_new dec6_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1598 | WCD9310_DEC_ENUM("DEC6 MUX Mux", dec6_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1599 | |
| 1600 | static const struct snd_kcontrol_new dec7_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1601 | WCD9310_DEC_ENUM("DEC7 MUX Mux", dec7_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1602 | |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1603 | static const struct snd_kcontrol_new dec8_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1604 | WCD9310_DEC_ENUM("DEC8 MUX Mux", dec8_mux_enum); |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 1605 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1606 | static const struct snd_kcontrol_new dec9_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1607 | WCD9310_DEC_ENUM("DEC9 MUX Mux", dec9_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1608 | |
| 1609 | static const struct snd_kcontrol_new dec10_mux = |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1610 | WCD9310_DEC_ENUM("DEC10 MUX Mux", dec10_mux_enum); |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 1611 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1612 | static const struct snd_kcontrol_new iir1_inp1_mux = |
| 1613 | SOC_DAPM_ENUM("IIR1 INP1 Mux", iir1_inp1_mux_enum); |
| 1614 | |
Kiran Kandi | 59a96b1 | 2012-01-16 02:20:03 -0800 | [diff] [blame] | 1615 | static const struct snd_kcontrol_new anc1_mux = |
| 1616 | SOC_DAPM_ENUM("ANC1 MUX Mux", anc1_mux_enum); |
| 1617 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1618 | static const struct snd_kcontrol_new anc2_mux = |
| 1619 | SOC_DAPM_ENUM("ANC2 MUX Mux", anc2_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1620 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1621 | static const struct snd_kcontrol_new anc1_fb_mux = |
| 1622 | SOC_DAPM_ENUM("ANC1 FB MUX Mux", anc1_fb_mux_enum); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1623 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 1624 | static const struct snd_kcontrol_new dac1_switch[] = { |
| 1625 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_EAR_EN, 5, 1, 0) |
| 1626 | }; |
| 1627 | static const struct snd_kcontrol_new hphl_switch[] = { |
| 1628 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_HPH_L_DAC_CTL, 6, 1, 0) |
| 1629 | }; |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1630 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 1631 | static const struct snd_kcontrol_new hphl_pa_mix[] = { |
| 1632 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1633 | 7, 1, 0), |
| 1634 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1635 | 7, 1, 0), |
| 1636 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1637 | TABLA_A_AUX_L_PA_CONN_INV, 7, 1, 0), |
| 1638 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1639 | TABLA_A_AUX_R_PA_CONN_INV, 7, 1, 0), |
| 1640 | }; |
| 1641 | |
| 1642 | static const struct snd_kcontrol_new hphr_pa_mix[] = { |
| 1643 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1644 | 6, 1, 0), |
| 1645 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1646 | 6, 1, 0), |
| 1647 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1648 | TABLA_A_AUX_L_PA_CONN_INV, 6, 1, 0), |
| 1649 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1650 | TABLA_A_AUX_R_PA_CONN_INV, 6, 1, 0), |
| 1651 | }; |
| 1652 | |
| 1653 | static const struct snd_kcontrol_new lineout1_pa_mix[] = { |
| 1654 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1655 | 5, 1, 0), |
| 1656 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1657 | 5, 1, 0), |
| 1658 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1659 | TABLA_A_AUX_L_PA_CONN_INV, 5, 1, 0), |
| 1660 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1661 | TABLA_A_AUX_R_PA_CONN_INV, 5, 1, 0), |
| 1662 | }; |
| 1663 | |
| 1664 | static const struct snd_kcontrol_new lineout2_pa_mix[] = { |
| 1665 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1666 | 4, 1, 0), |
| 1667 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1668 | 4, 1, 0), |
| 1669 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1670 | TABLA_A_AUX_L_PA_CONN_INV, 4, 1, 0), |
| 1671 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1672 | TABLA_A_AUX_R_PA_CONN_INV, 4, 1, 0), |
| 1673 | }; |
| 1674 | |
| 1675 | static const struct snd_kcontrol_new lineout3_pa_mix[] = { |
| 1676 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1677 | 3, 1, 0), |
| 1678 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1679 | 3, 1, 0), |
| 1680 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1681 | TABLA_A_AUX_L_PA_CONN_INV, 3, 1, 0), |
| 1682 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1683 | TABLA_A_AUX_R_PA_CONN_INV, 3, 1, 0), |
| 1684 | }; |
| 1685 | |
| 1686 | static const struct snd_kcontrol_new lineout4_pa_mix[] = { |
| 1687 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1688 | 2, 1, 0), |
| 1689 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1690 | 2, 1, 0), |
| 1691 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1692 | TABLA_A_AUX_L_PA_CONN_INV, 2, 1, 0), |
| 1693 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1694 | TABLA_A_AUX_R_PA_CONN_INV, 2, 1, 0), |
| 1695 | }; |
| 1696 | |
| 1697 | static const struct snd_kcontrol_new lineout5_pa_mix[] = { |
| 1698 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1699 | 1, 1, 0), |
| 1700 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1701 | 1, 1, 0), |
| 1702 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1703 | TABLA_A_AUX_L_PA_CONN_INV, 1, 1, 0), |
| 1704 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1705 | TABLA_A_AUX_R_PA_CONN_INV, 1, 1, 0), |
| 1706 | }; |
| 1707 | |
| 1708 | static const struct snd_kcontrol_new ear_pa_mix[] = { |
| 1709 | SOC_DAPM_SINGLE("AUX_PGA_L Switch", TABLA_A_AUX_L_PA_CONN, |
| 1710 | 0, 1, 0), |
| 1711 | SOC_DAPM_SINGLE("AUX_PGA_R Switch", TABLA_A_AUX_R_PA_CONN, |
| 1712 | 0, 1, 0), |
| 1713 | SOC_DAPM_SINGLE("AUX_PGA_L_INV Switch", |
| 1714 | TABLA_A_AUX_L_PA_CONN_INV, 0, 1, 0), |
| 1715 | SOC_DAPM_SINGLE("AUX_PGA_R_INV Switch", |
| 1716 | TABLA_A_AUX_R_PA_CONN_INV, 0, 1, 0), |
| 1717 | }; |
| 1718 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 1719 | static const struct snd_kcontrol_new lineout3_ground_switch = |
| 1720 | SOC_DAPM_SINGLE("Switch", TABLA_A_RX_LINE_3_DAC_CTL, 6, 1, 0); |
| 1721 | |
| 1722 | static const struct snd_kcontrol_new lineout4_ground_switch = |
| 1723 | 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] | 1724 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1725 | /* virtual port entries */ |
| 1726 | static int slim_tx_mixer_get(struct snd_kcontrol *kcontrol, |
| 1727 | struct snd_ctl_elem_value *ucontrol) |
| 1728 | { |
| 1729 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1730 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1731 | |
| 1732 | ucontrol->value.integer.value[0] = widget->value; |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
| 1736 | static int slim_tx_mixer_put(struct snd_kcontrol *kcontrol, |
| 1737 | struct snd_ctl_elem_value *ucontrol) |
| 1738 | { |
| 1739 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1740 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1741 | struct snd_soc_codec *codec = widget->codec; |
| 1742 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 1743 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1744 | struct soc_multi_mixer_control *mixer = |
| 1745 | ((struct soc_multi_mixer_control *)kcontrol->private_value); |
| 1746 | u32 dai_id = widget->shift; |
| 1747 | u32 port_id = mixer->shift; |
| 1748 | u32 enable = ucontrol->value.integer.value[0]; |
| 1749 | |
| 1750 | pr_debug("%s: wname %s cname %s value %u shift %d item %ld\n", __func__, |
| 1751 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 1752 | ucontrol->value.integer.value[0]); |
| 1753 | |
| 1754 | mutex_lock(&codec->mutex); |
| 1755 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1756 | if (dai_id != AIF1_CAP) { |
| 1757 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1758 | __func__); |
| 1759 | mutex_unlock(&codec->mutex); |
| 1760 | return -EINVAL; |
| 1761 | } |
| 1762 | } |
| 1763 | switch (dai_id) { |
| 1764 | case AIF1_CAP: |
| 1765 | case AIF2_CAP: |
| 1766 | case AIF3_CAP: |
| 1767 | /* only add to the list if value not set |
| 1768 | */ |
| 1769 | if (enable && !(widget->value & 1 << port_id)) { |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1770 | if (wcd9xxx_tx_vport_validation( |
| 1771 | vport_check_table[dai_id], |
| 1772 | port_id, |
| 1773 | tabla_p->dai)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1774 | pr_info("%s: TX%u is used by other virtual port\n", |
| 1775 | __func__, port_id + 1); |
| 1776 | mutex_unlock(&codec->mutex); |
| 1777 | return -EINVAL; |
| 1778 | } |
| 1779 | widget->value |= 1 << port_id; |
| 1780 | list_add_tail(&core->tx_chs[port_id].list, |
| 1781 | &tabla_p->dai[dai_id].wcd9xxx_ch_list |
| 1782 | ); |
| 1783 | } else if (!enable && (widget->value & 1 << port_id)) { |
| 1784 | widget->value &= ~(1 << port_id); |
| 1785 | list_del_init(&core->tx_chs[port_id].list); |
| 1786 | } else { |
| 1787 | if (enable) |
| 1788 | pr_info("%s: TX%u port is used by this virtual port\n", |
| 1789 | __func__, port_id + 1); |
| 1790 | else |
| 1791 | pr_info("%s: TX%u port is not used by this virtual port\n", |
| 1792 | __func__, port_id + 1); |
| 1793 | /* avoid update power function */ |
| 1794 | mutex_unlock(&codec->mutex); |
| 1795 | return 0; |
| 1796 | } |
| 1797 | break; |
| 1798 | default: |
| 1799 | pr_err("Unknown AIF %d\n", dai_id); |
| 1800 | mutex_unlock(&codec->mutex); |
| 1801 | return -EINVAL; |
| 1802 | } |
| 1803 | pr_debug("%s: name %s sname %s updated value %u shift %d\n", __func__, |
| 1804 | widget->name, widget->sname, widget->value, widget->shift); |
| 1805 | |
| 1806 | snd_soc_dapm_mixer_update_power(widget, kcontrol, enable); |
| 1807 | |
| 1808 | mutex_unlock(&codec->mutex); |
| 1809 | return 0; |
| 1810 | } |
| 1811 | |
| 1812 | static int slim_rx_mux_get(struct snd_kcontrol *kcontrol, |
| 1813 | struct snd_ctl_elem_value *ucontrol) |
| 1814 | { |
| 1815 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1816 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1817 | |
| 1818 | ucontrol->value.enumerated.item[0] = widget->value; |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | static const char *const slim_rx_mux_text[] = { |
| 1823 | "ZERO", "AIF1_PB", "AIF2_PB", "AIF3_PB" |
| 1824 | }; |
| 1825 | |
| 1826 | static int slim_rx_mux_put(struct snd_kcontrol *kcontrol, |
| 1827 | struct snd_ctl_elem_value *ucontrol) |
| 1828 | { |
| 1829 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1830 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 1831 | struct snd_soc_codec *codec = widget->codec; |
| 1832 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 1833 | struct wcd9xxx *core = dev_get_drvdata(codec->dev->parent); |
| 1834 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 1835 | u32 port_id = widget->shift; |
| 1836 | |
| 1837 | pr_debug("%s: wname %s cname %s value %u shift %d item %u\n", __func__, |
| 1838 | widget->name, ucontrol->id.name, widget->value, widget->shift, |
| 1839 | ucontrol->value.enumerated.item[0]); |
| 1840 | |
| 1841 | widget->value = ucontrol->value.enumerated.item[0]; |
| 1842 | |
| 1843 | mutex_lock(&codec->mutex); |
| 1844 | |
| 1845 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 1846 | if (widget->value > 1) { |
| 1847 | dev_err(codec->dev, "%s: invalid AIF for I2C mode\n", |
| 1848 | __func__); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1849 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1850 | } |
| 1851 | } |
| 1852 | /* value need to match the Virtual port and AIF number |
| 1853 | */ |
| 1854 | switch (widget->value) { |
| 1855 | case 0: |
| 1856 | list_del_init(&core->rx_chs[port_id].list); |
| 1857 | break; |
| 1858 | case 1: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1859 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 1860 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 1861 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1862 | list_add_tail(&core->rx_chs[port_id].list, |
| 1863 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list); |
| 1864 | break; |
| 1865 | case 2: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1866 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 1867 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 1868 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1869 | list_add_tail(&core->rx_chs[port_id].list, |
| 1870 | &tabla_p->dai[AIF2_PB].wcd9xxx_ch_list); |
| 1871 | break; |
| 1872 | case 3: |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1873 | if (wcd9xxx_rx_vport_validation(port_id + core->num_tx_port, |
| 1874 | &tabla_p->dai[AIF1_PB].wcd9xxx_ch_list)) |
| 1875 | goto pr_err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1876 | list_add_tail(&core->rx_chs[port_id].list, |
| 1877 | &tabla_p->dai[AIF3_PB].wcd9xxx_ch_list); |
| 1878 | break; |
| 1879 | default: |
| 1880 | pr_err("Unknown AIF %d\n", widget->value); |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1881 | goto err; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | snd_soc_dapm_mux_update_power(widget, kcontrol, 1, widget->value, e); |
| 1885 | |
| 1886 | mutex_unlock(&codec->mutex); |
| 1887 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1888 | |
| 1889 | pr_err: |
| 1890 | pr_err("%s: RX%u is used by current requesting AIF_PB itself\n", |
| 1891 | __func__, port_id + 1); |
Santosh Mardi | 2a831d7 | 2012-11-07 20:45:52 +0530 | [diff] [blame] | 1892 | mutex_unlock(&codec->mutex); |
| 1893 | return 0; |
Kuirong Wang | dcc392e | 2012-10-19 00:33:38 -0700 | [diff] [blame] | 1894 | err: |
| 1895 | mutex_unlock(&codec->mutex); |
| 1896 | return -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | static const struct soc_enum slim_rx_mux_enum = |
| 1900 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(slim_rx_mux_text), slim_rx_mux_text); |
| 1901 | |
| 1902 | static const struct snd_kcontrol_new slim_rx_mux[TABLA_RX_MAX] = { |
| 1903 | SOC_DAPM_ENUM_EXT("SLIM RX1 Mux", slim_rx_mux_enum, |
| 1904 | slim_rx_mux_get, slim_rx_mux_put), |
| 1905 | SOC_DAPM_ENUM_EXT("SLIM RX2 Mux", slim_rx_mux_enum, |
| 1906 | slim_rx_mux_get, slim_rx_mux_put), |
| 1907 | SOC_DAPM_ENUM_EXT("SLIM RX3 Mux", slim_rx_mux_enum, |
| 1908 | slim_rx_mux_get, slim_rx_mux_put), |
| 1909 | SOC_DAPM_ENUM_EXT("SLIM RX4 Mux", slim_rx_mux_enum, |
| 1910 | slim_rx_mux_get, slim_rx_mux_put), |
| 1911 | SOC_DAPM_ENUM_EXT("SLIM RX5 Mux", slim_rx_mux_enum, |
| 1912 | slim_rx_mux_get, slim_rx_mux_put), |
| 1913 | SOC_DAPM_ENUM_EXT("SLIM RX6 Mux", slim_rx_mux_enum, |
| 1914 | slim_rx_mux_get, slim_rx_mux_put), |
| 1915 | SOC_DAPM_ENUM_EXT("SLIM RX7 Mux", slim_rx_mux_enum, |
| 1916 | slim_rx_mux_get, slim_rx_mux_put), |
| 1917 | }; |
| 1918 | |
| 1919 | static const struct snd_kcontrol_new aif_cap_mixer[] = { |
| 1920 | SOC_SINGLE_EXT("SLIM TX1", SND_SOC_NOPM, TABLA_TX1, 1, 0, |
| 1921 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1922 | SOC_SINGLE_EXT("SLIM TX2", SND_SOC_NOPM, TABLA_TX2, 1, 0, |
| 1923 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1924 | SOC_SINGLE_EXT("SLIM TX3", SND_SOC_NOPM, TABLA_TX3, 1, 0, |
| 1925 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1926 | SOC_SINGLE_EXT("SLIM TX4", SND_SOC_NOPM, TABLA_TX4, 1, 0, |
| 1927 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1928 | SOC_SINGLE_EXT("SLIM TX5", SND_SOC_NOPM, TABLA_TX5, 1, 0, |
| 1929 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1930 | SOC_SINGLE_EXT("SLIM TX6", SND_SOC_NOPM, TABLA_TX6, 1, 0, |
| 1931 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1932 | SOC_SINGLE_EXT("SLIM TX7", SND_SOC_NOPM, TABLA_TX7, 1, 0, |
| 1933 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1934 | SOC_SINGLE_EXT("SLIM TX8", SND_SOC_NOPM, TABLA_TX8, 1, 0, |
| 1935 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1936 | SOC_SINGLE_EXT("SLIM TX9", SND_SOC_NOPM, TABLA_TX9, 1, 0, |
| 1937 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1938 | SOC_SINGLE_EXT("SLIM TX10", SND_SOC_NOPM, TABLA_TX10, 1, 0, |
| 1939 | slim_tx_mixer_get, slim_tx_mixer_put), |
| 1940 | }; |
| 1941 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1942 | static void tabla_codec_enable_adc_block(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1943 | int enable) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1944 | { |
| 1945 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 1946 | |
| 1947 | pr_debug("%s %d\n", __func__, enable); |
| 1948 | |
| 1949 | if (enable) { |
| 1950 | tabla->adc_count++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1951 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, 0x2, 0x2); |
| 1952 | } else { |
| 1953 | tabla->adc_count--; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 1954 | if (!tabla->adc_count) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1955 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_OTHR_CTL, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 1956 | 0x2, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1957 | } |
| 1958 | } |
| 1959 | |
| 1960 | static int tabla_codec_enable_adc(struct snd_soc_dapm_widget *w, |
| 1961 | struct snd_kcontrol *kcontrol, int event) |
| 1962 | { |
| 1963 | struct snd_soc_codec *codec = w->codec; |
| 1964 | u16 adc_reg; |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1965 | u8 init_bit_shift; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1966 | |
| 1967 | pr_debug("%s %d\n", __func__, event); |
| 1968 | |
| 1969 | if (w->reg == TABLA_A_TX_1_2_EN) |
| 1970 | adc_reg = TABLA_A_TX_1_2_TEST_CTL; |
| 1971 | else if (w->reg == TABLA_A_TX_3_4_EN) |
| 1972 | adc_reg = TABLA_A_TX_3_4_TEST_CTL; |
| 1973 | else if (w->reg == TABLA_A_TX_5_6_EN) |
| 1974 | adc_reg = TABLA_A_TX_5_6_TEST_CTL; |
| 1975 | else { |
| 1976 | pr_err("%s: Error, invalid adc register\n", __func__); |
| 1977 | return -EINVAL; |
| 1978 | } |
| 1979 | |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1980 | if (w->shift == 3) |
| 1981 | init_bit_shift = 6; |
| 1982 | else if (w->shift == 7) |
| 1983 | init_bit_shift = 7; |
| 1984 | else { |
| 1985 | pr_err("%s: Error, invalid init bit postion adc register\n", |
| 1986 | __func__); |
| 1987 | return -EINVAL; |
| 1988 | } |
| 1989 | |
| 1990 | |
| 1991 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1992 | switch (event) { |
| 1993 | case SND_SOC_DAPM_PRE_PMU: |
| 1994 | tabla_codec_enable_adc_block(codec, 1); |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1995 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, |
| 1996 | 1 << init_bit_shift); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1997 | break; |
| 1998 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | 9a2c62a8 | 2011-12-07 13:13:26 -0800 | [diff] [blame] | 1999 | |
| 2000 | snd_soc_update_bits(codec, adc_reg, 1 << init_bit_shift, 0x00); |
| 2001 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2002 | break; |
| 2003 | case SND_SOC_DAPM_POST_PMD: |
| 2004 | tabla_codec_enable_adc_block(codec, 0); |
| 2005 | break; |
| 2006 | } |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2010 | static void tabla_codec_enable_audio_mode_bandgap(struct snd_soc_codec *codec) |
| 2011 | { |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2012 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2013 | 0x80); |
| 2014 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x04, |
| 2015 | 0x04); |
| 2016 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2017 | 0x01); |
| 2018 | usleep_range(1000, 1000); |
| 2019 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2020 | 0x00); |
| 2021 | } |
| 2022 | |
| 2023 | static void tabla_codec_enable_bandgap(struct snd_soc_codec *codec, |
| 2024 | enum tabla_bandgap_type choice) |
| 2025 | { |
| 2026 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2027 | |
| 2028 | /* TODO lock resources accessed by audio streams and threaded |
| 2029 | * interrupt handlers |
| 2030 | */ |
| 2031 | |
| 2032 | pr_debug("%s, choice is %d, current is %d\n", __func__, choice, |
| 2033 | tabla->bandgap_type); |
| 2034 | |
| 2035 | if (tabla->bandgap_type == choice) |
| 2036 | return; |
| 2037 | |
| 2038 | if ((tabla->bandgap_type == TABLA_BANDGAP_OFF) && |
| 2039 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
| 2040 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2041 | } else if (choice == TABLA_BANDGAP_MBHC_MODE) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2042 | /* bandgap mode becomes fast, |
| 2043 | * mclk should be off or clk buff source souldn't be VBG |
| 2044 | * Let's turn off mclk always */ |
| 2045 | 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] | 2046 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x2, |
| 2047 | 0x2); |
| 2048 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2049 | 0x80); |
| 2050 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x4, |
| 2051 | 0x4); |
| 2052 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x01, |
| 2053 | 0x01); |
| 2054 | usleep_range(1000, 1000); |
| 2055 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x80, |
| 2056 | 0x00); |
| 2057 | } else if ((tabla->bandgap_type == TABLA_BANDGAP_MBHC_MODE) && |
| 2058 | (choice == TABLA_BANDGAP_AUDIO_MODE)) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2059 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2060 | usleep_range(100, 100); |
| 2061 | tabla_codec_enable_audio_mode_bandgap(codec); |
| 2062 | } else if (choice == TABLA_BANDGAP_OFF) { |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 2063 | snd_soc_write(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2064 | } else { |
| 2065 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 2066 | } |
| 2067 | tabla->bandgap_type = choice; |
| 2068 | } |
| 2069 | |
| 2070 | static void tabla_codec_disable_clock_block(struct snd_soc_codec *codec) |
| 2071 | { |
| 2072 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2073 | pr_debug("%s\n", __func__); |
| 2074 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2075 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2076 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 2077 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2078 | usleep_range(50, 50); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2079 | tabla->clock_active = false; |
| 2080 | } |
| 2081 | |
| 2082 | static int tabla_codec_mclk_index(const struct tabla_priv *tabla) |
| 2083 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2084 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2085 | return 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2086 | else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2087 | return 1; |
| 2088 | else { |
| 2089 | BUG_ON(1); |
| 2090 | return -EINVAL; |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | static void tabla_enable_rx_bias(struct snd_soc_codec *codec, u32 enable) |
| 2095 | { |
| 2096 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2097 | |
| 2098 | if (enable) { |
| 2099 | tabla->rx_bias_count++; |
| 2100 | if (tabla->rx_bias_count == 1) |
| 2101 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2102 | 0x80, 0x80); |
| 2103 | } else { |
| 2104 | tabla->rx_bias_count--; |
| 2105 | if (!tabla->rx_bias_count) |
| 2106 | snd_soc_update_bits(codec, TABLA_A_RX_COM_BIAS, |
| 2107 | 0x80, 0x00); |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | static int tabla_codec_enable_config_mode(struct snd_soc_codec *codec, |
| 2112 | int enable) |
| 2113 | { |
| 2114 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2115 | |
| 2116 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 2117 | if (enable) { |
| 2118 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x10, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2119 | /* bandgap mode to fast */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2120 | snd_soc_write(codec, TABLA_A_BIAS_CONFIG_MODE_BG_CTL, 0x17); |
| 2121 | usleep_range(5, 5); |
| 2122 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2123 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2124 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2125 | 0x80); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2126 | usleep_range(10, 10); |
| 2127 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_TEST, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2128 | usleep_range(10000, 10000); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2129 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 2130 | } else { |
| 2131 | 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] | 2132 | 0); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2133 | snd_soc_update_bits(codec, TABLA_A_CONFIG_MODE_FREQ, 0x80, 0); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2134 | /* clk source to ext clk and clk buff ref to VBG */ |
| 2135 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x0C, 0x04); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2136 | } |
| 2137 | tabla->config_mode_active = enable ? true : false; |
| 2138 | |
| 2139 | return 0; |
| 2140 | } |
| 2141 | |
| 2142 | static int tabla_codec_enable_clock_block(struct snd_soc_codec *codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2143 | int config_mode) |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2144 | { |
| 2145 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2146 | |
| 2147 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 2148 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2149 | /* transit to RCO requires mclk off */ |
| 2150 | 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] | 2151 | if (config_mode) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2152 | /* enable RCO and switch to it */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2153 | tabla_codec_enable_config_mode(codec, 1); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2154 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2155 | usleep_range(1000, 1000); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2156 | } else { |
| 2157 | /* switch to MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2158 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 2159 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2160 | if (tabla->mbhc_polling_active) { |
| 2161 | snd_soc_write(codec, TABLA_A_CLK_BUFF_EN2, 0x02); |
| 2162 | tabla_codec_enable_config_mode(codec, 0); |
| 2163 | } |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2166 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x01, 0x01); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2167 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x02, 0x00); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 2168 | /* on MCLK */ |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 2169 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 2170 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 2171 | usleep_range(50, 50); |
| 2172 | tabla->clock_active = true; |
| 2173 | return 0; |
| 2174 | } |
| 2175 | |
| 2176 | static int tabla_codec_enable_aux_pga(struct snd_soc_dapm_widget *w, |
| 2177 | struct snd_kcontrol *kcontrol, int event) |
| 2178 | { |
| 2179 | struct snd_soc_codec *codec = w->codec; |
| 2180 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2181 | |
| 2182 | pr_debug("%s: %d\n", __func__, event); |
| 2183 | |
| 2184 | switch (event) { |
| 2185 | case SND_SOC_DAPM_PRE_PMU: |
| 2186 | tabla_codec_enable_bandgap(codec, |
| 2187 | TABLA_BANDGAP_AUDIO_MODE); |
| 2188 | tabla_enable_rx_bias(codec, 1); |
| 2189 | |
| 2190 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2191 | 0x08, 0x08); |
| 2192 | /* Enable Zero Cross detect for AUX PGA channel |
| 2193 | * and set the initial AUX PGA gain to NEG_0P0_DB |
| 2194 | * to avoid glitches. |
| 2195 | */ |
| 2196 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2197 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2198 | 0x20, 0x20); |
| 2199 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2200 | TABLA_A_AUX_L_GAIN); |
| 2201 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2202 | } else { |
| 2203 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2204 | 0x20, 0x20); |
| 2205 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2206 | TABLA_A_AUX_R_GAIN); |
| 2207 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2208 | } |
| 2209 | if (tabla->aux_pga_cnt++ == 1 |
| 2210 | && !tabla->mclk_enabled) { |
| 2211 | tabla_codec_enable_clock_block(codec, 1); |
| 2212 | pr_debug("AUX PGA enabled RC osc\n"); |
| 2213 | } |
| 2214 | break; |
| 2215 | |
| 2216 | case SND_SOC_DAPM_POST_PMU: |
| 2217 | if (w->reg == TABLA_A_AUX_L_EN) |
| 2218 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2219 | tabla->aux_l_gain); |
| 2220 | else |
| 2221 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2222 | tabla->aux_r_gain); |
| 2223 | break; |
| 2224 | |
| 2225 | case SND_SOC_DAPM_PRE_PMD: |
| 2226 | /* Mute AUX PGA channel in use before disabling AUX PGA */ |
| 2227 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2228 | tabla->aux_l_gain = snd_soc_read(codec, |
| 2229 | TABLA_A_AUX_L_GAIN); |
| 2230 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, 0x1F); |
| 2231 | } else { |
| 2232 | tabla->aux_r_gain = snd_soc_read(codec, |
| 2233 | TABLA_A_AUX_R_GAIN); |
| 2234 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, 0x1F); |
| 2235 | } |
| 2236 | break; |
| 2237 | |
| 2238 | case SND_SOC_DAPM_POST_PMD: |
| 2239 | tabla_enable_rx_bias(codec, 0); |
| 2240 | |
| 2241 | snd_soc_update_bits(codec, TABLA_A_AUX_COM_CTL, |
| 2242 | 0x08, 0x00); |
| 2243 | if (w->reg == TABLA_A_AUX_L_EN) { |
| 2244 | snd_soc_write(codec, TABLA_A_AUX_L_GAIN, |
| 2245 | tabla->aux_l_gain); |
| 2246 | snd_soc_update_bits(codec, TABLA_A_AUX_L_EN, |
| 2247 | 0x20, 0x00); |
| 2248 | } else { |
| 2249 | snd_soc_write(codec, TABLA_A_AUX_R_GAIN, |
| 2250 | tabla->aux_r_gain); |
| 2251 | snd_soc_update_bits(codec, TABLA_A_AUX_R_EN, |
| 2252 | 0x20, 0x00); |
| 2253 | } |
| 2254 | |
| 2255 | if (tabla->aux_pga_cnt-- == 0) { |
| 2256 | if (tabla->mbhc_polling_active) |
| 2257 | tabla_codec_enable_bandgap(codec, |
| 2258 | TABLA_BANDGAP_MBHC_MODE); |
| 2259 | else |
| 2260 | tabla_codec_enable_bandgap(codec, |
| 2261 | TABLA_BANDGAP_OFF); |
| 2262 | |
| 2263 | if (!tabla->mclk_enabled && |
| 2264 | !tabla->mbhc_polling_active) { |
| 2265 | tabla_codec_enable_clock_block(codec, 0); |
| 2266 | } |
| 2267 | } |
| 2268 | break; |
| 2269 | } |
| 2270 | return 0; |
| 2271 | } |
| 2272 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2273 | static int tabla_codec_enable_lineout(struct snd_soc_dapm_widget *w, |
| 2274 | struct snd_kcontrol *kcontrol, int event) |
| 2275 | { |
| 2276 | struct snd_soc_codec *codec = w->codec; |
| 2277 | u16 lineout_gain_reg; |
| 2278 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2279 | pr_debug("%s %d %s\n", __func__, event, w->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2280 | |
| 2281 | switch (w->shift) { |
| 2282 | case 0: |
| 2283 | lineout_gain_reg = TABLA_A_RX_LINE_1_GAIN; |
| 2284 | break; |
| 2285 | case 1: |
| 2286 | lineout_gain_reg = TABLA_A_RX_LINE_2_GAIN; |
| 2287 | break; |
| 2288 | case 2: |
| 2289 | lineout_gain_reg = TABLA_A_RX_LINE_3_GAIN; |
| 2290 | break; |
| 2291 | case 3: |
| 2292 | lineout_gain_reg = TABLA_A_RX_LINE_4_GAIN; |
| 2293 | break; |
| 2294 | case 4: |
| 2295 | lineout_gain_reg = TABLA_A_RX_LINE_5_GAIN; |
| 2296 | break; |
| 2297 | default: |
| 2298 | pr_err("%s: Error, incorrect lineout register value\n", |
| 2299 | __func__); |
| 2300 | return -EINVAL; |
| 2301 | } |
| 2302 | |
| 2303 | switch (event) { |
| 2304 | case SND_SOC_DAPM_PRE_PMU: |
| 2305 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x40); |
| 2306 | break; |
| 2307 | case SND_SOC_DAPM_POST_PMU: |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2308 | pr_debug("%s: sleeping 16 ms after %s PA turn on\n", |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 2309 | __func__, w->name); |
Krishnankutty Kolathappilly | 31169f4 | 2011-11-17 10:33:11 -0800 | [diff] [blame] | 2310 | usleep_range(16000, 16000); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2311 | break; |
| 2312 | case SND_SOC_DAPM_POST_PMD: |
| 2313 | snd_soc_update_bits(codec, lineout_gain_reg, 0x40, 0x00); |
| 2314 | break; |
| 2315 | } |
| 2316 | return 0; |
| 2317 | } |
| 2318 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2319 | |
| 2320 | static int tabla_codec_enable_dmic(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2321 | struct snd_kcontrol *kcontrol, int event) |
| 2322 | { |
| 2323 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2324 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2325 | u8 dmic_clk_en; |
| 2326 | s32 *dmic_clk_cnt; |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2327 | unsigned int dmic; |
| 2328 | int ret; |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2329 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2330 | ret = kstrtouint(strpbrk(w->name, "123456"), 10, &dmic); |
| 2331 | if (ret < 0) { |
| 2332 | pr_err("%s: Invalid DMIC line on the codec\n", __func__); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2333 | return -EINVAL; |
| 2334 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2335 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2336 | switch (dmic) { |
| 2337 | case 1: |
| 2338 | case 2: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2339 | dmic_clk_en = 0x01; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2340 | dmic_clk_cnt = &(tabla->dmic_1_2_clk_cnt); |
| 2341 | |
| 2342 | pr_debug("%s() event %d DMIC%d dmic_1_2_clk_cnt %d\n", |
| 2343 | __func__, event, dmic, *dmic_clk_cnt); |
| 2344 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2345 | break; |
| 2346 | |
| 2347 | case 3: |
| 2348 | case 4: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2349 | dmic_clk_en = 0x04; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2350 | dmic_clk_cnt = &(tabla->dmic_3_4_clk_cnt); |
| 2351 | |
| 2352 | pr_debug("%s() event %d DMIC%d dmic_3_4_clk_cnt %d\n", |
| 2353 | __func__, event, dmic, *dmic_clk_cnt); |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2354 | break; |
| 2355 | |
| 2356 | case 5: |
| 2357 | case 6: |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2358 | dmic_clk_en = 0x10; |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2359 | dmic_clk_cnt = &(tabla->dmic_5_6_clk_cnt); |
| 2360 | |
| 2361 | pr_debug("%s() event %d DMIC%d dmic_5_6_clk_cnt %d\n", |
| 2362 | __func__, event, dmic, *dmic_clk_cnt); |
| 2363 | |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 2364 | break; |
| 2365 | |
| 2366 | default: |
| 2367 | pr_err("%s: Invalid DMIC Selection\n", __func__); |
| 2368 | return -EINVAL; |
| 2369 | } |
| 2370 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2371 | switch (event) { |
| 2372 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2373 | |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2374 | (*dmic_clk_cnt)++; |
| 2375 | if (*dmic_clk_cnt == 1) |
| 2376 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2377 | dmic_clk_en, dmic_clk_en); |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 2378 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2379 | break; |
| 2380 | case SND_SOC_DAPM_POST_PMD: |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 2381 | |
| 2382 | (*dmic_clk_cnt)--; |
| 2383 | if (*dmic_clk_cnt == 0) |
| 2384 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_DMIC_CTL, |
| 2385 | dmic_clk_en, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2386 | break; |
| 2387 | } |
| 2388 | return 0; |
| 2389 | } |
| 2390 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2391 | static int tabla_codec_enable_anc(struct snd_soc_dapm_widget *w, |
| 2392 | struct snd_kcontrol *kcontrol, int event) |
| 2393 | { |
| 2394 | struct snd_soc_codec *codec = w->codec; |
| 2395 | const char *filename; |
| 2396 | const struct firmware *fw; |
| 2397 | int i; |
| 2398 | int ret; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2399 | int num_anc_slots; |
| 2400 | struct anc_header *anc_head; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2401 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2402 | u32 anc_writes_size = 0; |
| 2403 | int anc_size_remaining; |
| 2404 | u32 *anc_ptr; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2405 | u16 reg; |
| 2406 | u8 mask, val, old_val; |
| 2407 | |
| 2408 | pr_debug("%s %d\n", __func__, event); |
| 2409 | switch (event) { |
| 2410 | case SND_SOC_DAPM_PRE_PMU: |
| 2411 | |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2412 | filename = "wcd9310/wcd9310_anc.bin"; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2413 | |
| 2414 | ret = request_firmware(&fw, filename, codec->dev); |
| 2415 | if (ret != 0) { |
| 2416 | dev_err(codec->dev, "Failed to acquire ANC data: %d\n", |
| 2417 | ret); |
| 2418 | return -ENODEV; |
| 2419 | } |
| 2420 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2421 | if (fw->size < sizeof(struct anc_header)) { |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2422 | dev_err(codec->dev, "Not enough data\n"); |
| 2423 | release_firmware(fw); |
| 2424 | return -ENOMEM; |
| 2425 | } |
| 2426 | |
| 2427 | /* First number is the number of register writes */ |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2428 | anc_head = (struct anc_header *)(fw->data); |
| 2429 | anc_ptr = (u32 *)((u32)fw->data + sizeof(struct anc_header)); |
| 2430 | anc_size_remaining = fw->size - sizeof(struct anc_header); |
| 2431 | num_anc_slots = anc_head->num_anc_slots; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2432 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2433 | if (tabla->anc_slot >= num_anc_slots) { |
| 2434 | dev_err(codec->dev, "Invalid ANC slot selected\n"); |
| 2435 | release_firmware(fw); |
| 2436 | return -EINVAL; |
| 2437 | } |
| 2438 | |
| 2439 | for (i = 0; i < num_anc_slots; i++) { |
| 2440 | |
| 2441 | if (anc_size_remaining < TABLA_PACKED_REG_SIZE) { |
| 2442 | dev_err(codec->dev, "Invalid register format\n"); |
| 2443 | release_firmware(fw); |
| 2444 | return -EINVAL; |
| 2445 | } |
| 2446 | anc_writes_size = (u32)(*anc_ptr); |
| 2447 | anc_size_remaining -= sizeof(u32); |
| 2448 | anc_ptr += 1; |
| 2449 | |
| 2450 | if (anc_writes_size * TABLA_PACKED_REG_SIZE |
| 2451 | > anc_size_remaining) { |
| 2452 | dev_err(codec->dev, "Invalid register format\n"); |
| 2453 | release_firmware(fw); |
| 2454 | return -ENOMEM; |
| 2455 | } |
| 2456 | |
| 2457 | if (tabla->anc_slot == i) |
| 2458 | break; |
| 2459 | |
| 2460 | anc_size_remaining -= (anc_writes_size * |
| 2461 | TABLA_PACKED_REG_SIZE); |
Bradley Rubin | 939ff3f | 2011-08-26 17:19:34 -0700 | [diff] [blame] | 2462 | anc_ptr += anc_writes_size; |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2463 | } |
| 2464 | if (i == num_anc_slots) { |
| 2465 | dev_err(codec->dev, "Selected ANC slot not present\n"); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2466 | release_firmware(fw); |
| 2467 | return -ENOMEM; |
| 2468 | } |
| 2469 | |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 2470 | for (i = 0; i < anc_writes_size; i++) { |
| 2471 | TABLA_CODEC_UNPACK_ENTRY(anc_ptr[i], reg, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2472 | mask, val); |
| 2473 | old_val = snd_soc_read(codec, reg); |
Bradley Rubin | 4283a4c | 2011-07-29 16:18:54 -0700 | [diff] [blame] | 2474 | snd_soc_write(codec, reg, (old_val & ~mask) | |
| 2475 | (val & mask)); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2476 | } |
| 2477 | release_firmware(fw); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2478 | |
Joonwoo Park | 743d0e3 | 2012-05-17 15:11:58 -0700 | [diff] [blame] | 2479 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 2480 | /* if MBHC polling is active, set TX7_MBHC_EN bit 7 */ |
| 2481 | if (tabla->mbhc_polling_active) |
| 2482 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, |
| 2483 | 0x80); |
| 2484 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2485 | break; |
| 2486 | case SND_SOC_DAPM_POST_PMD: |
Joonwoo Park | 743d0e3 | 2012-05-17 15:11:58 -0700 | [diff] [blame] | 2487 | /* unset TX7_MBHC_EN bit 7 */ |
| 2488 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x00); |
| 2489 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2490 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_RESET_CTL, 0xFF); |
| 2491 | snd_soc_write(codec, TABLA_A_CDC_CLK_ANC_CLK_EN_CTL, 0); |
| 2492 | break; |
| 2493 | } |
| 2494 | return 0; |
| 2495 | } |
| 2496 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2497 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2498 | static void tabla_codec_start_hs_polling(struct snd_soc_codec *codec) |
| 2499 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2500 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2501 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
| 2502 | int mbhc_state = tabla->mbhc_state; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2503 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2504 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2505 | if (!tabla->mbhc_polling_active) { |
| 2506 | pr_debug("Polling is not active, do not start polling\n"); |
| 2507 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2508 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2509 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2510 | |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 2511 | if (tabla->no_mic_headset_override) { |
| 2512 | pr_debug("%s setting button threshold to min", __func__); |
| 2513 | /* set to min */ |
| 2514 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, 0x80); |
| 2515 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0x00); |
| 2516 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x80); |
| 2517 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0x00); |
| 2518 | } else if (unlikely(mbhc_state == MBHC_STATE_POTENTIAL)) { |
| 2519 | pr_debug("%s recovering MBHC state machine\n", __func__); |
| 2520 | tabla->mbhc_state = MBHC_STATE_POTENTIAL_RECOVERY; |
| 2521 | /* set to max button press threshold */ |
| 2522 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, 0x7F); |
| 2523 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, 0xFF); |
| 2524 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 2525 | (TABLA_IS_1_X(tabla_core->version) ? |
| 2526 | 0x07 : 0x7F)); |
| 2527 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, 0xFF); |
| 2528 | /* set to max */ |
| 2529 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, 0x7F); |
| 2530 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, 0xFF); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2533 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
| 2534 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x0); |
| 2535 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x1); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2536 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2539 | /* called under codec_resource_lock acquisition */ |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2540 | static void tabla_codec_pause_hs_polling(struct snd_soc_codec *codec) |
| 2541 | { |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2542 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2543 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2544 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2545 | if (!tabla->mbhc_polling_active) { |
| 2546 | pr_debug("polling not active, nothing to pause\n"); |
| 2547 | return; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 2548 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2549 | |
| 2550 | 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] | 2551 | pr_debug("%s: leave\n", __func__); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2554 | 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] | 2555 | { |
| 2556 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2557 | u8 reg_mode_val, cur_mode_val; |
| 2558 | bool mbhc_was_polling = false; |
| 2559 | |
| 2560 | if (mode) |
| 2561 | reg_mode_val = TABLA_CFILT_FAST_MODE; |
| 2562 | else |
| 2563 | reg_mode_val = TABLA_CFILT_SLOW_MODE; |
| 2564 | |
| 2565 | cur_mode_val = snd_soc_read(codec, |
| 2566 | tabla->mbhc_bias_regs.cfilt_ctl) & 0x40; |
| 2567 | |
| 2568 | if (cur_mode_val != reg_mode_val) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2569 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2570 | if (tabla->mbhc_polling_active) { |
| 2571 | tabla_codec_pause_hs_polling(codec); |
| 2572 | mbhc_was_polling = true; |
| 2573 | } |
| 2574 | snd_soc_update_bits(codec, |
| 2575 | tabla->mbhc_bias_regs.cfilt_ctl, 0x40, reg_mode_val); |
| 2576 | if (mbhc_was_polling) |
| 2577 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2578 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 2579 | pr_debug("%s: CFILT mode change (%x to %x)\n", __func__, |
| 2580 | cur_mode_val, reg_mode_val); |
| 2581 | } else { |
| 2582 | pr_debug("%s: CFILT Value is already %x\n", |
| 2583 | __func__, cur_mode_val); |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | static void tabla_codec_update_cfilt_usage(struct snd_soc_codec *codec, |
| 2588 | u8 cfilt_sel, int inc) |
| 2589 | { |
| 2590 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2591 | u32 *cfilt_cnt_ptr = NULL; |
| 2592 | u16 micb_cfilt_reg; |
| 2593 | |
| 2594 | switch (cfilt_sel) { |
| 2595 | case TABLA_CFILT1_SEL: |
| 2596 | cfilt_cnt_ptr = &tabla->cfilt1_cnt; |
| 2597 | micb_cfilt_reg = TABLA_A_MICB_CFILT_1_CTL; |
| 2598 | break; |
| 2599 | case TABLA_CFILT2_SEL: |
| 2600 | cfilt_cnt_ptr = &tabla->cfilt2_cnt; |
| 2601 | micb_cfilt_reg = TABLA_A_MICB_CFILT_2_CTL; |
| 2602 | break; |
| 2603 | case TABLA_CFILT3_SEL: |
| 2604 | cfilt_cnt_ptr = &tabla->cfilt3_cnt; |
| 2605 | micb_cfilt_reg = TABLA_A_MICB_CFILT_3_CTL; |
| 2606 | break; |
| 2607 | default: |
| 2608 | return; /* should not happen */ |
| 2609 | } |
| 2610 | |
| 2611 | if (inc) { |
| 2612 | if (!(*cfilt_cnt_ptr)++) { |
| 2613 | /* Switch CFILT to slow mode if MBHC CFILT being used */ |
| 2614 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2615 | tabla_codec_switch_cfilt_mode(codec, 0); |
| 2616 | |
| 2617 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 2618 | } |
| 2619 | } else { |
| 2620 | /* check if count not zero, decrement |
| 2621 | * then check if zero, go ahead disable cfilter |
| 2622 | */ |
| 2623 | if ((*cfilt_cnt_ptr) && !--(*cfilt_cnt_ptr)) { |
| 2624 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 2625 | |
| 2626 | /* Switch CFILT to fast mode if MBHC CFILT being used */ |
| 2627 | if (cfilt_sel == tabla->mbhc_bias_regs.cfilt_sel) |
| 2628 | tabla_codec_switch_cfilt_mode(codec, 1); |
| 2629 | } |
| 2630 | } |
| 2631 | } |
| 2632 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2633 | static int tabla_find_k_value(unsigned int ldoh_v, unsigned int cfilt_mv) |
| 2634 | { |
| 2635 | int rc = -EINVAL; |
| 2636 | unsigned min_mv, max_mv; |
| 2637 | |
| 2638 | switch (ldoh_v) { |
| 2639 | case TABLA_LDOH_1P95_V: |
| 2640 | min_mv = 160; |
| 2641 | max_mv = 1800; |
| 2642 | break; |
| 2643 | case TABLA_LDOH_2P35_V: |
| 2644 | min_mv = 200; |
| 2645 | max_mv = 2200; |
| 2646 | break; |
| 2647 | case TABLA_LDOH_2P75_V: |
| 2648 | min_mv = 240; |
| 2649 | max_mv = 2600; |
| 2650 | break; |
| 2651 | case TABLA_LDOH_2P85_V: |
| 2652 | min_mv = 250; |
| 2653 | max_mv = 2700; |
| 2654 | break; |
| 2655 | default: |
| 2656 | goto done; |
| 2657 | } |
| 2658 | |
| 2659 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 2660 | goto done; |
| 2661 | |
| 2662 | for (rc = 4; rc <= 44; rc++) { |
| 2663 | min_mv = max_mv * (rc) / 44; |
| 2664 | if (min_mv >= cfilt_mv) { |
| 2665 | rc -= 4; |
| 2666 | break; |
| 2667 | } |
| 2668 | } |
| 2669 | done: |
| 2670 | return rc; |
| 2671 | } |
| 2672 | |
| 2673 | static bool tabla_is_hph_pa_on(struct snd_soc_codec *codec) |
| 2674 | { |
| 2675 | u8 hph_reg_val = 0; |
| 2676 | hph_reg_val = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_EN); |
| 2677 | |
| 2678 | return (hph_reg_val & 0x30) ? true : false; |
| 2679 | } |
| 2680 | |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 2681 | static bool tabla_is_hph_dac_on(struct snd_soc_codec *codec, int left) |
| 2682 | { |
| 2683 | u8 hph_reg_val = 0; |
| 2684 | if (left) |
| 2685 | hph_reg_val = snd_soc_read(codec, |
| 2686 | TABLA_A_RX_HPH_L_DAC_CTL); |
| 2687 | else |
| 2688 | hph_reg_val = snd_soc_read(codec, |
| 2689 | TABLA_A_RX_HPH_R_DAC_CTL); |
| 2690 | |
| 2691 | return (hph_reg_val & 0xC0) ? true : false; |
| 2692 | } |
| 2693 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2694 | static void tabla_turn_onoff_override(struct snd_soc_codec *codec, bool on) |
| 2695 | { |
| 2696 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, on << 2); |
| 2697 | } |
| 2698 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2699 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2700 | static void tabla_codec_drive_v_to_micbias(struct snd_soc_codec *codec, |
| 2701 | int usec) |
| 2702 | { |
| 2703 | int cfilt_k_val; |
| 2704 | bool set = true; |
| 2705 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2706 | |
| 2707 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 2708 | tabla->mbhc_micbias_switched) { |
| 2709 | pr_debug("%s: set mic V to micbias V\n", __func__); |
| 2710 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 2711 | tabla_turn_onoff_override(codec, true); |
| 2712 | while (1) { |
| 2713 | cfilt_k_val = tabla_find_k_value( |
| 2714 | tabla->pdata->micbias.ldoh_v, |
| 2715 | set ? tabla->mbhc_data.micb_mv : |
| 2716 | VDDIO_MICBIAS_MV); |
| 2717 | snd_soc_update_bits(codec, |
| 2718 | tabla->mbhc_bias_regs.cfilt_val, |
| 2719 | 0xFC, (cfilt_k_val << 2)); |
| 2720 | if (!set) |
| 2721 | break; |
| 2722 | usleep_range(usec, usec); |
| 2723 | set = false; |
| 2724 | } |
| 2725 | tabla_turn_onoff_override(codec, false); |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | /* called under codec_resource_lock acquisition */ |
| 2730 | static void __tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2731 | int vddio_switch, bool restartpolling, |
| 2732 | bool checkpolling) |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2733 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2734 | int cfilt_k_val; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2735 | bool override; |
| 2736 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2737 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2738 | if (vddio_switch && !tabla->mbhc_micbias_switched && |
| 2739 | (!checkpolling || tabla->mbhc_polling_active)) { |
| 2740 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2741 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2742 | override = snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04; |
| 2743 | if (!override) |
| 2744 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2745 | /* Adjust threshold if Mic Bias voltage changes */ |
| 2746 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2747 | cfilt_k_val = tabla_find_k_value( |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2748 | tabla->pdata->micbias.ldoh_v, |
| 2749 | VDDIO_MICBIAS_MV); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2750 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2751 | tabla->mbhc_bias_regs.cfilt_val, |
| 2752 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2753 | usleep_range(cfilt_adjust_ms * 1000, |
| 2754 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2755 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2756 | tabla->mbhc_data.adj_v_ins_hu & 0xFF); |
| 2757 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2758 | (tabla->mbhc_data.adj_v_ins_hu >> 8) & |
| 2759 | 0xFF); |
| 2760 | pr_debug("%s: Programmed MBHC thresholds to VDDIO\n", |
| 2761 | __func__); |
| 2762 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2763 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2764 | /* enable MIC BIAS Switch to VDDIO */ |
| 2765 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2766 | 0x80, 0x80); |
| 2767 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2768 | 0x10, 0x00); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 2769 | if (!override) |
| 2770 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2771 | if (restartpolling) |
Bhalchandra Gajare | c1e19c4 | 2011-11-18 11:22:56 -0800 | [diff] [blame] | 2772 | tabla_codec_start_hs_polling(codec); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2773 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2774 | tabla->mbhc_micbias_switched = true; |
| 2775 | pr_debug("%s: VDDIO switch enabled\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2776 | } else if (!vddio_switch && tabla->mbhc_micbias_switched) { |
| 2777 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2778 | restartpolling) |
| 2779 | tabla_codec_pause_hs_polling(codec); |
| 2780 | /* Reprogram thresholds */ |
| 2781 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 2782 | cfilt_k_val = tabla_find_k_value( |
| 2783 | tabla->pdata->micbias.ldoh_v, |
| 2784 | tabla->mbhc_data.micb_mv); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2785 | snd_soc_update_bits(codec, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2786 | tabla->mbhc_bias_regs.cfilt_val, |
| 2787 | 0xFC, (cfilt_k_val << 2)); |
Joonwoo Park | c1c67a9 | 2012-08-07 16:05:36 -0700 | [diff] [blame] | 2788 | usleep_range(cfilt_adjust_ms * 1000, |
| 2789 | cfilt_adjust_ms * 1000); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2790 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 2791 | tabla->mbhc_data.v_ins_hu & 0xFF); |
| 2792 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 2793 | (tabla->mbhc_data.v_ins_hu >> 8) & 0xFF); |
| 2794 | pr_debug("%s: Programmed MBHC thresholds to MICBIAS\n", |
| 2795 | __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2796 | } |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2797 | |
| 2798 | /* Disable MIC BIAS Switch to VDDIO */ |
| 2799 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2800 | 0x80, 0x00); |
| 2801 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 2802 | 0x10, 0x00); |
| 2803 | |
| 2804 | if ((!checkpolling || tabla->mbhc_polling_active) && |
| 2805 | restartpolling) |
| 2806 | tabla_codec_start_hs_polling(codec); |
| 2807 | |
| 2808 | tabla->mbhc_micbias_switched = false; |
| 2809 | pr_debug("%s: VDDIO switch disabled\n", __func__); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
| 2812 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 2813 | static void tabla_codec_switch_micbias(struct snd_soc_codec *codec, |
| 2814 | int vddio_switch) |
| 2815 | { |
| 2816 | return __tabla_codec_switch_micbias(codec, vddio_switch, true, true); |
| 2817 | } |
| 2818 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2819 | static int tabla_codec_enable_micbias(struct snd_soc_dapm_widget *w, |
| 2820 | struct snd_kcontrol *kcontrol, int event) |
| 2821 | { |
| 2822 | struct snd_soc_codec *codec = w->codec; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2823 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 2824 | u16 micb_int_reg; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2825 | int micb_line; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2826 | u8 cfilt_sel_val = 0; |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2827 | char *internal1_text = "Internal1"; |
| 2828 | char *internal2_text = "Internal2"; |
| 2829 | char *internal3_text = "Internal3"; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2830 | |
| 2831 | pr_debug("%s %d\n", __func__, event); |
| 2832 | switch (w->reg) { |
| 2833 | case TABLA_A_MICB_1_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2834 | micb_int_reg = TABLA_A_MICB_1_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2835 | cfilt_sel_val = tabla->pdata->micbias.bias1_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2836 | micb_line = TABLA_MICBIAS1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2837 | break; |
| 2838 | case TABLA_A_MICB_2_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2839 | micb_int_reg = TABLA_A_MICB_2_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2840 | cfilt_sel_val = tabla->pdata->micbias.bias2_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2841 | micb_line = TABLA_MICBIAS2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2842 | break; |
| 2843 | case TABLA_A_MICB_3_CTL: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2844 | micb_int_reg = TABLA_A_MICB_3_INT_RBIAS; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2845 | cfilt_sel_val = tabla->pdata->micbias.bias3_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2846 | micb_line = TABLA_MICBIAS3; |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2847 | break; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 2848 | case TABLA_1_A_MICB_4_CTL: |
| 2849 | case TABLA_2_A_MICB_4_CTL: |
| 2850 | micb_int_reg = tabla->reg_addr.micb_4_int_rbias; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2851 | cfilt_sel_val = tabla->pdata->micbias.bias4_cfilt_sel; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2852 | micb_line = TABLA_MICBIAS4; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2853 | break; |
| 2854 | default: |
| 2855 | pr_err("%s: Error, invalid micbias register\n", __func__); |
| 2856 | return -EINVAL; |
| 2857 | } |
| 2858 | |
| 2859 | switch (event) { |
| 2860 | case SND_SOC_DAPM_PRE_PMU: |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2861 | /* Decide whether to switch the micbias for MBHC */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2862 | if (w->reg == tabla->mbhc_bias_regs.ctl_reg) { |
| 2863 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2864 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2865 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2866 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2867 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 2868 | snd_soc_update_bits(codec, w->reg, 0x0E, 0x0A); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2869 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 1); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2870 | |
| 2871 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2872 | snd_soc_update_bits(codec, micb_int_reg, 0xE0, 0xE0); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2873 | else if (strnstr(w->name, internal2_text, 30)) |
| 2874 | snd_soc_update_bits(codec, micb_int_reg, 0x1C, 0x1C); |
| 2875 | else if (strnstr(w->name, internal3_text, 30)) |
| 2876 | snd_soc_update_bits(codec, micb_int_reg, 0x3, 0x3); |
| 2877 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2878 | break; |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2879 | case SND_SOC_DAPM_POST_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2880 | |
| 2881 | usleep_range(20000, 20000); |
| 2882 | |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2883 | if (tabla->mbhc_polling_active && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2884 | tabla->mbhc_cfg.micbias == micb_line) { |
| 2885 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2886 | tabla_codec_pause_hs_polling(codec); |
| 2887 | tabla_codec_start_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2888 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bradley Rubin | 4d09cf4 | 2011-08-17 17:59:16 -0700 | [diff] [blame] | 2889 | } |
| 2890 | break; |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2891 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2892 | case SND_SOC_DAPM_POST_PMD: |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 2893 | if ((w->reg == tabla->mbhc_bias_regs.ctl_reg) && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2894 | tabla_is_hph_pa_on(codec)) { |
| 2895 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2896 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 2897 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 2898 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 2899 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2900 | if (strnstr(w->name, internal1_text, 30)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2901 | snd_soc_update_bits(codec, micb_int_reg, 0x80, 0x00); |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 2902 | else if (strnstr(w->name, internal2_text, 30)) |
| 2903 | snd_soc_update_bits(codec, micb_int_reg, 0x10, 0x00); |
| 2904 | else if (strnstr(w->name, internal3_text, 30)) |
| 2905 | snd_soc_update_bits(codec, micb_int_reg, 0x2, 0x0); |
| 2906 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 2907 | tabla_codec_update_cfilt_usage(codec, cfilt_sel_val, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2908 | break; |
| 2909 | } |
| 2910 | |
| 2911 | return 0; |
| 2912 | } |
| 2913 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2914 | |
| 2915 | static void tx_hpf_corner_freq_callback(struct work_struct *work) |
| 2916 | { |
| 2917 | struct delayed_work *hpf_delayed_work; |
| 2918 | struct hpf_work *hpf_work; |
| 2919 | struct tabla_priv *tabla; |
| 2920 | struct snd_soc_codec *codec; |
| 2921 | u16 tx_mux_ctl_reg; |
| 2922 | u8 hpf_cut_of_freq; |
| 2923 | |
| 2924 | hpf_delayed_work = to_delayed_work(work); |
| 2925 | hpf_work = container_of(hpf_delayed_work, struct hpf_work, dwork); |
| 2926 | tabla = hpf_work->tabla; |
| 2927 | codec = hpf_work->tabla->codec; |
| 2928 | hpf_cut_of_freq = hpf_work->tx_hpf_cut_of_freq; |
| 2929 | |
| 2930 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + |
| 2931 | (hpf_work->decimator - 1) * 8; |
| 2932 | |
| 2933 | pr_debug("%s(): decimator %u hpf_cut_of_freq 0x%x\n", __func__, |
| 2934 | hpf_work->decimator, (unsigned int)hpf_cut_of_freq); |
| 2935 | |
| 2936 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, hpf_cut_of_freq << 4); |
| 2937 | } |
| 2938 | |
| 2939 | #define TX_MUX_CTL_CUT_OFF_FREQ_MASK 0x30 |
| 2940 | #define CF_MIN_3DB_4HZ 0x0 |
| 2941 | #define CF_MIN_3DB_75HZ 0x1 |
| 2942 | #define CF_MIN_3DB_150HZ 0x2 |
| 2943 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2944 | static int tabla_codec_enable_dec(struct snd_soc_dapm_widget *w, |
| 2945 | struct snd_kcontrol *kcontrol, int event) |
| 2946 | { |
| 2947 | struct snd_soc_codec *codec = w->codec; |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2948 | unsigned int decimator; |
| 2949 | char *dec_name = NULL; |
| 2950 | char *widget_name = NULL; |
| 2951 | char *temp; |
| 2952 | int ret = 0; |
| 2953 | u16 dec_reset_reg, tx_vol_ctl_reg, tx_mux_ctl_reg; |
| 2954 | u8 dec_hpf_cut_of_freq; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2955 | int offset; |
| 2956 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2957 | |
| 2958 | pr_debug("%s %d\n", __func__, event); |
| 2959 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2960 | widget_name = kstrndup(w->name, 15, GFP_KERNEL); |
| 2961 | if (!widget_name) |
| 2962 | return -ENOMEM; |
| 2963 | temp = widget_name; |
| 2964 | |
| 2965 | dec_name = strsep(&widget_name, " "); |
| 2966 | widget_name = temp; |
| 2967 | if (!dec_name) { |
| 2968 | pr_err("%s: Invalid decimator = %s\n", __func__, w->name); |
| 2969 | ret = -EINVAL; |
| 2970 | goto out; |
| 2971 | } |
| 2972 | |
| 2973 | ret = kstrtouint(strpbrk(dec_name, "123456789"), 10, &decimator); |
| 2974 | if (ret < 0) { |
| 2975 | pr_err("%s: Invalid decimator = %s\n", __func__, dec_name); |
| 2976 | ret = -EINVAL; |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
| 2980 | pr_debug("%s(): widget = %s dec_name = %s decimator = %u\n", __func__, |
| 2981 | w->name, dec_name, decimator); |
| 2982 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2983 | if (w->reg == TABLA_A_CDC_CLK_TX_CLK_EN_B1_CTL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2984 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B1_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2985 | offset = 0; |
| 2986 | } 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] | 2987 | dec_reset_reg = TABLA_A_CDC_CLK_TX_RESET_B2_CTL; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 2988 | offset = 8; |
| 2989 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2990 | pr_err("%s: Error, incorrect dec\n", __func__); |
| 2991 | return -EINVAL; |
| 2992 | } |
| 2993 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2994 | tx_vol_ctl_reg = TABLA_A_CDC_TX1_VOL_CTL_CFG + 8 * (decimator -1); |
| 2995 | tx_mux_ctl_reg = TABLA_A_CDC_TX1_MUX_CTL + 8 * (decimator - 1); |
| 2996 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2997 | switch (event) { |
| 2998 | case SND_SOC_DAPM_PRE_PMU: |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 2999 | |
| 3000 | // Enableable TX digital mute */ |
| 3001 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3002 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3003 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, |
| 3004 | 1 << w->shift); |
| 3005 | snd_soc_update_bits(codec, dec_reset_reg, 1 << w->shift, 0x0); |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3006 | |
| 3007 | dec_hpf_cut_of_freq = snd_soc_read(codec, tx_mux_ctl_reg); |
| 3008 | |
| 3009 | dec_hpf_cut_of_freq = (dec_hpf_cut_of_freq & 0x30) >> 4; |
| 3010 | |
| 3011 | tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq = |
| 3012 | dec_hpf_cut_of_freq; |
| 3013 | |
| 3014 | if ((dec_hpf_cut_of_freq != CF_MIN_3DB_150HZ)) { |
| 3015 | |
| 3016 | /* set cut of freq to CF_MIN_3DB_150HZ (0x1); */ |
| 3017 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3018 | CF_MIN_3DB_150HZ << 4); |
| 3019 | } |
| 3020 | |
| 3021 | /* enable HPF */ |
| 3022 | snd_soc_update_bits(codec, tx_mux_ctl_reg , 0x08, 0x00); |
| 3023 | |
| 3024 | break; |
| 3025 | |
| 3026 | case SND_SOC_DAPM_POST_PMU: |
| 3027 | |
| 3028 | /* Disable TX digital mute */ |
| 3029 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x00); |
| 3030 | |
| 3031 | if (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq != |
| 3032 | CF_MIN_3DB_150HZ) { |
| 3033 | |
| 3034 | schedule_delayed_work(&tx_hpf_work[decimator - 1].dwork, |
| 3035 | msecs_to_jiffies(300)); |
| 3036 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3037 | /* apply the digital gain after the decimator is enabled*/ |
| 3038 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 3039 | snd_soc_write(codec, |
| 3040 | tx_digital_gain_reg[w->shift + offset], |
| 3041 | snd_soc_read(codec, |
| 3042 | tx_digital_gain_reg[w->shift + offset]) |
| 3043 | ); |
| 3044 | |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3045 | break; |
| 3046 | |
| 3047 | case SND_SOC_DAPM_PRE_PMD: |
| 3048 | |
| 3049 | snd_soc_update_bits(codec, tx_vol_ctl_reg, 0x01, 0x01); |
| 3050 | cancel_delayed_work_sync(&tx_hpf_work[decimator - 1].dwork); |
| 3051 | break; |
| 3052 | |
| 3053 | case SND_SOC_DAPM_POST_PMD: |
| 3054 | |
| 3055 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x08, 0x08); |
| 3056 | snd_soc_update_bits(codec, tx_mux_ctl_reg, 0x30, |
| 3057 | (tx_hpf_work[decimator - 1].tx_hpf_cut_of_freq) << 4); |
| 3058 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3059 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3060 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 3061 | out: |
| 3062 | kfree(widget_name); |
| 3063 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3066 | static int tabla_codec_reset_interpolator(struct snd_soc_dapm_widget *w, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3067 | struct snd_kcontrol *kcontrol, int event) |
| 3068 | { |
| 3069 | struct snd_soc_codec *codec = w->codec; |
| 3070 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3071 | pr_debug("%s %d %s\n", __func__, event, w->name); |
| 3072 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3073 | switch (event) { |
| 3074 | case SND_SOC_DAPM_PRE_PMU: |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3075 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3076 | 1 << w->shift, 1 << w->shift); |
| 3077 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_RESET_CTL, |
| 3078 | 1 << w->shift, 0x0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3079 | break; |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3080 | case SND_SOC_DAPM_POST_PMU: |
| 3081 | /* apply the digital gain after the interpolator is enabled*/ |
| 3082 | if ((w->shift) < ARRAY_SIZE(rx_digital_gain_reg)) |
| 3083 | snd_soc_write(codec, |
| 3084 | rx_digital_gain_reg[w->shift], |
| 3085 | snd_soc_read(codec, |
| 3086 | rx_digital_gain_reg[w->shift]) |
| 3087 | ); |
| 3088 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3089 | } |
| 3090 | return 0; |
| 3091 | } |
| 3092 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3093 | static int tabla_codec_enable_ldo_h(struct snd_soc_dapm_widget *w, |
| 3094 | struct snd_kcontrol *kcontrol, int event) |
| 3095 | { |
| 3096 | switch (event) { |
| 3097 | case SND_SOC_DAPM_POST_PMU: |
| 3098 | case SND_SOC_DAPM_POST_PMD: |
| 3099 | usleep_range(1000, 1000); |
| 3100 | break; |
| 3101 | } |
| 3102 | return 0; |
| 3103 | } |
| 3104 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3105 | static int tabla_codec_enable_rx_bias(struct snd_soc_dapm_widget *w, |
| 3106 | struct snd_kcontrol *kcontrol, int event) |
| 3107 | { |
| 3108 | struct snd_soc_codec *codec = w->codec; |
| 3109 | |
| 3110 | pr_debug("%s %d\n", __func__, event); |
| 3111 | |
| 3112 | switch (event) { |
| 3113 | case SND_SOC_DAPM_PRE_PMU: |
| 3114 | tabla_enable_rx_bias(codec, 1); |
| 3115 | break; |
| 3116 | case SND_SOC_DAPM_POST_PMD: |
| 3117 | tabla_enable_rx_bias(codec, 0); |
| 3118 | break; |
| 3119 | } |
| 3120 | return 0; |
| 3121 | } |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3122 | static int tabla_hphr_dac_event(struct snd_soc_dapm_widget *w, |
| 3123 | struct snd_kcontrol *kcontrol, int event) |
| 3124 | { |
| 3125 | struct snd_soc_codec *codec = w->codec; |
| 3126 | |
| 3127 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3128 | |
| 3129 | switch (event) { |
| 3130 | case SND_SOC_DAPM_PRE_PMU: |
| 3131 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3132 | break; |
| 3133 | case SND_SOC_DAPM_POST_PMD: |
| 3134 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3135 | break; |
| 3136 | } |
| 3137 | return 0; |
| 3138 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3139 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3140 | static void tabla_snd_soc_jack_report(struct tabla_priv *tabla, |
| 3141 | struct snd_soc_jack *jack, int status, |
| 3142 | int mask) |
| 3143 | { |
| 3144 | /* XXX: wake_lock_timeout()? */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3145 | snd_soc_jack_report_no_dapm(jack, status, mask); |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3146 | } |
| 3147 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3148 | static void hphocp_off_report(struct tabla_priv *tabla, |
| 3149 | u32 jack_status, int irq) |
| 3150 | { |
| 3151 | struct snd_soc_codec *codec; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3152 | if (!tabla) { |
| 3153 | pr_err("%s: Bad tabla private data\n", __func__); |
| 3154 | return; |
| 3155 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3156 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3157 | pr_debug("%s: clear ocp status %x\n", __func__, jack_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3158 | codec = tabla->codec; |
| 3159 | if (tabla->hph_status & jack_status) { |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3160 | tabla->hph_status &= ~jack_status; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3161 | if (tabla->mbhc_cfg.headset_jack) |
| 3162 | tabla_snd_soc_jack_report(tabla, |
| 3163 | tabla->mbhc_cfg.headset_jack, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 3164 | tabla->hph_status, |
| 3165 | TABLA_JACK_MASK); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3166 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x00); |
| 3167 | 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] | 3168 | /* reset retry counter as PA is turned off signifying |
| 3169 | * start of new OCP detection session |
| 3170 | */ |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3171 | if (WCD9XXX_IRQ_HPH_PA_OCPL_FAULT) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 3172 | tabla->hphlocp_cnt = 0; |
| 3173 | else |
| 3174 | tabla->hphrocp_cnt = 0; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3175 | wcd9xxx_enable_irq(codec->control_data, irq); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | static void hphlocp_off_report(struct work_struct *work) |
| 3180 | { |
| 3181 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3182 | hphlocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3183 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
| 3184 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | static void hphrocp_off_report(struct work_struct *work) |
| 3188 | { |
| 3189 | struct tabla_priv *tabla = container_of(work, struct tabla_priv, |
| 3190 | hphrocp_work); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 3191 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
| 3192 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3193 | } |
| 3194 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3195 | static int tabla_hph_pa_event(struct snd_soc_dapm_widget *w, |
| 3196 | struct snd_kcontrol *kcontrol, int event) |
| 3197 | { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3198 | struct snd_soc_codec *codec = w->codec; |
| 3199 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 3200 | u8 mbhc_micb_ctl_val; |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3201 | pr_debug("%s: event = %d\n", __func__, event); |
| 3202 | |
| 3203 | switch (event) { |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3204 | case SND_SOC_DAPM_PRE_PMU: |
| 3205 | mbhc_micb_ctl_val = snd_soc_read(codec, |
| 3206 | tabla->mbhc_bias_regs.ctl_reg); |
| 3207 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3208 | if (!(mbhc_micb_ctl_val & 0x80)) { |
| 3209 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3210 | tabla_codec_switch_micbias(codec, 1); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3211 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 3212 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3213 | break; |
| 3214 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3215 | case SND_SOC_DAPM_POST_PMD: |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 3216 | /* schedule work is required because at the time HPH PA DAPM |
| 3217 | * event callback is called by DAPM framework, CODEC dapm mutex |
| 3218 | * would have been locked while snd_soc_jack_report also |
| 3219 | * attempts to acquire same lock. |
| 3220 | */ |
Joonwoo Park | a944445 | 2011-12-08 18:48:27 -0800 | [diff] [blame] | 3221 | if (w->shift == 5) { |
| 3222 | clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 3223 | &tabla->hph_pa_dac_state); |
| 3224 | clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 3225 | &tabla->hph_pa_dac_state); |
| 3226 | if (tabla->hph_status & SND_JACK_OC_HPHL) |
| 3227 | schedule_work(&tabla->hphlocp_work); |
| 3228 | } else if (w->shift == 4) { |
| 3229 | clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 3230 | &tabla->hph_pa_dac_state); |
| 3231 | clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 3232 | &tabla->hph_pa_dac_state); |
| 3233 | if (tabla->hph_status & SND_JACK_OC_HPHR) |
| 3234 | schedule_work(&tabla->hphrocp_work); |
| 3235 | } |
| 3236 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3237 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 3238 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3239 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 3240 | |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3241 | pr_debug("%s: sleep 10 ms after %s PA disable.\n", __func__, |
| 3242 | w->name); |
| 3243 | usleep_range(10000, 10000); |
Kiran Kandi | bf0b1ff | 2011-09-15 13:55:21 -0700 | [diff] [blame] | 3244 | break; |
| 3245 | } |
| 3246 | return 0; |
| 3247 | } |
| 3248 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3249 | static void tabla_get_mbhc_micbias_regs(struct snd_soc_codec *codec, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3250 | struct mbhc_micbias_regs *micbias_regs) |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3251 | { |
| 3252 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3253 | unsigned int cfilt; |
| 3254 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 3255 | switch (tabla->mbhc_cfg.micbias) { |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3256 | case TABLA_MICBIAS1: |
| 3257 | cfilt = tabla->pdata->micbias.bias1_cfilt_sel; |
| 3258 | micbias_regs->mbhc_reg = TABLA_A_MICB_1_MBHC; |
| 3259 | micbias_regs->int_rbias = TABLA_A_MICB_1_INT_RBIAS; |
| 3260 | micbias_regs->ctl_reg = TABLA_A_MICB_1_CTL; |
| 3261 | break; |
| 3262 | case TABLA_MICBIAS2: |
| 3263 | cfilt = tabla->pdata->micbias.bias2_cfilt_sel; |
| 3264 | micbias_regs->mbhc_reg = TABLA_A_MICB_2_MBHC; |
| 3265 | micbias_regs->int_rbias = TABLA_A_MICB_2_INT_RBIAS; |
| 3266 | micbias_regs->ctl_reg = TABLA_A_MICB_2_CTL; |
| 3267 | break; |
| 3268 | case TABLA_MICBIAS3: |
| 3269 | cfilt = tabla->pdata->micbias.bias3_cfilt_sel; |
| 3270 | micbias_regs->mbhc_reg = TABLA_A_MICB_3_MBHC; |
| 3271 | micbias_regs->int_rbias = TABLA_A_MICB_3_INT_RBIAS; |
| 3272 | micbias_regs->ctl_reg = TABLA_A_MICB_3_CTL; |
| 3273 | break; |
| 3274 | case TABLA_MICBIAS4: |
| 3275 | cfilt = tabla->pdata->micbias.bias4_cfilt_sel; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3276 | micbias_regs->mbhc_reg = tabla->reg_addr.micb_4_mbhc; |
| 3277 | micbias_regs->int_rbias = tabla->reg_addr.micb_4_int_rbias; |
| 3278 | micbias_regs->ctl_reg = tabla->reg_addr.micb_4_ctl; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3279 | break; |
| 3280 | default: |
| 3281 | /* Should never reach here */ |
| 3282 | pr_err("%s: Invalid MIC BIAS for MBHC\n", __func__); |
Jordan Crouse | 239d841 | 2011-11-23 11:47:02 -0700 | [diff] [blame] | 3283 | return; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 3286 | micbias_regs->cfilt_sel = cfilt; |
| 3287 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3288 | switch (cfilt) { |
| 3289 | case TABLA_CFILT1_SEL: |
| 3290 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_1_VAL; |
| 3291 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_1_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3292 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt1_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3293 | break; |
| 3294 | case TABLA_CFILT2_SEL: |
| 3295 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_2_VAL; |
| 3296 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_2_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3297 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt2_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3298 | break; |
| 3299 | case TABLA_CFILT3_SEL: |
| 3300 | micbias_regs->cfilt_val = TABLA_A_MICB_CFILT_3_VAL; |
| 3301 | micbias_regs->cfilt_ctl = TABLA_A_MICB_CFILT_3_CTL; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 3302 | tabla->mbhc_data.micb_mv = tabla->pdata->micbias.cfilt3_mv; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3303 | break; |
| 3304 | } |
| 3305 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3306 | static const struct snd_soc_dapm_widget tabla_dapm_i2s_widgets[] = { |
| 3307 | SND_SOC_DAPM_SUPPLY("RX_I2S_CLK", TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 3308 | 4, 0, NULL, 0), |
| 3309 | SND_SOC_DAPM_SUPPLY("TX_I2S_CLK", TABLA_A_CDC_CLK_TX_I2S_CTL, 4, |
| 3310 | 0, NULL, 0), |
| 3311 | }; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 3312 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3313 | static int tabla_lineout_dac_event(struct snd_soc_dapm_widget *w, |
| 3314 | struct snd_kcontrol *kcontrol, int event) |
| 3315 | { |
| 3316 | struct snd_soc_codec *codec = w->codec; |
| 3317 | |
| 3318 | pr_debug("%s %s %d\n", __func__, w->name, event); |
| 3319 | |
| 3320 | switch (event) { |
| 3321 | case SND_SOC_DAPM_PRE_PMU: |
| 3322 | snd_soc_update_bits(codec, w->reg, 0x40, 0x40); |
| 3323 | break; |
| 3324 | |
| 3325 | case SND_SOC_DAPM_POST_PMD: |
| 3326 | snd_soc_update_bits(codec, w->reg, 0x40, 0x00); |
| 3327 | break; |
| 3328 | } |
| 3329 | return 0; |
| 3330 | } |
| 3331 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 3332 | static int tabla_ear_pa_event(struct snd_soc_dapm_widget *w, |
| 3333 | struct snd_kcontrol *kcontrol, int event) |
| 3334 | { |
| 3335 | struct snd_soc_codec *codec = w->codec; |
| 3336 | |
| 3337 | pr_debug("%s %d\n", __func__, event); |
| 3338 | |
| 3339 | switch (event) { |
| 3340 | case SND_SOC_DAPM_PRE_PMU: |
| 3341 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x50, 0x50); |
| 3342 | break; |
| 3343 | |
| 3344 | case SND_SOC_DAPM_PRE_PMD: |
| 3345 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x10, 0x00); |
| 3346 | snd_soc_update_bits(codec, TABLA_A_RX_EAR_EN, 0x40, 0x00); |
| 3347 | break; |
| 3348 | } |
| 3349 | return 0; |
| 3350 | } |
| 3351 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3352 | static const struct snd_soc_dapm_widget tabla_1_x_dapm_widgets[] = { |
| 3353 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_1_A_MICB_4_CTL, 7, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3354 | 0, tabla_codec_enable_micbias, |
| 3355 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3356 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3357 | }; |
| 3358 | |
| 3359 | static const struct snd_soc_dapm_widget tabla_2_higher_dapm_widgets[] = { |
| 3360 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS4 External", TABLA_2_A_MICB_4_CTL, 7, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3361 | 0, tabla_codec_enable_micbias, |
| 3362 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3363 | SND_SOC_DAPM_POST_PMD), |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3364 | }; |
| 3365 | |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3366 | static const struct snd_soc_dapm_route audio_i2s_map[] = { |
| 3367 | {"RX_I2S_CLK", NULL, "CDC_CONN"}, |
| 3368 | {"SLIM RX1", NULL, "RX_I2S_CLK"}, |
| 3369 | {"SLIM RX2", NULL, "RX_I2S_CLK"}, |
| 3370 | {"SLIM RX3", NULL, "RX_I2S_CLK"}, |
| 3371 | {"SLIM RX4", NULL, "RX_I2S_CLK"}, |
| 3372 | |
| 3373 | {"SLIM TX7", NULL, "TX_I2S_CLK"}, |
| 3374 | {"SLIM TX8", NULL, "TX_I2S_CLK"}, |
| 3375 | {"SLIM TX9", NULL, "TX_I2S_CLK"}, |
| 3376 | {"SLIM TX10", NULL, "TX_I2S_CLK"}, |
| 3377 | }; |
| 3378 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3379 | static const struct snd_soc_dapm_route audio_map[] = { |
| 3380 | /* SLIMBUS Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3381 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3382 | {"AIF1 CAP", NULL, "AIF1_CAP Mixer"}, |
| 3383 | {"AIF2 CAP", NULL, "AIF2_CAP Mixer"}, |
| 3384 | {"AIF3 CAP", NULL, "AIF3_CAP Mixer"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3385 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3386 | /* SLIM_MIXER("AIF1_CAP Mixer"),*/ |
| 3387 | {"AIF1_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3388 | {"AIF1_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3389 | {"AIF1_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3390 | {"AIF1_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3391 | {"AIF1_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3392 | {"AIF1_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3393 | {"AIF1_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3394 | {"AIF1_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3395 | {"AIF1_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3396 | {"AIF1_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3397 | /* SLIM_MIXER("AIF2_CAP Mixer"),*/ |
| 3398 | {"AIF2_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3399 | {"AIF2_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3400 | {"AIF2_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3401 | {"AIF2_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3402 | {"AIF2_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3403 | {"AIF2_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3404 | {"AIF2_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3405 | {"AIF2_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3406 | {"AIF2_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3407 | {"AIF2_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3408 | /* SLIM_MIXER("AIF3_CAP Mixer"),*/ |
| 3409 | {"AIF3_CAP Mixer", "SLIM TX1", "SLIM TX1 MUX"}, |
| 3410 | {"AIF3_CAP Mixer", "SLIM TX2", "SLIM TX2 MUX"}, |
| 3411 | {"AIF3_CAP Mixer", "SLIM TX3", "SLIM TX3 MUX"}, |
| 3412 | {"AIF3_CAP Mixer", "SLIM TX4", "SLIM TX4 MUX"}, |
| 3413 | {"AIF3_CAP Mixer", "SLIM TX5", "SLIM TX5 MUX"}, |
| 3414 | {"AIF3_CAP Mixer", "SLIM TX6", "SLIM TX6 MUX"}, |
| 3415 | {"AIF3_CAP Mixer", "SLIM TX7", "SLIM TX7 MUX"}, |
| 3416 | {"AIF3_CAP Mixer", "SLIM TX8", "SLIM TX8 MUX"}, |
| 3417 | {"AIF3_CAP Mixer", "SLIM TX9", "SLIM TX9 MUX"}, |
| 3418 | {"AIF3_CAP Mixer", "SLIM TX10", "SLIM TX10 MUX"}, |
| 3419 | |
| 3420 | {"SLIM TX1 MUX", "DEC1", "DEC1 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3421 | {"SLIM TX2 MUX", "DEC2", "DEC2 MUX"}, |
| 3422 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3423 | {"SLIM TX3 MUX", "DEC3", "DEC3 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3424 | {"SLIM TX3 MUX", "RMIX1", "RX1 MIX1"}, |
| 3425 | {"SLIM TX3 MUX", "RMIX2", "RX2 MIX1"}, |
| 3426 | {"SLIM TX3 MUX", "RMIX3", "RX3 MIX1"}, |
| 3427 | {"SLIM TX3 MUX", "RMIX4", "RX4 MIX1"}, |
| 3428 | {"SLIM TX3 MUX", "RMIX5", "RX5 MIX1"}, |
| 3429 | {"SLIM TX3 MUX", "RMIX6", "RX6 MIX1"}, |
| 3430 | {"SLIM TX3 MUX", "RMIX7", "RX7 MIX1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3431 | |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3432 | {"SLIM TX4 MUX", "DEC4", "DEC4 MUX"}, |
| 3433 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3434 | {"SLIM TX5 MUX", "DEC5", "DEC5 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3435 | {"SLIM TX5 MUX", "RMIX1", "RX1 MIX1"}, |
| 3436 | {"SLIM TX5 MUX", "RMIX2", "RX2 MIX1"}, |
| 3437 | {"SLIM TX5 MUX", "RMIX3", "RX3 MIX1"}, |
| 3438 | {"SLIM TX5 MUX", "RMIX4", "RX4 MIX1"}, |
| 3439 | {"SLIM TX5 MUX", "RMIX5", "RX5 MIX1"}, |
| 3440 | {"SLIM TX5 MUX", "RMIX6", "RX6 MIX1"}, |
| 3441 | {"SLIM TX5 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3442 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3443 | {"SLIM TX6 MUX", "DEC6", "DEC6 MUX"}, |
| 3444 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3445 | {"SLIM TX7 MUX", "DEC1", "DEC1 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3446 | {"SLIM TX7 MUX", "DEC2", "DEC2 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3447 | {"SLIM TX7 MUX", "DEC3", "DEC3 MUX"}, |
| 3448 | {"SLIM TX7 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3449 | {"SLIM TX7 MUX", "DEC5", "DEC5 MUX"}, |
| 3450 | {"SLIM TX7 MUX", "DEC6", "DEC6 MUX"}, |
Bhalchandra Gajare | 0d77e1b | 2011-07-08 10:54:14 -0700 | [diff] [blame] | 3451 | {"SLIM TX7 MUX", "DEC7", "DEC7 MUX"}, |
| 3452 | {"SLIM TX7 MUX", "DEC8", "DEC8 MUX"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3453 | {"SLIM TX7 MUX", "DEC9", "DEC9 MUX"}, |
| 3454 | {"SLIM TX7 MUX", "DEC10", "DEC10 MUX"}, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 3455 | {"SLIM TX7 MUX", "RMIX1", "RX1 MIX1"}, |
| 3456 | {"SLIM TX7 MUX", "RMIX2", "RX2 MIX1"}, |
| 3457 | {"SLIM TX7 MUX", "RMIX3", "RX3 MIX1"}, |
| 3458 | {"SLIM TX7 MUX", "RMIX4", "RX4 MIX1"}, |
| 3459 | {"SLIM TX7 MUX", "RMIX5", "RX5 MIX1"}, |
| 3460 | {"SLIM TX7 MUX", "RMIX6", "RX6 MIX1"}, |
| 3461 | {"SLIM TX7 MUX", "RMIX7", "RX7 MIX1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3462 | |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3463 | {"SLIM TX8 MUX", "DEC1", "DEC1 MUX"}, |
| 3464 | {"SLIM TX8 MUX", "DEC2", "DEC2 MUX"}, |
| 3465 | {"SLIM TX8 MUX", "DEC3", "DEC3 MUX"}, |
Bhalchandra Gajare | 9ec83cd | 2011-09-23 17:25:07 -0700 | [diff] [blame] | 3466 | {"SLIM TX8 MUX", "DEC4", "DEC4 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3467 | {"SLIM TX8 MUX", "DEC5", "DEC5 MUX"}, |
| 3468 | {"SLIM TX8 MUX", "DEC6", "DEC6 MUX"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3469 | {"SLIM TX8 MUX", "DEC7", "DEC7 MUX"}, |
| 3470 | {"SLIM TX8 MUX", "DEC8", "DEC8 MUX"}, |
| 3471 | {"SLIM TX8 MUX", "DEC9", "DEC9 MUX"}, |
| 3472 | {"SLIM TX8 MUX", "DEC10", "DEC10 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3473 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3474 | {"SLIM TX9 MUX", "DEC1", "DEC1 MUX"}, |
| 3475 | {"SLIM TX9 MUX", "DEC2", "DEC2 MUX"}, |
| 3476 | {"SLIM TX9 MUX", "DEC3", "DEC3 MUX"}, |
| 3477 | {"SLIM TX9 MUX", "DEC4", "DEC4 MUX"}, |
| 3478 | {"SLIM TX9 MUX", "DEC5", "DEC5 MUX"}, |
| 3479 | {"SLIM TX9 MUX", "DEC6", "DEC6 MUX"}, |
| 3480 | {"SLIM TX9 MUX", "DEC7", "DEC7 MUX"}, |
| 3481 | {"SLIM TX9 MUX", "DEC8", "DEC8 MUX"}, |
| 3482 | {"SLIM TX9 MUX", "DEC9", "DEC9 MUX"}, |
| 3483 | {"SLIM TX9 MUX", "DEC10", "DEC10 MUX"}, |
| 3484 | |
Kiran Kandi | 3426e51 | 2011-09-13 22:50:10 -0700 | [diff] [blame] | 3485 | {"SLIM TX10 MUX", "DEC1", "DEC1 MUX"}, |
| 3486 | {"SLIM TX10 MUX", "DEC2", "DEC2 MUX"}, |
| 3487 | {"SLIM TX10 MUX", "DEC3", "DEC3 MUX"}, |
| 3488 | {"SLIM TX10 MUX", "DEC4", "DEC4 MUX"}, |
| 3489 | {"SLIM TX10 MUX", "DEC5", "DEC5 MUX"}, |
| 3490 | {"SLIM TX10 MUX", "DEC6", "DEC6 MUX"}, |
| 3491 | {"SLIM TX10 MUX", "DEC7", "DEC7 MUX"}, |
| 3492 | {"SLIM TX10 MUX", "DEC8", "DEC8 MUX"}, |
| 3493 | {"SLIM TX10 MUX", "DEC9", "DEC9 MUX"}, |
| 3494 | {"SLIM TX10 MUX", "DEC10", "DEC10 MUX"}, |
| 3495 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3496 | /* Earpiece (RX MIX1) */ |
| 3497 | {"EAR", NULL, "EAR PA"}, |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3498 | {"EAR PA", NULL, "EAR_PA_MIXER"}, |
| 3499 | {"EAR_PA_MIXER", NULL, "DAC1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3500 | {"DAC1", NULL, "CP"}, |
| 3501 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3502 | {"ANC1 FB MUX", "EAR_HPH_L", "RX1 MIX2"}, |
| 3503 | {"ANC1 FB MUX", "EAR_LINE_1", "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3504 | {"ANC", NULL, "ANC1 FB MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3505 | |
| 3506 | /* Headset (RX MIX1 and RX MIX2) */ |
| 3507 | {"HEADPHONE", NULL, "HPHL"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3508 | {"HEADPHONE", NULL, "HPHR"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3509 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3510 | {"HPHL", NULL, "HPHL_PA_MIXER"}, |
| 3511 | {"HPHL_PA_MIXER", NULL, "HPHL DAC"}, |
| 3512 | |
| 3513 | {"HPHR", NULL, "HPHR_PA_MIXER"}, |
| 3514 | {"HPHR_PA_MIXER", NULL, "HPHR DAC"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3515 | |
| 3516 | {"HPHL DAC", NULL, "CP"}, |
| 3517 | {"HPHR DAC", NULL, "CP"}, |
| 3518 | |
| 3519 | {"ANC", NULL, "ANC1 MUX"}, |
| 3520 | {"ANC", NULL, "ANC2 MUX"}, |
| 3521 | {"ANC1 MUX", "ADC1", "ADC1"}, |
| 3522 | {"ANC1 MUX", "ADC2", "ADC2"}, |
| 3523 | {"ANC1 MUX", "ADC3", "ADC3"}, |
| 3524 | {"ANC1 MUX", "ADC4", "ADC4"}, |
| 3525 | {"ANC2 MUX", "ADC1", "ADC1"}, |
| 3526 | {"ANC2 MUX", "ADC2", "ADC2"}, |
| 3527 | {"ANC2 MUX", "ADC3", "ADC3"}, |
| 3528 | {"ANC2 MUX", "ADC4", "ADC4"}, |
| 3529 | |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3530 | {"ANC", NULL, "CDC_CONN"}, |
| 3531 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3532 | {"DAC1", "Switch", "RX1 CHAIN"}, |
| 3533 | {"HPHL DAC", "Switch", "RX1 CHAIN"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3534 | {"HPHR DAC", NULL, "RX2 CHAIN"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3535 | |
Kiran Kandi | db0a4b0 | 2011-08-23 09:32:09 -0700 | [diff] [blame] | 3536 | {"LINEOUT1", NULL, "LINEOUT1 PA"}, |
| 3537 | {"LINEOUT2", NULL, "LINEOUT2 PA"}, |
| 3538 | {"LINEOUT3", NULL, "LINEOUT3 PA"}, |
| 3539 | {"LINEOUT4", NULL, "LINEOUT4 PA"}, |
| 3540 | {"LINEOUT5", NULL, "LINEOUT5 PA"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3541 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3542 | {"LINEOUT1 PA", NULL, "LINEOUT1_PA_MIXER"}, |
| 3543 | {"LINEOUT1_PA_MIXER", NULL, "LINEOUT1 DAC"}, |
| 3544 | {"LINEOUT2 PA", NULL, "LINEOUT2_PA_MIXER"}, |
| 3545 | {"LINEOUT2_PA_MIXER", NULL, "LINEOUT2 DAC"}, |
| 3546 | {"LINEOUT3 PA", NULL, "LINEOUT3_PA_MIXER"}, |
| 3547 | {"LINEOUT3_PA_MIXER", NULL, "LINEOUT3 DAC"}, |
| 3548 | {"LINEOUT4 PA", NULL, "LINEOUT4_PA_MIXER"}, |
| 3549 | {"LINEOUT4_PA_MIXER", NULL, "LINEOUT4 DAC"}, |
| 3550 | {"LINEOUT5 PA", NULL, "LINEOUT5_PA_MIXER"}, |
| 3551 | {"LINEOUT5_PA_MIXER", NULL, "LINEOUT5 DAC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3552 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3553 | {"LINEOUT1 DAC", NULL, "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3554 | {"LINEOUT5 DAC", NULL, "RX7 MIX1"}, |
| 3555 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3556 | {"RX1 CHAIN", NULL, "RX1 MIX2"}, |
| 3557 | {"RX2 CHAIN", NULL, "RX2 MIX2"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3558 | {"RX1 CHAIN", NULL, "ANC"}, |
| 3559 | {"RX2 CHAIN", NULL, "ANC"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3560 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3561 | {"CP", NULL, "RX_BIAS"}, |
| 3562 | {"LINEOUT1 DAC", NULL, "RX_BIAS"}, |
| 3563 | {"LINEOUT2 DAC", NULL, "RX_BIAS"}, |
| 3564 | {"LINEOUT3 DAC", NULL, "RX_BIAS"}, |
| 3565 | {"LINEOUT4 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3566 | {"LINEOUT5 DAC", NULL, "RX_BIAS"}, |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 3567 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 3568 | {"RX1 MIX1", NULL, "COMP1_CLK"}, |
| 3569 | {"RX2 MIX1", NULL, "COMP1_CLK"}, |
| 3570 | {"RX3 MIX1", NULL, "COMP2_CLK"}, |
| 3571 | {"RX5 MIX1", NULL, "COMP2_CLK"}, |
| 3572 | |
| 3573 | |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3574 | {"RX1 MIX1", NULL, "RX1 MIX1 INP1"}, |
| 3575 | {"RX1 MIX1", NULL, "RX1 MIX1 INP2"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3576 | {"RX1 MIX1", NULL, "RX1 MIX1 INP3"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3577 | {"RX2 MIX1", NULL, "RX2 MIX1 INP1"}, |
| 3578 | {"RX2 MIX1", NULL, "RX2 MIX1 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3579 | {"RX3 MIX1", NULL, "RX3 MIX1 INP1"}, |
| 3580 | {"RX3 MIX1", NULL, "RX3 MIX1 INP2"}, |
| 3581 | {"RX4 MIX1", NULL, "RX4 MIX1 INP1"}, |
| 3582 | {"RX4 MIX1", NULL, "RX4 MIX1 INP2"}, |
| 3583 | {"RX5 MIX1", NULL, "RX5 MIX1 INP1"}, |
| 3584 | {"RX5 MIX1", NULL, "RX5 MIX1 INP2"}, |
| 3585 | {"RX6 MIX1", NULL, "RX6 MIX1 INP1"}, |
| 3586 | {"RX6 MIX1", NULL, "RX6 MIX1 INP2"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3587 | {"RX7 MIX1", NULL, "RX7 MIX1 INP1"}, |
| 3588 | {"RX7 MIX1", NULL, "RX7 MIX1 INP2"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3589 | {"RX1 MIX2", NULL, "RX1 MIX1"}, |
| 3590 | {"RX1 MIX2", NULL, "RX1 MIX2 INP1"}, |
| 3591 | {"RX1 MIX2", NULL, "RX1 MIX2 INP2"}, |
| 3592 | {"RX2 MIX2", NULL, "RX2 MIX1"}, |
| 3593 | {"RX2 MIX2", NULL, "RX2 MIX2 INP1"}, |
| 3594 | {"RX2 MIX2", NULL, "RX2 MIX2 INP2"}, |
| 3595 | {"RX3 MIX2", NULL, "RX3 MIX1"}, |
| 3596 | {"RX3 MIX2", NULL, "RX3 MIX2 INP1"}, |
| 3597 | {"RX3 MIX2", NULL, "RX3 MIX2 INP2"}, |
Bradley Rubin | 74a9b4a | 2011-06-13 15:03:43 -0700 | [diff] [blame] | 3598 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3599 | /* SLIM_MUX("AIF1_PB", "AIF1 PB"),*/ |
| 3600 | {"SLIM RX1 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3601 | {"SLIM RX2 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3602 | {"SLIM RX3 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3603 | {"SLIM RX4 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3604 | {"SLIM RX5 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3605 | {"SLIM RX6 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3606 | {"SLIM RX7 MUX", "AIF1_PB", "AIF1 PB"}, |
| 3607 | /* SLIM_MUX("AIF2_PB", "AIF2 PB"),*/ |
| 3608 | {"SLIM RX1 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3609 | {"SLIM RX2 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3610 | {"SLIM RX3 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3611 | {"SLIM RX4 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3612 | {"SLIM RX5 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3613 | {"SLIM RX6 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3614 | {"SLIM RX7 MUX", "AIF2_PB", "AIF2 PB"}, |
| 3615 | /* SLIM_MUX("AIF3_PB", "AIF3 PB"),*/ |
| 3616 | {"SLIM RX1 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3617 | {"SLIM RX2 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3618 | {"SLIM RX3 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3619 | {"SLIM RX4 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3620 | {"SLIM RX5 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3621 | {"SLIM RX6 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3622 | {"SLIM RX7 MUX", "AIF3_PB", "AIF3 PB"}, |
| 3623 | |
| 3624 | {"SLIM RX1", NULL, "SLIM RX1 MUX"}, |
| 3625 | {"SLIM RX2", NULL, "SLIM RX2 MUX"}, |
| 3626 | {"SLIM RX3", NULL, "SLIM RX3 MUX"}, |
| 3627 | {"SLIM RX4", NULL, "SLIM RX4 MUX"}, |
| 3628 | {"SLIM RX5", NULL, "SLIM RX5 MUX"}, |
| 3629 | {"SLIM RX6", NULL, "SLIM RX6 MUX"}, |
| 3630 | {"SLIM RX7", NULL, "SLIM RX7 MUX"}, |
| 3631 | |
| 3632 | /* Mixer control for output path */ |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3633 | {"RX1 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3634 | {"RX1 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3635 | {"RX1 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3636 | {"RX1 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3637 | {"RX1 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3638 | {"RX1 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3639 | {"RX1 MIX1 INP1", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3640 | {"RX1 MIX1 INP1", "IIR1", "IIR1"}, |
| 3641 | {"RX1 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3642 | {"RX1 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3643 | {"RX1 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3644 | {"RX1 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3645 | {"RX1 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3646 | {"RX1 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3647 | {"RX1 MIX1 INP2", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3648 | {"RX1 MIX1 INP2", "IIR1", "IIR1"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3649 | {"RX1 MIX1 INP3", "RX1", "SLIM RX1"}, |
| 3650 | {"RX1 MIX1 INP3", "RX2", "SLIM RX2"}, |
| 3651 | {"RX1 MIX1 INP3", "RX3", "SLIM RX3"}, |
| 3652 | {"RX1 MIX1 INP3", "RX4", "SLIM RX4"}, |
| 3653 | {"RX1 MIX1 INP3", "RX5", "SLIM RX5"}, |
| 3654 | {"RX1 MIX1 INP3", "RX6", "SLIM RX6"}, |
| 3655 | {"RX1 MIX1 INP3", "RX7", "SLIM RX7"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3656 | {"RX2 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3657 | {"RX2 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3658 | {"RX2 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3659 | {"RX2 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3660 | {"RX2 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3661 | {"RX2 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3662 | {"RX2 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3663 | {"RX2 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3664 | {"RX2 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3665 | {"RX2 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3666 | {"RX2 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3667 | {"RX2 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3668 | {"RX2 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3669 | {"RX2 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3670 | {"RX2 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3671 | {"RX2 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3672 | {"RX3 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3673 | {"RX3 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3674 | {"RX3 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3675 | {"RX3 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3676 | {"RX3 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3677 | {"RX3 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3678 | {"RX3 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3679 | {"RX3 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3680 | {"RX3 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3681 | {"RX3 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3682 | {"RX3 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3683 | {"RX3 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3684 | {"RX3 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3685 | {"RX3 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3686 | {"RX3 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3687 | {"RX3 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3688 | {"RX4 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3689 | {"RX4 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3690 | {"RX4 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3691 | {"RX4 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3692 | {"RX4 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3693 | {"RX4 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3694 | {"RX4 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3695 | {"RX4 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3696 | {"RX4 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3697 | {"RX4 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3698 | {"RX4 MIX1 INP2", "RX3", "SLIM RX3"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3699 | {"RX4 MIX1 INP2", "RX5", "SLIM RX5"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3700 | {"RX4 MIX1 INP2", "RX4", "SLIM RX4"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3701 | {"RX4 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3702 | {"RX4 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3703 | {"RX4 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3704 | {"RX5 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3705 | {"RX5 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3706 | {"RX5 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3707 | {"RX5 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3708 | {"RX5 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3709 | {"RX5 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3710 | {"RX5 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3711 | {"RX5 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3712 | {"RX5 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3713 | {"RX5 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3714 | {"RX5 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3715 | {"RX5 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3716 | {"RX5 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3717 | {"RX5 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3718 | {"RX5 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3719 | {"RX5 MIX1 INP2", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3720 | {"RX6 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3721 | {"RX6 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3722 | {"RX6 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3723 | {"RX6 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3724 | {"RX6 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3725 | {"RX6 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3726 | {"RX6 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3727 | {"RX6 MIX1 INP1", "IIR1", "IIR1"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3728 | {"RX6 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3729 | {"RX6 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3730 | {"RX6 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3731 | {"RX6 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3732 | {"RX6 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3733 | {"RX6 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3734 | {"RX6 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3735 | {"RX6 MIX1 INP2", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3736 | {"RX7 MIX1 INP1", "RX1", "SLIM RX1"}, |
| 3737 | {"RX7 MIX1 INP1", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3738 | {"RX7 MIX1 INP1", "RX3", "SLIM RX3"}, |
| 3739 | {"RX7 MIX1 INP1", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3740 | {"RX7 MIX1 INP1", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3741 | {"RX7 MIX1 INP1", "RX6", "SLIM RX6"}, |
| 3742 | {"RX7 MIX1 INP1", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3743 | {"RX7 MIX1 INP1", "IIR1", "IIR1"}, |
Bhalchandra Gajare | 0a8ad17 | 2011-08-12 13:32:22 -0700 | [diff] [blame] | 3744 | {"RX7 MIX1 INP2", "RX1", "SLIM RX1"}, |
| 3745 | {"RX7 MIX1 INP2", "RX2", "SLIM RX2"}, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 3746 | {"RX7 MIX1 INP2", "RX3", "SLIM RX3"}, |
| 3747 | {"RX7 MIX1 INP2", "RX4", "SLIM RX4"}, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 3748 | {"RX7 MIX1 INP2", "RX5", "SLIM RX5"}, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 3749 | {"RX7 MIX1 INP2", "RX6", "SLIM RX6"}, |
| 3750 | {"RX7 MIX1 INP2", "RX7", "SLIM RX7"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3751 | {"RX7 MIX1 INP2", "IIR1", "IIR1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3752 | {"RX1 MIX2 INP1", "IIR1", "IIR1"}, |
| 3753 | {"RX1 MIX2 INP2", "IIR1", "IIR1"}, |
| 3754 | {"RX2 MIX2 INP1", "IIR1", "IIR1"}, |
| 3755 | {"RX2 MIX2 INP2", "IIR1", "IIR1"}, |
| 3756 | {"RX3 MIX2 INP1", "IIR1", "IIR1"}, |
| 3757 | {"RX3 MIX2 INP2", "IIR1", "IIR1"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3758 | |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3759 | /* Decimator Inputs */ |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3760 | {"DEC1 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3761 | {"DEC1 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3762 | {"DEC1 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3763 | {"DEC2 MUX", "DMIC2", "DMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3764 | {"DEC2 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3765 | {"DEC2 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3766 | {"DEC3 MUX", "DMIC3", "DMIC3"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3767 | {"DEC3 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3768 | {"DEC3 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3769 | {"DEC4 MUX", "DMIC4", "DMIC4"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3770 | {"DEC4 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3771 | {"DEC4 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3772 | {"DEC5 MUX", "DMIC5", "DMIC5"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3773 | {"DEC5 MUX", "ADC2", "ADC2"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3774 | {"DEC5 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | 7cf018e | 2011-08-11 18:58:32 -0700 | [diff] [blame] | 3775 | {"DEC6 MUX", "DMIC6", "DMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3776 | {"DEC6 MUX", "ADC1", "ADC1"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3777 | {"DEC6 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3778 | {"DEC7 MUX", "DMIC1", "DMIC1"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3779 | {"DEC7 MUX", "DMIC6", "DMIC6"}, |
| 3780 | {"DEC7 MUX", "ADC1", "ADC1"}, |
Kiran Kandi | cf45f6a | 2011-07-17 21:10:19 -0700 | [diff] [blame] | 3781 | {"DEC7 MUX", "ADC6", "ADC6"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3782 | {"DEC7 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3783 | {"DEC8 MUX", "DMIC2", "DMIC2"}, |
| 3784 | {"DEC8 MUX", "DMIC5", "DMIC5"}, |
| 3785 | {"DEC8 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3786 | {"DEC8 MUX", "ADC5", "ADC5"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3787 | {"DEC8 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3788 | {"DEC9 MUX", "DMIC4", "DMIC4"}, |
| 3789 | {"DEC9 MUX", "DMIC5", "DMIC5"}, |
| 3790 | {"DEC9 MUX", "ADC2", "ADC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3791 | {"DEC9 MUX", "ADC3", "ADC3"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3792 | {"DEC9 MUX", NULL, "CDC_CONN"}, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 3793 | {"DEC10 MUX", "DMIC3", "DMIC3"}, |
| 3794 | {"DEC10 MUX", "DMIC6", "DMIC6"}, |
| 3795 | {"DEC10 MUX", "ADC1", "ADC1"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3796 | {"DEC10 MUX", "ADC4", "ADC4"}, |
Bradley Rubin | e1d0862 | 2011-07-20 18:01:35 -0700 | [diff] [blame] | 3797 | {"DEC10 MUX", NULL, "CDC_CONN"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3798 | |
| 3799 | /* ADC Connections */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3800 | {"ADC1", NULL, "AMIC1"}, |
| 3801 | {"ADC2", NULL, "AMIC2"}, |
Bhalchandra Gajare | cc6ffa0 | 2011-07-14 18:35:41 -0700 | [diff] [blame] | 3802 | {"ADC3", NULL, "AMIC3"}, |
| 3803 | {"ADC4", NULL, "AMIC4"}, |
| 3804 | {"ADC5", NULL, "AMIC5"}, |
| 3805 | {"ADC6", NULL, "AMIC6"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3806 | |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 3807 | /* AUX PGA Connections */ |
| 3808 | {"HPHL_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3809 | {"HPHL_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3810 | {"HPHL_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3811 | {"HPHL_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3812 | {"HPHR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3813 | {"HPHR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3814 | {"HPHR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3815 | {"HPHR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3816 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3817 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3818 | {"LINEOUT1_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3819 | {"LINEOUT1_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3820 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3821 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3822 | {"LINEOUT2_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3823 | {"LINEOUT2_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3824 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3825 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3826 | {"LINEOUT3_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3827 | {"LINEOUT3_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3828 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3829 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3830 | {"LINEOUT4_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3831 | {"LINEOUT4_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3832 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3833 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3834 | {"LINEOUT5_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3835 | {"LINEOUT5_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3836 | {"EAR_PA_MIXER", "AUX_PGA_L Switch", "AUX_PGA_Left"}, |
| 3837 | {"EAR_PA_MIXER", "AUX_PGA_R Switch", "AUX_PGA_Right"}, |
| 3838 | {"EAR_PA_MIXER", "AUX_PGA_L_INV Switch", "AUX_PGA_Left"}, |
| 3839 | {"EAR_PA_MIXER", "AUX_PGA_R_INV Switch", "AUX_PGA_Right"}, |
| 3840 | {"AUX_PGA_Left", NULL, "AMIC5"}, |
| 3841 | {"AUX_PGA_Right", NULL, "AMIC6"}, |
| 3842 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3843 | {"IIR1", NULL, "IIR1 INP1 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3844 | {"IIR1 INP1 MUX", "DEC1", "DEC1 MUX"}, |
| 3845 | {"IIR1 INP1 MUX", "DEC2", "DEC2 MUX"}, |
| 3846 | {"IIR1 INP1 MUX", "DEC3", "DEC3 MUX"}, |
| 3847 | {"IIR1 INP1 MUX", "DEC4", "DEC4 MUX"}, |
| 3848 | {"IIR1 INP1 MUX", "DEC5", "DEC5 MUX"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3849 | {"IIR1 INP1 MUX", "DEC6", "DEC6 MUX"}, |
Patrick Lai | 16261e8 | 2011-09-30 13:25:52 -0700 | [diff] [blame] | 3850 | {"IIR1 INP1 MUX", "DEC7", "DEC7 MUX"}, |
| 3851 | {"IIR1 INP1 MUX", "DEC8", "DEC8 MUX"}, |
| 3852 | {"IIR1 INP1 MUX", "DEC9", "DEC9 MUX"}, |
| 3853 | {"IIR1 INP1 MUX", "DEC10", "DEC10 MUX"}, |
Bradley Rubin | 229c6a5 | 2011-07-12 16:18:48 -0700 | [diff] [blame] | 3854 | |
| 3855 | {"MIC BIAS1 Internal1", NULL, "LDO_H"}, |
| 3856 | {"MIC BIAS1 Internal2", NULL, "LDO_H"}, |
| 3857 | {"MIC BIAS1 External", NULL, "LDO_H"}, |
| 3858 | {"MIC BIAS2 Internal1", NULL, "LDO_H"}, |
| 3859 | {"MIC BIAS2 Internal2", NULL, "LDO_H"}, |
| 3860 | {"MIC BIAS2 Internal3", NULL, "LDO_H"}, |
| 3861 | {"MIC BIAS2 External", NULL, "LDO_H"}, |
| 3862 | {"MIC BIAS3 Internal1", NULL, "LDO_H"}, |
| 3863 | {"MIC BIAS3 Internal2", NULL, "LDO_H"}, |
| 3864 | {"MIC BIAS3 External", NULL, "LDO_H"}, |
| 3865 | {"MIC BIAS4 External", NULL, "LDO_H"}, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3866 | }; |
| 3867 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3868 | static const struct snd_soc_dapm_route tabla_1_x_lineout_2_to_4_map[] = { |
| 3869 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3870 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3871 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3872 | |
| 3873 | {"LINEOUT2 DAC", NULL, "RX4 DSM MUX"}, |
| 3874 | |
| 3875 | {"LINEOUT3 DAC", NULL, "RX5 MIX1"}, |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3876 | {"LINEOUT3 DAC GROUND", "Switch", "RX3 MIX2"}, |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 3877 | {"LINEOUT3 DAC", NULL, "LINEOUT3 DAC GROUND"}, |
| 3878 | |
| 3879 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3880 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3881 | |
| 3882 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3883 | {"LINEOUT4 DAC GROUND", "Switch", "RX4 DSM MUX"}, |
| 3884 | {"LINEOUT4 DAC", NULL, "LINEOUT4 DAC GROUND"}, |
| 3885 | }; |
| 3886 | |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3887 | |
| 3888 | static const struct snd_soc_dapm_route tabla_2_x_lineout_2_to_4_map[] = { |
| 3889 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 3890 | {"RX4 DSM MUX", "DSM_INV", "RX3 MIX2"}, |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 3891 | {"RX4 DSM MUX", "CIC_OUT", "RX4 MIX1"}, |
| 3892 | |
| 3893 | {"LINEOUT3 DAC", NULL, "RX4 DSM MUX"}, |
| 3894 | |
| 3895 | {"LINEOUT2 DAC", NULL, "RX5 MIX1"}, |
| 3896 | |
| 3897 | {"RX6 DSM MUX", "DSM_INV", "RX5 MIX1"}, |
| 3898 | {"RX6 DSM MUX", "CIC_OUT", "RX6 MIX1"}, |
| 3899 | |
| 3900 | {"LINEOUT4 DAC", NULL, "RX6 DSM MUX"}, |
| 3901 | }; |
| 3902 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3903 | static int tabla_readable(struct snd_soc_codec *ssc, unsigned int reg) |
| 3904 | { |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3905 | int i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3906 | struct wcd9xxx *tabla_core = dev_get_drvdata(ssc->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 3907 | |
| 3908 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 3909 | for (i = 0; i < ARRAY_SIZE(tabla_1_reg_readable); i++) { |
| 3910 | if (tabla_1_reg_readable[i] == reg) |
| 3911 | return 1; |
| 3912 | } |
| 3913 | } else { |
| 3914 | for (i = 0; i < ARRAY_SIZE(tabla_2_reg_readable); i++) { |
| 3915 | if (tabla_2_reg_readable[i] == reg) |
| 3916 | return 1; |
| 3917 | } |
| 3918 | } |
| 3919 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3920 | return tabla_reg_readable[reg]; |
| 3921 | } |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3922 | static bool tabla_is_digital_gain_register(unsigned int reg) |
| 3923 | { |
| 3924 | bool rtn = false; |
| 3925 | switch (reg) { |
| 3926 | case TABLA_A_CDC_RX1_VOL_CTL_B2_CTL: |
| 3927 | case TABLA_A_CDC_RX2_VOL_CTL_B2_CTL: |
| 3928 | case TABLA_A_CDC_RX3_VOL_CTL_B2_CTL: |
| 3929 | case TABLA_A_CDC_RX4_VOL_CTL_B2_CTL: |
| 3930 | case TABLA_A_CDC_RX5_VOL_CTL_B2_CTL: |
| 3931 | case TABLA_A_CDC_RX6_VOL_CTL_B2_CTL: |
| 3932 | case TABLA_A_CDC_RX7_VOL_CTL_B2_CTL: |
| 3933 | case TABLA_A_CDC_TX1_VOL_CTL_GAIN: |
| 3934 | case TABLA_A_CDC_TX2_VOL_CTL_GAIN: |
| 3935 | case TABLA_A_CDC_TX3_VOL_CTL_GAIN: |
| 3936 | case TABLA_A_CDC_TX4_VOL_CTL_GAIN: |
| 3937 | case TABLA_A_CDC_TX5_VOL_CTL_GAIN: |
| 3938 | case TABLA_A_CDC_TX6_VOL_CTL_GAIN: |
| 3939 | case TABLA_A_CDC_TX7_VOL_CTL_GAIN: |
| 3940 | case TABLA_A_CDC_TX8_VOL_CTL_GAIN: |
| 3941 | case TABLA_A_CDC_TX9_VOL_CTL_GAIN: |
| 3942 | case TABLA_A_CDC_TX10_VOL_CTL_GAIN: |
| 3943 | rtn = true; |
| 3944 | break; |
| 3945 | default: |
| 3946 | break; |
| 3947 | } |
| 3948 | return rtn; |
| 3949 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3950 | static int tabla_volatile(struct snd_soc_codec *ssc, unsigned int reg) |
| 3951 | { |
| 3952 | /* Registers lower than 0x100 are top level registers which can be |
| 3953 | * written by the Tabla core driver. |
| 3954 | */ |
| 3955 | |
| 3956 | if ((reg >= TABLA_A_CDC_MBHC_EN_CTL) || (reg < 0x100)) |
| 3957 | return 1; |
| 3958 | |
Ben Romberger | 1f045a7 | 2011-11-04 10:14:57 -0700 | [diff] [blame] | 3959 | /* IIR Coeff registers are not cacheable */ |
| 3960 | if ((reg >= TABLA_A_CDC_IIR1_COEF_B1_CTL) && |
| 3961 | (reg <= TABLA_A_CDC_IIR2_COEF_B5_CTL)) |
| 3962 | return 1; |
| 3963 | |
Kuirong Wang | e9c8a22 | 2012-03-28 16:24:09 -0700 | [diff] [blame] | 3964 | /* Digital gain register is not cacheable so we have to write |
| 3965 | * the setting even it is the same |
| 3966 | */ |
| 3967 | if (tabla_is_digital_gain_register(reg)) |
| 3968 | return 1; |
| 3969 | |
Joonwoo Park | ab2c587 | 2012-05-03 15:16:02 -0700 | [diff] [blame] | 3970 | /* HPH status registers */ |
| 3971 | if (reg == TABLA_A_RX_HPH_L_STATUS || reg == TABLA_A_RX_HPH_R_STATUS) |
| 3972 | return 1; |
| 3973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3974 | return 0; |
| 3975 | } |
| 3976 | |
| 3977 | #define TABLA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE) |
| 3978 | static int tabla_write(struct snd_soc_codec *codec, unsigned int reg, |
| 3979 | unsigned int value) |
| 3980 | { |
| 3981 | int ret; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 3982 | |
| 3983 | if (reg == SND_SOC_NOPM) |
| 3984 | return 0; |
| 3985 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3986 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 3987 | |
| 3988 | if (!tabla_volatile(codec, reg)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3989 | ret = snd_soc_cache_write(codec, reg, value); |
| 3990 | if (ret != 0) |
| 3991 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 3992 | reg, ret); |
| 3993 | } |
| 3994 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 3995 | return wcd9xxx_reg_write(codec->control_data, reg, value); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3996 | } |
| 3997 | static unsigned int tabla_read(struct snd_soc_codec *codec, |
| 3998 | unsigned int reg) |
| 3999 | { |
| 4000 | unsigned int val; |
| 4001 | int ret; |
| 4002 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4003 | if (reg == SND_SOC_NOPM) |
| 4004 | return 0; |
| 4005 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4006 | BUG_ON(reg > TABLA_MAX_REGISTER); |
| 4007 | |
| 4008 | if (!tabla_volatile(codec, reg) && tabla_readable(codec, reg) && |
| 4009 | reg < codec->driver->reg_cache_size) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4010 | ret = snd_soc_cache_read(codec, reg, &val); |
| 4011 | if (ret >= 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4012 | return val; |
| 4013 | } else |
| 4014 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 4015 | reg, ret); |
| 4016 | } |
| 4017 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4018 | val = wcd9xxx_reg_read(codec->control_data, reg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4019 | return val; |
| 4020 | } |
| 4021 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4022 | static s16 tabla_get_current_v_ins(struct tabla_priv *tabla, bool hu) |
| 4023 | { |
| 4024 | s16 v_ins; |
| 4025 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4026 | tabla->mbhc_micbias_switched) |
| 4027 | v_ins = hu ? (s16)tabla->mbhc_data.adj_v_ins_hu : |
| 4028 | (s16)tabla->mbhc_data.adj_v_ins_h; |
| 4029 | else |
| 4030 | v_ins = hu ? (s16)tabla->mbhc_data.v_ins_hu : |
| 4031 | (s16)tabla->mbhc_data.v_ins_h; |
| 4032 | return v_ins; |
| 4033 | } |
| 4034 | |
| 4035 | static s16 tabla_get_current_v_hs_max(struct tabla_priv *tabla) |
| 4036 | { |
| 4037 | s16 v_hs_max; |
| 4038 | struct tabla_mbhc_plug_type_cfg *plug_type; |
| 4039 | |
| 4040 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 4041 | if ((tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) && |
| 4042 | tabla->mbhc_micbias_switched) |
| 4043 | v_hs_max = tabla->mbhc_data.adj_v_hs_max; |
| 4044 | else |
| 4045 | v_hs_max = plug_type->v_hs_max; |
| 4046 | return v_hs_max; |
| 4047 | } |
| 4048 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4049 | static void tabla_codec_calibrate_rel(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4050 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4051 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4052 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4053 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B3_CTL, |
| 4054 | tabla->mbhc_data.v_b1_hu & 0xFF); |
| 4055 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B4_CTL, |
| 4056 | (tabla->mbhc_data.v_b1_hu >> 8) & 0xFF); |
| 4057 | |
| 4058 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B5_CTL, |
| 4059 | tabla->mbhc_data.v_b1_h & 0xFF); |
| 4060 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B6_CTL, |
| 4061 | (tabla->mbhc_data.v_b1_h >> 8) & 0xFF); |
| 4062 | |
| 4063 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B9_CTL, |
| 4064 | tabla->mbhc_data.v_brh & 0xFF); |
| 4065 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B10_CTL, |
| 4066 | (tabla->mbhc_data.v_brh >> 8) & 0xFF); |
| 4067 | |
| 4068 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B11_CTL, |
| 4069 | tabla->mbhc_data.v_brl & 0xFF); |
| 4070 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B12_CTL, |
| 4071 | (tabla->mbhc_data.v_brl >> 8) & 0xFF); |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 4072 | } |
| 4073 | |
| 4074 | static void tabla_codec_calibrate_hs_polling(struct snd_soc_codec *codec) |
| 4075 | { |
| 4076 | u8 *n_ready, *n_cic; |
| 4077 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 4078 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4079 | const s16 v_ins_hu = tabla_get_current_v_ins(tabla, true); |
| 4080 | |
| 4081 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 4082 | |
| 4083 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B1_CTL, |
| 4084 | v_ins_hu & 0xFF); |
| 4085 | snd_soc_write(codec, TABLA_A_CDC_MBHC_VOLT_B2_CTL, |
| 4086 | (v_ins_hu >> 8) & 0xFF); |
| 4087 | |
| 4088 | tabla_codec_calibrate_rel(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4089 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4090 | 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] | 4091 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B1_CTL, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 4092 | n_ready[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4093 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B2_CTL, |
| 4094 | tabla->mbhc_data.npoll); |
| 4095 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B3_CTL, |
| 4096 | tabla->mbhc_data.nbounce_wait); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 4097 | 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] | 4098 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B6_CTL, |
| 4099 | n_cic[tabla_codec_mclk_index(tabla)]); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4102 | static int tabla_startup(struct snd_pcm_substream *substream, |
| 4103 | struct snd_soc_dai *dai) |
| 4104 | { |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4105 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4106 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4107 | substream->name, substream->stream); |
Kuirong Wang | a545e72 | 2012-02-06 19:12:54 -0800 | [diff] [blame] | 4108 | if ((tabla_core != NULL) && |
| 4109 | (tabla_core->dev != NULL) && |
| 4110 | (tabla_core->dev->parent != NULL)) |
| 4111 | pm_runtime_get_sync(tabla_core->dev->parent); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4112 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4113 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4114 | } |
| 4115 | |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4116 | static void tabla_shutdown(struct snd_pcm_substream *substream, |
| 4117 | struct snd_soc_dai *dai) |
| 4118 | { |
| 4119 | struct wcd9xxx *tabla_core = dev_get_drvdata(dai->codec->dev->parent); |
| 4120 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4121 | u32 active = 0; |
| 4122 | |
| 4123 | pr_debug("%s(): substream = %s stream = %d\n" , __func__, |
| 4124 | substream->name, substream->stream); |
| 4125 | if (tabla->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4126 | return; |
| 4127 | |
| 4128 | if (dai->id <= NUM_CODEC_DAIS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4129 | if (tabla->dai[dai->id].ch_mask) { |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4130 | active = 1; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 4131 | pr_debug("%s(): Codec DAI: chmask[%d] = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4132 | __func__, dai->id, tabla->dai[dai->id].ch_mask); |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | if ((tabla_core != NULL) && |
| 4137 | (tabla_core->dev != NULL) && |
| 4138 | (tabla_core->dev->parent != NULL) && |
| 4139 | (active == 0)) { |
| 4140 | pm_runtime_mark_last_busy(tabla_core->dev->parent); |
| 4141 | pm_runtime_put(tabla_core->dev->parent); |
| 4142 | } |
| 4143 | } |
| 4144 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4145 | 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] | 4146 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4147 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4148 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 4149 | pr_debug("%s: mclk_enable = %u, dapm = %d\n", __func__, mclk_enable, |
| 4150 | dapm); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4151 | if (dapm) |
| 4152 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4153 | if (mclk_enable) { |
| 4154 | tabla->mclk_enabled = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4155 | |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4156 | if (tabla->mbhc_polling_active) { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4157 | tabla_codec_pause_hs_polling(codec); |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4158 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4159 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4160 | TABLA_BANDGAP_AUDIO_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4161 | tabla_codec_enable_clock_block(codec, 0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 4162 | tabla_codec_calibrate_hs_polling(codec); |
| 4163 | tabla_codec_start_hs_polling(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4164 | } else { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4165 | tabla_codec_disable_clock_block(codec); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4166 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4167 | TABLA_BANDGAP_AUDIO_MODE); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4168 | tabla_codec_enable_clock_block(codec, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4169 | } |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4170 | } else { |
| 4171 | |
| 4172 | if (!tabla->mclk_enabled) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4173 | if (dapm) |
| 4174 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4175 | pr_err("Error, MCLK already diabled\n"); |
| 4176 | return -EINVAL; |
| 4177 | } |
| 4178 | tabla->mclk_enabled = false; |
| 4179 | |
| 4180 | if (tabla->mbhc_polling_active) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4181 | tabla_codec_pause_hs_polling(codec); |
| 4182 | tabla_codec_disable_clock_block(codec); |
| 4183 | tabla_codec_enable_bandgap(codec, |
| 4184 | TABLA_BANDGAP_MBHC_MODE); |
| 4185 | tabla_enable_rx_bias(codec, 1); |
| 4186 | tabla_codec_enable_clock_block(codec, 1); |
| 4187 | tabla_codec_calibrate_hs_polling(codec); |
| 4188 | tabla_codec_start_hs_polling(codec); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4189 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, |
| 4190 | 0x05, 0x01); |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 4191 | } else { |
| 4192 | tabla_codec_disable_clock_block(codec); |
| 4193 | tabla_codec_enable_bandgap(codec, |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 4194 | TABLA_BANDGAP_OFF); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4195 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4196 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 4197 | if (dapm) |
| 4198 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 4199 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4200 | } |
| 4201 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4202 | static int tabla_set_dai_sysclk(struct snd_soc_dai *dai, |
| 4203 | int clk_id, unsigned int freq, int dir) |
| 4204 | { |
| 4205 | pr_debug("%s\n", __func__); |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
| 4209 | static int tabla_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 4210 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4211 | u8 val = 0; |
| 4212 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
| 4213 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4214 | pr_debug("%s\n", __func__); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4215 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 4216 | case SND_SOC_DAIFMT_CBS_CFS: |
| 4217 | /* CPU is master */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4218 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4219 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4220 | snd_soc_update_bits(dai->codec, |
| 4221 | TABLA_A_CDC_CLK_TX_I2S_CTL, |
| 4222 | TABLA_I2S_MASTER_MODE_MASK, 0); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4223 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4224 | snd_soc_update_bits(dai->codec, |
| 4225 | TABLA_A_CDC_CLK_RX_I2S_CTL, |
| 4226 | TABLA_I2S_MASTER_MODE_MASK, 0); |
| 4227 | } |
| 4228 | break; |
| 4229 | case SND_SOC_DAIFMT_CBM_CFM: |
| 4230 | /* CPU is slave */ |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4231 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4232 | val = TABLA_I2S_MASTER_MODE_MASK; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4233 | if (dai->id == AIF1_CAP) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4234 | snd_soc_update_bits(dai->codec, |
| 4235 | TABLA_A_CDC_CLK_TX_I2S_CTL, val, val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4236 | else if (dai->id == AIF1_PB) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4237 | snd_soc_update_bits(dai->codec, |
| 4238 | TABLA_A_CDC_CLK_RX_I2S_CTL, val, val); |
| 4239 | } |
| 4240 | break; |
| 4241 | default: |
| 4242 | return -EINVAL; |
| 4243 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4244 | return 0; |
| 4245 | } |
| 4246 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4247 | static int tabla_set_channel_map(struct snd_soc_dai *dai, |
| 4248 | unsigned int tx_num, unsigned int *tx_slot, |
| 4249 | unsigned int rx_num, unsigned int *rx_slot) |
| 4250 | |
| 4251 | { |
| 4252 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4253 | struct wcd9xxx *core = dev_get_drvdata(dai->codec->dev->parent); |
| 4254 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4255 | if (!tx_slot && !rx_slot) { |
| 4256 | pr_err("%s: Invalid\n", __func__); |
| 4257 | return -EINVAL; |
| 4258 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4259 | pr_debug("%s(): dai_name = %s DAI-ID %x tx_ch %d rx_ch %d\n" |
| 4260 | "tabla->intf_type %d\n", |
| 4261 | __func__, dai->name, dai->id, tx_num, rx_num, |
| 4262 | tabla->intf_type); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4263 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4264 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
| 4265 | wcd9xxx_init_slimslave(core, core->slim->laddr, |
| 4266 | tx_num, tx_slot, rx_num, rx_slot); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4267 | return 0; |
| 4268 | } |
| 4269 | |
| 4270 | static int tabla_get_channel_map(struct snd_soc_dai *dai, |
| 4271 | unsigned int *tx_num, unsigned int *tx_slot, |
| 4272 | unsigned int *rx_num, unsigned int *rx_slot) |
| 4273 | |
| 4274 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4275 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(dai->codec); |
| 4276 | u32 i = 0; |
| 4277 | struct wcd9xxx_ch *ch; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4278 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4279 | switch (dai->id) { |
| 4280 | case AIF1_PB: |
| 4281 | case AIF2_PB: |
| 4282 | case AIF3_PB: |
| 4283 | if (!rx_slot || !rx_num) { |
| 4284 | pr_err("%s: Invalid rx_slot %d or rx_num %d\n", |
| 4285 | __func__, (u32) rx_slot, (u32) rx_num); |
| 4286 | return -EINVAL; |
| 4287 | } |
| 4288 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4289 | list) { |
| 4290 | rx_slot[i++] = ch->ch_num; |
| 4291 | } |
| 4292 | *rx_num = i; |
| 4293 | break; |
| 4294 | case AIF1_CAP: |
| 4295 | case AIF2_CAP: |
| 4296 | case AIF3_CAP: |
| 4297 | if (!tx_slot || !tx_num) { |
| 4298 | pr_err("%s: Invalid tx_slot %d or tx_num %d\n", |
| 4299 | __func__, (u32) tx_slot, (u32) tx_num); |
| 4300 | return -EINVAL; |
| 4301 | } |
| 4302 | list_for_each_entry(ch, &tabla_p->dai[dai->id].wcd9xxx_ch_list, |
| 4303 | list) { |
| 4304 | tx_slot[i++] = ch->ch_num; |
| 4305 | } |
| 4306 | *tx_num = i; |
| 4307 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4308 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4309 | default: |
| 4310 | pr_err("%s: Invalid DAI ID %x\n", __func__, dai->id); |
| 4311 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4312 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4313 | return 0; |
| 4314 | } |
| 4315 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4316 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4317 | static int tabla_set_interpolator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4318 | u8 rx_fs_rate_reg_val, |
| 4319 | u32 compander_fs, |
| 4320 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4321 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4322 | u32 j; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4323 | u8 rx_mix1_inp; |
| 4324 | u16 rx_mix_1_reg_1, rx_mix_1_reg_2; |
| 4325 | u16 rx_fs_reg; |
| 4326 | u8 rx_mix_1_reg_1_val, rx_mix_1_reg_2_val; |
| 4327 | struct snd_soc_codec *codec = dai->codec; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4328 | struct wcd9xxx_ch *ch; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4329 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4330 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4331 | 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] | 4332 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4333 | rx_mix1_inp = ch->port - RX_MIX1_INP_SEL_RX1; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4334 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4335 | if ((rx_mix1_inp < RX_MIX1_INP_SEL_RX1) || |
| 4336 | (rx_mix1_inp > RX_MIX1_INP_SEL_RX7)) { |
| 4337 | pr_err("%s: Invalid TABLA_RX%u port. Dai ID is %d\n", |
| 4338 | __func__, rx_mix1_inp - 5 , dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4339 | return -EINVAL; |
| 4340 | } |
| 4341 | |
| 4342 | rx_mix_1_reg_1 = TABLA_A_CDC_CONN_RX1_B1_CTL; |
| 4343 | |
| 4344 | for (j = 0; j < NUM_INTERPOLATORS; j++) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4345 | rx_mix_1_reg_2 = rx_mix_1_reg_1 + 1; |
| 4346 | |
| 4347 | rx_mix_1_reg_1_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4348 | rx_mix_1_reg_1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4349 | rx_mix_1_reg_2_val = snd_soc_read(codec, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4350 | rx_mix_1_reg_2); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4351 | |
| 4352 | if (((rx_mix_1_reg_1_val & 0x0F) == rx_mix1_inp) || |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4353 | (((rx_mix_1_reg_1_val >> 4) & 0x0F) == rx_mix1_inp) || |
| 4354 | ((rx_mix_1_reg_2_val & 0x0F) == rx_mix1_inp)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4355 | |
| 4356 | rx_fs_reg = TABLA_A_CDC_RX1_B5_CTL + 8 * j; |
| 4357 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4358 | pr_debug("%s: AIF_PB DAI(%d) connected to RX%u\n", |
| 4359 | __func__, dai->id, j + 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4360 | |
| 4361 | pr_debug("%s: set RX%u sample rate to %u\n", |
| 4362 | __func__, j + 1, sample_rate); |
| 4363 | |
| 4364 | snd_soc_update_bits(codec, rx_fs_reg, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4365 | 0xE0, rx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4366 | |
| 4367 | if (comp_rx_path[j] < COMPANDER_MAX) |
| 4368 | tabla->comp_fs[comp_rx_path[j]] |
| 4369 | = compander_fs; |
| 4370 | } |
| 4371 | if (j <= 2) |
| 4372 | rx_mix_1_reg_1 += 3; |
| 4373 | else |
| 4374 | rx_mix_1_reg_1 += 2; |
| 4375 | } |
| 4376 | } |
| 4377 | return 0; |
| 4378 | } |
| 4379 | |
| 4380 | static int tabla_set_decimator_rate(struct snd_soc_dai *dai, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4381 | u8 tx_fs_rate_reg_val, |
| 4382 | u32 sample_rate) |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4383 | { |
| 4384 | struct snd_soc_codec *codec = dai->codec; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4385 | struct wcd9xxx_ch *ch; |
| 4386 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 4387 | u32 tx_port; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4388 | u16 tx_port_reg, tx_fs_reg; |
| 4389 | u8 tx_port_reg_val; |
| 4390 | s8 decimator; |
| 4391 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4392 | 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] | 4393 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4394 | tx_port = ch->port + 1; |
| 4395 | pr_debug("%s: dai->id = %d, tx_port = %d", |
| 4396 | __func__, dai->id, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4397 | |
| 4398 | if ((tx_port < 1) || (tx_port > NUM_DECIMATORS)) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4399 | pr_err("%s: Invalid SLIM TX%u port. DAI ID is %d\n", |
| 4400 | __func__, tx_port, dai->id); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4401 | return -EINVAL; |
| 4402 | } |
| 4403 | |
| 4404 | tx_port_reg = TABLA_A_CDC_CONN_TX_SB_B1_CTL + (tx_port - 1); |
| 4405 | tx_port_reg_val = snd_soc_read(codec, tx_port_reg); |
| 4406 | |
| 4407 | decimator = 0; |
| 4408 | |
| 4409 | if ((tx_port >= 1) && (tx_port <= 6)) { |
| 4410 | |
| 4411 | tx_port_reg_val = tx_port_reg_val & 0x0F; |
| 4412 | if (tx_port_reg_val == 0x8) |
| 4413 | decimator = tx_port; |
| 4414 | |
| 4415 | } else if ((tx_port >= 7) && (tx_port <= NUM_DECIMATORS)) { |
| 4416 | |
| 4417 | tx_port_reg_val = tx_port_reg_val & 0x1F; |
| 4418 | |
| 4419 | if ((tx_port_reg_val >= 0x8) && |
| 4420 | (tx_port_reg_val <= 0x11)) { |
| 4421 | |
| 4422 | decimator = (tx_port_reg_val - 0x8) + 1; |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | if (decimator) { /* SLIM_TX port has a DEC as input */ |
| 4427 | |
| 4428 | tx_fs_reg = TABLA_A_CDC_TX1_CLK_FS_CTL + |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4429 | 8 * (decimator - 1); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4430 | |
| 4431 | pr_debug("%s: set DEC%u (-> SLIM_TX%u) rate to %u\n", |
| 4432 | __func__, decimator, tx_port, sample_rate); |
| 4433 | |
| 4434 | snd_soc_update_bits(codec, tx_fs_reg, 0x07, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4435 | tx_fs_rate_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4436 | |
| 4437 | } else { |
| 4438 | if ((tx_port_reg_val >= 0x1) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4439 | (tx_port_reg_val <= 0x7)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4440 | |
| 4441 | pr_debug("%s: RMIX%u going to SLIM TX%u\n", |
| 4442 | __func__, tx_port_reg_val, tx_port); |
| 4443 | |
| 4444 | } else if ((tx_port_reg_val >= 0x8) && |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4445 | (tx_port_reg_val <= 0x11)) { |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4446 | |
| 4447 | pr_err("%s: ERROR: Should not be here\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4448 | __func__); |
| 4449 | pr_err("%s: ERROR: DEC connected to SLIM TX%u\n", |
| 4450 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4451 | return -EINVAL; |
| 4452 | |
| 4453 | } else if (tx_port_reg_val == 0) { |
| 4454 | pr_debug("%s: no signal to SLIM TX%u\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4455 | __func__, tx_port); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4456 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4457 | pr_err("%s: ERROR: wrong signal to SLIM TX%u\n", |
| 4458 | __func__, tx_port); |
| 4459 | pr_err("%s: ERROR: wrong signal = %u\n", |
| 4460 | __func__, tx_port_reg_val); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4461 | return -EINVAL; |
| 4462 | } |
| 4463 | } |
| 4464 | } |
| 4465 | return 0; |
| 4466 | } |
| 4467 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4468 | static int tabla_hw_params(struct snd_pcm_substream *substream, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4469 | struct snd_pcm_hw_params *params, |
| 4470 | struct snd_soc_dai *dai) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4471 | { |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4472 | struct snd_soc_codec *codec = dai->codec; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4473 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(dai->codec); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4474 | u8 tx_fs_rate_reg_val, rx_fs_rate_reg_val; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4475 | u32 compander_fs; |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4476 | int ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4477 | |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4478 | 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] | 4479 | dai->name, dai->id, params_rate(params), |
| 4480 | params_channels(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4481 | |
| 4482 | switch (params_rate(params)) { |
| 4483 | case 8000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4484 | tx_fs_rate_reg_val = 0x00; |
| 4485 | rx_fs_rate_reg_val = 0x00; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4486 | compander_fs = COMPANDER_FS_8KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4487 | break; |
| 4488 | case 16000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4489 | tx_fs_rate_reg_val = 0x01; |
| 4490 | rx_fs_rate_reg_val = 0x20; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4491 | compander_fs = COMPANDER_FS_16KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4492 | break; |
| 4493 | case 32000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4494 | tx_fs_rate_reg_val = 0x02; |
| 4495 | rx_fs_rate_reg_val = 0x40; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4496 | compander_fs = COMPANDER_FS_32KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4497 | break; |
| 4498 | case 48000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4499 | tx_fs_rate_reg_val = 0x03; |
| 4500 | rx_fs_rate_reg_val = 0x60; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 4501 | compander_fs = COMPANDER_FS_48KHZ; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4502 | break; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4503 | case 96000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4504 | tx_fs_rate_reg_val = 0x04; |
| 4505 | rx_fs_rate_reg_val = 0x80; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4506 | compander_fs = COMPANDER_FS_96KHZ; |
| 4507 | break; |
| 4508 | case 192000: |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4509 | tx_fs_rate_reg_val = 0x05; |
| 4510 | rx_fs_rate_reg_val = 0xA0; |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4511 | compander_fs = COMPANDER_FS_192KHZ; |
| 4512 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4513 | default: |
| 4514 | pr_err("%s: Invalid sampling rate %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4515 | params_rate(params)); |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4516 | return -EINVAL; |
| 4517 | } |
| 4518 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4519 | switch (substream->stream) { |
| 4520 | case SNDRV_PCM_STREAM_CAPTURE: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4521 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4522 | ret = tabla_set_decimator_rate(dai, tx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4523 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4524 | if (ret < 0) { |
| 4525 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4526 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4527 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4528 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4529 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4530 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4531 | switch (params_format(params)) { |
| 4532 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4533 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4534 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4535 | break; |
| 4536 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4537 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4538 | TABLA_A_CDC_CLK_TX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4539 | break; |
| 4540 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4541 | pr_err("%s: Invalid format %d\n", __func__, |
| 4542 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4543 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4544 | } |
| 4545 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_TX_I2S_CTL, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4546 | 0x07, tx_fs_rate_reg_val); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4547 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4548 | switch (params_format(params)) { |
| 4549 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4550 | tabla->dai[dai->id].bit_width = 16; |
| 4551 | break; |
| 4552 | default: |
| 4553 | pr_err("%s: Invalid TX format %d\n", __func__, |
| 4554 | params_format(params)); |
| 4555 | return -EINVAL; |
| 4556 | } |
| 4557 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4558 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4559 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4560 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4561 | case SNDRV_PCM_STREAM_PLAYBACK: |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4562 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4563 | ret = tabla_set_interpolator_rate(dai, rx_fs_rate_reg_val, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4564 | compander_fs, |
| 4565 | params_rate(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4566 | if (ret < 0) { |
| 4567 | pr_err("%s: set decimator rate failed %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4568 | ret); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4569 | return ret; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4570 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4571 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 4572 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4573 | switch (params_format(params)) { |
| 4574 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4575 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4576 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x20); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4577 | break; |
| 4578 | case SNDRV_PCM_FORMAT_S32_LE: |
| 4579 | snd_soc_update_bits(codec, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4580 | TABLA_A_CDC_CLK_RX_I2S_CTL, 0x20, 0x00); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4581 | break; |
| 4582 | default: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4583 | pr_err("%s: Invalid RX format %d\n", __func__, |
| 4584 | params_format(params)); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4585 | return -EINVAL; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4586 | } |
| 4587 | snd_soc_update_bits(codec, TABLA_A_CDC_CLK_RX_I2S_CTL, |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4588 | 0x03, (rx_fs_rate_reg_val >> 0x05)); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4589 | } else { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4590 | switch (params_format(params)) { |
| 4591 | case SNDRV_PCM_FORMAT_S16_LE: |
| 4592 | tabla->dai[dai->id].bit_width = 16; |
| 4593 | break; |
| 4594 | default: |
| 4595 | pr_err("%s: Invalid format %d\n", __func__, |
| 4596 | params_format(params)); |
| 4597 | return -EINVAL; |
| 4598 | } |
| 4599 | tabla->dai[dai->id].rate = params_rate(params); |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4600 | } |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4601 | break; |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4602 | |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4603 | default: |
| 4604 | pr_err("%s: Invalid stream type %d\n", __func__, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4605 | substream->stream); |
Kiran Kandi | 9392390 | 2012-06-20 17:00:25 -0700 | [diff] [blame] | 4606 | return -EINVAL; |
| 4607 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4608 | return 0; |
| 4609 | } |
| 4610 | |
| 4611 | static struct snd_soc_dai_ops tabla_dai_ops = { |
| 4612 | .startup = tabla_startup, |
Swaminathan Sathappan | f95ece6 | 2012-08-23 16:01:50 -0700 | [diff] [blame] | 4613 | .shutdown = tabla_shutdown, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4614 | .hw_params = tabla_hw_params, |
| 4615 | .set_sysclk = tabla_set_dai_sysclk, |
| 4616 | .set_fmt = tabla_set_dai_fmt, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4617 | .set_channel_map = tabla_set_channel_map, |
| 4618 | .get_channel_map = tabla_get_channel_map, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4619 | }; |
| 4620 | |
| 4621 | static struct snd_soc_dai_driver tabla_dai[] = { |
| 4622 | { |
| 4623 | .name = "tabla_rx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4624 | .id = AIF1_PB, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4625 | .playback = { |
| 4626 | .stream_name = "AIF1 Playback", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4627 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4628 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4629 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4630 | .rate_min = 8000, |
| 4631 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4632 | .channels_max = 2, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4633 | }, |
| 4634 | .ops = &tabla_dai_ops, |
| 4635 | }, |
| 4636 | { |
| 4637 | .name = "tabla_tx1", |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4638 | .id = AIF1_CAP, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4639 | .capture = { |
| 4640 | .stream_name = "AIF1 Capture", |
Bhalchandra Gajare | 9a901fd | 2011-08-01 10:07:15 -0700 | [diff] [blame] | 4641 | .rates = WCD9310_RATES, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4642 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4643 | .rate_max = 192000, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4644 | .rate_min = 8000, |
| 4645 | .channels_min = 1, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4646 | .channels_max = 4, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4647 | }, |
| 4648 | .ops = &tabla_dai_ops, |
| 4649 | }, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4650 | { |
| 4651 | .name = "tabla_rx2", |
| 4652 | .id = AIF2_PB, |
| 4653 | .playback = { |
| 4654 | .stream_name = "AIF2 Playback", |
| 4655 | .rates = WCD9310_RATES, |
| 4656 | .formats = TABLA_FORMATS, |
| 4657 | .rate_min = 8000, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4658 | .rate_max = 192000, |
Neema Shetty | d3a8926 | 2012-02-16 10:23:50 -0800 | [diff] [blame] | 4659 | .channels_min = 1, |
| 4660 | .channels_max = 2, |
| 4661 | }, |
| 4662 | .ops = &tabla_dai_ops, |
| 4663 | }, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4664 | { |
| 4665 | .name = "tabla_tx2", |
| 4666 | .id = AIF2_CAP, |
| 4667 | .capture = { |
| 4668 | .stream_name = "AIF2 Capture", |
| 4669 | .rates = WCD9310_RATES, |
| 4670 | .formats = TABLA_FORMATS, |
| 4671 | .rate_max = 192000, |
| 4672 | .rate_min = 8000, |
| 4673 | .channels_min = 1, |
| 4674 | .channels_max = 4, |
| 4675 | }, |
| 4676 | .ops = &tabla_dai_ops, |
| 4677 | }, |
Neema Shetty | 3fb1b80 | 2012-04-27 13:53:24 -0700 | [diff] [blame] | 4678 | { |
| 4679 | .name = "tabla_tx3", |
| 4680 | .id = AIF3_CAP, |
| 4681 | .capture = { |
| 4682 | .stream_name = "AIF3 Capture", |
| 4683 | .rates = WCD9310_RATES, |
| 4684 | .formats = TABLA_FORMATS, |
| 4685 | .rate_max = 48000, |
| 4686 | .rate_min = 8000, |
| 4687 | .channels_min = 1, |
| 4688 | .channels_max = 2, |
| 4689 | }, |
| 4690 | .ops = &tabla_dai_ops, |
| 4691 | }, |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4692 | { |
| 4693 | .name = "tabla_rx3", |
| 4694 | .id = AIF3_PB, |
| 4695 | .playback = { |
| 4696 | .stream_name = "AIF3 Playback", |
| 4697 | .rates = WCD9310_RATES, |
| 4698 | .formats = TABLA_FORMATS, |
| 4699 | .rate_min = 8000, |
| 4700 | .rate_max = 192000, |
| 4701 | .channels_min = 1, |
| 4702 | .channels_max = 2, |
| 4703 | }, |
| 4704 | .ops = &tabla_dai_ops, |
| 4705 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4706 | }; |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4707 | |
| 4708 | static struct snd_soc_dai_driver tabla_i2s_dai[] = { |
| 4709 | { |
| 4710 | .name = "tabla_i2s_rx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4711 | .id = AIF1_PB, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4712 | .playback = { |
| 4713 | .stream_name = "AIF1 Playback", |
| 4714 | .rates = WCD9310_RATES, |
| 4715 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4716 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4717 | .rate_min = 8000, |
| 4718 | .channels_min = 1, |
| 4719 | .channels_max = 4, |
| 4720 | }, |
| 4721 | .ops = &tabla_dai_ops, |
| 4722 | }, |
| 4723 | { |
| 4724 | .name = "tabla_i2s_tx1", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4725 | .id = AIF1_CAP, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4726 | .capture = { |
| 4727 | .stream_name = "AIF1 Capture", |
| 4728 | .rates = WCD9310_RATES, |
| 4729 | .formats = TABLA_FORMATS, |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4730 | .rate_max = 192000, |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 4731 | .rate_min = 8000, |
| 4732 | .channels_min = 1, |
| 4733 | .channels_max = 4, |
| 4734 | }, |
| 4735 | .ops = &tabla_dai_ops, |
| 4736 | }, |
| 4737 | }; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4738 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4739 | static int tabla_codec_enable_chmask(struct tabla_priv *tabla_p, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4740 | int event, int index) |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4741 | { |
| 4742 | int ret = 0; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4743 | struct wcd9xxx_ch *ch; |
| 4744 | |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4745 | switch (event) { |
| 4746 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4747 | list_for_each_entry(ch, |
| 4748 | &tabla_p->dai[index].wcd9xxx_ch_list, list) { |
| 4749 | ret = wcd9xxx_get_slave_port(ch->ch_num); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4750 | if (ret < 0) { |
| 4751 | pr_err("%s: Invalid slave port ID: %d\n", |
| 4752 | __func__, ret); |
| 4753 | ret = -EINVAL; |
| 4754 | break; |
| 4755 | } |
| 4756 | tabla_p->dai[index].ch_mask |= 1 << ret; |
| 4757 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4758 | break; |
| 4759 | case SND_SOC_DAPM_POST_PMD: |
| 4760 | ret = wait_event_timeout(tabla_p->dai[index].dai_wait, |
| 4761 | (tabla_p->dai[index].ch_mask == 0), |
| 4762 | msecs_to_jiffies(SLIM_CLOSE_TIMEOUT)); |
| 4763 | if (!ret) { |
| 4764 | pr_err("%s: Slim close tx/rx wait timeout\n", |
| 4765 | __func__); |
| 4766 | ret = -EINVAL; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4767 | } |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 4768 | break; |
| 4769 | } |
| 4770 | return ret; |
| 4771 | } |
| 4772 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4773 | static int tabla_codec_enable_slimrx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4774 | struct snd_kcontrol *kcontrol, |
| 4775 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4776 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4777 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4778 | struct snd_soc_codec *codec = w->codec; |
| 4779 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4780 | u32 ret = 0; |
| 4781 | struct wcd9xxx_codec_dai_data *dai; |
| 4782 | |
| 4783 | core = dev_get_drvdata(codec->dev->parent); |
| 4784 | |
| 4785 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 4786 | "stream name %s event %d\n", |
| 4787 | __func__, w->codec->name, w->codec->num_dai, |
| 4788 | w->sname, event); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4789 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4790 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4791 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4792 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 4793 | (core->dev != NULL) && |
| 4794 | (core->dev->parent != NULL)) { |
| 4795 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4796 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4797 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4798 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4799 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4800 | pr_debug("%s: w->name %s w->shift %d event %d\n", |
| 4801 | __func__, w->name, w->shift, event); |
| 4802 | dai = &tabla_p->dai[w->shift]; |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 4803 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4804 | switch (event) { |
| 4805 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4806 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 4807 | w->shift); |
| 4808 | ret = wcd9xxx_cfg_slim_sch_rx(core, &dai->wcd9xxx_ch_list, |
| 4809 | dai->rate, dai->bit_width, |
| 4810 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4811 | break; |
| 4812 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4813 | ret = wcd9xxx_close_slim_sch_rx(core, |
| 4814 | &dai->wcd9xxx_ch_list, |
| 4815 | dai->grph); |
| 4816 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 4817 | w->shift); |
| 4818 | if (ret < 0) { |
| 4819 | ret = wcd9xxx_disconnect_port(core, |
| 4820 | &dai->wcd9xxx_ch_list, |
| 4821 | dai->grph); |
| 4822 | pr_info("%s: Disconnect RX port, ret = %d\n", |
| 4823 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4824 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4825 | if ((core != NULL) && |
| 4826 | (core->dev != NULL) && |
| 4827 | (core->dev->parent != NULL)) { |
| 4828 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4829 | pm_runtime_put(core->dev->parent); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4830 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4831 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4832 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4833 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4834 | return ret; |
| 4835 | } |
| 4836 | |
| 4837 | static int tabla_codec_enable_slimtx(struct snd_soc_dapm_widget *w, |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4838 | struct snd_kcontrol *kcontrol, |
| 4839 | int event) |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4840 | { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4841 | struct wcd9xxx *core; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4842 | struct snd_soc_codec *codec = w->codec; |
| 4843 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4844 | u32 ret = 0; |
| 4845 | struct wcd9xxx_codec_dai_data *dai; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4846 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4847 | core = dev_get_drvdata(codec->dev->parent); |
| 4848 | |
| 4849 | pr_debug("%s: event called! codec name %s num_dai %d\n" |
| 4850 | "stream name %s\n", __func__, w->codec->name, |
| 4851 | w->codec->num_dai, w->sname); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4852 | |
| 4853 | /* Execute the callback only if interface type is slimbus */ |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4854 | if (tabla_p->intf_type != WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4855 | if (event == SND_SOC_DAPM_POST_PMD && (core != NULL) && |
| 4856 | (core->dev != NULL) && |
| 4857 | (core->dev->parent != NULL)) { |
| 4858 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4859 | pm_runtime_put(core->dev->parent); |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4860 | } |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4861 | return 0; |
Swaminathan Sathappan | b74caaa | 2012-07-10 17:28:54 -0700 | [diff] [blame] | 4862 | } |
Kiran Kandi | 1e6371d | 2012-03-29 11:48:57 -0700 | [diff] [blame] | 4863 | |
| 4864 | pr_debug("%s(): %s %d\n", __func__, w->name, event); |
| 4865 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4866 | dai = &tabla_p->dai[w->shift]; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4867 | switch (event) { |
| 4868 | case SND_SOC_DAPM_POST_PMU: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4869 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMU, |
| 4870 | w->shift); |
| 4871 | ret = wcd9xxx_cfg_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 4872 | dai->rate, |
| 4873 | dai->bit_width, |
| 4874 | &dai->grph); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4875 | break; |
| 4876 | case SND_SOC_DAPM_POST_PMD: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4877 | ret = wcd9xxx_close_slim_sch_tx(core, &dai->wcd9xxx_ch_list, |
| 4878 | dai->grph); |
| 4879 | ret = tabla_codec_enable_chmask(tabla_p, SND_SOC_DAPM_POST_PMD, |
| 4880 | w->shift); |
| 4881 | if (ret < 0) { |
| 4882 | ret = wcd9xxx_disconnect_port(core, |
| 4883 | &dai->wcd9xxx_ch_list, |
| 4884 | dai->grph); |
| 4885 | pr_info("%s: Disconnect TX port, ret = %d\n", |
| 4886 | __func__, ret); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4887 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4888 | if ((core != NULL) && |
| 4889 | (core->dev != NULL) && |
| 4890 | (core->dev->parent != NULL)) { |
| 4891 | pm_runtime_mark_last_busy(core->dev->parent); |
| 4892 | pm_runtime_put(core->dev->parent); |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4893 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4894 | break; |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4895 | } |
| 4896 | return ret; |
| 4897 | } |
| 4898 | |
| 4899 | /* Todo: Have seperate dapm widgets for I2S and Slimbus. |
| 4900 | * Might Need to have callbacks registered only for slimbus |
| 4901 | */ |
| 4902 | static const struct snd_soc_dapm_widget tabla_dapm_widgets[] = { |
| 4903 | /*RX stuff */ |
| 4904 | SND_SOC_DAPM_OUTPUT("EAR"), |
| 4905 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 4906 | SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM, 0, 0, NULL, |
| 4907 | 0, tabla_ear_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4908 | SND_SOC_DAPM_PRE_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4909 | |
Damir Didjusto | 7c85d71 | 2012-08-16 21:22:29 -0700 | [diff] [blame] | 4910 | SND_SOC_DAPM_MIXER("DAC1", SND_SOC_NOPM, 0, 0, dac1_switch, |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 4911 | ARRAY_SIZE(dac1_switch)), |
| 4912 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 4913 | SND_SOC_DAPM_AIF_IN_E("AIF1 PB", "AIF1 Playback", 0, SND_SOC_NOPM, |
| 4914 | AIF1_PB, 0, tabla_codec_enable_slimrx, |
| 4915 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4916 | SND_SOC_DAPM_AIF_IN_E("AIF2 PB", "AIF2 Playback", 0, SND_SOC_NOPM, |
| 4917 | AIF2_PB, 0, tabla_codec_enable_slimrx, |
| 4918 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4919 | SND_SOC_DAPM_AIF_IN_E("AIF3 PB", "AIF3 Playback", 0, SND_SOC_NOPM, |
| 4920 | AIF3_PB, 0, tabla_codec_enable_slimrx, |
| 4921 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4922 | |
| 4923 | SND_SOC_DAPM_MUX("SLIM RX1 MUX", SND_SOC_NOPM, TABLA_RX1, 0, |
| 4924 | &slim_rx_mux[TABLA_RX1]), |
| 4925 | SND_SOC_DAPM_MUX("SLIM RX2 MUX", SND_SOC_NOPM, TABLA_RX2, 0, |
| 4926 | &slim_rx_mux[TABLA_RX2]), |
| 4927 | SND_SOC_DAPM_MUX("SLIM RX3 MUX", SND_SOC_NOPM, TABLA_RX3, 0, |
| 4928 | &slim_rx_mux[TABLA_RX3]), |
| 4929 | SND_SOC_DAPM_MUX("SLIM RX4 MUX", SND_SOC_NOPM, TABLA_RX4, 0, |
| 4930 | &slim_rx_mux[TABLA_RX4]), |
| 4931 | SND_SOC_DAPM_MUX("SLIM RX5 MUX", SND_SOC_NOPM, TABLA_RX5, 0, |
| 4932 | &slim_rx_mux[TABLA_RX5]), |
| 4933 | SND_SOC_DAPM_MUX("SLIM RX6 MUX", SND_SOC_NOPM, TABLA_RX6, 0, |
| 4934 | &slim_rx_mux[TABLA_RX6]), |
| 4935 | SND_SOC_DAPM_MUX("SLIM RX7 MUX", SND_SOC_NOPM, TABLA_RX7, 0, |
| 4936 | &slim_rx_mux[TABLA_RX7]), |
| 4937 | |
| 4938 | SND_SOC_DAPM_MIXER("SLIM RX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4939 | SND_SOC_DAPM_MIXER("SLIM RX2", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4940 | SND_SOC_DAPM_MIXER("SLIM RX3", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4941 | SND_SOC_DAPM_MIXER("SLIM RX4", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4942 | SND_SOC_DAPM_MIXER("SLIM RX5", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4943 | SND_SOC_DAPM_MIXER("SLIM RX6", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 4944 | 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] | 4945 | /* Headphone */ |
| 4946 | SND_SOC_DAPM_OUTPUT("HEADPHONE"), |
| 4947 | SND_SOC_DAPM_PGA_E("HPHL", TABLA_A_RX_HPH_CNP_EN, 5, 0, NULL, 0, |
| 4948 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4949 | SND_SOC_DAPM_POST_PMD), |
| 4950 | SND_SOC_DAPM_MIXER("HPHL DAC", TABLA_A_RX_HPH_L_DAC_CTL, 7, 0, |
| 4951 | hphl_switch, ARRAY_SIZE(hphl_switch)), |
| 4952 | |
| 4953 | SND_SOC_DAPM_PGA_E("HPHR", TABLA_A_RX_HPH_CNP_EN, 4, 0, NULL, 0, |
| 4954 | tabla_hph_pa_event, SND_SOC_DAPM_PRE_PMU | |
| 4955 | SND_SOC_DAPM_POST_PMD), |
| 4956 | |
| 4957 | SND_SOC_DAPM_DAC_E("HPHR DAC", NULL, TABLA_A_RX_HPH_R_DAC_CTL, 7, 0, |
| 4958 | tabla_hphr_dac_event, |
| 4959 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4960 | |
| 4961 | /* Speaker */ |
| 4962 | SND_SOC_DAPM_OUTPUT("LINEOUT1"), |
| 4963 | SND_SOC_DAPM_OUTPUT("LINEOUT2"), |
| 4964 | SND_SOC_DAPM_OUTPUT("LINEOUT3"), |
| 4965 | SND_SOC_DAPM_OUTPUT("LINEOUT4"), |
| 4966 | SND_SOC_DAPM_OUTPUT("LINEOUT5"), |
| 4967 | |
| 4968 | SND_SOC_DAPM_PGA_E("LINEOUT1 PA", TABLA_A_RX_LINE_CNP_EN, 0, 0, NULL, |
| 4969 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4970 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4971 | SND_SOC_DAPM_PGA_E("LINEOUT2 PA", TABLA_A_RX_LINE_CNP_EN, 1, 0, NULL, |
| 4972 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4973 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4974 | SND_SOC_DAPM_PGA_E("LINEOUT3 PA", TABLA_A_RX_LINE_CNP_EN, 2, 0, NULL, |
| 4975 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4976 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4977 | SND_SOC_DAPM_PGA_E("LINEOUT4 PA", TABLA_A_RX_LINE_CNP_EN, 3, 0, NULL, |
| 4978 | 0, tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4979 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4980 | SND_SOC_DAPM_PGA_E("LINEOUT5 PA", TABLA_A_RX_LINE_CNP_EN, 4, 0, NULL, 0, |
| 4981 | tabla_codec_enable_lineout, SND_SOC_DAPM_PRE_PMU | |
| 4982 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 4983 | |
| 4984 | SND_SOC_DAPM_DAC_E("LINEOUT1 DAC", NULL, TABLA_A_RX_LINE_1_DAC_CTL, 7, 0 |
| 4985 | , tabla_lineout_dac_event, |
| 4986 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4987 | SND_SOC_DAPM_DAC_E("LINEOUT2 DAC", NULL, TABLA_A_RX_LINE_2_DAC_CTL, 7, 0 |
| 4988 | , tabla_lineout_dac_event, |
| 4989 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4990 | SND_SOC_DAPM_DAC_E("LINEOUT3 DAC", NULL, TABLA_A_RX_LINE_3_DAC_CTL, 7, 0 |
| 4991 | , tabla_lineout_dac_event, |
| 4992 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4993 | SND_SOC_DAPM_SWITCH("LINEOUT3 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4994 | &lineout3_ground_switch), |
| 4995 | SND_SOC_DAPM_DAC_E("LINEOUT4 DAC", NULL, TABLA_A_RX_LINE_4_DAC_CTL, 7, 0 |
| 4996 | , tabla_lineout_dac_event, |
| 4997 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 4998 | SND_SOC_DAPM_SWITCH("LINEOUT4 DAC GROUND", SND_SOC_NOPM, 0, 0, |
| 4999 | &lineout4_ground_switch), |
| 5000 | SND_SOC_DAPM_DAC_E("LINEOUT5 DAC", NULL, TABLA_A_RX_LINE_5_DAC_CTL, 7, 0 |
| 5001 | , tabla_lineout_dac_event, |
| 5002 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 5003 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5004 | 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] | 5005 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5006 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5007 | 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] | 5008 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5009 | SND_SOC_DAPM_POST_PMU), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5010 | 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] | 5011 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5012 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5013 | 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] | 5014 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5015 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5016 | 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] | 5017 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5018 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5019 | 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] | 5020 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5021 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5022 | 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] | 5023 | 0, tabla_codec_reset_interpolator, SND_SOC_DAPM_PRE_PMU | |
| 5024 | SND_SOC_DAPM_POST_PMU), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5025 | |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5026 | SND_SOC_DAPM_MIXER("RX1 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5027 | SND_SOC_DAPM_MIXER("RX2 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5028 | SND_SOC_DAPM_MIXER("RX3 MIX1", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 5029 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5030 | SND_SOC_DAPM_MUX_E("RX4 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 3, 0, |
| 5031 | &rx4_dsm_mux, tabla_codec_reset_interpolator, |
| 5032 | SND_SOC_DAPM_PRE_PMU), |
| 5033 | |
| 5034 | SND_SOC_DAPM_MUX_E("RX6 DSM MUX", TABLA_A_CDC_CLK_RX_B1_CTL, 5, 0, |
| 5035 | &rx6_dsm_mux, tabla_codec_reset_interpolator, |
| 5036 | SND_SOC_DAPM_PRE_PMU), |
| 5037 | |
| 5038 | SND_SOC_DAPM_MIXER("RX1 CHAIN", TABLA_A_CDC_RX1_B6_CTL, 5, 0, NULL, 0), |
| 5039 | SND_SOC_DAPM_MIXER("RX2 CHAIN", TABLA_A_CDC_RX2_B6_CTL, 5, 0, NULL, 0), |
| 5040 | |
| 5041 | SND_SOC_DAPM_MUX("RX1 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5042 | &rx_mix1_inp1_mux), |
| 5043 | SND_SOC_DAPM_MUX("RX1 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5044 | &rx_mix1_inp2_mux), |
Kiran Kandi | a9fffe9 | 2012-05-20 23:42:30 -0700 | [diff] [blame] | 5045 | SND_SOC_DAPM_MUX("RX1 MIX1 INP3", SND_SOC_NOPM, 0, 0, |
| 5046 | &rx_mix1_inp3_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5047 | SND_SOC_DAPM_MUX("RX2 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5048 | &rx2_mix1_inp1_mux), |
| 5049 | SND_SOC_DAPM_MUX("RX2 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5050 | &rx2_mix1_inp2_mux), |
| 5051 | SND_SOC_DAPM_MUX("RX3 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5052 | &rx3_mix1_inp1_mux), |
| 5053 | SND_SOC_DAPM_MUX("RX3 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5054 | &rx3_mix1_inp2_mux), |
| 5055 | SND_SOC_DAPM_MUX("RX4 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5056 | &rx4_mix1_inp1_mux), |
| 5057 | SND_SOC_DAPM_MUX("RX4 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5058 | &rx4_mix1_inp2_mux), |
| 5059 | SND_SOC_DAPM_MUX("RX5 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5060 | &rx5_mix1_inp1_mux), |
| 5061 | SND_SOC_DAPM_MUX("RX5 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5062 | &rx5_mix1_inp2_mux), |
| 5063 | SND_SOC_DAPM_MUX("RX6 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5064 | &rx6_mix1_inp1_mux), |
| 5065 | SND_SOC_DAPM_MUX("RX6 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5066 | &rx6_mix1_inp2_mux), |
| 5067 | SND_SOC_DAPM_MUX("RX7 MIX1 INP1", SND_SOC_NOPM, 0, 0, |
| 5068 | &rx7_mix1_inp1_mux), |
| 5069 | SND_SOC_DAPM_MUX("RX7 MIX1 INP2", SND_SOC_NOPM, 0, 0, |
| 5070 | &rx7_mix1_inp2_mux), |
Kuirong Wang | bfdd6ca | 2012-02-29 13:06:38 -0800 | [diff] [blame] | 5071 | SND_SOC_DAPM_MUX("RX1 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5072 | &rx1_mix2_inp1_mux), |
| 5073 | SND_SOC_DAPM_MUX("RX1 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5074 | &rx1_mix2_inp2_mux), |
| 5075 | SND_SOC_DAPM_MUX("RX2 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5076 | &rx2_mix2_inp1_mux), |
| 5077 | SND_SOC_DAPM_MUX("RX2 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5078 | &rx2_mix2_inp2_mux), |
| 5079 | SND_SOC_DAPM_MUX("RX3 MIX2 INP1", SND_SOC_NOPM, 0, 0, |
| 5080 | &rx3_mix2_inp1_mux), |
| 5081 | SND_SOC_DAPM_MUX("RX3 MIX2 INP2", SND_SOC_NOPM, 0, 0, |
| 5082 | &rx3_mix2_inp2_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5083 | |
| 5084 | SND_SOC_DAPM_SUPPLY("CP", TABLA_A_CP_EN, 0, 0, |
| 5085 | tabla_codec_enable_charge_pump, SND_SOC_DAPM_POST_PMU | |
| 5086 | SND_SOC_DAPM_PRE_PMD), |
| 5087 | |
| 5088 | SND_SOC_DAPM_SUPPLY("RX_BIAS", SND_SOC_NOPM, 0, 0, |
| 5089 | tabla_codec_enable_rx_bias, SND_SOC_DAPM_PRE_PMU | |
| 5090 | SND_SOC_DAPM_POST_PMD), |
| 5091 | |
| 5092 | /* TX */ |
| 5093 | |
| 5094 | SND_SOC_DAPM_SUPPLY("CDC_CONN", TABLA_A_CDC_CLK_OTHR_CTL, 2, 0, NULL, |
| 5095 | 0), |
| 5096 | |
| 5097 | SND_SOC_DAPM_SUPPLY("LDO_H", TABLA_A_LDO_H_MODE_1, 7, 0, |
| 5098 | tabla_codec_enable_ldo_h, SND_SOC_DAPM_POST_PMU), |
| 5099 | |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 5100 | SND_SOC_DAPM_SUPPLY("COMP1_CLK", SND_SOC_NOPM, 0, 0, |
| 5101 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5102 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5103 | SND_SOC_DAPM_SUPPLY("COMP2_CLK", SND_SOC_NOPM, 1, 0, |
| 5104 | tabla_config_compander, SND_SOC_DAPM_PRE_PMU | |
| 5105 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_POST_PMD), |
| 5106 | |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5107 | SND_SOC_DAPM_INPUT("AMIC1"), |
| 5108 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 External", TABLA_A_MICB_1_CTL, 7, 0, |
| 5109 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5110 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5111 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal1", TABLA_A_MICB_1_CTL, 7, 0, |
| 5112 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5113 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5114 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS1 Internal2", TABLA_A_MICB_1_CTL, 7, 0, |
| 5115 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5116 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5117 | SND_SOC_DAPM_ADC_E("ADC1", NULL, TABLA_A_TX_1_2_EN, 7, 0, |
| 5118 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5119 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5120 | |
| 5121 | SND_SOC_DAPM_INPUT("AMIC3"), |
| 5122 | SND_SOC_DAPM_ADC_E("ADC3", NULL, TABLA_A_TX_3_4_EN, 7, 0, |
| 5123 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5124 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5125 | |
| 5126 | SND_SOC_DAPM_INPUT("AMIC4"), |
| 5127 | SND_SOC_DAPM_ADC_E("ADC4", NULL, TABLA_A_TX_3_4_EN, 3, 0, |
| 5128 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5129 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5130 | |
| 5131 | SND_SOC_DAPM_INPUT("AMIC5"), |
| 5132 | SND_SOC_DAPM_ADC_E("ADC5", NULL, TABLA_A_TX_5_6_EN, 7, 0, |
| 5133 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5134 | |
| 5135 | SND_SOC_DAPM_INPUT("AMIC6"), |
| 5136 | SND_SOC_DAPM_ADC_E("ADC6", NULL, TABLA_A_TX_5_6_EN, 3, 0, |
| 5137 | tabla_codec_enable_adc, SND_SOC_DAPM_POST_PMU), |
| 5138 | |
| 5139 | 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] | 5140 | &dec1_mux, tabla_codec_enable_dec, |
| 5141 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5142 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5143 | |
| 5144 | 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] | 5145 | &dec2_mux, tabla_codec_enable_dec, |
| 5146 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5147 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5148 | |
| 5149 | 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] | 5150 | &dec3_mux, tabla_codec_enable_dec, |
| 5151 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5152 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5153 | |
| 5154 | 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] | 5155 | &dec4_mux, tabla_codec_enable_dec, |
| 5156 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5157 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5158 | |
| 5159 | 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] | 5160 | &dec5_mux, tabla_codec_enable_dec, |
| 5161 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5162 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5163 | |
| 5164 | 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] | 5165 | &dec6_mux, tabla_codec_enable_dec, |
| 5166 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5167 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5168 | |
| 5169 | 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] | 5170 | &dec7_mux, tabla_codec_enable_dec, |
| 5171 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5172 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5173 | |
| 5174 | 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] | 5175 | &dec8_mux, tabla_codec_enable_dec, |
| 5176 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5177 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5178 | |
| 5179 | 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] | 5180 | &dec9_mux, tabla_codec_enable_dec, |
| 5181 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5182 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5183 | |
| 5184 | 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] | 5185 | &dec10_mux, tabla_codec_enable_dec, |
| 5186 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 5187 | SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5188 | |
| 5189 | SND_SOC_DAPM_MUX("ANC1 MUX", SND_SOC_NOPM, 0, 0, &anc1_mux), |
| 5190 | SND_SOC_DAPM_MUX("ANC2 MUX", SND_SOC_NOPM, 0, 0, &anc2_mux), |
| 5191 | |
| 5192 | SND_SOC_DAPM_MIXER_E("ANC", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 5193 | tabla_codec_enable_anc, SND_SOC_DAPM_PRE_PMU | |
| 5194 | SND_SOC_DAPM_POST_PMD), |
| 5195 | |
| 5196 | SND_SOC_DAPM_MUX("ANC1 FB MUX", SND_SOC_NOPM, 0, 0, &anc1_fb_mux), |
| 5197 | |
| 5198 | SND_SOC_DAPM_INPUT("AMIC2"), |
| 5199 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 External", TABLA_A_MICB_2_CTL, 7, 0, |
| 5200 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5201 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5202 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal1", TABLA_A_MICB_2_CTL, 7, 0, |
| 5203 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5204 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5205 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal2", TABLA_A_MICB_2_CTL, 7, 0, |
| 5206 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5207 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5208 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS2 Internal3", TABLA_A_MICB_2_CTL, 7, 0, |
| 5209 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5210 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5211 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 External", TABLA_A_MICB_3_CTL, 7, 0, |
| 5212 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5213 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5214 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal1", TABLA_A_MICB_3_CTL, 7, 0, |
| 5215 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5216 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5217 | SND_SOC_DAPM_MICBIAS_E("MIC BIAS3 Internal2", TABLA_A_MICB_3_CTL, 7, 0, |
| 5218 | tabla_codec_enable_micbias, SND_SOC_DAPM_PRE_PMU | |
| 5219 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5220 | SND_SOC_DAPM_ADC_E("ADC2", NULL, TABLA_A_TX_1_2_EN, 3, 0, |
| 5221 | tabla_codec_enable_adc, SND_SOC_DAPM_PRE_PMU | |
| 5222 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5223 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 5224 | SND_SOC_DAPM_AIF_OUT_E("AIF1 CAP", "AIF1 Capture", 0, SND_SOC_NOPM, |
| 5225 | AIF1_CAP, 0, tabla_codec_enable_slimtx, |
| 5226 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5227 | |
| 5228 | SND_SOC_DAPM_AIF_OUT_E("AIF2 CAP", "AIF2 Capture", 0, SND_SOC_NOPM, |
| 5229 | AIF2_CAP, 0, tabla_codec_enable_slimtx, |
| 5230 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5231 | |
| 5232 | SND_SOC_DAPM_AIF_OUT_E("AIF3 CAP", "AIF3 Capture", 0, SND_SOC_NOPM, |
| 5233 | AIF3_CAP, 0, tabla_codec_enable_slimtx, |
| 5234 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 5235 | |
| 5236 | SND_SOC_DAPM_MIXER("AIF1_CAP Mixer", SND_SOC_NOPM, AIF1_CAP, 0, |
| 5237 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5238 | |
| 5239 | SND_SOC_DAPM_MIXER("AIF2_CAP Mixer", SND_SOC_NOPM, AIF2_CAP, 0, |
| 5240 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5241 | |
| 5242 | SND_SOC_DAPM_MIXER("AIF3_CAP Mixer", SND_SOC_NOPM, AIF3_CAP, 0, |
| 5243 | aif_cap_mixer, ARRAY_SIZE(aif_cap_mixer)), |
| 5244 | |
| 5245 | SND_SOC_DAPM_MUX("SLIM TX1 MUX", SND_SOC_NOPM, TABLA_TX1, 0, |
| 5246 | &sb_tx1_mux), |
| 5247 | SND_SOC_DAPM_MUX("SLIM TX2 MUX", SND_SOC_NOPM, TABLA_TX2, 0, |
| 5248 | &sb_tx2_mux), |
| 5249 | SND_SOC_DAPM_MUX("SLIM TX3 MUX", SND_SOC_NOPM, TABLA_TX3, 0, |
| 5250 | &sb_tx3_mux), |
| 5251 | SND_SOC_DAPM_MUX("SLIM TX4 MUX", SND_SOC_NOPM, TABLA_TX4, 0, |
| 5252 | &sb_tx4_mux), |
| 5253 | SND_SOC_DAPM_MUX("SLIM TX5 MUX", SND_SOC_NOPM, TABLA_TX5, 0, |
| 5254 | &sb_tx5_mux), |
| 5255 | SND_SOC_DAPM_MUX("SLIM TX6 MUX", SND_SOC_NOPM, TABLA_TX6, 0, |
| 5256 | &sb_tx6_mux), |
| 5257 | SND_SOC_DAPM_MUX("SLIM TX7 MUX", SND_SOC_NOPM, TABLA_TX7, 0, |
| 5258 | &sb_tx7_mux), |
| 5259 | SND_SOC_DAPM_MUX("SLIM TX8 MUX", SND_SOC_NOPM, TABLA_TX8, 0, |
| 5260 | &sb_tx8_mux), |
| 5261 | SND_SOC_DAPM_MUX("SLIM TX9 MUX", SND_SOC_NOPM, TABLA_TX9, 0, |
| 5262 | &sb_tx9_mux), |
| 5263 | SND_SOC_DAPM_MUX("SLIM TX10 MUX", SND_SOC_NOPM, TABLA_TX10, 0, |
| 5264 | &sb_tx10_mux), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5265 | |
| 5266 | /* Digital Mic Inputs */ |
| 5267 | SND_SOC_DAPM_ADC_E("DMIC1", NULL, SND_SOC_NOPM, 0, 0, |
| 5268 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5269 | SND_SOC_DAPM_POST_PMD), |
| 5270 | |
| 5271 | SND_SOC_DAPM_ADC_E("DMIC2", NULL, SND_SOC_NOPM, 0, 0, |
| 5272 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5273 | SND_SOC_DAPM_POST_PMD), |
| 5274 | |
| 5275 | SND_SOC_DAPM_ADC_E("DMIC3", NULL, SND_SOC_NOPM, 0, 0, |
| 5276 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5277 | SND_SOC_DAPM_POST_PMD), |
| 5278 | |
| 5279 | SND_SOC_DAPM_ADC_E("DMIC4", NULL, SND_SOC_NOPM, 0, 0, |
| 5280 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5281 | SND_SOC_DAPM_POST_PMD), |
| 5282 | |
| 5283 | SND_SOC_DAPM_ADC_E("DMIC5", NULL, SND_SOC_NOPM, 0, 0, |
| 5284 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5285 | SND_SOC_DAPM_POST_PMD), |
| 5286 | SND_SOC_DAPM_ADC_E("DMIC6", NULL, SND_SOC_NOPM, 0, 0, |
| 5287 | tabla_codec_enable_dmic, SND_SOC_DAPM_PRE_PMU | |
| 5288 | SND_SOC_DAPM_POST_PMD), |
| 5289 | |
| 5290 | /* Sidetone */ |
| 5291 | SND_SOC_DAPM_MUX("IIR1 INP1 MUX", SND_SOC_NOPM, 0, 0, &iir1_inp1_mux), |
| 5292 | 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] | 5293 | |
| 5294 | /* AUX PGA */ |
| 5295 | SND_SOC_DAPM_ADC_E("AUX_PGA_Left", NULL, TABLA_A_AUX_L_EN, 7, 0, |
| 5296 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5297 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5298 | SND_SOC_DAPM_POST_PMD), |
| 5299 | |
| 5300 | SND_SOC_DAPM_ADC_E("AUX_PGA_Right", NULL, TABLA_A_AUX_R_EN, 7, 0, |
| 5301 | tabla_codec_enable_aux_pga, SND_SOC_DAPM_PRE_PMU | |
| 5302 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD | |
| 5303 | SND_SOC_DAPM_POST_PMD), |
| 5304 | |
| 5305 | /* Lineout, ear and HPH PA Mixers */ |
| 5306 | SND_SOC_DAPM_MIXER("HPHL_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5307 | hphl_pa_mix, ARRAY_SIZE(hphl_pa_mix)), |
| 5308 | |
| 5309 | SND_SOC_DAPM_MIXER("HPHR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5310 | hphr_pa_mix, ARRAY_SIZE(hphr_pa_mix)), |
| 5311 | |
| 5312 | SND_SOC_DAPM_MIXER("LINEOUT1_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5313 | lineout1_pa_mix, ARRAY_SIZE(lineout1_pa_mix)), |
| 5314 | |
| 5315 | SND_SOC_DAPM_MIXER("LINEOUT2_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5316 | lineout2_pa_mix, ARRAY_SIZE(lineout2_pa_mix)), |
| 5317 | |
| 5318 | SND_SOC_DAPM_MIXER("LINEOUT3_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5319 | lineout3_pa_mix, ARRAY_SIZE(lineout3_pa_mix)), |
| 5320 | |
| 5321 | SND_SOC_DAPM_MIXER("LINEOUT4_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5322 | lineout4_pa_mix, ARRAY_SIZE(lineout4_pa_mix)), |
| 5323 | |
| 5324 | SND_SOC_DAPM_MIXER("LINEOUT5_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5325 | lineout5_pa_mix, ARRAY_SIZE(lineout5_pa_mix)), |
| 5326 | |
| 5327 | SND_SOC_DAPM_MIXER("EAR_PA_MIXER", SND_SOC_NOPM, 0, 0, |
| 5328 | ear_pa_mix, ARRAY_SIZE(ear_pa_mix)), |
Bharath Ramachandramurthy | 9c79f13 | 2011-11-28 11:18:57 -0800 | [diff] [blame] | 5329 | }; |
| 5330 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5331 | static short tabla_codec_read_sta_result(struct snd_soc_codec *codec) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5332 | { |
| 5333 | u8 bias_msb, bias_lsb; |
| 5334 | short bias_value; |
| 5335 | |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5336 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B3_STATUS); |
| 5337 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B2_STATUS); |
| 5338 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5339 | return bias_value; |
| 5340 | } |
| 5341 | |
| 5342 | static short tabla_codec_read_dce_result(struct snd_soc_codec *codec) |
| 5343 | { |
| 5344 | u8 bias_msb, bias_lsb; |
| 5345 | short bias_value; |
| 5346 | |
| 5347 | bias_msb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B5_STATUS); |
| 5348 | bias_lsb = snd_soc_read(codec, TABLA_A_CDC_MBHC_B4_STATUS); |
| 5349 | bias_value = (bias_msb << 8) | bias_lsb; |
| 5350 | return bias_value; |
| 5351 | } |
| 5352 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5353 | 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] | 5354 | { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5355 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x02, on << 1); |
| 5356 | } |
| 5357 | |
| 5358 | static short __tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5359 | bool override_bypass, bool noreldetection) |
| 5360 | { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5361 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5362 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 5363 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5364 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5365 | if (noreldetection) |
| 5366 | tabla_turn_onoff_rel_detection(codec, false); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5367 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5368 | /* Turn on the override */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5369 | if (!override_bypass) |
| 5370 | 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] | 5371 | if (dce) { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5372 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5373 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
| 5374 | 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] | 5375 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5376 | tabla->mbhc_data.t_sta_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5377 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x4); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5378 | usleep_range(tabla->mbhc_data.t_dce, |
| 5379 | tabla->mbhc_data.t_dce); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5380 | bias_value = tabla_codec_read_dce_result(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5381 | } else { |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5382 | 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] | 5383 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5384 | 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] | 5385 | usleep_range(tabla->mbhc_data.t_sta_dce, |
| 5386 | tabla->mbhc_data.t_sta_dce); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5387 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x2); |
| 5388 | usleep_range(tabla->mbhc_data.t_sta, |
| 5389 | tabla->mbhc_data.t_sta); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5390 | bias_value = tabla_codec_read_sta_result(codec); |
| 5391 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5392 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x0); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5393 | } |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5394 | /* Turn off the override after measuring mic voltage */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5395 | if (!override_bypass) |
| 5396 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x00); |
| 5397 | |
| 5398 | if (noreldetection) |
| 5399 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5400 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5401 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5402 | return bias_value; |
| 5403 | } |
| 5404 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5405 | static short tabla_codec_sta_dce(struct snd_soc_codec *codec, int dce, |
| 5406 | bool norel) |
| 5407 | { |
| 5408 | return __tabla_codec_sta_dce(codec, dce, false, norel); |
| 5409 | } |
| 5410 | |
| 5411 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5412 | static short tabla_codec_setup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5413 | { |
| 5414 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5415 | short bias_value; |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 5416 | u8 cfilt_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5417 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5418 | pr_debug("%s: enter, mclk_enabled %d\n", __func__, tabla->mclk_enabled); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5419 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5420 | pr_err("Error, no tabla calibration\n"); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5421 | return -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5422 | } |
| 5423 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5424 | if (!tabla->mclk_enabled) { |
Joonwoo Park | 8a6bccc | 2012-05-03 15:13:13 -0700 | [diff] [blame] | 5425 | tabla_codec_disable_clock_block(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5426 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_MBHC_MODE); |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 5427 | tabla_enable_rx_bias(codec, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5428 | tabla_codec_enable_clock_block(codec, 1); |
| 5429 | } |
| 5430 | |
| 5431 | snd_soc_update_bits(codec, TABLA_A_CLK_BUFF_EN1, 0x05, 0x01); |
| 5432 | |
Bhalchandra Gajare | 19d9c13 | 2011-11-18 14:57:08 -0800 | [diff] [blame] | 5433 | /* Make sure CFILT is in fast mode, save current mode */ |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5434 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
| 5435 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x70, 0x00); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 5436 | |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 5437 | 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] | 5438 | |
| 5439 | 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] | 5440 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5441 | |
| 5442 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x80, 0x80); |
| 5443 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, 0x1F, 0x1C); |
| 5444 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x40, 0x40); |
| 5445 | |
| 5446 | 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] | 5447 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5448 | 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] | 5449 | |
Joonwoo Park | 925914c | 2012-01-05 13:35:18 -0800 | [diff] [blame] | 5450 | 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] | 5451 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x8, 0x8); |
| 5452 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5453 | tabla_codec_calibrate_hs_polling(codec); |
| 5454 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5455 | /* don't flip override */ |
| 5456 | bias_value = __tabla_codec_sta_dce(codec, 1, true, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5457 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5458 | cfilt_mode); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 5459 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5460 | |
Bhalchandra Gajare | 343cbb0 | 2011-09-07 18:58:19 -0700 | [diff] [blame] | 5461 | return bias_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5464 | static int tabla_cancel_btn_work(struct tabla_priv *tabla) |
| 5465 | { |
| 5466 | int r = 0; |
| 5467 | struct wcd9xxx *core = dev_get_drvdata(tabla->codec->dev->parent); |
| 5468 | |
| 5469 | if (cancel_delayed_work_sync(&tabla->mbhc_btn_dwork)) { |
| 5470 | /* if scheduled mbhc_btn_dwork is canceled from here, |
| 5471 | * we have to unlock from here instead btn_work */ |
| 5472 | wcd9xxx_unlock_sleep(core); |
| 5473 | r = 1; |
| 5474 | } |
| 5475 | return r; |
| 5476 | } |
| 5477 | |
| 5478 | /* called under codec_resource_lock acquisition */ |
| 5479 | void tabla_set_and_turnoff_hph_padac(struct snd_soc_codec *codec) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5480 | { |
| 5481 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5482 | u8 wg_time; |
| 5483 | |
| 5484 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5485 | wg_time += 1; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5486 | |
| 5487 | /* If headphone PA is on, check if userspace receives |
| 5488 | * removal event to sync-up PA's state */ |
| 5489 | if (tabla_is_hph_pa_on(codec)) { |
| 5490 | pr_debug("%s PA is on, setting PA_OFF_ACK\n", __func__); |
| 5491 | set_bit(TABLA_HPHL_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5492 | set_bit(TABLA_HPHR_PA_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5493 | } else { |
| 5494 | pr_debug("%s PA is off\n", __func__); |
| 5495 | } |
| 5496 | |
| 5497 | if (tabla_is_hph_dac_on(codec, 1)) |
| 5498 | set_bit(TABLA_HPHL_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
| 5499 | if (tabla_is_hph_dac_on(codec, 0)) |
| 5500 | set_bit(TABLA_HPHR_DAC_OFF_ACK, &tabla->hph_pa_dac_state); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5501 | |
| 5502 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_CNP_EN, 0x30, 0x00); |
| 5503 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5504 | 0xC0, 0x00); |
| 5505 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5506 | 0xC0, 0x00); |
| 5507 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5508 | } |
| 5509 | |
| 5510 | static void tabla_clr_and_turnon_hph_padac(struct tabla_priv *tabla) |
| 5511 | { |
| 5512 | bool pa_turned_on = false; |
| 5513 | struct snd_soc_codec *codec = tabla->codec; |
| 5514 | u8 wg_time; |
| 5515 | |
| 5516 | wg_time = snd_soc_read(codec, TABLA_A_RX_HPH_CNP_WG_TIME) ; |
| 5517 | wg_time += 1; |
| 5518 | |
| 5519 | if (test_and_clear_bit(TABLA_HPHR_DAC_OFF_ACK, |
| 5520 | &tabla->hph_pa_dac_state)) { |
| 5521 | pr_debug("%s: HPHR clear flag and enable DAC\n", __func__); |
| 5522 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_R_DAC_CTL, |
| 5523 | 0xC0, 0xC0); |
| 5524 | } |
| 5525 | if (test_and_clear_bit(TABLA_HPHL_DAC_OFF_ACK, |
| 5526 | &tabla->hph_pa_dac_state)) { |
| 5527 | pr_debug("%s: HPHL clear flag and enable DAC\n", __func__); |
| 5528 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_L_DAC_CTL, |
| 5529 | 0xC0, 0xC0); |
| 5530 | } |
| 5531 | |
| 5532 | if (test_and_clear_bit(TABLA_HPHR_PA_OFF_ACK, |
| 5533 | &tabla->hph_pa_dac_state)) { |
| 5534 | pr_debug("%s: HPHR clear flag and enable PA\n", __func__); |
| 5535 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x10, |
| 5536 | 1 << 4); |
| 5537 | pa_turned_on = true; |
| 5538 | } |
| 5539 | if (test_and_clear_bit(TABLA_HPHL_PA_OFF_ACK, |
| 5540 | &tabla->hph_pa_dac_state)) { |
| 5541 | pr_debug("%s: HPHL clear flag and enable PA\n", __func__); |
| 5542 | snd_soc_update_bits(tabla->codec, TABLA_A_RX_HPH_CNP_EN, 0x20, |
| 5543 | 1 << 5); |
| 5544 | pa_turned_on = true; |
| 5545 | } |
| 5546 | |
| 5547 | if (pa_turned_on) { |
| 5548 | pr_debug("%s: PA was turned off by MBHC and not by DAPM\n", |
| 5549 | __func__); |
| 5550 | usleep_range(wg_time * 1000, wg_time * 1000); |
| 5551 | } |
| 5552 | } |
| 5553 | |
| 5554 | /* called under codec_resource_lock acquisition */ |
| 5555 | static void tabla_codec_report_plug(struct snd_soc_codec *codec, int insertion, |
| 5556 | enum snd_jack_types jack_type) |
| 5557 | { |
| 5558 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5559 | pr_debug("%s: enter insertion %d hph_status %x\n", |
| 5560 | __func__, insertion, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5561 | if (!insertion) { |
| 5562 | /* Report removal */ |
| 5563 | tabla->hph_status &= ~jack_type; |
| 5564 | if (tabla->mbhc_cfg.headset_jack) { |
| 5565 | /* cancel possibly scheduled btn work and |
| 5566 | * report release if we reported button press */ |
| 5567 | if (tabla_cancel_btn_work(tabla)) { |
| 5568 | pr_debug("%s: button press is canceled\n", |
| 5569 | __func__); |
| 5570 | } else if (tabla->buttons_pressed) { |
| 5571 | pr_debug("%s: Reporting release for reported " |
| 5572 | "button press %d\n", __func__, |
| 5573 | jack_type); |
| 5574 | tabla_snd_soc_jack_report(tabla, |
| 5575 | tabla->mbhc_cfg.button_jack, 0, |
| 5576 | tabla->buttons_pressed); |
| 5577 | tabla->buttons_pressed &= |
| 5578 | ~TABLA_JACK_BUTTON_MASK; |
| 5579 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5580 | pr_debug("%s: Reporting removal %d(%x)\n", __func__, |
| 5581 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5582 | tabla_snd_soc_jack_report(tabla, |
| 5583 | tabla->mbhc_cfg.headset_jack, |
| 5584 | tabla->hph_status, |
| 5585 | TABLA_JACK_MASK); |
| 5586 | } |
| 5587 | tabla_set_and_turnoff_hph_padac(codec); |
| 5588 | hphocp_off_report(tabla, SND_JACK_OC_HPHR, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5589 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5590 | hphocp_off_report(tabla, SND_JACK_OC_HPHL, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5591 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5592 | tabla->current_plug = PLUG_TYPE_NONE; |
| 5593 | tabla->mbhc_polling_active = false; |
| 5594 | } else { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5595 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 5596 | /* Report removal of current jack type */ |
| 5597 | if (tabla->hph_status != jack_type && |
| 5598 | tabla->mbhc_cfg.headset_jack) { |
| 5599 | pr_debug("%s: Reporting removal (%x)\n", |
| 5600 | __func__, tabla->hph_status); |
| 5601 | tabla_snd_soc_jack_report(tabla, |
| 5602 | tabla->mbhc_cfg.headset_jack, |
| 5603 | 0, TABLA_JACK_MASK); |
| 5604 | tabla->hph_status = 0; |
| 5605 | } |
| 5606 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5607 | /* Report insertion */ |
| 5608 | tabla->hph_status |= jack_type; |
| 5609 | |
| 5610 | if (jack_type == SND_JACK_HEADPHONE) |
| 5611 | tabla->current_plug = PLUG_TYPE_HEADPHONE; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5612 | else if (jack_type == SND_JACK_UNSUPPORTED) |
| 5613 | tabla->current_plug = PLUG_TYPE_GND_MIC_SWAP; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5614 | else if (jack_type == SND_JACK_HEADSET) { |
| 5615 | tabla->mbhc_polling_active = true; |
| 5616 | tabla->current_plug = PLUG_TYPE_HEADSET; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5617 | } else if (jack_type == SND_JACK_LINEOUT) |
| 5618 | tabla->current_plug = PLUG_TYPE_HIGH_HPH; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5619 | if (tabla->mbhc_cfg.headset_jack) { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 5620 | pr_debug("%s: Reporting insertion %d(%x)\n", __func__, |
| 5621 | jack_type, tabla->hph_status); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5622 | tabla_snd_soc_jack_report(tabla, |
| 5623 | tabla->mbhc_cfg.headset_jack, |
| 5624 | tabla->hph_status, |
| 5625 | TABLA_JACK_MASK); |
| 5626 | } |
| 5627 | tabla_clr_and_turnon_hph_padac(tabla); |
| 5628 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5629 | pr_debug("%s: leave hph_status %x\n", __func__, tabla->hph_status); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5630 | } |
| 5631 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5632 | static int tabla_codec_enable_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5633 | int insertion, int trigger, |
| 5634 | bool padac_off) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5635 | { |
| 5636 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5637 | int central_bias_enabled = 0; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5638 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5639 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5640 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5641 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5642 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 5643 | pr_debug("%s: enter insertion(%d) trigger(0x%x)\n", |
| 5644 | __func__, insertion, trigger); |
| 5645 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5646 | if (!tabla->mbhc_cfg.calibration) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5647 | pr_err("Error, no tabla calibration\n"); |
| 5648 | return -EINVAL; |
| 5649 | } |
| 5650 | |
| 5651 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x1, 0); |
| 5652 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5653 | /* Make sure mic bias and Mic line schmitt trigger |
| 5654 | * are turned OFF |
| 5655 | */ |
| 5656 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x01); |
| 5657 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 5658 | |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5659 | if (insertion) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 5660 | pr_debug("%s: setup for insertion\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5661 | tabla_codec_switch_micbias(codec, 0); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5662 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5663 | /* DAPM can manipulate PA/DAC bits concurrently */ |
| 5664 | if (padac_off == true) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5665 | tabla_set_and_turnoff_hph_padac(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5666 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5667 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5668 | if (trigger & MBHC_USE_HPHL_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5669 | /* Enable HPH Schmitt Trigger */ |
| 5670 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x11, |
| 5671 | 0x11); |
| 5672 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x0C, |
| 5673 | plug_det->hph_current << 2); |
| 5674 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x02, |
| 5675 | 0x02); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 5676 | } |
| 5677 | if (trigger & MBHC_USE_MB_TRIGGER) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5678 | /* enable the mic line schmitt trigger */ |
| 5679 | snd_soc_update_bits(codec, |
| 5680 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5681 | 0x60, plug_det->mic_current << 5); |
| 5682 | snd_soc_update_bits(codec, |
| 5683 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5684 | 0x80, 0x80); |
| 5685 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
| 5686 | snd_soc_update_bits(codec, |
| 5687 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 5688 | 0x00); |
| 5689 | snd_soc_update_bits(codec, |
| 5690 | tabla->mbhc_bias_regs.mbhc_reg, |
| 5691 | 0x10, 0x10); |
| 5692 | } |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5693 | |
| 5694 | /* setup for insetion detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5695 | 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] | 5696 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5697 | pr_debug("setup for removal detection\n"); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5698 | /* Make sure the HPH schmitt trigger is OFF */ |
| 5699 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x12, 0x00); |
| 5700 | |
| 5701 | /* enable the mic line schmitt trigger */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5702 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 5703 | 0x01, 0x00); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5704 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x60, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5705 | plug_det->mic_current << 5); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5706 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 5707 | 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5708 | usleep_range(plug_det->t_mic_pid, plug_det->t_mic_pid); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 5709 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, |
| 5710 | 0x10, 0x10); |
| 5711 | |
| 5712 | /* Setup for low power removal detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5713 | 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] | 5714 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5715 | |
| 5716 | if (snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x4) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5717 | /* called called by interrupt */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5718 | if (!(tabla->clock_active)) { |
| 5719 | tabla_codec_enable_config_mode(codec, 1); |
| 5720 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5721 | 0x06, 0); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5722 | usleep_range(generic->t_shutdown_plug_rem, |
| 5723 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5724 | tabla_codec_enable_config_mode(codec, 0); |
| 5725 | } else |
| 5726 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 5727 | 0x06, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5728 | } |
| 5729 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 5730 | 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] | 5731 | |
| 5732 | /* If central bandgap disabled */ |
| 5733 | if (!(snd_soc_read(codec, TABLA_A_PIN_CTL_OE1) & 1)) { |
| 5734 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x3, 0x3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5735 | usleep_range(generic->t_bg_fast_settle, |
| 5736 | generic->t_bg_fast_settle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5737 | central_bias_enabled = 1; |
| 5738 | } |
| 5739 | |
| 5740 | /* If LDO_H disabled */ |
| 5741 | if (snd_soc_read(codec, TABLA_A_PIN_CTL_OE0) & 0x80) { |
| 5742 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x10, 0); |
| 5743 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0x80); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5744 | usleep_range(generic->t_ldoh, generic->t_ldoh); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5745 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE0, 0x80, 0); |
| 5746 | |
| 5747 | if (central_bias_enabled) |
| 5748 | snd_soc_update_bits(codec, TABLA_A_PIN_CTL_OE1, 0x1, 0); |
| 5749 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5750 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 5751 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x3, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5752 | tabla->mbhc_cfg.micbias); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5753 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5754 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5755 | 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] | 5756 | pr_debug("%s: leave\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5757 | return 0; |
| 5758 | } |
| 5759 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5760 | static u16 tabla_codec_v_sta_dce(struct snd_soc_codec *codec, bool dce, |
| 5761 | s16 vin_mv) |
| 5762 | { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5763 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5764 | s16 diff, zero; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5765 | u32 mb_mv, in; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5766 | u16 value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5767 | |
| 5768 | tabla = snd_soc_codec_get_drvdata(codec); |
| 5769 | mb_mv = tabla->mbhc_data.micb_mv; |
| 5770 | |
| 5771 | if (mb_mv == 0) { |
| 5772 | pr_err("%s: Mic Bias voltage is set to zero\n", __func__); |
| 5773 | return -EINVAL; |
| 5774 | } |
| 5775 | |
| 5776 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5777 | diff = (tabla->mbhc_data.dce_mb) - (tabla->mbhc_data.dce_z); |
| 5778 | zero = (tabla->mbhc_data.dce_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5779 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5780 | diff = (tabla->mbhc_data.sta_mb) - (tabla->mbhc_data.sta_z); |
| 5781 | zero = (tabla->mbhc_data.sta_z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5782 | } |
| 5783 | in = (u32) diff * vin_mv; |
| 5784 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5785 | value = (u16) (in / mb_mv) + zero; |
| 5786 | return value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5787 | } |
| 5788 | |
| 5789 | static s32 tabla_codec_sta_dce_v(struct snd_soc_codec *codec, s8 dce, |
| 5790 | u16 bias_value) |
| 5791 | { |
| 5792 | struct tabla_priv *tabla; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5793 | s16 value, z, mb; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5794 | s32 mv; |
| 5795 | |
| 5796 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5797 | value = bias_value; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5798 | if (dce) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5799 | z = (tabla->mbhc_data.dce_z); |
| 5800 | mb = (tabla->mbhc_data.dce_mb); |
| 5801 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5802 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5803 | z = (tabla->mbhc_data.sta_z); |
| 5804 | mb = (tabla->mbhc_data.sta_mb); |
| 5805 | mv = (value - z) * (s32)tabla->mbhc_data.micb_mv / (mb - z); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5806 | } |
| 5807 | |
| 5808 | return mv; |
| 5809 | } |
| 5810 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5811 | static void btn_lpress_fn(struct work_struct *work) |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5812 | { |
| 5813 | struct delayed_work *delayed_work; |
| 5814 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5815 | short bias_value; |
| 5816 | int dce_mv, sta_mv; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5817 | struct wcd9xxx *core; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5818 | |
| 5819 | pr_debug("%s:\n", __func__); |
| 5820 | |
| 5821 | delayed_work = to_delayed_work(work); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5822 | tabla = container_of(delayed_work, struct tabla_priv, mbhc_btn_dwork); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 5823 | core = dev_get_drvdata(tabla->codec->dev->parent); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5824 | |
| 5825 | if (tabla) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5826 | if (tabla->mbhc_cfg.button_jack) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5827 | bias_value = tabla_codec_read_sta_result(tabla->codec); |
| 5828 | sta_mv = tabla_codec_sta_dce_v(tabla->codec, 0, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5829 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5830 | bias_value = tabla_codec_read_dce_result(tabla->codec); |
| 5831 | dce_mv = tabla_codec_sta_dce_v(tabla->codec, 1, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 5832 | bias_value); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5833 | pr_debug("%s: Reporting long button press event" |
| 5834 | " STA: %d, DCE: %d\n", __func__, |
| 5835 | sta_mv, dce_mv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5836 | tabla_snd_soc_jack_report(tabla, |
| 5837 | tabla->mbhc_cfg.button_jack, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5838 | tabla->buttons_pressed, |
| 5839 | tabla->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5840 | } |
| 5841 | } else { |
| 5842 | pr_err("%s: Bad tabla private data\n", __func__); |
| 5843 | } |
| 5844 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5845 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 5846 | wcd9xxx_unlock_sleep(core); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 5847 | } |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 5848 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5849 | static u16 tabla_get_cfilt_reg(struct snd_soc_codec *codec, u8 cfilt) |
| 5850 | { |
| 5851 | u16 reg; |
| 5852 | |
| 5853 | switch (cfilt) { |
| 5854 | case TABLA_CFILT1_SEL: |
| 5855 | reg = TABLA_A_MICB_CFILT_1_CTL; |
| 5856 | break; |
| 5857 | case TABLA_CFILT2_SEL: |
| 5858 | reg = TABLA_A_MICB_CFILT_2_CTL; |
| 5859 | break; |
| 5860 | case TABLA_CFILT3_SEL: |
| 5861 | reg = TABLA_A_MICB_CFILT_3_CTL; |
| 5862 | break; |
| 5863 | default: |
| 5864 | BUG(); |
| 5865 | } |
| 5866 | return reg; |
| 5867 | } |
| 5868 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5869 | void tabla_mbhc_cal(struct snd_soc_codec *codec) |
| 5870 | { |
| 5871 | struct tabla_priv *tabla; |
| 5872 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5873 | u8 cfilt_mode, micbias2_cfilt_mode, bg_mode; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5874 | u8 ncic, nmeas, navg; |
| 5875 | u32 mclk_rate; |
| 5876 | u32 dce_wait, sta_wait; |
| 5877 | u8 *n_cic; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5878 | void *calibration; |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5879 | u16 bias2_ctl; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5880 | |
| 5881 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5882 | calibration = tabla->mbhc_cfg.calibration; |
| 5883 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5884 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5885 | tabla_turn_onoff_rel_detection(codec, false); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5886 | |
| 5887 | /* First compute the DCE / STA wait times |
| 5888 | * depending on tunable parameters. |
| 5889 | * The value is computed in microseconds |
| 5890 | */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5891 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5892 | 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] | 5893 | ncic = n_cic[tabla_codec_mclk_index(tabla)]; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5894 | nmeas = TABLA_MBHC_CAL_BTN_DET_PTR(calibration)->n_meas; |
| 5895 | navg = TABLA_MBHC_CAL_GENERAL_PTR(calibration)->mbhc_navg; |
| 5896 | mclk_rate = tabla->mbhc_cfg.mclk_rate; |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 5897 | dce_wait = (1000 * 512 * ncic * (nmeas + 1)) / (mclk_rate / 1000); |
| 5898 | sta_wait = (1000 * 128 * (navg + 1)) / (mclk_rate / 1000); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5899 | |
| 5900 | tabla->mbhc_data.t_dce = dce_wait; |
| 5901 | tabla->mbhc_data.t_sta = sta_wait; |
| 5902 | |
| 5903 | /* LDOH and CFILT are already configured during pdata handling. |
| 5904 | * Only need to make sure CFILT and bandgap are in Fast mode. |
| 5905 | * Need to restore defaults once calculation is done. |
| 5906 | */ |
| 5907 | cfilt_mode = snd_soc_read(codec, tabla->mbhc_bias_regs.cfilt_ctl); |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5908 | micbias2_cfilt_mode = |
| 5909 | snd_soc_read(codec, tabla_get_cfilt_reg(codec, |
| 5910 | tabla->pdata->micbias.bias2_cfilt_sel)); |
| 5911 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5912 | TABLA_CFILT_FAST_MODE); |
| 5913 | snd_soc_update_bits(codec, |
| 5914 | tabla_get_cfilt_reg(codec, |
| 5915 | tabla->pdata->micbias.bias2_cfilt_sel), |
| 5916 | 0x40, TABLA_CFILT_FAST_MODE); |
| 5917 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5918 | bg_mode = snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, |
| 5919 | 0x02); |
| 5920 | |
| 5921 | /* Micbias, CFILT, LDOH, MBHC MUX mode settings |
| 5922 | * to perform ADC calibration |
| 5923 | */ |
| 5924 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x60, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5925 | tabla->mbhc_cfg.micbias << 5); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5926 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 5927 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x60, 0x60); |
| 5928 | snd_soc_write(codec, TABLA_A_TX_7_MBHC_TEST_CTL, 0x78); |
| 5929 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x04, 0x04); |
| 5930 | |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5931 | /* MICBIAS2 routing for calibration */ |
| 5932 | bias2_ctl = snd_soc_read(codec, TABLA_A_MICB_2_CTL); |
| 5933 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, TABLA_MICBIAS2); |
| 5934 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, |
| 5935 | snd_soc_read(codec, tabla->mbhc_bias_regs.ctl_reg)); |
| 5936 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5937 | /* DCE measurement for 0 volts */ |
| 5938 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5939 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5940 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5941 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5942 | usleep_range(100, 100); |
| 5943 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5944 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5945 | tabla->mbhc_data.dce_z = tabla_codec_read_dce_result(codec); |
| 5946 | |
| 5947 | /* DCE measurment for MB voltage */ |
| 5948 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5949 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
| 5950 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5951 | usleep_range(100, 100); |
| 5952 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x04); |
| 5953 | usleep_range(tabla->mbhc_data.t_dce, tabla->mbhc_data.t_dce); |
| 5954 | tabla->mbhc_data.dce_mb = tabla_codec_read_dce_result(codec); |
| 5955 | |
| 5956 | /* Sta measuremnt for 0 volts */ |
| 5957 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x0A); |
| 5958 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5959 | snd_soc_write(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x02); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5960 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x81); |
| 5961 | usleep_range(100, 100); |
| 5962 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5963 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5964 | tabla->mbhc_data.sta_z = tabla_codec_read_sta_result(codec); |
| 5965 | |
| 5966 | /* STA Measurement for MB Voltage */ |
| 5967 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x82); |
| 5968 | usleep_range(100, 100); |
| 5969 | snd_soc_write(codec, TABLA_A_CDC_MBHC_EN_CTL, 0x02); |
| 5970 | usleep_range(tabla->mbhc_data.t_sta, tabla->mbhc_data.t_sta); |
| 5971 | tabla->mbhc_data.sta_mb = tabla_codec_read_sta_result(codec); |
| 5972 | |
| 5973 | /* Restore default settings. */ |
Joonwoo Park | e067b23 | 2012-06-14 13:11:30 -0700 | [diff] [blame] | 5974 | snd_soc_write(codec, TABLA_A_MICB_2_CTL, bias2_ctl); |
| 5975 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 5976 | tabla->mbhc_cfg.micbias); |
| 5977 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5978 | 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] | 5979 | snd_soc_update_bits(codec, |
| 5980 | tabla_get_cfilt_reg(codec, |
| 5981 | tabla->pdata->micbias.bias2_cfilt_sel), 0x40, |
| 5982 | micbias2_cfilt_mode); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5983 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, 0x40, |
| 5984 | cfilt_mode); |
| 5985 | snd_soc_update_bits(codec, TABLA_A_BIAS_CENTRAL_BG_CTL, 0x02, bg_mode); |
| 5986 | |
| 5987 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 5988 | usleep_range(100, 100); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5989 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 5990 | wcd9xxx_enable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 5991 | tabla_turn_onoff_rel_detection(codec, true); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 5992 | } |
| 5993 | |
| 5994 | void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg* btn_det, |
| 5995 | const enum tabla_mbhc_btn_det_mem mem) |
| 5996 | { |
| 5997 | void *ret = &btn_det->_v_btn_low; |
| 5998 | |
| 5999 | switch (mem) { |
| 6000 | case TABLA_BTN_DET_GAIN: |
| 6001 | ret += sizeof(btn_det->_n_cic); |
| 6002 | case TABLA_BTN_DET_N_CIC: |
| 6003 | ret += sizeof(btn_det->_n_ready); |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6004 | case TABLA_BTN_DET_N_READY: |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6005 | ret += sizeof(btn_det->_v_btn_high[0]) * btn_det->num_btn; |
| 6006 | case TABLA_BTN_DET_V_BTN_HIGH: |
| 6007 | ret += sizeof(btn_det->_v_btn_low[0]) * btn_det->num_btn; |
| 6008 | case TABLA_BTN_DET_V_BTN_LOW: |
| 6009 | /* do nothing */ |
| 6010 | break; |
| 6011 | default: |
| 6012 | ret = NULL; |
| 6013 | } |
| 6014 | |
| 6015 | return ret; |
| 6016 | } |
| 6017 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6018 | static s16 tabla_scale_v_micb_vddio(struct tabla_priv *tabla, int v, |
| 6019 | bool tovddio) |
| 6020 | { |
| 6021 | int r; |
| 6022 | int vddio_k, mb_k; |
| 6023 | vddio_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6024 | VDDIO_MICBIAS_MV); |
| 6025 | mb_k = tabla_find_k_value(tabla->pdata->micbias.ldoh_v, |
| 6026 | tabla->mbhc_data.micb_mv); |
| 6027 | if (tovddio) |
| 6028 | r = v * vddio_k / mb_k; |
| 6029 | else |
| 6030 | r = v * mb_k / vddio_k; |
| 6031 | return r; |
| 6032 | } |
| 6033 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6034 | static void tabla_mbhc_calc_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6035 | { |
| 6036 | s16 deltamv; |
| 6037 | struct tabla_priv *tabla; |
| 6038 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6039 | |
| 6040 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6041 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6042 | |
| 6043 | tabla->mbhc_data.v_b1_h = |
| 6044 | tabla_codec_v_sta_dce(codec, DCE, |
| 6045 | mv + btn_det->v_btn_press_delta_cic); |
| 6046 | |
| 6047 | tabla->mbhc_data.v_brh = tabla->mbhc_data.v_b1_h; |
| 6048 | |
| 6049 | tabla->mbhc_data.v_brl = TABLA_MBHC_BUTTON_MIN; |
| 6050 | |
| 6051 | deltamv = mv + btn_det->v_btn_press_delta_sta; |
| 6052 | tabla->mbhc_data.v_b1_hu = tabla_codec_v_sta_dce(codec, STA, deltamv); |
| 6053 | |
| 6054 | deltamv = mv + btn_det->v_btn_press_delta_cic; |
| 6055 | tabla->mbhc_data.v_b1_huc = tabla_codec_v_sta_dce(codec, DCE, deltamv); |
| 6056 | } |
| 6057 | |
| 6058 | static void tabla_mbhc_set_rel_thres(struct snd_soc_codec *codec, s16 mv) |
| 6059 | { |
| 6060 | tabla_mbhc_calc_rel_thres(codec, mv); |
| 6061 | tabla_codec_calibrate_rel(codec); |
| 6062 | } |
| 6063 | |
| 6064 | static s16 tabla_mbhc_highest_btn_mv(struct snd_soc_codec *codec) |
| 6065 | { |
| 6066 | struct tabla_priv *tabla; |
| 6067 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6068 | u16 *btn_high; |
| 6069 | |
| 6070 | tabla = snd_soc_codec_get_drvdata(codec); |
| 6071 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6072 | btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_HIGH); |
| 6073 | |
| 6074 | return btn_high[btn_det->num_btn - 1]; |
| 6075 | } |
| 6076 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6077 | static void tabla_mbhc_calc_thres(struct snd_soc_codec *codec) |
| 6078 | { |
| 6079 | struct tabla_priv *tabla; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6080 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6081 | struct tabla_mbhc_plug_type_cfg *plug_type; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6082 | u8 *n_ready; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6083 | |
| 6084 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6085 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
| 6086 | plug_type = TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6087 | |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6088 | 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] | 6089 | if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_12288KHZ) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6090 | tabla->mbhc_data.npoll = 4; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6091 | tabla->mbhc_data.nbounce_wait = 30; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6092 | } else if (tabla->mbhc_cfg.mclk_rate == TABLA_MCLK_RATE_9600KHZ) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6093 | tabla->mbhc_data.npoll = 7; |
| 6094 | tabla->mbhc_data.nbounce_wait = 23; |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6095 | } |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6096 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6097 | tabla->mbhc_data.t_sta_dce = ((1000 * 256) / |
| 6098 | (tabla->mbhc_cfg.mclk_rate / 1000) * |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 6099 | n_ready[tabla_codec_mclk_index(tabla)]) + |
| 6100 | 10; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6101 | tabla->mbhc_data.v_ins_hu = |
| 6102 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_hs_max); |
| 6103 | tabla->mbhc_data.v_ins_h = |
| 6104 | tabla_codec_v_sta_dce(codec, DCE, plug_type->v_hs_max); |
| 6105 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6106 | tabla->mbhc_data.v_inval_ins_low = TABLA_MBHC_FAKE_INSERT_LOW; |
| 6107 | if (tabla->mbhc_cfg.gpio) |
| 6108 | tabla->mbhc_data.v_inval_ins_high = |
| 6109 | TABLA_MBHC_FAKE_INSERT_HIGH; |
| 6110 | else |
| 6111 | tabla->mbhc_data.v_inval_ins_high = |
| 6112 | TABLA_MBHC_FAKE_INS_HIGH_NO_GPIO; |
| 6113 | |
| 6114 | if (tabla->mbhc_data.micb_mv != VDDIO_MICBIAS_MV) { |
| 6115 | tabla->mbhc_data.adj_v_hs_max = |
| 6116 | tabla_scale_v_micb_vddio(tabla, plug_type->v_hs_max, true); |
| 6117 | tabla->mbhc_data.adj_v_ins_hu = |
| 6118 | tabla_codec_v_sta_dce(codec, STA, |
| 6119 | tabla->mbhc_data.adj_v_hs_max); |
| 6120 | tabla->mbhc_data.adj_v_ins_h = |
| 6121 | tabla_codec_v_sta_dce(codec, DCE, |
| 6122 | tabla->mbhc_data.adj_v_hs_max); |
| 6123 | tabla->mbhc_data.v_inval_ins_low = |
| 6124 | tabla_scale_v_micb_vddio(tabla, |
| 6125 | tabla->mbhc_data.v_inval_ins_low, |
| 6126 | false); |
| 6127 | tabla->mbhc_data.v_inval_ins_high = |
| 6128 | tabla_scale_v_micb_vddio(tabla, |
| 6129 | tabla->mbhc_data.v_inval_ins_high, |
| 6130 | false); |
| 6131 | } |
| 6132 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6133 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6134 | |
| 6135 | tabla->mbhc_data.v_no_mic = |
| 6136 | tabla_codec_v_sta_dce(codec, STA, plug_type->v_no_mic); |
| 6137 | } |
| 6138 | |
| 6139 | void tabla_mbhc_init(struct snd_soc_codec *codec) |
| 6140 | { |
| 6141 | struct tabla_priv *tabla; |
| 6142 | struct tabla_mbhc_general_cfg *generic; |
| 6143 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6144 | int n; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6145 | u8 *n_cic, *gain; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6146 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6147 | |
| 6148 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6149 | generic = TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
| 6150 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(tabla->mbhc_cfg.calibration); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6151 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6152 | for (n = 0; n < 8; n++) { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 6153 | if ((!TABLA_IS_1_X(tabla_core->version)) || n != 7) { |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6154 | snd_soc_update_bits(codec, |
| 6155 | TABLA_A_CDC_MBHC_FEATURE_B1_CFG, |
| 6156 | 0x07, n); |
| 6157 | snd_soc_write(codec, TABLA_A_CDC_MBHC_FEATURE_B2_CFG, |
| 6158 | btn_det->c[n]); |
| 6159 | } |
| 6160 | } |
| 6161 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x07, |
| 6162 | btn_det->nc); |
| 6163 | |
| 6164 | n_cic = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_N_CIC); |
| 6165 | 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] | 6166 | n_cic[tabla_codec_mclk_index(tabla)]); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6167 | |
| 6168 | 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] | 6169 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B2_CTL, 0x78, |
| 6170 | gain[tabla_codec_mclk_index(tabla)] << 3); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6171 | |
| 6172 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x70, |
| 6173 | generic->mbhc_nsa << 4); |
| 6174 | |
| 6175 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_TIMER_B4_CTL, 0x0F, |
| 6176 | btn_det->n_meas); |
| 6177 | |
| 6178 | snd_soc_write(codec, TABLA_A_CDC_MBHC_TIMER_B5_CTL, generic->mbhc_navg); |
| 6179 | |
| 6180 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x80, 0x80); |
| 6181 | |
| 6182 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_B1_CTL, 0x78, |
| 6183 | btn_det->mbhc_nsc << 3); |
| 6184 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 6185 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_mbhc, 0x03, |
| 6186 | TABLA_MICBIAS2); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6187 | |
| 6188 | 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] | 6189 | |
| 6190 | 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] | 6191 | |
| 6192 | /* override mbhc's micbias */ |
| 6193 | snd_soc_update_bits(codec, TABLA_A_MICB_1_MBHC, 0x03, |
| 6194 | tabla->mbhc_cfg.micbias); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6195 | } |
| 6196 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 6197 | static bool tabla_mbhc_fw_validate(const struct firmware *fw) |
| 6198 | { |
| 6199 | u32 cfg_offset; |
| 6200 | struct tabla_mbhc_imped_detect_cfg *imped_cfg; |
| 6201 | struct tabla_mbhc_btn_detect_cfg *btn_cfg; |
| 6202 | |
| 6203 | if (fw->size < TABLA_MBHC_CAL_MIN_SIZE) |
| 6204 | return false; |
| 6205 | |
| 6206 | /* previous check guarantees that there is enough fw data up |
| 6207 | * to num_btn |
| 6208 | */ |
| 6209 | btn_cfg = TABLA_MBHC_CAL_BTN_DET_PTR(fw->data); |
| 6210 | cfg_offset = (u32) ((void *) btn_cfg - (void *) fw->data); |
| 6211 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_BTN_SZ(btn_cfg))) |
| 6212 | return false; |
| 6213 | |
| 6214 | /* previous check guarantees that there is enough fw data up |
| 6215 | * to start of impedance detection configuration |
| 6216 | */ |
| 6217 | imped_cfg = TABLA_MBHC_CAL_IMPED_DET_PTR(fw->data); |
| 6218 | cfg_offset = (u32) ((void *) imped_cfg - (void *) fw->data); |
| 6219 | |
| 6220 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_MIN_SZ)) |
| 6221 | return false; |
| 6222 | |
| 6223 | if (fw->size < (cfg_offset + TABLA_MBHC_CAL_IMPED_SZ(imped_cfg))) |
| 6224 | return false; |
| 6225 | |
| 6226 | return true; |
| 6227 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6228 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6229 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6230 | static int tabla_determine_button(const struct tabla_priv *priv, |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6231 | const s32 micmv) |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6232 | { |
| 6233 | s16 *v_btn_low, *v_btn_high; |
| 6234 | struct tabla_mbhc_btn_detect_cfg *btn_det; |
| 6235 | int i, btn = -1; |
| 6236 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6237 | btn_det = TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6238 | v_btn_low = tabla_mbhc_cal_btn_det_mp(btn_det, TABLA_BTN_DET_V_BTN_LOW); |
| 6239 | v_btn_high = tabla_mbhc_cal_btn_det_mp(btn_det, |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6240 | TABLA_BTN_DET_V_BTN_HIGH); |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6241 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6242 | for (i = 0; i < btn_det->num_btn; i++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6243 | if ((v_btn_low[i] <= micmv) && (v_btn_high[i] >= micmv)) { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6244 | btn = i; |
| 6245 | break; |
| 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | if (btn == -1) |
| 6250 | 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] | 6251 | __func__, micmv); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6252 | |
| 6253 | return btn; |
| 6254 | } |
| 6255 | |
| 6256 | static int tabla_get_button_mask(const int btn) |
| 6257 | { |
| 6258 | int mask = 0; |
| 6259 | switch (btn) { |
| 6260 | case 0: |
| 6261 | mask = SND_JACK_BTN_0; |
| 6262 | break; |
| 6263 | case 1: |
| 6264 | mask = SND_JACK_BTN_1; |
| 6265 | break; |
| 6266 | case 2: |
| 6267 | mask = SND_JACK_BTN_2; |
| 6268 | break; |
| 6269 | case 3: |
| 6270 | mask = SND_JACK_BTN_3; |
| 6271 | break; |
| 6272 | case 4: |
| 6273 | mask = SND_JACK_BTN_4; |
| 6274 | break; |
| 6275 | case 5: |
| 6276 | mask = SND_JACK_BTN_5; |
| 6277 | break; |
| 6278 | case 6: |
| 6279 | mask = SND_JACK_BTN_6; |
| 6280 | break; |
| 6281 | case 7: |
| 6282 | mask = SND_JACK_BTN_7; |
| 6283 | break; |
| 6284 | } |
| 6285 | return mask; |
| 6286 | } |
| 6287 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6288 | static irqreturn_t tabla_dce_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6289 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6290 | int i, mask; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6291 | short dce, sta; |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6292 | s32 mv, mv_s, stamv, stamv_s; |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6293 | bool vddio; |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6294 | u16 *btn_high; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6295 | int btn = -1, meas = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6296 | struct tabla_priv *priv = data; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6297 | const struct tabla_mbhc_btn_detect_cfg *d = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6298 | TABLA_MBHC_CAL_BTN_DET_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6299 | short btnmeas[d->n_btn_meas + 1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6300 | struct snd_soc_codec *codec = priv->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6301 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6302 | int n_btn_meas = d->n_btn_meas; |
| 6303 | 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] | 6304 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6305 | pr_debug("%s: enter\n", __func__); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6306 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6307 | 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] | 6308 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6309 | if (priv->mbhc_state == MBHC_STATE_POTENTIAL_RECOVERY) { |
| 6310 | pr_debug("%s: mbhc is being recovered, skip button press\n", |
| 6311 | __func__); |
| 6312 | goto done; |
| 6313 | } |
| 6314 | |
| 6315 | priv->mbhc_state = MBHC_STATE_POTENTIAL; |
| 6316 | |
| 6317 | if (!priv->mbhc_polling_active) { |
| 6318 | pr_warn("%s: mbhc polling is not active, skip button press\n", |
| 6319 | __func__); |
| 6320 | goto done; |
| 6321 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6322 | |
| 6323 | dce = tabla_codec_read_dce_result(codec); |
| 6324 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6325 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6326 | /* If GPIO interrupt already kicked in, ignore button press */ |
| 6327 | if (priv->in_gpio_handler) { |
| 6328 | pr_debug("%s: GPIO State Changed, ignore button press\n", |
| 6329 | __func__); |
| 6330 | btn = -1; |
| 6331 | goto done; |
| 6332 | } |
| 6333 | |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6334 | vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 6335 | priv->mbhc_micbias_switched); |
| 6336 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6337 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6338 | if (mbhc_status != TABLA_MBHC_STATUS_REL_DETECTION) { |
| 6339 | if (priv->mbhc_last_resume && |
| 6340 | !time_after(jiffies, priv->mbhc_last_resume + HZ)) { |
| 6341 | pr_debug("%s: Button is already released shortly after " |
| 6342 | "resume\n", __func__); |
| 6343 | n_btn_meas = 0; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6344 | } |
| 6345 | } |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 6346 | |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6347 | /* save hw dce */ |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6348 | btnmeas[meas++] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6349 | pr_debug("%s: meas HW - DCE %x,%d,%d button %d\n", __func__, |
| 6350 | dce, mv, mv_s, btnmeas[0]); |
| 6351 | if (n_btn_meas == 0) { |
| 6352 | sta = tabla_codec_read_sta_result(codec); |
| 6353 | stamv_s = stamv = tabla_codec_sta_dce_v(codec, 0, sta); |
| 6354 | if (vddio) |
| 6355 | stamv_s = tabla_scale_v_micb_vddio(priv, stamv, false); |
| 6356 | btn = tabla_determine_button(priv, stamv_s); |
| 6357 | pr_debug("%s: meas HW - STA %x,%d,%d button %d\n", __func__, |
| 6358 | sta, stamv, stamv_s, btn); |
| 6359 | BUG_ON(meas != 1); |
| 6360 | if (btnmeas[0] != btn) |
| 6361 | btn = -1; |
| 6362 | } |
| 6363 | |
| 6364 | /* determine pressed button */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6365 | for (; ((d->n_btn_meas) && (meas < (d->n_btn_meas + 1))); meas++) { |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6366 | dce = tabla_codec_sta_dce(codec, 1, false); |
| 6367 | mv = tabla_codec_sta_dce_v(codec, 1, dce); |
| 6368 | mv_s = vddio ? tabla_scale_v_micb_vddio(priv, mv, false) : mv; |
| 6369 | |
| 6370 | btnmeas[meas] = tabla_determine_button(priv, mv_s); |
Joonwoo Park | 1233483 | 2012-07-23 19:27:52 -0700 | [diff] [blame] | 6371 | pr_debug("%s: meas %d - DCE %x,%d,%d button %d\n", |
Joonwoo Park | fee1743 | 2012-04-16 16:33:55 -0700 | [diff] [blame] | 6372 | __func__, meas, dce, mv, mv_s, btnmeas[meas]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6373 | /* if large enough measurements are collected, |
| 6374 | * start to check if last all n_btn_con measurements were |
| 6375 | * in same button low/high range */ |
| 6376 | if (meas + 1 >= d->n_btn_con) { |
| 6377 | for (i = 0; i < d->n_btn_con; i++) |
| 6378 | if ((btnmeas[meas] < 0) || |
| 6379 | (btnmeas[meas] != btnmeas[meas - i])) |
| 6380 | break; |
| 6381 | if (i == d->n_btn_con) { |
| 6382 | /* button pressed */ |
| 6383 | btn = btnmeas[meas]; |
| 6384 | break; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6385 | } else if ((n_btn_meas - meas) < (d->n_btn_con - 1)) { |
| 6386 | /* if left measurements are less than n_btn_con, |
| 6387 | * it's impossible to find button number */ |
| 6388 | break; |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6389 | } |
| 6390 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6391 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6392 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6393 | if (btn >= 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6394 | if (priv->in_gpio_handler) { |
| 6395 | pr_debug("%s: GPIO already triggered, ignore button " |
| 6396 | "press\n", __func__); |
| 6397 | goto done; |
| 6398 | } |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6399 | /* narrow down release threshold */ |
| 6400 | tabla_mbhc_set_rel_thres(codec, btn_high[btn]); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6401 | mask = tabla_get_button_mask(btn); |
| 6402 | priv->buttons_pressed |= mask; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6403 | wcd9xxx_lock_sleep(core); |
| 6404 | if (schedule_delayed_work(&priv->mbhc_btn_dwork, |
| 6405 | msecs_to_jiffies(400)) == 0) { |
| 6406 | WARN(1, "Button pressed twice without release" |
| 6407 | "event\n"); |
| 6408 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6409 | } |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6410 | } else { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6411 | pr_debug("%s: bogus button press, too short press?\n", |
| 6412 | __func__); |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6413 | } |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6414 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6415 | done: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6416 | pr_debug("%s: leave\n", __func__); |
| 6417 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6418 | return IRQ_HANDLED; |
| 6419 | } |
| 6420 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6421 | static int tabla_is_fake_press(struct tabla_priv *priv) |
| 6422 | { |
| 6423 | int i; |
| 6424 | int r = 0; |
| 6425 | struct snd_soc_codec *codec = priv->codec; |
| 6426 | const int dces = MBHC_NUM_DCE_PLUG_DETECT; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6427 | s16 mb_v, v_ins_hu, v_ins_h; |
| 6428 | |
| 6429 | v_ins_hu = tabla_get_current_v_ins(priv, true); |
| 6430 | v_ins_h = tabla_get_current_v_ins(priv, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6431 | |
| 6432 | for (i = 0; i < dces; i++) { |
| 6433 | usleep_range(10000, 10000); |
| 6434 | if (i == 0) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6435 | mb_v = tabla_codec_sta_dce(codec, 0, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6436 | pr_debug("%s: STA[0]: %d,%d\n", __func__, mb_v, |
| 6437 | tabla_codec_sta_dce_v(codec, 0, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6438 | if (mb_v < (s16)priv->mbhc_data.v_b1_hu || |
| 6439 | mb_v > v_ins_hu) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6440 | r = 1; |
| 6441 | break; |
| 6442 | } |
| 6443 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6444 | mb_v = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6445 | pr_debug("%s: DCE[%d]: %d,%d\n", __func__, i, mb_v, |
| 6446 | tabla_codec_sta_dce_v(codec, 1, mb_v)); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6447 | if (mb_v < (s16)priv->mbhc_data.v_b1_h || |
| 6448 | mb_v > v_ins_h) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6449 | r = 1; |
| 6450 | break; |
| 6451 | } |
| 6452 | } |
| 6453 | } |
| 6454 | |
| 6455 | return r; |
| 6456 | } |
| 6457 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6458 | static irqreturn_t tabla_release_handler(int irq, void *data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6459 | { |
Joonwoo Park | e5d3aa9 | 2012-01-11 14:47:15 -0800 | [diff] [blame] | 6460 | int ret; |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 6461 | struct tabla_priv *priv = data; |
| 6462 | struct snd_soc_codec *codec = priv->codec; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6463 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6464 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6465 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6466 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
| 6467 | priv->mbhc_state = MBHC_STATE_RELEASE; |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6468 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6469 | tabla_codec_drive_v_to_micbias(codec, 10000); |
| 6470 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6471 | if (priv->buttons_pressed & TABLA_JACK_BUTTON_MASK) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6472 | ret = tabla_cancel_btn_work(priv); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6473 | if (ret == 0) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6474 | pr_debug("%s: Reporting long button release event\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6475 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6476 | if (priv->mbhc_cfg.button_jack) |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 6477 | tabla_snd_soc_jack_report(priv, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6478 | priv->mbhc_cfg.button_jack, 0, |
| 6479 | priv->buttons_pressed); |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6480 | } else { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6481 | if (tabla_is_fake_press(priv)) { |
| 6482 | pr_debug("%s: Fake button press interrupt\n", |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6483 | __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6484 | } else if (priv->mbhc_cfg.button_jack) { |
| 6485 | if (priv->in_gpio_handler) { |
| 6486 | pr_debug("%s: GPIO kicked in, ignore\n", |
| 6487 | __func__); |
| 6488 | } else { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6489 | pr_debug("%s: Reporting short button " |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6490 | "press and release\n", |
| 6491 | __func__); |
| 6492 | tabla_snd_soc_jack_report(priv, |
| 6493 | priv->mbhc_cfg.button_jack, |
| 6494 | priv->buttons_pressed, |
| 6495 | priv->buttons_pressed); |
| 6496 | tabla_snd_soc_jack_report(priv, |
| 6497 | priv->mbhc_cfg.button_jack, 0, |
| 6498 | priv->buttons_pressed); |
| 6499 | } |
Bhalchandra Gajare | 0a792b1 | 2011-09-06 16:36:58 -0700 | [diff] [blame] | 6500 | } |
| 6501 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6502 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 6503 | priv->buttons_pressed &= ~TABLA_JACK_BUTTON_MASK; |
| 6504 | } |
| 6505 | |
Joonwoo Park | dd9d296 | 2012-07-23 19:24:20 -0700 | [diff] [blame] | 6506 | /* revert narrowed release threshold */ |
| 6507 | tabla_mbhc_calc_rel_thres(codec, tabla_mbhc_highest_btn_mv(codec)); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6508 | tabla_codec_calibrate_hs_polling(codec); |
| 6509 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6510 | if (priv->mbhc_cfg.gpio) |
| 6511 | msleep(TABLA_MBHC_GPIO_REL_DEBOUNCE_TIME_MS); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6512 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6513 | tabla_codec_start_hs_polling(codec); |
| 6514 | |
| 6515 | pr_debug("%s: leave\n", __func__); |
| 6516 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6517 | return IRQ_HANDLED; |
| 6518 | } |
| 6519 | |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6520 | static void tabla_codec_shutdown_hs_removal_detect(struct snd_soc_codec *codec) |
| 6521 | { |
| 6522 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6523 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6524 | TABLA_MBHC_CAL_GENERAL_PTR(tabla->mbhc_cfg.calibration); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6525 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6526 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6527 | tabla_codec_enable_config_mode(codec, 1); |
| 6528 | |
| 6529 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, 0x2, 0x2); |
| 6530 | 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] | 6531 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 6532 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x80, 0x00); |
| 6533 | |
| 6534 | usleep_range(generic->t_shutdown_plug_rem, |
| 6535 | generic->t_shutdown_plug_rem); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6536 | |
| 6537 | 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] | 6538 | if (!tabla->mclk_enabled && !tabla->mbhc_polling_active) |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6539 | tabla_codec_enable_config_mode(codec, 0); |
| 6540 | |
| 6541 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x00); |
| 6542 | } |
| 6543 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6544 | static void tabla_codec_cleanup_hs_polling(struct snd_soc_codec *codec) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6545 | { |
| 6546 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 6547 | |
| 6548 | tabla_codec_shutdown_hs_removal_detect(codec); |
| 6549 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 6550 | if (!tabla->mclk_enabled) { |
Asish Bhattacharya | 486745a | 2012-01-20 06:41:53 +0530 | [diff] [blame] | 6551 | tabla_codec_disable_clock_block(codec); |
| 6552 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6553 | } |
| 6554 | |
| 6555 | tabla->mbhc_polling_active = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6556 | tabla->mbhc_state = MBHC_STATE_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6557 | } |
| 6558 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6559 | static irqreturn_t tabla_hphl_ocp_irq(int irq, void *data) |
| 6560 | { |
| 6561 | struct tabla_priv *tabla = data; |
| 6562 | struct snd_soc_codec *codec; |
| 6563 | |
| 6564 | pr_info("%s: received HPHL OCP irq\n", __func__); |
| 6565 | |
| 6566 | if (tabla) { |
| 6567 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 6568 | if ((tabla->hphlocp_cnt < TABLA_OCP_ATTEMPT) && |
| 6569 | (!tabla->hphrocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6570 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 6571 | tabla->hphlocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6572 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6573 | 0x00); |
| 6574 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6575 | 0x10); |
| 6576 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6577 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6578 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6579 | tabla->hph_status |= SND_JACK_OC_HPHL; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6580 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6581 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6582 | tabla->mbhc_cfg.headset_jack, |
| 6583 | tabla->hph_status, |
| 6584 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6585 | } |
| 6586 | } else { |
| 6587 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6588 | } |
| 6589 | |
| 6590 | return IRQ_HANDLED; |
| 6591 | } |
| 6592 | |
| 6593 | static irqreturn_t tabla_hphr_ocp_irq(int irq, void *data) |
| 6594 | { |
| 6595 | struct tabla_priv *tabla = data; |
| 6596 | struct snd_soc_codec *codec; |
| 6597 | |
| 6598 | pr_info("%s: received HPHR OCP irq\n", __func__); |
| 6599 | |
| 6600 | if (tabla) { |
| 6601 | codec = tabla->codec; |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 6602 | if ((tabla->hphrocp_cnt < TABLA_OCP_ATTEMPT) && |
| 6603 | (!tabla->hphlocp_cnt)) { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6604 | pr_info("%s: retry\n", __func__); |
Patrick Lai | c2d833d | 2012-07-06 22:42:52 -0700 | [diff] [blame] | 6605 | tabla->hphrocp_cnt++; |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6606 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6607 | 0x00); |
| 6608 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, |
| 6609 | 0x10); |
| 6610 | } else { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 6611 | wcd9xxx_disable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 6612 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6613 | tabla->hph_status |= SND_JACK_OC_HPHR; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6614 | if (tabla->mbhc_cfg.headset_jack) |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 6615 | tabla_snd_soc_jack_report(tabla, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6616 | tabla->mbhc_cfg.headset_jack, |
| 6617 | tabla->hph_status, |
| 6618 | TABLA_JACK_MASK); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 6619 | } |
| 6620 | } else { |
| 6621 | pr_err("%s: Bad tabla private data\n", __func__); |
| 6622 | } |
| 6623 | |
| 6624 | return IRQ_HANDLED; |
| 6625 | } |
| 6626 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6627 | static bool tabla_is_inval_ins_range(struct snd_soc_codec *codec, |
| 6628 | s32 mic_volt, bool highhph, bool *highv) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6629 | { |
| 6630 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6631 | bool invalid = false; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6632 | s16 v_hs_max; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6633 | |
| 6634 | /* Perform this check only when the high voltage headphone |
| 6635 | * needs to be considered as invalid |
| 6636 | */ |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6637 | v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6638 | *highv = mic_volt > v_hs_max; |
| 6639 | if (!highhph && *highv) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6640 | invalid = true; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 6641 | else if (mic_volt < tabla->mbhc_data.v_inval_ins_high && |
| 6642 | (mic_volt > tabla->mbhc_data.v_inval_ins_low)) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6643 | invalid = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6644 | |
| 6645 | return invalid; |
| 6646 | } |
| 6647 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6648 | static bool tabla_is_inval_ins_delta(struct snd_soc_codec *codec, |
| 6649 | int mic_volt, int mic_volt_prev, |
| 6650 | int threshold) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6651 | { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6652 | return abs(mic_volt - mic_volt_prev) > threshold; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6653 | } |
| 6654 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6655 | /* called under codec_resource_lock acquisition */ |
| 6656 | void tabla_find_plug_and_report(struct snd_soc_codec *codec, |
| 6657 | enum tabla_mbhc_plug_type plug_type) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 6658 | { |
| 6659 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6660 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6661 | pr_debug("%s: enter current_plug(%d) new_plug(%d)\n", |
| 6662 | __func__, tabla->current_plug, plug_type); |
| 6663 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6664 | if (plug_type == PLUG_TYPE_HEADPHONE && |
| 6665 | tabla->current_plug == PLUG_TYPE_NONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6666 | /* Nothing was reported previously |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6667 | * report a headphone or unsupported |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6668 | */ |
| 6669 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 6670 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6671 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6672 | if (!tabla->mbhc_cfg.detect_extn_cable) { |
| 6673 | if (tabla->current_plug == PLUG_TYPE_HEADSET) |
| 6674 | tabla_codec_report_plug(codec, 0, |
| 6675 | SND_JACK_HEADSET); |
| 6676 | else if (tabla->current_plug == PLUG_TYPE_HEADPHONE) |
| 6677 | tabla_codec_report_plug(codec, 0, |
| 6678 | SND_JACK_HEADPHONE); |
| 6679 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6680 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 6681 | tabla_codec_cleanup_hs_polling(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6682 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 6683 | /* If Headphone was reported previously, this will |
| 6684 | * only report the mic line |
| 6685 | */ |
| 6686 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame^] | 6687 | if (!tabla->mbhc_micbias_switched && |
| 6688 | tabla_is_hph_pa_on(codec)) { |
| 6689 | /*If the headphone path is on, switch the micbias |
| 6690 | to VDDIO to avoid noise due to button polling */ |
| 6691 | tabla_codec_switch_micbias(codec, 1); |
| 6692 | pr_debug("%s: HPH path is still up\n", __func__); |
| 6693 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6694 | msleep(100); |
| 6695 | tabla_codec_start_hs_polling(codec); |
| 6696 | } else if (plug_type == PLUG_TYPE_HIGH_HPH) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6697 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 6698 | /* High impedance device found. Report as LINEOUT*/ |
| 6699 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 6700 | tabla_codec_cleanup_hs_polling(codec); |
| 6701 | pr_debug("%s: setup mic trigger for further detection\n", |
| 6702 | __func__); |
| 6703 | tabla->lpi_enabled = true; |
| 6704 | /* |
| 6705 | * Do not enable HPHL trigger. If playback is active, |
| 6706 | * it might lead to continuous false HPHL triggers |
| 6707 | */ |
| 6708 | tabla_codec_enable_hs_detect(codec, 1, |
| 6709 | MBHC_USE_MB_TRIGGER, |
| 6710 | false); |
| 6711 | } else { |
| 6712 | if (tabla->current_plug == PLUG_TYPE_NONE) |
| 6713 | tabla_codec_report_plug(codec, 1, |
| 6714 | SND_JACK_HEADPHONE); |
| 6715 | tabla_codec_cleanup_hs_polling(codec); |
| 6716 | pr_debug("setup mic trigger for further detection\n"); |
| 6717 | tabla->lpi_enabled = true; |
| 6718 | tabla_codec_enable_hs_detect(codec, 1, |
| 6719 | MBHC_USE_MB_TRIGGER | |
| 6720 | MBHC_USE_HPHL_TRIGGER, |
| 6721 | false); |
| 6722 | } |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6723 | } else { |
| 6724 | WARN(1, "Unexpected current plug_type %d, plug_type %d\n", |
| 6725 | tabla->current_plug, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6726 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6727 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6728 | } |
| 6729 | |
| 6730 | /* should be called under interrupt context that hold suspend */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 6731 | static void tabla_schedule_hs_detect_plug(struct tabla_priv *tabla, |
| 6732 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6733 | { |
| 6734 | pr_debug("%s: scheduling tabla_hs_correct_gpio_plug\n", __func__); |
| 6735 | tabla->hs_detect_work_stop = false; |
| 6736 | wcd9xxx_lock_sleep(tabla->codec->control_data); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 6737 | schedule_work(correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
| 6740 | /* called under codec_resource_lock acquisition */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 6741 | static void tabla_cancel_hs_detect_plug(struct tabla_priv *tabla, |
| 6742 | struct work_struct *correct_plug_work) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6743 | { |
| 6744 | pr_debug("%s: canceling hs_correct_plug_work\n", __func__); |
| 6745 | tabla->hs_detect_work_stop = true; |
| 6746 | wmb(); |
| 6747 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 6748 | if (cancel_work_sync(correct_plug_work)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6749 | pr_debug("%s: hs_correct_plug_work is canceled\n", __func__); |
| 6750 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 6751 | } |
| 6752 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6753 | } |
| 6754 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6755 | static bool tabla_hs_gpio_level_remove(struct tabla_priv *tabla) |
| 6756 | { |
| 6757 | return (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) != |
| 6758 | tabla->mbhc_cfg.gpio_level_insert); |
| 6759 | } |
| 6760 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6761 | /* called under codec_resource_lock acquisition */ |
| 6762 | static void tabla_codec_hphr_gnd_switch(struct snd_soc_codec *codec, bool on) |
| 6763 | { |
| 6764 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, on); |
| 6765 | if (on) |
| 6766 | usleep_range(5000, 5000); |
| 6767 | } |
| 6768 | |
| 6769 | /* called under codec_resource_lock acquisition and mbhc override = 1 */ |
| 6770 | static enum tabla_mbhc_plug_type |
| 6771 | tabla_codec_get_plug_type(struct snd_soc_codec *codec, bool highhph) |
| 6772 | { |
| 6773 | int i; |
| 6774 | bool gndswitch, vddioswitch; |
| 6775 | int scaled; |
| 6776 | struct tabla_mbhc_plug_type_cfg *plug_type_ptr; |
| 6777 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6778 | int num_det = MBHC_NUM_DCE_PLUG_DETECT + 1; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6779 | enum tabla_mbhc_plug_type plug_type[num_det]; |
| 6780 | s16 mb_v[num_det]; |
| 6781 | s32 mic_mv[num_det]; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6782 | bool inval; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 6783 | bool highdelta = false; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6784 | bool ahighv = false, highv; |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6785 | bool gndmicswapped = false; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6786 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6787 | pr_debug("%s: enter\n", __func__); |
| 6788 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6789 | /* make sure override is on */ |
| 6790 | WARN_ON(!(snd_soc_read(codec, TABLA_A_CDC_MBHC_B1_CTL) & 0x04)); |
| 6791 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6792 | /* GND and MIC swap detection requires at least 2 rounds of DCE */ |
| 6793 | BUG_ON(num_det < 2); |
| 6794 | |
| 6795 | plug_type_ptr = |
| 6796 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 6797 | |
| 6798 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6799 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6800 | /* performs DCEs for N times |
| 6801 | * 1st: check if voltage is in invalid range |
| 6802 | * 2nd - N-2nd: check voltage range and delta |
| 6803 | * N-1st: check voltage range, delta with HPHR GND switch |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6804 | * Nth: check voltage range with VDDIO switch */ |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6805 | for (i = 0; i < num_det; i++) { |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6806 | gndswitch = (i == (num_det - 2)); |
| 6807 | vddioswitch = (i == (num_det - 1)) || (i == (num_det - 2)); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6808 | if (i == 0) { |
| 6809 | mb_v[i] = tabla_codec_setup_hs_polling(codec); |
| 6810 | 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] | 6811 | inval = tabla_is_inval_ins_range(codec, mic_mv[i], |
| 6812 | highhph, &highv); |
| 6813 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6814 | scaled = mic_mv[i]; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6815 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6816 | if (vddioswitch) |
| 6817 | __tabla_codec_switch_micbias(tabla->codec, 1, |
| 6818 | false, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6819 | if (gndswitch) |
| 6820 | tabla_codec_hphr_gnd_switch(codec, true); |
| 6821 | mb_v[i] = __tabla_codec_sta_dce(codec, 1, true, true); |
| 6822 | 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] | 6823 | if (vddioswitch) |
| 6824 | scaled = tabla_scale_v_micb_vddio(tabla, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6825 | mic_mv[i], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6826 | false); |
| 6827 | else |
| 6828 | scaled = mic_mv[i]; |
| 6829 | /* !gndswitch & vddioswitch means the previous DCE |
| 6830 | * was done with gndswitch, don't compare with DCE |
| 6831 | * with gndswitch */ |
| 6832 | highdelta = tabla_is_inval_ins_delta(codec, scaled, |
Joonwoo Park | 6a5a4f1 | 2012-06-15 15:56:25 -0700 | [diff] [blame] | 6833 | mic_mv[i - 1], |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6834 | TABLA_MBHC_FAKE_INS_DELTA_SCALED_MV); |
| 6835 | inval = (tabla_is_inval_ins_range(codec, mic_mv[i], |
| 6836 | highhph, &highv) || |
| 6837 | highdelta); |
| 6838 | ahighv |= highv; |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6839 | if (gndswitch) |
| 6840 | tabla_codec_hphr_gnd_switch(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6841 | if (vddioswitch) |
| 6842 | __tabla_codec_switch_micbias(tabla->codec, 0, |
| 6843 | false, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6844 | } |
| 6845 | 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] | 6846 | "VDDIO %d, inval %d\n", __func__, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6847 | i + 1, mb_v[i] & 0xffff, mic_mv[i], scaled, gndswitch, |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6848 | vddioswitch, inval); |
| 6849 | /* don't need to run further DCEs */ |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 6850 | if ((ahighv || !vddioswitch) && inval) |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6851 | break; |
| 6852 | mic_mv[i] = scaled; |
Ravi Kumar Alamanda | 1c713b2 | 2012-09-27 17:14:27 -0700 | [diff] [blame] | 6853 | |
| 6854 | /* |
| 6855 | * claim UNSUPPORTED plug insertion when |
| 6856 | * good headset is detected but HPHR GND switch makes |
| 6857 | * delta difference |
| 6858 | */ |
| 6859 | if (i == (num_det - 2) && highdelta && !ahighv) |
| 6860 | gndmicswapped = true; |
| 6861 | else if (i == (num_det - 1) && inval) { |
| 6862 | if (gndmicswapped) |
| 6863 | plug_type[0] = PLUG_TYPE_GND_MIC_SWAP; |
| 6864 | else |
| 6865 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6866 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6867 | } |
| 6868 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6869 | for (i = 0; (plug_type[0] != PLUG_TYPE_GND_MIC_SWAP && !inval) && |
| 6870 | i < num_det; i++) { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6871 | /* |
| 6872 | * If we are here, means none of the all |
| 6873 | * measurements are fake, continue plug type detection. |
| 6874 | * If all three measurements do not produce same |
| 6875 | * plug type, restart insertion detection |
| 6876 | */ |
| 6877 | if (mic_mv[i] < plug_type_ptr->v_no_mic) { |
| 6878 | plug_type[i] = PLUG_TYPE_HEADPHONE; |
| 6879 | pr_debug("%s: Detect attempt %d, detected Headphone\n", |
| 6880 | __func__, i); |
| 6881 | } else if (highhph && (mic_mv[i] > plug_type_ptr->v_hs_max)) { |
| 6882 | plug_type[i] = PLUG_TYPE_HIGH_HPH; |
| 6883 | pr_debug("%s: Detect attempt %d, detected High " |
| 6884 | "Headphone\n", __func__, i); |
| 6885 | } else { |
| 6886 | plug_type[i] = PLUG_TYPE_HEADSET; |
| 6887 | pr_debug("%s: Detect attempt %d, detected Headset\n", |
| 6888 | __func__, i); |
| 6889 | } |
| 6890 | |
| 6891 | if (i > 0 && (plug_type[i - 1] != plug_type[i])) { |
| 6892 | pr_err("%s: Detect attempt %d and %d are not same", |
| 6893 | __func__, i - 1, i); |
| 6894 | plug_type[0] = PLUG_TYPE_INVALID; |
| 6895 | inval = true; |
| 6896 | break; |
| 6897 | } |
| 6898 | } |
| 6899 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6900 | 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] | 6901 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6902 | return plug_type[0]; |
| 6903 | } |
| 6904 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6905 | static void tabla_hs_correct_gpio_plug(struct work_struct *work) |
| 6906 | { |
| 6907 | struct tabla_priv *tabla; |
| 6908 | struct snd_soc_codec *codec; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6909 | int retry = 0, pt_gnd_mic_swap_cnt = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6910 | bool correction = false; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6911 | enum tabla_mbhc_plug_type plug_type = PLUG_TYPE_INVALID; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6912 | unsigned long timeout; |
| 6913 | |
| 6914 | tabla = container_of(work, struct tabla_priv, hs_correct_plug_work); |
| 6915 | codec = tabla->codec; |
| 6916 | |
| 6917 | pr_debug("%s: enter\n", __func__); |
| 6918 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 6919 | |
| 6920 | /* Keep override on during entire plug type correction work. |
| 6921 | * |
| 6922 | * This is okay under the assumption that any GPIO irqs which use |
| 6923 | * MBHC block cancel and sync this work so override is off again |
| 6924 | * prior to GPIO interrupt handler's MBHC block usage. |
| 6925 | * Also while this correction work is running, we can guarantee |
| 6926 | * DAPM doesn't use any MBHC block as this work only runs with |
| 6927 | * headphone detection. |
| 6928 | */ |
| 6929 | tabla_turn_onoff_override(codec, true); |
| 6930 | |
| 6931 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 6932 | while (!time_after(jiffies, timeout)) { |
| 6933 | ++retry; |
| 6934 | rmb(); |
| 6935 | if (tabla->hs_detect_work_stop) { |
| 6936 | pr_debug("%s: stop requested\n", __func__); |
| 6937 | break; |
| 6938 | } |
| 6939 | |
| 6940 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 6941 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 6942 | pr_debug("%s: GPIO value is low\n", __func__); |
| 6943 | break; |
| 6944 | } |
| 6945 | |
| 6946 | /* can race with removal interrupt */ |
| 6947 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6948 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6949 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6950 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6951 | pr_debug("%s: attempt(%d) current_plug(%d) new_plug(%d)\n", |
| 6952 | __func__, retry, tabla->current_plug, plug_type); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6953 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6954 | pr_debug("Invalid plug in attempt # %d\n", retry); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6955 | if (!tabla->mbhc_cfg.detect_extn_cable && |
| 6956 | retry == NUM_ATTEMPTS_TO_REPORT && |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6957 | tabla->current_plug == PLUG_TYPE_NONE) { |
| 6958 | tabla_codec_report_plug(codec, 1, |
| 6959 | SND_JACK_HEADPHONE); |
| 6960 | } |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6961 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6962 | pr_debug("Good headphone detected, continue polling mic\n"); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 6963 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 6964 | if (tabla->current_plug != plug_type) |
| 6965 | tabla_codec_report_plug(codec, 1, |
| 6966 | SND_JACK_HEADPHONE); |
| 6967 | } else if (tabla->current_plug == PLUG_TYPE_NONE) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6968 | tabla_codec_report_plug(codec, 1, |
| 6969 | SND_JACK_HEADPHONE); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6970 | } else { |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6971 | if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 6972 | pt_gnd_mic_swap_cnt++; |
| 6973 | if (pt_gnd_mic_swap_cnt < |
| 6974 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) |
| 6975 | continue; |
| 6976 | else if (pt_gnd_mic_swap_cnt > |
| 6977 | TABLA_MBHC_GND_MIC_SWAP_THRESHOLD) { |
| 6978 | /* This is due to GND/MIC switch didn't |
| 6979 | * work, Report unsupported plug */ |
| 6980 | } else if (tabla->mbhc_cfg.swap_gnd_mic) { |
| 6981 | /* if switch is toggled, check again, |
| 6982 | * otherwise report unsupported plug */ |
| 6983 | if (tabla->mbhc_cfg.swap_gnd_mic(codec)) |
| 6984 | continue; |
| 6985 | } |
| 6986 | } else |
| 6987 | pt_gnd_mic_swap_cnt = 0; |
| 6988 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6989 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 6990 | /* Turn off override */ |
| 6991 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 6992 | /* The valid plug also includes PLUG_TYPE_GND_MIC_SWAP |
| 6993 | */ |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6994 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6995 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 6996 | pr_debug("Attempt %d found correct plug %d\n", retry, |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 6997 | plug_type); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 6998 | correction = true; |
| 6999 | break; |
| 7000 | } |
| 7001 | } |
| 7002 | |
| 7003 | /* Turn off override */ |
| 7004 | if (!correction) |
| 7005 | tabla_turn_onoff_override(codec, false); |
| 7006 | |
| 7007 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7008 | |
| 7009 | if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7010 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7011 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE || |
| 7012 | tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP || |
| 7013 | tabla->current_plug == PLUG_TYPE_INVALID || |
| 7014 | plug_type == PLUG_TYPE_INVALID) { |
| 7015 | /* Enable removal detection */ |
| 7016 | tabla_codec_cleanup_hs_polling(codec); |
| 7017 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 7018 | } |
| 7019 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7020 | } |
| 7021 | pr_debug("%s: leave current_plug(%d)\n", |
| 7022 | __func__, tabla->current_plug); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7023 | /* unlock sleep */ |
| 7024 | wcd9xxx_unlock_sleep(tabla->codec->control_data); |
| 7025 | } |
| 7026 | |
| 7027 | /* called under codec_resource_lock acquisition */ |
| 7028 | static void tabla_codec_decide_gpio_plug(struct snd_soc_codec *codec) |
| 7029 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7030 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7031 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7032 | |
| 7033 | pr_debug("%s: enter\n", __func__); |
| 7034 | |
| 7035 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7036 | plug_type = tabla_codec_get_plug_type(codec, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7037 | tabla_turn_onoff_override(codec, false); |
| 7038 | |
| 7039 | if (tabla_hs_gpio_level_remove(tabla)) { |
| 7040 | pr_debug("%s: GPIO value is low when determining plug\n", |
| 7041 | __func__); |
| 7042 | return; |
| 7043 | } |
| 7044 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7045 | if (plug_type == PLUG_TYPE_INVALID || |
| 7046 | plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7047 | tabla_schedule_hs_detect_plug(tabla, |
| 7048 | &tabla->hs_correct_plug_work); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7049 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7050 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7051 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7052 | tabla_schedule_hs_detect_plug(tabla, |
| 7053 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7054 | } else { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7055 | pr_debug("%s: Valid plug found, determine plug type %d\n", |
| 7056 | __func__, plug_type); |
| 7057 | tabla_find_plug_and_report(codec, plug_type); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7058 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7059 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | /* called under codec_resource_lock acquisition */ |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7063 | static void tabla_codec_detect_plug_type(struct snd_soc_codec *codec) |
| 7064 | { |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7065 | enum tabla_mbhc_plug_type plug_type; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7066 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7067 | const struct tabla_mbhc_plug_detect_cfg *plug_det = |
| 7068 | TABLA_MBHC_CAL_PLUG_DET_PTR(tabla->mbhc_cfg.calibration); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7069 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7070 | /* Turn on the override, |
| 7071 | * tabla_codec_setup_hs_polling requires override on */ |
| 7072 | tabla_turn_onoff_override(codec, true); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7073 | |
| 7074 | if (plug_det->t_ins_complete > 20) |
| 7075 | msleep(plug_det->t_ins_complete); |
| 7076 | else |
| 7077 | usleep_range(plug_det->t_ins_complete * 1000, |
| 7078 | plug_det->t_ins_complete * 1000); |
| 7079 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7080 | if (tabla->mbhc_cfg.gpio) { |
| 7081 | /* Turn off the override */ |
| 7082 | tabla_turn_onoff_override(codec, false); |
| 7083 | if (tabla_hs_gpio_level_remove(tabla)) |
| 7084 | pr_debug("%s: GPIO value is low when determining " |
| 7085 | "plug\n", __func__); |
| 7086 | else |
| 7087 | tabla_codec_decide_gpio_plug(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7088 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7089 | return; |
| 7090 | } |
| 7091 | |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7092 | plug_type = tabla_codec_get_plug_type(codec, false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7093 | tabla_turn_onoff_override(codec, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7094 | |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7095 | if (plug_type == PLUG_TYPE_INVALID) { |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7096 | pr_debug("%s: Invalid plug type detected\n", __func__); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7097 | 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] | 7098 | tabla_codec_cleanup_hs_polling(codec); |
| 7099 | tabla_codec_enable_hs_detect(codec, 1, |
| 7100 | MBHC_USE_MB_TRIGGER | |
| 7101 | MBHC_USE_HPHL_TRIGGER, false); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7102 | } else if (plug_type == PLUG_TYPE_GND_MIC_SWAP) { |
| 7103 | pr_debug("%s: GND-MIC swapped plug type detected\n", __func__); |
| 7104 | tabla_codec_report_plug(codec, 1, SND_JACK_UNSUPPORTED); |
| 7105 | tabla_codec_cleanup_hs_polling(codec); |
| 7106 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7107 | } else if (plug_type == PLUG_TYPE_HEADPHONE) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7108 | pr_debug("%s: Headphone Detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7109 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADPHONE); |
| 7110 | tabla_codec_cleanup_hs_polling(codec); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7111 | tabla_schedule_hs_detect_plug(tabla, |
| 7112 | &tabla->hs_correct_plug_work_nogpio); |
Joonwoo Park | 4195672 | 2012-04-18 13:13:07 -0700 | [diff] [blame] | 7113 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7114 | pr_debug("%s: Headset detected\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7115 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7116 | /* avoid false button press detect */ |
| 7117 | msleep(50); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7118 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7119 | } else if (tabla->mbhc_cfg.detect_extn_cable && |
| 7120 | plug_type == PLUG_TYPE_HIGH_HPH) { |
| 7121 | pr_debug("%s: High impedance plug type detected\n", __func__); |
| 7122 | tabla_codec_report_plug(codec, 1, SND_JACK_LINEOUT); |
| 7123 | /* Enable insertion detection on the other end of cable */ |
| 7124 | tabla_codec_cleanup_hs_polling(codec); |
| 7125 | tabla_codec_enable_hs_detect(codec, 1, |
| 7126 | MBHC_USE_MB_TRIGGER, false); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7127 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7128 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7129 | } |
| 7130 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7131 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7132 | 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] | 7133 | { |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7134 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7135 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7136 | |
| 7137 | if (!is_removal) { |
| 7138 | pr_debug("%s: MIC trigger insertion interrupt\n", __func__); |
| 7139 | |
| 7140 | rmb(); |
| 7141 | if (priv->lpi_enabled) |
| 7142 | msleep(100); |
| 7143 | |
| 7144 | rmb(); |
| 7145 | if (!priv->lpi_enabled) { |
| 7146 | pr_debug("%s: lpi is disabled\n", __func__); |
| 7147 | } else if (gpio_get_value_cansleep(priv->mbhc_cfg.gpio) == |
| 7148 | priv->mbhc_cfg.gpio_level_insert) { |
| 7149 | pr_debug("%s: Valid insertion, " |
| 7150 | "detect plug type\n", __func__); |
| 7151 | tabla_codec_decide_gpio_plug(codec); |
| 7152 | } else { |
| 7153 | pr_debug("%s: Invalid insertion, " |
| 7154 | "stop plug detection\n", __func__); |
| 7155 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7156 | } else if (tabla->mbhc_cfg.detect_extn_cable) { |
| 7157 | pr_debug("%s: Removal\n", __func__); |
| 7158 | if (!tabla_hs_gpio_level_remove(tabla)) { |
| 7159 | /* |
| 7160 | * gpio says, something is still inserted, could be |
| 7161 | * extension cable i.e. headset is removed from |
| 7162 | * extension cable |
| 7163 | */ |
| 7164 | /* cancel detect plug */ |
| 7165 | tabla_cancel_hs_detect_plug(tabla, |
| 7166 | &tabla->hs_correct_plug_work); |
| 7167 | tabla_codec_decide_gpio_plug(codec); |
| 7168 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7169 | } else { |
| 7170 | pr_err("%s: GPIO used, invalid MBHC Removal\n", __func__); |
| 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7175 | static void tabla_hs_insert_irq_nogpio(struct tabla_priv *priv, bool is_removal, |
| 7176 | bool is_mb_trigger) |
| 7177 | { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7178 | int ret; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7179 | struct snd_soc_codec *codec = priv->codec; |
| 7180 | struct wcd9xxx *core = dev_get_drvdata(priv->codec->dev->parent); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7181 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7182 | |
| 7183 | /* Cancel possibly running hs_detect_work */ |
| 7184 | tabla_cancel_hs_detect_plug(tabla, |
| 7185 | &tabla->hs_correct_plug_work_nogpio); |
Bhalchandra Gajare | 7fc7233 | 2011-10-13 19:01:55 -0700 | [diff] [blame] | 7186 | |
| 7187 | if (is_removal) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7188 | |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 7189 | /* |
| 7190 | * If headphone is removed while playback is in progress, |
| 7191 | * it is possible that micbias will be switched to VDDIO. |
| 7192 | */ |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7193 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7194 | if (priv->current_plug == PLUG_TYPE_HEADPHONE) |
| 7195 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 7196 | else if (priv->current_plug == PLUG_TYPE_GND_MIC_SWAP) |
| 7197 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 7198 | else |
| 7199 | WARN(1, "%s: Unexpected current plug type %d\n", |
| 7200 | __func__, priv->current_plug); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7201 | tabla_codec_shutdown_hs_removal_detect(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7202 | tabla_codec_enable_hs_detect(codec, 1, |
| 7203 | MBHC_USE_MB_TRIGGER | |
| 7204 | MBHC_USE_HPHL_TRIGGER, |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7205 | true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7206 | } else if (is_mb_trigger && !is_removal) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7207 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7208 | __func__); |
| 7209 | wcd9xxx_lock_sleep(core); |
| 7210 | if (schedule_delayed_work(&priv->mbhc_insert_dwork, |
| 7211 | usecs_to_jiffies(1000000)) == 0) { |
| 7212 | pr_err("%s: mbhc_insert_dwork is already scheduled\n", |
| 7213 | __func__); |
| 7214 | wcd9xxx_unlock_sleep(core); |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 7215 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7216 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7217 | false); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7218 | } else { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7219 | ret = cancel_delayed_work(&priv->mbhc_insert_dwork); |
| 7220 | if (ret != 0) { |
| 7221 | pr_debug("%s: Complete plug insertion, Detecting plug " |
| 7222 | "type\n", __func__); |
| 7223 | tabla_codec_detect_plug_type(codec); |
| 7224 | wcd9xxx_unlock_sleep(core); |
| 7225 | } else { |
| 7226 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7227 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7228 | pr_err("%s: Error detecting plug insertion\n", |
| 7229 | __func__); |
| 7230 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7231 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7232 | } |
Bhalchandra Gajare | 9494fa26 | 2011-11-10 19:25:59 -0800 | [diff] [blame] | 7233 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7234 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7235 | static void tabla_hs_insert_irq_extn(struct tabla_priv *priv, |
| 7236 | bool is_mb_trigger) |
| 7237 | { |
| 7238 | struct snd_soc_codec *codec = priv->codec; |
| 7239 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7240 | |
| 7241 | /* Cancel possibly running hs_detect_work */ |
| 7242 | tabla_cancel_hs_detect_plug(tabla, |
| 7243 | &tabla->hs_correct_plug_work); |
| 7244 | |
| 7245 | if (is_mb_trigger) { |
| 7246 | pr_debug("%s: Waiting for Headphone left trigger\n", |
| 7247 | __func__); |
| 7248 | tabla_codec_enable_hs_detect(codec, 1, MBHC_USE_HPHL_TRIGGER, |
| 7249 | false); |
| 7250 | } else { |
| 7251 | pr_debug("%s: HPHL trigger received, detecting plug type\n", |
| 7252 | __func__); |
| 7253 | tabla_codec_detect_plug_type(codec); |
| 7254 | } |
| 7255 | } |
| 7256 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7257 | static irqreturn_t tabla_hs_insert_irq(int irq, void *data) |
| 7258 | { |
| 7259 | bool is_mb_trigger, is_removal; |
| 7260 | struct tabla_priv *priv = data; |
| 7261 | struct snd_soc_codec *codec = priv->codec; |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7262 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7263 | pr_debug("%s: enter\n", __func__); |
| 7264 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7265 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7266 | |
| 7267 | is_mb_trigger = !!(snd_soc_read(codec, priv->mbhc_bias_regs.mbhc_reg) & |
| 7268 | 0x10); |
| 7269 | is_removal = !!(snd_soc_read(codec, TABLA_A_CDC_MBHC_INT_CTL) & 0x02); |
| 7270 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_INT_CTL, 0x03, 0x00); |
| 7271 | |
| 7272 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 7273 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 7274 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 7275 | snd_soc_update_bits(codec, priv->mbhc_bias_regs.ctl_reg, 0x01, 0x00); |
| 7276 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7277 | if (priv->mbhc_cfg.detect_extn_cable && |
| 7278 | priv->current_plug == PLUG_TYPE_HIGH_HPH) |
| 7279 | tabla_hs_insert_irq_extn(priv, is_mb_trigger); |
| 7280 | else if (priv->mbhc_cfg.gpio) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7281 | tabla_hs_insert_irq_gpio(priv, is_removal); |
| 7282 | else |
| 7283 | tabla_hs_insert_irq_nogpio(priv, is_removal, is_mb_trigger); |
| 7284 | |
| 7285 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 7286 | return IRQ_HANDLED; |
| 7287 | } |
| 7288 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7289 | static bool is_valid_mic_voltage(struct snd_soc_codec *codec, s32 mic_mv) |
| 7290 | { |
| 7291 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7292 | const struct tabla_mbhc_plug_type_cfg *plug_type = |
| 7293 | TABLA_MBHC_CAL_PLUG_TYPE_PTR(tabla->mbhc_cfg.calibration); |
| 7294 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7295 | |
| 7296 | 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] | 7297 | && (mic_mv < v_hs_max)) ? true : false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7298 | } |
| 7299 | |
| 7300 | /* called under codec_resource_lock acquisition |
| 7301 | * returns true if mic voltage range is back to normal insertion |
| 7302 | * returns false either if timedout or removed */ |
| 7303 | static bool tabla_hs_remove_settle(struct snd_soc_codec *codec) |
| 7304 | { |
| 7305 | int i; |
| 7306 | bool timedout, settled = false; |
| 7307 | s32 mic_mv[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7308 | short mb_v[MBHC_NUM_DCE_PLUG_DETECT]; |
| 7309 | unsigned long retry = 0, timeout; |
| 7310 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7311 | const s16 v_hs_max = tabla_get_current_v_hs_max(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7312 | |
| 7313 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7314 | while (!(timedout = time_after(jiffies, timeout))) { |
| 7315 | retry++; |
| 7316 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7317 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7318 | break; |
| 7319 | } |
| 7320 | |
| 7321 | if (tabla->mbhc_cfg.gpio) { |
| 7322 | if (retry > 1) |
| 7323 | msleep(250); |
| 7324 | else |
| 7325 | msleep(50); |
| 7326 | } |
| 7327 | |
| 7328 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7329 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7330 | break; |
| 7331 | } |
| 7332 | |
| 7333 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) { |
| 7334 | mb_v[i] = tabla_codec_sta_dce(codec, 1, true); |
| 7335 | mic_mv[i] = tabla_codec_sta_dce_v(codec, 1 , mb_v[i]); |
| 7336 | pr_debug("%s : DCE run %lu, mic_mv = %d(%x)\n", |
| 7337 | __func__, retry, mic_mv[i], mb_v[i]); |
| 7338 | } |
| 7339 | |
| 7340 | if (tabla->mbhc_cfg.gpio && tabla_hs_gpio_level_remove(tabla)) { |
| 7341 | pr_debug("%s: GPIO indicates removal\n", __func__); |
| 7342 | break; |
| 7343 | } |
| 7344 | |
| 7345 | if (tabla->current_plug == PLUG_TYPE_NONE) { |
| 7346 | pr_debug("%s : headset/headphone is removed\n", |
| 7347 | __func__); |
| 7348 | break; |
| 7349 | } |
| 7350 | |
| 7351 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
| 7352 | if (!is_valid_mic_voltage(codec, mic_mv[i])) |
| 7353 | break; |
| 7354 | |
| 7355 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7356 | pr_debug("%s: MIC voltage settled\n", __func__); |
| 7357 | settled = true; |
| 7358 | msleep(200); |
| 7359 | break; |
| 7360 | } |
| 7361 | |
| 7362 | /* only for non-GPIO remove irq */ |
| 7363 | if (!tabla->mbhc_cfg.gpio) { |
| 7364 | for (i = 0; i < MBHC_NUM_DCE_PLUG_DETECT; i++) |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7365 | if (mic_mv[i] < v_hs_max) |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7366 | break; |
| 7367 | if (i == MBHC_NUM_DCE_PLUG_DETECT) { |
| 7368 | pr_debug("%s: Headset is removed\n", __func__); |
| 7369 | break; |
| 7370 | } |
| 7371 | } |
| 7372 | } |
| 7373 | |
| 7374 | if (timedout) |
| 7375 | pr_debug("%s: Microphone did not settle in %d seconds\n", |
| 7376 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7377 | return settled; |
| 7378 | } |
| 7379 | |
| 7380 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7381 | static void tabla_hs_remove_irq_gpio(struct tabla_priv *priv) |
| 7382 | { |
| 7383 | struct snd_soc_codec *codec = priv->codec; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7384 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7385 | if (tabla_hs_remove_settle(codec)) |
| 7386 | tabla_codec_start_hs_polling(codec); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7387 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | /* called only from interrupt which is under codec_resource_lock acquisition */ |
| 7391 | static void tabla_hs_remove_irq_nogpio(struct tabla_priv *priv) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7392 | { |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7393 | short bias_value; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7394 | bool removed = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7395 | struct snd_soc_codec *codec = priv->codec; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7396 | const struct tabla_mbhc_general_cfg *generic = |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7397 | TABLA_MBHC_CAL_GENERAL_PTR(priv->mbhc_cfg.calibration); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7398 | int min_us = TABLA_FAKE_REMOVAL_MIN_PERIOD_MS * 1000; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7399 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7400 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7401 | if (priv->current_plug != PLUG_TYPE_HEADSET) { |
| 7402 | pr_debug("%s(): Headset is not inserted, ignore removal\n", |
| 7403 | __func__); |
| 7404 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7405 | 0x08, 0x08); |
| 7406 | return; |
| 7407 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7408 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 7409 | usleep_range(generic->t_shutdown_plug_rem, |
| 7410 | generic->t_shutdown_plug_rem); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7411 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7412 | do { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7413 | bias_value = tabla_codec_sta_dce(codec, 1, true); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7414 | pr_debug("%s: DCE %d,%d, %d us left\n", __func__, bias_value, |
| 7415 | tabla_codec_sta_dce_v(codec, 1, bias_value), min_us); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7416 | if (bias_value < tabla_get_current_v_ins(priv, false)) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7417 | pr_debug("%s: checking false removal\n", __func__); |
| 7418 | msleep(500); |
| 7419 | removed = !tabla_hs_remove_settle(codec); |
| 7420 | pr_debug("%s: headset %sactually removed\n", __func__, |
| 7421 | removed ? "" : "not "); |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 7422 | break; |
| 7423 | } |
| 7424 | min_us -= priv->mbhc_data.t_dce; |
| 7425 | } while (min_us > 0); |
Bradley Rubin | 89ffd0a | 2011-07-21 16:04:06 -0700 | [diff] [blame] | 7426 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7427 | if (removed) { |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7428 | if (priv->mbhc_cfg.detect_extn_cable) { |
| 7429 | if (!tabla_hs_gpio_level_remove(priv)) { |
| 7430 | /* |
| 7431 | * extension cable is still plugged in |
| 7432 | * report it as LINEOUT device |
| 7433 | */ |
| 7434 | tabla_codec_report_plug(codec, 1, |
| 7435 | SND_JACK_LINEOUT); |
| 7436 | tabla_codec_cleanup_hs_polling(codec); |
| 7437 | tabla_codec_enable_hs_detect(codec, 1, |
| 7438 | MBHC_USE_MB_TRIGGER, |
| 7439 | false); |
| 7440 | } |
| 7441 | } else { |
| 7442 | /* Cancel possibly running hs_detect_work */ |
| 7443 | tabla_cancel_hs_detect_plug(priv, |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7444 | &priv->hs_correct_plug_work_nogpio); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7445 | /* |
| 7446 | * If this removal is not false, first check the micbias |
| 7447 | * switch status and switch it to LDOH if it is already |
| 7448 | * switched to VDDIO. |
| 7449 | */ |
| 7450 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7451 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7452 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 7453 | tabla_codec_cleanup_hs_polling(codec); |
| 7454 | tabla_codec_enable_hs_detect(codec, 1, |
| 7455 | MBHC_USE_MB_TRIGGER | |
| 7456 | MBHC_USE_HPHL_TRIGGER, |
| 7457 | true); |
| 7458 | } |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7459 | } else { |
| 7460 | tabla_codec_start_hs_polling(codec); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7461 | } |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7462 | pr_debug("%s: leave\n", __func__); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7463 | } |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 7464 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7465 | static irqreturn_t tabla_hs_remove_irq(int irq, void *data) |
| 7466 | { |
| 7467 | struct tabla_priv *priv = data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7468 | bool vddio; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7469 | pr_debug("%s: enter, removal interrupt\n", __func__); |
| 7470 | |
| 7471 | TABLA_ACQUIRE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7472 | vddio = (priv->mbhc_data.micb_mv != VDDIO_MICBIAS_MV && |
| 7473 | priv->mbhc_micbias_switched); |
| 7474 | if (vddio) |
| 7475 | __tabla_codec_switch_micbias(priv->codec, 0, false, true); |
| 7476 | |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7477 | if ((priv->mbhc_cfg.detect_extn_cable && |
| 7478 | !tabla_hs_gpio_level_remove(priv)) || |
| 7479 | !priv->mbhc_cfg.gpio) { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7480 | tabla_hs_remove_irq_nogpio(priv); |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7481 | } else |
| 7482 | tabla_hs_remove_irq_gpio(priv); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7483 | |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7484 | /* if driver turned off vddio switch and headset is not removed, |
| 7485 | * turn on the vddio switch back, if headset is removed then vddio |
| 7486 | * switch is off by time now and shouldn't be turn on again from here */ |
| 7487 | if (vddio && priv->current_plug == PLUG_TYPE_HEADSET) |
| 7488 | __tabla_codec_switch_micbias(priv->codec, 1, true, true); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7489 | TABLA_RELEASE_LOCK(priv->codec_resource_lock); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 7490 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7491 | return IRQ_HANDLED; |
| 7492 | } |
| 7493 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7494 | void mbhc_insert_work(struct work_struct *work) |
| 7495 | { |
| 7496 | struct delayed_work *dwork; |
| 7497 | struct tabla_priv *tabla; |
| 7498 | struct snd_soc_codec *codec; |
| 7499 | struct wcd9xxx *tabla_core; |
| 7500 | |
| 7501 | dwork = to_delayed_work(work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7502 | tabla = container_of(dwork, struct tabla_priv, mbhc_insert_dwork); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7503 | codec = tabla->codec; |
| 7504 | tabla_core = dev_get_drvdata(codec->dev->parent); |
| 7505 | |
| 7506 | pr_debug("%s:\n", __func__); |
| 7507 | |
| 7508 | /* Turn off both HPH and MIC line schmitt triggers */ |
| 7509 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.mbhc_reg, 0x90, 0x00); |
| 7510 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x13, 0x00); |
| 7511 | 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] | 7512 | wcd9xxx_disable_irq_sync(codec->control_data, |
| 7513 | WCD9XXX_IRQ_MBHC_INSERTION); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7514 | tabla_codec_detect_plug_type(codec); |
| 7515 | wcd9xxx_unlock_sleep(tabla_core); |
| 7516 | } |
| 7517 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7518 | static void tabla_hs_gpio_handler(struct snd_soc_codec *codec) |
| 7519 | { |
| 7520 | bool insert; |
| 7521 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
| 7522 | bool is_removed = false; |
| 7523 | |
| 7524 | pr_debug("%s: enter\n", __func__); |
| 7525 | |
| 7526 | tabla->in_gpio_handler = true; |
| 7527 | /* Wait here for debounce time */ |
| 7528 | usleep_range(TABLA_GPIO_IRQ_DEBOUNCE_TIME_US, |
| 7529 | TABLA_GPIO_IRQ_DEBOUNCE_TIME_US); |
| 7530 | |
| 7531 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7532 | |
| 7533 | /* cancel pending button press */ |
| 7534 | if (tabla_cancel_btn_work(tabla)) |
| 7535 | pr_debug("%s: button press is canceled\n", __func__); |
| 7536 | |
| 7537 | insert = (gpio_get_value_cansleep(tabla->mbhc_cfg.gpio) == |
| 7538 | tabla->mbhc_cfg.gpio_level_insert); |
| 7539 | if ((tabla->current_plug == PLUG_TYPE_NONE) && insert) { |
| 7540 | tabla->lpi_enabled = false; |
| 7541 | wmb(); |
| 7542 | |
| 7543 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7544 | tabla_cancel_hs_detect_plug(tabla, |
| 7545 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7546 | |
| 7547 | /* Disable Mic Bias pull down and HPH Switch to GND */ |
| 7548 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 7549 | 0x00); |
| 7550 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x00); |
| 7551 | tabla_codec_detect_plug_type(codec); |
| 7552 | } else if ((tabla->current_plug != PLUG_TYPE_NONE) && !insert) { |
| 7553 | tabla->lpi_enabled = false; |
| 7554 | wmb(); |
| 7555 | |
| 7556 | /* cancel detect plug */ |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7557 | tabla_cancel_hs_detect_plug(tabla, |
| 7558 | &tabla->hs_correct_plug_work); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7559 | |
| 7560 | if (tabla->current_plug == PLUG_TYPE_HEADPHONE) { |
| 7561 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADPHONE); |
| 7562 | is_removed = true; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 7563 | } else if (tabla->current_plug == PLUG_TYPE_GND_MIC_SWAP) { |
| 7564 | tabla_codec_report_plug(codec, 0, SND_JACK_UNSUPPORTED); |
| 7565 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7566 | } else if (tabla->current_plug == PLUG_TYPE_HEADSET) { |
| 7567 | tabla_codec_pause_hs_polling(codec); |
| 7568 | tabla_codec_cleanup_hs_polling(codec); |
| 7569 | tabla_codec_report_plug(codec, 0, SND_JACK_HEADSET); |
| 7570 | is_removed = true; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 7571 | } else if (tabla->current_plug == PLUG_TYPE_HIGH_HPH) { |
| 7572 | tabla_codec_report_plug(codec, 0, SND_JACK_LINEOUT); |
| 7573 | is_removed = true; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7574 | } |
| 7575 | |
| 7576 | if (is_removed) { |
| 7577 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 7578 | snd_soc_update_bits(codec, |
| 7579 | tabla->mbhc_bias_regs.ctl_reg, 0x01, |
| 7580 | 0x01); |
| 7581 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, |
| 7582 | 0x01); |
| 7583 | /* Make sure mic trigger is turned off */ |
| 7584 | snd_soc_update_bits(codec, |
| 7585 | tabla->mbhc_bias_regs.ctl_reg, |
| 7586 | 0x01, 0x01); |
| 7587 | snd_soc_update_bits(codec, |
| 7588 | tabla->mbhc_bias_regs.mbhc_reg, |
| 7589 | 0x90, 0x00); |
| 7590 | /* Reset MBHC State Machine */ |
| 7591 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7592 | 0x08, 0x08); |
| 7593 | snd_soc_update_bits(codec, TABLA_A_CDC_MBHC_CLK_CTL, |
| 7594 | 0x08, 0x00); |
| 7595 | /* Turn off override */ |
| 7596 | tabla_turn_onoff_override(codec, false); |
Simmi Pateriya | 2137501 | 2012-11-26 23:06:01 +0530 | [diff] [blame^] | 7597 | tabla_codec_switch_micbias(codec, 0); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7598 | } |
| 7599 | } |
| 7600 | |
| 7601 | tabla->in_gpio_handler = false; |
| 7602 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7603 | pr_debug("%s: leave\n", __func__); |
| 7604 | } |
| 7605 | |
| 7606 | static irqreturn_t tabla_mechanical_plug_detect_irq(int irq, void *data) |
| 7607 | { |
| 7608 | int r = IRQ_HANDLED; |
| 7609 | struct snd_soc_codec *codec = data; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 7610 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7611 | |
| 7612 | if (unlikely(wcd9xxx_lock_sleep(codec->control_data) == false)) { |
| 7613 | pr_warn("%s: failed to hold suspend\n", __func__); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 7614 | /* |
| 7615 | * Give up this IRQ for now and resend this IRQ so IRQ can be |
| 7616 | * handled after system resume |
| 7617 | */ |
| 7618 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7619 | tabla->gpio_irq_resend = true; |
| 7620 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7621 | wake_lock_timeout(&tabla->irq_resend_wlock, HZ); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7622 | r = IRQ_NONE; |
| 7623 | } else { |
| 7624 | tabla_hs_gpio_handler(codec); |
| 7625 | wcd9xxx_unlock_sleep(codec->control_data); |
| 7626 | } |
| 7627 | |
| 7628 | return r; |
| 7629 | } |
| 7630 | |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7631 | static void tabla_hs_correct_plug_nogpio(struct work_struct *work) |
| 7632 | { |
| 7633 | struct tabla_priv *tabla; |
| 7634 | struct snd_soc_codec *codec; |
| 7635 | unsigned long timeout; |
| 7636 | int retry = 0; |
| 7637 | enum tabla_mbhc_plug_type plug_type; |
| 7638 | bool is_headset = false; |
| 7639 | |
| 7640 | pr_debug("%s(): Poll Microphone voltage for %d seconds\n", |
| 7641 | __func__, TABLA_HS_DETECT_PLUG_TIME_MS / 1000); |
| 7642 | |
| 7643 | tabla = container_of(work, struct tabla_priv, |
| 7644 | hs_correct_plug_work_nogpio); |
| 7645 | codec = tabla->codec; |
| 7646 | |
| 7647 | /* Make sure the MBHC mux is connected to MIC Path */ |
| 7648 | snd_soc_write(codec, TABLA_A_MBHC_SCALING_MUX_1, 0x84); |
| 7649 | |
| 7650 | /* setup for microphone polling */ |
| 7651 | tabla_turn_onoff_override(codec, true); |
| 7652 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 7653 | |
| 7654 | timeout = jiffies + msecs_to_jiffies(TABLA_HS_DETECT_PLUG_TIME_MS); |
| 7655 | while (!time_after(jiffies, timeout)) { |
| 7656 | ++retry; |
| 7657 | |
| 7658 | msleep(TABLA_HS_DETECT_PLUG_INERVAL_MS); |
| 7659 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7660 | plug_type = tabla_codec_get_plug_type(codec, false); |
| 7661 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7662 | |
| 7663 | if (plug_type == PLUG_TYPE_HIGH_HPH |
| 7664 | || plug_type == PLUG_TYPE_INVALID) { |
| 7665 | |
| 7666 | /* this means the plug is removed |
| 7667 | * End microphone polling and setup |
| 7668 | * for low power removal detection. |
| 7669 | */ |
| 7670 | pr_debug("%s(): Plug may be removed, setup removal\n", |
| 7671 | __func__); |
| 7672 | break; |
| 7673 | } else if (plug_type == PLUG_TYPE_HEADSET) { |
| 7674 | /* Plug is corrected from headphone to headset, |
| 7675 | * report headset and end the polling |
| 7676 | */ |
| 7677 | is_headset = true; |
| 7678 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 7679 | tabla_turn_onoff_override(codec, false); |
| 7680 | tabla_codec_report_plug(codec, 1, SND_JACK_HEADSET); |
| 7681 | tabla_codec_start_hs_polling(codec); |
| 7682 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 7683 | pr_debug("%s(): corrected from headphone to headset\n", |
| 7684 | __func__); |
| 7685 | break; |
| 7686 | } |
| 7687 | } |
| 7688 | |
| 7689 | /* Undo setup for microphone polling depending |
| 7690 | * result from polling |
| 7691 | */ |
| 7692 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 7693 | if (!is_headset) { |
Bhalchandra Gajare | afc8643 | 2012-08-23 13:44:07 -0700 | [diff] [blame] | 7694 | pr_debug("%s: Inserted headphone is not a headset\n", |
| 7695 | __func__); |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7696 | tabla_turn_onoff_override(codec, false); |
| 7697 | tabla_codec_cleanup_hs_polling(codec); |
| 7698 | tabla_codec_enable_hs_detect(codec, 0, 0, false); |
| 7699 | } |
| 7700 | wcd9xxx_unlock_sleep(codec->control_data); |
| 7701 | } |
| 7702 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7703 | static int tabla_mbhc_init_and_calibrate(struct tabla_priv *tabla) |
| 7704 | { |
| 7705 | int ret = 0; |
| 7706 | struct snd_soc_codec *codec = tabla->codec; |
| 7707 | |
| 7708 | tabla->mbhc_cfg.mclk_cb_fn(codec, 1, false); |
| 7709 | tabla_mbhc_init(codec); |
| 7710 | tabla_mbhc_cal(codec); |
| 7711 | tabla_mbhc_calc_thres(codec); |
| 7712 | tabla->mbhc_cfg.mclk_cb_fn(codec, 0, false); |
| 7713 | tabla_codec_calibrate_hs_polling(codec); |
| 7714 | if (!tabla->mbhc_cfg.gpio) { |
Bhalchandra Gajare | ac0bddf | 2012-04-06 12:33:54 -0700 | [diff] [blame] | 7715 | INIT_WORK(&tabla->hs_correct_plug_work_nogpio, |
| 7716 | tabla_hs_correct_plug_nogpio); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7717 | ret = tabla_codec_enable_hs_detect(codec, 1, |
| 7718 | MBHC_USE_MB_TRIGGER | |
| 7719 | MBHC_USE_HPHL_TRIGGER, |
| 7720 | false); |
| 7721 | |
| 7722 | if (IS_ERR_VALUE(ret)) |
| 7723 | pr_err("%s: Failed to setup MBHC detection\n", |
| 7724 | __func__); |
| 7725 | } else { |
| 7726 | /* Enable Mic Bias pull down and HPH Switch to GND */ |
| 7727 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.ctl_reg, |
| 7728 | 0x01, 0x01); |
| 7729 | snd_soc_update_bits(codec, TABLA_A_MBHC_HPH, 0x01, 0x01); |
| 7730 | INIT_WORK(&tabla->hs_correct_plug_work, |
| 7731 | tabla_hs_correct_gpio_plug); |
| 7732 | } |
| 7733 | |
| 7734 | if (!IS_ERR_VALUE(ret)) { |
| 7735 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, 0x10, 0x10); |
| 7736 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7737 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7738 | wcd9xxx_enable_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 7739 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7740 | |
| 7741 | if (tabla->mbhc_cfg.gpio) { |
| 7742 | ret = request_threaded_irq(tabla->mbhc_cfg.gpio_irq, |
| 7743 | NULL, |
| 7744 | tabla_mechanical_plug_detect_irq, |
| 7745 | (IRQF_TRIGGER_RISING | |
| 7746 | IRQF_TRIGGER_FALLING), |
| 7747 | "tabla-gpio", codec); |
| 7748 | if (!IS_ERR_VALUE(ret)) { |
| 7749 | ret = enable_irq_wake(tabla->mbhc_cfg.gpio_irq); |
| 7750 | /* Bootup time detection */ |
| 7751 | tabla_hs_gpio_handler(codec); |
| 7752 | } |
| 7753 | } |
| 7754 | } |
| 7755 | |
| 7756 | return ret; |
| 7757 | } |
| 7758 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7759 | static void mbhc_fw_read(struct work_struct *work) |
| 7760 | { |
| 7761 | struct delayed_work *dwork; |
| 7762 | struct tabla_priv *tabla; |
| 7763 | struct snd_soc_codec *codec; |
| 7764 | const struct firmware *fw; |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7765 | int ret = -1, retry = 0; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7766 | |
| 7767 | dwork = to_delayed_work(work); |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7768 | tabla = container_of(dwork, struct tabla_priv, mbhc_firmware_dwork); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7769 | codec = tabla->codec; |
| 7770 | |
| 7771 | while (retry < MBHC_FW_READ_ATTEMPTS) { |
| 7772 | retry++; |
| 7773 | pr_info("%s:Attempt %d to request MBHC firmware\n", |
| 7774 | __func__, retry); |
| 7775 | ret = request_firmware(&fw, "wcd9310/wcd9310_mbhc.bin", |
| 7776 | codec->dev); |
| 7777 | |
| 7778 | if (ret != 0) { |
| 7779 | usleep_range(MBHC_FW_READ_TIMEOUT, |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7780 | MBHC_FW_READ_TIMEOUT); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7781 | } else { |
| 7782 | pr_info("%s: MBHC Firmware read succesful\n", __func__); |
| 7783 | break; |
| 7784 | } |
| 7785 | } |
| 7786 | |
| 7787 | if (ret != 0) { |
| 7788 | pr_err("%s: Cannot load MBHC firmware use default cal\n", |
| 7789 | __func__); |
| 7790 | } else if (tabla_mbhc_fw_validate(fw) == false) { |
| 7791 | pr_err("%s: Invalid MBHC cal data size use default cal\n", |
| 7792 | __func__); |
| 7793 | release_firmware(fw); |
| 7794 | } else { |
| 7795 | tabla->mbhc_cfg.calibration = (void *)fw->data; |
| 7796 | tabla->mbhc_fw = fw; |
| 7797 | } |
| 7798 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7799 | (void) tabla_mbhc_init_and_calibrate(tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7800 | } |
| 7801 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7802 | int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7803 | const struct tabla_mbhc_config *cfg) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7804 | { |
| 7805 | struct tabla_priv *tabla; |
| 7806 | int rc = 0; |
| 7807 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7808 | if (!codec || !cfg->calibration) { |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7809 | pr_err("Error: no codec or calibration\n"); |
| 7810 | return -EINVAL; |
| 7811 | } |
| 7812 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7813 | if (cfg->mclk_rate != TABLA_MCLK_RATE_12288KHZ) { |
| 7814 | if (cfg->mclk_rate == TABLA_MCLK_RATE_9600KHZ) |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7815 | pr_err("Error: clock rate %dHz is not yet supported\n", |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7816 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7817 | else |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7818 | pr_err("Error: unsupported clock rate %d\n", |
| 7819 | cfg->mclk_rate); |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7820 | return -EINVAL; |
| 7821 | } |
| 7822 | |
| 7823 | tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7824 | tabla->mbhc_cfg = *cfg; |
| 7825 | tabla->in_gpio_handler = false; |
| 7826 | tabla->current_plug = PLUG_TYPE_NONE; |
| 7827 | tabla->lpi_enabled = false; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7828 | tabla_get_mbhc_micbias_regs(codec, &tabla->mbhc_bias_regs); |
| 7829 | |
| 7830 | /* Put CFILT in fast mode by default */ |
| 7831 | snd_soc_update_bits(codec, tabla->mbhc_bias_regs.cfilt_ctl, |
| 7832 | 0x40, TABLA_CFILT_FAST_MODE); |
| 7833 | INIT_DELAYED_WORK(&tabla->mbhc_firmware_dwork, mbhc_fw_read); |
| 7834 | INIT_DELAYED_WORK(&tabla->mbhc_btn_dwork, btn_lpress_fn); |
| 7835 | INIT_WORK(&tabla->hphlocp_work, hphlocp_off_report); |
| 7836 | INIT_WORK(&tabla->hphrocp_work, hphrocp_off_report); |
| 7837 | INIT_DELAYED_WORK(&tabla->mbhc_insert_dwork, mbhc_insert_work); |
| 7838 | |
Joonwoo Park | 1305bab | 2012-05-21 15:08:42 -0700 | [diff] [blame] | 7839 | if (!tabla->mbhc_cfg.read_fw_bin) |
| 7840 | rc = tabla_mbhc_init_and_calibrate(tabla); |
| 7841 | else |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7842 | schedule_delayed_work(&tabla->mbhc_firmware_dwork, |
| 7843 | usecs_to_jiffies(MBHC_FW_READ_TIMEOUT)); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 7844 | |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 7845 | return rc; |
| 7846 | } |
| 7847 | EXPORT_SYMBOL_GPL(tabla_hs_detect); |
| 7848 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7849 | static irqreturn_t tabla_slimbus_irq(int irq, void *data) |
| 7850 | { |
| 7851 | struct tabla_priv *priv = data; |
| 7852 | struct snd_soc_codec *codec = priv->codec; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7853 | struct tabla_priv *tabla_p = snd_soc_codec_get_drvdata(codec); |
| 7854 | int i, j, port_id, k, ch_mask_temp; |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 7855 | unsigned long slimbus_value; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7856 | u8 val; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7857 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) { |
| 7858 | slimbus_value = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7859 | TABLA_SLIM_PGD_PORT_INT_STATUS0 + i); |
| 7860 | for_each_set_bit(j, &slimbus_value, BITS_PER_BYTE) { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7861 | val = wcd9xxx_interface_reg_read(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7862 | TABLA_SLIM_PGD_PORT_INT_SOURCE0 + i*8 + j); |
| 7863 | if (val & 0x1) |
| 7864 | pr_err_ratelimited("overflow error on port %x," |
| 7865 | " value %x\n", i*8 + j, val); |
| 7866 | if (val & 0x2) |
| 7867 | pr_err_ratelimited("underflow error on port %x," |
| 7868 | " value %x\n", i*8 + j, val); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7869 | if (val & 0x4) { |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7870 | port_id = i*8 + j; |
| 7871 | for (k = 0; k < ARRAY_SIZE(tabla_dai); k++) { |
| 7872 | ch_mask_temp = 1 << port_id; |
Joonwoo Park | 9bbb4d1 | 2012-11-09 19:58:11 -0800 | [diff] [blame] | 7873 | pr_debug("%s: tabla_p->dai[%d].ch_mask = 0x%lx\n", |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 7874 | __func__, k, |
| 7875 | tabla_p->dai[k].ch_mask); |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7876 | if (ch_mask_temp & |
| 7877 | tabla_p->dai[k].ch_mask) { |
| 7878 | tabla_p->dai[k].ch_mask &= |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 7879 | ~ch_mask_temp; |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7880 | if (!tabla_p->dai[k].ch_mask) |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 7881 | wake_up( |
Swaminathan Sathappan | 2aa4c04 | 2012-06-26 13:08:45 -0700 | [diff] [blame] | 7882 | &tabla_p->dai[k].dai_wait); |
| 7883 | } |
| 7884 | } |
| 7885 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7886 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7887 | wcd9xxx_interface_reg_write(codec->control_data, |
Swaminathan Sathappan | 4bd3894 | 2012-07-17 11:31:31 -0700 | [diff] [blame] | 7888 | TABLA_SLIM_PGD_PORT_INT_CLR0 + i, slimbus_value); |
| 7889 | val = 0x0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7890 | } |
| 7891 | |
| 7892 | return IRQ_HANDLED; |
| 7893 | } |
| 7894 | |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7895 | static int tabla_handle_pdata(struct tabla_priv *tabla) |
| 7896 | { |
| 7897 | struct snd_soc_codec *codec = tabla->codec; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 7898 | struct wcd9xxx_pdata *pdata = tabla->pdata; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7899 | int k1, k2, k3, rc = 0; |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7900 | u8 leg_mode = pdata->amic_settings.legacy_mode; |
| 7901 | u8 txfe_bypass = pdata->amic_settings.txfe_enable; |
| 7902 | u8 txfe_buff = pdata->amic_settings.txfe_buff; |
| 7903 | u8 flag = pdata->amic_settings.use_pdata; |
| 7904 | u8 i = 0, j = 0; |
| 7905 | u8 val_txfe = 0, value = 0; |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7906 | |
| 7907 | if (!pdata) { |
| 7908 | rc = -ENODEV; |
| 7909 | goto done; |
| 7910 | } |
| 7911 | |
| 7912 | /* Make sure settings are correct */ |
| 7913 | if ((pdata->micbias.ldoh_v > TABLA_LDOH_2P85_V) || |
| 7914 | (pdata->micbias.bias1_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7915 | (pdata->micbias.bias2_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7916 | (pdata->micbias.bias3_cfilt_sel > TABLA_CFILT3_SEL) || |
| 7917 | (pdata->micbias.bias4_cfilt_sel > TABLA_CFILT3_SEL)) { |
| 7918 | rc = -EINVAL; |
| 7919 | goto done; |
| 7920 | } |
| 7921 | |
| 7922 | /* figure out k value */ |
| 7923 | k1 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7924 | pdata->micbias.cfilt1_mv); |
| 7925 | k2 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7926 | pdata->micbias.cfilt2_mv); |
| 7927 | k3 = tabla_find_k_value(pdata->micbias.ldoh_v, |
| 7928 | pdata->micbias.cfilt3_mv); |
| 7929 | |
| 7930 | if (IS_ERR_VALUE(k1) || IS_ERR_VALUE(k2) || IS_ERR_VALUE(k3)) { |
| 7931 | rc = -EINVAL; |
| 7932 | goto done; |
| 7933 | } |
| 7934 | |
| 7935 | /* Set voltage level and always use LDO */ |
| 7936 | snd_soc_update_bits(codec, TABLA_A_LDO_H_MODE_1, 0x0C, |
| 7937 | (pdata->micbias.ldoh_v << 2)); |
| 7938 | |
| 7939 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_1_VAL, 0xFC, |
| 7940 | (k1 << 2)); |
| 7941 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_2_VAL, 0xFC, |
| 7942 | (k2 << 2)); |
| 7943 | snd_soc_update_bits(codec, TABLA_A_MICB_CFILT_3_VAL, 0xFC, |
| 7944 | (k3 << 2)); |
| 7945 | |
| 7946 | snd_soc_update_bits(codec, TABLA_A_MICB_1_CTL, 0x60, |
| 7947 | (pdata->micbias.bias1_cfilt_sel << 5)); |
| 7948 | snd_soc_update_bits(codec, TABLA_A_MICB_2_CTL, 0x60, |
| 7949 | (pdata->micbias.bias2_cfilt_sel << 5)); |
| 7950 | snd_soc_update_bits(codec, TABLA_A_MICB_3_CTL, 0x60, |
| 7951 | (pdata->micbias.bias3_cfilt_sel << 5)); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 7952 | snd_soc_update_bits(codec, tabla->reg_addr.micb_4_ctl, 0x60, |
| 7953 | (pdata->micbias.bias4_cfilt_sel << 5)); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 7954 | |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 7955 | for (i = 0; i < 6; j++, i += 2) { |
| 7956 | if (flag & (0x01 << i)) { |
| 7957 | value = (leg_mode & (0x01 << i)) ? 0x10 : 0x00; |
| 7958 | val_txfe = (txfe_bypass & (0x01 << i)) ? 0x20 : 0x00; |
| 7959 | val_txfe = val_txfe | |
| 7960 | ((txfe_buff & (0x01 << i)) ? 0x10 : 0x00); |
| 7961 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 7962 | 0x10, value); |
| 7963 | snd_soc_update_bits(codec, |
| 7964 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 7965 | 0x30, val_txfe); |
| 7966 | } |
| 7967 | if (flag & (0x01 << (i + 1))) { |
| 7968 | value = (leg_mode & (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 7969 | val_txfe = (txfe_bypass & |
| 7970 | (0x01 << (i + 1))) ? 0x02 : 0x00; |
| 7971 | val_txfe |= (txfe_buff & |
| 7972 | (0x01 << (i + 1))) ? 0x01 : 0x00; |
| 7973 | snd_soc_update_bits(codec, TABLA_A_TX_1_2_EN + j * 10, |
| 7974 | 0x01, value); |
| 7975 | snd_soc_update_bits(codec, |
| 7976 | TABLA_A_TX_1_2_TEST_EN + j * 10, |
| 7977 | 0x03, val_txfe); |
| 7978 | } |
| 7979 | } |
| 7980 | if (flag & 0x40) { |
| 7981 | value = (leg_mode & 0x40) ? 0x10 : 0x00; |
| 7982 | value = value | ((txfe_bypass & 0x40) ? 0x02 : 0x00); |
| 7983 | value = value | ((txfe_buff & 0x40) ? 0x01 : 0x00); |
| 7984 | snd_soc_update_bits(codec, TABLA_A_TX_7_MBHC_EN, |
| 7985 | 0x13, value); |
| 7986 | } |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 7987 | |
| 7988 | if (pdata->ocp.use_pdata) { |
| 7989 | /* not defined in CODEC specification */ |
| 7990 | if (pdata->ocp.hph_ocp_limit == 1 || |
| 7991 | pdata->ocp.hph_ocp_limit == 5) { |
| 7992 | rc = -EINVAL; |
| 7993 | goto done; |
| 7994 | } |
| 7995 | snd_soc_update_bits(codec, TABLA_A_RX_COM_OCP_CTL, |
| 7996 | 0x0F, pdata->ocp.num_attempts); |
| 7997 | snd_soc_write(codec, TABLA_A_RX_COM_OCP_COUNT, |
| 7998 | ((pdata->ocp.run_time << 4) | pdata->ocp.wait_time)); |
| 7999 | snd_soc_update_bits(codec, TABLA_A_RX_HPH_OCP_CTL, |
| 8000 | 0xE0, (pdata->ocp.hph_ocp_limit << 5)); |
| 8001 | } |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8002 | |
| 8003 | for (i = 0; i < ARRAY_SIZE(pdata->regulator); i++) { |
| 8004 | if (!strncmp(pdata->regulator[i].name, "CDC_VDDA_RX", 11)) { |
| 8005 | if (pdata->regulator[i].min_uV == 1800000 && |
| 8006 | pdata->regulator[i].max_uV == 1800000) { |
| 8007 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8008 | 0x1C); |
| 8009 | } else if (pdata->regulator[i].min_uV == 2200000 && |
| 8010 | pdata->regulator[i].max_uV == 2200000) { |
| 8011 | snd_soc_write(codec, TABLA_A_BIAS_REF_CTL, |
| 8012 | 0x1E); |
| 8013 | } else { |
| 8014 | pr_err("%s: unsupported CDC_VDDA_RX voltage " |
| 8015 | "min %d, max %d\n", __func__, |
| 8016 | pdata->regulator[i].min_uV, |
| 8017 | pdata->regulator[i].max_uV); |
| 8018 | rc = -EINVAL; |
| 8019 | } |
| 8020 | break; |
| 8021 | } |
| 8022 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8023 | done: |
| 8024 | return rc; |
| 8025 | } |
| 8026 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8027 | static const struct tabla_reg_mask_val tabla_1_1_reg_defaults[] = { |
| 8028 | |
| 8029 | /* Tabla 1.1 MICBIAS changes */ |
| 8030 | TABLA_REG_VAL(TABLA_A_MICB_1_INT_RBIAS, 0x24), |
| 8031 | TABLA_REG_VAL(TABLA_A_MICB_2_INT_RBIAS, 0x24), |
| 8032 | TABLA_REG_VAL(TABLA_A_MICB_3_INT_RBIAS, 0x24), |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8033 | |
| 8034 | /* Tabla 1.1 HPH changes */ |
| 8035 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_PA, 0x57), |
| 8036 | TABLA_REG_VAL(TABLA_A_RX_HPH_BIAS_LDO, 0x56), |
| 8037 | |
| 8038 | /* Tabla 1.1 EAR PA changes */ |
| 8039 | TABLA_REG_VAL(TABLA_A_RX_EAR_BIAS_PA, 0xA6), |
| 8040 | TABLA_REG_VAL(TABLA_A_RX_EAR_GAIN, 0x02), |
| 8041 | TABLA_REG_VAL(TABLA_A_RX_EAR_VCM, 0x03), |
| 8042 | |
| 8043 | /* Tabla 1.1 Lineout_5 Changes */ |
| 8044 | TABLA_REG_VAL(TABLA_A_RX_LINE_5_GAIN, 0x10), |
| 8045 | |
| 8046 | /* Tabla 1.1 RX Changes */ |
| 8047 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B5_CTL, 0x78), |
| 8048 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B5_CTL, 0x78), |
| 8049 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B5_CTL, 0x78), |
| 8050 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B5_CTL, 0x78), |
| 8051 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B5_CTL, 0x78), |
| 8052 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B5_CTL, 0x78), |
| 8053 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B5_CTL, 0x78), |
| 8054 | |
| 8055 | /* Tabla 1.1 RX1 and RX2 Changes */ |
| 8056 | TABLA_REG_VAL(TABLA_A_CDC_RX1_B6_CTL, 0xA0), |
| 8057 | TABLA_REG_VAL(TABLA_A_CDC_RX2_B6_CTL, 0xA0), |
| 8058 | |
| 8059 | /* Tabla 1.1 RX3 to RX7 Changes */ |
| 8060 | TABLA_REG_VAL(TABLA_A_CDC_RX3_B6_CTL, 0x80), |
| 8061 | TABLA_REG_VAL(TABLA_A_CDC_RX4_B6_CTL, 0x80), |
| 8062 | TABLA_REG_VAL(TABLA_A_CDC_RX5_B6_CTL, 0x80), |
| 8063 | TABLA_REG_VAL(TABLA_A_CDC_RX6_B6_CTL, 0x80), |
| 8064 | TABLA_REG_VAL(TABLA_A_CDC_RX7_B6_CTL, 0x80), |
| 8065 | |
| 8066 | /* Tabla 1.1 CLASSG Changes */ |
| 8067 | TABLA_REG_VAL(TABLA_A_CDC_CLSG_FREQ_THRESH_B3_CTL, 0x1B), |
| 8068 | }; |
| 8069 | |
| 8070 | static const struct tabla_reg_mask_val tabla_2_0_reg_defaults[] = { |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8071 | /* Tabla 2.0 MICBIAS changes */ |
| 8072 | TABLA_REG_VAL(TABLA_A_MICB_2_MBHC, 0x02), |
| 8073 | }; |
| 8074 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8075 | static const struct tabla_reg_mask_val tabla_1_x_only_reg_2_0_defaults[] = { |
| 8076 | TABLA_REG_VAL(TABLA_1_A_MICB_4_INT_RBIAS, 0x24), |
| 8077 | }; |
| 8078 | |
| 8079 | static const struct tabla_reg_mask_val tabla_2_only_reg_2_0_defaults[] = { |
| 8080 | TABLA_REG_VAL(TABLA_2_A_MICB_4_INT_RBIAS, 0x24), |
| 8081 | }; |
| 8082 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8083 | static void tabla_update_reg_defaults(struct snd_soc_codec *codec) |
| 8084 | { |
| 8085 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8086 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8087 | |
| 8088 | for (i = 0; i < ARRAY_SIZE(tabla_1_1_reg_defaults); i++) |
| 8089 | snd_soc_write(codec, tabla_1_1_reg_defaults[i].reg, |
| 8090 | tabla_1_1_reg_defaults[i].val); |
| 8091 | |
| 8092 | for (i = 0; i < ARRAY_SIZE(tabla_2_0_reg_defaults); i++) |
| 8093 | snd_soc_write(codec, tabla_2_0_reg_defaults[i].reg, |
| 8094 | tabla_2_0_reg_defaults[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8095 | |
| 8096 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8097 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_only_reg_2_0_defaults); |
| 8098 | i++) |
| 8099 | snd_soc_write(codec, |
| 8100 | tabla_1_x_only_reg_2_0_defaults[i].reg, |
| 8101 | tabla_1_x_only_reg_2_0_defaults[i].val); |
| 8102 | } else { |
| 8103 | for (i = 0; i < ARRAY_SIZE(tabla_2_only_reg_2_0_defaults); i++) |
| 8104 | snd_soc_write(codec, |
| 8105 | tabla_2_only_reg_2_0_defaults[i].reg, |
| 8106 | tabla_2_only_reg_2_0_defaults[i].val); |
| 8107 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8108 | } |
| 8109 | |
| 8110 | static const struct tabla_reg_mask_val tabla_codec_reg_init_val[] = { |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8111 | /* Initialize current threshold to 350MA |
| 8112 | * number of wait and run cycles to 4096 |
| 8113 | */ |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8114 | {TABLA_A_RX_HPH_OCP_CTL, 0xE0, 0x60}, |
Patrick Lai | c7cae88 | 2011-11-18 11:52:49 -0800 | [diff] [blame] | 8115 | {TABLA_A_RX_COM_OCP_COUNT, 0xFF, 0xFF}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8116 | |
Santosh Mardi | 3217101 | 2011-10-28 23:32:06 +0530 | [diff] [blame] | 8117 | {TABLA_A_QFUSE_CTL, 0xFF, 0x03}, |
| 8118 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8119 | /* Initialize gain registers to use register gain */ |
| 8120 | {TABLA_A_RX_HPH_L_GAIN, 0x10, 0x10}, |
| 8121 | {TABLA_A_RX_HPH_R_GAIN, 0x10, 0x10}, |
| 8122 | {TABLA_A_RX_LINE_1_GAIN, 0x10, 0x10}, |
| 8123 | {TABLA_A_RX_LINE_2_GAIN, 0x10, 0x10}, |
| 8124 | {TABLA_A_RX_LINE_3_GAIN, 0x10, 0x10}, |
| 8125 | {TABLA_A_RX_LINE_4_GAIN, 0x10, 0x10}, |
| 8126 | |
Kuirong Wang | ccb29c6 | 2012-06-15 11:09:07 -0700 | [diff] [blame] | 8127 | /* Set the MICBIAS default output as pull down*/ |
| 8128 | {TABLA_A_MICB_1_CTL, 0x01, 0x01}, |
| 8129 | {TABLA_A_MICB_2_CTL, 0x01, 0x01}, |
| 8130 | {TABLA_A_MICB_3_CTL, 0x01, 0x01}, |
| 8131 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8132 | /* Initialize mic biases to differential mode */ |
| 8133 | {TABLA_A_MICB_1_INT_RBIAS, 0x24, 0x24}, |
| 8134 | {TABLA_A_MICB_2_INT_RBIAS, 0x24, 0x24}, |
| 8135 | {TABLA_A_MICB_3_INT_RBIAS, 0x24, 0x24}, |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8136 | |
| 8137 | {TABLA_A_CDC_CONN_CLSG_CTL, 0x3C, 0x14}, |
| 8138 | |
| 8139 | /* Use 16 bit sample size for TX1 to TX6 */ |
| 8140 | {TABLA_A_CDC_CONN_TX_SB_B1_CTL, 0x30, 0x20}, |
| 8141 | {TABLA_A_CDC_CONN_TX_SB_B2_CTL, 0x30, 0x20}, |
| 8142 | {TABLA_A_CDC_CONN_TX_SB_B3_CTL, 0x30, 0x20}, |
| 8143 | {TABLA_A_CDC_CONN_TX_SB_B4_CTL, 0x30, 0x20}, |
| 8144 | {TABLA_A_CDC_CONN_TX_SB_B5_CTL, 0x30, 0x20}, |
| 8145 | {TABLA_A_CDC_CONN_TX_SB_B6_CTL, 0x30, 0x20}, |
| 8146 | |
| 8147 | /* Use 16 bit sample size for TX7 to TX10 */ |
| 8148 | {TABLA_A_CDC_CONN_TX_SB_B7_CTL, 0x60, 0x40}, |
| 8149 | {TABLA_A_CDC_CONN_TX_SB_B8_CTL, 0x60, 0x40}, |
| 8150 | {TABLA_A_CDC_CONN_TX_SB_B9_CTL, 0x60, 0x40}, |
| 8151 | {TABLA_A_CDC_CONN_TX_SB_B10_CTL, 0x60, 0x40}, |
| 8152 | |
| 8153 | /* Use 16 bit sample size for RX */ |
| 8154 | {TABLA_A_CDC_CONN_RX_SB_B1_CTL, 0xFF, 0xAA}, |
| 8155 | {TABLA_A_CDC_CONN_RX_SB_B2_CTL, 0xFF, 0xAA}, |
| 8156 | |
| 8157 | /*enable HPF filter for TX paths */ |
| 8158 | {TABLA_A_CDC_TX1_MUX_CTL, 0x8, 0x0}, |
| 8159 | {TABLA_A_CDC_TX2_MUX_CTL, 0x8, 0x0}, |
| 8160 | {TABLA_A_CDC_TX3_MUX_CTL, 0x8, 0x0}, |
| 8161 | {TABLA_A_CDC_TX4_MUX_CTL, 0x8, 0x0}, |
| 8162 | {TABLA_A_CDC_TX5_MUX_CTL, 0x8, 0x0}, |
| 8163 | {TABLA_A_CDC_TX6_MUX_CTL, 0x8, 0x0}, |
| 8164 | {TABLA_A_CDC_TX7_MUX_CTL, 0x8, 0x0}, |
| 8165 | {TABLA_A_CDC_TX8_MUX_CTL, 0x8, 0x0}, |
| 8166 | {TABLA_A_CDC_TX9_MUX_CTL, 0x8, 0x0}, |
| 8167 | {TABLA_A_CDC_TX10_MUX_CTL, 0x8, 0x0}, |
Kiran Kandi | 0ba468f | 2012-05-08 11:45:05 -0700 | [diff] [blame] | 8168 | |
| 8169 | /* config Decimator for DMIC CLK_MODE_1(3.072Mhz@12.88Mhz mclk) */ |
| 8170 | {TABLA_A_CDC_TX1_DMIC_CTL, 0x1, 0x1}, |
| 8171 | {TABLA_A_CDC_TX2_DMIC_CTL, 0x1, 0x1}, |
| 8172 | {TABLA_A_CDC_TX3_DMIC_CTL, 0x1, 0x1}, |
| 8173 | {TABLA_A_CDC_TX4_DMIC_CTL, 0x1, 0x1}, |
| 8174 | {TABLA_A_CDC_TX5_DMIC_CTL, 0x1, 0x1}, |
| 8175 | {TABLA_A_CDC_TX6_DMIC_CTL, 0x1, 0x1}, |
| 8176 | {TABLA_A_CDC_TX7_DMIC_CTL, 0x1, 0x1}, |
| 8177 | {TABLA_A_CDC_TX8_DMIC_CTL, 0x1, 0x1}, |
| 8178 | {TABLA_A_CDC_TX9_DMIC_CTL, 0x1, 0x1}, |
| 8179 | {TABLA_A_CDC_TX10_DMIC_CTL, 0x1, 0x1}, |
| 8180 | |
| 8181 | /* config DMIC clk to CLK_MODE_1 (3.072Mhz@12.88Mhz mclk) */ |
| 8182 | {TABLA_A_CDC_CLK_DMIC_CTL, 0x2A, 0x2A}, |
| 8183 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8184 | }; |
| 8185 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8186 | 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] | 8187 | /* Set the MICBIAS default output as pull down*/ |
| 8188 | {TABLA_1_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8189 | /* Initialize mic biases to differential mode */ |
| 8190 | {TABLA_1_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8191 | }; |
| 8192 | |
| 8193 | 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] | 8194 | |
| 8195 | /* Set the MICBIAS default output as pull down*/ |
| 8196 | {TABLA_2_A_MICB_4_CTL, 0x01, 0x01}, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8197 | /* Initialize mic biases to differential mode */ |
| 8198 | {TABLA_2_A_MICB_4_INT_RBIAS, 0x24, 0x24}, |
| 8199 | }; |
| 8200 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8201 | static void tabla_codec_init_reg(struct snd_soc_codec *codec) |
| 8202 | { |
| 8203 | u32 i; |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8204 | struct wcd9xxx *tabla_core = dev_get_drvdata(codec->dev->parent); |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8205 | |
| 8206 | for (i = 0; i < ARRAY_SIZE(tabla_codec_reg_init_val); i++) |
| 8207 | snd_soc_update_bits(codec, tabla_codec_reg_init_val[i].reg, |
| 8208 | tabla_codec_reg_init_val[i].mask, |
| 8209 | tabla_codec_reg_init_val[i].val); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8210 | if (TABLA_IS_1_X(tabla_core->version)) { |
| 8211 | for (i = 0; i < ARRAY_SIZE(tabla_1_x_codec_reg_init_val); i++) |
| 8212 | snd_soc_update_bits(codec, |
| 8213 | tabla_1_x_codec_reg_init_val[i].reg, |
| 8214 | tabla_1_x_codec_reg_init_val[i].mask, |
| 8215 | tabla_1_x_codec_reg_init_val[i].val); |
| 8216 | } else { |
| 8217 | for (i = 0; i < ARRAY_SIZE(tabla_2_higher_codec_reg_init_val); |
| 8218 | i++) |
| 8219 | snd_soc_update_bits(codec, |
| 8220 | tabla_2_higher_codec_reg_init_val[i].reg, |
| 8221 | tabla_2_higher_codec_reg_init_val[i].mask, |
| 8222 | tabla_2_higher_codec_reg_init_val[i].val); |
| 8223 | } |
| 8224 | } |
| 8225 | |
| 8226 | static void tabla_update_reg_address(struct tabla_priv *priv) |
| 8227 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8228 | struct wcd9xxx *tabla_core = dev_get_drvdata(priv->codec->dev->parent); |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8229 | struct tabla_reg_address *reg_addr = &priv->reg_addr; |
| 8230 | |
| 8231 | if (TABLA_IS_1_X(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8232 | reg_addr->micb_4_mbhc = TABLA_1_A_MICB_4_MBHC; |
| 8233 | 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] | 8234 | reg_addr->micb_4_ctl = TABLA_1_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8235 | } else if (TABLA_IS_2_0(tabla_core->version)) { |
Joonwoo Park | cb7c892 | 2012-02-16 23:12:59 -0800 | [diff] [blame] | 8236 | reg_addr->micb_4_mbhc = TABLA_2_A_MICB_4_MBHC; |
| 8237 | 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] | 8238 | reg_addr->micb_4_ctl = TABLA_2_A_MICB_4_CTL; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8239 | } |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 8240 | } |
| 8241 | |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8242 | #ifdef CONFIG_DEBUG_FS |
| 8243 | static int codec_debug_open(struct inode *inode, struct file *file) |
| 8244 | { |
| 8245 | file->private_data = inode->i_private; |
| 8246 | return 0; |
| 8247 | } |
| 8248 | |
| 8249 | static ssize_t codec_debug_write(struct file *filp, |
| 8250 | const char __user *ubuf, size_t cnt, loff_t *ppos) |
| 8251 | { |
| 8252 | char lbuf[32]; |
| 8253 | char *buf; |
| 8254 | int rc; |
| 8255 | struct tabla_priv *tabla = filp->private_data; |
| 8256 | |
| 8257 | if (cnt > sizeof(lbuf) - 1) |
| 8258 | return -EINVAL; |
| 8259 | |
| 8260 | rc = copy_from_user(lbuf, ubuf, cnt); |
| 8261 | if (rc) |
| 8262 | return -EFAULT; |
| 8263 | |
| 8264 | lbuf[cnt] = '\0'; |
| 8265 | buf = (char *)lbuf; |
Joonwoo Park | 5bbcb0c | 2012-08-07 17:25:52 -0700 | [diff] [blame] | 8266 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
| 8267 | tabla->no_mic_headset_override = |
| 8268 | (*strsep(&buf, " ") == '0') ? false : true; |
| 8269 | if (tabla->no_mic_headset_override && tabla->mbhc_polling_active) { |
| 8270 | tabla_codec_pause_hs_polling(tabla->codec); |
| 8271 | tabla_codec_start_hs_polling(tabla->codec); |
| 8272 | } |
| 8273 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8274 | return cnt; |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8275 | } |
| 8276 | |
| 8277 | static ssize_t codec_mbhc_debug_read(struct file *file, char __user *buf, |
| 8278 | size_t count, loff_t *pos) |
| 8279 | { |
| 8280 | const int size = 768; |
| 8281 | char buffer[size]; |
| 8282 | int n = 0; |
| 8283 | struct tabla_priv *tabla = file->private_data; |
| 8284 | struct snd_soc_codec *codec = tabla->codec; |
| 8285 | const struct mbhc_internal_cal_data *p = &tabla->mbhc_data; |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8286 | const s16 v_ins_hu_cur = tabla_get_current_v_ins(tabla, true); |
| 8287 | 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] | 8288 | |
| 8289 | n = scnprintf(buffer, size - n, "dce_z = %x(%dmv)\n", p->dce_z, |
| 8290 | tabla_codec_sta_dce_v(codec, 1, p->dce_z)); |
| 8291 | n += scnprintf(buffer + n, size - n, "dce_mb = %x(%dmv)\n", |
| 8292 | p->dce_mb, tabla_codec_sta_dce_v(codec, 1, p->dce_mb)); |
| 8293 | n += scnprintf(buffer + n, size - n, "sta_z = %x(%dmv)\n", |
| 8294 | p->sta_z, tabla_codec_sta_dce_v(codec, 0, p->sta_z)); |
| 8295 | n += scnprintf(buffer + n, size - n, "sta_mb = %x(%dmv)\n", |
| 8296 | p->sta_mb, tabla_codec_sta_dce_v(codec, 0, p->sta_mb)); |
| 8297 | n += scnprintf(buffer + n, size - n, "t_dce = %x\n", p->t_dce); |
| 8298 | n += scnprintf(buffer + n, size - n, "t_sta = %x\n", p->t_sta); |
| 8299 | n += scnprintf(buffer + n, size - n, "micb_mv = %dmv\n", |
| 8300 | p->micb_mv); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8301 | 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] | 8302 | p->v_ins_hu, |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8303 | tabla_codec_sta_dce_v(codec, 0, p->v_ins_hu), |
| 8304 | p->v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8305 | n += scnprintf(buffer + n, size - n, "v_ins_h = %x(%dmv)%s\n", |
| 8306 | p->v_ins_h, tabla_codec_sta_dce_v(codec, 1, p->v_ins_h), |
| 8307 | p->v_ins_h == v_ins_h_cur ? "*" : ""); |
| 8308 | n += scnprintf(buffer + n, size - n, "adj_v_ins_hu = %x(%dmv)%s\n", |
| 8309 | p->adj_v_ins_hu, |
| 8310 | tabla_codec_sta_dce_v(codec, 0, p->adj_v_ins_hu), |
| 8311 | p->adj_v_ins_hu == v_ins_hu_cur ? "*" : ""); |
| 8312 | n += scnprintf(buffer + n, size - n, "adj_v_ins_h = %x(%dmv)%s\n", |
| 8313 | p->adj_v_ins_h, |
| 8314 | tabla_codec_sta_dce_v(codec, 1, p->adj_v_ins_h), |
| 8315 | p->adj_v_ins_h == v_ins_h_cur ? "*" : ""); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8316 | n += scnprintf(buffer + n, size - n, "v_b1_hu = %x(%dmv)\n", |
| 8317 | p->v_b1_hu, tabla_codec_sta_dce_v(codec, 0, p->v_b1_hu)); |
| 8318 | n += scnprintf(buffer + n, size - n, "v_b1_h = %x(%dmv)\n", |
| 8319 | p->v_b1_h, tabla_codec_sta_dce_v(codec, 1, p->v_b1_h)); |
| 8320 | n += scnprintf(buffer + n, size - n, "v_b1_huc = %x(%dmv)\n", |
| 8321 | p->v_b1_huc, |
| 8322 | tabla_codec_sta_dce_v(codec, 1, p->v_b1_huc)); |
| 8323 | n += scnprintf(buffer + n, size - n, "v_brh = %x(%dmv)\n", |
| 8324 | p->v_brh, tabla_codec_sta_dce_v(codec, 1, p->v_brh)); |
| 8325 | n += scnprintf(buffer + n, size - n, "v_brl = %x(%dmv)\n", p->v_brl, |
| 8326 | tabla_codec_sta_dce_v(codec, 0, p->v_brl)); |
| 8327 | n += scnprintf(buffer + n, size - n, "v_no_mic = %x(%dmv)\n", |
| 8328 | p->v_no_mic, |
| 8329 | tabla_codec_sta_dce_v(codec, 0, p->v_no_mic)); |
| 8330 | n += scnprintf(buffer + n, size - n, "npoll = %d\n", p->npoll); |
| 8331 | n += scnprintf(buffer + n, size - n, "nbounce_wait = %d\n", |
| 8332 | p->nbounce_wait); |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 8333 | n += scnprintf(buffer + n, size - n, "v_inval_ins_low = %d\n", |
| 8334 | p->v_inval_ins_low); |
| 8335 | n += scnprintf(buffer + n, size - n, "v_inval_ins_high = %d\n", |
| 8336 | p->v_inval_ins_high); |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 8337 | if (tabla->mbhc_cfg.gpio) |
| 8338 | n += scnprintf(buffer + n, size - n, "GPIO insert = %d\n", |
| 8339 | tabla_hs_gpio_level_remove(tabla)); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8340 | buffer[n] = 0; |
| 8341 | |
| 8342 | return simple_read_from_buffer(buf, count, pos, buffer, n); |
| 8343 | } |
| 8344 | |
| 8345 | static const struct file_operations codec_debug_ops = { |
| 8346 | .open = codec_debug_open, |
| 8347 | .write = codec_debug_write, |
| 8348 | }; |
| 8349 | |
| 8350 | static const struct file_operations codec_mbhc_debug_ops = { |
| 8351 | .open = codec_debug_open, |
| 8352 | .read = codec_mbhc_debug_read, |
| 8353 | }; |
| 8354 | #endif |
| 8355 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8356 | static int tabla_codec_probe(struct snd_soc_codec *codec) |
| 8357 | { |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8358 | struct wcd9xxx *control; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8359 | struct tabla_priv *tabla; |
| 8360 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 8361 | int ret = 0; |
| 8362 | int i; |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8363 | void *ptr = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8364 | |
| 8365 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
| 8366 | control = codec->control_data; |
| 8367 | |
| 8368 | tabla = kzalloc(sizeof(struct tabla_priv), GFP_KERNEL); |
| 8369 | if (!tabla) { |
| 8370 | dev_err(codec->dev, "Failed to allocate private data\n"); |
| 8371 | return -ENOMEM; |
| 8372 | } |
Kiran Kandi | d8cf521 | 2012-03-02 15:34:53 -0800 | [diff] [blame] | 8373 | for (i = 0 ; i < NUM_DECIMATORS; i++) { |
| 8374 | tx_hpf_work[i].tabla = tabla; |
| 8375 | tx_hpf_work[i].decimator = i + 1; |
| 8376 | INIT_DELAYED_WORK(&tx_hpf_work[i].dwork, |
| 8377 | tx_hpf_corner_freq_callback); |
| 8378 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8379 | |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8380 | /* Make sure mbhc micbias register addresses are zeroed out */ |
| 8381 | memset(&tabla->mbhc_bias_regs, 0, |
| 8382 | sizeof(struct mbhc_micbias_regs)); |
Bhalchandra Gajare | d9ebb6c | 2011-10-03 19:54:41 -0700 | [diff] [blame] | 8383 | tabla->mbhc_micbias_switched = false; |
Bhalchandra Gajare | 02d90cd | 2011-09-30 16:14:00 -0700 | [diff] [blame] | 8384 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8385 | /* Make sure mbhc intenal calibration data is zeroed out */ |
| 8386 | memset(&tabla->mbhc_data, 0, |
| 8387 | sizeof(struct mbhc_internal_cal_data)); |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 8388 | tabla->mbhc_data.t_sta_dce = DEFAULT_DCE_STA_WAIT; |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 8389 | tabla->mbhc_data.t_dce = DEFAULT_DCE_WAIT; |
| 8390 | tabla->mbhc_data.t_sta = DEFAULT_STA_WAIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8391 | snd_soc_codec_set_drvdata(codec, tabla); |
| 8392 | |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 8393 | tabla->mclk_enabled = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8394 | tabla->bandgap_type = TABLA_BANDGAP_OFF; |
| 8395 | tabla->clock_active = false; |
| 8396 | tabla->config_mode_active = false; |
| 8397 | tabla->mbhc_polling_active = false; |
Joonwoo Park | f4267c2 | 2012-01-10 13:25:24 -0800 | [diff] [blame] | 8398 | tabla->mbhc_fake_ins_start = 0; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8399 | tabla->no_mic_headset_override = false; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8400 | tabla->hs_polling_irq_prepared = false; |
| 8401 | mutex_init(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8402 | tabla->codec = codec; |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8403 | tabla->mbhc_state = MBHC_STATE_NONE; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8404 | tabla->mbhc_last_resume = 0; |
Kuirong Wang | 0f8ade3 | 2012-02-27 16:29:45 -0800 | [diff] [blame] | 8405 | for (i = 0; i < COMPANDER_MAX; i++) { |
| 8406 | tabla->comp_enabled[i] = 0; |
| 8407 | tabla->comp_fs[i] = COMPANDER_FS_48KHZ; |
| 8408 | } |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8409 | tabla->pdata = dev_get_platdata(codec->dev->parent); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8410 | tabla->intf_type = wcd9xxx_get_intf_type(); |
Bhalchandra Gajare | b0f1513 | 2012-02-07 15:00:21 -0800 | [diff] [blame] | 8411 | tabla->aux_pga_cnt = 0; |
| 8412 | tabla->aux_l_gain = 0x1F; |
| 8413 | tabla->aux_r_gain = 0x1F; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8414 | tabla_update_reg_address(tabla); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8415 | tabla_update_reg_defaults(codec); |
| 8416 | tabla_codec_init_reg(codec); |
Santosh Mardi | 2292028 | 2011-10-26 02:38:40 +0530 | [diff] [blame] | 8417 | ret = tabla_handle_pdata(tabla); |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8418 | if (IS_ERR_VALUE(ret)) { |
| 8419 | pr_err("%s: bad pdata\n", __func__); |
| 8420 | goto err_pdata; |
| 8421 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8422 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8423 | if (TABLA_IS_1_X(control->version)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8424 | snd_soc_add_codec_controls(codec, tabla_1_x_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8425 | ARRAY_SIZE(tabla_1_x_snd_controls)); |
| 8426 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8427 | snd_soc_add_codec_controls(codec, tabla_2_higher_snd_controls, |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8428 | ARRAY_SIZE(tabla_2_higher_snd_controls)); |
| 8429 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8430 | if (TABLA_IS_1_X(control->version)) |
| 8431 | snd_soc_dapm_new_controls(dapm, tabla_1_x_dapm_widgets, |
| 8432 | ARRAY_SIZE(tabla_1_x_dapm_widgets)); |
| 8433 | else |
| 8434 | snd_soc_dapm_new_controls(dapm, tabla_2_higher_dapm_widgets, |
| 8435 | ARRAY_SIZE(tabla_2_higher_dapm_widgets)); |
| 8436 | |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8437 | |
| 8438 | ptr = kmalloc((sizeof(tabla_rx_chs) + |
| 8439 | sizeof(tabla_tx_chs)), GFP_KERNEL); |
| 8440 | if (!ptr) { |
| 8441 | pr_err("%s: no mem for slim chan ctl data\n", __func__); |
| 8442 | ret = -ENOMEM; |
| 8443 | goto err_nomem_slimch; |
| 8444 | } |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8445 | if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_I2C) { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8446 | snd_soc_dapm_new_controls(dapm, tabla_dapm_i2s_widgets, |
| 8447 | ARRAY_SIZE(tabla_dapm_i2s_widgets)); |
| 8448 | snd_soc_dapm_add_routes(dapm, audio_i2s_map, |
| 8449 | ARRAY_SIZE(audio_i2s_map)); |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8450 | for (i = 0; i < ARRAY_SIZE(tabla_i2s_dai); i++) |
| 8451 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8452 | } else if (tabla->intf_type == WCD9XXX_INTERFACE_TYPE_SLIMBUS) { |
| 8453 | for (i = 0; i < NUM_CODEC_DAIS; i++) { |
| 8454 | INIT_LIST_HEAD(&tabla->dai[i].wcd9xxx_ch_list); |
| 8455 | init_waitqueue_head(&tabla->dai[i].dai_wait); |
| 8456 | } |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8457 | } |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8458 | |
| 8459 | control->num_rx_port = TABLA_RX_MAX; |
| 8460 | control->rx_chs = ptr; |
| 8461 | memcpy(control->rx_chs, tabla_rx_chs, sizeof(tabla_rx_chs)); |
| 8462 | control->num_tx_port = TABLA_TX_MAX; |
| 8463 | control->tx_chs = ptr + sizeof(tabla_rx_chs); |
| 8464 | memcpy(control->tx_chs, tabla_tx_chs, sizeof(tabla_tx_chs)); |
| 8465 | |
Kiran Kandi | 8b3a830 | 2011-09-27 16:13:28 -0700 | [diff] [blame] | 8466 | |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 8467 | if (TABLA_IS_1_X(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8468 | 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] | 8469 | ARRAY_SIZE(tabla_1_x_lineout_2_to_4_map)); |
| 8470 | } else if (TABLA_IS_2_0(control->version)) { |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8471 | 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] | 8472 | ARRAY_SIZE(tabla_2_x_lineout_2_to_4_map)); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8473 | } else { |
| 8474 | pr_err("%s : ERROR. Unsupported Tabla version 0x%2x\n", |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8475 | __func__, control->version); |
Kiran Kandi | 7a9fd90 | 2011-11-14 13:51:45 -0800 | [diff] [blame] | 8476 | goto err_pdata; |
| 8477 | } |
| 8478 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8479 | snd_soc_dapm_sync(dapm); |
| 8480 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8481 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8482 | WCD9XXX_IRQ_MBHC_INSERTION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8483 | tabla_hs_insert_irq, "Headset insert detect", tabla); |
| 8484 | if (ret) { |
| 8485 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8486 | WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8487 | goto err_insert_irq; |
| 8488 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8489 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8490 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8491 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8492 | WCD9XXX_IRQ_MBHC_REMOVAL, |
| 8493 | tabla_hs_remove_irq, |
| 8494 | "Headset remove detect", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8495 | if (ret) { |
| 8496 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8497 | WCD9XXX_IRQ_MBHC_REMOVAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8498 | goto err_remove_irq; |
| 8499 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8500 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8501 | ret = wcd9xxx_request_irq(codec->control_data, |
| 8502 | WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 8503 | tabla_dce_handler, "DC Estimation detect", |
| 8504 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8505 | if (ret) { |
| 8506 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8507 | WCD9XXX_IRQ_MBHC_POTENTIAL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8508 | goto err_potential_irq; |
| 8509 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8510 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8511 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, |
| 8512 | tabla_release_handler, |
| 8513 | "Button Release detect", tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 8514 | if (ret) { |
| 8515 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8516 | WCD9XXX_IRQ_MBHC_RELEASE); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 8517 | goto err_release_irq; |
| 8518 | } |
| 8519 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8520 | ret = wcd9xxx_request_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, |
| 8521 | tabla_slimbus_irq, "SLIMBUS Slave", tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8522 | if (ret) { |
| 8523 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8524 | WCD9XXX_IRQ_SLIMBUS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8525 | goto err_slimbus_irq; |
| 8526 | } |
| 8527 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8528 | for (i = 0; i < WCD9XXX_SLIM_NUM_PORT_REG; i++) |
| 8529 | wcd9xxx_interface_reg_write(codec->control_data, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8530 | TABLA_SLIM_PGD_PORT_INT_EN0 + i, 0xFF); |
| 8531 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8532 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8533 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, |
| 8534 | tabla_hphl_ocp_irq, |
| 8535 | "HPH_L OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8536 | if (ret) { |
| 8537 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8538 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8539 | goto err_hphl_ocp_irq; |
| 8540 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8541 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPL_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8542 | |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8543 | ret = wcd9xxx_request_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8544 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT, |
| 8545 | tabla_hphr_ocp_irq, |
| 8546 | "HPH_R OCP detect", tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8547 | if (ret) { |
| 8548 | pr_err("%s: Failed to request irq %d\n", __func__, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8549 | WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8550 | goto err_hphr_ocp_irq; |
| 8551 | } |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8552 | wcd9xxx_disable_irq(codec->control_data, WCD9XXX_IRQ_HPH_PA_OCPR_FAULT); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8553 | |
| 8554 | /* |
| 8555 | * Register suspend lock and notifier to resend edge triggered |
| 8556 | * gpio IRQs |
| 8557 | */ |
| 8558 | wake_lock_init(&tabla->irq_resend_wlock, WAKE_LOCK_SUSPEND, |
| 8559 | "tabla_gpio_irq_resend"); |
| 8560 | tabla->gpio_irq_resend = false; |
| 8561 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8562 | |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8563 | #ifdef CONFIG_DEBUG_FS |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8564 | if (ret == 0) { |
| 8565 | tabla->debugfs_poke = |
| 8566 | debugfs_create_file("TRRS", S_IFREG | S_IRUGO, NULL, tabla, |
| 8567 | &codec_debug_ops); |
| 8568 | tabla->debugfs_mbhc = |
| 8569 | debugfs_create_file("tabla_mbhc", S_IFREG | S_IRUGO, |
| 8570 | NULL, tabla, &codec_mbhc_debug_ops); |
| 8571 | } |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8572 | #endif |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8573 | codec->ignore_pmdown_time = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8574 | return ret; |
| 8575 | |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8576 | err_hphr_ocp_irq: |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8577 | wcd9xxx_free_irq(codec->control_data, |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8578 | WCD9XXX_IRQ_HPH_PA_OCPL_FAULT, tabla); |
Patrick Lai | 49efeac | 2011-11-03 11:01:12 -0700 | [diff] [blame] | 8579 | err_hphl_ocp_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8580 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8581 | err_slimbus_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8582 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
Bradley Rubin | cb1e273 | 2011-06-23 16:49:20 -0700 | [diff] [blame] | 8583 | err_release_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8584 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 8585 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8586 | err_potential_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8587 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8588 | err_remove_irq: |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8589 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 8590 | tabla); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8591 | err_insert_irq: |
Patrick Lai | 3043fba | 2011-08-01 14:15:57 -0700 | [diff] [blame] | 8592 | err_pdata: |
Kuirong Wang | 906ac47 | 2012-07-09 12:54:44 -0700 | [diff] [blame] | 8593 | kfree(ptr); |
| 8594 | err_nomem_slimch: |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8595 | mutex_destroy(&tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8596 | kfree(tabla); |
| 8597 | return ret; |
| 8598 | } |
| 8599 | static int tabla_codec_remove(struct snd_soc_codec *codec) |
| 8600 | { |
| 8601 | struct tabla_priv *tabla = snd_soc_codec_get_drvdata(codec); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8602 | |
| 8603 | wake_lock_destroy(&tabla->irq_resend_wlock); |
| 8604 | |
Joonwoo Park | f6574c7 | 2012-10-10 17:29:57 -0700 | [diff] [blame] | 8605 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_SLIMBUS, tabla); |
| 8606 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_RELEASE, tabla); |
| 8607 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_POTENTIAL, |
| 8608 | tabla); |
| 8609 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_REMOVAL, tabla); |
| 8610 | wcd9xxx_free_irq(codec->control_data, WCD9XXX_IRQ_MBHC_INSERTION, |
| 8611 | tabla); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8612 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8613 | tabla_codec_disable_clock_block(codec); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8614 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8615 | tabla_codec_enable_bandgap(codec, TABLA_BANDGAP_OFF); |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 8616 | if (tabla->mbhc_fw) |
| 8617 | release_firmware(tabla->mbhc_fw); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 8618 | mutex_destroy(&tabla->codec_resource_lock); |
Joonwoo Park | 179b9ec | 2012-03-26 10:56:20 -0700 | [diff] [blame] | 8619 | #ifdef CONFIG_DEBUG_FS |
| 8620 | debugfs_remove(tabla->debugfs_poke); |
| 8621 | debugfs_remove(tabla->debugfs_mbhc); |
| 8622 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8623 | kfree(tabla); |
| 8624 | return 0; |
| 8625 | } |
| 8626 | static struct snd_soc_codec_driver soc_codec_dev_tabla = { |
| 8627 | .probe = tabla_codec_probe, |
| 8628 | .remove = tabla_codec_remove, |
| 8629 | .read = tabla_read, |
| 8630 | .write = tabla_write, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8631 | .readable_register = tabla_readable, |
| 8632 | .volatile_register = tabla_volatile, |
| 8633 | |
| 8634 | .reg_cache_size = TABLA_CACHE_SIZE, |
| 8635 | .reg_cache_default = tabla_reg_defaults, |
| 8636 | .reg_word_size = 1, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8637 | .controls = tabla_snd_controls, |
| 8638 | .num_controls = ARRAY_SIZE(tabla_snd_controls), |
| 8639 | .dapm_widgets = tabla_dapm_widgets, |
| 8640 | .num_dapm_widgets = ARRAY_SIZE(tabla_dapm_widgets), |
| 8641 | .dapm_routes = audio_map, |
| 8642 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8643 | }; |
Bradley Rubin | cb3950a | 2011-08-18 13:07:26 -0700 | [diff] [blame] | 8644 | |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8645 | #ifdef CONFIG_PM |
| 8646 | static int tabla_suspend(struct device *dev) |
| 8647 | { |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 8648 | dev_dbg(dev, "%s: system suspend\n", __func__); |
| 8649 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | static int tabla_resume(struct device *dev) |
| 8653 | { |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8654 | int irq; |
Joonwoo Park | 0332483 | 2012-03-19 19:36:16 -0700 | [diff] [blame] | 8655 | struct platform_device *pdev = to_platform_device(dev); |
| 8656 | struct tabla_priv *tabla = platform_get_drvdata(pdev); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8657 | |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 8658 | dev_dbg(dev, "%s: system resume tabla %p\n", __func__, tabla); |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8659 | if (tabla) { |
| 8660 | TABLA_ACQUIRE_LOCK(tabla->codec_resource_lock); |
Joonwoo Park | d6e48bd | 2012-09-20 11:14:15 -0700 | [diff] [blame] | 8661 | tabla->mbhc_last_resume = jiffies; |
Joonwoo Park | ecf379c | 2012-10-04 16:57:52 -0700 | [diff] [blame] | 8662 | if (tabla->gpio_irq_resend) { |
| 8663 | WARN_ON(!tabla->mbhc_cfg.gpio_irq); |
| 8664 | tabla->gpio_irq_resend = false; |
| 8665 | |
| 8666 | irq = tabla->mbhc_cfg.gpio_irq; |
| 8667 | pr_debug("%s: Resending GPIO IRQ %d\n", __func__, irq); |
| 8668 | irq_set_pending(irq); |
| 8669 | check_irq_resend(irq_to_desc(irq), irq); |
| 8670 | |
| 8671 | /* release suspend lock */ |
| 8672 | wake_unlock(&tabla->irq_resend_wlock); |
| 8673 | } |
| 8674 | TABLA_RELEASE_LOCK(tabla->codec_resource_lock); |
| 8675 | } |
| 8676 | |
Joonwoo Park | 816b8e6 | 2012-01-23 16:03:21 -0800 | [diff] [blame] | 8677 | return 0; |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8678 | } |
| 8679 | |
| 8680 | static const struct dev_pm_ops tabla_pm_ops = { |
| 8681 | .suspend = tabla_suspend, |
| 8682 | .resume = tabla_resume, |
| 8683 | }; |
| 8684 | #endif |
| 8685 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8686 | static int __devinit tabla_probe(struct platform_device *pdev) |
| 8687 | { |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8688 | int ret = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 8689 | pr_err("tabla_probe\n"); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8690 | if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_SLIMBUS) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8691 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 8692 | tabla_dai, ARRAY_SIZE(tabla_dai)); |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 8693 | else if (wcd9xxx_get_intf_type() == WCD9XXX_INTERFACE_TYPE_I2C) |
Santosh Mardi | e15e230 | 2011-11-15 10:39:23 +0530 | [diff] [blame] | 8694 | ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_tabla, |
| 8695 | tabla_i2s_dai, ARRAY_SIZE(tabla_i2s_dai)); |
| 8696 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8697 | } |
| 8698 | static int __devexit tabla_remove(struct platform_device *pdev) |
| 8699 | { |
| 8700 | snd_soc_unregister_codec(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8701 | return 0; |
| 8702 | } |
| 8703 | static struct platform_driver tabla_codec_driver = { |
| 8704 | .probe = tabla_probe, |
| 8705 | .remove = tabla_remove, |
| 8706 | .driver = { |
| 8707 | .name = "tabla_codec", |
| 8708 | .owner = THIS_MODULE, |
Joonwoo Park | 8b1f098 | 2011-12-08 17:12:45 -0800 | [diff] [blame] | 8709 | #ifdef CONFIG_PM |
| 8710 | .pm = &tabla_pm_ops, |
| 8711 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8712 | }, |
| 8713 | }; |
| 8714 | |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8715 | static struct platform_driver tabla1x_codec_driver = { |
| 8716 | .probe = tabla_probe, |
| 8717 | .remove = tabla_remove, |
| 8718 | .driver = { |
| 8719 | .name = "tabla1x_codec", |
| 8720 | .owner = THIS_MODULE, |
| 8721 | #ifdef CONFIG_PM |
| 8722 | .pm = &tabla_pm_ops, |
| 8723 | #endif |
| 8724 | }, |
| 8725 | }; |
| 8726 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8727 | static int __init tabla_codec_init(void) |
| 8728 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8729 | int rtn = platform_driver_register(&tabla_codec_driver); |
| 8730 | if (rtn == 0) { |
| 8731 | rtn = platform_driver_register(&tabla1x_codec_driver); |
| 8732 | if (rtn != 0) |
| 8733 | platform_driver_unregister(&tabla_codec_driver); |
| 8734 | } |
| 8735 | return rtn; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8736 | } |
| 8737 | |
| 8738 | static void __exit tabla_codec_exit(void) |
| 8739 | { |
Kuirong Wang | cd4b6da | 2012-01-16 22:54:45 -0800 | [diff] [blame] | 8740 | platform_driver_unregister(&tabla1x_codec_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 8741 | platform_driver_unregister(&tabla_codec_driver); |
| 8742 | } |
| 8743 | |
| 8744 | module_init(tabla_codec_init); |
| 8745 | module_exit(tabla_codec_exit); |
| 8746 | |
| 8747 | MODULE_DESCRIPTION("Tabla codec driver"); |
| 8748 | MODULE_VERSION("1.0"); |
| 8749 | MODULE_LICENSE("GPL v2"); |